From f66f30f4cb6375ac1e547ce78023ae233e74bf5d Mon Sep 17 00:00:00 2001 From: z-bowen Date: Fri, 31 Aug 2018 15:14:52 +0200 Subject: [PATCH 1/2] Problem: Big blocks of commented out code have been around for months Solution: Removed the dead code --- bigchaindb/lib.py | 16 ---------------- tests/tendermint/test_core.py | 7 ------- tests/tendermint/test_lib.py | 23 +++-------------------- 3 files changed, 3 insertions(+), 43 deletions(-) diff --git a/bigchaindb/lib.py b/bigchaindb/lib.py index 05ca3e69..5ba72883 100644 --- a/bigchaindb/lib.py +++ b/bigchaindb/lib.py @@ -98,22 +98,6 @@ class BigchainDB(object): return (500, 'Internal error') return (202, '') - # result = response['result'] - # if mode == self.mode_list[2]: - # return self._process_commit_mode_response(result) - # else: - # status_code = result['code'] - # return self._process_status_code(status_code, - # 'Error while processing transaction') - - # def _process_commit_mode_response(self, result): - # check_tx_status_code = result['check_tx']['code'] - # if check_tx_status_code == 0: - # deliver_tx_status_code = result['deliver_tx']['code'] - # return self._process_status_code(deliver_tx_status_code, - # 'Error while commiting the transaction') - # else: - # return (500, 'Error while validating the transaction') def process_status_code(self, status_code, failure_msg): return (202, '') if status_code == 0 else (500, failure_msg) diff --git a/tests/tendermint/test_core.py b/tests/tendermint/test_core.py index 40958aa2..19e92ca8 100644 --- a/tests/tendermint/test_core.py +++ b/tests/tendermint/test_core.py @@ -84,13 +84,6 @@ def test_deliver_tx__valid_create_updates_db(b, init_chain_request): app.commit() assert b.get_transaction(tx.id).id == tx.id - # unspent_outputs = b.get_unspent_outputs() - # unspent_output = next(unspent_outputs) - # expected_unspent_output = next(tx.unspent_outputs)._asdict() - # assert unspent_output == expected_unspent_output - # with pytest.raises(StopIteration): - # next(unspent_outputs) - def test_deliver_tx__double_spend_fails(b, init_chain_request): from bigchaindb import App diff --git a/tests/tendermint/test_lib.py b/tests/tendermint/test_lib.py index 4e8ff6b3..cee5a062 100644 --- a/tests/tendermint/test_lib.py +++ b/tests/tendermint/test_lib.py @@ -195,12 +195,6 @@ def test_store_transaction(mocker, b, signed_create_tx, mocked_store_transaction = mocker.patch( 'bigchaindb.backend.query.store_transactions') b.store_bulk_transactions([signed_create_tx]) - # mongo_client = MongoClient(host=db_context.host, port=db_context.port) - # utxoset = mongo_client[db_context.name]['utxos'] - # assert utxoset.count() == 1 - # utxo = utxoset.find_one() - # assert utxo['transaction_id'] == signed_create_tx.id - # assert utxo['output_index'] == 0 mocked_store_asset.assert_called_once_with( b.connection, @@ -219,10 +213,7 @@ def test_store_transaction(mocker, b, signed_create_tx, mocked_store_metadata.reset_mock() mocked_store_transaction.reset_mock() b.store_bulk_transactions([signed_transfer_tx]) - # assert utxoset.count() == 1 - # utxo = utxoset.find_one() - # assert utxo['transaction_id'] == signed_transfer_tx.id - # assert utxo['output_index'] == 0 + assert not mocked_store_asset.called mocked_store_metadata.asser_called_once_with( b.connection, @@ -245,12 +236,7 @@ def test_store_bulk_transaction(mocker, b, signed_create_tx, mocked_store_transactions = mocker.patch( 'bigchaindb.backend.query.store_transactions') b.store_bulk_transactions((signed_create_tx,)) - # mongo_client = MongoClient(host=db_context.host, port=db_context.port) - # utxoset = mongo_client[db_context.name]['utxos'] - # assert utxoset.count() == 1 - # utxo = utxoset.find_one() - # assert utxo['transaction_id'] == signed_create_tx.id - # assert utxo['output_index'] == 0 + mocked_store_assets.assert_called_once_with( b.connection, [{'id': signed_create_tx.id, 'data': signed_create_tx.asset['data']}], @@ -268,10 +254,7 @@ def test_store_bulk_transaction(mocker, b, signed_create_tx, mocked_store_metadata.reset_mock() mocked_store_transactions.reset_mock() b.store_bulk_transactions((signed_transfer_tx,)) - # assert utxoset.count() == 1 - # utxo = utxoset.find_one() - # assert utxo['transaction_id'] == signed_transfer_tx.id - # assert utxo['output_index'] == 0 + assert not mocked_store_assets.called mocked_store_metadata.asser_called_once_with( b.connection, From bec2abeb55daaeb376109279c2bb450b4efa74ca Mon Sep 17 00:00:00 2001 From: z-bowen Date: Fri, 31 Aug 2018 15:16:05 +0200 Subject: [PATCH 2/2] Problem: TODO to improve error reporting in one of the queries Solution: Raise an exception with some info about what failed --- bigchaindb/backend/localmongodb/query.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bigchaindb/backend/localmongodb/query.py b/bigchaindb/backend/localmongodb/query.py index 29993b30..4e7aad6f 100644 --- a/bigchaindb/backend/localmongodb/query.py +++ b/bigchaindb/backend/localmongodb/query.py @@ -7,6 +7,7 @@ from pymongo import DESCENDING from bigchaindb import backend +from bigchaindb.backend import exceptions from bigchaindb.backend.exceptions import DuplicateKeyError from bigchaindb.backend.utils import module_dispatch_registrar from bigchaindb.backend.localmongodb.connection import LocalMongoDBConnection @@ -227,8 +228,10 @@ def store_unspent_outputs(conn, *unspent_outputs): ordered=False, ) ) - except DuplicateKeyError: - # TODO log warning at least + except DuplicateKeyError as err: + raise exceptions.DuplicateKeyError( + f'Duplicate key in transactions list {unspent_outputs}. Exception raised with error {err}' + ) pass