From 6d0af34aa2875ad4974670d3684c6989ca86d99c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Eckel?= Date: Wed, 15 Jun 2022 14:16:48 +0200 Subject: [PATCH] simplified zenroom unit test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jürgen Eckel --- tests/assets/test_zenroom_signing.py | 193 +-------------------------- 1 file changed, 2 insertions(+), 191 deletions(-) diff --git a/tests/assets/test_zenroom_signing.py b/tests/assets/test_zenroom_signing.py index 65ad81b..6af73ce 100644 --- a/tests/assets/test_zenroom_signing.py +++ b/tests/assets/test_zenroom_signing.py @@ -54,185 +54,6 @@ HOUSE_ASSETS = { metadata = {"units": 300, "type": "KG"} -def test_manual_tx_crafting_ext(): - - producer = generate_key_pair() - - producer_ed25519 = Ed25519Sha256(public_key=base58.b58decode(producer.public_key)) - condition_uri = producer_ed25519.condition.serialize_uri() - output = { - "amount": "3000", - "condition": { - "details": {"type": "ed25519-sha-256", "public_key": producer.public_key}, - "uri": condition_uri, - }, - "public_keys": [ - producer.public_key, - ], - } - input_ = { - "fulfillment": None, - "fulfills": None, - "owners_before": [ - producer.public_key, - ], - } - version = "2.0" - - prepared_token_tx = { - "operation": "CREATE", - "asset": HOUSE_ASSETS, # rfid_token, - "metadata": metadata, - "outputs": [ - output, - ], - "inputs": [ - input_, - ], - "version": version, - "id": None, - } - - print(f"prepared: {prepared_token_tx}") - - # Create sha3-256 of message to sign - message = json.dumps( - prepared_token_tx, - sort_keys=True, - separators=(",", ":"), - ensure_ascii=False, - ) - message_hash = sha3_256(message.encode()) - - producer_ed25519.sign(message_hash.digest(), base58.b58decode(producer.private_key)) - - fulfillment_uri = producer_ed25519.serialize_uri() - - prepared_token_tx["inputs"][0]["fulfillment"] = fulfillment_uri - - json_str_tx = json.dumps( - prepared_token_tx, - sort_keys=True, - separators=(",", ":"), - ensure_ascii=False, - ) - creation_txid = sha3_256(json_str_tx.encode()).hexdigest() - - prepared_token_tx["id"] = creation_txid - - print(f"signed: {prepared_token_tx}") - - from planetmint.models import Transaction - from planetmint.transactions.common.exceptions import ( - SchemaValidationError, - ValidationError, - ) - - validated = None - try: - tx_obj = Transaction.from_dict(prepared_token_tx) - except SchemaValidationError: - assert () - except ValidationError as e: - print(e) - assert () - - from planetmint.lib import Planetmint - - planet = Planetmint() - validated = planet.validate_transaction(tx_obj) - print(f"\n\nVALIDATED =====: {validated}") - assert validated == False is False - - -def test_manual_tx_crafting_ext_zenroom(): - producer = generate_key_pair() - producer_ed25519 = Ed25519Sha256(public_key=base58.b58decode(producer.public_key)) - condition_uri = producer_ed25519.condition.serialize_uri() - output = { - "amount": "3000", - "condition": { - "details": {"type": "ed25519-sha-256", "public_key": producer.public_key}, - "uri": condition_uri, - }, - "public_keys": [ - producer.public_key, - ], - } - input_ = { - "fulfillment": None, - "fulfills": None, - "owners_before": [ - producer.public_key, - ], - } - version = "2.0" - prepared_token_tx = { - "operation": "CREATE", - "asset": HOUSE_ASSETS, # rfid_token, - "metadata": metadata, - "outputs": [ - output, - ], - "inputs": [ - input_, - ], - "version": version, - "id": None, - } - - print(f"prepared: {prepared_token_tx}") - - # Create sha3-256 of message to sign - message = json.dumps( - prepared_token_tx, - sort_keys=True, - separators=(",", ":"), - ensure_ascii=False, - ) - message_hash = sha3_256(message.encode()) - - producer_ed25519.sign(message_hash.digest(), base58.b58decode(producer.private_key)) - - fulfillment_uri = producer_ed25519.serialize_uri() - - prepared_token_tx["inputs"][0]["fulfillment"] = fulfillment_uri - - json_str_tx = json.dumps( - prepared_token_tx, - sort_keys=True, - separators=(",", ":"), - ensure_ascii=False, - ) - creation_txid = sha3_256(json_str_tx.encode()).hexdigest() - - prepared_token_tx["id"] = creation_txid - - print(f"signed: {prepared_token_tx}") - - from planetmint.models import Transaction - from planetmint.transactions.common.exceptions import ( - SchemaValidationError, - ValidationError, - ) - - validated = None - try: - tx_obj = Transaction.from_dict(prepared_token_tx) - except SchemaValidationError: - assert () - except ValidationError as e: - print(e) - assert () - - from planetmint.lib import Planetmint - - planet = Planetmint() - validated = planet.validate_transaction(tx_obj) - print(f"\n\nVALIDATED =====: {validated}") - assert validated == False is False - - def test_zenroom_signing(): biolabs = generate_key_pair() @@ -332,9 +153,7 @@ def test_zenroom_signing(): SchemaValidationError, ValidationError, ) - from planetmint.transactions.common.transaction_mode_types import BROADCAST_TX_ASYNC - validated = None try: tx_obj = Transaction.from_dict(message) except SchemaValidationError: @@ -343,13 +162,5 @@ def test_zenroom_signing(): print(e) assert () - from planetmint.lib import Planetmint - - planet = Planetmint() - validated = planet.validate_transaction(tx_obj) - - mode = BROADCAST_TX_ASYNC - status_code, message = planet.write_transaction(tx_obj, mode) - print(f"\n\nstatus and result : {status_code} + {message}") - print(f"VALIDATED : {validated}") - assert (validated == False) is False + print(f"VALIDATED : {tx_obj}") + assert (tx_obj == False) is False