test_partition_eligible_votes

This commit is contained in:
Scott Sadler 2017-02-23 21:10:12 +01:00
parent 89e76ffec2
commit 1ff84bd670
2 changed files with 21 additions and 11 deletions

View File

@ -49,12 +49,11 @@ class Voting:
voter_eligible = vote.get('node_pubkey') in eligible_voters voter_eligible = vote.get('node_pubkey') in eligible_voters
if voter_eligible: if voter_eligible:
try: try:
cls.verify_vote_signature(vote) if cls.verify_vote_signature(vote):
except ValueError:
pass
else:
eligible.append(vote) eligible.append(vote)
continue continue
except ValueError:
pass
ineligible.append(vote) ineligible.append(vote)
return eligible, ineligible return eligible, ineligible

View File

@ -9,15 +9,26 @@ from bigchaindb.voting import Voting, INVALID, VALID, UNDECIDED
# Tests for checking vote eligibility # Tests for checking vote eligibility
@patch('bigchaindb.voting.Voting.verify_vote_signature') def test_partition_eligible_votes():
def test_partition_eligible_votes(_): class TestVoting(Voting):
nodes = list(map(Bigchain, 'abc')) @classmethod
votes = [n.vote('block', 'a', True) for n in nodes] def verify_vote_signature(cls, vote):
if vote['node_pubkey'] == 'invalid sig':
return False
if vote['node_pubkey'] == 'value error':
raise ValueError()
return True
el, inel = Voting.partition_eligible_votes(votes, 'abc') voters = ['valid', 'invalid sig', 'value error', 'not in set']
votes = [{'node_pubkey': k} for k in voters]
assert el == votes el, inel = TestVoting.partition_eligible_votes(votes, voters[:-1])
assert inel == [] assert el == [votes[0]]
assert inel == votes[1:]
################################################################################
# Test vote counting
@patch('bigchaindb.voting.Voting.verify_vote_schema') @patch('bigchaindb.voting.Voting.verify_vote_schema')