mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-26 07:25:44 +00:00
blackified the project
Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
parent
0e79bbecca
commit
be6afa8785
@ -462,18 +462,19 @@ class Planetmint(object):
|
||||
if not tx.inputs_valid(input_conditions_converted):
|
||||
raise InvalidSignature("Transaction signature is invalid.")
|
||||
|
||||
def validate_asset_id(self, tx: Transaction, input_txs:list):
|
||||
def validate_asset_id(self, tx: Transaction, input_txs: list):
|
||||
# validate asset
|
||||
if tx.operation != Transaction.COMPOSE:
|
||||
asset_id = tx.get_asset_id(input_txs)
|
||||
if asset_id != Transaction.read_out_asset_id(tx):
|
||||
raise AssetIdMismatch(("The asset id of the input does not" " match the asset id of the" " transaction"))
|
||||
raise AssetIdMismatch(
|
||||
("The asset id of the input does not" " match the asset id of the" " transaction")
|
||||
)
|
||||
else:
|
||||
asset_ids = Transaction.get_asset_ids( input_txs )
|
||||
asset_ids = Transaction.get_asset_ids(input_txs)
|
||||
if Transaction.read_out_asset_id(tx) in asset_ids:
|
||||
raise AssetIdMismatch(("The asset ID of the compose must be different to all of its input asset IDs"))
|
||||
|
||||
|
||||
def validate_inputs_distinct(self, tx):
|
||||
# Validate that all inputs are distinct
|
||||
links = [i.fulfills.to_uri() for i in tx.inputs]
|
||||
|
||||
@ -68,6 +68,7 @@ def test_asset_id_mismatch(alice, user_pk):
|
||||
with pytest.raises(AssetIdMismatch):
|
||||
Transaction.get_asset_id([tx1, tx2])
|
||||
|
||||
|
||||
def test_compose_valid_transactions(b, user_pk, user_sk, alice, signed_create_tx, _bdb):
|
||||
from transactions.types.assets.compose import Compose
|
||||
|
||||
@ -78,7 +79,8 @@ def test_compose_valid_transactions(b, user_pk, user_sk, alice, signed_create_tx
|
||||
assets = [signed_create_tx.id, "QmW5GVMW98D3mktSDfWHS8nX2UiCd8gP1uCiujnFX4yK8n"]
|
||||
compose_transaction = Compose.generate(inputs=inputs, recipients=[([user_pk], 1)], assets=assets)
|
||||
compose_transaction.sign([user_sk])
|
||||
assert b.validate_transaction( compose_transaction)
|
||||
assert b.validate_transaction(compose_transaction)
|
||||
|
||||
|
||||
def test_create_valid_divisible_asset(b, user_pk, user_sk, _bdb):
|
||||
tx = Create.generate([user_pk], [([user_pk], 2)])
|
||||
|
||||
@ -32,6 +32,7 @@ from transactions.common.crypto import generate_key_pair
|
||||
|
||||
TX_ENDPOINT = "/api/v1/transactions/"
|
||||
|
||||
|
||||
@pytest.mark.abci
|
||||
def test_get_transaction_endpoint(client, posted_create_tx):
|
||||
res = client.get(TX_ENDPOINT + posted_create_tx.id)
|
||||
@ -473,9 +474,14 @@ def test_post_transaction_invalid_mode(client):
|
||||
assert "400 BAD REQUEST" in response.status
|
||||
assert 'Mode must be "async", "sync" or "commit"' == json.loads(response.data.decode("utf8"))["message"]["mode"]
|
||||
|
||||
|
||||
def test_post_transaction_compose_valid_wo_abci(b, _bdb):
|
||||
alice = generate_key_pair()
|
||||
tx = Create.generate([alice.public_key], [([alice.public_key], 1)], assets=[{"data":"QmW5GVMW98D3mktSDfWHS8nX2UiCd8gP1uCiujnFX4yK97"}]).sign([alice.private_key])
|
||||
tx = Create.generate(
|
||||
[alice.public_key],
|
||||
[([alice.public_key], 1)],
|
||||
assets=[{"data": "QmW5GVMW98D3mktSDfWHS8nX2UiCd8gP1uCiujnFX4yK97"}],
|
||||
).sign([alice.private_key])
|
||||
validated = b.validate_transaction(tx)
|
||||
b.store_bulk_transactions([validated])
|
||||
|
||||
@ -484,20 +490,24 @@ def test_post_transaction_compose_valid_wo_abci(b, _bdb):
|
||||
compose_asset_cid = "bafkreignwcoye67vn6edp23mj4llhpzzkgyuefu7xesjzjxcv2bz3p4nfm"
|
||||
inputs_ = tx_obj.to_inputs()
|
||||
|
||||
assets_ = [ tx["id"], compose_asset_cid]
|
||||
assets_ = [tx["id"], compose_asset_cid]
|
||||
compose_transaction = Compose.generate(inputs=inputs_, recipients=[([alice.public_key], 1)], assets=assets_)
|
||||
signed_compose_tx = compose_transaction.sign( [alice.private_key])
|
||||
signed_compose_tx = compose_transaction.sign([alice.private_key])
|
||||
compose_dict = signed_compose_tx.to_dict()
|
||||
compose_obj = Transaction.from_dict( compose_dict)
|
||||
compose_obj = Transaction.from_dict(compose_dict)
|
||||
validated_compose = b.validate_transaction(compose_obj)
|
||||
b.store_bulk_transactions([validated_compose])
|
||||
|
||||
|
||||
@pytest.mark.abci
|
||||
def test_post_transaction_compose_valid(client,b):
|
||||
def test_post_transaction_compose_valid(client, b):
|
||||
mode = ("?mode=commit", BROADCAST_TX_COMMIT)
|
||||
alice = generate_key_pair()
|
||||
tx = Create.generate([alice.public_key], [([alice.public_key], 1)], assets=[{"data":"QmW5GVMW98D3mktSDfWHS8nX2UiCd8gP1uCiujnFX4yK97"}]).sign([alice.private_key])
|
||||
tx = Create.generate(
|
||||
[alice.public_key],
|
||||
[([alice.public_key], 1)],
|
||||
assets=[{"data": "QmW5GVMW98D3mktSDfWHS8nX2UiCd8gP1uCiujnFX4yK97"}],
|
||||
).sign([alice.private_key])
|
||||
mode_endpoint = TX_ENDPOINT + mode[0]
|
||||
response = client.post(mode_endpoint, data=json.dumps(tx.to_dict()))
|
||||
assert "202 ACCEPTED" in response.status
|
||||
@ -506,9 +516,9 @@ def test_post_transaction_compose_valid(client,b):
|
||||
compose_asset_cid = "bafkreignwcoye67vn6edp23mj4llhpzzkgyuefu7xesjzjxcv2bz3p4nfm"
|
||||
inputs_ = tx_obj.to_inputs()
|
||||
|
||||
assets_ = [ tx["id"], compose_asset_cid]
|
||||
assets_ = [tx["id"], compose_asset_cid]
|
||||
compose_transaction = Compose.generate(inputs=inputs_, recipients=[([alice.public_key], 1)], assets=assets_)
|
||||
signed_tx = compose_transaction.sign( [alice.private_key])
|
||||
signed_tx = compose_transaction.sign([alice.private_key])
|
||||
validated_compose = b.validate_transaction(signed_tx)
|
||||
mode_endpoint = TX_ENDPOINT + "?mode=commit"
|
||||
response = client.post(mode_endpoint, data=json.dumps(signed_tx.to_dict()))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user