mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-24 14:35:45 +00:00
fixed web test cases
Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
parent
a0f0db0989
commit
9a669a1993
@ -192,22 +192,22 @@ def store_block(connection, block: dict):
|
|||||||
|
|
||||||
@register_query(TarantoolDBConnection)
|
@register_query(TarantoolDBConnection)
|
||||||
def get_txids_filtered(
|
def get_txids_filtered(
|
||||||
connection, asset_id: str, operation: str = None, last_tx: any = None
|
connection, asset_ids: list[str], operation: str = None, last_tx: any = None
|
||||||
): # TODO here is used 'OR' operator
|
): # TODO here is used 'OR' operator
|
||||||
actions = {
|
actions = {
|
||||||
"CREATE": {"sets": ["CREATE", asset_id], "index": "transaction_search"},
|
"CREATE": {"sets": ["CREATE", asset_ids], "index": "transaction_search"},
|
||||||
# 1 - operation, 2 - id (only in transactions) +
|
# 1 - operation, 2 - id (only in transactions) +
|
||||||
"TRANSFER": {"sets": ["TRANSFER", asset_id], "index": "transaction_search"},
|
"TRANSFER": {"sets": ["TRANSFER", asset_ids], "index": "transaction_search"},
|
||||||
# 1 - operation, 2 - asset.id (linked mode) + OPERATOR OR
|
# 1 - operation, 2 - asset.id (linked mode) + OPERATOR OR
|
||||||
None: {"sets": [asset_id, asset_id]},
|
None: {"sets": [asset_ids, asset_ids]},
|
||||||
}[operation]
|
}[operation]
|
||||||
_transactions = []
|
_transactions = []
|
||||||
if actions["sets"][0] == "CREATE": # +
|
if actions["sets"][0] == "CREATE": # +
|
||||||
_transactions = connection.run(
|
_transactions = connection.run(
|
||||||
connection.space("transactions").select([operation, asset_id], index=actions["index"])
|
connection.space("transactions").select([operation, asset_ids[0]], index=actions["index"])
|
||||||
)
|
)
|
||||||
elif actions["sets"][0] == "TRANSFER": # +
|
elif actions["sets"][0] == "TRANSFER": # +
|
||||||
_assets = connection.run(connection.space("assets").select([asset_id], index="only_asset_search"))
|
_assets = connection.run(connection.space("assets").select(asset_ids, index="only_asset_search"))
|
||||||
|
|
||||||
for asset in _assets:
|
for asset in _assets:
|
||||||
_txid = asset[1]
|
_txid = asset[1]
|
||||||
@ -217,8 +217,8 @@ def get_txids_filtered(
|
|||||||
if len(_tmp_transactions) != 0:
|
if len(_tmp_transactions) != 0:
|
||||||
_transactions.extend(_tmp_transactions)
|
_transactions.extend(_tmp_transactions)
|
||||||
else:
|
else:
|
||||||
_tx_ids = connection.run(connection.space("transactions").select([asset_id], index="id_search"))
|
_tx_ids = connection.run(connection.space("transactions").select(asset_ids, index="id_search"))
|
||||||
_assets_ids = connection.run(connection.space("assets").select([asset_id], index="only_asset_search"))
|
_assets_ids = connection.run(connection.space("assets").select(asset_ids, index="only_asset_search"))
|
||||||
return tuple(set([sublist[1] for sublist in _assets_ids] + [sublist[0] for sublist in _tx_ids]))
|
return tuple(set([sublist[1] for sublist in _assets_ids] + [sublist[0] for sublist in _tx_ids]))
|
||||||
|
|
||||||
if last_tx:
|
if last_tx:
|
||||||
|
|||||||
@ -57,11 +57,11 @@ class Dispatcher:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def eventify_block(block):
|
def eventify_block(block):
|
||||||
for tx in block["transactions"]:
|
for tx in block["transactions"]:
|
||||||
if tx.asset:
|
if tx.assets:
|
||||||
asset_id = tx.asset.get("id", tx.id)
|
asset_ids = [asset.get("id", tx.id) for asset in tx.assets]
|
||||||
else:
|
else:
|
||||||
asset_id = tx.id
|
asset_ids = [tx.id]
|
||||||
yield {"height": block["height"], "asset_id": asset_id, "transaction_id": tx.id}
|
yield {"height": block["height"], "asset_ids": asset_ids, "transaction_id": tx.id}
|
||||||
|
|
||||||
async def publish(self):
|
async def publish(self):
|
||||||
"""Publish new events to the subscribers."""
|
"""Publish new events to the subscribers."""
|
||||||
|
|||||||
@ -28,15 +28,15 @@ def test_get_txids_filtered(signed_create_tx, signed_transfer_tx, db_conn):
|
|||||||
asset_id = Transaction.get_asset_id([signed_create_tx, signed_transfer_tx])
|
asset_id = Transaction.get_asset_id([signed_create_tx, signed_transfer_tx])
|
||||||
|
|
||||||
# Test get by just asset id
|
# Test get by just asset id
|
||||||
txids = set(query.get_txids_filtered(connection=db_conn, asset_id=asset_id))
|
txids = set(query.get_txids_filtered(connection=db_conn, asset_ids=[asset_id]))
|
||||||
assert txids == {signed_create_tx.id, signed_transfer_tx.id}
|
assert txids == {signed_create_tx.id, signed_transfer_tx.id}
|
||||||
|
|
||||||
# Test get by asset and CREATE
|
# Test get by asset and CREATE
|
||||||
txids = set(query.get_txids_filtered(connection=db_conn, asset_id=asset_id, operation=Transaction.CREATE))
|
txids = set(query.get_txids_filtered(connection=db_conn, asset_ids=[asset_id], operation=Transaction.CREATE))
|
||||||
assert txids == {signed_create_tx.id}
|
assert txids == {signed_create_tx.id}
|
||||||
|
|
||||||
# Test get by asset and TRANSFER
|
# Test get by asset and TRANSFER
|
||||||
txids = set(query.get_txids_filtered(connection=db_conn, asset_id=asset_id, operation=Transaction.TRANSFER))
|
txids = set(query.get_txids_filtered(connection=db_conn, asset_ids=[asset_id], operation=Transaction.TRANSFER))
|
||||||
assert txids == {signed_transfer_tx.id}
|
assert txids == {signed_transfer_tx.id}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -397,13 +397,13 @@ def test_transactions_get_list_good(client):
|
|||||||
["last_tx", None],
|
["last_tx", None],
|
||||||
["operation", None],
|
["operation", None],
|
||||||
]
|
]
|
||||||
url = TX_ENDPOINT + "?asset_id=" + ','.join(asset_ids) + "&operation=CREATE"
|
url = TX_ENDPOINT + "?asset_ids=" + ','.join(asset_ids) + "&operation=CREATE"
|
||||||
assert client.get(url).json == [
|
assert client.get(url).json == [
|
||||||
["asset_ids", asset_ids],
|
["asset_ids", asset_ids],
|
||||||
["last_tx", None],
|
["last_tx", None],
|
||||||
["operation", "CREATE"],
|
["operation", "CREATE"],
|
||||||
]
|
]
|
||||||
url = TX_ENDPOINT + "?asset_id=" + ','.join(asset_ids) + "&last_tx=true"
|
url = TX_ENDPOINT + "?asset_ids=" + ','.join(asset_ids) + "&last_tx=true"
|
||||||
assert client.get(url).json == [
|
assert client.get(url).json == [
|
||||||
["asset_ids", asset_ids],
|
["asset_ids", asset_ids],
|
||||||
["last_tx", True],
|
["last_tx", True],
|
||||||
|
|||||||
@ -37,8 +37,8 @@ def test_eventify_block_works_with_any_transaction():
|
|||||||
block = {"height": 1, "transactions": [tx, tx_transfer]}
|
block = {"height": 1, "transactions": [tx, tx_transfer]}
|
||||||
|
|
||||||
expected_events = [
|
expected_events = [
|
||||||
{"height": 1, "asset_id": tx.id, "transaction_id": tx.id},
|
{"height": 1, "asset_ids": [tx.id], "transaction_id": tx.id},
|
||||||
{"height": 1, "asset_id": tx_transfer.assets[0]["id"], "transaction_id": tx_transfer.id},
|
{"height": 1, "asset_ids": [tx_transfer.assets[0]["id"]], "transaction_id": tx_transfer.id},
|
||||||
]
|
]
|
||||||
|
|
||||||
for event, expected in zip(Dispatcher.eventify_block(block), expected_events):
|
for event, expected in zip(Dispatcher.eventify_block(block), expected_events):
|
||||||
@ -192,7 +192,7 @@ async def test_websocket_transaction_event(aiohttp_client, event_loop):
|
|||||||
json_result = json.loads(result.data)
|
json_result = json.loads(result.data)
|
||||||
assert json_result["transaction_id"] == tx.id
|
assert json_result["transaction_id"] == tx.id
|
||||||
# Since the transactions are all CREATEs, asset id == transaction id
|
# Since the transactions are all CREATEs, asset id == transaction id
|
||||||
assert json_result["asset_id"] == tx.id
|
assert json_result["asset_ids"] == [tx.id]
|
||||||
assert json_result["height"] == block["height"]
|
assert json_result["height"] == block["height"]
|
||||||
|
|
||||||
await tx_source.put(events.POISON_PILL)
|
await tx_source.put(events.POISON_PILL)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user