diff --git a/bigchaindb/elections/election.py b/bigchaindb/elections/election.py index b6deff7c..e8b3256e 100644 --- a/bigchaindb/elections/election.py +++ b/bigchaindb/elections/election.py @@ -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'] diff --git a/tests/elections/test_election.py b/tests/elections/test_election.py index ccef0e29..a8c5ce98 100644 --- a/tests/elections/test_election.py +++ b/tests/elections/test_election.py @@ -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) + second_election, second_votes = generate_election(b, + ChainMigrationElection, + public_key, private_key, + {}) + + Election.process_block(b, 2, total_votes + [second_election]) b.store_block(Block(height=2, - transactions=[v.id for v in total_votes], + transactions=[v.id for v in total_votes + [second_election]], app_hash='')._asdict()) - election, votes = generate_election(b, - ChainMigrationElection, - public_key, private_key, - {}) - txs = [election] - total_votes = votes - 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 == {