mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
tests for vote schema and signature validation
This commit is contained in:
parent
e88c98a695
commit
c44c9d0282
@ -170,5 +170,5 @@ class Voting:
|
|||||||
try:
|
try:
|
||||||
validate_vote_schema(vote)
|
validate_vote_schema(vote)
|
||||||
return True
|
return True
|
||||||
except SchemaValidationError:
|
except SchemaValidationError as e:
|
||||||
return False
|
return False
|
||||||
|
@ -106,52 +106,30 @@ def test_decide_votes_checks_arguments():
|
|||||||
n_agree_prev_block=2)
|
n_agree_prev_block=2)
|
||||||
|
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Tests for vote signature
|
||||||
|
|
||||||
|
|
||||||
|
def test_verify_vote_signature_passes(b):
|
||||||
|
vote = b.vote('block', 'a', True)
|
||||||
|
assert Voting.verify_vote_signature(vote)
|
||||||
|
|
||||||
|
|
||||||
|
def test_verify_vote_signature_fails(b):
|
||||||
|
vote = b.vote('block', 'a', True)
|
||||||
|
vote['signature'] = ''
|
||||||
|
assert not Voting.verify_vote_signature(vote)
|
||||||
|
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
|
# Tests for vote schema
|
||||||
# DEBT
|
|
||||||
|
|
||||||
|
|
||||||
|
def test_verify_vote_schema(b):
|
||||||
def _test_verify_vote_passes(b, structurally_valid_vote):
|
vote = b.vote('b' * 64, 'a' * 64, True)
|
||||||
from bigchaindb.consensus import BaseConsensusRules
|
assert Voting.verify_vote_schema(vote)
|
||||||
from bigchaindb.common import crypto
|
vote = b.vote('b', 'a', True)
|
||||||
from bigchaindb.common.utils import serialize
|
assert not Voting.verify_vote_schema(vote)
|
||||||
vote_body = structurally_valid_vote['vote']
|
|
||||||
vote_data = serialize(vote_body)
|
|
||||||
signature = crypto.PrivateKey(b.me_private).sign(vote_data.encode())
|
|
||||||
vote_signed = {
|
|
||||||
'node_pubkey': b.me,
|
|
||||||
'signature': signature.decode(),
|
|
||||||
'vote': vote_body
|
|
||||||
}
|
|
||||||
assert BaseConsensusRules.verify_vote([b.me], vote_signed)
|
|
||||||
|
|
||||||
|
|
||||||
def _test_verify_vote_fails_signature(b, structurally_valid_vote):
|
|
||||||
from bigchaindb.consensus import BaseConsensusRules
|
|
||||||
vote_body = structurally_valid_vote['vote']
|
|
||||||
vote_signed = {
|
|
||||||
'node_pubkey': b.me,
|
|
||||||
'signature': 'a' * 86,
|
|
||||||
'vote': vote_body
|
|
||||||
}
|
|
||||||
assert not BaseConsensusRules.verify_vote([b.me], vote_signed)
|
|
||||||
|
|
||||||
|
|
||||||
def _test_verify_vote_fails_schema(b):
|
|
||||||
from bigchaindb.consensus import BaseConsensusRules
|
|
||||||
from bigchaindb.common import crypto
|
|
||||||
from bigchaindb.common.utils import serialize
|
|
||||||
vote_body = {}
|
|
||||||
vote_data = serialize(vote_body)
|
|
||||||
signature = crypto.PrivateKey(b.me_private).sign(vote_data.encode())
|
|
||||||
vote_signed = {
|
|
||||||
'node_pubkey': b.me,
|
|
||||||
'signature': signature.decode(),
|
|
||||||
'vote': vote_body
|
|
||||||
}
|
|
||||||
assert not BaseConsensusRules.verify_vote([b.me], vote_signed)
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user