From ea6926ab4d351ea8f3cf2b2de0f927b929d83b9f Mon Sep 17 00:00:00 2001 From: Janet Liang <56005637+janet-harmony@users.noreply.github.com> Date: Fri, 22 May 2020 04:35:28 -0700 Subject: [PATCH] [blockchain] Add methods for getValidatorKeys & getBlockSignerKeys (#7) * [blockchain] Add methods for getValidatorKeys & getBlockSignerKeys * [blockchain] Update documentation for new methods * [test] Fix blockchain test ordering --- pyhmy/blockchain.py | 48 ++++++++++++++++++++++++++++++ tests/sdk-pyhmy/test_blockchain.py | 12 ++++++++ 2 files changed, 60 insertions(+) diff --git a/pyhmy/blockchain.py b/pyhmy/blockchain.py index 03b56de..d8e318e 100644 --- a/pyhmy/blockchain.py +++ b/pyhmy/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'] +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: """ 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'] +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: """ Get list of bad blocks in memory of specific node diff --git a/tests/sdk-pyhmy/test_blockchain.py b/tests/sdk-pyhmy/test_blockchain.py index 3f622ef..034bf6b 100644 --- a/tests/sdk-pyhmy/test_blockchain.py +++ b/tests/sdk-pyhmy/test_blockchain.py @@ -142,3 +142,15 @@ def test_get_bad_blocks(setup_blockchain): pytest.skip("Known error with hmy_getCurrentBadBlocks") bad_blocks = _test_blockchain_rpc(blockchain.get_bad_blocks) 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