mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-24 22:45:44 +00:00
resolved merge conflicts
Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
commit
e239368c66
@ -17,6 +17,7 @@ from json import dumps, loads
|
||||
|
||||
register_query = module_dispatch_registrar(query)
|
||||
|
||||
|
||||
@register_query(TarantoolDBConnection)
|
||||
def _group_transaction_by_ids(connection, txids: list):
|
||||
_transactions = []
|
||||
@ -53,24 +54,42 @@ def store_transactions(connection, signed_transactions: list):
|
||||
txprepare = TransactionDecompose(transaction)
|
||||
txtuples = txprepare.convert_to_tuple()
|
||||
try:
|
||||
connection.run(connection.space("transactions").insert(txtuples["transactions"]))
|
||||
connection.run(
|
||||
connection.space("transactions").insert(txtuples["transactions"]),
|
||||
only_data=False
|
||||
)
|
||||
except: # This is used for omitting duplicate error in database for test -> test_bigchain_api::test_double_inclusion
|
||||
continue
|
||||
|
||||
for _in in txtuples["inputs"]:
|
||||
connection.run(connection.space("inputs").insert(_in))
|
||||
connection.run(
|
||||
connection.space("inputs").insert(_in),
|
||||
only_data=False
|
||||
)
|
||||
|
||||
for _out in txtuples["outputs"]:
|
||||
connection.run(connection.space("outputs").insert(_out))
|
||||
connection.run(
|
||||
connection.space("outputs").insert(_out),
|
||||
only_data=False
|
||||
)
|
||||
|
||||
for _key in txtuples["keys"]:
|
||||
connection.run(connection.space("keys").insert(_key))
|
||||
connection.run(
|
||||
connection.space("keys").insert(_key),
|
||||
only_data=False
|
||||
)
|
||||
|
||||
if txtuples["metadata"] is not None:
|
||||
connection.run(connection.space("meta_data").insert(txtuples["metadata"]))
|
||||
connection.run(
|
||||
connection.space("meta_data").insert(txtuples["metadata"]),
|
||||
only_data=False
|
||||
)
|
||||
|
||||
if txtuples["asset"] is not None:
|
||||
connection.run(connection.space("asset").insert(txtuples["asset"]))
|
||||
connection.run(
|
||||
connection.space("assets").insert(txtuples["asset"]),
|
||||
only_data=False
|
||||
)
|
||||
|
||||
|
||||
@register_query(TarantoolDBConnection)
|
||||
@ -485,7 +504,8 @@ def get_election(connection, election_id: str):
|
||||
|
||||
|
||||
@register_query(TarantoolDBConnection)
|
||||
def get_asset_tokens_for_public_key(connection, asset_id: str, public_key: str): # FIXME Something can be wrong with this function ! (public_key) is not used
|
||||
def get_asset_tokens_for_public_key(connection, asset_id: str,
|
||||
public_key: str): # FIXME Something can be wrong with this function ! (public_key) is not used
|
||||
# space = connection.space("keys")
|
||||
# _keys = space.select([public_key], index="keys_search")
|
||||
_transactions = connection.run(
|
||||
|
||||
@ -91,7 +91,7 @@ def test_bigchain_show_config(capsys):
|
||||
|
||||
def test__run_init(mocker):
|
||||
init_db_mock = mocker.patch(
|
||||
'planetmint.backend.tarantool.connection.TarantoolDB.init_database')
|
||||
'planetmint.backend.tarantool.connection.TarantoolDBConnection.init_database')
|
||||
|
||||
from planetmint.backend.connection import connect
|
||||
|
||||
|
||||
@ -553,7 +553,7 @@ def tarantool_client(db_context): # TODO Here add TarantoolConnectionClass
|
||||
|
||||
@pytest.fixture
|
||||
def utxo_collection(tarantool_client):
|
||||
return tarantool_client.space("utxos")
|
||||
return tarantool_client.get_space("utxos")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
||||
@ -29,12 +29,10 @@ def test_asset_is_separated_from_transaciton(b):
|
||||
import copy
|
||||
from planetmint.transactions.common.crypto import generate_key_pair
|
||||
from planetmint.backend.tarantool.connection import TarantoolDBConnection
|
||||
|
||||
|
||||
if isinstance(b.connection, TarantoolDBConnection):
|
||||
pytest.skip("This specific function is skipped because, assets are stored differently if using Tarantool")
|
||||
|
||||
|
||||
alice = generate_key_pair()
|
||||
bob = generate_key_pair()
|
||||
|
||||
@ -48,9 +46,9 @@ def test_asset_is_separated_from_transaciton(b):
|
||||
'hurt you']}
|
||||
|
||||
tx = Create.generate([alice.public_key],
|
||||
[([bob.public_key], 1)],
|
||||
metadata=None,
|
||||
asset=asset) \
|
||||
[([bob.public_key], 1)],
|
||||
metadata=None,
|
||||
asset=asset) \
|
||||
.sign([alice.private_key])
|
||||
|
||||
# with store_bulk_transactions we use `insert_many` where PyMongo
|
||||
@ -92,8 +90,8 @@ def test_validation_error(b):
|
||||
|
||||
alice = generate_key_pair()
|
||||
tx = Create.generate([alice.public_key],
|
||||
[([alice.public_key], 1)],
|
||||
asset=None) \
|
||||
[([alice.public_key], 1)],
|
||||
asset=None) \
|
||||
.sign([alice.private_key]).to_dict()
|
||||
|
||||
tx['metadata'] = ''
|
||||
@ -107,8 +105,8 @@ def test_write_and_post_transaction(mock_post, b):
|
||||
|
||||
alice = generate_key_pair()
|
||||
tx = Create.generate([alice.public_key],
|
||||
[([alice.public_key], 1)],
|
||||
asset=None) \
|
||||
[([alice.public_key], 1)],
|
||||
asset=None) \
|
||||
.sign([alice.private_key]).to_dict()
|
||||
|
||||
tx = b.validate_transaction(tx)
|
||||
@ -131,8 +129,8 @@ def test_post_transaction_valid_modes(mock_post, b, mode):
|
||||
from planetmint.transactions.common.crypto import generate_key_pair
|
||||
alice = generate_key_pair()
|
||||
tx = Create.generate([alice.public_key],
|
||||
[([alice.public_key], 1)],
|
||||
asset=None) \
|
||||
[([alice.public_key], 1)],
|
||||
asset=None) \
|
||||
.sign([alice.private_key]).to_dict()
|
||||
tx = b.validate_transaction(tx)
|
||||
b.write_transaction(tx, mode)
|
||||
@ -146,8 +144,8 @@ def test_post_transaction_invalid_mode(b):
|
||||
from planetmint.transactions.common.exceptions import ValidationError
|
||||
alice = generate_key_pair()
|
||||
tx = Create.generate([alice.public_key],
|
||||
[([alice.public_key], 1)],
|
||||
asset=None) \
|
||||
[([alice.public_key], 1)],
|
||||
asset=None) \
|
||||
.sign([alice.private_key]).to_dict()
|
||||
tx = b.validate_transaction(tx)
|
||||
with pytest.raises(ValidationError):
|
||||
@ -342,7 +340,7 @@ def test_delete_many_unspent_outputs(b, utxoset):
|
||||
assert utxo_collection.count_documents(
|
||||
{'transaction_id': 'a', 'output_index': 1}) == 1
|
||||
else: # TODO It looks ugly because query.get_unspent_outputs function, has not yet implemented query parameter.
|
||||
utx_space = b.connection.space("utxos")
|
||||
utx_space = b.connection.get_space("utxos")
|
||||
res1 = utx_space.select(['a', 0], index="id_search").data
|
||||
res2 = utx_space.select(['b', 0], index="id_search").data
|
||||
assert len(res1) + len(res2) == 0
|
||||
@ -350,7 +348,6 @@ def test_delete_many_unspent_outputs(b, utxoset):
|
||||
assert len(res3) == 1
|
||||
|
||||
|
||||
|
||||
@pytest.mark.bdb
|
||||
def test_store_zero_unspent_output(b, utxo_collection):
|
||||
res = b.store_unspent_outputs()
|
||||
@ -370,12 +367,12 @@ def test_store_one_unspent_output(b, unspent_output_1, utxo_collection):
|
||||
'output_index': unspent_output_1['output_index']}
|
||||
) == 1
|
||||
else:
|
||||
utx_space = b.connection.space("utxos")
|
||||
res = utx_space.select([unspent_output_1["transaction_id"], unspent_output_1["output_index"]], index="id_search")
|
||||
utx_space = b.connection.get_space("utxos")
|
||||
res = utx_space.select([unspent_output_1["transaction_id"], unspent_output_1["output_index"]],
|
||||
index="id_search")
|
||||
assert len(res.data) == 1
|
||||
|
||||
|
||||
|
||||
@pytest.mark.bdb
|
||||
def test_store_many_unspent_outputs(b, unspent_outputs, utxo_collection):
|
||||
from planetmint.backend.tarantool.connection import TarantoolDBConnection
|
||||
@ -387,7 +384,7 @@ def test_store_many_unspent_outputs(b, unspent_outputs, utxo_collection):
|
||||
{'transaction_id': unspent_outputs[0]['transaction_id']}
|
||||
) == 3
|
||||
else:
|
||||
utxo_space = b.connection.space("utxos") # .select([], index="transaction_search").data
|
||||
utxo_space = b.connection.get_space("utxos") # .select([], index="transaction_search").data
|
||||
res = utxo_space.select([unspent_outputs[0]["transaction_id"]], index="transaction_search")
|
||||
assert len(res.data) == 3
|
||||
|
||||
@ -413,23 +410,23 @@ def test_get_spent_transaction_critical_double_spend(b, alice, bob, carol):
|
||||
asset = {'test': 'asset'}
|
||||
|
||||
tx = Create.generate([alice.public_key],
|
||||
[([alice.public_key], 1)],
|
||||
asset=asset) \
|
||||
[([alice.public_key], 1)],
|
||||
asset=asset) \
|
||||
.sign([alice.private_key])
|
||||
|
||||
tx_transfer = Transfer.generate(tx.to_inputs(),
|
||||
[([bob.public_key], 1)],
|
||||
asset_id=tx.id) \
|
||||
[([bob.public_key], 1)],
|
||||
asset_id=tx.id) \
|
||||
.sign([alice.private_key])
|
||||
|
||||
double_spend = Transfer.generate(tx.to_inputs(),
|
||||
[([carol.public_key], 1)],
|
||||
asset_id=tx.id) \
|
||||
[([carol.public_key], 1)],
|
||||
asset_id=tx.id) \
|
||||
.sign([alice.private_key])
|
||||
|
||||
same_input_double_spend = Transfer.generate(tx.to_inputs() + tx.to_inputs(),
|
||||
[([bob.public_key], 1)],
|
||||
asset_id=tx.id) \
|
||||
[([bob.public_key], 1)],
|
||||
asset_id=tx.id) \
|
||||
.sign([alice.private_key])
|
||||
|
||||
b.store_bulk_transactions([tx])
|
||||
@ -461,11 +458,11 @@ def test_validation_with_transaction_buffer(b):
|
||||
|
||||
create_tx = Create.generate([pub_key], [([pub_key], 10)]).sign([priv_key])
|
||||
transfer_tx = Transfer.generate(create_tx.to_inputs(),
|
||||
[([pub_key], 10)],
|
||||
asset_id=create_tx.id).sign([priv_key])
|
||||
[([pub_key], 10)],
|
||||
asset_id=create_tx.id).sign([priv_key])
|
||||
double_spend = Transfer.generate(create_tx.to_inputs(),
|
||||
[([pub_key], 10)],
|
||||
asset_id=create_tx.id).sign([priv_key])
|
||||
[([pub_key], 10)],
|
||||
asset_id=create_tx.id).sign([priv_key])
|
||||
|
||||
assert b.is_valid_transaction(create_tx)
|
||||
assert b.is_valid_transaction(transfer_tx, [create_tx])
|
||||
@ -517,8 +514,8 @@ def test_get_spent_key_order(b, user_pk, user_sk, user2_pk, user2_sk):
|
||||
bob = generate_key_pair()
|
||||
|
||||
tx1 = Create.generate([user_pk],
|
||||
[([alice.public_key], 3), ([user_pk], 2)],
|
||||
asset=None) \
|
||||
[([alice.public_key], 3), ([user_pk], 2)],
|
||||
asset=None) \
|
||||
.sign([user_sk])
|
||||
b.store_bulk_transactions([tx1])
|
||||
assert tx1.validate(b)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user