[blockchain] Add methods for getValidatorKeys & getBlockSignerKeys (#7)

* [blockchain] Add methods for getValidatorKeys & getBlockSignerKeys

* [blockchain] Update documentation for new methods

* [test] Fix blockchain test ordering
fix
Janet Liang 5 years ago committed by GitHub
parent 6881847544
commit ea6926ab4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 48
      pyhmy/blockchain.py
  2. 12
      tests/sdk-pyhmy/test_blockchain.py

@ -480,6 +480,30 @@ def get_block_signers(block_num, endpoint=_default_endpoint, timeout=_default_ti
return rpc_request('hmy_getBlockSigners', params=params, endpoint=endpoint, timeout=timeout)['result'] return rpc_request('hmy_getBlockSigners', params=params, endpoint=endpoint, timeout=timeout)['result']
def get_block_signer_keys(block_num, endpoint=_default_endpoint, timeout=_default_timeout) -> list:
"""
Get list of block signer public bls keys for specific block number
Parameters
----------
block_num: int
Block number to get signer keys for
endpoint: :obj:`str`, optional
Endpoint to send request to
timeout: :obj:`int`, optional
Timeout in seconds
Returns
-------
list
List of bls public keys that signed the block
"""
params = [
str(hex(block_num))
]
return rpc_request('hmy_getBlockSignerKeys', params=params, endpoint=endpoint, timeout=timeout)['result']
def get_validators(epoch, endpoint=_default_endpoint, timeout=_default_timeout) -> dict: def get_validators(epoch, endpoint=_default_endpoint, timeout=_default_timeout) -> dict:
""" """
Get list of validators for specific epoch number Get list of validators for specific epoch number
@ -504,6 +528,30 @@ def get_validators(epoch, endpoint=_default_endpoint, timeout=_default_timeout)
return rpc_request('hmy_getValidators', params=params, endpoint=endpoint, timeout=timeout)['result'] return rpc_request('hmy_getValidators', params=params, endpoint=endpoint, timeout=timeout)['result']
def get_validator_keys(epoch, endpoint=_default_endpoint, timeout=_default_timeout) -> list:
"""
Get list of validator public bls keys for specific epoch number
Parameters
----------
epoch: int
Epoch to get list of validator keys for
endpoint: :obj:`str`, optional
Endpoint to send request to
timeout: :obj:`int`, optional
Timeout in seconds
Returns
-------
list
List of bls public keys in the validator committee
"""
params = [
epoch
]
return rpc_request('hmy_getValidatorKeys', params=params, endpoint=endpoint, timeout=timeout)['result']
def get_bad_blocks(endpoint=_default_endpoint, timeout=_default_timeout) -> list: def get_bad_blocks(endpoint=_default_endpoint, timeout=_default_timeout) -> list:
""" """
Get list of bad blocks in memory of specific node Get list of bad blocks in memory of specific node

@ -142,3 +142,15 @@ def test_get_bad_blocks(setup_blockchain):
pytest.skip("Known error with hmy_getCurrentBadBlocks") pytest.skip("Known error with hmy_getCurrentBadBlocks")
bad_blocks = _test_blockchain_rpc(blockchain.get_bad_blocks) bad_blocks = _test_blockchain_rpc(blockchain.get_bad_blocks)
assert isinstance(bad_blocks, list) assert isinstance(bad_blocks, list)
@pytest.mark.run(order=21)
def test_get_validator_keys(setup_blockchain):
keys = _test_blockchain_rpc(blockchain.get_validator_keys, test_epoch_number)
assert isinstance(keys, list)
assert len(keys) > 0
@pytest.mark.run(order=22)
def test_get_block_signer_keys(setup_blockchain):
keys = _test_blockchain_rpc(blockchain.get_block_signer_keys, test_block_number)
assert isinstance(keys, list)
assert len(keys) > 0

Loading…
Cancel
Save