From 5695672ccae464ca9941f8e7751fec03ff903731 Mon Sep 17 00:00:00 2001 From: codegeschrei Date: Wed, 11 Jul 2018 11:20:56 +0200 Subject: [PATCH] Problem: transaction parameter are not required anymore Solution: remove transaction parameter --- bigchaindb/models.py | 4 ++-- bigchaindb/tendermint/lib.py | 28 +++++----------------------- bigchaindb/web/views/transactions.py | 2 +- tests/db/test_bigchain_api.py | 1 - tests/web/test_transactions.py | 19 ------------------- 5 files changed, 8 insertions(+), 46 deletions(-) diff --git a/bigchaindb/models.py b/bigchaindb/models.py index 33689d0c..f1a3cec1 100644 --- a/bigchaindb/models.py +++ b/bigchaindb/models.py @@ -45,13 +45,13 @@ class Transaction(Transaction): # transactions in current round if ctxn.id == input_txid: input_tx = ctxn - status = bigchain.TX_VALID + status = 'valid' if input_tx is None: raise InputDoesNotExist("input `{}` doesn't exist" .format(input_txid)) - if status != bigchain.TX_VALID: + if status != 'valid': raise TransactionNotInValidBlock( 'input `{}` does not exist in a valid block'.format( input_txid)) diff --git a/bigchaindb/tendermint/lib.py b/bigchaindb/tendermint/lib.py index 5fddaf2b..badcedca 100644 --- a/bigchaindb/tendermint/lib.py +++ b/bigchaindb/tendermint/lib.py @@ -35,12 +35,6 @@ class BigchainDB(object): Create, read, sign, write transactions to the database """ - TX_VALID = 'valid' - """return if a tx is in valid block""" - - TX_UNDECIDED = 'undecided' - """return if tx is in undecided block""" - def __init__(self, connection=None): """Initialize the Bigchain instance @@ -265,19 +259,15 @@ class BigchainDB(object): transaction = Transaction.from_dict(transaction) if include_status: - return transaction, self.TX_VALID if transaction else None + return transaction, 'valid' if transaction else None else: return transaction def get_transactions_filtered(self, asset_id, operation=None): """Get a list of transactions filtered on some criteria """ - txids = backend.query.get_txids_filtered(self.connection, asset_id, - operation) - for txid in txids: - tx, status = self.get_transaction(txid, True) - if status == self.TX_VALID: - yield tx + return backend.query.get_txids_filtered(self.connection, asset_id, + operation) def get_outputs_filtered(self, owner, spent=None): """Get a list of output links filtered on some criteria @@ -416,16 +406,8 @@ class BigchainDB(object): Returns: iter: An iterator of assets that match the text search. """ - objects = backend.query.text_search(self.connection, search, limit=limit, - table=table) - - # TODO: This is not efficient. There may be a more efficient way to - # query by storing block ids with the assets and using fastquery. - # See https://github.com/bigchaindb/bigchaindb/issues/1496 - for obj in objects: - tx, status = self.get_transaction(obj['id'], True) - if status == self.TX_VALID: - yield obj + return backend.query.text_search(self.connection, search, limit=limit, + table=table) def get_assets(self, asset_ids): """Return a list of assets that match the asset_ids diff --git a/bigchaindb/web/views/transactions.py b/bigchaindb/web/views/transactions.py index 61a592ee..1a5f24f9 100644 --- a/bigchaindb/web/views/transactions.py +++ b/bigchaindb/web/views/transactions.py @@ -30,7 +30,7 @@ class TransactionApi(Resource): with pool() as bigchain: tx, status = bigchain.get_transaction(tx_id, include_status=True) - if not tx or status is not bigchain.TX_VALID: + if not tx: return make_error(404) return tx.to_dict() diff --git a/tests/db/test_bigchain_api.py b/tests/db/test_bigchain_api.py index eb9e1f7d..268ed47d 100644 --- a/tests/db/test_bigchain_api.py +++ b/tests/db/test_bigchain_api.py @@ -313,7 +313,6 @@ class TestBigchainApi(object): response, status = b.get_transaction(tx.id, include_status=True) # add validity information, which will be returned assert tx.to_dict() == response.to_dict() - assert status == b.TX_UNDECIDED @pytest.mark.usefixtures('inputs') def test_read_transaction_invalid_block(self, b, user_pk, user_sk): diff --git a/tests/web/test_transactions.py b/tests/web/test_transactions.py index ef582978..cf6a0bfb 100644 --- a/tests/web/test_transactions.py +++ b/tests/web/test_transactions.py @@ -402,25 +402,6 @@ def test_transactions_get_list_bad(client): assert client.get(url).status_code == 400 -@pytest.mark.tendermint -def test_return_only_valid_transaction(client): - from bigchaindb.tendermint import BigchainDB - - def get_transaction_patched(status): - def inner(self, tx_id, include_status): - return {}, status - return inner - - # 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', - get_transaction_patched(BigchainDB.TX_UNDECIDED)): - url = '{}{}'.format(TX_ENDPOINT, '123') - assert client.get(url).status_code == 404 - - @pytest.mark.tendermint @patch('requests.post') @pytest.mark.parametrize('mode', [