mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
test_count_votes
This commit is contained in:
parent
1ff84bd670
commit
e88c98a695
@ -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
|
||||||
|
@ -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]],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user