test_count_votes

This commit is contained in:
Scott Sadler 2017-02-23 21:39:38 +01:00
parent 1ff84bd670
commit e88c98a695
2 changed files with 20 additions and 9 deletions

View File

@ -94,8 +94,8 @@ class Voting:
n_invalid += 1 n_invalid += 1
continue continue
prev_blocks[vote['vote']['previous_block']] += 1
if vote['vote']['is_block_valid']: if vote['vote']['is_block_valid']:
prev_blocks[vote['vote']['previous_block']] += 1
n_valid += 1 n_valid += 1
else: else:
n_invalid += 1 n_invalid += 1

View File

@ -31,16 +31,27 @@ def test_partition_eligible_votes():
# Test vote counting # Test vote counting
@patch('bigchaindb.voting.Voting.verify_vote_schema') def test_count_votes():
def test_count_votes(_): class TestVoting(Voting):
nodes = list(map(Bigchain, 'abc')) @classmethod
def verify_vote_schema(cls, vote):
return vote['node_pubkey'] != 'malformed'
votes = [n.vote('block', 'a', True) for n in nodes] voters = ['cheat', 'cheat', 'says invalid', 'malformed']
voters += ['kosher' + str(i) for i in range(10)]
assert Voting.count_votes(votes)['counts'] == { votes = [Bigchain(v).vote('block', 'a', True) for v in voters]
'n_valid': 3, votes[2]['vote']['is_block_valid'] = False
'n_invalid': 0, votes[-1]['vote']['previous_block'] = 'z'
'n_agree_prev_block': 3
assert TestVoting.count_votes(votes) == {
'counts': {
'n_valid': 10,
'n_invalid': 3,
'n_agree_prev_block': 9
},
'cheat': [votes[:2]],
'malformed': [votes[3]],
} }