Problem: Block parameters are not required anymore

Solution: remove Block parameters
This commit is contained in:
codegeschrei 2018-07-03 13:51:46 +02:00
parent b08f4f3761
commit 09e66a117a
4 changed files with 6 additions and 49 deletions

View File

@ -35,17 +35,11 @@ class BigchainDB(object):
Create, read, sign, write transactions to the database Create, read, sign, write transactions to the database
""" """
BLOCK_INVALID = 'invalid' TX_VALID = 'valid'
"""return if a block is invalid""" """return if a tx is in valid block"""
BLOCK_VALID = TX_VALID = 'valid' TX_UNDECIDED = 'undecided'
"""return if a block is valid, or tx is in valid block""" """return if tx is in undecided 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"""
def __init__(self, connection=None): def __init__(self, connection=None):
"""Initialize the Bigchain instance """Initialize the Bigchain instance

View File

@ -280,7 +280,6 @@ class TestBigchainApi(object):
@pytest.mark.usefixtures('inputs') @pytest.mark.usefixtures('inputs')
def test_write_transaction(self, b, user_pk, user_sk): def test_write_transaction(self, b, user_pk, user_sk):
from bigchaindb.tendermint import BigchainDB
from bigchaindb.models import Transaction from bigchaindb.models import Transaction
input_tx = b.get_owned_ids(user_pk).pop() 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) tx_from_db, status = b.get_transaction(tx.id, include_status=True)
assert tx_from_db.to_dict() == tx.to_dict() assert tx_from_db.to_dict() == tx.to_dict()
assert status == BigchainDB.TX_IN_BACKLOG
@pytest.mark.usefixtures('inputs') @pytest.mark.usefixtures('inputs')
def test_read_transaction(self, b, user_pk, user_sk): 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 # and a copy of the tx is not in the backlog
assert response is None 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') @pytest.mark.usefixtures('inputs')
def test_genesis_block(self, b): def test_genesis_block(self, b):
from bigchaindb.backend import query from bigchaindb.backend import query

View File

@ -63,7 +63,6 @@ def test_get_blocks_status_containing_tx(monkeypatch):
{'id': 1}, {'id': 2} {'id': 1}, {'id': 2}
] ]
monkeypatch.setattr(backend_query, 'get_blocks_status_from_transaction', lambda x: blocks) 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') bigchain = BigchainDB(public_key='pubkey', private_key='privkey')
with pytest.raises(Exception): with pytest.raises(Exception):
bigchain.get_blocks_status_containing_tx('txid') bigchain.get_blocks_status_containing_tx('txid')

View File

@ -411,8 +411,8 @@ def test_return_only_valid_transaction(client):
return {}, status return {}, status
return inner return inner
# NOTE: `get_transaction` only returns a transaction if it's included in an # NOTE: `get_transaction` only returns a transaction if it's included in a
# UNDECIDED or VALID block, as well as transactions from the backlog. # VALID block.
# As the endpoint uses `get_transaction`, we don't have to test # As the endpoint uses `get_transaction`, we don't have to test
# against invalid transactions here. # against invalid transactions here.
with patch('bigchaindb.tendermint.BigchainDB.get_transaction', with patch('bigchaindb.tendermint.BigchainDB.get_transaction',
@ -420,11 +420,6 @@ def test_return_only_valid_transaction(client):
url = '{}{}'.format(TX_ENDPOINT, '123') url = '{}{}'.format(TX_ENDPOINT, '123')
assert client.get(url).status_code == 404 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 @pytest.mark.tendermint
@patch('requests.post') @patch('requests.post')