diff --git a/tests/commands/test_commands.py b/tests/commands/test_commands.py index 27f5f0f0..fba99181 100644 --- a/tests/commands/test_commands.py +++ b/tests/commands/test_commands.py @@ -10,6 +10,7 @@ from argparse import Namespace import pytest from bigchaindb import ValidatorElection +from bigchaindb.common.exceptions import KeypairMismatchException from tests.conftest import node_keys @@ -428,6 +429,7 @@ def test_upsert_validator_approve_with_tendermint(b, priv_validator_path, user_s assert b.get_transaction(approve) +@pytest.mark.bdb @pytest.mark.tendermint def test_upsert_validator_approve_without_tendermint(b, priv_validator_path, new_validator, node_key): from bigchaindb.commands.bigchaindb import run_upsert_validator_approve @@ -465,6 +467,42 @@ def test_upsert_validator_approve_without_tendermint(b, priv_validator_path, new assert b.get_transaction(approval_id) +@pytest.mark.bdb +@pytest.mark.tendermint +def test_upsert_validator_approve_called_with_bad_key(b, bad_validator_path, new_validator, node_key): + from bigchaindb.commands.bigchaindb import run_upsert_validator_approve + from argparse import Namespace + + def mock_write(tx, mode): + b.store_bulk_transactions([tx]) + return (202, '') + + # patch the validator set. We now have one validator with power 10 + b.get_validators = mock_get + b.write_transaction = mock_write + + # our voters is a list of length 1, populated from our mocked validator + voters = ValidatorElection.recipients(b) + # and our voter is the public key from the voter list + voter = node_key.public_key + valid_election = ValidatorElection.generate([voter], + voters, + new_validator, None).sign([node_key.private_key]) + + # patch in an election with a vote issued to the user + election_id = valid_election.id + b.store_bulk_transactions([valid_election]) + + # call run_upsert_validator_approve with args that point to the election, but a bad signing key + args = Namespace(action='approve', + election_id=election_id, + sk=bad_validator_path, + config={}) + + with pytest.raises(KeypairMismatchException): + run_upsert_validator_approve(args, b) + + def mock_get(height): keys = node_keys() pub_key = list(keys.keys())[0] diff --git a/tests/conftest.py b/tests/conftest.py index df0d903b..c2f474bb 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -702,6 +702,30 @@ def priv_validator_path(node_keys): return path +@pytest.fixture +def bad_validator_path(node_keys): + (public_key, private_key) = list(node_keys.items())[1] + priv_validator = { + 'address': '84F787D95E196DC5DE5F972666CFECCA36801426', + 'pub_key': { + 'type': 'AC26791624DE60', + 'value': public_key + }, + 'last_height': 0, + 'last_round': 0, + 'last_step': 0, + 'priv_key': { + 'type': '954568A3288910', + 'value': private_key + } + } + fd, path = tempfile.mkstemp() + socket = os.fdopen(fd, 'w') + json.dump(priv_validator, socket) + socket.close() + return path + + @pytest.fixture def validators(b, node_keys): from bigchaindb.backend import query