mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Problem: MigrationElection naming may conflict with future migration types
Solution: Renamed the class `ChainMigrationElection`
This commit is contained in:
parent
c5062a0829
commit
e599914f31
@ -7,7 +7,7 @@ import logging
|
||||
|
||||
from bigchaindb.log import DEFAULT_LOGGING_CONFIG as log_config
|
||||
from bigchaindb.lib import BigchainDB # noqa
|
||||
from bigchaindb.migrations.migration_election import MigrationElection
|
||||
from bigchaindb.migrations.chain_migration_election import ChainMigrationElection
|
||||
from bigchaindb.version import __version__ # noqa
|
||||
from bigchaindb.core import App # noqa
|
||||
|
||||
@ -100,5 +100,5 @@ from bigchaindb.elections.vote import Vote # noqa
|
||||
Transaction.register_type(Transaction.CREATE, models.Transaction)
|
||||
Transaction.register_type(Transaction.TRANSFER, models.Transaction)
|
||||
Transaction.register_type(ValidatorElection.OPERATION, ValidatorElection)
|
||||
Transaction.register_type(MigrationElection.OPERATION, MigrationElection)
|
||||
Transaction.register_type(ChainMigrationElection.OPERATION, ChainMigrationElection)
|
||||
Transaction.register_type(Vote.OPERATION, Vote)
|
||||
|
||||
@ -13,7 +13,7 @@ import copy
|
||||
import json
|
||||
import sys
|
||||
|
||||
from bigchaindb.migrations.migration_election import MigrationElection
|
||||
from bigchaindb.migrations.chain_migration_election import ChainMigrationElection
|
||||
from bigchaindb.utils import load_node_key
|
||||
from bigchaindb.common.exceptions import (DatabaseDoesNotExist,
|
||||
ValidationError)
|
||||
@ -165,7 +165,7 @@ def run_election_new_upsert_validator(args, bigchain):
|
||||
return create_new_election(args.sk, bigchain, ValidatorElection, new_validator)
|
||||
|
||||
|
||||
def run_election_new_migration(args, bigchain):
|
||||
def run_election_new_chain_migration(args, bigchain):
|
||||
"""Initiates an election to halt block production
|
||||
|
||||
:param args: dict
|
||||
@ -176,7 +176,7 @@ def run_election_new_migration(args, bigchain):
|
||||
:return: election_id or `False` in case of failure
|
||||
"""
|
||||
|
||||
return create_new_election(args.sk, bigchain, MigrationElection, {})
|
||||
return create_new_election(args.sk, bigchain, ChainMigrationElection, {})
|
||||
|
||||
|
||||
def run_election_approve(args, bigchain):
|
||||
|
||||
@ -17,7 +17,7 @@ elections = {
|
||||
}
|
||||
}
|
||||
},
|
||||
'migration': {
|
||||
'chain-migration': {
|
||||
'help': 'Call for a halt to block production to allow for a version change across breaking changes.',
|
||||
'args': {
|
||||
'--private-key': {
|
||||
|
||||
@ -37,8 +37,8 @@ _, TX_SCHEMA_TRANSFER = _load_schema('transaction_transfer_' +
|
||||
_, TX_SCHEMA_VALIDATOR_ELECTION = _load_schema('transaction_validator_election_' +
|
||||
TX_SCHEMA_VERSION)
|
||||
|
||||
_, TX_SCHEMA_MIGRATION_ELECTION = _load_schema('transaction_migration_election_' +
|
||||
TX_SCHEMA_VERSION)
|
||||
_, TX_SCHEMA_CHAIN_MIGRATION_ELECTION = _load_schema('transaction_chain_migration_election_' +
|
||||
TX_SCHEMA_VERSION)
|
||||
|
||||
_, TX_SCHEMA_VOTE = _load_schema('transaction_vote_' + TX_SCHEMA_VERSION)
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
---
|
||||
"$schema": "http://json-schema.org/draft-04/schema#"
|
||||
type: object
|
||||
title: Migration Election Schema - Propose a halt in block production to allow for a version change
|
||||
title: Chain Migration Election Schema - Propose a halt in block production to allow for a version change
|
||||
required:
|
||||
- operation
|
||||
- asset
|
||||
@ -13,7 +13,7 @@ required:
|
||||
properties:
|
||||
operation:
|
||||
type: string
|
||||
value: "MIGRATION_ELECTION"
|
||||
value: "CHAIN_MIGRATION_ELECTION"
|
||||
asset:
|
||||
additionalProperties: false
|
||||
properties:
|
||||
@ -63,7 +63,7 @@ definitions:
|
||||
- CREATE
|
||||
- TRANSFER
|
||||
- VALIDATOR_ELECTION
|
||||
- MIGRATION_ELECTION
|
||||
- CHAIN_MIGRATION_ELECTION
|
||||
- VOTE
|
||||
asset:
|
||||
type: object
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
from bigchaindb.common.schema import TX_SCHEMA_MIGRATION_ELECTION
|
||||
from bigchaindb.common.schema import TX_SCHEMA_CHAIN_MIGRATION_ELECTION
|
||||
from bigchaindb.elections.election import Election
|
||||
|
||||
|
||||
class MigrationElection(Election):
|
||||
class ChainMigrationElection(Election):
|
||||
|
||||
OPERATION = 'MIGRATION_ELECTION'
|
||||
OPERATION = 'CHAIN_MIGRATION_ELECTION'
|
||||
CREATE = OPERATION
|
||||
ALLOWED_OPERATIONS = (OPERATION,)
|
||||
TX_SCHEMA_CUSTOM = TX_SCHEMA_MIGRATION_ELECTION
|
||||
TX_SCHEMA_CUSTOM = TX_SCHEMA_CHAIN_MIGRATION_ELECTION
|
||||
CHANGES_VALIDATOR_SET = False
|
||||
|
||||
@classmethod
|
||||
@ -26,7 +26,7 @@ def test_make_sure_we_dont_remove_any_command():
|
||||
assert parser.parse_args(['start']).command
|
||||
assert parser.parse_args(['election', 'new', 'upsert-validator', 'TEMP_PUB_KEYPAIR', '10', 'TEMP_NODE_ID',
|
||||
'--private-key', 'TEMP_PATH_TO_PRIVATE_KEY']).command
|
||||
assert parser.parse_args(['election', 'new', 'migration',
|
||||
assert parser.parse_args(['election', 'new', 'chain-migration',
|
||||
'--private-key', 'TEMP_PATH_TO_PRIVATE_KEY']).command
|
||||
assert parser.parse_args(['election', 'approve', 'ELECTION_ID', '--private-key',
|
||||
'TEMP_PATH_TO_PRIVATE_KEY']).command
|
||||
@ -344,22 +344,22 @@ def test_election_new_upsert_validator_without_tendermint(caplog, b, priv_valida
|
||||
|
||||
|
||||
@pytest.mark.abci
|
||||
def test_election_new_migration_with_tendermint(b, priv_validator_path, user_sk, validators):
|
||||
from bigchaindb.commands.bigchaindb import run_election_new_migration
|
||||
def test_election_new_chain_migration_with_tendermint(b, priv_validator_path, user_sk, validators):
|
||||
from bigchaindb.commands.bigchaindb import run_election_new_chain_migration
|
||||
|
||||
new_args = Namespace(action='new',
|
||||
election_type='migration',
|
||||
sk=priv_validator_path,
|
||||
config={})
|
||||
|
||||
election_id = run_election_new_migration(new_args, b)
|
||||
election_id = run_election_new_chain_migration(new_args, b)
|
||||
|
||||
assert b.get_transaction(election_id)
|
||||
|
||||
|
||||
@pytest.mark.bdb
|
||||
def test_election_new_migration_without_tendermint(caplog, b, priv_validator_path, user_sk):
|
||||
from bigchaindb.commands.bigchaindb import run_election_new_migration
|
||||
def test_election_new_chain_migration_without_tendermint(caplog, b, priv_validator_path, user_sk):
|
||||
from bigchaindb.commands.bigchaindb import run_election_new_chain_migration
|
||||
|
||||
def mock_write(tx, mode):
|
||||
b.store_bulk_transactions([tx])
|
||||
@ -374,7 +374,7 @@ def test_election_new_migration_without_tendermint(caplog, b, priv_validator_pat
|
||||
config={})
|
||||
|
||||
with caplog.at_level(logging.INFO):
|
||||
election_id = run_election_new_migration(args, b)
|
||||
election_id = run_election_new_chain_migration(args, b)
|
||||
assert caplog.records[0].msg == '[SUCCESS] Submitted proposal with id: ' + election_id
|
||||
assert b.get_transaction(election_id)
|
||||
|
||||
|
||||
@ -23,7 +23,7 @@ from pymongo import MongoClient
|
||||
from bigchaindb import ValidatorElection
|
||||
from bigchaindb.common import crypto
|
||||
from bigchaindb.log import setup_logging
|
||||
from bigchaindb.migrations.migration_election import MigrationElection
|
||||
from bigchaindb.migrations.chain_migration_election import ChainMigrationElection
|
||||
from bigchaindb.tendermint_utils import key_from_base64
|
||||
from bigchaindb.backend import schema, query
|
||||
from bigchaindb.common.crypto import (key_pair_from_ed25519_key,
|
||||
@ -715,19 +715,19 @@ def valid_upsert_validator_election_2(b_mock, node_key, new_validator):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def valid_migration_election(b_mock, node_key):
|
||||
voters = MigrationElection.recipients(b_mock)
|
||||
return MigrationElection.generate([node_key.public_key],
|
||||
voters,
|
||||
{}, None).sign([node_key.private_key])
|
||||
def valid_chain_migration_election(b_mock, node_key):
|
||||
voters = ChainMigrationElection.recipients(b_mock)
|
||||
return ChainMigrationElection.generate([node_key.public_key],
|
||||
voters,
|
||||
{}, None).sign([node_key.private_key])
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def valid_migration_election_2(b_mock, node_key):
|
||||
voters = MigrationElection.recipients(b_mock)
|
||||
return MigrationElection.generate([node_key.public_key],
|
||||
voters,
|
||||
{}, None).sign([node_key.private_key])
|
||||
def valid_chain_migration_election_2(b_mock, node_key):
|
||||
voters = ChainMigrationElection.recipients(b_mock)
|
||||
return ChainMigrationElection.generate([node_key.public_key],
|
||||
voters,
|
||||
{}, None).sign([node_key.private_key])
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@ -759,21 +759,21 @@ def ongoing_validator_election_2(b, valid_upsert_validator_election_2, ed25519_n
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def ongoing_migration_election(b, valid_migration_election, ed25519_node_keys):
|
||||
def ongoing_chain_migration_election(b, valid_chain_migration_election, ed25519_node_keys):
|
||||
|
||||
b.store_bulk_transactions([valid_migration_election])
|
||||
block_1 = Block(app_hash='hash_1', height=1, transactions=[valid_migration_election.id])
|
||||
b.store_bulk_transactions([valid_chain_migration_election])
|
||||
block_1 = Block(app_hash='hash_1', height=1, transactions=[valid_chain_migration_election.id])
|
||||
b.store_block(block_1._asdict())
|
||||
return valid_migration_election
|
||||
return valid_chain_migration_election
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def ongoing_migration_election_2(b, valid_migration_election_2, ed25519_node_keys):
|
||||
def ongoing_chain_migration_election_2(b, valid_chain_migration_election_2, ed25519_node_keys):
|
||||
|
||||
b.store_bulk_transactions([valid_migration_election_2])
|
||||
block_1 = Block(app_hash='hash_2', height=1, transactions=[valid_migration_election_2.id])
|
||||
b.store_bulk_transactions([valid_chain_migration_election_2])
|
||||
block_1 = Block(app_hash='hash_2', height=1, transactions=[valid_chain_migration_election_2.id])
|
||||
b.store_block(block_1._asdict())
|
||||
return valid_migration_election_2
|
||||
return valid_chain_migration_election_2
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@ -791,16 +791,16 @@ def validator_election_votes_2(b_mock, ongoing_validator_election_2, ed25519_nod
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def migration_election_votes(b_mock, ongoing_migration_election, ed25519_node_keys):
|
||||
voters = MigrationElection.recipients(b_mock)
|
||||
votes = generate_votes(ongoing_migration_election, voters, ed25519_node_keys)
|
||||
def chain_migration_election_votes(b_mock, ongoing_chain_migration_election, ed25519_node_keys):
|
||||
voters = ChainMigrationElection.recipients(b_mock)
|
||||
votes = generate_votes(ongoing_chain_migration_election, voters, ed25519_node_keys)
|
||||
return votes
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def migration_election_votes_2(b_mock, ongoing_migration_election_2, ed25519_node_keys):
|
||||
voters = MigrationElection.recipients(b_mock)
|
||||
votes = generate_votes(ongoing_migration_election_2, voters, ed25519_node_keys)
|
||||
def chain_migration_election_votes_2(b_mock, ongoing_chain_migration_election_2, ed25519_node_keys):
|
||||
voters = ChainMigrationElection.recipients(b_mock)
|
||||
votes = generate_votes(ongoing_chain_migration_election_2, voters, ed25519_node_keys)
|
||||
return votes
|
||||
|
||||
|
||||
|
||||
@ -6,37 +6,43 @@ 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_migration_election, migration_election_votes):
|
||||
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 + \
|
||||
migration_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_migration_election, migration_election_votes):
|
||||
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 + \
|
||||
migration_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_two_migrations_one_upsert(b,
|
||||
ongoing_validator_election, validator_election_votes,
|
||||
ongoing_migration_election, migration_election_votes,
|
||||
ongoing_migration_election_2, migration_election_votes_2):
|
||||
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 + \
|
||||
migration_election_votes + \
|
||||
migration_election_votes_2
|
||||
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()
|
||||
|
||||
@ -1,11 +0,0 @@
|
||||
import pytest
|
||||
|
||||
from bigchaindb.migrations.migration_election import MigrationElection
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def valid_migration_election(b_mock, node_key):
|
||||
voters = MigrationElection.recipients(b_mock)
|
||||
return MigrationElection.generate([node_key.public_key],
|
||||
voters,
|
||||
{}, None).sign([node_key.private_key])
|
||||
@ -1,9 +1,9 @@
|
||||
from bigchaindb.migrations.migration_election import MigrationElection
|
||||
from bigchaindb.migrations.chain_migration_election import ChainMigrationElection
|
||||
|
||||
|
||||
def test_valid_migration_election(b_mock, node_key):
|
||||
voters = MigrationElection.recipients(b_mock)
|
||||
election = MigrationElection.generate([node_key.public_key],
|
||||
voters,
|
||||
{}, None).sign([node_key.private_key])
|
||||
voters = ChainMigrationElection.recipients(b_mock)
|
||||
election = ChainMigrationElection.generate([node_key.public_key],
|
||||
voters,
|
||||
{}, None).sign([node_key.private_key])
|
||||
assert election.validate(b_mock)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user