Add more blocks in inputs fixture

This commit is contained in:
vrde 2016-07-14 15:03:16 +02:00
parent e9b4b99946
commit e0d0ab21d3
No known key found for this signature in database
GPG Key ID: 6581C7C39B3D397D
3 changed files with 22 additions and 17 deletions

View File

@ -598,9 +598,11 @@ class Bigchain(object):
.order_by(r.desc(r.row['block']['timestamp'])) \ .order_by(r.desc(r.row['block']['timestamp'])) \
.run(self.conn) .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) unvoted = filter(lambda block: not util.is_genesis_block(block), unvoted)
return unvoted return list(unvoted)
def block_election_status(self, block): def block_election_status(self, block):
"""Tally the votes on a block, and return the status: valid, invalid, or undecided.""" """Tally the votes on a block, and return the status: valid, invalid, or undecided."""

View File

@ -98,7 +98,7 @@ def cleanup_tables(request, node_config):
@pytest.fixture @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 from bigchaindb.exceptions import GenesisBlockAlreadyExistsError
# 1. create the genesis block # 1. create the genesis block
b = b or Bigchain() b = b or Bigchain()
@ -108,13 +108,13 @@ def inputs(user_vk, amount=1, b=None):
pass pass
# 2. create block with transactions for `USER` to spend # 2. create block with transactions for `USER` to spend
transactions = [] for block in range(blocks):
for i in range(amount): transactions = []
tx = b.create_transaction(b.me, user_vk, None, 'CREATE') for i in range(amount):
tx_signed = b.sign_transaction(tx, b.me_private) tx = b.create_transaction(b.me, user_vk, None, 'CREATE')
transactions.append(tx_signed) tx_signed = b.sign_transaction(tx, b.me_private)
b.write_transaction(tx_signed) transactions.append(tx_signed)
b.write_transaction(tx_signed)
block = b.create_block(transactions) block = b.create_block(transactions)
b.write_block(block, durability='hard') b.write_block(block, durability='hard')
return block

View File

@ -182,11 +182,13 @@ class TestBigchainApi(object):
def test_genesis_block(self, b): def test_genesis_block(self, b):
response = list(r.table('bigchain') response = list(r.table('bigchain')
.filter(util.is_genesis_block) .filter(util.is_genesis_block)
.run(b.conn))[0] .run(b.conn))
assert len(response['block']['transactions']) == 1 assert len(response) == 1
assert response['block']['transactions'][0]['transaction']['operation'] == 'GENESIS' block = response[0]
assert response['block']['transactions'][0]['transaction']['fulfillments'][0]['input'] is None 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): def test_create_genesis_block_fails_if_table_not_empty(self, b):
b.create_genesis_block() b.create_genesis_block()
@ -1988,6 +1990,7 @@ class TestCryptoconditions(object):
@pytest.mark.usefixtures('inputs') @pytest.mark.usefixtures('inputs')
def test_transfer_asset_with_hashlock_condition(self, b, user_vk, user_sk): 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() first_input_tx = b.get_owned_ids(user_vk).pop()
hashlock_tx = b.create_transaction(user_vk, None, first_input_tx, 'TRANSFER') 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.validate_transaction(hashlock_tx_signed) == hashlock_tx_signed
assert b.is_valid_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) b.write_transaction(hashlock_tx_signed)
@ -2018,7 +2021,7 @@ class TestCryptoconditions(object):
block = b.create_block([hashlock_tx_signed]) block = b.create_block([hashlock_tx_signed])
b.write_block(block, durability='hard') 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): def test_create_and_fulfill_asset_with_hashlock_condition(self, b, user_vk):
hashlock_tx = b.create_transaction(b.me, None, None, 'CREATE') hashlock_tx = b.create_transaction(b.me, None, None, 'CREATE')