mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-24 06:25:45 +00:00
added compose test case. schema validation is still failing.
Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
parent
3e2182fffb
commit
6f6c0d07a7
@ -1,7 +1,7 @@
|
||||
[pytest]
|
||||
testpaths = tests/
|
||||
norecursedirs = .* *.egg *.egg-info env* devenv* docs
|
||||
#addopts = -m "not abci"
|
||||
addopts = -m "abci"
|
||||
looponfailroots = planetmint tests
|
||||
asyncio_mode = strict
|
||||
markers =
|
||||
|
||||
@ -15,16 +15,23 @@ from hashlib import sha3_256
|
||||
from transactions.common import crypto
|
||||
from transactions.common.transaction import Transaction
|
||||
from transactions.types.assets.create import Create
|
||||
from transactions.types.assets.compose import Compose
|
||||
from transactions.types.assets.transfer import Transfer
|
||||
from transactions.common.transaction_mode_types import (
|
||||
BROADCAST_TX_COMMIT,
|
||||
BROADCAST_TX_ASYNC,
|
||||
BROADCAST_TX_SYNC,
|
||||
)
|
||||
from transactions.common.transaction import (
|
||||
Input,
|
||||
TransactionLink,
|
||||
)
|
||||
from transactions.common.utils import _fulfillment_from_details
|
||||
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)
|
||||
@ -444,8 +451,6 @@ def test_transactions_get_list_bad(client):
|
||||
],
|
||||
)
|
||||
def test_post_transaction_valid_modes(mock_post, client, mode):
|
||||
from transactions.common.crypto import generate_key_pair
|
||||
|
||||
def _mock_post(*args, **kwargs):
|
||||
return Mock(json=Mock(return_value={"result": {"code": 0}}))
|
||||
|
||||
@ -461,11 +466,42 @@ def test_post_transaction_valid_modes(mock_post, client, mode):
|
||||
|
||||
@pytest.mark.abci
|
||||
def test_post_transaction_invalid_mode(client):
|
||||
from transactions.common.crypto import generate_key_pair
|
||||
|
||||
alice = generate_key_pair()
|
||||
tx = Create.generate([alice.public_key], [([alice.public_key], 1)], assets=None).sign([alice.private_key])
|
||||
mode_endpoint = TX_ENDPOINT + "?mode=nope"
|
||||
response = client.post(mode_endpoint, data=json.dumps(tx.to_dict()))
|
||||
assert "400 BAD REQUEST" in response.status
|
||||
assert 'Mode must be "async", "sync" or "commit"' == json.loads(response.data.decode("utf8"))["message"]["mode"]
|
||||
|
||||
|
||||
@pytest.mark.abci
|
||||
def test_post_transaction_compose_valid( client):
|
||||
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])
|
||||
mode_endpoint = TX_ENDPOINT + mode[0]
|
||||
response = client.post(mode_endpoint, data=json.dumps(tx.to_dict()))
|
||||
tx = tx.to_dict()
|
||||
|
||||
compose_asset_cid = "QmW5GVMW98D3mktSDfWHS8nX2UiCd8gP1uCiujnFX4yK8n"
|
||||
|
||||
condition_index = 0
|
||||
condition = tx["outputs"][condition_index]
|
||||
inputs_ = [
|
||||
Input(
|
||||
_fulfillment_from_details(condition["condition"]["details"]),
|
||||
condition["public_keys"],
|
||||
fulfills=TransactionLink(
|
||||
txid=tx["id"],
|
||||
output=condition_index,
|
||||
),
|
||||
)
|
||||
]
|
||||
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])
|
||||
mode_endpoint = TX_ENDPOINT + "?mode=commit"
|
||||
response = client.post(mode_endpoint, data=json.dumps(signed_tx.to_dict()))
|
||||
assert "400 BAD REQUEST" in response.status
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user