Fix election test setup.

This commit is contained in:
Lev Berman 2018-09-20 18:34:54 +02:00
parent 15e4d39077
commit 44b1b16dd6
2 changed files with 18 additions and 17 deletions

View File

@ -229,8 +229,6 @@ class Election(Transaction):
latest_change_height = latest_change['height']
election = self.get_election(self.id, bigchain)
if not election:
return True
return latest_change_height > election['height']

View File

@ -34,12 +34,13 @@ def test_process_block_concludes_all_elections(b):
total_votes += votes
b.store_abci_chain(1, 'chain-X')
Election.process_block(b, 1, txs)
b.store_block(Block(height=1,
transactions=[tx.id for tx in txs],
app_hash='')._asdict())
b.store_bulk_transactions(txs)
Election.process_block(b, 2, txs + total_votes)
Election.process_block(b, 2, total_votes)
validators = b.get_validators()
assert len(validators) == 5
@ -82,12 +83,13 @@ def test_process_block_approves_only_one_validator_update(b):
txs += [election]
total_votes += votes
Election.process_block(b, 1, txs)
b.store_block(Block(height=1,
transactions=[tx.id for tx in txs],
app_hash='')._asdict())
b.store_bulk_transactions(txs)
Election.process_block(b, 2, txs + total_votes)
Election.process_block(b, 2, total_votes)
validators = b.get_validators()
assert len(validators) == 5
@ -132,12 +134,13 @@ def test_process_block_approves_after_pending_validator_update(b):
total_votes += votes
b.store_abci_chain(1, 'chain-X')
Election.process_block(b, 1, txs)
b.store_block(Block(height=1,
transactions=[tx.id for tx in txs],
app_hash='')._asdict())
b.store_bulk_transactions(txs)
Election.process_block(b, 2, txs + total_votes)
Election.process_block(b, 2, total_votes)
validators = b.get_validators()
assert len(validators) == 5
@ -172,25 +175,24 @@ def test_process_block_does_not_approve_after_validator_update(b):
b.store_block(Block(height=1,
transactions=[tx.id for tx in txs],
app_hash='')._asdict())
Election.process_block(b, 1, txs)
b.store_bulk_transactions(txs)
Election.process_block(b, 2, txs + total_votes)
b.store_block(Block(height=2,
transactions=[v.id for v in total_votes],
app_hash='')._asdict())
election, votes = generate_election(b,
second_election, second_votes = generate_election(b,
ChainMigrationElection,
public_key, private_key,
{})
txs = [election]
total_votes = votes
Election.process_block(b, 2, total_votes + [second_election])
b.store_block(Block(height=2,
transactions=[v.id for v in total_votes + [second_election]],
app_hash='')._asdict())
b.store_abci_chain(1, 'chain-X')
Election.process_block(b, 3, txs + total_votes)
Election.process_block(b, 3, second_votes)
assert not b.get_election(election.id)['is_concluded']
assert not b.get_election(second_election.id)['is_concluded']
assert b.get_latest_abci_chain() == {'height': 1,
'chain_id': 'chain-X',
'is_synced': True}
@ -219,12 +221,13 @@ def test_process_block_applies_only_one_migration(b):
total_votes += votes
b.store_abci_chain(1, 'chain-X')
Election.process_block(b, 1, txs)
b.store_block(Block(height=1,
transactions=[tx.id for tx in txs],
app_hash='')._asdict())
b.store_bulk_transactions(txs)
Election.process_block(b, 1, txs + total_votes)
Election.process_block(b, 1, total_votes)
chain = b.get_latest_abci_chain()
assert chain
assert chain == {