mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Problem: upsert-validator needs a command to 'show' election data
Solution: Wrote `upsert-validator show` as specified in BEP-21
This commit is contained in:
parent
1a1f16b65b
commit
96d39778c5
@ -139,6 +139,19 @@ def run_upsert_validator_new(args, bigchain):
|
|||||||
raise OperationError('Failed to commit election')
|
raise OperationError('Failed to commit election')
|
||||||
|
|
||||||
|
|
||||||
|
def run_upsert_validator_show(args, bigchain):
|
||||||
|
|
||||||
|
election = bigchain.get_transaction(args.election_id)
|
||||||
|
|
||||||
|
new_validator = election.asset['data']
|
||||||
|
|
||||||
|
public_key = new_validator['public_key']
|
||||||
|
power = new_validator['power']
|
||||||
|
node_id = new_validator['node_id']
|
||||||
|
|
||||||
|
return public_key, power, node_id
|
||||||
|
|
||||||
|
|
||||||
def _run_init():
|
def _run_init():
|
||||||
bdb = bigchaindb.BigchainDB()
|
bdb = bigchaindb.BigchainDB()
|
||||||
|
|
||||||
@ -260,6 +273,12 @@ def create_parser():
|
|||||||
dest='sk',
|
dest='sk',
|
||||||
help='Path to the private key of the election initiator.')
|
help='Path to the private key of the election initiator.')
|
||||||
|
|
||||||
|
show_election_parser = validator_subparser.add_parser('show',
|
||||||
|
help='Provides information about an election.')
|
||||||
|
|
||||||
|
show_election_parser.add_argument('election_id',
|
||||||
|
help='The transaction id of the election you wish to query.')
|
||||||
|
|
||||||
# parsers for showing/exporting config values
|
# parsers for showing/exporting config values
|
||||||
subparsers.add_parser('show-config',
|
subparsers.add_parser('show-config',
|
||||||
help='Show the current configuration')
|
help='Show the current configuration')
|
||||||
|
|||||||
@ -409,3 +409,44 @@ def test_upsert_validator_new_without_tendermint(b, priv_validator_path, user_sk
|
|||||||
resp = run_upsert_validator_new(args, b)
|
resp = run_upsert_validator_new(args, b)
|
||||||
|
|
||||||
assert b.get_transaction(resp)
|
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():
|
||||||
|
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