From 09e66a117a702b8bcc3db700a296d5740673173f Mon Sep 17 00:00:00 2001 From: codegeschrei Date: Tue, 3 Jul 2018 13:51:46 +0200 Subject: [PATCH] Problem: Block parameters are not required anymore Solution: remove Block parameters --- bigchaindb/tendermint/lib.py | 14 ++++---------- tests/db/test_bigchain_api.py | 31 ------------------------------- tests/test_core.py | 1 - tests/web/test_transactions.py | 9 ++------- 4 files changed, 6 insertions(+), 49 deletions(-) diff --git a/bigchaindb/tendermint/lib.py b/bigchaindb/tendermint/lib.py index ed7aec15..5fddaf2b 100644 --- a/bigchaindb/tendermint/lib.py +++ b/bigchaindb/tendermint/lib.py @@ -35,17 +35,11 @@ class BigchainDB(object): Create, read, sign, write transactions to the database """ - BLOCK_INVALID = 'invalid' - """return if a block is invalid""" + TX_VALID = 'valid' + """return if a tx is in valid block""" - BLOCK_VALID = TX_VALID = 'valid' - """return if a block is valid, or tx is in valid block""" - - BLOCK_UNDECIDED = TX_UNDECIDED = 'undecided' - """return if block is undecided, or tx is in undecided block""" - - TX_IN_BACKLOG = 'backlog' - """return if transaction is in backlog""" + TX_UNDECIDED = 'undecided' + """return if tx is in undecided block""" def __init__(self, connection=None): """Initialize the Bigchain instance diff --git a/tests/db/test_bigchain_api.py b/tests/db/test_bigchain_api.py index c285401a..eb9e1f7d 100644 --- a/tests/db/test_bigchain_api.py +++ b/tests/db/test_bigchain_api.py @@ -280,7 +280,6 @@ class TestBigchainApi(object): @pytest.mark.usefixtures('inputs') def test_write_transaction(self, b, user_pk, user_sk): - from bigchaindb.tendermint import BigchainDB from bigchaindb.models import Transaction input_tx = b.get_owned_ids(user_pk).pop() @@ -294,7 +293,6 @@ class TestBigchainApi(object): tx_from_db, status = b.get_transaction(tx.id, include_status=True) assert tx_from_db.to_dict() == tx.to_dict() - assert status == BigchainDB.TX_IN_BACKLOG @pytest.mark.usefixtures('inputs') def test_read_transaction(self, b, user_pk, user_sk): @@ -342,35 +340,6 @@ class TestBigchainApi(object): # and a copy of the tx is not in the backlog assert response is None - @pytest.mark.usefixtures('inputs') - def test_read_transaction_invalid_block_and_backlog(self, b, user_pk, user_sk): - from bigchaindb.models import Transaction - - input_tx = b.get_owned_ids(user_pk).pop() - input_tx = b.get_transaction(input_tx.txid) - inputs = input_tx.to_inputs() - tx = Transaction.transfer(inputs, [([user_pk], 1)], - asset_id=input_tx.id) - tx = tx.sign([user_sk]) - - # Make sure there's a copy of tx in the backlog - b.write_transaction(tx) - - # create block - block = b.create_block([tx]) - b.write_block(block) - - # vote the block invalid - vote = b.vote(block.id, b.get_last_voted_block().id, False) - b.write_vote(vote) - - # a copy of the tx is both in the backlog and in an invalid - # block, so get_transaction should return a transaction, - # and a status of TX_IN_BACKLOG - response, status = b.get_transaction(tx.id, include_status=True) - assert tx.to_dict() == response.to_dict() - assert status == b.TX_IN_BACKLOG - @pytest.mark.usefixtures('inputs') def test_genesis_block(self, b): from bigchaindb.backend import query diff --git a/tests/test_core.py b/tests/test_core.py index 9f6150e6..ee89c11e 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -63,7 +63,6 @@ def test_get_blocks_status_containing_tx(monkeypatch): {'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') diff --git a/tests/web/test_transactions.py b/tests/web/test_transactions.py index 7c52ea94..ef582978 100644 --- a/tests/web/test_transactions.py +++ b/tests/web/test_transactions.py @@ -411,8 +411,8 @@ def test_return_only_valid_transaction(client): return {}, status return inner - # NOTE: `get_transaction` only returns a transaction if it's included in an - # UNDECIDED or VALID block, as well as transactions from the backlog. + # NOTE: `get_transaction` only returns a transaction if it's included in a + # VALID block. # As the endpoint uses `get_transaction`, we don't have to test # against invalid transactions here. with patch('bigchaindb.tendermint.BigchainDB.get_transaction', @@ -420,11 +420,6 @@ def test_return_only_valid_transaction(client): url = '{}{}'.format(TX_ENDPOINT, '123') assert client.get(url).status_code == 404 - with patch('bigchaindb.tendermint.BigchainDB.get_transaction', - get_transaction_patched(BigchainDB.TX_IN_BACKLOG)): - url = '{}{}'.format(TX_ENDPOINT, '123') - assert client.get(url).status_code == 404 - @pytest.mark.tendermint @patch('requests.post')