mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-24 14:35:45 +00:00
store transactions of various versions (backwardcompatibility)
added _bdb variable to init/drop DBs for the single use cases (started failing as TXs are looked up in DB - compared to before) Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
parent
dbbdcc88ff
commit
2f09eec368
@ -36,6 +36,7 @@ from planetmint.backend.tarantool.const import (
|
|||||||
from planetmint.backend.utils import module_dispatch_registrar
|
from planetmint.backend.utils import module_dispatch_registrar
|
||||||
from planetmint.backend.models import Asset, Block, Output
|
from planetmint.backend.models import Asset, Block, Output
|
||||||
from planetmint.backend.tarantool.connection import TarantoolDBConnection
|
from planetmint.backend.tarantool.connection import TarantoolDBConnection
|
||||||
|
from transactions.common.transaction import Transaction
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -127,12 +128,13 @@ def store_transaction(connection, transaction, table = TARANT_TABLE_TRANSACTION)
|
|||||||
scripts = None
|
scripts = None
|
||||||
if TARANT_TABLE_SCRIPT in transaction:
|
if TARANT_TABLE_SCRIPT in transaction:
|
||||||
scripts = transaction[TARANT_TABLE_SCRIPT]
|
scripts = transaction[TARANT_TABLE_SCRIPT]
|
||||||
|
asset_obj = Transaction.get_assets_tag(transaction["version"])
|
||||||
tx = (
|
tx = (
|
||||||
transaction["id"],
|
transaction["id"],
|
||||||
transaction["operation"],
|
transaction["operation"],
|
||||||
transaction["version"],
|
transaction["version"],
|
||||||
transaction["metadata"],
|
transaction["metadata"],
|
||||||
transaction["assets"],
|
transaction[asset_obj],
|
||||||
transaction["inputs"],
|
transaction["inputs"],
|
||||||
scripts,
|
scripts,
|
||||||
)
|
)
|
||||||
@ -148,7 +150,7 @@ def store_transaction(connection, transaction, table = TARANT_TABLE_TRANSACTION)
|
|||||||
|
|
||||||
@register_query(TarantoolDBConnection)
|
@register_query(TarantoolDBConnection)
|
||||||
def get_transaction_by_id(connection, transaction_id, table=TARANT_TABLE_TRANSACTION):
|
def get_transaction_by_id(connection, transaction_id, table=TARANT_TABLE_TRANSACTION):
|
||||||
txs = connection.run(connection.space(table).select(transaction_id, index=TARANT_ID_SEARCH))
|
txs = connection.run(connection.space(table).select(transaction_id, index=TARANT_ID_SEARCH), only_data=False)
|
||||||
if len(txs) == 0:
|
if len(txs) == 0:
|
||||||
return None
|
return None
|
||||||
return DbTransaction.from_tuple(txs[0])
|
return DbTransaction.from_tuple(txs[0])
|
||||||
|
|||||||
@ -9,7 +9,7 @@ from transactions.types.assets.create import Create
|
|||||||
from transactions.types.assets.transfer import Transfer
|
from transactions.types.assets.transfer import Transfer
|
||||||
|
|
||||||
|
|
||||||
def test_asset_transfer(b, signed_create_tx, user_pk, user_sk):
|
def test_asset_transfer(b, signed_create_tx, user_pk, user_sk, _bdb):
|
||||||
tx_transfer = Transfer.generate(signed_create_tx.to_inputs(), [([user_pk], 1)], [signed_create_tx.id])
|
tx_transfer = Transfer.generate(signed_create_tx.to_inputs(), [([user_pk], 1)], [signed_create_tx.id])
|
||||||
tx_transfer_signed = tx_transfer.sign([user_sk])
|
tx_transfer_signed = tx_transfer.sign([user_sk])
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ def test_asset_transfer(b, signed_create_tx, user_pk, user_sk):
|
|||||||
# from planetmint.transactions.common.exceptions import AssetIdMismatch
|
# from planetmint.transactions.common.exceptions import AssetIdMismatch
|
||||||
|
|
||||||
|
|
||||||
def test_validate_transfer_asset_id_mismatch(b, signed_create_tx, user_pk, user_sk):
|
def test_validate_transfer_asset_id_mismatch(b, signed_create_tx, user_pk, user_sk,_bdb):
|
||||||
from transactions.common.exceptions import AssetIdMismatch
|
from transactions.common.exceptions import AssetIdMismatch
|
||||||
|
|
||||||
tx_transfer = Transfer.generate(signed_create_tx.to_inputs(), [([user_pk], 1)], [signed_create_tx.id])
|
tx_transfer = Transfer.generate(signed_create_tx.to_inputs(), [([user_pk], 1)], [signed_create_tx.id])
|
||||||
@ -69,22 +69,22 @@ def test_asset_id_mismatch(alice, user_pk):
|
|||||||
Transaction.get_asset_id([tx1, tx2])
|
Transaction.get_asset_id([tx1, tx2])
|
||||||
|
|
||||||
|
|
||||||
def test_create_valid_divisible_asset(b, user_pk, user_sk):
|
def test_create_valid_divisible_asset(b, user_pk, user_sk, _bdb):
|
||||||
tx = Create.generate([user_pk], [([user_pk], 2)])
|
tx = Create.generate([user_pk], [([user_pk], 2)])
|
||||||
tx_signed = tx.sign([user_sk])
|
tx_signed = tx.sign([user_sk])
|
||||||
assert b.validate_transaction(tx_signed) == tx_signed
|
assert b.validate_transaction(tx_signed) == tx_signed
|
||||||
|
|
||||||
|
|
||||||
def test_v_2_0_validation_create(b, signed_2_0_create_tx):
|
def test_v_2_0_validation_create(b, signed_2_0_create_tx, _bdb):
|
||||||
validated = b.validate_transaction(signed_2_0_create_tx)
|
validated = b.validate_transaction(signed_2_0_create_tx)
|
||||||
assert validated.to_dict() == 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):
|
def test_v_2_0_validation_create_invalid(b, signed_2_0_create_tx_assets, _bdb):
|
||||||
assert b.validate_transaction(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):
|
def test_v_2_0_validation_transfer(b, signed_2_0_create_tx, signed_2_0_transfer_tx, _bdb):
|
||||||
validated = b.validate_transaction(signed_2_0_create_tx)
|
validated = b.validate_transaction(signed_2_0_create_tx)
|
||||||
b.store_bulk_transactions([validated])
|
b.store_bulk_transactions([validated])
|
||||||
assert validated.to_dict() == signed_2_0_create_tx
|
assert validated.to_dict() == signed_2_0_create_tx
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user