mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-24 06:25:45 +00:00
simplified zenroom unit test
Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
parent
ea05872927
commit
6d0af34aa2
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user