diff --git a/bigchaindb/core.py b/bigchaindb/core.py index 0ab7dd86..79d30baa 100644 --- a/bigchaindb/core.py +++ b/bigchaindb/core.py @@ -598,9 +598,11 @@ class Bigchain(object): .order_by(r.desc(r.row['block']['timestamp'])) \ .run(self.conn) + # FIXME: I (@vrde) don't like this solution. Filtering should be done at a + # database level. Solving issue #444 can help untangling the situation unvoted = filter(lambda block: not util.is_genesis_block(block), unvoted) - return unvoted + return list(unvoted) def block_election_status(self, block): """Tally the votes on a block, and return the status: valid, invalid, or undecided.""" diff --git a/tests/db/conftest.py b/tests/db/conftest.py index 900e7918..4ae4f0c3 100644 --- a/tests/db/conftest.py +++ b/tests/db/conftest.py @@ -98,7 +98,7 @@ def cleanup_tables(request, node_config): @pytest.fixture -def inputs(user_vk, amount=1, b=None): +def inputs(user_vk, amount=4, b=None, blocks=4): from bigchaindb.exceptions import GenesisBlockAlreadyExistsError # 1. create the genesis block b = b or Bigchain() @@ -108,13 +108,13 @@ def inputs(user_vk, amount=1, b=None): pass # 2. create block with transactions for `USER` to spend - transactions = [] - for i in range(amount): - tx = b.create_transaction(b.me, user_vk, None, 'CREATE') - tx_signed = b.sign_transaction(tx, b.me_private) - transactions.append(tx_signed) - b.write_transaction(tx_signed) + for block in range(blocks): + transactions = [] + for i in range(amount): + tx = b.create_transaction(b.me, user_vk, None, 'CREATE') + tx_signed = b.sign_transaction(tx, b.me_private) + transactions.append(tx_signed) + b.write_transaction(tx_signed) - block = b.create_block(transactions) - b.write_block(block, durability='hard') - return block + block = b.create_block(transactions) + b.write_block(block, durability='hard') diff --git a/tests/db/test_bigchain_api.py b/tests/db/test_bigchain_api.py index 61d58e1e..92d36857 100644 --- a/tests/db/test_bigchain_api.py +++ b/tests/db/test_bigchain_api.py @@ -182,11 +182,13 @@ class TestBigchainApi(object): def test_genesis_block(self, b): response = list(r.table('bigchain') .filter(util.is_genesis_block) - .run(b.conn))[0] + .run(b.conn)) - assert len(response['block']['transactions']) == 1 - assert response['block']['transactions'][0]['transaction']['operation'] == 'GENESIS' - assert response['block']['transactions'][0]['transaction']['fulfillments'][0]['input'] is None + assert len(response) == 1 + block = response[0] + assert len(block['block']['transactions']) == 1 + assert block['block']['transactions'][0]['transaction']['operation'] == 'GENESIS' + assert block['block']['transactions'][0]['transaction']['fulfillments'][0]['input'] is None def test_create_genesis_block_fails_if_table_not_empty(self, b): b.create_genesis_block() @@ -1988,6 +1990,7 @@ class TestCryptoconditions(object): @pytest.mark.usefixtures('inputs') def test_transfer_asset_with_hashlock_condition(self, b, user_vk, user_sk): + owned_count = len(b.get_owned_ids(user_vk)) first_input_tx = b.get_owned_ids(user_vk).pop() hashlock_tx = b.create_transaction(user_vk, None, first_input_tx, 'TRANSFER') @@ -2010,7 +2013,7 @@ class TestCryptoconditions(object): assert b.validate_transaction(hashlock_tx_signed) == hashlock_tx_signed assert b.is_valid_transaction(hashlock_tx_signed) == hashlock_tx_signed - assert len(b.get_owned_ids(user_vk)) == 1 + assert len(b.get_owned_ids(user_vk)) == owned_count b.write_transaction(hashlock_tx_signed) @@ -2018,7 +2021,7 @@ class TestCryptoconditions(object): block = b.create_block([hashlock_tx_signed]) b.write_block(block, durability='hard') - assert len(b.get_owned_ids(user_vk)) == 0 + assert len(b.get_owned_ids(user_vk)) == owned_count - 1 def test_create_and_fulfill_asset_with_hashlock_condition(self, b, user_vk): hashlock_tx = b.create_transaction(b.me, None, None, 'CREATE')