mirror of
https://github.com/planetmint/planetmint.git
synced 2025-05-30 10:46:37 +00:00

* added support for v2.0 TX * integrated transactions package deeper into the code * added test cases for v2.0 TXs * added version gateway to the push transactions API to only allow latest versions schemes to enter the APP * replaced exception catching by version-management Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
92 lines
3.5 KiB
Python
92 lines
3.5 KiB
Python
# Copyright © 2020 Interplanetary Database Association e.V.,
|
|
# Planetmint and IPDB software contributors.
|
|
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
|
# Code is Apache-2.0 and docs are CC-BY-4.0
|
|
|
|
import pytest
|
|
|
|
from transactions.types.assets.create import Create
|
|
from transactions.types.assets.transfer import Transfer
|
|
|
|
|
|
def test_asset_transfer(b, signed_create_tx, user_pk, user_sk):
|
|
tx_transfer = Transfer.generate(signed_create_tx.to_inputs(), [([user_pk], 1)], [signed_create_tx.id])
|
|
tx_transfer_signed = tx_transfer.sign([user_sk])
|
|
|
|
b.store_bulk_transactions([signed_create_tx])
|
|
|
|
assert b.validate_transaction(tx_transfer_signed) == tx_transfer_signed
|
|
assert tx_transfer_signed.assets[0]["id"] == signed_create_tx.id
|
|
|
|
|
|
# NOTE: TO BE REMOVED BECAUSE V3.0 ALLOWS FOR MULTIPLE ASSETS THEREFOR MULTIPLE ASSET IDS
|
|
# def test_validate_transfer_asset_id_mismatch(b, signed_create_tx, user_pk, user_sk):
|
|
# from planetmint.transactions.common.exceptions import AssetIdMismatch
|
|
|
|
|
|
def test_validate_transfer_asset_id_mismatch(b, signed_create_tx, user_pk, user_sk):
|
|
from transactions.common.exceptions import AssetIdMismatch
|
|
|
|
tx_transfer = Transfer.generate(signed_create_tx.to_inputs(), [([user_pk], 1)], [signed_create_tx.id])
|
|
tx_transfer.assets[0]["id"] = "a" * 64
|
|
tx_transfer_signed = tx_transfer.sign([user_sk])
|
|
|
|
b.store_bulk_transactions([signed_create_tx])
|
|
|
|
with pytest.raises(AssetIdMismatch):
|
|
b.validate_transaction(tx_transfer_signed)
|
|
|
|
|
|
def test_get_asset_id_create_transaction(alice, user_pk):
|
|
from transactions.common.transaction import Transaction
|
|
|
|
tx_create = Create.generate([alice.public_key], [([user_pk], 1)])
|
|
assert Transaction.get_asset_id(tx_create) == tx_create.id
|
|
|
|
|
|
def test_get_asset_id_transfer_transaction(b, signed_create_tx, user_pk):
|
|
from transactions.common.transaction import Transaction
|
|
|
|
tx_transfer = Transfer.generate(signed_create_tx.to_inputs(), [([user_pk], 1)], [signed_create_tx.id])
|
|
asset_id = Transaction.get_asset_id(tx_transfer)
|
|
assert asset_id == tx_transfer.assets[0]["id"]
|
|
|
|
|
|
def test_asset_id_mismatch(alice, user_pk):
|
|
from transactions.common.transaction import Transaction
|
|
from transactions.common.exceptions import AssetIdMismatch
|
|
|
|
tx1 = Create.generate(
|
|
[alice.public_key], [([user_pk], 1)], metadata="QmaozNR7DZHQK1ZcU9p7QdrshMvXqWK6gpu5rmrkPdT3L4"
|
|
)
|
|
tx1.sign([alice.private_key])
|
|
tx2 = Create.generate(
|
|
[alice.public_key], [([user_pk], 1)], metadata="zb2rhe5P4gXftAwvA4eXQ5HJwsER2owDyS9sKaQRRVQPn93bA"
|
|
)
|
|
tx2.sign([alice.private_key])
|
|
|
|
with pytest.raises(AssetIdMismatch):
|
|
Transaction.get_asset_id([tx1, tx2])
|
|
|
|
|
|
def test_create_valid_divisible_asset(b, user_pk, user_sk):
|
|
tx = Create.generate([user_pk], [([user_pk], 2)])
|
|
tx_signed = tx.sign([user_sk])
|
|
assert b.validate_transaction(tx_signed) == tx_signed
|
|
|
|
|
|
def test_v_2_0_validation_create(b, signed_2_0_create_tx):
|
|
validated = b.validate_transaction(signed_2_0_create_tx)
|
|
assert validated.to_dict() == signed_2_0_create_tx
|
|
|
|
|
|
def test_v_2_0_validation_create_invalid(b, signed_2_0_create_tx_assets):
|
|
assert b.validate_transaction(signed_2_0_create_tx_assets)
|
|
|
|
|
|
def test_v_2_0_validation_transfer(b, signed_2_0_create_tx, signed_2_0_transfer_tx):
|
|
validated = b.validate_transaction(signed_2_0_create_tx)
|
|
b.store_bulk_transactions([validated])
|
|
assert validated.to_dict() == signed_2_0_create_tx
|
|
assert b.validate_transaction(signed_2_0_transfer_tx).to_dict() == signed_2_0_transfer_tx
|