From bdfa059046c8e6f4547eb3fd460a6bcc8ccfbced Mon Sep 17 00:00:00 2001 From: codegeschrei Date: Wed, 8 Aug 2018 12:17:44 +0200 Subject: [PATCH] Problem: some tests are not activated (#2390) * Problem: core.py contains an unused class, `Bigchain` Solution: Remove core.py. Refactor BigchainDB Class to remove inheritance from Bigchain. * Problem: core.py contains an unused class, `Bigchain` Solution: Remove core.py. Refactor BigchainDB Class to remove inheritance from Bigchain. * Fixed flake8 complaint about too many blank lines * Attempting to fix Sphinx docs. This may result in some redundant commits, as I don't know what I'm doing, and I can't experiment without running the CI... Sorry in advance! * Attempting to fix Sphinx docs. This may result in some redundant commits, as I don't know what I'm doing, and I can't experiment without running the CI... Sorry in advance! * Updating from master changed BigchainDB.process_post_response to a private method, so I had to align with that. * Fixed a couple stale references to bigchaindb.Bigchain in docstrings * Missed a reference to `Bigchain` in a patch call... * Problem: some tests are not activated Solution: activate and remove or fix tests * Problem: accidentally un-skipped test_get_blocks_status_containing_tx during merge Solution: Replaced the skip --- tests/test_core.py | 25 ++++++------------------- tests/test_txlist.py | 39 ++++++++++----------------------------- 2 files changed, 16 insertions(+), 48 deletions(-) diff --git a/tests/test_core.py b/tests/test_core.py index 7a648d83..45c369ad 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1,6 +1,5 @@ import pytest - pytestmark = pytest.mark.tendermint @@ -21,6 +20,10 @@ def config(request, monkeypatch): 'connection_timeout': 5000, 'max_tries': 3 }, + 'tendermint': { + 'host': 'localhost', + 'port': 26657, + }, 'CONFIGURED': True, } @@ -29,7 +32,6 @@ def config(request, monkeypatch): return config -@pytest.mark.skipif(reason='will be fixed in another PR') def test_bigchain_class_default_initialization(config): from bigchaindb import BigchainDB from bigchaindb.consensus import BaseConsensusRules @@ -42,8 +44,7 @@ def test_bigchain_class_default_initialization(config): assert bigchain.consensus == BaseConsensusRules -@pytest.mark.skipif(reason='will be fixed in another PR') -def test_bigchain_class_initialization_with_parameters(config): +def test_bigchain_class_initialization_with_parameters(): from bigchaindb import BigchainDB from bigchaindb.backend import connect from bigchaindb.consensus import BaseConsensusRules @@ -54,7 +55,7 @@ def test_bigchain_class_initialization_with_parameters(config): 'name': 'this_is_the_db_name', } connection = connect(**init_db_kwargs) - bigchain = BigchainDB(connection=connection, **init_db_kwargs) + bigchain = BigchainDB(connection=connection) assert bigchain.connection == connection assert bigchain.connection.host == init_db_kwargs['host'] assert bigchain.connection.port == init_db_kwargs['port'] @@ -62,20 +63,6 @@ def test_bigchain_class_initialization_with_parameters(config): assert bigchain.consensus == BaseConsensusRules -@pytest.mark.skipif(reason='will be fixed in another PR') -def test_get_blocks_status_containing_tx(monkeypatch): - from bigchaindb.backend import query as backend_query - from bigchaindb import BigchainDB - blocks = [ - {'id': 1}, {'id': 2} - ] - monkeypatch.setattr(backend_query, 'get_blocks_status_from_transaction', lambda x: blocks) - monkeypatch.setattr(BigchainDB, 'block_election_status', lambda x, y, z: BigchainDB.BLOCK_VALID) - bigchain = BigchainDB(public_key='pubkey', private_key='privkey') - with pytest.raises(Exception): - bigchain.get_blocks_status_containing_tx('txid') - - @pytest.mark.genesis def test_get_spent_issue_1271(b, alice, bob, carol): from bigchaindb.models import Transaction diff --git a/tests/test_txlist.py b/tests/test_txlist.py index 61c31bb8..7b4f4d5d 100644 --- a/tests/test_txlist.py +++ b/tests/test_txlist.py @@ -4,46 +4,27 @@ This test module defines it's own fixture which is used by all the tests. """ import pytest +pytestmark = pytest.mark.tendermint + @pytest.fixture -def txlist(b, user_pk, user2_pk, user_sk, user2_sk, genesis_block): +def txlist(b, user_pk, user2_pk, user_sk, user2_sk): from bigchaindb.models import Transaction - prev_block_id = genesis_block.id - # Create first block with CREATE transactions + # Create two CREATE transactions create1 = Transaction.create([user_pk], [([user2_pk], 6)]) \ .sign([user_sk]) + create2 = Transaction.create([user2_pk], [([user2_pk], 5), ([user_pk], 5)]) \ - .sign([user2_sk]) - block1 = b.create_block([create1, create2]) - b.write_block(block1) + .sign([user2_sk]) - # Create second block with TRANSFER transactions + # Create a TRANSFER transactions transfer1 = Transaction.transfer(create1.to_inputs(), [([user_pk], 8)], create1.id).sign([user2_sk]) - block2 = b.create_block([transfer1]) - b.write_block(block2) - # Create block with double spend - tx_doublespend = Transaction.transfer(create1.to_inputs(), [([user_pk], 9)], - create1.id).sign([user2_sk]) - block_doublespend = b.create_block([tx_doublespend]) - b.write_block(block_doublespend) - - # Vote on all the blocks - prev_block_id = genesis_block.id - for bid in [block1.id, block2.id]: - vote = b.vote(bid, prev_block_id, True) - prev_block_id = bid - b.write_vote(vote) - - # Create undecided block - untx = Transaction.create([user_pk], [([user2_pk], 7)]) \ - .sign([user_sk]) - block_undecided = b.create_block([untx]) - b.write_block(block_undecided) + b.store_bulk_transactions([create1, create2, transfer1]) return type('', (), { 'create1': create1, @@ -54,8 +35,8 @@ def txlist(b, user_pk, user2_pk, user_sk, user2_sk, genesis_block): @pytest.mark.bdb def test_get_txlist_by_asset(b, txlist): res = b.get_transactions_filtered(txlist.create1.id) - assert set(tx.id for tx in res) == set([txlist.transfer1.id, - txlist.create1.id]) + assert sorted(set(tx.id for tx in res)) == sorted( + set([txlist.transfer1.id, txlist.create1.id])) @pytest.mark.bdb