mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Problem: No test covering upsert-validator show
Solution: Wrote a test. Also changed validator node_ids to include the name of the test they're part of, which should prevent `DuplicateTransaction` collisions during testing.
This commit is contained in:
parent
6ca97bd0e5
commit
b3a0c13da1
@ -352,34 +352,22 @@ class MockResponse():
|
||||
return {'result': {'latest_block_height': self.height}}
|
||||
|
||||
|
||||
# @pytest.mark.execute
|
||||
# @patch('bigchaindb.lib.BigchainDB.get_validators')
|
||||
# @pytest.mark.abci
|
||||
@pytest.mark.skip
|
||||
def test_upsert_validator_new_with_tendermint(b, priv_validator_path, user_sk, monkeypatch):
|
||||
@pytest.mark.abci
|
||||
def test_upsert_validator_new_with_tendermint(b, priv_validator_path, user_sk, validators):
|
||||
"""WIP: Will be fixed and activated in the next PR
|
||||
"""
|
||||
from bigchaindb.commands.bigchaindb import run_upsert_validator_new
|
||||
import time
|
||||
|
||||
time.sleep(3)
|
||||
new_args = Namespace(action='new',
|
||||
public_key='8eJ8q9ZQpReWyQT5aFCiwtZ5wDZC4eDnCen88p3tQ6ie',
|
||||
power=1,
|
||||
node_id='unique_node_id_for_test_upsert_validator_new_with_tendermint',
|
||||
sk=priv_validator_path,
|
||||
config={})
|
||||
|
||||
# b.get_validators = mock_get
|
||||
# mock_get_validators = mock_get
|
||||
# monkeypatch.setattr('requests.get', mock_get)
|
||||
election_id = run_upsert_validator_new(new_args, b)
|
||||
|
||||
proposer_key = b.get_validators()[0]['pub_key']['value']
|
||||
|
||||
args = Namespace(action='new',
|
||||
public_key=proposer_key,
|
||||
power=1,
|
||||
node_id='12345',
|
||||
sk=priv_validator_path,
|
||||
config={})
|
||||
resp = run_upsert_validator_new(args, b)
|
||||
time.sleep(3)
|
||||
|
||||
assert b.get_transaction(resp)
|
||||
assert b.get_transaction(election_id)
|
||||
|
||||
|
||||
@pytest.mark.tendermint
|
||||
@ -391,13 +379,13 @@ def test_upsert_validator_new_without_tendermint(b, priv_validator_path, user_sk
|
||||
b.store_bulk_transactions([tx])
|
||||
return (202, '')
|
||||
|
||||
b.get_validators = mock_get
|
||||
b.get_validators = mock_get_validators
|
||||
b.write_transaction = mock_write
|
||||
|
||||
args = Namespace(action='new',
|
||||
public_key='CJxdItf4lz2PwEf4SmYNAu/c/VpmX39JEgC5YpH7fxg=',
|
||||
power=1,
|
||||
node_id='12345',
|
||||
node_id='unique_node_id_for_test_upsert_validator_new_without_tendermint',
|
||||
sk=priv_validator_path,
|
||||
config={})
|
||||
resp = run_upsert_validator_new(args, b)
|
||||
@ -405,6 +393,47 @@ def test_upsert_validator_new_without_tendermint(b, priv_validator_path, user_sk
|
||||
assert b.get_transaction(resp)
|
||||
|
||||
|
||||
@pytest.mark.tendermint
|
||||
@pytest.mark.bdb
|
||||
def test_upsert_validator_show(b, priv_validator_path, user_sk, monkeypatch):
|
||||
from bigchaindb.commands.bigchaindb import run_upsert_validator_show, 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_bulk_transactions([tx])
|
||||
return 202, ''
|
||||
|
||||
b.get_validators = mock_get
|
||||
b.write_transaction = mock_write
|
||||
|
||||
monkeypatch.setattr('requests.get', mock_get)
|
||||
|
||||
public_key = 'CJxdItf4lz2PwEf4SmYNAu/c/VpmX39JEgC5YpH7fxg='
|
||||
power = 1
|
||||
node_id = 'unique_node_id_for_test_upsert_validator_show'
|
||||
|
||||
new_args = Namespace(action='new',
|
||||
public_key=public_key,
|
||||
power=1,
|
||||
node_id=node_id,
|
||||
sk=priv_validator_path,
|
||||
config={})
|
||||
election_id = run_upsert_validator_new(new_args, b)
|
||||
|
||||
show_args = Namespace(action='show',
|
||||
election_id=election_id)
|
||||
|
||||
resp = run_upsert_validator_show(show_args, b)
|
||||
|
||||
assert resp == (public_key, power, node_id)
|
||||
|
||||
|
||||
@pytest.mark.abci
|
||||
def test_upsert_validator_approve_with_tendermint(b, priv_validator_path, user_sk, validators):
|
||||
from bigchaindb.commands.bigchaindb import run_upsert_validator_new, \
|
||||
@ -414,7 +443,7 @@ def test_upsert_validator_approve_with_tendermint(b, priv_validator_path, user_s
|
||||
new_args = Namespace(action='new',
|
||||
public_key=public_key,
|
||||
power=1,
|
||||
node_id='12345',
|
||||
node_id='unique_node_id_for_test_upsert_validator_approve_with_tendermint',
|
||||
sk=priv_validator_path,
|
||||
config={})
|
||||
|
||||
@ -467,7 +496,7 @@ def test_upsert_validator_approve_called_with_bad_key(b, bad_validator_path, new
|
||||
run_upsert_validator_approve(args, b)
|
||||
|
||||
|
||||
def mock_get(height):
|
||||
def mock_get_validators(height):
|
||||
keys = node_keys()
|
||||
pub_key = list(keys.keys())[0]
|
||||
return [
|
||||
@ -484,7 +513,7 @@ def call_election(b, new_validator, node_key):
|
||||
return (202, '')
|
||||
|
||||
# patch the validator set. We now have one validator with power 10
|
||||
b.get_validators = mock_get
|
||||
b.get_validators = mock_get_validators
|
||||
b.write_transaction = mock_write
|
||||
|
||||
# our voters is a list of length 1, populated from our mocked validator
|
||||
@ -500,44 +529,3 @@ def call_election(b, new_validator, node_key):
|
||||
b.store_bulk_transactions([valid_election])
|
||||
|
||||
return b, election_id
|
||||
|
||||
|
||||
@pytest.mark.tendermint
|
||||
@pytest.mark.bdb
|
||||
def test_upsert_validator_show(b, priv_validator_path, user_sk, monkeypatch):
|
||||
from bigchaindb.commands.bigchaindb import run_upsert_validator_show, run_upsert_validator_new
|
||||
|
||||
def mock_get():
|
||||
return [
|
||||
{'pub_key': {'value': 'zL/DasvKulXZzhSNFwx4cLRXKkSM9GPK7Y0nZ4FEylM=',
|
||||
'type': 'tendermint/PubKeyEd25519'},
|
||||
'voting_power': 10}
|
||||
]
|
||||
|
||||
def mock_write(tx, mode):
|
||||
b.store_transaction(tx)
|
||||
return 202, ''
|
||||
|
||||
b.get_validators = mock_get
|
||||
b.write_transaction = mock_write
|
||||
|
||||
monkeypatch.setattr('requests.get', mock_get)
|
||||
|
||||
public_key = 'CJxdItf4lz2PwEf4SmYNAu/c/VpmX39JEgC5YpH7fxg='
|
||||
power = 1
|
||||
node_id = '12345'
|
||||
|
||||
new_args = Namespace(action='new',
|
||||
public_key=public_key,
|
||||
power=1,
|
||||
node_id='12345',
|
||||
sk=priv_validator_path,
|
||||
config={})
|
||||
election_id = run_upsert_validator_new(new_args, b)
|
||||
|
||||
show_args = Namespace(action='show',
|
||||
election_id=election_id)
|
||||
|
||||
resp = run_upsert_validator_show(show_args, b)
|
||||
|
||||
assert resp == (public_key, power, node_id)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user