def test_upsert_validator_new_without_tendermint(b, priv_validator_path, user_sk, monkeypatch): 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, '') b.get_validators = mock_get b.write_transaction = mock_write args = Namespace(action='new', public_key='CJxdItf4lz2PwEf4SmYNAu/c/VpmX39JEgC5YpH7fxg=', power=1, node_id='12345', sk=priv_validator_path, config={}) resp = run_upsert_validator_new(args, b) assert b.get_transaction(resp)
def test_upsert_validator_new_with_tendermint(b, priv_validator_path, user_sk, monkeypatch): """WIP: Will be fixed and activated in the next PR """ from bigchaindb.commands.bigchaindb import run_upsert_validator_new import time time.sleep(3) # b.get_validators = mock_get # mock_get_validators = mock_get # monkeypatch.setattr('requests.get', mock_get) 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)
def test_upsert_validator_new_with_tendermint(b, priv_validator_path, user_sk, monkeypatch): """WIP: Will be fixed and activated in the next PR """ from bigchaindb.commands.bigchaindb import run_upsert_validator_new import time 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) 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)
def test_upsert_validator_new_invalid_election(caplog, b, priv_validator_path, user_sk): from bigchaindb.commands.bigchaindb import run_upsert_validator_new args = Namespace(action='new', public_key='CJxdItf4lz2PwEf4SmYNAu/c/VpmX39JEgC5YpH7fxg=', power=10, node_id='fb7140f03a4ffad899fabbbf655b97e0321add66', sk='/tmp/invalid/path/key.json', config={}) with caplog.at_level(logging.ERROR): assert not run_upsert_validator_new(args, b) assert caplog.records[0].msg.__class__ == FileNotFoundError
def test_upsert_validator_new_with_tendermint(b, priv_validator_path, user_sk, validators): from bigchaindb.commands.bigchaindb import run_upsert_validator_new new_args = Namespace(action='new', public_key='HHG0IQRybpT6nJMIWWFWhMczCLHt6xcm7eP52GnGuPY=', power=1, node_id='unique_node_id_for_test_upsert_validator_new_with_tendermint', sk=priv_validator_path, config={}) election_id = run_upsert_validator_new(new_args, b) assert b.get_transaction(election_id)
def test_upsert_validator_new_with_tendermint(b, priv_validator_path, user_sk, validators): from bigchaindb.commands.bigchaindb import run_upsert_validator_new 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={}) election_id = run_upsert_validator_new(new_args, b) assert b.get_transaction(election_id)
def test_upsert_validator_new_election_invalid_power(caplog, b, priv_validator_path, user_sk): from bigchaindb.commands.bigchaindb import run_upsert_validator_new from bigchaindb.common.exceptions import InvalidPowerChange def mock_write(tx, mode): b.store_bulk_transactions([tx]) return (400, '') b.write_transaction = mock_write b.get_validators = mock_get_validators args = Namespace(action='new', public_key='CJxdItf4lz2PwEf4SmYNAu/c/VpmX39JEgC5YpH7fxg=', power=10, node_id='fb7140f03a4ffad899fabbbf655b97e0321add66', sk=priv_validator_path, config={}) with caplog.at_level(logging.ERROR): assert not run_upsert_validator_new(args, b) assert caplog.records[0].msg.__class__ == InvalidPowerChange
def test_upsert_validator_new_without_tendermint(b, priv_validator_path, user_sk): from bigchaindb.commands.bigchaindb import run_upsert_validator_new def mock_write(tx, mode): b.store_bulk_transactions([tx]) return (202, '') b.get_validators = mock_get b.write_transaction = mock_write args = Namespace(action='new', public_key='CJxdItf4lz2PwEf4SmYNAu/c/VpmX39JEgC5YpH7fxg=', power=1, node_id='12345', sk=priv_validator_path, config={}) resp = run_upsert_validator_new(args, b) assert b.get_transaction(resp)
def test_upsert_validator_new_without_tendermint(caplog, b, priv_validator_path, user_sk): from bigchaindb.commands.bigchaindb import run_upsert_validator_new def mock_write(tx, mode): b.store_bulk_transactions([tx]) return (202, '') b.get_validators = mock_get_validators b.write_transaction = mock_write args = Namespace(action='new', public_key='CJxdItf4lz2PwEf4SmYNAu/c/VpmX39JEgC5YpH7fxg=', power=1, node_id='fb7140f03a4ffad899fabbbf655b97e0321add66', sk=priv_validator_path, config={}) with caplog.at_level(logging.INFO): election_id = run_upsert_validator_new(args, b) assert caplog.records[0].msg == '[SUCCESS] Submitted proposal with id: ' + election_id assert b.get_transaction(election_id)
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) public_key = 'CJxdItf4lz2PwEf4SmYNAu/c/VpmX39JEgC5YpH7fxg=' new_args = Namespace(action='new', public_key=public_key, power=1, node_id='fb7140f03a4ffad899fabbbf655b97e0321add66', sk=priv_validator_path, config={}) election_id = run_upsert_validator_new(new_args, b) args = Namespace(action='approve', election_id=election_id, sk=priv_validator_path, config={}) approve = run_upsert_validator_approve(args, b) assert b.get_transaction(approve)
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 public_key = '8eJ8q9ZQpReWyQT5aFCiwtZ5wDZC4eDnCen88p3tQ6ie' 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) args = Namespace(action='approve', election_id=election_id, sk=priv_validator_path, config={}) approve = run_upsert_validator_approve(args, b) assert b.get_transaction(approve)