mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-24 14:35:45 +00:00
fix tests
Signed-off-by: cybnon <stefan.weber93@googlemail.com>
This commit is contained in:
parent
2028eb449d
commit
3edd365646
@ -42,7 +42,7 @@ class Input:
|
|||||||
|
|
||||||
return Input(tx_id, fulfills, owners_before, fulfillment)
|
return Input(tx_id, fulfills, owners_before, fulfillment)
|
||||||
|
|
||||||
def to_input_dict(self) -> dict:
|
def to_dict(self) -> dict:
|
||||||
fulfills = {
|
fulfills = {
|
||||||
"transaction_id": self.fulfills.transaction_id,
|
"transaction_id": self.fulfills.transaction_id,
|
||||||
"output_index": self.fulfills.output_index
|
"output_index": self.fulfills.output_index
|
||||||
|
|||||||
@ -67,7 +67,7 @@ class Output:
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
def to_output_dict(self) -> dict:
|
def to_dict(self) -> dict:
|
||||||
return {
|
return {
|
||||||
"id": self.tx_id,
|
"id": self.tx_id,
|
||||||
"amount": self.amount,
|
"amount": self.amount,
|
||||||
|
|||||||
@ -12,6 +12,7 @@ class Transaction:
|
|||||||
id: str = ""
|
id: str = ""
|
||||||
operation: str = ""
|
operation: str = ""
|
||||||
version: str = ""
|
version: str = ""
|
||||||
|
raw_transaction: dict = dict
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_dict(transaction: dict) -> Transaction:
|
def from_dict(transaction: dict) -> Transaction:
|
||||||
@ -19,6 +20,7 @@ class Transaction:
|
|||||||
id=transaction["id"],
|
id=transaction["id"],
|
||||||
operation=transaction["operation"],
|
operation=transaction["operation"],
|
||||||
version=transaction["version"],
|
version=transaction["version"],
|
||||||
|
raw_transaction=transaction["transaction"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -28,11 +30,14 @@ class Transaction:
|
|||||||
id=transaction[0],
|
id=transaction[0],
|
||||||
operation=transaction[1],
|
operation=transaction[1],
|
||||||
version=transaction[2],
|
version=transaction[2],
|
||||||
|
raw_transaction=transaction[3],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def to_dict(self) -> dict:
|
def to_dict(self) -> dict:
|
||||||
return {
|
return {
|
||||||
"id": self.id,
|
"id": self.id,
|
||||||
"operation": self.operation,
|
"operation": self.operation,
|
||||||
"version": self.version,
|
"version": self.version,
|
||||||
|
"transaction": self.raw_transaction,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -67,7 +67,7 @@ def store_transaction(connection, transaction):
|
|||||||
|
|
||||||
|
|
||||||
@singledispatch
|
@singledispatch
|
||||||
def get_transaction(conn, transaction_id):
|
def get_transaction(connection, transaction_id):
|
||||||
"""Get a transaction from the database."""
|
"""Get a transaction from the database."""
|
||||||
|
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|||||||
@ -26,9 +26,8 @@ register_query = module_dispatch_registrar(query)
|
|||||||
def _group_transaction_by_ids(connection, txids: list):
|
def _group_transaction_by_ids(connection, txids: list):
|
||||||
_transactions = []
|
_transactions = []
|
||||||
for txid in txids:
|
for txid in txids:
|
||||||
_txobject = connection.run(connection.space(TARANT_TABLE_TRANSACTION).get(txid, index=TARANT_ID_SEARCH))
|
tx = get_transaction(connection, txid)
|
||||||
|
if tx is None:
|
||||||
if _txobject is None:
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
_txinputs = get_inputs_by_tx_id(connection, txid)
|
_txinputs = get_inputs_by_tx_id(connection, txid)
|
||||||
@ -38,17 +37,17 @@ def _group_transaction_by_ids(connection, txids: list):
|
|||||||
_txmeta = get_metadata_by_tx_id(connection, txid)
|
_txmeta = get_metadata_by_tx_id(connection, txid)
|
||||||
_txscript = get_script_by_tx_id(connection, txid)
|
_txscript = get_script_by_tx_id(connection, txid)
|
||||||
|
|
||||||
_transaction = get_transaction(connection, txid)
|
tx = {
|
||||||
_transaction[TARANT_TABLE_TRANSACTION] = [tx.to_dict for tx in _transactions]
|
TARANT_TABLE_TRANSACTION: tx,
|
||||||
_transaction[TARANT_TABLE_INPUT] + [input.to_input_dict() for input in _txinputs]
|
TARANT_TABLE_INPUT: [tx_input.to_dict() for tx_input in _txinputs],
|
||||||
_transaction[TARANT_TABLE_OUTPUT] = [output.to_output_dict() for output in _txoutputs]
|
TARANT_TABLE_OUTPUT: [output.to_dict() for output in _txoutputs],
|
||||||
_transaction[TARANT_TABLE_KEYS] = [key.to_dict() for key in _txkeys]
|
TARANT_TABLE_KEYS: [key.to_dict() for key in _txkeys],
|
||||||
_transaction["assets"] = [asset.data for asset in _txassets]
|
TARANT_TABLE_ASSETS: _txassets,
|
||||||
_transaction["metadata"] = _txmeta.metadata
|
TARANT_TABLE_META_DATA: _txmeta,
|
||||||
|
TARANT_TABLE_SCRIPT: _txscript.script if _txscript else None,
|
||||||
|
}
|
||||||
|
|
||||||
if _txscript.script:
|
_transactions.append(tx)
|
||||||
_transaction[TARANT_TABLE_SCRIPT] = _txscript.script
|
|
||||||
_transactions.append(_transaction)
|
|
||||||
return _transactions
|
return _transactions
|
||||||
|
|
||||||
|
|
||||||
@ -141,6 +140,7 @@ def store_transaction_keys(connection, keys: Keys, output_id: str, index: int):
|
|||||||
@register_query(TarantoolDBConnection)
|
@register_query(TarantoolDBConnection)
|
||||||
def store_transactions(connection, signed_transactions: list):
|
def store_transactions(connection, signed_transactions: list):
|
||||||
for transaction in signed_transactions:
|
for transaction in signed_transactions:
|
||||||
|
store_transaction(connection, transaction)
|
||||||
|
|
||||||
[store_transaction_inputs(connection, Input.from_dict(input, transaction["id"]), index) for
|
[store_transaction_inputs(connection, Input.from_dict(input, transaction["id"]), index) for
|
||||||
index, input in enumerate(transaction[TARANT_TABLE_INPUT])]
|
index, input in enumerate(transaction[TARANT_TABLE_INPUT])]
|
||||||
@ -165,19 +165,20 @@ def store_transactions(connection, signed_transactions: list):
|
|||||||
|
|
||||||
@register_query(TarantoolDBConnection)
|
@register_query(TarantoolDBConnection)
|
||||||
def store_transaction(connection, transaction):
|
def store_transaction(connection, transaction):
|
||||||
tx = Transaction(id=transaction["id"], operation=transaction["operation"], version=transaction["version"])
|
tx = (transaction["id"], transaction["operation"], transaction["version"],
|
||||||
|
transaction)
|
||||||
connection.run(connection.space(TARANT_TABLE_TRANSACTION).insert(
|
connection.run(connection.space(TARANT_TABLE_TRANSACTION).insert(
|
||||||
tx.id,
|
tx
|
||||||
tx.operation,
|
|
||||||
tx.version,
|
|
||||||
),
|
),
|
||||||
only_data=False)
|
only_data=False)
|
||||||
|
|
||||||
|
|
||||||
@register_query(TarantoolDBConnection)
|
@register_query(TarantoolDBConnection)
|
||||||
def get_transaction(connection, transaction_id: str) -> Transaction:
|
def get_transaction(connection, transaction_id):
|
||||||
return Transaction.from_tuple(
|
txs = connection.run(connection.space(TARANT_TABLE_TRANSACTION).select(transaction_id, index=TARANT_ID_SEARCH))
|
||||||
connection.run(connection.space(TARANT_TABLE_TRANSACTION).get(transaction_id, index=TARANT_ID_SEARCH)))
|
if len(txs) == 0:
|
||||||
|
return None
|
||||||
|
return Transaction.from_tuple(txs[0])
|
||||||
|
|
||||||
|
|
||||||
@register_query(TarantoolDBConnection)
|
@register_query(TarantoolDBConnection)
|
||||||
|
|||||||
@ -8,11 +8,8 @@ MongoDB.
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
from collections import namedtuple
|
|
||||||
from uuid import uuid4
|
|
||||||
from planetmint.backend.connection import Connection
|
from planetmint.backend.connection import Connection
|
||||||
|
|
||||||
from hashlib import sha3_256
|
|
||||||
import json
|
import json
|
||||||
import rapidjson
|
import rapidjson
|
||||||
import requests
|
import requests
|
||||||
@ -40,6 +37,7 @@ from transactions.common.transaction import VALIDATOR_ELECTION, CHAIN_MIGRATION_
|
|||||||
from transactions.common.transaction_mode_types import BROADCAST_TX_COMMIT, BROADCAST_TX_ASYNC, BROADCAST_TX_SYNC
|
from transactions.common.transaction_mode_types import BROADCAST_TX_COMMIT, BROADCAST_TX_ASYNC, BROADCAST_TX_SYNC
|
||||||
from transactions.types.elections.election import Election
|
from transactions.types.elections.election import Election
|
||||||
from transactions.types.elections.validator_utils import election_id_to_public_key
|
from transactions.types.elections.validator_utils import election_id_to_public_key
|
||||||
|
|
||||||
from planetmint.config import Config
|
from planetmint.config import Config
|
||||||
from planetmint import backend, config_utils, fastquery
|
from planetmint import backend, config_utils, fastquery
|
||||||
from planetmint.tendermint_utils import (
|
from planetmint.tendermint_utils import (
|
||||||
@ -230,8 +228,7 @@ class Planetmint(object):
|
|||||||
return bool(transaction)
|
return bool(transaction)
|
||||||
|
|
||||||
def get_transaction(self, transaction_id):
|
def get_transaction(self, transaction_id):
|
||||||
transaction = backend.query.get_transaction(self.connection, transaction_id)
|
return backend.query.get_transaction(self.connection, transaction_id)
|
||||||
return Transaction.from_dict(transaction, False)
|
|
||||||
|
|
||||||
def get_transactions(self, txn_ids):
|
def get_transactions(self, txn_ids):
|
||||||
return backend.query.get_transactions(self.connection, txn_ids)
|
return backend.query.get_transactions(self.connection, txn_ids)
|
||||||
|
|||||||
@ -204,8 +204,8 @@ def test_get_owned_ids(signed_create_tx, user_pk, db_conn):
|
|||||||
query.store_transactions(connection=db_conn, signed_transactions=[signed_create_tx.to_dict()])
|
query.store_transactions(connection=db_conn, signed_transactions=[signed_create_tx.to_dict()])
|
||||||
txns = list(query.get_owned_ids(connection=db_conn, owner=user_pk))
|
txns = list(query.get_owned_ids(connection=db_conn, owner=user_pk))
|
||||||
tx_dict = signed_create_tx.to_dict()
|
tx_dict = signed_create_tx.to_dict()
|
||||||
founded = [tx for tx in txns if tx["id"] == tx_dict["id"]]
|
founded = [tx for tx in txns if tx["transactions"].id == tx_dict["id"]]
|
||||||
assert founded[0] == tx_dict
|
assert founded[0]["transactions"].raw_transaction == tx_dict
|
||||||
|
|
||||||
|
|
||||||
def test_get_spending_transactions(user_pk, user_sk, db_conn):
|
def test_get_spending_transactions(user_pk, user_sk, db_conn):
|
||||||
@ -225,7 +225,8 @@ def test_get_spending_transactions(user_pk, user_sk, db_conn):
|
|||||||
txns = list(query.get_spending_transactions(connection=db_conn, inputs=links))
|
txns = list(query.get_spending_transactions(connection=db_conn, inputs=links))
|
||||||
|
|
||||||
# tx3 not a member because input 1 not asked for
|
# tx3 not a member because input 1 not asked for
|
||||||
assert txns == [tx2.to_dict(), tx4.to_dict()]
|
assert txns[0]["transactions"].raw_transaction == tx2.to_dict()
|
||||||
|
assert txns[1]["transactions"].raw_transaction == tx4.to_dict()
|
||||||
|
|
||||||
|
|
||||||
def test_get_spending_transactions_multiple_inputs(db_conn):
|
def test_get_spending_transactions_multiple_inputs(db_conn):
|
||||||
@ -261,7 +262,7 @@ def test_get_spending_transactions_multiple_inputs(db_conn):
|
|||||||
txns = list(query.get_spending_transactions(connection=db_conn, inputs=[li]))
|
txns = list(query.get_spending_transactions(connection=db_conn, inputs=[li]))
|
||||||
assert len(txns) == num
|
assert len(txns) == num
|
||||||
if len(txns):
|
if len(txns):
|
||||||
assert [tx["id"] for tx in txns] == match
|
assert [tx["transactions"].id for tx in txns] == match
|
||||||
|
|
||||||
|
|
||||||
def test_store_block(db_conn):
|
def test_store_block(db_conn):
|
||||||
|
|||||||
@ -110,10 +110,10 @@ class TestBigchainApi(object):
|
|||||||
before = tx.to_dict()
|
before = tx.to_dict()
|
||||||
after = tx_from_db.to_dict()
|
after = tx_from_db.to_dict()
|
||||||
|
|
||||||
assert before["assets"][0]["data"] == after["assets"][0]["data"]
|
assert before["assets"][0]["data"] == after["transaction"]["assets"][0]["data"]
|
||||||
before.pop("asset", None)
|
before.pop("asset", None)
|
||||||
after.pop("asset", None)
|
after["transaction"].pop("asset", None)
|
||||||
assert before == after
|
assert before == after["transaction"]
|
||||||
|
|
||||||
|
|
||||||
class TestTransactionValidation(object):
|
class TestTransactionValidation(object):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user