From e32047d99954d73e92615e9d61272a8259b1f427 Mon Sep 17 00:00:00 2001 From: Lorenz Herzberger Date: Wed, 6 Apr 2022 14:20:10 +0200 Subject: [PATCH] switched asset_id for asset_ids Signed-off-by: Lorenz Herzberger --- .../generate_http_server_api_documentation.py | 4 +-- planetmint/lib.py | 6 +++- planetmint/models.py | 6 ++-- planetmint/transactions/common/transaction.py | 12 +++---- .../transactions/types/assets/transfer.py | 17 ++++++---- tests/assets/test_digital_assets.py | 2 +- tests/assets/test_divisible_assets.py | 32 +++++++++---------- tests/common/test_transaction.py | 4 +-- tests/conftest.py | 4 +-- tests/db/test_planetmint_api.py | 28 ++++++++-------- tests/tendermint/test_core.py | 4 +-- tests/tendermint/test_integration.py | 4 +-- tests/tendermint/test_lib.py | 10 +++--- tests/test_core.py | 4 +-- tests/test_parallel_validation.py | 4 +-- .../validation/test_transaction_structure.py | 8 ++--- tests/web/test_outputs.py | 4 +-- tests/web/test_transactions.py | 6 ++-- tests/web/test_websocket_server.py | 2 +- 19 files changed, 85 insertions(+), 76 deletions(-) diff --git a/docs/root/generate_http_server_api_documentation.py b/docs/root/generate_http_server_api_documentation.py index 61458ba..ccb035c 100644 --- a/docs/root/generate_http_server_api_documentation.py +++ b/docs/root/generate_http_server_api_documentation.py @@ -150,7 +150,7 @@ def main(): input_ = Input(fulfillment=tx.outputs[cid].fulfillment, fulfills=TransactionLink(txid=tx.id, output=cid), owners_before=tx.outputs[cid].public_keys) - tx_transfer = Transfer.generate([input_], [([pubkey_transfer], 1)], asset_id=tx.id, metadata={'sequence': 1}) + tx_transfer = Transfer.generate([input_], [([pubkey_transfer], 1)], asset_ids=[tx.id], metadata={'sequence': 1}) tx_transfer = tx_transfer.sign([privkey]) ctx['tx_transfer'] = pretty_json(tx_transfer.to_dict()) ctx['public_keys_transfer'] = tx_transfer.outputs[0].public_keys[0] @@ -164,7 +164,7 @@ def main(): fulfills=TransactionLink(txid=tx_transfer.id, output=cid), owners_before=tx_transfer.outputs[cid].public_keys) tx_transfer_last = Transfer.generate([input_], [([pubkey_transfer_last], 1)], - asset_id=tx.id, metadata={'sequence': 2}) + asset_ids=[tx.id], metadata={'sequence': 2}) tx_transfer_last = tx_transfer_last.sign([privkey_transfer]) ctx['tx_transfer_last'] = pretty_json(tx_transfer_last.to_dict()) ctx['tx_transfer_last_id'] = tx_transfer_last.id diff --git a/planetmint/lib.py b/planetmint/lib.py index dd8e870..bbd05bd 100644 --- a/planetmint/lib.py +++ b/planetmint/lib.py @@ -239,11 +239,15 @@ class Planetmint(object): def get_transaction(self, transaction_id): transaction = backend.query.get_transaction(self.connection, transaction_id) + # TODO: adjust assets fetching for multiasset support + # Dirty hack backend.query.get_assets needs to be implemented + # NOTE: Read up on localmongodb setup and how the connection calls are actually loaded => implementation shows NotImplementError + if transaction: asset = backend.query.get_asset(self.connection, transaction_id) metadata = backend.query.get_metadata(self.connection, [transaction_id]) if asset: - transaction['asset'] = asset + transaction['assets'] = asset if 'metadata' not in transaction: metadata = metadata[0] if metadata else None diff --git a/planetmint/models.py b/planetmint/models.py index 419cb44..a2113b7 100644 --- a/planetmint/models.py +++ b/planetmint/models.py @@ -11,7 +11,7 @@ from planetmint.transactions.common.utils import (validate_txn_obj, validate_key class Transaction(Transaction): - ASSET = 'asset' + ASSETS = 'assets' METADATA = 'metadata' DATA = 'data' @@ -49,9 +49,9 @@ class Transaction(Transaction): @classmethod def validate_schema(cls, tx_body): validate_transaction_schema(tx_body) - validate_txn_obj(cls.ASSET, tx_body[cls.ASSET], cls.DATA, validate_key) + validate_txn_obj(cls.ASSETS, tx_body[cls.ASSETS], cls.DATA, validate_key) validate_txn_obj(cls.METADATA, tx_body, cls.METADATA, validate_key) - validate_language_key(tx_body[cls.ASSET], cls.DATA) + validate_language_key(tx_body[cls.ASSETS], cls.DATA) validate_language_key(tx_body, cls.METADATA) diff --git a/planetmint/transactions/common/transaction.py b/planetmint/transactions/common/transaction.py index b046794..a0e6628 100644 --- a/planetmint/transactions/common/transaction.py +++ b/planetmint/transactions/common/transaction.py @@ -603,7 +603,7 @@ class Transaction(object): asset_ids = [] for tx in transactions: if tx.operation == tx.CREATE: - asset_ids.append(tx.assets[0]['id']) + asset_ids.append(tx.id) else: asset_ids.extend([asset['id'] for asset in tx.assets]) @@ -757,11 +757,11 @@ class Transaction(object): raise DoubleSpend('tx "{}" spends inputs twice'.format(self.id)) # validate asset id - asset_id = self.get_asset_id(input_txs) - if asset_id != self.asset['id']: - raise AssetIdMismatch(('The asset id of the input does not' - ' match the asset id of the' - ' transaction')) + # asset_id = self.get_asset_id(input_txs) + # if asset_id != self.asset['id']: + # raise AssetIdMismatch(('The asset id of the input does not' + # ' match the asset id of the' + # ' transaction')) input_amount = sum([input_condition.amount for input_condition in input_conditions]) output_amount = sum([output_condition.amount for output_condition in self.outputs]) diff --git a/planetmint/transactions/types/assets/transfer.py b/planetmint/transactions/types/assets/transfer.py index a658bc0..92ea37e 100644 --- a/planetmint/transactions/types/assets/transfer.py +++ b/planetmint/transactions/types/assets/transfer.py @@ -13,7 +13,7 @@ class Transfer(Transaction): ALLOWED_OPERATIONS = (OPERATION,) @classmethod - def validate_transfer(cls, inputs, recipients, asset_id, metadata): + def validate_transfer(cls, inputs, recipients, asset_ids, metadata): if not isinstance(inputs, list): raise TypeError('`inputs` must be a list instance') if len(inputs) == 0: @@ -32,13 +32,14 @@ class Transfer(Transaction): pub_keys, amount = recipient outputs.append(Output.generate(pub_keys, amount)) - if not isinstance(asset_id, str): - raise TypeError('`asset_id` must be a string') + if not isinstance(asset_ids, list): + raise TypeError('`asset_ids` must be a list') return (deepcopy(inputs), outputs) + # Adjust asset_id to asset_ids check references/refactor them @classmethod - def generate(cls, inputs, recipients, asset_id, metadata=None): + def generate(cls, inputs, recipients, asset_ids, metadata=None): """A simple way to generate a `TRANSFER` transaction. Note: @@ -76,5 +77,9 @@ class Transfer(Transaction): Returns: :class:`~planetmint.common.transaction.Transaction` """ - (inputs, outputs) = cls.validate_transfer(inputs, recipients, asset_id, metadata) - return cls(cls.OPERATION, {'id': asset_id}, inputs, outputs, metadata) + (inputs, outputs) = cls.validate_transfer(inputs, recipients, asset_ids, metadata) + # TODO: Clean this up + assets = [] + for asset_id in asset_ids: + assets.append({'id': asset_id}) + return cls(cls.OPERATION, assets, inputs, outputs, metadata) diff --git a/tests/assets/test_digital_assets.py b/tests/assets/test_digital_assets.py index 3a5b88b..d676c51 100644 --- a/tests/assets/test_digital_assets.py +++ b/tests/assets/test_digital_assets.py @@ -47,7 +47,7 @@ def test_get_asset_id_transfer_transaction(b, signed_create_tx, user_pk): asset_id = Transaction.get_asset_id(tx_transfer) assert asset_id == tx_transfer.asset['id'] - +# This test is not relevant anymore def test_asset_id_mismatch(alice, user_pk): from planetmint.models import Transaction from planetmint.transactions.common.exceptions import AssetIdMismatch diff --git a/tests/assets/test_divisible_assets.py b/tests/assets/test_divisible_assets.py index cd09630..885e52b 100644 --- a/tests/assets/test_divisible_assets.py +++ b/tests/assets/test_divisible_assets.py @@ -125,7 +125,7 @@ def test_single_in_single_own_single_out_single_own_transfer(alice, b, user_pk, # TRANSFER tx_transfer = Transfer.generate(tx_create.to_inputs(), [([alice.public_key], 100)], - asset_id=tx_create.id) + asset_ids=[tx_create.id]) tx_transfer_signed = tx_transfer.sign([user_sk]) b.store_bulk_transactions([tx_create_signed]) @@ -151,7 +151,7 @@ def test_single_in_single_own_multiple_out_single_own_transfer(alice, b, user_pk # TRANSFER tx_transfer = Transfer.generate(tx_create.to_inputs(), [([alice.public_key], 50), ([alice.public_key], 50)], - asset_id=tx_create.id) + asset_ids=[tx_create.id]) tx_transfer_signed = tx_transfer.sign([user_sk]) b.store_bulk_transactions([tx_create_signed]) @@ -178,7 +178,7 @@ def test_single_in_single_own_single_out_multiple_own_transfer(alice, b, user_pk # TRANSFER tx_transfer = Transfer.generate(tx_create.to_inputs(), [([alice.public_key, alice.public_key], 100)], - asset_id=tx_create.id) + asset_ids=[tx_create.id]) tx_transfer_signed = tx_transfer.sign([user_sk]) b.store_bulk_transactions([tx_create_signed]) @@ -214,7 +214,7 @@ def test_single_in_single_own_multiple_out_mix_own_transfer(alice, b, user_pk, # TRANSFER tx_transfer = Transfer.generate(tx_create.to_inputs(), [([alice.public_key], 50), ([alice.public_key, alice.public_key], 50)], - asset_id=tx_create.id) + asset_ids=[tx_create.id]) tx_transfer_signed = tx_transfer.sign([user_sk]) b.store_bulk_transactions([tx_create_signed]) @@ -251,7 +251,7 @@ def test_single_in_multiple_own_single_out_single_own_transfer(alice, b, user_pk # TRANSFER tx_transfer = Transfer.generate(tx_create.to_inputs(), [([alice.public_key], 100)], - asset_id=tx_create.id) + asset_ids=[tx_create.id]) tx_transfer_signed = tx_transfer.sign([alice.private_key, user_sk]) b.store_bulk_transactions([tx_create_signed]) @@ -284,7 +284,7 @@ def test_multiple_in_single_own_single_out_single_own_transfer(alice, b, user_pk # TRANSFER tx_transfer = Transfer.generate(tx_create.to_inputs(), [([alice.public_key], 100)], - asset_id=tx_create.id) + asset_ids=[tx_create.id]) tx_transfer_signed = tx_transfer.sign([user_sk]) b.store_bulk_transactions([tx_create_signed]) @@ -316,7 +316,7 @@ def test_multiple_in_multiple_own_single_out_single_own_transfer(alice, b, user_ # TRANSFER tx_transfer = Transfer.generate(tx_create.to_inputs(), [([alice.public_key], 100)], - asset_id=tx_create.id) + asset_ids=[tx_create.id]) tx_transfer_signed = tx_transfer.sign([alice.private_key, user_sk]) b.store_bulk_transactions([tx_create_signed]) @@ -355,7 +355,7 @@ def test_muiltiple_in_mix_own_multiple_out_single_own_transfer(alice, b, user_pk # TRANSFER tx_transfer = Transfer.generate(tx_create.to_inputs(), [([alice.public_key], 100)], - asset_id=tx_create.id) + asset_ids=[tx_create.id]) tx_transfer_signed = tx_transfer.sign([alice.private_key, user_sk]) b.store_bulk_transactions([tx_create_signed]) @@ -395,7 +395,7 @@ def test_muiltiple_in_mix_own_multiple_out_mix_own_transfer(alice, b, user_pk, # TRANSFER tx_transfer = Transfer.generate(tx_create.to_inputs(), [([alice.public_key], 50), ([alice.public_key, user_pk], 50)], - asset_id=tx_create.id) + asset_ids=[tx_create.id]) tx_transfer_signed = tx_transfer.sign([alice.private_key, user_sk]) b.store_bulk_transactions([tx_create_signed]) @@ -443,7 +443,7 @@ def test_multiple_in_different_transactions(alice, b, user_pk, user_sk): # split across two different transactions tx_transfer1 = Transfer.generate(tx_create.to_inputs([1]), [([user_pk], 50)], - asset_id=tx_create.id) + asset_ids=[tx_create.id]) tx_transfer1_signed = tx_transfer1.sign([alice.private_key]) # TRANSFER @@ -452,7 +452,7 @@ def test_multiple_in_different_transactions(alice, b, user_pk, user_sk): tx_transfer2 = Transfer.generate(tx_create.to_inputs([0]) + tx_transfer1.to_inputs([0]), [([alice.private_key], 100)], - asset_id=tx_create.id) + asset_ids=[tx_create.id]) tx_transfer2_signed = tx_transfer2.sign([user_sk]) b.store_bulk_transactions([tx_create_signed, tx_transfer1_signed]) @@ -483,7 +483,7 @@ def test_amount_error_transfer(alice, b, user_pk, user_sk): # TRANSFER # output amount less than input amount tx_transfer = Transfer.generate(tx_create.to_inputs(), [([alice.public_key], 50)], - asset_id=tx_create.id) + asset_ids=[tx_create.id]) tx_transfer_signed = tx_transfer.sign([user_sk]) with pytest.raises(AmountError): @@ -492,7 +492,7 @@ def test_amount_error_transfer(alice, b, user_pk, user_sk): # TRANSFER # output amount greater than input amount tx_transfer = Transfer.generate(tx_create.to_inputs(), [([alice.public_key], 101)], - asset_id=tx_create.id) + asset_ids=[tx_create.id]) tx_transfer_signed = tx_transfer.sign([user_sk]) with pytest.raises(AmountError): @@ -514,7 +514,7 @@ def test_threshold_same_public_key(alice, b, user_pk, user_sk): # TRANSFER tx_transfer = Transfer.generate(tx_create.to_inputs(), [([alice.public_key], 100)], - asset_id=tx_create.id) + asset_ids=[tx_create.id]) tx_transfer_signed = tx_transfer.sign([user_sk, user_sk]) b.store_bulk_transactions([tx_create_signed]) @@ -536,7 +536,7 @@ def test_sum_amount(alice, b, user_pk, user_sk): # create a transfer transaction with one output and check if the amount # is 3 tx_transfer = Transfer.generate(tx_create.to_inputs(), [([alice.public_key], 3)], - asset_id=tx_create.id) + asset_ids=[tx_create.id]) tx_transfer_signed = tx_transfer.sign([user_sk]) b.store_bulk_transactions([tx_create_signed]) @@ -560,7 +560,7 @@ def test_divide(alice, b, user_pk, user_sk): # of each output is 1 tx_transfer = Transfer.generate(tx_create.to_inputs(), [([alice.public_key], 1), ([alice.public_key], 1), ([alice.public_key], 1)], - asset_id=tx_create.id) + asset_ids=[tx_create.id]) tx_transfer_signed = tx_transfer.sign([user_sk]) b.store_bulk_transactions([tx_create_signed]) diff --git a/tests/common/test_transaction.py b/tests/common/test_transaction.py index 59588b0..46ee05b 100644 --- a/tests/common/test_transaction.py +++ b/tests/common/test_transaction.py @@ -856,7 +856,7 @@ def test_create_transfer_transaction_single_io(tx, user_pub, user2_pub, } inputs = tx.to_inputs([0]) transfer_tx = Transfer.generate(inputs, [([user2_pub], 1)], - asset_id=tx.id) + asset_ids=[tx.id]) transfer_tx = transfer_tx.sign([user_priv]) transfer_tx = transfer_tx.to_dict() @@ -920,7 +920,7 @@ def test_create_transfer_transaction_multiple_io(user_pub, user_priv, transfer_tx = Transfer.generate(tx.to_inputs(), [([user2_pub], 1), ([user2_pub], 1)], - asset_id=tx.id) + asset_ids=[tx.id]) transfer_tx = transfer_tx.sign([user_priv, user2_priv]) assert len(transfer_tx.inputs) == 2 diff --git a/tests/conftest.py b/tests/conftest.py index 4979d27..69188e7 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -306,7 +306,7 @@ def posted_create_tx(b, signed_create_tx): def signed_transfer_tx(signed_create_tx, user_pk, user_sk): from planetmint.transactions.types.assets.transfer import Transfer inputs = signed_create_tx.to_inputs() - tx = Transfer.generate(inputs, [([user_pk], 1)], asset_id=signed_create_tx.id) + tx = Transfer.generate(inputs, [([user_pk], 1)], asset_ids=[signed_create_tx.id]) return tx.sign([user_sk]) @@ -315,7 +315,7 @@ def double_spend_tx(signed_create_tx, carol_pubkey, user_sk): from planetmint.transactions.types.assets.transfer import Transfer inputs = signed_create_tx.to_inputs() tx = Transfer.generate( - inputs, [([carol_pubkey], 1)], asset_id=signed_create_tx.id) + inputs, [([carol_pubkey], 1)], asset_ids=[signed_create_tx.id]) return tx.sign([user_sk]) diff --git a/tests/db/test_planetmint_api.py b/tests/db/test_planetmint_api.py index d41b539..019ce77 100644 --- a/tests/db/test_planetmint_api.py +++ b/tests/db/test_planetmint_api.py @@ -25,10 +25,10 @@ class TestBigchainApi(object): b.store_bulk_transactions([tx]) transfer_tx = Transfer.generate(tx.to_inputs(), [([alice.public_key], 1)], - asset_id=tx.id) + asset_ids=[tx.id]) transfer_tx = transfer_tx.sign([alice.private_key]) transfer_tx2 = Transfer.generate(tx.to_inputs(), [([alice.public_key], 2)], - asset_id=tx.id) + asset_ids=[tx.id]) transfer_tx2 = transfer_tx2.sign([alice.private_key]) with pytest.raises(DoubleSpend): @@ -88,7 +88,7 @@ class TestBigchainApi(object): [user_pk], TransactionLink('somethingsomething', 0)) tx = Transfer.generate([input], [([user_pk], 1)], - asset_id='mock_asset_link') + asset_ids=['mock_asset_link']) with pytest.raises(InputDoesNotExist): tx.validate(b) @@ -160,7 +160,7 @@ class TestMultipleInputs(object): input_tx = b.get_transaction(tx_link.txid) inputs = input_tx.to_inputs() tx = Transfer.generate(inputs, [([user2_pk], 1)], - asset_id=input_tx.id) + asset_ids=[input_tx.id]) tx = tx.sign([user_sk]) # validate transaction @@ -181,7 +181,7 @@ class TestMultipleInputs(object): input_tx = b.get_transaction(tx_link.txid) tx = Transfer.generate(input_tx.to_inputs(), [([user2_pk, user3_pk], 1)], - asset_id=input_tx.id) + asset_ids=[input_tx.id]) tx = tx.sign([user_sk]) tx.validate(b) @@ -207,7 +207,7 @@ class TestMultipleInputs(object): inputs = input_tx.to_inputs() transfer_tx = Transfer.generate(inputs, [([user3_pk], 1)], - asset_id=input_tx.id) + asset_ids=[input_tx.id]) transfer_tx = transfer_tx.sign([user_sk, user2_sk]) # validate transaction @@ -236,7 +236,7 @@ class TestMultipleInputs(object): tx = Transfer.generate(tx_input.to_inputs(), [([user3_pk, user4_pk], 1)], - asset_id=tx_input.id) + asset_ids=[tx_input.id]) tx = tx.sign([user_sk, user2_sk]) tx.validate(b) @@ -259,7 +259,7 @@ class TestMultipleInputs(object): assert owned_inputs_user2 == [] tx_transfer = Transfer.generate(tx.to_inputs(), [([user2_pk], 1)], - asset_id=tx.id) + asset_ids=[tx.id]) tx_transfer = tx_transfer.sign([user_sk]) b.store_bulk_transactions([tx_transfer]) @@ -293,7 +293,7 @@ class TestMultipleInputs(object): # transfer divisible asset divided in two outputs tx_transfer = Transfer.generate(tx_create.to_inputs(), [([user2_pk], 1), ([user2_pk], 1)], - asset_id=tx_create.id) + asset_ids=[tx_create.id]) tx_transfer_signed = tx_transfer.sign([user_sk]) b.store_bulk_transactions([tx_transfer_signed]) @@ -323,7 +323,7 @@ class TestMultipleInputs(object): assert owned_inputs_user1 == expected_owned_inputs_user1 tx = Transfer.generate(tx.to_inputs(), [([user3_pk], 1)], - asset_id=tx.id) + asset_ids=[tx.id]) tx = tx.sign([user_sk, user2_sk]) b.store_bulk_transactions([tx]) @@ -352,7 +352,7 @@ class TestMultipleInputs(object): # create a transaction and send it tx = Transfer.generate(tx.to_inputs(), [([user2_pk], 1)], - asset_id=tx.id) + asset_ids=[tx.id]) tx = tx.sign([user_sk]) b.store_bulk_transactions([tx]) @@ -382,7 +382,7 @@ class TestMultipleInputs(object): # transfer the first 2 inputs tx_transfer = Transfer.generate(tx_create.to_inputs()[:2], [([user2_pk], 1), ([user2_pk], 1)], - asset_id=tx_create.id) + asset_ids=[tx_create.id]) tx_transfer_signed = tx_transfer.sign([user_sk]) b.store_bulk_transactions([tx_transfer_signed]) @@ -419,7 +419,7 @@ class TestMultipleInputs(object): # create a transaction tx = Transfer.generate(transactions[0].to_inputs(), [([user3_pk], 1)], - asset_id=transactions[0].id) + asset_ids=[transactions[0].id]) tx = tx.sign([user_sk, user2_sk]) b.store_bulk_transactions([tx]) @@ -494,7 +494,7 @@ def test_cant_spend_same_input_twice_in_tx(b, alice): # Create a transfer transaction with duplicated fulfillments dup_inputs = tx_create.to_inputs() + tx_create.to_inputs() tx_transfer = Transfer.generate(dup_inputs, [([alice.public_key], 200)], - asset_id=tx_create.id) + asset_ids=[tx_create.id]) tx_transfer_signed = tx_transfer.sign([alice.private_key]) with pytest.raises(DoubleSpend): tx_transfer_signed.validate(b) diff --git a/tests/tendermint/test_core.py b/tests/tendermint/test_core.py index e44c9cf..a8ed299 100644 --- a/tests/tendermint/test_core.py +++ b/tests/tendermint/test_core.py @@ -326,7 +326,7 @@ def test_deliver_transfer_tx__double_spend_fails(b, init_chain_request): tx_transfer = Transfer.generate(tx.to_inputs(), [([bob.public_key], 1)], - asset_id=tx.id)\ + asset_ids=[tx.id])\ .sign([alice.private_key]) result = app.deliver_tx(encode_tx_to_bytes(tx_transfer)) @@ -334,7 +334,7 @@ def test_deliver_transfer_tx__double_spend_fails(b, init_chain_request): double_spend = Transfer.generate(tx.to_inputs(), [([carly.public_key], 1)], - asset_id=tx.id)\ + asset_ids=[tx.id])\ .sign([alice.private_key]) result = app.deliver_tx(encode_tx_to_bytes(double_spend)) diff --git a/tests/tendermint/test_integration.py b/tests/tendermint/test_integration.py index 1b2ae02..8061997 100644 --- a/tests/tendermint/test_integration.py +++ b/tests/tendermint/test_integration.py @@ -128,7 +128,7 @@ def test_post_transaction_responses(tendermint_ws_url, b): tx_transfer = Transfer.generate(tx.to_inputs(), [([bob.public_key], 1)], - asset_id=tx.id)\ + asset_ids=[tx.id])\ .sign([alice.private_key]) code, message = b.write_transaction(tx_transfer, BROADCAST_TX_COMMIT) @@ -138,7 +138,7 @@ def test_post_transaction_responses(tendermint_ws_url, b): double_spend = Transfer.generate( tx.to_inputs(), [([carly.public_key], 1)], - asset_id=tx.id, + asset_ids=[tx.id], ).sign([alice.private_key]) for mode in (BROADCAST_TX_SYNC, BROADCAST_TX_COMMIT): code, message = b.write_transaction(double_spend, mode) diff --git a/tests/tendermint/test_lib.py b/tests/tendermint/test_lib.py index 35d621c..b56ee9d 100644 --- a/tests/tendermint/test_lib.py +++ b/tests/tendermint/test_lib.py @@ -363,17 +363,17 @@ def test_get_spent_transaction_critical_double_spend(b, alice, bob, carol): tx_transfer = Transfer.generate(tx.to_inputs(), [([bob.public_key], 1)], - asset_id=tx.id)\ + asset_ids=[tx.id])\ .sign([alice.private_key]) double_spend = Transfer.generate(tx.to_inputs(), [([carol.public_key], 1)], - asset_id=tx.id)\ + asset_ids=[tx.id])\ .sign([alice.private_key]) same_input_double_spend = Transfer.generate(tx.to_inputs() + tx.to_inputs(), [([bob.public_key], 1)], - asset_id=tx.id)\ + asset_ids=[tx.id])\ .sign([alice.private_key]) b.store_bulk_transactions([tx]) @@ -406,10 +406,10 @@ def test_validation_with_transaction_buffer(b): create_tx = Create.generate([pub_key], [([pub_key], 10)]).sign([priv_key]) transfer_tx = Transfer.generate(create_tx.to_inputs(), [([pub_key], 10)], - asset_id=create_tx.id).sign([priv_key]) + asset_ids=create_tx.id).sign([priv_key]) double_spend = Transfer.generate(create_tx.to_inputs(), [([pub_key], 10)], - asset_id=create_tx.id).sign([priv_key]) + asset_ids=create_tx.id).sign([priv_key]) assert b.is_valid_transaction(create_tx) assert b.is_valid_transaction(transfer_tx, [create_tx]) diff --git a/tests/test_core.py b/tests/test_core.py index e1dc7d2..f0fcbd5 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -326,7 +326,7 @@ def test_deliver_transfer_tx__double_spend_fails(b, init_chain_request): tx_transfer = Transfer.generate(tx.to_inputs(), [([bob.public_key], 1)], - asset_id=tx.id)\ + asset_ids=[tx.id])\ .sign([alice.private_key]) result = app.deliver_tx(encode_tx_to_bytes(tx_transfer)) @@ -334,7 +334,7 @@ def test_deliver_transfer_tx__double_spend_fails(b, init_chain_request): double_spend = Transfer.generate(tx.to_inputs(), [([carly.public_key], 1)], - asset_id=tx.id)\ + asset_ids=[tx.id])\ .sign([alice.private_key]) result = app.deliver_tx(encode_tx_to_bytes(double_spend)) diff --git a/tests/test_parallel_validation.py b/tests/test_parallel_validation.py index 29e8864..b61c7b4 100644 --- a/tests/test_parallel_validation.py +++ b/tests/test_parallel_validation.py @@ -20,7 +20,7 @@ def generate_create_and_transfer(keypair=None): transfer_tx = Transfer.generate( create_tx.to_inputs(), [([pub_key], 10)], - asset_id=create_tx.id).sign([priv_key]) + asset_ids=[create_tx.id]).sign([priv_key]) return create_tx, transfer_tx @@ -33,7 +33,7 @@ def test_validation_worker_process_multiple_transactions(b): double_spend = Transfer.generate( create_tx.to_inputs(), [([keypair.public_key], 10)], - asset_id=create_tx.id).sign([keypair.private_key]) + asset_ids=[create_tx.id]).sign([keypair.private_key]) in_queue, results_queue = mp.Queue(), mp.Queue() vw = ValidationWorker(in_queue, results_queue) diff --git a/tests/validation/test_transaction_structure.py b/tests/validation/test_transaction_structure.py index 5fcb425..d389c7e 100644 --- a/tests/validation/test_transaction_structure.py +++ b/tests/validation/test_transaction_structure.py @@ -108,12 +108,12 @@ def test_transfer_asset_schema(user_sk, signed_transfer_tx): tx = signed_transfer_tx.to_dict() validate(tx) tx['id'] = None - tx['asset']['data'] = {} + tx['assets'][0]['data'] = {} tx = Transaction.from_dict(tx).sign([user_sk]).to_dict() validate_raises(tx) tx['id'] = None - del tx['asset']['data'] - tx['asset']['id'] = 'b' * 63 + del tx['assets'][0]['data'] + tx['assets'][0]['id'] = 'b' * 63 tx = Transaction.from_dict(tx).sign([user_sk]).to_dict() validate_raises(tx) @@ -132,7 +132,7 @@ def test_create_tx_asset_type(b, create_tx, alice): def test_create_tx_no_asset_data(b, create_tx, alice): tx_body = create_tx.to_dict() - del tx_body['asset']['data'] + del tx_body['assets'][0]['data'] tx_serialized = json.dumps( tx_body, skipkeys=False, sort_keys=True, separators=(',', ':')) tx_body['id'] = sha3.sha3_256(tx_serialized.encode()).hexdigest() diff --git a/tests/web/test_outputs.py b/tests/web/test_outputs.py index 16783b8..84ee8b2 100644 --- a/tests/web/test_outputs.py +++ b/tests/web/test_outputs.py @@ -108,7 +108,7 @@ def test_get_divisble_transactions_returns_500(b, client): transfer_tx = Transfer.generate(create_tx.to_inputs(), [([alice_pub], 3), ([bob_pub], 1)], - asset_id=create_tx.id) + asset_ids=[create_tx.id]) transfer_tx.sign([alice_priv]) res = client.post(TX_ENDPOINT, data=json.dumps(transfer_tx.to_dict())) @@ -118,7 +118,7 @@ def test_get_divisble_transactions_returns_500(b, client): transfer_tx_carly = Transfer.generate([transfer_tx.to_inputs()[1]], [([carly_pub], 1)], - asset_id=create_tx.id) + asset_ids=[create_tx.id]) transfer_tx_carly.sign([bob_priv]) res = client.post(TX_ENDPOINT, data=json.dumps(transfer_tx_carly.to_dict())) diff --git a/tests/web/test_transactions.py b/tests/web/test_transactions.py index b65b440..d5c5537 100644 --- a/tests/web/test_transactions.py +++ b/tests/web/test_transactions.py @@ -306,7 +306,7 @@ def test_post_transfer_transaction_endpoint(client, user_pk, user_sk, posted_cre transfer_tx = Transfer.generate(posted_create_tx.to_inputs(), [([user_pk], 1)], - asset_id=posted_create_tx.id) + asset_ids=[posted_create_tx.id]) transfer_tx = transfer_tx.sign([user_sk]) res = client.post(TX_ENDPOINT, data=json.dumps(transfer_tx.to_dict())) @@ -323,7 +323,7 @@ def test_post_invalid_transfer_transaction_returns_400(client, user_pk, posted_c transfer_tx = Transfer.generate(posted_create_tx.to_inputs(), [([user_pk], 1)], - asset_id=posted_create_tx.id) + asset_ids=[posted_create_tx.id]) transfer_tx._hash() res = client.post(TX_ENDPOINT, data=json.dumps(transfer_tx.to_dict())) @@ -348,7 +348,7 @@ def test_post_wrong_asset_division_transfer_returns_400(b, client, user_pk): transfer_tx = Transfer.generate(create_tx.to_inputs(), [([pub_key], 20)], # 20 > 10 - asset_id=create_tx.id).sign([priv_key]) + asset_ids=[create_tx.id]).sign([priv_key]) res = client.post(TX_ENDPOINT + '?mode=commit', data=json.dumps(transfer_tx.to_dict())) expected_error_message = \ f'Invalid transaction ({AmountError.__name__}): ' + \ diff --git a/tests/web/test_websocket_server.py b/tests/web/test_websocket_server.py index 5ce2f4a..5ef4147 100644 --- a/tests/web/test_websocket_server.py +++ b/tests/web/test_websocket_server.py @@ -33,7 +33,7 @@ def test_eventify_block_works_with_any_transaction(): .sign([alice.private_key]) tx_transfer = Transfer.generate(tx.to_inputs(), [([alice.public_key], 1)], - asset_id=tx.id)\ + asset_ids=[tx.id])\ .sign([alice.private_key]) block = {'height': 1,