check count_votes invalid input

This commit is contained in:
Scott Sadler 2017-02-23 17:29:46 +01:00
parent d71e560ba4
commit 20f6539e10
2 changed files with 22 additions and 5 deletions

View File

@ -7,6 +7,11 @@ to test.
import collections
VALID = 'valid'
INVALID = 'invalid'
UNDECIDED = 'undecided'
def partition_eligible_votes(votes, eligible_voters, verify_vote_signature):
"""
Filter votes from unknown nodes or nodes that are not listed on
@ -92,8 +97,3 @@ def decide_votes(n_voters, n_valid, n_invalid, n_agree_prev_block):
return VALID
return INVALID
return UNDECIDED
INVALID = 'invalid'
VALID = TX_VALID = 'valid'
UNDECIDED = TX_UNDECIDED = 'undecided'

View File

@ -5,6 +5,10 @@ from bigchaindb.voting import (count_votes, partition_eligible_votes,
decide_votes, INVALID, VALID, UNDECIDED)
################################################################################
# Tests for checking vote eligibility
def test_partition_eligible_votes():
nodes = list(map(Bigchain, 'abc'))
votes = [n.vote('block', 'a', True) for n in nodes]
@ -26,6 +30,10 @@ def test_count_votes():
}, {})
################################################################################
# Tests for vote decision making
DECISION_TESTS = [dict(
zip(['n_voters', 'n_valid', 'n_invalid', 'n_agree_prev_block'], t))
for t in [
@ -59,3 +67,12 @@ def test_decide_votes_invalid(kwargs):
assert decide_votes(**kwargs) == INVALID
kwargs['n_invalid'] -= 1
assert decide_votes(**kwargs) == UNDECIDED
def test_decide_votes_checks_arguments():
with pytest.raises(ValueError):
decide_votes(n_voters=1, n_valid=2, n_invalid=0, n_agree_prev_block=0)
with pytest.raises(ValueError):
decide_votes(n_voters=1, n_valid=0, n_invalid=2, n_agree_prev_block=0)
with pytest.raises(ValueError):
decide_votes(n_voters=1, n_valid=0, n_invalid=0, n_agree_prev_block=2)