From 2c6c082f5231e65c2b5bd923c6dddf4d527b08a1 Mon Sep 17 00:00:00 2001 From: codegeschrei Date: Tue, 14 Aug 2018 15:14:39 +0200 Subject: [PATCH] Problem: we don't test the transaction split Solution: undelete `test_store_transaction` --- tests/tendermint/test_lib.py | 49 ++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/tendermint/test_lib.py b/tests/tendermint/test_lib.py index 60bbff35..9ceed73d 100644 --- a/tests/tendermint/test_lib.py +++ b/tests/tendermint/test_lib.py @@ -183,6 +183,55 @@ def test_update_utxoset(tb, signed_create_tx, signed_transfer_tx, db_context): assert utxo['output_index'] == 0 +@pytest.mark.bdb +def test_store_transaction(mocker, tb, signed_create_tx, + signed_transfer_tx, db_context): + mocked_store_asset = mocker.patch('bigchaindb.backend.query.store_assets') + mocked_store_metadata = mocker.patch( + 'bigchaindb.backend.query.store_metadatas') + mocked_store_transaction = mocker.patch( + 'bigchaindb.backend.query.store_transactions') + tb.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( + tb.connection, + [{'id': signed_create_tx.id, 'data': signed_create_tx.asset['data']}], + ) + mocked_store_metadata.assert_called_once_with( + tb.connection, + [{'id': signed_create_tx.id, 'metadata': signed_create_tx.metadata}], + ) + mocked_store_transaction.assert_called_once_with( + tb.connection, + [{k: v for k, v in signed_create_tx.to_dict().items() + if k not in ('asset', 'metadata')}], + ) + mocked_store_asset.reset_mock() + mocked_store_metadata.reset_mock() + mocked_store_transaction.reset_mock() + tb.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( + tb.connection, + [{'id': signed_transfer_tx.id, 'metadata': signed_transfer_tx.metadata}], + ) + mocked_store_transaction.assert_called_once_with( + tb.connection, + [{k: v for k, v in signed_transfer_tx.to_dict().items() + if k != 'metadata'}], + ) + + @pytest.mark.bdb def test_store_bulk_transaction(mocker, tb, signed_create_tx, signed_transfer_tx, db_context):