mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
restore tx validation in block
This commit is contained in:
parent
b6ae91c541
commit
17cf9178ce
@ -12,7 +12,7 @@ from multipipes import Pipeline, Node, Pipe
|
||||
import bigchaindb
|
||||
from bigchaindb import backend
|
||||
from bigchaindb.backend.changefeed import ChangeFeed
|
||||
from bigchaindb.models import FastTransaction
|
||||
from bigchaindb.models import Transaction
|
||||
from bigchaindb.common.exceptions import ValidationError
|
||||
from bigchaindb import Bigchain
|
||||
|
||||
@ -57,11 +57,11 @@ class BlockPipeline:
|
||||
tx (dict): the transaction to validate.
|
||||
|
||||
Returns:
|
||||
:class:`~bigchaindb.models.FastTransaction`: The transaction if valid,
|
||||
:class:`~bigchaindb.models.Transaction`: The transaction if valid,
|
||||
``None`` otherwise.
|
||||
"""
|
||||
try:
|
||||
tx = FastTransaction(tx)
|
||||
tx = Transaction.from_dict(tx)
|
||||
except ValidationError:
|
||||
return None
|
||||
|
||||
@ -71,7 +71,14 @@ class BlockPipeline:
|
||||
self.bigchain.delete_transaction(tx.id)
|
||||
return None
|
||||
|
||||
return tx
|
||||
# If transaction is not valid it should not be included
|
||||
try:
|
||||
tx.validate(self.bigchain)
|
||||
return tx
|
||||
except ValidationError as e:
|
||||
logger.warning('Invalid tx: %s', e)
|
||||
self.bigchain.delete_transaction(tx.id)
|
||||
return None
|
||||
|
||||
def create(self, tx, timeout=False):
|
||||
"""Create a block.
|
||||
|
@ -28,14 +28,15 @@ def test_filter_by_assignee(b, signed_create_tx):
|
||||
|
||||
|
||||
@pytest.mark.bdb
|
||||
def test_validate_transaction(b):
|
||||
def test_validate_transaction(b, create_tx):
|
||||
from bigchaindb.pipelines.block import BlockPipeline
|
||||
|
||||
# validate_tx doesn't actually validate schema anymore.
|
||||
tx = {'id': 'a'}
|
||||
|
||||
block_maker = BlockPipeline()
|
||||
assert block_maker.validate_tx(tx).data == tx
|
||||
|
||||
assert block_maker.validate_tx(create_tx.to_dict()) is None
|
||||
|
||||
valid_tx = create_tx.sign([b.me_private])
|
||||
assert block_maker.validate_tx(valid_tx.to_dict()) == valid_tx
|
||||
|
||||
|
||||
def test_validate_transaction_handles_exceptions(b, signed_create_tx):
|
||||
@ -49,7 +50,7 @@ def test_validate_transaction_handles_exceptions(b, signed_create_tx):
|
||||
|
||||
tx_dict = signed_create_tx.to_dict()
|
||||
|
||||
with patch('bigchaindb.models.FastTransaction.__init__') as validate:
|
||||
with patch('bigchaindb.models.Transaction.validate') as validate:
|
||||
# Assert that validationerror gets caught
|
||||
validate.side_effect = ValidationError()
|
||||
assert block_maker.validate_tx(tx_dict) is None
|
||||
|
Loading…
x
Reference in New Issue
Block a user