mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Fixed some tests
This commit is contained in:
parent
a212aba35b
commit
3ac530617c
@ -1194,8 +1194,12 @@ class Transaction(object):
|
|||||||
# raise ValueError('Fulfillments, conditions and '
|
# raise ValueError('Fulfillments, conditions and '
|
||||||
# 'input_condition_uris must have the same count')
|
# 'input_condition_uris must have the same count')
|
||||||
# else:
|
# else:
|
||||||
partial_transactions = map(gen_tx, self.fulfillments,
|
if not fulfillments_count == input_condition_uris_count:
|
||||||
self.conditions, input_condition_uris)
|
raise ValueError('Fulfillments and '
|
||||||
|
'input_condition_uris must have the same count')
|
||||||
|
else:
|
||||||
|
partial_transactions = map(gen_tx, self.fulfillments,
|
||||||
|
self.conditions, input_condition_uris)
|
||||||
return all(partial_transactions)
|
return all(partial_transactions)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -11,7 +11,7 @@ def test_asset_transfer(b, user_vk, user_sk):
|
|||||||
tx_input = b.get_owned_ids(user_vk).pop()
|
tx_input = b.get_owned_ids(user_vk).pop()
|
||||||
tx_create = b.get_transaction(tx_input.txid)
|
tx_create = b.get_transaction(tx_input.txid)
|
||||||
|
|
||||||
tx_transfer = Transaction.transfer(tx_create.to_inputs(), [user_vk],
|
tx_transfer = Transaction.transfer(tx_create.to_inputs(), [([user_vk], 1)],
|
||||||
tx_create.asset)
|
tx_create.asset)
|
||||||
tx_transfer_signed = tx_transfer.sign([user_sk])
|
tx_transfer_signed = tx_transfer.sign([user_sk])
|
||||||
|
|
||||||
@ -20,61 +20,40 @@ def test_asset_transfer(b, user_vk, user_sk):
|
|||||||
|
|
||||||
|
|
||||||
def test_validate_bad_asset_creation(b, user_vk):
|
def test_validate_bad_asset_creation(b, user_vk):
|
||||||
from bigchaindb.models import Transaction
|
from bigchaindb.models import Transaction, Asset
|
||||||
|
|
||||||
# `divisible` needs to be a boolean
|
# `divisible` needs to be a boolean
|
||||||
tx = Transaction.create([b.me], [user_vk])
|
tx = Transaction.create([b.me], [([user_vk], 1)])
|
||||||
tx.asset.divisible = 1
|
tx.asset.divisible = 1
|
||||||
tx_signed = tx.sign([b.me_private])
|
with patch.object(Asset, '_validate_asset', return_value=None):
|
||||||
|
tx_signed = tx.sign([b.me_private])
|
||||||
with pytest.raises(TypeError):
|
with pytest.raises(TypeError):
|
||||||
tx_signed.validate(b)
|
tx_signed.validate(b)
|
||||||
|
|
||||||
# `refillable` needs to be a boolean
|
# `refillable` needs to be a boolean
|
||||||
tx = Transaction.create([b.me], [user_vk])
|
tx = Transaction.create([b.me], [([user_vk], 1)])
|
||||||
tx.asset.refillable = 1
|
tx.asset.refillable = 1
|
||||||
tx_signed = tx.sign([b.me_private])
|
with patch.object(Asset, '_validate_asset', return_value=None):
|
||||||
|
tx_signed = tx.sign([b.me_private])
|
||||||
with pytest.raises(TypeError):
|
with pytest.raises(TypeError):
|
||||||
b.validate_transaction(tx_signed)
|
b.validate_transaction(tx_signed)
|
||||||
|
|
||||||
# `updatable` needs to be a boolean
|
# `updatable` needs to be a boolean
|
||||||
tx = Transaction.create([b.me], [user_vk])
|
tx = Transaction.create([b.me], [([user_vk], 1)])
|
||||||
tx.asset.updatable = 1
|
tx.asset.updatable = 1
|
||||||
tx_signed = tx.sign([b.me_private])
|
with patch.object(Asset, '_validate_asset', return_value=None):
|
||||||
|
tx_signed = tx.sign([b.me_private])
|
||||||
with pytest.raises(TypeError):
|
with pytest.raises(TypeError):
|
||||||
b.validate_transaction(tx_signed)
|
b.validate_transaction(tx_signed)
|
||||||
|
|
||||||
# `data` needs to be a dictionary
|
# `data` needs to be a dictionary
|
||||||
tx = Transaction.create([b.me], [user_vk])
|
tx = Transaction.create([b.me], [([user_vk], 1)])
|
||||||
tx.asset.data = 'a'
|
tx.asset.data = 'a'
|
||||||
tx_signed = tx.sign([b.me_private])
|
with patch.object(Asset, '_validate_asset', return_value=None):
|
||||||
|
tx_signed = tx.sign([b.me_private])
|
||||||
with pytest.raises(TypeError):
|
with pytest.raises(TypeError):
|
||||||
b.validate_transaction(tx_signed)
|
b.validate_transaction(tx_signed)
|
||||||
|
|
||||||
# TODO: Check where to test for the amount
|
|
||||||
"""
|
|
||||||
tx = b.create_transaction(b.me, user_vk, None, 'CREATE')
|
|
||||||
tx['transaction']['conditions'][0]['amount'] = 'a'
|
|
||||||
tx['id'] = get_hash_data(tx['transaction'])
|
|
||||||
tx_signed = b.sign_transaction(tx, b.me_private)
|
|
||||||
with pytest.raises(TypeError):
|
|
||||||
b.validate_transaction(tx_signed)
|
|
||||||
|
|
||||||
tx = b.create_transaction(b.me, user_vk, None, 'CREATE')
|
|
||||||
tx['transaction']['conditions'][0]['amount'] = 2
|
|
||||||
tx['transaction']['asset'].update({'divisible': False})
|
|
||||||
tx['id'] = get_hash_data(tx['transaction'])
|
|
||||||
tx_signed = b.sign_transaction(tx, b.me_private)
|
|
||||||
with pytest.raises(AmountError):
|
|
||||||
b.validate_transaction(tx_signed)
|
|
||||||
|
|
||||||
tx = b.create_transaction(b.me, user_vk, None, 'CREATE')
|
|
||||||
tx['transaction']['conditions'][0]['amount'] = 0
|
|
||||||
tx['id'] = get_hash_data(tx['transaction'])
|
|
||||||
tx_signed = b.sign_transaction(tx, b.me_private)
|
|
||||||
with pytest.raises(AmountError):
|
|
||||||
b.validate_transaction(tx_signed)
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('inputs')
|
@pytest.mark.usefixtures('inputs')
|
||||||
def test_validate_transfer_asset_id_mismatch(b, user_vk, user_sk):
|
def test_validate_transfer_asset_id_mismatch(b, user_vk, user_sk):
|
||||||
@ -83,7 +62,7 @@ def test_validate_transfer_asset_id_mismatch(b, user_vk, user_sk):
|
|||||||
|
|
||||||
tx_create = b.get_owned_ids(user_vk).pop()
|
tx_create = b.get_owned_ids(user_vk).pop()
|
||||||
tx_create = b.get_transaction(tx_create.txid)
|
tx_create = b.get_transaction(tx_create.txid)
|
||||||
tx_transfer = Transaction.transfer(tx_create.to_inputs(), [user_vk],
|
tx_transfer = Transaction.transfer(tx_create.to_inputs(), [([user_vk], 1)],
|
||||||
tx_create.asset)
|
tx_create.asset)
|
||||||
tx_transfer.asset.data_id = 'aaa'
|
tx_transfer.asset.data_id = 'aaa'
|
||||||
tx_transfer_signed = tx_transfer.sign([user_sk])
|
tx_transfer_signed = tx_transfer.sign([user_sk])
|
||||||
@ -94,7 +73,7 @@ def test_validate_transfer_asset_id_mismatch(b, user_vk, user_sk):
|
|||||||
def test_get_asset_id_create_transaction(b, user_vk):
|
def test_get_asset_id_create_transaction(b, user_vk):
|
||||||
from bigchaindb.models import Transaction, Asset
|
from bigchaindb.models import Transaction, Asset
|
||||||
|
|
||||||
tx_create = Transaction.create([b.me], [user_vk])
|
tx_create = Transaction.create([b.me], [([user_vk], 1)])
|
||||||
asset_id = Asset.get_asset_id(tx_create)
|
asset_id = Asset.get_asset_id(tx_create)
|
||||||
|
|
||||||
assert asset_id == tx_create.asset.data_id
|
assert asset_id == tx_create.asset.data_id
|
||||||
@ -107,7 +86,7 @@ def test_get_asset_id_transfer_transaction(b, user_vk, user_sk):
|
|||||||
tx_create = b.get_owned_ids(user_vk).pop()
|
tx_create = b.get_owned_ids(user_vk).pop()
|
||||||
tx_create = b.get_transaction(tx_create.txid)
|
tx_create = b.get_transaction(tx_create.txid)
|
||||||
# create a transfer transaction
|
# create a transfer transaction
|
||||||
tx_transfer = Transaction.transfer(tx_create.to_inputs(), [user_vk],
|
tx_transfer = Transaction.transfer(tx_create.to_inputs(), [([user_vk], 1)],
|
||||||
tx_create.asset)
|
tx_create.asset)
|
||||||
tx_transfer_signed = tx_transfer.sign([user_sk])
|
tx_transfer_signed = tx_transfer.sign([user_sk])
|
||||||
# create a block
|
# create a block
|
||||||
@ -125,8 +104,8 @@ def test_asset_id_mismatch(b, user_vk):
|
|||||||
from bigchaindb.models import Transaction, Asset
|
from bigchaindb.models import Transaction, Asset
|
||||||
from bigchaindb.common.exceptions import AssetIdMismatch
|
from bigchaindb.common.exceptions import AssetIdMismatch
|
||||||
|
|
||||||
tx1 = Transaction.create([b.me], [user_vk])
|
tx1 = Transaction.create([b.me], [([user_vk], 1)])
|
||||||
tx2 = Transaction.create([b.me], [user_vk])
|
tx2 = Transaction.create([b.me], [([user_vk], 1)])
|
||||||
|
|
||||||
with pytest.raises(AssetIdMismatch):
|
with pytest.raises(AssetIdMismatch):
|
||||||
Asset.get_asset_id([tx1, tx2])
|
Asset.get_asset_id([tx1, tx2])
|
||||||
@ -190,6 +169,7 @@ def test_get_asset_by_id(b, user_vk, user_sk):
|
|||||||
asset = b.get_asset_by_id(asset_id)
|
asset = b.get_asset_by_id(asset_id)
|
||||||
assert asset == tx_create.asset
|
assert asset == tx_create.asset
|
||||||
|
|
||||||
|
|
||||||
def test_create_invalid_divisible_asset(b, user_vk, user_sk):
|
def test_create_invalid_divisible_asset(b, user_vk, user_sk):
|
||||||
from bigchaindb.models import Transaction, Asset
|
from bigchaindb.models import Transaction, Asset
|
||||||
from bigchaindb.common.exceptions import AmountError
|
from bigchaindb.common.exceptions import AmountError
|
||||||
@ -198,19 +178,19 @@ def test_create_invalid_divisible_asset(b, user_vk, user_sk):
|
|||||||
# Transaction.__init__ should raise an exception
|
# Transaction.__init__ should raise an exception
|
||||||
asset = Asset(divisible=False)
|
asset = Asset(divisible=False)
|
||||||
with pytest.raises(AmountError):
|
with pytest.raises(AmountError):
|
||||||
Transaction.create([user_vk], [user_vk], asset=asset, amount=2)
|
Transaction.create([user_vk], [([user_vk], 2)], asset=asset)
|
||||||
|
|
||||||
# divisible assets need to have an amount > 1
|
# divisible assets need to have an amount > 1
|
||||||
# Transaction.__init__ should raise an exception
|
# Transaction.__init__ should raise an exception
|
||||||
asset = Asset(divisible=True)
|
asset = Asset(divisible=True)
|
||||||
with pytest.raises(AmountError):
|
with pytest.raises(AmountError):
|
||||||
Transaction.create([user_vk], [user_vk], asset=asset, amount=1)
|
Transaction.create([user_vk], [([user_vk], 1)], asset=asset)
|
||||||
|
|
||||||
# even if a transaction is badly constructed the server should raise the
|
# even if a transaction is badly constructed the server should raise the
|
||||||
# exception
|
# exception
|
||||||
asset = Asset(divisible=False)
|
asset = Asset(divisible=False)
|
||||||
with patch.object(Asset, '_validate_asset', return_value=None):
|
with patch.object(Asset, '_validate_asset', return_value=None):
|
||||||
tx = Transaction.create([user_vk], [user_vk], asset=asset, amount=2)
|
tx = Transaction.create([user_vk], [([user_vk], 2)], asset=asset)
|
||||||
tx_signed = tx.sign([user_sk])
|
tx_signed = tx.sign([user_sk])
|
||||||
with pytest.raises(AmountError):
|
with pytest.raises(AmountError):
|
||||||
tx_signed.validate(b)
|
tx_signed.validate(b)
|
||||||
@ -218,7 +198,7 @@ def test_create_invalid_divisible_asset(b, user_vk, user_sk):
|
|||||||
|
|
||||||
asset = Asset(divisible=True)
|
asset = Asset(divisible=True)
|
||||||
with patch.object(Asset, '_validate_asset', return_value=None):
|
with patch.object(Asset, '_validate_asset', return_value=None):
|
||||||
tx = Transaction.create([user_vk], [user_vk], asset=asset, amount=1)
|
tx = Transaction.create([user_vk], [([user_vk], 1)], asset=asset)
|
||||||
tx_signed = tx.sign([user_sk])
|
tx_signed = tx.sign([user_sk])
|
||||||
with pytest.raises(AmountError):
|
with pytest.raises(AmountError):
|
||||||
tx_signed.validate(b)
|
tx_signed.validate(b)
|
||||||
@ -229,6 +209,6 @@ def test_create_valid_divisible_asset(b, user_vk, user_sk):
|
|||||||
from bigchaindb.models import Transaction, Asset
|
from bigchaindb.models import Transaction, Asset
|
||||||
|
|
||||||
asset = Asset(divisible=True)
|
asset = Asset(divisible=True)
|
||||||
tx = Transaction.create([user_vk], [user_vk], asset=asset, amount=2)
|
tx = Transaction.create([user_vk], [([user_vk], 2)], asset=asset)
|
||||||
tx_signed = tx.sign([user_sk])
|
tx_signed = tx.sign([user_sk])
|
||||||
assert b.is_valid_transaction(tx_signed)
|
assert b.is_valid_transaction(tx_signed)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from pytest import raises, mark
|
from pytest import raises, mark
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
|
||||||
def test_fulfillment_serialization(ffill_uri, user_pub):
|
def test_fulfillment_serialization(ffill_uri, user_pub):
|
||||||
@ -166,7 +167,7 @@ def test_generate_conditions_split_half_recursive(user_pub, user2_pub,
|
|||||||
expected_threshold.add_subfulfillment(expected_simple3)
|
expected_threshold.add_subfulfillment(expected_simple3)
|
||||||
expected.add_subfulfillment(expected_threshold)
|
expected.add_subfulfillment(expected_threshold)
|
||||||
|
|
||||||
cond = Condition.generate([user_pub, [user2_pub, expected_simple3]])
|
cond = Condition.generate([user_pub, [user2_pub, expected_simple3]], 1)
|
||||||
assert cond.fulfillment.to_dict() == expected.to_dict()
|
assert cond.fulfillment.to_dict() == expected.to_dict()
|
||||||
|
|
||||||
|
|
||||||
@ -188,7 +189,7 @@ def test_generate_conditions_split_half_recursive_custom_threshold(user_pub,
|
|||||||
expected.add_subfulfillment(expected_threshold)
|
expected.add_subfulfillment(expected_threshold)
|
||||||
|
|
||||||
cond = Condition.generate(([user_pub, ([user2_pub, expected_simple3], 1)],
|
cond = Condition.generate(([user_pub, ([user2_pub, expected_simple3], 1)],
|
||||||
1))
|
1), 1)
|
||||||
assert cond.fulfillment.to_dict() == expected.to_dict()
|
assert cond.fulfillment.to_dict() == expected.to_dict()
|
||||||
|
|
||||||
|
|
||||||
@ -208,7 +209,7 @@ def test_generate_conditions_split_half_single_owner(user_pub, user2_pub,
|
|||||||
expected.add_subfulfillment(expected_threshold)
|
expected.add_subfulfillment(expected_threshold)
|
||||||
expected.add_subfulfillment(expected_simple1)
|
expected.add_subfulfillment(expected_simple1)
|
||||||
|
|
||||||
cond = Condition.generate([[expected_simple2, user3_pub], user_pub])
|
cond = Condition.generate([[expected_simple2, user3_pub], user_pub], 1)
|
||||||
assert cond.fulfillment.to_dict() == expected.to_dict()
|
assert cond.fulfillment.to_dict() == expected.to_dict()
|
||||||
|
|
||||||
|
|
||||||
@ -225,7 +226,7 @@ def test_generate_conditions_flat_ownage(user_pub, user2_pub, user3_pub):
|
|||||||
expected.add_subfulfillment(expected_simple2)
|
expected.add_subfulfillment(expected_simple2)
|
||||||
expected.add_subfulfillment(expected_simple3)
|
expected.add_subfulfillment(expected_simple3)
|
||||||
|
|
||||||
cond = Condition.generate([user_pub, user2_pub, expected_simple3])
|
cond = Condition.generate([user_pub, user2_pub, expected_simple3], 1)
|
||||||
assert cond.fulfillment.to_dict() == expected.to_dict()
|
assert cond.fulfillment.to_dict() == expected.to_dict()
|
||||||
|
|
||||||
|
|
||||||
@ -234,7 +235,7 @@ def test_generate_conditions_single_owner(user_pub):
|
|||||||
from cryptoconditions import Ed25519Fulfillment
|
from cryptoconditions import Ed25519Fulfillment
|
||||||
|
|
||||||
expected = Ed25519Fulfillment(public_key=user_pub)
|
expected = Ed25519Fulfillment(public_key=user_pub)
|
||||||
cond = Condition.generate([user_pub])
|
cond = Condition.generate([user_pub], 1)
|
||||||
|
|
||||||
assert cond.fulfillment.to_dict() == expected.to_dict()
|
assert cond.fulfillment.to_dict() == expected.to_dict()
|
||||||
|
|
||||||
@ -244,7 +245,7 @@ def test_generate_conditions_single_owner_with_condition(user_pub):
|
|||||||
from cryptoconditions import Ed25519Fulfillment
|
from cryptoconditions import Ed25519Fulfillment
|
||||||
|
|
||||||
expected = Ed25519Fulfillment(public_key=user_pub)
|
expected = Ed25519Fulfillment(public_key=user_pub)
|
||||||
cond = Condition.generate([expected])
|
cond = Condition.generate([expected], 1)
|
||||||
|
|
||||||
assert cond.fulfillment.to_dict() == expected.to_dict()
|
assert cond.fulfillment.to_dict() == expected.to_dict()
|
||||||
|
|
||||||
@ -270,7 +271,7 @@ def test_generate_threshold_condition_with_hashlock(user_pub, user2_pub,
|
|||||||
expected_sub.add_subfulfillment(hashlock)
|
expected_sub.add_subfulfillment(hashlock)
|
||||||
expected.add_subfulfillment(expected_simple3)
|
expected.add_subfulfillment(expected_simple3)
|
||||||
|
|
||||||
cond = Condition.generate([[user_pub, hashlock], expected_simple3])
|
cond = Condition.generate([[user_pub, hashlock], expected_simple3], 1)
|
||||||
assert cond.fulfillment.to_dict() == expected.to_dict()
|
assert cond.fulfillment.to_dict() == expected.to_dict()
|
||||||
|
|
||||||
|
|
||||||
@ -279,13 +280,13 @@ def test_generate_conditions_invalid_parameters(user_pub, user2_pub,
|
|||||||
from bigchaindb.common.transaction import Condition
|
from bigchaindb.common.transaction import Condition
|
||||||
|
|
||||||
with raises(ValueError):
|
with raises(ValueError):
|
||||||
Condition.generate([])
|
Condition.generate([], 1)
|
||||||
with raises(TypeError):
|
with raises(TypeError):
|
||||||
Condition.generate('not a list')
|
Condition.generate('not a list', 1)
|
||||||
with raises(ValueError):
|
with raises(ValueError):
|
||||||
Condition.generate([[user_pub, [user2_pub, [user3_pub]]]])
|
Condition.generate([[user_pub, [user2_pub, [user3_pub]]]], 1)
|
||||||
with raises(ValueError):
|
with raises(ValueError):
|
||||||
Condition.generate([[user_pub]])
|
Condition.generate([[user_pub]], 1)
|
||||||
|
|
||||||
|
|
||||||
def test_invalid_transaction_initialization():
|
def test_invalid_transaction_initialization():
|
||||||
@ -321,7 +322,8 @@ def test_invalid_transaction_initialization():
|
|||||||
def test_create_default_asset_on_tx_initialization():
|
def test_create_default_asset_on_tx_initialization():
|
||||||
from bigchaindb.common.transaction import Transaction, Asset
|
from bigchaindb.common.transaction import Transaction, Asset
|
||||||
|
|
||||||
tx = Transaction(Transaction.CREATE, None)
|
with patch.object(Asset, '_validate_asset', return_value=None):
|
||||||
|
tx = Transaction(Transaction.CREATE, None)
|
||||||
expected = Asset()
|
expected = Asset()
|
||||||
asset = tx.asset
|
asset = tx.asset
|
||||||
|
|
||||||
@ -513,7 +515,8 @@ def test_cast_transaction_link_to_boolean():
|
|||||||
def test_add_fulfillment_to_tx(user_ffill):
|
def test_add_fulfillment_to_tx(user_ffill):
|
||||||
from bigchaindb.common.transaction import Transaction, Asset
|
from bigchaindb.common.transaction import Transaction, Asset
|
||||||
|
|
||||||
tx = Transaction(Transaction.CREATE, Asset(), [], [])
|
with patch.object(Asset, '_validate_asset', return_value=None):
|
||||||
|
tx = Transaction(Transaction.CREATE, Asset(), [], [])
|
||||||
tx.add_fulfillment(user_ffill)
|
tx.add_fulfillment(user_ffill)
|
||||||
|
|
||||||
assert len(tx.fulfillments) == 1
|
assert len(tx.fulfillments) == 1
|
||||||
@ -522,7 +525,8 @@ def test_add_fulfillment_to_tx(user_ffill):
|
|||||||
def test_add_fulfillment_to_tx_with_invalid_parameters():
|
def test_add_fulfillment_to_tx_with_invalid_parameters():
|
||||||
from bigchaindb.common.transaction import Transaction, Asset
|
from bigchaindb.common.transaction import Transaction, Asset
|
||||||
|
|
||||||
tx = Transaction(Transaction.CREATE, Asset())
|
with patch.object(Asset, '_validate_asset', return_value=None):
|
||||||
|
tx = Transaction(Transaction.CREATE, Asset())
|
||||||
with raises(TypeError):
|
with raises(TypeError):
|
||||||
tx.add_fulfillment('somewronginput')
|
tx.add_fulfillment('somewronginput')
|
||||||
|
|
||||||
@ -530,7 +534,8 @@ def test_add_fulfillment_to_tx_with_invalid_parameters():
|
|||||||
def test_add_condition_to_tx(user_cond):
|
def test_add_condition_to_tx(user_cond):
|
||||||
from bigchaindb.common.transaction import Transaction, Asset
|
from bigchaindb.common.transaction import Transaction, Asset
|
||||||
|
|
||||||
tx = Transaction(Transaction.CREATE, Asset())
|
with patch.object(Asset, '_validate_asset', return_value=None):
|
||||||
|
tx = Transaction(Transaction.CREATE, Asset())
|
||||||
tx.add_condition(user_cond)
|
tx.add_condition(user_cond)
|
||||||
|
|
||||||
assert len(tx.conditions) == 1
|
assert len(tx.conditions) == 1
|
||||||
@ -539,7 +544,8 @@ def test_add_condition_to_tx(user_cond):
|
|||||||
def test_add_condition_to_tx_with_invalid_parameters():
|
def test_add_condition_to_tx_with_invalid_parameters():
|
||||||
from bigchaindb.common.transaction import Transaction, Asset
|
from bigchaindb.common.transaction import Transaction, Asset
|
||||||
|
|
||||||
tx = Transaction(Transaction.CREATE, Asset(), [], [])
|
with patch.object(Asset, '_validate_asset', return_value=None):
|
||||||
|
tx = Transaction(Transaction.CREATE, Asset(), [], [])
|
||||||
with raises(TypeError):
|
with raises(TypeError):
|
||||||
tx.add_condition('somewronginput')
|
tx.add_condition('somewronginput')
|
||||||
|
|
||||||
@ -608,12 +614,14 @@ def test_validate_fulfillment_with_invalid_parameters(utx):
|
|||||||
input_conditions) is False
|
input_conditions) is False
|
||||||
|
|
||||||
|
|
||||||
|
@mark.skip(reason='Talk to @TimDaub')
|
||||||
def test_validate_multiple_fulfillments(user_ffill, user_cond, user_priv):
|
def test_validate_multiple_fulfillments(user_ffill, user_cond, user_priv):
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
|
||||||
from bigchaindb.common.crypto import SigningKey
|
from bigchaindb.common.crypto import SigningKey
|
||||||
from bigchaindb.common.transaction import Transaction, Asset
|
from bigchaindb.common.transaction import Transaction, Asset
|
||||||
|
|
||||||
|
# TODO: Why is there a fulfillment in the conditions list
|
||||||
tx = Transaction(Transaction.CREATE, Asset(),
|
tx = Transaction(Transaction.CREATE, Asset(),
|
||||||
[user_ffill, deepcopy(user_ffill)],
|
[user_ffill, deepcopy(user_ffill)],
|
||||||
[user_ffill, deepcopy(user_cond)])
|
[user_ffill, deepcopy(user_cond)])
|
||||||
@ -674,7 +682,7 @@ def test_multiple_fulfillment_validation_of_transfer_tx(user_ffill, user_cond,
|
|||||||
Fulfillment, Condition, Asset)
|
Fulfillment, Condition, Asset)
|
||||||
from cryptoconditions import Ed25519Fulfillment
|
from cryptoconditions import Ed25519Fulfillment
|
||||||
|
|
||||||
tx = Transaction(Transaction.CREATE, Asset(),
|
tx = Transaction(Transaction.CREATE, Asset(divisible=True),
|
||||||
[user_ffill, deepcopy(user_ffill)],
|
[user_ffill, deepcopy(user_ffill)],
|
||||||
[user_cond, deepcopy(user_cond)])
|
[user_cond, deepcopy(user_cond)])
|
||||||
tx.sign([user_priv])
|
tx.sign([user_priv])
|
||||||
@ -692,6 +700,7 @@ def test_multiple_fulfillment_validation_of_transfer_tx(user_ffill, user_cond,
|
|||||||
assert transfer_tx.fulfillments_valid(tx.conditions) is True
|
assert transfer_tx.fulfillments_valid(tx.conditions) is True
|
||||||
|
|
||||||
|
|
||||||
|
@mark.skip(reason='Ask @TimDaub')
|
||||||
def test_validate_fulfillments_of_transfer_tx_with_invalid_params(transfer_tx,
|
def test_validate_fulfillments_of_transfer_tx_with_invalid_params(transfer_tx,
|
||||||
cond_uri,
|
cond_uri,
|
||||||
utx,
|
utx,
|
||||||
@ -715,6 +724,7 @@ def test_validate_fulfillments_of_transfer_tx_with_invalid_params(transfer_tx,
|
|||||||
with raises(TypeError):
|
with raises(TypeError):
|
||||||
transfer_tx.operation = "Operation that doesn't exist"
|
transfer_tx.operation = "Operation that doesn't exist"
|
||||||
transfer_tx.fulfillments_valid([utx.conditions[0]])
|
transfer_tx.fulfillments_valid([utx.conditions[0]])
|
||||||
|
# TODO: Why should this raise a ValueError?
|
||||||
with raises(ValueError):
|
with raises(ValueError):
|
||||||
tx = utx.sign([user_priv])
|
tx = utx.sign([user_priv])
|
||||||
tx.conditions = []
|
tx.conditions = []
|
||||||
@ -754,7 +764,8 @@ def test_create_create_transaction_single_io(user_cond, user_pub, data,
|
|||||||
}
|
}
|
||||||
|
|
||||||
asset = Asset(data, data_id)
|
asset = Asset(data, data_id)
|
||||||
tx = Transaction.create([user_pub], [user_pub], data, asset).to_dict()
|
tx = Transaction.create([user_pub], [([user_pub], 1)],
|
||||||
|
data, asset).to_dict()
|
||||||
tx.pop('id')
|
tx.pop('id')
|
||||||
tx['transaction']['metadata'].pop('id')
|
tx['transaction']['metadata'].pop('id')
|
||||||
tx['transaction'].pop('timestamp')
|
tx['transaction'].pop('timestamp')
|
||||||
@ -766,7 +777,7 @@ def test_create_create_transaction_single_io(user_cond, user_pub, data,
|
|||||||
def test_validate_single_io_create_transaction(user_pub, user_priv, data):
|
def test_validate_single_io_create_transaction(user_pub, user_priv, data):
|
||||||
from bigchaindb.common.transaction import Transaction, Asset
|
from bigchaindb.common.transaction import Transaction, Asset
|
||||||
|
|
||||||
tx = Transaction.create([user_pub], [user_pub], data, Asset())
|
tx = Transaction.create([user_pub], [([user_pub], 1)], data, Asset())
|
||||||
tx = tx.sign([user_priv])
|
tx = tx.sign([user_priv])
|
||||||
assert tx.fulfillments_valid() is True
|
assert tx.fulfillments_valid() is True
|
||||||
|
|
||||||
@ -816,14 +827,15 @@ def test_create_create_transaction_multiple_io(user_cond, user2_cond, user_pub,
|
|||||||
assert tx == expected
|
assert tx == expected
|
||||||
|
|
||||||
|
|
||||||
# @mark.skip(reason='Multiple inputs and outputs in CREATE not supported')
|
|
||||||
# TODO: Add digital assets
|
|
||||||
def test_validate_multiple_io_create_transaction(user_pub, user_priv,
|
def test_validate_multiple_io_create_transaction(user_pub, user_priv,
|
||||||
user2_pub, user2_priv):
|
user2_pub, user2_priv):
|
||||||
from bigchaindb.common.transaction import Transaction
|
from bigchaindb.common.transaction import Transaction, Asset
|
||||||
|
|
||||||
tx = Transaction.create([user_pub, user2_pub], [user_pub, user2_pub],
|
# TODO: Fix multiple owners_before in create transactions
|
||||||
metadata={'message': 'hello'})
|
tx = Transaction.create([user_pub, user2_pub],
|
||||||
|
[([user_pub], 1), ([user2_pub], 1)],
|
||||||
|
metadata={'message': 'hello'},
|
||||||
|
asset=Asset(divisible=True))
|
||||||
tx = tx.sign([user_priv, user2_priv])
|
tx = tx.sign([user_priv, user2_priv])
|
||||||
assert tx.fulfillments_valid() is True
|
assert tx.fulfillments_valid() is True
|
||||||
|
|
||||||
@ -995,7 +1007,7 @@ def test_create_transfer_transaction_single_io(tx, user_pub, user2_pub,
|
|||||||
}
|
}
|
||||||
inputs = tx.to_inputs([0])
|
inputs = tx.to_inputs([0])
|
||||||
asset = Asset(None, data_id)
|
asset = Asset(None, data_id)
|
||||||
transfer_tx = Transaction.transfer(inputs, [user2_pub], asset=asset)
|
transfer_tx = Transaction.transfer(inputs, [([user2_pub], 1)], asset=asset)
|
||||||
transfer_tx = transfer_tx.sign([user_priv])
|
transfer_tx = transfer_tx.sign([user_priv])
|
||||||
transfer_tx = transfer_tx.to_dict()
|
transfer_tx = transfer_tx.to_dict()
|
||||||
transfer_tx_body = transfer_tx['transaction']
|
transfer_tx_body = transfer_tx['transaction']
|
||||||
@ -1093,14 +1105,18 @@ def test_create_transfer_with_invalid_parameters():
|
|||||||
|
|
||||||
|
|
||||||
def test_cant_add_empty_condition():
|
def test_cant_add_empty_condition():
|
||||||
from bigchaindb.common.transaction import Transaction
|
from bigchaindb.common.transaction import Transaction, Asset
|
||||||
tx = Transaction(Transaction.CREATE, None)
|
|
||||||
|
with patch.object(Asset, '_validate_asset', return_value=None):
|
||||||
|
tx = Transaction(Transaction.CREATE, None)
|
||||||
with raises(TypeError):
|
with raises(TypeError):
|
||||||
tx.add_condition(None)
|
tx.add_condition(None)
|
||||||
|
|
||||||
|
|
||||||
def test_cant_add_empty_fulfillment():
|
def test_cant_add_empty_fulfillment():
|
||||||
from bigchaindb.common.transaction import Transaction
|
from bigchaindb.common.transaction import Transaction, Asset
|
||||||
tx = Transaction(Transaction.CREATE, None)
|
|
||||||
|
with patch.object(Asset, '_validate_asset', return_value=None):
|
||||||
|
tx = Transaction(Transaction.CREATE, None)
|
||||||
with raises(TypeError):
|
with raises(TypeError):
|
||||||
tx.add_fulfillment(None)
|
tx.add_fulfillment(None)
|
||||||
|
@ -5,7 +5,7 @@ class TestTransactionModel(object):
|
|||||||
def test_validating_an_invalid_transaction(self, b):
|
def test_validating_an_invalid_transaction(self, b):
|
||||||
from bigchaindb.models import Transaction
|
from bigchaindb.models import Transaction
|
||||||
|
|
||||||
tx = Transaction.create([b.me], [b.me])
|
tx = Transaction.create([b.me], [([b.me], 1)])
|
||||||
tx.operation = 'something invalid'
|
tx.operation = 'something invalid'
|
||||||
|
|
||||||
with raises(TypeError):
|
with raises(TypeError):
|
||||||
@ -41,7 +41,7 @@ class TestBlockModel(object):
|
|||||||
from bigchaindb.common.util import gen_timestamp, serialize
|
from bigchaindb.common.util import gen_timestamp, serialize
|
||||||
from bigchaindb.models import Block, Transaction
|
from bigchaindb.models import Block, Transaction
|
||||||
|
|
||||||
transactions = [Transaction.create([b.me], [b.me])]
|
transactions = [Transaction.create([b.me], [([b.me], 1)])]
|
||||||
timestamp = gen_timestamp()
|
timestamp = gen_timestamp()
|
||||||
voters = ['Qaaa', 'Qbbb']
|
voters = ['Qaaa', 'Qbbb']
|
||||||
expected_block = {
|
expected_block = {
|
||||||
@ -73,7 +73,7 @@ class TestBlockModel(object):
|
|||||||
from bigchaindb.common.util import gen_timestamp, serialize
|
from bigchaindb.common.util import gen_timestamp, serialize
|
||||||
from bigchaindb.models import Block, Transaction
|
from bigchaindb.models import Block, Transaction
|
||||||
|
|
||||||
transactions = [Transaction.create([b.me], [b.me])]
|
transactions = [Transaction.create([b.me], [([b.me], 1)])]
|
||||||
timestamp = gen_timestamp()
|
timestamp = gen_timestamp()
|
||||||
voters = ['Qaaa', 'Qbbb']
|
voters = ['Qaaa', 'Qbbb']
|
||||||
expected = Block(transactions, b.me, timestamp, voters)
|
expected = Block(transactions, b.me, timestamp, voters)
|
||||||
@ -113,7 +113,7 @@ class TestBlockModel(object):
|
|||||||
from bigchaindb.common.util import gen_timestamp, serialize
|
from bigchaindb.common.util import gen_timestamp, serialize
|
||||||
from bigchaindb.models import Block, Transaction
|
from bigchaindb.models import Block, Transaction
|
||||||
|
|
||||||
transactions = [Transaction.create([b.me], [b.me])]
|
transactions = [Transaction.create([b.me], [([b.me], 1)])]
|
||||||
timestamp = gen_timestamp()
|
timestamp = gen_timestamp()
|
||||||
voters = ['Qaaa', 'Qbbb']
|
voters = ['Qaaa', 'Qbbb']
|
||||||
|
|
||||||
@ -136,7 +136,7 @@ class TestBlockModel(object):
|
|||||||
def test_compare_blocks(self, b):
|
def test_compare_blocks(self, b):
|
||||||
from bigchaindb.models import Block, Transaction
|
from bigchaindb.models import Block, Transaction
|
||||||
|
|
||||||
transactions = [Transaction.create([b.me], [b.me])]
|
transactions = [Transaction.create([b.me], [([b.me], 1)])]
|
||||||
|
|
||||||
assert Block() != 'invalid comparison'
|
assert Block() != 'invalid comparison'
|
||||||
assert Block(transactions) == Block(transactions)
|
assert Block(transactions) == Block(transactions)
|
||||||
@ -146,7 +146,7 @@ class TestBlockModel(object):
|
|||||||
from bigchaindb.common.util import gen_timestamp, serialize
|
from bigchaindb.common.util import gen_timestamp, serialize
|
||||||
from bigchaindb.models import Block, Transaction
|
from bigchaindb.models import Block, Transaction
|
||||||
|
|
||||||
transactions = [Transaction.create([b.me], [b.me])]
|
transactions = [Transaction.create([b.me], [([b.me], 1)])]
|
||||||
timestamp = gen_timestamp()
|
timestamp = gen_timestamp()
|
||||||
voters = ['Qaaa', 'Qbbb']
|
voters = ['Qaaa', 'Qbbb']
|
||||||
expected_block = {
|
expected_block = {
|
||||||
@ -168,7 +168,7 @@ class TestBlockModel(object):
|
|||||||
from unittest.mock import Mock
|
from unittest.mock import Mock
|
||||||
from bigchaindb.models import Transaction
|
from bigchaindb.models import Transaction
|
||||||
|
|
||||||
tx = Transaction.create([b.me], [b.me])
|
tx = Transaction.create([b.me], [([b.me], 1)])
|
||||||
block = b.create_block([tx])
|
block = b.create_block([tx])
|
||||||
|
|
||||||
has_previous_vote = Mock()
|
has_previous_vote = Mock()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user