mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
add call to vote schema validate in consensus.py
This commit is contained in:
parent
855dc7a5e8
commit
c43bf10151
@ -1,4 +1,5 @@
|
||||
from bigchaindb.util import verify_vote_signature
|
||||
from bigchaindb.common.schema import validate_vote_schema, SchemaValidationError
|
||||
|
||||
|
||||
class BaseConsensusRules():
|
||||
@ -19,10 +20,16 @@ class BaseConsensusRules():
|
||||
return block.validate(bigchain)
|
||||
|
||||
@staticmethod
|
||||
def verify_vote_signature(voters, signed_vote):
|
||||
def verify_vote(voters, signed_vote):
|
||||
"""Verify the signature of a vote.
|
||||
|
||||
Refer to the documentation of
|
||||
:func:`bigchaindb.util.verify_signature`.
|
||||
"""
|
||||
try:
|
||||
validate_vote_schema(signed_vote)
|
||||
except SchemaValidationError:
|
||||
# TODO: log this.
|
||||
return False
|
||||
else:
|
||||
return verify_vote_signature(voters, signed_vote)
|
||||
|
@ -648,7 +648,7 @@ class Bigchain(object):
|
||||
prev_block = [vote['vote']['previous_block'] for vote in votes]
|
||||
# vote_validity checks whether a vote is valid
|
||||
# or invalid, e.g. [False, True, True]
|
||||
vote_validity = [self.consensus.verify_vote_signature(voters, vote) for vote in votes]
|
||||
vote_validity = [self.consensus.verify_vote(voters, vote) for vote in votes]
|
||||
|
||||
# element-wise product of stated vote and validity of vote
|
||||
# vote_cast = [True, True, False] and
|
||||
|
@ -17,6 +17,9 @@ def dummy_block(b):
|
||||
return block
|
||||
|
||||
|
||||
DUMMY_SHA3 = '0123456789abcdef' * 4
|
||||
|
||||
|
||||
def test_vote_creation_valid(b):
|
||||
from bigchaindb.common import crypto
|
||||
from bigchaindb.common.util import serialize
|
||||
@ -24,11 +27,11 @@ def test_vote_creation_valid(b):
|
||||
# create valid block
|
||||
block = dummy_block(b)
|
||||
# retrieve vote
|
||||
vote = b.vote(block.id, 'abc', True)
|
||||
vote = b.vote(block.id, DUMMY_SHA3, True)
|
||||
|
||||
# assert vote is correct
|
||||
assert vote['vote']['voting_for_block'] == block.id
|
||||
assert vote['vote']['previous_block'] == 'abc'
|
||||
assert vote['vote']['previous_block'] == DUMMY_SHA3
|
||||
assert vote['vote']['is_block_valid'] is True
|
||||
assert vote['vote']['invalid_reason'] is None
|
||||
assert vote['node_pubkey'] == b.me
|
||||
@ -44,11 +47,11 @@ def test_vote_creation_invalid(b):
|
||||
# create valid block
|
||||
block = dummy_block(b)
|
||||
# retrieve vote
|
||||
vote = b.vote(block.id, 'abc', False)
|
||||
vote = b.vote(block.id, DUMMY_SHA3, False)
|
||||
|
||||
# assert vote is correct
|
||||
assert vote['vote']['voting_for_block'] == block.id
|
||||
assert vote['vote']['previous_block'] == 'abc'
|
||||
assert vote['vote']['previous_block'] == DUMMY_SHA3
|
||||
assert vote['vote']['is_block_valid'] is False
|
||||
assert vote['vote']['invalid_reason'] is None
|
||||
assert vote['node_pubkey'] == b.me
|
||||
|
Loading…
x
Reference in New Issue
Block a user