mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Problem: No test for the exception raised when approving an election with a bad key
Solution: Wrote such a test
This commit is contained in:
parent
2ade51056e
commit
8b27989af1
@ -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]
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user