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