mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
test_partition_eligible_votes
This commit is contained in:
parent
89e76ffec2
commit
1ff84bd670
@ -49,12 +49,11 @@ class Voting:
|
||||
voter_eligible = vote.get('node_pubkey') in eligible_voters
|
||||
if voter_eligible:
|
||||
try:
|
||||
cls.verify_vote_signature(vote)
|
||||
except ValueError:
|
||||
pass
|
||||
else:
|
||||
if cls.verify_vote_signature(vote):
|
||||
eligible.append(vote)
|
||||
continue
|
||||
except ValueError:
|
||||
pass
|
||||
ineligible.append(vote)
|
||||
|
||||
return eligible, ineligible
|
||||
|
@ -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')
|
||||
|
Loading…
x
Reference in New Issue
Block a user