1
0
mirror of https://github.com/bigchaindb/bigchaindb.git synced 2024-06-30 05:32:01 +02:00
bigchaindb/tests/elections/test_election.py
Zachary Bowen e6893632dc Create migration election class (#2535).
* Problem: We need a way to synchronize a halt to block production to allow for upgrades across breaking changes.

* Solution: Created `MigrationElection`.

* Problem: Need documentation for `migration` elections.

* Solution: Updated the docs.

* Problem: `MigrationElection` needs 'new' CLI method.

* Solution: Updated the definition of `election` to include the new `migration` type.

* Problem: The way `end_block` checks for concluded elections assumes there is only one type of election (so we can't conclude an `upsert-validator` and a `chain-migration` at the same height).

* Solution: Re-engineered the code in `Elections` to conclude multiple elections in the same block. If more than one election change the validator set, only one of them is applied.

* Problem: Tendermint change to store validator changes at height h+2 will break `Election.get_status`.

* Solution: Reworked `get_validator_change` to look at only the latest block height or less.
2018-09-17 13:59:57 +02:00

65 lines
2.3 KiB
Python

from unittest.mock import MagicMock
import pytest
from bigchaindb.elections.election import Election
@pytest.mark.bdb
def test_approved_elections_one_migration_one_upsert(
b,
ongoing_validator_election, validator_election_votes,
ongoing_chain_migration_election, chain_migration_election_votes
):
txns = validator_election_votes + \
chain_migration_election_votes
mock_chain_migration, mock_store_validator = run_approved_elections(b, txns)
mock_chain_migration.assert_called_once()
mock_store_validator.assert_called_once()
@pytest.mark.bdb
def test_approved_elections_one_migration_two_upsert(
b,
ongoing_validator_election, validator_election_votes,
ongoing_validator_election_2, validator_election_votes_2,
ongoing_chain_migration_election, chain_migration_election_votes
):
txns = validator_election_votes + \
validator_election_votes_2 + \
chain_migration_election_votes
mock_chain_migration, mock_store_validator = run_approved_elections(b, txns)
mock_chain_migration.assert_called_once()
mock_store_validator.assert_called_once()
@pytest.mark.bdb
def test_approved_elections_two_migrations_one_upsert(
b,
ongoing_validator_election, validator_election_votes,
ongoing_chain_migration_election, chain_migration_election_votes,
ongoing_chain_migration_election_2, chain_migration_election_votes_2
):
txns = validator_election_votes + \
chain_migration_election_votes + \
chain_migration_election_votes_2
mock_chain_migration, mock_store_validator = run_approved_elections(b, txns)
assert mock_chain_migration.call_count == 2
mock_store_validator.assert_called_once()
def test_approved_elections_no_elections(b):
txns = []
mock_chain_migration, mock_store_validator = run_approved_elections(b, txns)
mock_chain_migration.assert_not_called()
mock_store_validator.assert_not_called()
def run_approved_elections(bigchain, txns):
mock_chain_migration = MagicMock()
mock_store_validator = MagicMock()
bigchain.migrate_abci_chain = mock_chain_migration
bigchain.store_validator_set = mock_store_validator
Election.approved_elections(bigchain, 1, txns)
return mock_chain_migration, mock_store_validator