mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Voting pipeline now checks for duplicated transactions in blocks during
validation.
This commit is contained in:
parent
cd0a2dcdb7
commit
cb87221bdf
@ -187,6 +187,11 @@ class Block(object):
|
|||||||
if not self.is_signature_valid():
|
if not self.is_signature_valid():
|
||||||
raise InvalidSignature('Invalid block signature')
|
raise InvalidSignature('Invalid block signature')
|
||||||
|
|
||||||
|
# Check that the block contains no duplicated transactions
|
||||||
|
txids = [tx.id for tx in self.transactions]
|
||||||
|
if len(txids) != len(set(txids)):
|
||||||
|
raise DuplicateTransaction('Block has duplicate transaction')
|
||||||
|
|
||||||
def _validate_block_transactions(self, bigchain):
|
def _validate_block_transactions(self, bigchain):
|
||||||
"""Validate Block transactions.
|
"""Validate Block transactions.
|
||||||
|
|
||||||
@ -196,10 +201,6 @@ class Block(object):
|
|||||||
Raises:
|
Raises:
|
||||||
ValidationError: If an invalid transaction is found
|
ValidationError: If an invalid transaction is found
|
||||||
"""
|
"""
|
||||||
txids = [tx.id for tx in self.transactions]
|
|
||||||
if len(txids) != len(set(txids)):
|
|
||||||
raise DuplicateTransaction('Block has duplicate transaction')
|
|
||||||
|
|
||||||
for tx in self.transactions:
|
for tx in self.transactions:
|
||||||
# If a transaction is not valid, `validate_transactions` will
|
# If a transaction is not valid, `validate_transactions` will
|
||||||
# throw an an exception and block validation will be canceled.
|
# throw an an exception and block validation will be canceled.
|
||||||
|
@ -111,6 +111,18 @@ def test_validate_block_with_invalid_id(b):
|
|||||||
assert invalid_dummy_tx == [vote_obj.invalid_dummy_tx]
|
assert invalid_dummy_tx == [vote_obj.invalid_dummy_tx]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.genesis
|
||||||
|
def test_validate_block_with_duplicated_transactions(b):
|
||||||
|
from bigchaindb.pipelines import vote
|
||||||
|
|
||||||
|
tx = dummy_tx(b)
|
||||||
|
block = b.create_block([tx, tx]).to_dict()
|
||||||
|
|
||||||
|
vote_obj = vote.Vote()
|
||||||
|
block_id, invalid_dummy_tx = vote_obj.validate_block(block)
|
||||||
|
assert invalid_dummy_tx == [vote_obj.invalid_dummy_tx]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.genesis
|
@pytest.mark.genesis
|
||||||
def test_validate_block_with_invalid_signature(b):
|
def test_validate_block_with_invalid_signature(b):
|
||||||
from bigchaindb.pipelines import vote
|
from bigchaindb.pipelines import vote
|
||||||
|
@ -152,4 +152,4 @@ class TestBlockModel(object):
|
|||||||
tx = Transaction.create([b.me], [([b.me], 1)])
|
tx = Transaction.create([b.me], [([b.me], 1)])
|
||||||
block = b.create_block([tx, tx])
|
block = b.create_block([tx, tx])
|
||||||
with raises(DuplicateTransaction):
|
with raises(DuplicateTransaction):
|
||||||
block._validate_block_transactions(b)
|
block._validate_block(b)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user