diff --git a/bigchaindb/voting.py b/bigchaindb/voting.py index 159f631f..af12f691 100644 --- a/bigchaindb/voting.py +++ b/bigchaindb/voting.py @@ -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' diff --git a/tests/test_voting.py b/tests/test_voting.py index 67c5c284..33be2fde 100644 --- a/tests/test_voting.py +++ b/tests/test_voting.py @@ -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)