diff --git a/tests/commands/test_utils.py b/tests/commands/test_utils.py index e72b4df1..0aafde30 100644 --- a/tests/commands/test_utils.py +++ b/tests/commands/test_utils.py @@ -6,6 +6,8 @@ import pytest from unittest.mock import patch +pytestmark = pytest.mark.tendermint + @pytest.fixture def reset_bigchaindb_config(monkeypatch): diff --git a/tests/tendermint/test_lib.py b/tests/tendermint/test_lib.py index d9d9e320..bc5504a7 100644 --- a/tests/tendermint/test_lib.py +++ b/tests/tendermint/test_lib.py @@ -18,6 +18,7 @@ pytestmark = pytest.mark.tendermint @pytest.mark.bdb def test_asset_is_separated_from_transaciton(b): + import copy from bigchaindb.models import Transaction from bigchaindb.common.crypto import generate_key_pair @@ -39,10 +40,12 @@ def test_asset_is_separated_from_transaciton(b): asset=asset)\ .sign([alice.private_key]) - b.store_transaction(tx) + tx_dict = copy.deepcopy(tx.to_dict()) + + b.store_bulk_transactions([tx]) assert 'asset' not in backend.query.get_transaction(b.connection, tx.id) assert backend.query.get_asset(b.connection, tx.id)['data'] == asset - assert b.get_transaction(tx.id) == tx + assert b.get_transaction(tx.id).to_dict() == tx_dict @pytest.mark.bdb @@ -176,54 +179,6 @@ 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_asset') - mocked_store_metadata = mocker.patch( - 'bigchaindb.backend.query.store_metadatas') - mocked_store_transaction = mocker.patch( - 'bigchaindb.backend.query.store_transaction') - tb.store_transaction(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_transaction(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): diff --git a/tests/test_core.py b/tests/test_core.py index 45c369ad..274e2285 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -3,7 +3,6 @@ import pytest pytestmark = pytest.mark.tendermint -@pytest.mark.skipif(reason='will be fixed in another PR') @pytest.fixture def config(request, monkeypatch): backend = request.config.getoption('--database-backend') diff --git a/tests/web/test_assets.py b/tests/web/test_assets.py index 61134e8f..c3c792f1 100644 --- a/tests/web/test_assets.py +++ b/tests/web/test_assets.py @@ -33,7 +33,7 @@ def test_get_assets_tendermint(client, tb, alice): tx = Transaction.create([alice.public_key], [([alice.public_key], 1)], asset=asset).sign([alice.private_key]) - tb.store_transaction(tx) + tb.store_bulk_transactions([tx]) # test that asset is returned res = client.get(ASSETS_ENDPOINT + '?search=abc') @@ -60,8 +60,8 @@ def test_get_assets_limit_tendermint(client, tb, alice): tx2 = Transaction.create([alice.public_key], [([alice.public_key], 1)], asset=asset2).sign([alice.private_key]) - b.store_transaction(tx1) - b.store_transaction(tx2) + b.store_bulk_transactions([tx1]) + b.store_bulk_transactions([tx2]) # test that both assets are returned without limit res = client.get(ASSETS_ENDPOINT + '?search=abc') diff --git a/tests/web/test_block_tendermint.py b/tests/web/test_block_tendermint.py index d627c1fd..812d34b5 100644 --- a/tests/web/test_block_tendermint.py +++ b/tests/web/test_block_tendermint.py @@ -11,10 +11,12 @@ pytestmark = pytest.mark.tendermint @pytest.mark.bdb @pytest.mark.usefixtures('inputs') def test_get_block_endpoint(tb, client, alice): + import copy b = tb tx = Transaction.create([alice.public_key], [([alice.public_key], 1)], asset={'cycle': 'hero'}) tx = tx.sign([alice.private_key]) - b.store_transaction(tx) + tx_dict = copy.deepcopy(tx.to_dict()) + b.store_bulk_transactions([tx]) block = Block(app_hash='random_utxo', height=31, @@ -22,7 +24,7 @@ def test_get_block_endpoint(tb, client, alice): b.store_block(block._asdict()) res = client.get(BLOCKS_ENDPOINT + str(block.height)) - expected_response = {'height': block.height, 'transactions': [tx.to_dict()]} + expected_response = {'height': block.height, 'transactions': [tx_dict]} assert res.json == expected_response assert res.status_code == 200 @@ -42,7 +44,7 @@ def test_get_block_containing_transaction(tb, client, alice): b = tb tx = Transaction.create([alice.public_key], [([alice.public_key], 1)], asset={'cycle': 'hero'}) tx = tx.sign([alice.private_key]) - b.store_transaction(tx) + b.store_bulk_transactions([tx]) block = Block(app_hash='random_utxo', height=13, diff --git a/tests/web/test_metadata.py b/tests/web/test_metadata.py index db15bf52..c8af1859 100644 --- a/tests/web/test_metadata.py +++ b/tests/web/test_metadata.py @@ -35,7 +35,7 @@ def test_get_metadata_tendermint(client, tb, alice): tx = Transaction.create([alice.public_key], [([alice.public_key], 1)], metadata=metadata, asset=asset).sign([alice.private_key]) - b.store_transaction(tx) + b.store_bulk_transactions([tx]) # test that metadata is returned res = client.get(METADATA_ENDPOINT + '?search=my_meta') @@ -59,13 +59,13 @@ def test_get_metadata_limit_tendermint(client, tb, alice): meta1 = {'key': 'meta 1'} tx1 = Transaction.create([alice.public_key], [([alice.public_key], 1)], metadata=meta1, asset=asset1).sign([alice.private_key]) - b.store_transaction(tx1) + b.store_bulk_transactions([tx1]) asset2 = {'msg': 'abc 2'} meta2 = {'key': 'meta 2'} tx2 = Transaction.create([alice.public_key], [([alice.public_key], 1)], metadata=meta2, asset=asset2).sign([alice.private_key]) - b.store_transaction(tx2) + b.store_bulk_transactions([tx2]) # test that both assets are returned without limit res = client.get(METADATA_ENDPOINT + '?search=meta')