Problem: Asset tests are disabled. (#2277)

Solution: Update the tests to work with BigchainDB 2.* and enable them back.
This commit is contained in:
Lev Berman 2018-05-15 11:19:47 +02:00 committed by Vanshdeep Singh
parent 48cabdd6b9
commit 89d665c01e
4 changed files with 89 additions and 201 deletions

View File

@ -32,12 +32,9 @@ def store_transactions(conn, signed_transactions):
@register_query(LocalMongoDBConnection)
def get_transaction(conn, transaction_id):
try:
return conn.run(
conn.collection('transactions')
.find_one({'id': transaction_id}, {'_id': 0}))
except IndexError:
pass
return conn.run(
conn.collection('transactions')
.find_one({'id': transaction_id}, {'_id': 0}))
@register_query(LocalMongoDBConnection)

View File

@ -2,34 +2,33 @@ import pytest
import random
@pytest.mark.bdb
@pytest.mark.usefixtures('inputs')
def test_asset_transfer(b, user_pk, user_sk):
pytestmark = pytest.mark.tendermint
def test_asset_transfer(b, signed_create_tx, user_pk, user_sk):
from bigchaindb.models import Transaction
tx_input = b.get_owned_ids(user_pk).pop()
tx_create = b.get_transaction(tx_input.txid)
tx_transfer = Transaction.transfer(tx_create.to_inputs(), [([user_pk], 1)],
tx_create.id)
tx_transfer = Transaction.transfer(signed_create_tx.to_inputs(), [([user_pk], 1)],
signed_create_tx.id)
tx_transfer_signed = tx_transfer.sign([user_sk])
b.store_bulk_transactions([signed_create_tx, tx_transfer])
assert tx_transfer_signed.validate(b) == tx_transfer_signed
assert tx_transfer_signed.asset['id'] == tx_create.id
assert tx_transfer_signed.asset['id'] == signed_create_tx.id
@pytest.mark.bdb
@pytest.mark.usefixtures('inputs')
def test_validate_transfer_asset_id_mismatch(b, user_pk, user_sk):
def test_validate_transfer_asset_id_mismatch(b, signed_create_tx, user_pk, user_sk):
from bigchaindb.common.exceptions import AssetIdMismatch
from bigchaindb.models import Transaction
tx_create = b.get_owned_ids(user_pk).pop()
tx_create = b.get_transaction(tx_create.txid)
tx_transfer = Transaction.transfer(tx_create.to_inputs(), [([user_pk], 1)],
tx_create.id)
tx_transfer.asset['id'] = 'aaa'
tx_transfer = Transaction.transfer(signed_create_tx.to_inputs(), [([user_pk], 1)],
signed_create_tx.id)
tx_transfer.asset['id'] = 'a' * 64
tx_transfer_signed = tx_transfer.sign([user_sk])
b.store_bulk_transactions([signed_create_tx, tx_transfer_signed])
with pytest.raises(AssetIdMismatch):
tx_transfer_signed.validate(b)
@ -38,30 +37,15 @@ def test_get_asset_id_create_transaction(b, user_pk):
from bigchaindb.models import Transaction
tx_create = Transaction.create([b.me], [([user_pk], 1)])
asset_id = Transaction.get_asset_id(tx_create)
assert asset_id == tx_create.id
assert Transaction.get_asset_id(tx_create) == tx_create.id
@pytest.mark.bdb
@pytest.mark.usefixtures('inputs')
def test_get_asset_id_transfer_transaction(b, user_pk, user_sk):
def test_get_asset_id_transfer_transaction(b, signed_create_tx, user_pk):
from bigchaindb.models import Transaction
tx_create = b.get_owned_ids(user_pk).pop()
tx_create = b.get_transaction(tx_create.txid)
# create a transfer transaction
tx_transfer = Transaction.transfer(tx_create.to_inputs(), [([user_pk], 1)],
tx_create.id)
tx_transfer_signed = tx_transfer.sign([user_sk])
# create a block
block = b.create_block([tx_transfer_signed])
b.write_block(block)
# vote the block valid
vote = b.vote(block.id, b.get_last_voted_block().id, True)
b.write_vote(vote)
tx_transfer = Transaction.transfer(signed_create_tx.to_inputs(), [([user_pk], 1)],
signed_create_tx.id)
asset_id = Transaction.get_asset_id(tx_transfer)
assert asset_id == tx_transfer.asset['id']
@ -85,4 +69,4 @@ def test_create_valid_divisible_asset(b, user_pk, user_sk):
tx = Transaction.create([user_pk], [([user_pk], 2)])
tx_signed = tx.sign([user_sk])
tx_signed.validate(b)
assert tx_signed.validate(b) == tx_signed

View File

@ -1,4 +1,8 @@
import pytest
import random
pytestmark = pytest.mark.tendermint
# CREATE divisible asset
@ -9,7 +13,7 @@ import pytest
def test_single_in_single_own_single_out_single_own_create(b, user_pk):
from bigchaindb.models import Transaction
tx = Transaction.create([b.me], [([user_pk], 100)])
tx = Transaction.create([b.me], [([user_pk], 100)], asset={'name': random.random()})
tx_signed = tx.sign([b.me_private])
assert tx_signed.validate(b) == tx_signed
@ -26,7 +30,8 @@ def test_single_in_single_own_single_out_single_own_create(b, user_pk):
def test_single_in_single_own_multiple_out_single_own_create(b, user_pk):
from bigchaindb.models import Transaction
tx = Transaction.create([b.me], [([user_pk], 50), ([user_pk], 50)])
tx = Transaction.create([b.me], [([user_pk], 50), ([user_pk], 50)],
asset={'name': random.random()})
tx_signed = tx.sign([b.me_private])
assert tx_signed.validate(b) == tx_signed
@ -44,7 +49,7 @@ def test_single_in_single_own_multiple_out_single_own_create(b, user_pk):
def test_single_in_single_own_single_out_multiple_own_create(b, user_pk):
from bigchaindb.models import Transaction
tx = Transaction.create([b.me], [([user_pk, user_pk], 100)])
tx = Transaction.create([b.me], [([user_pk, user_pk], 100)], asset={'name': random.random()})
tx_signed = tx.sign([b.me_private])
assert tx_signed.validate(b) == tx_signed
@ -67,7 +72,8 @@ def test_single_in_single_own_single_out_multiple_own_create(b, user_pk):
def test_single_in_single_own_multiple_out_mix_own_create(b, user_pk):
from bigchaindb.models import Transaction
tx = Transaction.create([b.me], [([user_pk], 50), ([user_pk, user_pk], 50)])
tx = Transaction.create([b.me], [([user_pk], 50), ([user_pk, user_pk], 50)],
asset={'name': random.random()})
tx_signed = tx.sign([b.me_private])
assert tx_signed.validate(b) == tx_signed
@ -91,7 +97,7 @@ def test_single_in_multiple_own_single_out_single_own_create(b, user_pk,
from bigchaindb.models import Transaction
from bigchaindb.common.transaction import _fulfillment_to_details
tx = Transaction.create([b.me, user_pk], [([user_pk], 100)])
tx = Transaction.create([b.me, user_pk], [([user_pk], 100)], asset={'name': random.random()})
tx_signed = tx.sign([b.me_private, user_sk])
assert tx_signed.validate(b) == tx_signed
assert len(tx_signed.outputs) == 1
@ -108,32 +114,21 @@ def test_single_in_multiple_own_single_out_single_own_create(b, user_pk,
# Single owners_before
# Single output
# Single owners_after
# TODO: I don't really need inputs. But I need the database to be setup or
# else there will be no genesis block and b.get_last_voted_block will
# fail.
# Is there a better way of doing this?
@pytest.mark.bdb
@pytest.mark.usefixtures('inputs')
def test_single_in_single_own_single_out_single_own_transfer(b, user_pk,
user_sk):
from bigchaindb.models import Transaction
# CREATE divisible asset
tx_create = Transaction.create([b.me], [([user_pk], 100)])
tx_create = Transaction.create([b.me], [([user_pk], 100)], asset={'name': random.random()})
tx_create_signed = tx_create.sign([b.me_private])
# create block
block = b.create_block([tx_create_signed])
assert block.validate(b) == block
b.write_block(block)
# vote
vote = b.vote(block.id, b.get_last_voted_block().id, True)
b.write_vote(vote)
# TRANSFER
tx_transfer = Transaction.transfer(tx_create.to_inputs(), [([b.me], 100)],
asset_id=tx_create.id)
tx_transfer_signed = tx_transfer.sign([user_sk])
b.store_bulk_transactions([tx_create_signed, tx_transfer_signed])
assert tx_transfer_signed.validate(b)
assert len(tx_transfer_signed.outputs) == 1
assert tx_transfer_signed.outputs[0].amount == 100
@ -145,22 +140,13 @@ def test_single_in_single_own_single_out_single_own_transfer(b, user_pk,
# Single owners_before
# Multiple output
# Single owners_after
@pytest.mark.bdb
@pytest.mark.usefixtures('inputs')
def test_single_in_single_own_multiple_out_single_own_transfer(b, user_pk,
user_sk):
from bigchaindb.models import Transaction
# CREATE divisible asset
tx_create = Transaction.create([b.me], [([user_pk], 100)])
tx_create = Transaction.create([b.me], [([user_pk], 100)], asset={'name': random.random()})
tx_create_signed = tx_create.sign([b.me_private])
# create block
block = b.create_block([tx_create_signed])
assert block.validate(b) == block
b.write_block(block)
# vote
vote = b.vote(block.id, b.get_last_voted_block().id, True)
b.write_vote(vote)
# TRANSFER
tx_transfer = Transaction.transfer(tx_create.to_inputs(),
@ -168,6 +154,8 @@ def test_single_in_single_own_multiple_out_single_own_transfer(b, user_pk,
asset_id=tx_create.id)
tx_transfer_signed = tx_transfer.sign([user_sk])
b.store_bulk_transactions([tx_create_signed, tx_transfer_signed])
assert tx_transfer_signed.validate(b) == tx_transfer_signed
assert len(tx_transfer_signed.outputs) == 2
assert tx_transfer_signed.outputs[0].amount == 50
@ -180,22 +168,13 @@ def test_single_in_single_own_multiple_out_single_own_transfer(b, user_pk,
# Single owners_before
# Single output
# Multiple owners_after
@pytest.mark.bdb
@pytest.mark.usefixtures('inputs')
def test_single_in_single_own_single_out_multiple_own_transfer(b, user_pk,
user_sk):
from bigchaindb.models import Transaction
# CREATE divisible asset
tx_create = Transaction.create([b.me], [([user_pk], 100)])
tx_create = Transaction.create([b.me], [([user_pk], 100)], asset={'name': random.random()})
tx_create_signed = tx_create.sign([b.me_private])
# create block
block = b.create_block([tx_create_signed])
assert block.validate(b) == block
b.write_block(block)
# vote
vote = b.vote(block.id, b.get_last_voted_block().id, True)
b.write_vote(vote)
# TRANSFER
tx_transfer = Transaction.transfer(tx_create.to_inputs(),
@ -203,6 +182,8 @@ def test_single_in_single_own_single_out_multiple_own_transfer(b, user_pk,
asset_id=tx_create.id)
tx_transfer_signed = tx_transfer.sign([user_sk])
b.store_bulk_transactions([tx_create_signed, tx_transfer_signed])
assert tx_transfer_signed.validate(b) == tx_transfer_signed
assert len(tx_transfer_signed.outputs) == 1
assert tx_transfer_signed.outputs[0].amount == 100
@ -220,22 +201,13 @@ def test_single_in_single_own_single_out_multiple_own_transfer(b, user_pk,
# Multiple outputs
# Mix: one output with a single owners_after, one output with multiple
# owners_after
@pytest.mark.bdb
@pytest.mark.usefixtures('inputs')
def test_single_in_single_own_multiple_out_mix_own_transfer(b, user_pk,
user_sk):
from bigchaindb.models import Transaction
# CREATE divisible asset
tx_create = Transaction.create([b.me], [([user_pk], 100)])
tx_create = Transaction.create([b.me], [([user_pk], 100)], asset={'name': random.random()})
tx_create_signed = tx_create.sign([b.me_private])
# create block
block = b.create_block([tx_create_signed])
assert block.validate(b) == block
b.write_block(block)
# vote
vote = b.vote(block.id, b.get_last_voted_block().id, True)
b.write_vote(vote)
# TRANSFER
tx_transfer = Transaction.transfer(tx_create.to_inputs(),
@ -243,6 +215,8 @@ def test_single_in_single_own_multiple_out_mix_own_transfer(b, user_pk,
asset_id=tx_create.id)
tx_transfer_signed = tx_transfer.sign([user_sk])
b.store_bulk_transactions([tx_create_signed, tx_transfer_signed])
assert tx_transfer_signed.validate(b) == tx_transfer_signed
assert len(tx_transfer_signed.outputs) == 2
assert tx_transfer_signed.outputs[0].amount == 50
@ -260,29 +234,23 @@ def test_single_in_single_own_multiple_out_mix_own_transfer(b, user_pk,
# Multiple owners_before
# Single output
# Single owners_after
@pytest.mark.bdb
@pytest.mark.usefixtures('inputs')
def test_single_in_multiple_own_single_out_single_own_transfer(b, user_pk,
user_sk):
from bigchaindb.models import Transaction
from bigchaindb.common.transaction import _fulfillment_to_details
# CREATE divisible asset
tx_create = Transaction.create([b.me], [([b.me, user_pk], 100)])
tx_create = Transaction.create([b.me], [([b.me, user_pk], 100)],
asset={'name': random.random()})
tx_create_signed = tx_create.sign([b.me_private])
# create block
block = b.create_block([tx_create_signed])
assert block.validate(b) == block
b.write_block(block)
# vote
vote = b.vote(block.id, b.get_last_voted_block().id, True)
b.write_vote(vote)
# TRANSFER
tx_transfer = Transaction.transfer(tx_create.to_inputs(), [([b.me], 100)],
asset_id=tx_create.id)
tx_transfer_signed = tx_transfer.sign([b.me_private, user_sk])
b.store_bulk_transactions([tx_create_signed, tx_transfer_signed])
assert tx_transfer_signed.validate(b) == tx_transfer_signed
assert len(tx_transfer_signed.outputs) == 1
assert tx_transfer_signed.outputs[0].amount == 100
@ -298,28 +266,22 @@ def test_single_in_multiple_own_single_out_single_own_transfer(b, user_pk,
# Single owners_before per input
# Single output
# Single owners_after
@pytest.mark.bdb
@pytest.mark.usefixtures('inputs')
def test_multiple_in_single_own_single_out_single_own_transfer(b, user_pk,
user_sk):
from bigchaindb.models import Transaction
# CREATE divisible asset
tx_create = Transaction.create([b.me], [([user_pk], 50), ([user_pk], 50)])
tx_create = Transaction.create([b.me], [([user_pk], 50), ([user_pk], 50)],
asset={'name': random.random()})
tx_create_signed = tx_create.sign([b.me_private])
# create block
block = b.create_block([tx_create_signed])
assert block.validate(b) == block
b.write_block(block)
# vote
vote = b.vote(block.id, b.get_last_voted_block().id, True)
b.write_vote(vote)
# TRANSFER
tx_transfer = Transaction.transfer(tx_create.to_inputs(), [([b.me], 100)],
asset_id=tx_create.id)
tx_transfer_signed = tx_transfer.sign([user_sk])
b.store_bulk_transactions([tx_create_signed, tx_transfer_signed])
assert tx_transfer_signed.validate(b)
assert len(tx_transfer_signed.outputs) == 1
assert tx_transfer_signed.outputs[0].amount == 100
@ -331,29 +293,23 @@ def test_multiple_in_single_own_single_out_single_own_transfer(b, user_pk,
# Multiple owners_before per input
# Single output
# Single owners_after
@pytest.mark.bdb
@pytest.mark.usefixtures('inputs')
def test_multiple_in_multiple_own_single_out_single_own_transfer(b, user_pk,
user_sk):
from bigchaindb.models import Transaction
from bigchaindb.common.transaction import _fulfillment_to_details
# CREATE divisible asset
tx_create = Transaction.create([b.me], [([user_pk, b.me], 50), ([user_pk, b.me], 50)])
tx_create = Transaction.create([b.me], [([user_pk, b.me], 50), ([user_pk, b.me], 50)],
asset={'name': random.random()})
tx_create_signed = tx_create.sign([b.me_private])
# create block
block = b.create_block([tx_create_signed])
assert block.validate(b) == block
b.write_block(block)
# vote
vote = b.vote(block.id, b.get_last_voted_block().id, True)
b.write_vote(vote)
# TRANSFER
tx_transfer = Transaction.transfer(tx_create.to_inputs(), [([b.me], 100)],
asset_id=tx_create.id)
tx_transfer_signed = tx_transfer.sign([b.me_private, user_sk])
b.store_bulk_transactions([tx_create_signed, tx_transfer_signed])
assert tx_transfer_signed.validate(b)
assert len(tx_transfer_signed.outputs) == 1
assert tx_transfer_signed.outputs[0].amount == 100
@ -373,29 +329,23 @@ def test_multiple_in_multiple_own_single_out_single_own_transfer(b, user_pk,
# owners_before
# Single output
# Single owners_after
@pytest.mark.bdb
@pytest.mark.usefixtures('inputs')
def test_muiltiple_in_mix_own_multiple_out_single_own_transfer(b, user_pk,
user_sk):
from bigchaindb.models import Transaction
from bigchaindb.common.transaction import _fulfillment_to_details
# CREATE divisible asset
tx_create = Transaction.create([b.me], [([user_pk], 50), ([user_pk, b.me], 50)])
tx_create = Transaction.create([b.me], [([user_pk], 50), ([user_pk, b.me], 50)],
asset={'name': random.random()})
tx_create_signed = tx_create.sign([b.me_private])
# create block
block = b.create_block([tx_create_signed])
assert block.validate(b) == block
b.write_block(block)
# vote
vote = b.vote(block.id, b.get_last_voted_block().id, True)
b.write_vote(vote)
# TRANSFER
tx_transfer = Transaction.transfer(tx_create.to_inputs(), [([b.me], 100)],
asset_id=tx_create.id)
tx_transfer_signed = tx_transfer.sign([b.me_private, user_sk])
b.store_bulk_transactions([tx_create_signed, tx_transfer_signed])
assert tx_transfer_signed.validate(b) == tx_transfer_signed
assert len(tx_transfer_signed.outputs) == 1
assert tx_transfer_signed.outputs[0].amount == 100
@ -415,23 +365,15 @@ def test_muiltiple_in_mix_own_multiple_out_single_own_transfer(b, user_pk,
# Multiple outputs
# Mix: one output with a single owners_after, one output with multiple
# owners_after
@pytest.mark.bdb
@pytest.mark.usefixtures('inputs')
def test_muiltiple_in_mix_own_multiple_out_mix_own_transfer(b, user_pk,
user_sk):
from bigchaindb.models import Transaction
from bigchaindb.common.transaction import _fulfillment_to_details
# CREATE divisible asset
tx_create = Transaction.create([b.me], [([user_pk], 50), ([user_pk, b.me], 50)])
tx_create = Transaction.create([b.me], [([user_pk], 50), ([user_pk, b.me], 50)],
asset={'name': random.random()})
tx_create_signed = tx_create.sign([b.me_private])
# create block
block = b.create_block([tx_create_signed])
assert block.validate(b) == block
b.write_block(block)
# vote
vote = b.vote(block.id, b.get_last_voted_block().id, True)
b.write_vote(vote)
# TRANSFER
tx_transfer = Transaction.transfer(tx_create.to_inputs(),
@ -439,6 +381,8 @@ def test_muiltiple_in_mix_own_multiple_out_mix_own_transfer(b, user_pk,
asset_id=tx_create.id)
tx_transfer_signed = tx_transfer.sign([b.me_private, user_sk])
b.store_bulk_transactions([tx_create_signed, tx_transfer_signed])
assert tx_transfer_signed.validate(b) == tx_transfer_signed
assert len(tx_transfer_signed.outputs) == 2
assert tx_transfer_signed.outputs[0].amount == 50
@ -463,23 +407,15 @@ def test_muiltiple_in_mix_own_multiple_out_mix_own_transfer(b, user_pk,
# Single owners_before
# Single output
# Single owners_after
@pytest.mark.bdb
@pytest.mark.usefixtures('inputs')
def test_multiple_in_different_transactions(b, user_pk, user_sk):
from bigchaindb.models import Transaction
# CREATE divisible asset
# `b` creates a divisible asset and assigns 50 shares to `b` and
# 50 shares to `user_pk`
tx_create = Transaction.create([b.me], [([user_pk], 50), ([b.me], 50)])
tx_create = Transaction.create([b.me], [([user_pk], 50), ([b.me], 50)],
asset={'name': random.random()})
tx_create_signed = tx_create.sign([b.me_private])
# create block
block = b.create_block([tx_create_signed])
assert block.validate(b) == block
b.write_block(block)
# vote
vote = b.vote(block.id, b.get_last_voted_block().id, True)
b.write_vote(vote)
# TRANSFER divisible asset
# `b` transfers its 50 shares to `user_pk`
@ -489,13 +425,6 @@ def test_multiple_in_different_transactions(b, user_pk, user_sk):
[([user_pk], 50)],
asset_id=tx_create.id)
tx_transfer1_signed = tx_transfer1.sign([b.me_private])
# create block
block = b.create_block([tx_transfer1_signed])
assert block.validate(b) == block
b.write_block(block)
# vote
vote = b.vote(block.id, b.get_last_voted_block().id, True)
b.write_vote(vote)
# TRANSFER
# `user_pk` combines two different transaction with 50 shares each and
@ -506,6 +435,8 @@ def test_multiple_in_different_transactions(b, user_pk, user_sk):
asset_id=tx_create.id)
tx_transfer2_signed = tx_transfer2.sign([user_sk])
b.store_bulk_transactions([tx_create_signed, tx_transfer1_signed, tx_transfer2_signed])
assert tx_transfer2_signed.validate(b) == tx_transfer2_signed
assert len(tx_transfer2_signed.outputs) == 1
assert tx_transfer2_signed.outputs[0].amount == 100
@ -520,28 +451,22 @@ def test_multiple_in_different_transactions(b, user_pk, user_sk):
# In a TRANSFER transaction of a divisible asset the amount being spent in the
# inputs needs to match the amount being sent in the outputs.
# In other words `amount_in_inputs - amount_in_outputs == 0`
@pytest.mark.bdb
@pytest.mark.usefixtures('inputs')
def test_amount_error_transfer(b, user_pk, user_sk):
from bigchaindb.models import Transaction
from bigchaindb.common.exceptions import AmountError
# CREATE divisible asset
tx_create = Transaction.create([b.me], [([user_pk], 100)])
tx_create = Transaction.create([b.me], [([user_pk], 100)], asset={'name': random.random()})
tx_create_signed = tx_create.sign([b.me_private])
# create block
block = b.create_block([tx_create_signed])
assert block.validate(b) == block
b.write_block(block)
# vote
vote = b.vote(block.id, b.get_last_voted_block().id, True)
b.write_vote(vote)
b.store_bulk_transactions([tx_create_signed])
# TRANSFER
# output amount less than input amount
tx_transfer = Transaction.transfer(tx_create.to_inputs(), [([b.me], 50)],
asset_id=tx_create.id)
tx_transfer_signed = tx_transfer.sign([user_sk])
with pytest.raises(AmountError):
tx_transfer_signed.validate(b)
@ -550,13 +475,11 @@ def test_amount_error_transfer(b, user_pk, user_sk):
tx_transfer = Transaction.transfer(tx_create.to_inputs(), [([b.me], 101)],
asset_id=tx_create.id)
tx_transfer_signed = tx_transfer.sign([user_sk])
with pytest.raises(AmountError):
tx_transfer_signed.validate(b)
@pytest.mark.skip(reason='Figure out how to handle this case')
@pytest.mark.bdb
@pytest.mark.usefixtures('inputs')
def test_threshold_same_public_key(b, user_pk, user_sk):
# If we try to fulfill a threshold condition where each subcondition has
# the same key get_subcondition_from_vk will always return the first
@ -568,39 +491,27 @@ def test_threshold_same_public_key(b, user_pk, user_sk):
from bigchaindb.models import Transaction
# CREATE divisible asset
tx_create = Transaction.create([b.me], [([user_pk, user_pk], 100)])
tx_create = Transaction.create([b.me], [([user_pk, user_pk], 100)],
asset={'name': random.random()})
tx_create_signed = tx_create.sign([b.me_private])
# create block
block = b.create_block([tx_create_signed])
assert block.validate(b) == block
b.write_block(block)
# vote
vote = b.vote(block.id, b.get_last_voted_block().id, True)
b.write_vote(vote)
# TRANSFER
tx_transfer = Transaction.transfer(tx_create.to_inputs(), [([b.me], 100)],
asset_id=tx_create.id)
tx_transfer_signed = tx_transfer.sign([user_sk, user_sk])
b.store_bulk_transactions([tx_create_signed, tx_transfer_signed])
assert tx_transfer_signed.validate(b) == tx_transfer_signed
@pytest.mark.bdb
@pytest.mark.usefixtures('inputs')
def test_sum_amount(b, user_pk, user_sk):
from bigchaindb.models import Transaction
# CREATE divisible asset with 3 outputs with amount 1
tx_create = Transaction.create([b.me], [([user_pk], 1), ([user_pk], 1), ([user_pk], 1)])
tx_create = Transaction.create([b.me], [([user_pk], 1), ([user_pk], 1), ([user_pk], 1)],
asset={'name': random.random()})
tx_create_signed = tx_create.sign([b.me_private])
# create block
block = b.create_block([tx_create_signed])
assert block.validate(b) == block
b.write_block(block)
# vote
vote = b.vote(block.id, b.get_last_voted_block().id, True)
b.write_vote(vote)
# create a transfer transaction with one output and check if the amount
# is 3
@ -608,26 +519,19 @@ def test_sum_amount(b, user_pk, user_sk):
asset_id=tx_create.id)
tx_transfer_signed = tx_transfer.sign([user_sk])
b.store_bulk_transactions([tx_create_signed, tx_transfer_signed])
assert tx_transfer_signed.validate(b) == tx_transfer_signed
assert len(tx_transfer_signed.outputs) == 1
assert tx_transfer_signed.outputs[0].amount == 3
@pytest.mark.bdb
@pytest.mark.usefixtures('inputs')
def test_divide(b, user_pk, user_sk):
from bigchaindb.models import Transaction
# CREATE divisible asset with 1 output with amount 3
tx_create = Transaction.create([b.me], [([user_pk], 3)])
tx_create = Transaction.create([b.me], [([user_pk], 3)], asset={'name': random.random()})
tx_create_signed = tx_create.sign([b.me_private])
# create block
block = b.create_block([tx_create_signed])
assert block.validate(b) == block
b.write_block(block)
# vote
vote = b.vote(block.id, b.get_last_voted_block().id, True)
b.write_vote(vote)
# create a transfer transaction with 3 outputs and check if the amount
# of each output is 1
@ -636,6 +540,8 @@ def test_divide(b, user_pk, user_sk):
asset_id=tx_create.id)
tx_transfer_signed = tx_transfer.sign([user_sk])
b.store_bulk_transactions([tx_create_signed, tx_transfer_signed])
assert tx_transfer_signed.validate(b) == tx_transfer_signed
assert len(tx_transfer_signed.outputs) == 3
for output in tx_transfer_signed.outputs:

View File

@ -342,7 +342,8 @@ def tb():
@pytest.fixture
def create_tx(b, user_pk):
from bigchaindb.models import Transaction
return Transaction.create([b.me], [([user_pk], 1)], asset={'name': 'xyz'})
name = f'I am created by the create_tx fixture. My random identifier is {random.random()}.'
return Transaction.create([b.me], [([user_pk], 1)], asset={'name': name})
@pytest.fixture