Add genesis block fixture and marker

This commit is contained in:
Sylvain Bellemare 2016-12-20 05:00:21 +01:00 committed by Sylvain Bellemare
parent 5017ece84c
commit 44391da94a
4 changed files with 103 additions and 114 deletions

View File

@ -56,6 +56,14 @@ def pytest_configure(config):
'be suffixed with the process identifier, e.g.: "bigchain_test_gw0", '
'to ensure that each process session has its own separate database.'
)
config.addinivalue_line(
'markers',
'genesis(): Mark the test as needing a genesis block in place. The '
'prerequisite steps of configuration and database setup are taken '
'care of at session scope (if needed), prior to creating the genesis '
'block. The genesis block has function scope: it is destroyed after '
'each test function/method.'
)
@pytest.fixture(autouse=True)
@ -64,6 +72,12 @@ def _bdb_marker(request):
request.getfixturevalue('_bdb')
@pytest.fixture(autouse=True)
def _genesis_marker(request):
if request.keywords.get('genesis', None):
request.getfixturevalue('_genesis')
@pytest.fixture(autouse=True)
def _restore_config(_configure_bigchaindb):
from bigchaindb import config, config_utils
@ -158,6 +172,16 @@ def _bdb(_setup_database, _configure_bigchaindb):
flush_db(conn, dbname)
@pytest.fixture
def _genesis(_bdb, genesis_block):
# TODO for precision's sake, delete the block once the test is done. The
# deletion is done indirectly via the teardown code of _bdb but explicit
# deletion of the block would make things clearer. E.g.:
# yield
# tests.utils.delete_genesis_block(conn, dbname)
pass
# We need this function to avoid loading an existing
# conf file located in the home of the user running
# the tests. If it's too aggressive we can change it
@ -235,19 +259,16 @@ def structurally_valid_vote():
@pytest.fixture
def inputs(user_pk):
from bigchaindb import Bigchain
from bigchaindb.models import Transaction
from bigchaindb.common.exceptions import GenesisBlockAlreadyExistsError
# 1. create the genesis block
b = Bigchain()
try:
g = b.create_genesis_block()
except GenesisBlockAlreadyExistsError:
pass
def genesis_block(b):
return b.create_genesis_block()
# 2. create blocks with transactions for `USER` to spend
prev_block_id = g.id
@pytest.fixture
def inputs(user_pk, b, genesis_block):
from bigchaindb.models import Transaction
# create blocks with transactions for `USER` to spend
prev_block_id = genesis_block.id
for block in range(4):
transactions = [
Transaction.create([b.me], [([user_pk], 1)],
@ -258,26 +279,18 @@ def inputs(user_pk):
block = b.create_block(transactions)
b.write_block(block)
# 3. vote the blocks valid, so that the inputs are valid
# vote the blocks valid, so that the inputs are valid
vote = b.vote(block.id, prev_block_id, True)
prev_block_id = block.id
b.write_vote(vote)
@pytest.fixture
def inputs_shared(user_pk, user2_pk):
from bigchaindb import Bigchain
def inputs_shared(user_pk, user2_pk, genesis_block):
from bigchaindb.models import Transaction
from bigchaindb.common.exceptions import GenesisBlockAlreadyExistsError
# 1. create the genesis block
b = Bigchain()
try:
g = b.create_genesis_block()
except GenesisBlockAlreadyExistsError:
pass
# 2. create blocks with transactions for `USER` to spend
prev_block_id = g.id
# create blocks with transactions for `USER` to spend
prev_block_id = genesis_block.id
for block in range(4):
transactions = [
Transaction.create([b.me], [user_pk, user2_pk],
@ -288,7 +301,7 @@ def inputs_shared(user_pk, user2_pk):
block = b.create_block(transactions)
b.write_block(block)
# 3. vote the blocks valid, so that the inputs are valid
# vote the blocks valid, so that the inputs are valid
vote = b.vote(block.id, prev_block_id, True)
prev_block_id = block.id
b.write_vote(vote)

View File

@ -32,14 +32,14 @@ def dummy_block():
class TestBigchainApi(object):
@pytest.mark.genesis
def test_get_last_voted_block_cyclic_blockchain(self, b, monkeypatch):
from bigchaindb.common.crypto import PrivateKey
from bigchaindb.common.exceptions import CyclicBlockchainError
from bigchaindb.common.util import serialize
from bigchaindb.models import Transaction
b.create_genesis_block()
tx = Transaction.create([b.me], [([b.me], 1)])
tx = tx.sign([b.me_private])
monkeypatch.setattr('time.time', lambda: 1)
@ -56,13 +56,12 @@ class TestBigchainApi(object):
with pytest.raises(CyclicBlockchainError):
b.get_last_voted_block()
@pytest.mark.genesis
def test_try_voting_while_constructing_cyclic_blockchain(self, b,
monkeypatch):
from bigchaindb.common.exceptions import CyclicBlockchainError
from bigchaindb.models import Transaction
b.create_genesis_block()
tx = Transaction.create([b.me], [([b.me], 1)])
tx = tx.sign([b.me_private])
block1 = b.create_block([tx])
@ -72,11 +71,10 @@ class TestBigchainApi(object):
with pytest.raises(CyclicBlockchainError):
b.vote(block1.id, block1.id, True)
@pytest.mark.genesis
def test_has_previous_vote_when_already_voted(self, b, monkeypatch):
from bigchaindb.models import Transaction
b.create_genesis_block()
tx = Transaction.create([b.me], [([b.me], 1)])
tx = tx.sign([b.me_private])
@ -91,13 +89,12 @@ class TestBigchainApi(object):
assert b.has_previous_vote(block.id, block.voters) is True
@pytest.mark.genesis
def test_get_spent_with_double_spend(self, b, monkeypatch):
from bigchaindb.common.exceptions import DoubleSpend
from bigchaindb.common.transaction import AssetLink
from bigchaindb.models import Transaction
b.create_genesis_block()
tx = Transaction.create([b.me], [([b.me], 1)])
tx = tx.sign([b.me_private])
@ -128,12 +125,11 @@ class TestBigchainApi(object):
with pytest.raises(DoubleSpend):
b.get_spent(tx.id, 0)
@pytest.mark.genesis
def test_get_block_status_for_tx_with_double_spend(self, b, monkeypatch):
from bigchaindb.common.exceptions import DoubleSpend
from bigchaindb.models import Transaction
b.create_genesis_block()
tx = Transaction.create([b.me], [([b.me], 1)])
tx = tx.sign([b.me_private])
@ -154,11 +150,10 @@ class TestBigchainApi(object):
with pytest.raises(DoubleSpend):
b.get_blocks_status_containing_tx(tx.id)
@pytest.mark.genesis
def test_get_transaction_in_invalid_and_valid_block(self, monkeypatch, b):
from bigchaindb.models import Transaction
b.create_genesis_block()
monkeypatch.setattr('time.time', lambda: 1)
tx1 = Transaction.create([b.me], [([b.me], 1)],
metadata={'msg': random.random()})
@ -291,11 +286,10 @@ class TestBigchainApi(object):
assert block['block']['transactions'][0]['operation'] == 'GENESIS'
assert block['block']['transactions'][0]['fulfillments'][0]['input'] is None
@pytest.mark.genesis
def test_create_genesis_block_fails_if_table_not_empty(self, b):
from bigchaindb.common.exceptions import GenesisBlockAlreadyExistsError
b.create_genesis_block()
with pytest.raises(GenesisBlockAlreadyExistsError):
b.create_genesis_block()
@ -354,21 +348,22 @@ class TestBigchainApi(object):
block, status = b.get_block(new_block.id, include_status=True)
assert status == b.BLOCK_UNDECIDED
@pytest.mark.genesis
def test_get_last_voted_block_returns_genesis_if_no_votes_has_been_casted(self, b):
from bigchaindb.models import Block
from bigchaindb.backend import query
b.create_genesis_block()
genesis = query.get_genesis_block(b.connection)
genesis = Block.from_dict(genesis)
gb = b.get_last_voted_block()
assert gb == genesis
assert b.validate_block(gb) == gb
def test_get_last_voted_block_returns_the_correct_block_same_timestamp(self, b, monkeypatch):
genesis = b.create_genesis_block()
assert b.get_last_voted_block() == genesis
def test_get_last_voted_block_returns_the_correct_block_same_timestamp(self,
b,
monkeypatch,
genesis_block):
assert b.get_last_voted_block() == genesis_block
monkeypatch.setattr('time.time', lambda: 1)
block_1 = dummy_block()
@ -392,10 +387,11 @@ class TestBigchainApi(object):
b.write_vote(b.vote(block_3.id, b.get_last_voted_block().id, True))
assert b.get_last_voted_block().id == block_3.id
def test_get_last_voted_block_returns_the_correct_block_different_timestamps(self, b, monkeypatch):
genesis = b.create_genesis_block()
assert b.get_last_voted_block() == genesis
def test_get_last_voted_block_returns_the_correct_block_different_timestamps(self,
b,
monkeypatch,
genesis_block):
assert b.get_last_voted_block() == genesis_block
monkeypatch.setattr('time.time', lambda: 1)
block_1 = dummy_block()
@ -421,28 +417,27 @@ class TestBigchainApi(object):
b.write_vote(b.vote(block_3.id, b.get_last_voted_block().id, True))
assert b.get_last_voted_block().id == block_3.id
def test_no_vote_written_if_block_already_has_vote(self, b):
def test_no_vote_written_if_block_already_has_vote(self, b, genesis_block):
from bigchaindb.models import Block
genesis = b.create_genesis_block()
block_1 = dummy_block()
b.write_block(block_1)
b.write_vote(b.vote(block_1.id, genesis.id, True))
b.write_vote(b.vote(block_1.id, genesis_block.id, True))
retrieved_block_1 = b.get_block(block_1.id)
retrieved_block_1 = Block.from_dict(retrieved_block_1)
# try to vote again on the retrieved block, should do nothing
b.write_vote(b.vote(retrieved_block_1.id, genesis.id, True))
b.write_vote(b.vote(retrieved_block_1.id, genesis_block.id, True))
retrieved_block_2 = b.get_block(block_1.id)
retrieved_block_2 = Block.from_dict(retrieved_block_2)
assert retrieved_block_1 == retrieved_block_2
@pytest.mark.genesis
def test_more_votes_than_voters(self, b):
from bigchaindb.common.exceptions import MultipleVotesError
b.create_genesis_block()
block_1 = dummy_block()
b.write_block(block_1)
# insert duplicate votes
@ -457,15 +452,14 @@ class TestBigchainApi(object):
assert excinfo.value.args[0] == 'Block {block_id} has {n_votes} votes cast, but only {n_voters} voters'\
.format(block_id=block_1.id, n_votes=str(2), n_voters=str(1))
def test_multiple_votes_single_node(self, b):
def test_multiple_votes_single_node(self, b, genesis_block):
from bigchaindb.common.exceptions import MultipleVotesError
genesis = b.create_genesis_block()
block_1 = dummy_block()
b.write_block(block_1)
# insert duplicate votes
for i in range(2):
b.write_vote(b.vote(block_1.id, genesis.id, True))
b.write_vote(b.vote(block_1.id, genesis_block.id, True))
with pytest.raises(MultipleVotesError) as excinfo:
b.block_election_status(block_1.id, block_1.voters)
@ -477,10 +471,10 @@ class TestBigchainApi(object):
assert excinfo.value.args[0] == 'Block {block_id} has {n_votes} votes from public key {me}'\
.format(block_id=block_1.id, n_votes=str(2), me=b.me)
@pytest.mark.genesis
def test_improper_vote_error(selfs, b):
from bigchaindb.common.exceptions import ImproperVoteError
b.create_genesis_block()
block_1 = dummy_block()
b.write_block(block_1)
vote_1 = b.vote(block_1.id, b.get_last_voted_block().id, True)
@ -925,12 +919,12 @@ class TestMultipleInputs(object):
def test_get_owned_ids_single_tx_single_output_invalid_block(self, b,
user_sk,
user_pk):
user_pk,
genesis_block):
from bigchaindb.common import crypto
from bigchaindb.common.transaction import AssetLink, TransactionLink
from bigchaindb.models import Transaction
genesis = b.create_genesis_block()
user2_sk, user2_pk = crypto.generate_key_pair()
tx = Transaction.create([b.me], [([user_pk], 1)])
@ -939,7 +933,7 @@ class TestMultipleInputs(object):
b.write_block(block)
# vote the block VALID
vote = b.vote(block.id, genesis.id, True)
vote = b.vote(block.id, genesis_block.id, True)
b.write_vote(vote)
owned_inputs_user1 = b.get_owned_ids(user_pk)
@ -1068,13 +1062,14 @@ class TestMultipleInputs(object):
spent_inputs_user1 = b.get_spent(input_txid, input_cid)
assert spent_inputs_user1 == tx
def test_get_spent_single_tx_single_output_invalid_block(self, b, user_sk, user_pk):
def test_get_spent_single_tx_single_output_invalid_block(self, b,
user_sk,
user_pk,
genesis_block):
from bigchaindb.common import crypto
from bigchaindb.common.transaction import AssetLink
from bigchaindb.models import Transaction
genesis = b.create_genesis_block()
# create a new users
user2_sk, user2_pk = crypto.generate_key_pair()
@ -1084,7 +1079,7 @@ class TestMultipleInputs(object):
b.write_block(block)
# vote the block VALID
vote = b.vote(block.id, genesis.id, True)
vote = b.vote(block.id, genesis_block.id, True)
b.write_vote(vote)
owned_inputs_user1 = b.get_owned_ids(user_pk).pop()

View File

@ -3,8 +3,7 @@ from bigchaindb.pipelines import block, election, vote, stale
@pytest.fixture
def processes(b):
b.create_genesis_block()
def processes(genesis_block):
block_maker = block.start()
voter = vote.start()
election_runner = election.start()

View File

@ -62,11 +62,10 @@ def test_vote_creation_invalid(b):
vote['signature']) is True
@pytest.mark.bdb
@pytest.mark.genesis
def test_vote_ungroup_returns_a_set_of_results(b):
from bigchaindb.pipelines import vote
b.create_genesis_block()
block = dummy_block(b)
vote_obj = vote.Vote()
txs = list(vote_obj.ungroup(block.id, block.transactions))
@ -74,11 +73,10 @@ def test_vote_ungroup_returns_a_set_of_results(b):
assert len(txs) == 10
@pytest.mark.bdb
@pytest.mark.genesis
def test_vote_validate_block(b):
from bigchaindb.pipelines import vote
b.create_genesis_block()
tx = dummy_tx(b)
block = b.create_block([tx])
@ -99,11 +97,10 @@ def test_vote_validate_block(b):
assert tx1 == tx2
@pytest.mark.bdb
@pytest.mark.genesis
def test_validate_block_with_invalid_id(b):
from bigchaindb.pipelines import vote
b.create_genesis_block()
tx = dummy_tx(b)
block = b.create_block([tx]).to_dict()
block['id'] = 'an invalid id'
@ -114,11 +111,10 @@ def test_validate_block_with_invalid_id(b):
assert invalid_dummy_tx == [vote_obj.invalid_dummy_tx]
@pytest.mark.bdb
@pytest.mark.genesis
def test_validate_block_with_invalid_signature(b):
from bigchaindb.pipelines import vote
b.create_genesis_block()
tx = dummy_tx(b)
block = b.create_block([tx]).to_dict()
block['signature'] = 'an invalid signature'
@ -129,12 +125,11 @@ def test_validate_block_with_invalid_signature(b):
assert invalid_dummy_tx == [vote_obj.invalid_dummy_tx]
@pytest.mark.bdb
@pytest.mark.genesis
def test_vote_validate_transaction(b):
from bigchaindb.pipelines import vote
from bigchaindb.models import Transaction
b.create_genesis_block()
tx = dummy_tx(b)
vote_obj = vote.Vote()
validation = vote_obj.validate_tx(tx, 123, 1)
@ -146,11 +141,10 @@ def test_vote_validate_transaction(b):
assert validation == (False, 456, 10)
@pytest.mark.bdb
@pytest.mark.genesis
def test_vote_accumulates_transactions(b):
from bigchaindb.pipelines import vote
b.create_genesis_block()
vote_obj = vote.Vote()
for _ in range(10):
@ -166,13 +160,12 @@ def test_vote_accumulates_transactions(b):
@pytest.mark.bdb
def test_valid_block_voting_sequential(b, monkeypatch):
def test_valid_block_voting_sequential(b, genesis_block, monkeypatch):
from bigchaindb.backend import query
from bigchaindb.common import crypto, util
from bigchaindb.pipelines import vote
monkeypatch.setattr('time.time', lambda: 1111111111)
genesis = b.create_genesis_block()
vote_obj = vote.Vote()
block = dummy_block(b)
@ -184,7 +177,7 @@ def test_valid_block_voting_sequential(b, monkeypatch):
vote_doc = vote_rs.next()
assert vote_doc['vote'] == {'voting_for_block': block.id,
'previous_block': genesis.id,
'previous_block': genesis_block.id,
'is_block_valid': True,
'invalid_reason': None,
'timestamp': '1111111111'}
@ -196,7 +189,7 @@ def test_valid_block_voting_sequential(b, monkeypatch):
@pytest.mark.bdb
def test_valid_block_voting_multiprocessing(b, monkeypatch):
def test_valid_block_voting_multiprocessing(b, genesis_block, monkeypatch):
from bigchaindb.backend import query
from bigchaindb.common import crypto, util
from bigchaindb.pipelines import vote
@ -205,7 +198,6 @@ def test_valid_block_voting_multiprocessing(b, monkeypatch):
outpipe = Pipe()
monkeypatch.setattr('time.time', lambda: 1111111111)
genesis = b.create_genesis_block()
vote_pipeline = vote.create_pipeline()
vote_pipeline.setup(indata=inpipe, outdata=outpipe)
@ -220,7 +212,7 @@ def test_valid_block_voting_multiprocessing(b, monkeypatch):
vote_doc = vote_rs.next()
assert vote_out['vote'] == vote_doc['vote']
assert vote_doc['vote'] == {'voting_for_block': block.id,
'previous_block': genesis.id,
'previous_block': genesis_block.id,
'is_block_valid': True,
'invalid_reason': None,
'timestamp': '1111111111'}
@ -232,14 +224,14 @@ def test_valid_block_voting_multiprocessing(b, monkeypatch):
@pytest.mark.bdb
def test_valid_block_voting_with_create_transaction(b, monkeypatch):
def test_valid_block_voting_with_create_transaction(b,
genesis_block,
monkeypatch):
from bigchaindb.backend import query
from bigchaindb.common import crypto, util
from bigchaindb.models import Transaction
from bigchaindb.pipelines import vote
genesis = b.create_genesis_block()
# create a `CREATE` transaction
test_user_priv, test_user_pub = crypto.generate_key_pair()
tx = Transaction.create([b.me], [([test_user_pub], 1)])
@ -263,7 +255,7 @@ def test_valid_block_voting_with_create_transaction(b, monkeypatch):
vote_doc = vote_rs.next()
assert vote_out['vote'] == vote_doc['vote']
assert vote_doc['vote'] == {'voting_for_block': block.id,
'previous_block': genesis.id,
'previous_block': genesis_block.id,
'is_block_valid': True,
'invalid_reason': None,
'timestamp': '1111111111'}
@ -275,15 +267,14 @@ def test_valid_block_voting_with_create_transaction(b, monkeypatch):
@pytest.mark.bdb
def test_valid_block_voting_with_transfer_transactions(monkeypatch, b):
def test_valid_block_voting_with_transfer_transactions(monkeypatch,
b, genesis_block):
from bigchaindb.backend import query
from bigchaindb.common import crypto, util
from bigchaindb.common.transaction import AssetLink
from bigchaindb.models import Transaction
from bigchaindb.pipelines import vote
genesis = b.create_genesis_block()
# create a `CREATE` transaction
test_user_priv, test_user_pub = crypto.generate_key_pair()
tx = Transaction.create([b.me], [([test_user_pub], 1)])
@ -321,7 +312,7 @@ def test_valid_block_voting_with_transfer_transactions(monkeypatch, b):
vote_doc = vote_rs.next()
assert vote_out['vote'] == vote_doc['vote']
assert vote_doc['vote'] == {'voting_for_block': block.id,
'previous_block': genesis.id,
'previous_block': genesis_block.id,
'is_block_valid': True,
'invalid_reason': None,
'timestamp': '2222222222'}
@ -347,7 +338,7 @@ def test_valid_block_voting_with_transfer_transactions(monkeypatch, b):
@pytest.mark.bdb
def test_unsigned_tx_in_block_voting(monkeypatch, b, user_pk):
def test_unsigned_tx_in_block_voting(monkeypatch, b, user_pk, genesis_block):
from bigchaindb.backend import query
from bigchaindb.common import crypto, util
from bigchaindb.models import Transaction
@ -357,7 +348,6 @@ def test_unsigned_tx_in_block_voting(monkeypatch, b, user_pk):
outpipe = Pipe()
monkeypatch.setattr('time.time', lambda: 1111111111)
genesis = b.create_genesis_block()
vote_pipeline = vote.create_pipeline()
vote_pipeline.setup(indata=inpipe, outdata=outpipe)
@ -374,7 +364,7 @@ def test_unsigned_tx_in_block_voting(monkeypatch, b, user_pk):
vote_doc = vote_rs.next()
assert vote_out['vote'] == vote_doc['vote']
assert vote_doc['vote'] == {'voting_for_block': block.id,
'previous_block': genesis.id,
'previous_block': genesis_block.id,
'is_block_valid': False,
'invalid_reason': None,
'timestamp': '1111111111'}
@ -386,7 +376,7 @@ def test_unsigned_tx_in_block_voting(monkeypatch, b, user_pk):
@pytest.mark.bdb
def test_invalid_id_tx_in_block_voting(monkeypatch, b, user_pk):
def test_invalid_id_tx_in_block_voting(monkeypatch, b, user_pk, genesis_block):
from bigchaindb.backend import query
from bigchaindb.common import crypto, util
from bigchaindb.models import Transaction
@ -396,7 +386,6 @@ def test_invalid_id_tx_in_block_voting(monkeypatch, b, user_pk):
outpipe = Pipe()
monkeypatch.setattr('time.time', lambda: 1111111111)
genesis = b.create_genesis_block()
vote_pipeline = vote.create_pipeline()
vote_pipeline.setup(indata=inpipe, outdata=outpipe)
@ -415,7 +404,7 @@ def test_invalid_id_tx_in_block_voting(monkeypatch, b, user_pk):
vote_doc = vote_rs.next()
assert vote_out['vote'] == vote_doc['vote']
assert vote_doc['vote'] == {'voting_for_block': block['id'],
'previous_block': genesis.id,
'previous_block': genesis_block.id,
'is_block_valid': False,
'invalid_reason': None,
'timestamp': '1111111111'}
@ -427,7 +416,8 @@ def test_invalid_id_tx_in_block_voting(monkeypatch, b, user_pk):
@pytest.mark.bdb
def test_invalid_content_in_tx_in_block_voting(monkeypatch, b, user_pk):
def test_invalid_content_in_tx_in_block_voting(monkeypatch, b,
user_pk, genesis_block):
from bigchaindb.backend import query
from bigchaindb.common import crypto, util
from bigchaindb.models import Transaction
@ -437,7 +427,6 @@ def test_invalid_content_in_tx_in_block_voting(monkeypatch, b, user_pk):
outpipe = Pipe()
monkeypatch.setattr('time.time', lambda: 1111111111)
genesis = b.create_genesis_block()
vote_pipeline = vote.create_pipeline()
vote_pipeline.setup(indata=inpipe, outdata=outpipe)
@ -456,7 +445,7 @@ def test_invalid_content_in_tx_in_block_voting(monkeypatch, b, user_pk):
vote_doc = vote_rs.next()
assert vote_out['vote'] == vote_doc['vote']
assert vote_doc['vote'] == {'voting_for_block': block['id'],
'previous_block': genesis.id,
'previous_block': genesis_block.id,
'is_block_valid': False,
'invalid_reason': None,
'timestamp': '1111111111'}
@ -468,7 +457,7 @@ def test_invalid_content_in_tx_in_block_voting(monkeypatch, b, user_pk):
@pytest.mark.bdb
def test_invalid_block_voting(monkeypatch, b, user_pk):
def test_invalid_block_voting(monkeypatch, b, user_pk, genesis_block):
from bigchaindb.backend import query
from bigchaindb.common import crypto, util
from bigchaindb.pipelines import vote
@ -477,7 +466,6 @@ def test_invalid_block_voting(monkeypatch, b, user_pk):
outpipe = Pipe()
monkeypatch.setattr('time.time', lambda: 1111111111)
genesis = b.create_genesis_block()
vote_pipeline = vote.create_pipeline()
vote_pipeline.setup(indata=inpipe, outdata=outpipe)
@ -493,7 +481,7 @@ def test_invalid_block_voting(monkeypatch, b, user_pk):
vote_doc = vote_rs.next()
assert vote_out['vote'] == vote_doc['vote']
assert vote_doc['vote'] == {'voting_for_block': block['id'],
'previous_block': genesis.id,
'previous_block': genesis_block.id,
'is_block_valid': False,
'invalid_reason': None,
'timestamp': '1111111111'}
@ -504,7 +492,7 @@ def test_invalid_block_voting(monkeypatch, b, user_pk):
vote_doc['signature']) is True
@pytest.mark.bdb
@pytest.mark.genesis
def test_voter_considers_unvoted_blocks_when_single_node(monkeypatch, b):
from bigchaindb.backend import query
from bigchaindb.pipelines import vote
@ -512,7 +500,6 @@ def test_voter_considers_unvoted_blocks_when_single_node(monkeypatch, b):
outpipe = Pipe()
monkeypatch.setattr('time.time', lambda: 1111111111)
b.create_genesis_block()
block_ids = []
# insert blocks in the database while the voter process is not listening
@ -553,7 +540,7 @@ def test_voter_considers_unvoted_blocks_when_single_node(monkeypatch, b):
assert all(vote['node_pubkey'] == b.me for vote in votes)
@pytest.mark.bdb
@pytest.mark.genesis
def test_voter_chains_blocks_with_the_previous_ones(monkeypatch, b):
from bigchaindb.backend import query
from bigchaindb.pipelines import vote
@ -561,7 +548,6 @@ def test_voter_chains_blocks_with_the_previous_ones(monkeypatch, b):
outpipe = Pipe()
monkeypatch.setattr('time.time', lambda: 1111111111)
b.create_genesis_block()
block_ids = []
monkeypatch.setattr('time.time', lambda: 2222222222)
@ -595,7 +581,7 @@ def test_voter_chains_blocks_with_the_previous_ones(monkeypatch, b):
{block['id'] for block in blocks})
@pytest.mark.bdb
@pytest.mark.genesis
def test_voter_checks_for_previous_vote(monkeypatch, b):
from bigchaindb.backend import query
from bigchaindb.pipelines import vote
@ -604,7 +590,6 @@ def test_voter_checks_for_previous_vote(monkeypatch, b):
outpipe = Pipe()
monkeypatch.setattr('time.time', lambda: 1111111111)
b.create_genesis_block()
monkeypatch.setattr('time.time', lambda: 2222222222)
block_1 = dummy_block(b)
@ -637,14 +622,11 @@ def test_voter_checks_for_previous_vote(monkeypatch, b):
@patch.object(Pipeline, 'start')
@pytest.mark.bdb
@pytest.mark.genesis
def test_start(mock_start, b):
# TODO: `block.start` is just a wrapper around `vote.create_pipeline`,
# that is tested by `test_full_pipeline`.
# If anyone has better ideas on how to test this, please do a PR :)
from bigchaindb.pipelines import vote
b.create_genesis_block()
vote.start()
mock_start.assert_called_with()