def test_election_approve_called_with_bad_key(caplog, b, bad_validator_path, new_validator, node_key): from bigchaindb.commands.bigchaindb import run_election_approve from argparse import Namespace b, election_id = call_election(b, new_validator, node_key) # 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 caplog.at_level(logging.ERROR): assert not run_election_approve(args, b) assert caplog.records[0].msg == 'The key you provided does not match any of '\ 'the eligible voters in this election.'
def test_election_approve_without_tendermint(caplog, b, priv_validator_path, new_validator, node_key): from bigchaindb.commands.bigchaindb import run_election_approve from argparse import Namespace b, election_id = call_election(b, new_validator, node_key) # 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={}) # assert returned id is in the db with caplog.at_level(logging.INFO): approval_id = run_election_approve(args, b) assert caplog.records[0].msg == '[SUCCESS] Your vote has been submitted' assert b.get_transaction(approval_id)
def test_election_approve_without_tendermint(caplog, b, priv_validator_path, new_validator, node_key): from bigchaindb.commands.bigchaindb import run_election_approve from argparse import Namespace b, election_id = call_election(b, new_validator, node_key) # call run_election_approve with args that point to the election args = Namespace(action='approve', election_id=election_id, sk=priv_validator_path, config={}) # assert returned id is in the db with caplog.at_level(logging.INFO): approval_id = run_election_approve(args, b) assert caplog.records[ 0].msg == '[SUCCESS] Your vote has been submitted' assert b.get_transaction(approval_id)
def test_election_approve_failure(caplog, b, priv_validator_path, new_validator, node_key): from bigchaindb.commands.bigchaindb import run_election_approve from argparse import Namespace b, election_id = call_election(b, new_validator, node_key) def mock_write(tx, mode): b.store_bulk_transactions([tx]) return (400, '') b.write_transaction = mock_write # 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={}) with caplog.at_level(logging.ERROR): assert not run_election_approve(args, b) assert caplog.records[0].msg == 'Failed to commit vote'
def test_election_approve_with_tendermint(b, priv_validator_path, user_sk, validators): from bigchaindb.commands.bigchaindb import (run_election_new_upsert_validator, run_election_approve) public_key = 'CJxdItf4lz2PwEf4SmYNAu/c/VpmX39JEgC5YpH7fxg=' new_args = Namespace(action='new', election_type='upsert_validator', public_key=public_key, power=1, node_id='fb7140f03a4ffad899fabbbf655b97e0321add66', sk=priv_validator_path, config={}) election_id = run_election_new_upsert_validator(new_args, b) assert election_id args = Namespace(action='approve', election_id=election_id, sk=priv_validator_path, config={}) approve = run_election_approve(args, b) assert b.get_transaction(approve)
def test_election_approve_with_tendermint(b, priv_validator_path, user_sk, validators): from bigchaindb.commands.bigchaindb import ( run_election_new_upsert_validator, run_election_approve) public_key = 'CJxdItf4lz2PwEf4SmYNAu/c/VpmX39JEgC5YpH7fxg=' new_args = Namespace(action='new', election_type='upsert-validator', public_key=public_key, power=1, node_id='fb7140f03a4ffad899fabbbf655b97e0321add66', sk=priv_validator_path, config={}) election_id = run_election_new_upsert_validator(new_args, b) assert election_id args = Namespace(action='approve', election_id=election_id, sk=priv_validator_path, config={}) approve = run_election_approve(args, b) assert b.get_transaction(approve)