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
|
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):
|
||||||
|
eligible.append(vote)
|
||||||
|
continue
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
else:
|
|
||||||
eligible.append(vote)
|
|
||||||
continue
|
|
||||||
ineligible.append(vote)
|
ineligible.append(vote)
|
||||||
|
|
||||||
return eligible, ineligible
|
return eligible, ineligible
|
||||||
|
@ -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')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user