From eee5ae3d91ae33914f30b1e2fb2e500a215d80d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Eckel?= Date: Mon, 16 Jan 2023 10:10:29 +0100 Subject: [PATCH] blackified MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jürgen Eckel --- planetmint/backend/models/dbtransaction.py | 6 ++++-- planetmint/backend/tarantool/query.py | 22 +++++++++++++--------- planetmint/lib.py | 2 +- tests/assets/test_digital_assets.py | 2 +- tests/db/test_planetmint_api.py | 1 - tests/tendermint/test_lib.py | 12 ++---------- tests/test_core.py | 2 +- tests/utils.py | 4 +++- 8 files changed, 25 insertions(+), 26 deletions(-) diff --git a/planetmint/backend/models/dbtransaction.py b/planetmint/backend/models/dbtransaction.py index 6515721..8119113 100644 --- a/planetmint/backend/models/dbtransaction.py +++ b/planetmint/backend/models/dbtransaction.py @@ -39,7 +39,9 @@ class DbTransaction: operation=transaction[1], version=transaction[2], metadata=MetaData.from_dict(transaction[3]), - assets=Asset.from_list_dict(transaction[4]) if transaction[2] != "2.0" else Asset.from_dict(transaction[4][0]), + assets=Asset.from_list_dict(transaction[4]) + if transaction[2] != "2.0" + else Asset.from_dict(transaction[4][0]), inputs=Input.from_list_dict(transaction[5]), script=Script.from_dict(transaction[6]), ) @@ -66,7 +68,7 @@ class DbTransaction: "outputs": Output.list_to_dict(self.outputs), "operation": self.operation, "metadata": self.metadata.to_dict() if self.metadata is not None else None, - "assets": Asset.list_to_dict(self.assets) if self.version!="2.0" else Asset.to_dict(self.assets), + "assets": Asset.list_to_dict(self.assets) if self.version != "2.0" else Asset.to_dict(self.assets), "version": self.version, "id": self.id, "script": self.script.to_dict() if self.script is not None else None, diff --git a/planetmint/backend/tarantool/query.py b/planetmint/backend/tarantool/query.py index 74203da..56279aa 100644 --- a/planetmint/backend/tarantool/query.py +++ b/planetmint/backend/tarantool/query.py @@ -31,7 +31,7 @@ from planetmint.backend.tarantool.const import ( TARANT_TABLE_VALIDATOR_SETS, TARANT_TABLE_UTXOS, TARANT_TABLE_PRE_COMMITS, - TARANT_TABLE_ELECTIONS + TARANT_TABLE_ELECTIONS, ) from planetmint.backend.utils import module_dispatch_registrar from planetmint.backend.models import Asset, Block, Output @@ -114,7 +114,7 @@ def store_transaction_outputs(connection, output: Output, index: int) -> str: @register_query(TarantoolDBConnection) -def store_transactions(connection, signed_transactions: list, table = TARANT_TABLE_TRANSACTION): +def store_transactions(connection, signed_transactions: list, table=TARANT_TABLE_TRANSACTION): for transaction in signed_transactions: store_transaction(connection, transaction, table) [ @@ -124,13 +124,13 @@ def store_transactions(connection, signed_transactions: list, table = TARANT_TAB @register_query(TarantoolDBConnection) -def store_transaction(connection, transaction, table = TARANT_TABLE_TRANSACTION): +def store_transaction(connection, transaction, table=TARANT_TABLE_TRANSACTION): scripts = None if TARANT_TABLE_SCRIPT in transaction: scripts = transaction[TARANT_TABLE_SCRIPT] asset_obj = Transaction.get_assets_tag(transaction["version"]) - if( transaction["version"] == "2.0"): - asset_array = [ transaction[asset_obj] ] + if transaction["version"] == "2.0": + asset_array = [transaction[asset_obj]] else: asset_array = transaction[asset_obj] tx = ( @@ -146,7 +146,7 @@ def store_transaction(connection, transaction, table = TARANT_TABLE_TRANSACTION) connection.run(connection.space(table).insert(tx), only_data=False) except Exception as e: logger.info(f"Could not insert transactions: {e}") - if e.args[0] == 3 and e.args[1].startswith('Duplicate key exists in'): + if e.args[0] == 3 and e.args[1].startswith("Duplicate key exists in"): raise CriticalDoubleSpend() else: raise OperationDataInsertionError() @@ -320,7 +320,7 @@ def get_block_with_transaction(connection, txid: str) -> list[Block]: def delete_transactions(connection, txn_ids: list): try: for _id in txn_ids: - _outputs = get_outputs_by_tx_id( connection, _id) + _outputs = get_outputs_by_tx_id(connection, _id) for x in range(len(_outputs)): connection.connect().call("delete_output", (_outputs[x].id)) for _id in txn_ids: @@ -338,7 +338,9 @@ def store_unspent_outputs(connection, *unspent_outputs: list): for utxo in unspent_outputs: try: output = connection.run( - connection.space(TARANT_TABLE_UTXOS).insert((uuid4().hex, utxo["transaction_id"], utxo["output_index"], utxo)) + connection.space(TARANT_TABLE_UTXOS).insert( + (uuid4().hex, utxo["transaction_id"], utxo["output_index"], utxo) + ) ) result.append(output) except Exception as e: @@ -400,7 +402,9 @@ def get_pre_commit_state(connection) -> dict: @register_query(TarantoolDBConnection) def store_validator_set(conn, validators_update: dict): - _validator = conn.run(conn.space(TARANT_TABLE_VALIDATOR_SETS).select(validators_update["height"], index="height", limit=1)) + _validator = conn.run( + conn.space(TARANT_TABLE_VALIDATOR_SETS).select(validators_update["height"], index="height", limit=1) + ) unique_id = uuid4().hex if _validator is None or len(_validator) == 0 else _validator[0][0] try: conn.run( diff --git a/planetmint/lib.py b/planetmint/lib.py index f95619b..334d714 100644 --- a/planetmint/lib.py +++ b/planetmint/lib.py @@ -892,7 +892,7 @@ class Planetmint(object): self.delete_elections(new_height) txns = [self.get_transaction(tx_id) for tx_id in txn_ids] - + txns = [Transaction.from_dict(tx.to_dict()) for tx in txns] elections = self._get_votes(txns) diff --git a/tests/assets/test_digital_assets.py b/tests/assets/test_digital_assets.py index 02507d5..e0e678d 100644 --- a/tests/assets/test_digital_assets.py +++ b/tests/assets/test_digital_assets.py @@ -24,7 +24,7 @@ def test_asset_transfer(b, signed_create_tx, user_pk, user_sk, _bdb): # from planetmint.transactions.common.exceptions import AssetIdMismatch -def test_validate_transfer_asset_id_mismatch(b, signed_create_tx, user_pk, user_sk,_bdb): +def test_validate_transfer_asset_id_mismatch(b, signed_create_tx, user_pk, user_sk, _bdb): from transactions.common.exceptions import AssetIdMismatch tx_transfer = Transfer.generate(signed_create_tx.to_inputs(), [([user_pk], 1)], [signed_create_tx.id]) diff --git a/tests/db/test_planetmint_api.py b/tests/db/test_planetmint_api.py index 2711d31..e0e92eb 100644 --- a/tests/db/test_planetmint_api.py +++ b/tests/db/test_planetmint_api.py @@ -50,7 +50,6 @@ class TestBigchainApi(object): with pytest.raises(CriticalDoubleSpend): b.store_bulk_transactions([transfer_tx2]) - def test_double_inclusion(self, b, alice): from tarantool.error import DatabaseError diff --git a/tests/tendermint/test_lib.py b/tests/tendermint/test_lib.py index cb1e89a..dc04619 100644 --- a/tests/tendermint/test_lib.py +++ b/tests/tendermint/test_lib.py @@ -173,11 +173,7 @@ def test_update_utxoset(b, signed_create_tx, signed_transfer_tx, db_conn): def test_store_transaction(mocker, b, signed_create_tx, signed_transfer_tx): mocked_store_transaction = mocker.patch("planetmint.backend.query.store_transactions") b.store_bulk_transactions([signed_create_tx]) - mocked_store_transaction.assert_any_call( - b.connection, - [signed_create_tx.to_dict()], - "transactions" - ) + mocked_store_transaction.assert_any_call(b.connection, [signed_create_tx.to_dict()], "transactions") mocked_store_transaction.reset_mock() b.store_bulk_transactions([signed_transfer_tx]) @@ -186,11 +182,7 @@ def test_store_transaction(mocker, b, signed_create_tx, signed_transfer_tx): def test_store_bulk_transaction(mocker, b, signed_create_tx, signed_transfer_tx): mocked_store_transactions = mocker.patch("planetmint.backend.query.store_transactions") b.store_bulk_transactions((signed_create_tx,)) - mocked_store_transactions.assert_any_call( - b.connection, - [signed_create_tx.to_dict()], - "transactions" - ) + mocked_store_transactions.assert_any_call(b.connection, [signed_create_tx.to_dict()], "transactions") mocked_store_transactions.reset_mock() b.store_bulk_transactions((signed_transfer_tx,)) diff --git a/tests/test_core.py b/tests/test_core.py index 73f6778..dc1d5e4 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -89,7 +89,7 @@ def test_get_spent_issue_1271(b, alice, bob, carol): assert b.validate_transaction(tx_5) b.store_bulk_transactions([tx_5]) - assert b.get_spent(tx_2.id, 0) == tx_5.to_dict() + assert b.get_spent(tx_2.id, 0) == tx_5.to_dict() assert not b.get_spent(tx_5.id, 0) assert b.get_outputs_filtered(alice.public_key) assert b.get_outputs_filtered(alice.public_key, spent=False) diff --git a/tests/utils.py b/tests/utils.py index 5a37dbc..3fb951f 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -40,7 +40,9 @@ def generate_block(planet): from transactions.common.crypto import generate_key_pair alice = generate_key_pair() - tx = Create.generate([alice.public_key], [([alice.public_key], 1)], assets=[{"data":None}]).sign([alice.private_key]) + tx = Create.generate([alice.public_key], [([alice.public_key], 1)], assets=[{"data": None}]).sign( + [alice.private_key] + ) code, message = planet.write_transaction(tx, BROADCAST_TX_COMMIT) assert code == 202