mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
check count_votes invalid input
This commit is contained in:
parent
d71e560ba4
commit
20f6539e10
@ -7,6 +7,11 @@ to test.
|
|||||||
import collections
|
import collections
|
||||||
|
|
||||||
|
|
||||||
|
VALID = 'valid'
|
||||||
|
INVALID = 'invalid'
|
||||||
|
UNDECIDED = 'undecided'
|
||||||
|
|
||||||
|
|
||||||
def partition_eligible_votes(votes, eligible_voters, verify_vote_signature):
|
def partition_eligible_votes(votes, eligible_voters, verify_vote_signature):
|
||||||
"""
|
"""
|
||||||
Filter votes from unknown nodes or nodes that are not listed on
|
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 VALID
|
||||||
return INVALID
|
return INVALID
|
||||||
return UNDECIDED
|
return UNDECIDED
|
||||||
|
|
||||||
|
|
||||||
INVALID = 'invalid'
|
|
||||||
VALID = TX_VALID = 'valid'
|
|
||||||
UNDECIDED = TX_UNDECIDED = 'undecided'
|
|
||||||
|
@ -5,6 +5,10 @@ from bigchaindb.voting import (count_votes, partition_eligible_votes,
|
|||||||
decide_votes, INVALID, VALID, UNDECIDED)
|
decide_votes, INVALID, VALID, UNDECIDED)
|
||||||
|
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Tests for checking vote eligibility
|
||||||
|
|
||||||
|
|
||||||
def test_partition_eligible_votes():
|
def test_partition_eligible_votes():
|
||||||
nodes = list(map(Bigchain, 'abc'))
|
nodes = list(map(Bigchain, 'abc'))
|
||||||
votes = [n.vote('block', 'a', True) for n in nodes]
|
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(
|
DECISION_TESTS = [dict(
|
||||||
zip(['n_voters', 'n_valid', 'n_invalid', 'n_agree_prev_block'], t))
|
zip(['n_voters', 'n_valid', 'n_invalid', 'n_agree_prev_block'], t))
|
||||||
for t in [
|
for t in [
|
||||||
@ -59,3 +67,12 @@ def test_decide_votes_invalid(kwargs):
|
|||||||
assert decide_votes(**kwargs) == INVALID
|
assert decide_votes(**kwargs) == INVALID
|
||||||
kwargs['n_invalid'] -= 1
|
kwargs['n_invalid'] -= 1
|
||||||
assert decide_votes(**kwargs) == UNDECIDED
|
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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user