From 83e1e8d68df67d4d867e67bb5d2f1f45a5008cf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Eckel?= Date: Tue, 10 Jan 2023 17:37:17 +0100 Subject: [PATCH] added verification of ConditionDetails to the owner verification to avoid mixup between ConditionDetails and SubCondition fixed Object comparision issues due to object changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jürgen Eckel --- planetmint/utils.py | 4 ++-- tests/db/test_planetmint_api.py | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/planetmint/utils.py b/planetmint/utils.py index 6c94784..d62d73f 100644 --- a/planetmint/utils.py +++ b/planetmint/utils.py @@ -13,6 +13,7 @@ import setproctitle from packaging import version from planetmint.version import __tm_supported_versions__ from planetmint.tendermint_utils import key_from_base64 +from planetmint.backend.models.output import ConditionDetails from transactions.common.crypto import key_pair_from_ed25519_key @@ -120,11 +121,10 @@ def condition_details_has_owner(condition_details, owner): bool: True if the public key is found in the condition details, False otherwise """ - if condition_details.sub_conditions is not None: + if isinstance(condition_details, ConditionDetails) and condition_details.sub_conditions is not None: result = condition_details_has_owner(condition_details.sub_conditions, owner) if result: return True - elif isinstance(condition_details, list): for subcondition in condition_details: result = condition_details_has_owner(subcondition, owner) diff --git a/tests/db/test_planetmint_api.py b/tests/db/test_planetmint_api.py index 0742fd4..6d3d45a 100644 --- a/tests/db/test_planetmint_api.py +++ b/tests/db/test_planetmint_api.py @@ -164,8 +164,6 @@ class TestTransactionValidation(object): class TestMultipleInputs(object): def test_transfer_single_owner_single_input(self, b, inputs, user_pk, user_sk): user2_sk, user2_pk = crypto.generate_key_pair() - - tx_link = b.fastquery.get_outputs_by_public_key(user_pk).pop() input_tx = b.get_transaction(tx_link.txid) tx_converted = Transaction.from_dict( input_tx.to_dict(), True) @@ -204,9 +202,10 @@ class TestMultipleInputs(object): owned_input = b.fastquery.get_outputs_by_public_key(user_pk).pop() input_tx = b.get_transaction(owned_input.txid) - inputs = input_tx.to_inputs() + input_tx_converted = Transaction.from_dict( input_tx.to_dict(), True) - transfer_tx = Transfer.generate(inputs, [([user3_pk], 1)], asset_ids=[input_tx.id]) + + transfer_tx = Transfer.generate(input_tx_converted.to_inputs(), [([user3_pk], 1)], asset_ids=[input_tx.id]) transfer_tx = transfer_tx.sign([user_sk, user2_sk]) # validate transaction @@ -227,8 +226,10 @@ class TestMultipleInputs(object): # get input tx_link = b.fastquery.get_outputs_by_public_key(user_pk).pop() tx_input = b.get_transaction(tx_link.txid) + input_tx_converted = Transaction.from_dict( tx_input.to_dict(), True) - tx = Transfer.generate(tx_input.to_inputs(), [([user3_pk, user4_pk], 1)], asset_ids=[tx_input.id]) + + tx = Transfer.generate(input_tx_converted.to_inputs(), [([user3_pk, user4_pk], 1)], asset_ids=[tx_input.id]) tx = tx.sign([user_sk, user2_sk]) b.validate_transaction(tx) @@ -389,7 +390,7 @@ class TestMultipleInputs(object): b.store_bulk_transactions([tx]) # check that used inputs are marked as spent - assert b.get_spent(transactions[0].id, 0) == tx + assert b.get_spent(transactions[0].id, 0) == tx.to_dict() # check that the other remain marked as unspent for unspent in transactions[1:]: assert b.get_spent(unspent.id, 0) is None