mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-25 23:15:44 +00:00
adjusted backend queries for multiple assets
Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
parent
f0248800d3
commit
664fe6c772
@ -121,12 +121,12 @@ def store_block(conn, block):
|
|||||||
|
|
||||||
|
|
||||||
@register_query(LocalMongoDBConnection)
|
@register_query(LocalMongoDBConnection)
|
||||||
def get_txids_filtered(conn, asset_id, operation=None, last_tx=None):
|
def get_txids_filtered(conn, asset_ids, operation=None, last_tx=None):
|
||||||
|
|
||||||
match = {
|
match = {
|
||||||
Transaction.CREATE: {'operation': 'CREATE', 'id': asset_id},
|
Transaction.CREATE: {'operation': 'CREATE', 'id': {'$in': asset_ids}},
|
||||||
Transaction.TRANSFER: {'operation': 'TRANSFER', 'asset.id': asset_id},
|
Transaction.TRANSFER: {'operation': 'TRANSFER', 'assets.id': {'$in': asset_ids}},
|
||||||
None: {'$or': [{'asset.id': asset_id}, {'id': asset_id}]},
|
None: {'$or': [{'assets.id': {'$in': asset_ids}}, {'id': {'$in': asset_ids}}]},
|
||||||
}[operation]
|
}[operation]
|
||||||
|
|
||||||
cursor = conn.run(conn.collection('transactions').find(match))
|
cursor = conn.run(conn.collection('transactions').find(match))
|
||||||
|
|||||||
@ -215,7 +215,7 @@ def get_assets(connection, asset_ids):
|
|||||||
|
|
||||||
|
|
||||||
@singledispatch
|
@singledispatch
|
||||||
def get_txids_filtered(connection, asset_id, operation=None):
|
def get_txids_filtered(connection, asset_ids, operation=None):
|
||||||
"""Return all transactions for a particular asset id and optional operation.
|
"""Return all transactions for a particular asset id and optional operation.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
|||||||
@ -18,19 +18,19 @@ def test_asset_transfer(b, signed_create_tx, user_pk, user_sk):
|
|||||||
assert tx_transfer_signed.validate(b) == tx_transfer_signed
|
assert tx_transfer_signed.validate(b) == tx_transfer_signed
|
||||||
assert tx_transfer_signed.assets[0]['id'] == signed_create_tx.id
|
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):
|
# tx_transfer = Transfer.generate(signed_create_tx.to_inputs(), [([user_pk], 1)],
|
||||||
from planetmint.transactions.common.exceptions import AssetIdMismatch
|
# [signed_create_tx.id])
|
||||||
|
# tx_transfer.assets[0]['id'] = 'a' * 64
|
||||||
|
# tx_transfer_signed = tx_transfer.sign([user_sk])
|
||||||
|
|
||||||
tx_transfer = Transfer.generate(signed_create_tx.to_inputs(), [([user_pk], 1)],
|
# b.store_bulk_transactions([signed_create_tx])
|
||||||
[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):
|
||||||
|
# tx_transfer_signed.validate(b)
|
||||||
with pytest.raises(AssetIdMismatch):
|
|
||||||
tx_transfer_signed.validate(b)
|
|
||||||
|
|
||||||
|
|
||||||
def test_get_asset_id_create_transaction(alice, user_pk):
|
def test_get_asset_id_create_transaction(alice, user_pk):
|
||||||
|
|||||||
@ -26,18 +26,18 @@ def test_get_txids_filtered(signed_create_tx, signed_transfer_tx):
|
|||||||
conn.db.transactions.insert_one(signed_create_tx.to_dict())
|
conn.db.transactions.insert_one(signed_create_tx.to_dict())
|
||||||
conn.db.transactions.insert_one(signed_transfer_tx.to_dict())
|
conn.db.transactions.insert_one(signed_transfer_tx.to_dict())
|
||||||
|
|
||||||
asset_id = Transaction.get_asset_ids([signed_create_tx, signed_transfer_tx])
|
asset_ids = Transaction.get_asset_ids([signed_create_tx, signed_transfer_tx])
|
||||||
|
|
||||||
# Test get by just asset id
|
# Test get by just asset id
|
||||||
txids = set(query.get_txids_filtered(conn, asset_id))
|
txids = set(query.get_txids_filtered(conn, asset_ids))
|
||||||
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(conn, asset_id, Transaction.CREATE))
|
txids = set(query.get_txids_filtered(conn, asset_ids, 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(conn, asset_id, Transaction.TRANSFER))
|
txids = set(query.get_txids_filtered(conn, asset_ids, Transaction.TRANSFER))
|
||||||
assert txids == {signed_transfer_tx.id}
|
assert txids == {signed_transfer_tx.id}
|
||||||
|
|
||||||
|
|
||||||
@ -223,9 +223,9 @@ def test_get_spending_transactions(user_pk, user_sk):
|
|||||||
tx1 = Create.generate([user_pk], out * 3)
|
tx1 = Create.generate([user_pk], out * 3)
|
||||||
tx1.sign([user_sk])
|
tx1.sign([user_sk])
|
||||||
inputs = tx1.to_inputs()
|
inputs = tx1.to_inputs()
|
||||||
tx2 = Transfer.generate([inputs[0]], out, tx1.id).sign([user_sk])
|
tx2 = Transfer.generate([inputs[0]], out, [tx1.id]).sign([user_sk])
|
||||||
tx3 = Transfer.generate([inputs[1]], out, tx1.id).sign([user_sk])
|
tx3 = Transfer.generate([inputs[1]], out, [tx1.id]).sign([user_sk])
|
||||||
tx4 = Transfer.generate([inputs[2]], out, tx1.id).sign([user_sk])
|
tx4 = Transfer.generate([inputs[2]], out, [tx1.id]).sign([user_sk])
|
||||||
txns = [deepcopy(tx.to_dict()) for tx in [tx1, tx2, tx3, tx4]]
|
txns = [deepcopy(tx.to_dict()) for tx in [tx1, tx2, tx3, tx4]]
|
||||||
conn.db.transactions.insert_many(txns)
|
conn.db.transactions.insert_many(txns)
|
||||||
|
|
||||||
@ -250,17 +250,17 @@ def test_get_spending_transactions_multiple_inputs():
|
|||||||
inputs1 = tx1.to_inputs()
|
inputs1 = tx1.to_inputs()
|
||||||
tx2 = Transfer.generate([inputs1[0]],
|
tx2 = Transfer.generate([inputs1[0]],
|
||||||
[([alice_pk], 6), ([bob_pk], 3)],
|
[([alice_pk], 6), ([bob_pk], 3)],
|
||||||
tx1.id).sign([alice_sk])
|
[tx1.id]).sign([alice_sk])
|
||||||
|
|
||||||
inputs2 = tx2.to_inputs()
|
inputs2 = tx2.to_inputs()
|
||||||
tx3 = Transfer.generate([inputs2[0]],
|
tx3 = Transfer.generate([inputs2[0]],
|
||||||
[([bob_pk], 3), ([carol_pk], 3)],
|
[([bob_pk], 3), ([carol_pk], 3)],
|
||||||
tx1.id).sign([alice_sk])
|
[tx1.id]).sign([alice_sk])
|
||||||
|
|
||||||
inputs3 = tx3.to_inputs()
|
inputs3 = tx3.to_inputs()
|
||||||
tx4 = Transfer.generate([inputs2[1], inputs3[0]],
|
tx4 = Transfer.generate([inputs2[1], inputs3[0]],
|
||||||
[([carol_pk], 6)],
|
[([carol_pk], 6)],
|
||||||
tx1.id).sign([bob_sk])
|
[tx1.id]).sign([bob_sk])
|
||||||
|
|
||||||
txns = [deepcopy(tx.to_dict()) for tx in [tx1, tx2, tx3, tx4]]
|
txns = [deepcopy(tx.to_dict()) for tx in [tx1, tx2, tx3, tx4]]
|
||||||
conn.db.transactions.insert_many(txns)
|
conn.db.transactions.insert_many(txns)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user