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
if voter_eligible:
try:
cls.verify_vote_signature(vote)
if cls.verify_vote_signature(vote):
eligible.append(vote)
continue
except ValueError:
pass
else:
eligible.append(vote)
continue
ineligible.append(vote)
return eligible, ineligible

View File

@ -9,15 +9,26 @@ from bigchaindb.voting import Voting, INVALID, VALID, UNDECIDED
# Tests for checking vote eligibility
@patch('bigchaindb.voting.Voting.verify_vote_signature')
def test_partition_eligible_votes(_):
nodes = list(map(Bigchain, 'abc'))
votes = [n.vote('block', 'a', True) for n in nodes]
def test_partition_eligible_votes():
class TestVoting(Voting):
@classmethod
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
assert inel == []
el, inel = TestVoting.partition_eligible_votes(votes, voters[:-1])
assert el == [votes[0]]
assert inel == votes[1:]
################################################################################
# Test vote counting
@patch('bigchaindb.voting.Voting.verify_vote_schema')