Problem: Needed a tendermint test to cover run_upsert_validator_approve

Solution: Wrote a test
This commit is contained in:
z-bowen 2018-08-22 18:08:14 +02:00
parent e7d89abfce
commit d7feb8841a

View File

@ -9,6 +9,9 @@ from argparse import Namespace
import pytest
from bigchaindb import ValidatorElection
from tests.conftest import node_keys
@pytest.mark.tendermint
def test_make_sure_we_dont_remove_any_command():
@ -360,13 +363,6 @@ def test_upsert_validator_new_with_tendermint(b, priv_validator_path, user_sk, m
time.sleep(3)
def mock_get():
return [
{'pub_key': {'value': 'zL/DasvKulXZzhSNFwx4cLRXKkSM9GPK7Y0nZ4FEylM=',
'type': 'tendermint/PubKeyEd25519'},
'voting_power': 10}
]
# b.get_validators = mock_get
# mock_get_validators = mock_get
# monkeypatch.setattr('requests.get', mock_get)
@ -387,16 +383,9 @@ def test_upsert_validator_new_with_tendermint(b, priv_validator_path, user_sk, m
@pytest.mark.tendermint
@pytest.mark.bdb
def test_upsert_validator_new_without_tendermint(b, priv_validator_path, user_sk, monkeypatch):
def test_upsert_validator_new_without_tendermint(b, priv_validator_path, user_sk):
from bigchaindb.commands.bigchaindb import run_upsert_validator_new
def mock_get(height):
return [
{'pub_key': {'data': 'zL/DasvKulXZzhSNFwx4cLRXKkSM9GPK7Y0nZ4FEylM=',
'type': 'tendermint/PubKeyEd25519'},
'voting_power': 10}
]
def mock_write(tx, mode):
b.store_transaction(tx)
return (202, '')
@ -416,7 +405,7 @@ def test_upsert_validator_new_without_tendermint(b, priv_validator_path, user_sk
@pytest.mark.abci
def test_upsert_validator_approve(b, priv_validator_path, user_sk, validators):
def test_upsert_validator_approve_with_tendermint(b, priv_validator_path, user_sk, validators):
from bigchaindb.commands.bigchaindb import run_upsert_validator_new, \
run_upsert_validator_approve
@ -437,3 +426,50 @@ def test_upsert_validator_approve(b, priv_validator_path, user_sk, validators):
approve = run_upsert_validator_approve(args, b)
assert b.get_transaction(approve)
@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
from argparse import Namespace
def mock_write(tx, mode):
b.store_transaction(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_transaction(valid_election)
# call run_upsert_validator_approve with args that point to the election
args = Namespace(action='approve',
election_id=election_id,
sk=priv_validator_path,
config={})
approval_id = run_upsert_validator_approve(args, b)
# assert returned id is in the db
assert b.get_transaction(approval_id)
def mock_get(height):
keys = node_keys()
pub_key = list(keys.keys())[0]
return [
{'pub_key': {'data': pub_key,
'type': 'tendermint/PubKeyEd25519'},
'voting_power': 10}
]