mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00

* Adjust imports to bigchaindb_common * Adjust get_spent function signature * Adjust block serialization * Fix BigchainApi Test * Fix TestTransactionValidation tests * Fix TestBlockValidation tests * WIP: TestMultipleInputs * Adjust tests to tx-model interface changes - Fix old tests - Fix tests in TestMultipleInputs class * Remove fulfillment message tests * Fix TransactionMalleability tests * Remove Cryptoconditions tests * Remove create_transaction * Remove signing logic * Remove consensus plugin * Fix block_creation pipeline * Fix election pipeline * Replace some util functions with bdb_common ones - timestamp ==> gen_timestamp - serialize. * Implement Block model * Simplify function signatures for vote functions Change parameter interface for the following functions: - has_previous_vote - verify_vote_signature - block_election_status so that they take a block's id and voters instead of a fake block. * Integrate Block and Transaction model * Fix leftover tests and cleanup conftest * Add bigchaindb-common to install_requires * Delete transactions after block is written (#609) * delete transactions after block is written * cleanup transaction_exists * check for duplicate transactions * delete invalid tx from backlog * test duplicate transaction * Remove dead code * Test processes.py * Test invalid tx in on server * Fix tests for core.py * Fix models tests * Test commands main fn * Add final coverage to vote pipeline * Add more tests to voting pipeline * Remove consensus plugin docs and misc * Post rebase fixes * Fix rebase mess * Remove extra blank line * Improve docstring * Remove comment handled in bigchaindb/cryptoconditions#27; see https://github.com/bigchaindb/cryptoconditions/issues/27 * Fix block serialization in block creation * Add signed_ prefix to transfer_tx * Improve docs * Add library documentation page on pipelines * PR feedback for models.py * Impr. readability of get_last_voted_block * Use dict comprehension * Add docker-compose file to build and serve docs locally for development purposes * Change private_key for signing_key * Improve docstrings * Remove consensus docs * Document new consensus module * Create different transactions for the block * Cleanup variable names in block.py * Create different transactions for the block * Cleanup variable names in block.py
109 lines
3.6 KiB
Python
109 lines
3.6 KiB
Python
from collections import namedtuple
|
|
|
|
from rethinkdb.ast import RqlQuery
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture
|
|
def config(request, monkeypatch):
|
|
config = {
|
|
'database': {
|
|
'host': 'host',
|
|
'port': 28015,
|
|
'name': 'bigchain',
|
|
},
|
|
'keypair': {
|
|
'public': 'pubkey',
|
|
'private': 'privkey',
|
|
},
|
|
'keyring': [],
|
|
'CONFIGURED': True,
|
|
'backlog_reassign_delay': 30
|
|
}
|
|
|
|
monkeypatch.setattr('bigchaindb.config', config)
|
|
|
|
return config
|
|
|
|
|
|
def test_bigchain_class_default_initialization(config):
|
|
from bigchaindb.core import Bigchain
|
|
from bigchaindb.consensus import BaseConsensusRules
|
|
bigchain = Bigchain()
|
|
assert bigchain.host == config['database']['host']
|
|
assert bigchain.port == config['database']['port']
|
|
assert bigchain.dbname == config['database']['name']
|
|
assert bigchain.me == config['keypair']['public']
|
|
assert bigchain.me_private == config['keypair']['private']
|
|
assert bigchain.nodes_except_me == config['keyring']
|
|
assert bigchain.consensus == BaseConsensusRules
|
|
assert bigchain._conn is None
|
|
|
|
|
|
def test_bigchain_class_initialization_with_parameters(config):
|
|
from bigchaindb.core import Bigchain
|
|
from bigchaindb.consensus import BaseConsensusRules
|
|
init_kwargs = {
|
|
'host': 'some_node',
|
|
'port': '12345',
|
|
'dbname': 'atom',
|
|
'public_key': 'white',
|
|
'private_key': 'black',
|
|
'keyring': ['key_one', 'key_two'],
|
|
}
|
|
bigchain = Bigchain(**init_kwargs)
|
|
assert bigchain.host == init_kwargs['host']
|
|
assert bigchain.port == init_kwargs['port']
|
|
assert bigchain.dbname == init_kwargs['dbname']
|
|
assert bigchain.me == init_kwargs['public_key']
|
|
assert bigchain.me_private == init_kwargs['private_key']
|
|
assert bigchain.nodes_except_me == init_kwargs['keyring']
|
|
assert bigchain.consensus == BaseConsensusRules
|
|
assert bigchain._conn is None
|
|
|
|
|
|
def test_get_blocks_status_containing_tx(monkeypatch):
|
|
from bigchaindb.core import Bigchain
|
|
blocks = [
|
|
{'id': 1}, {'id': 2}
|
|
]
|
|
monkeypatch.setattr(
|
|
Bigchain, 'search_block_election_on_index', lambda x, y: blocks)
|
|
monkeypatch.setattr(
|
|
Bigchain, 'block_election_status', lambda x, y, z: Bigchain.BLOCK_VALID)
|
|
bigchain = Bigchain(public_key='pubkey', private_key='privkey')
|
|
with pytest.raises(Exception):
|
|
bigchain.get_blocks_status_containing_tx('txid')
|
|
|
|
|
|
def test_has_previous_vote(monkeypatch):
|
|
from bigchaindb.core import Bigchain
|
|
monkeypatch.setattr(
|
|
'bigchaindb.util.verify_vote_signature', lambda voters, vote: False)
|
|
bigchain = Bigchain(public_key='pubkey', private_key='privkey')
|
|
block = {'votes': ({'node_pubkey': 'pubkey'},)}
|
|
with pytest.raises(Exception):
|
|
bigchain.has_previous_vote(block)
|
|
|
|
|
|
@pytest.mark.parametrize('items,exists', (((0,), True), ((), False)))
|
|
def test_transaction_exists(monkeypatch, items, exists):
|
|
from bigchaindb.core import Bigchain
|
|
monkeypatch.setattr(
|
|
RqlQuery, 'run', lambda x, y: namedtuple('response', 'items')(items))
|
|
bigchain = Bigchain(public_key='pubkey', private_key='privkey')
|
|
assert bigchain.transaction_exists('txid') is exists
|
|
|
|
|
|
@pytest.mark.skip(reason='until tim decides')
|
|
def test_write_transaction_no_sideffects(b):
|
|
from rethinkdb.errors import ReqlOpFailedError
|
|
transaction = {'id': 'abc'}
|
|
expected = {'id': 'abc'}
|
|
with pytest.raises(ReqlOpFailedError):
|
|
b.write_transaction(transaction)
|
|
assert transaction == expected
|
|
with pytest.raises(KeyError):
|
|
transaction['assignee']
|