You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
3.6 KiB
94 lines
3.6 KiB
5 years ago
|
import pytest
|
||
|
import requests
|
||
|
|
||
|
from pyhmy import (
|
||
|
staking
|
||
|
)
|
||
|
|
||
|
from pyhmy.rpc import (
|
||
|
exceptions
|
||
|
)
|
||
|
|
||
|
|
||
5 years ago
|
explorer_endpoint = 'http://localhost:9599'
|
||
5 years ago
|
test_validator_address = 'one18tvf56zqjkjnak686lwutcp5mqfnvee35xjnhc'
|
||
|
|
||
|
def _test_staking_rpc(fn, *args, **kwargs):
|
||
|
if not callable(fn):
|
||
|
pytest.fail(f'Invalid function: {fn}')
|
||
|
|
||
|
try:
|
||
|
response = fn(*args, **kwargs)
|
||
|
except Exception as e:
|
||
|
if isinstance(e, exceptions.RPCError) and 'does not exist/is not available' in str(e):
|
||
|
pytest.skip(f'{str(e)}')
|
||
|
pytest.fail(f'Unexpected error: {e.__class__} {e}')
|
||
|
return response
|
||
|
|
||
|
@pytest.mark.run(order=1)
|
||
|
def test_get_all_validator_addresses(setup_blockchain):
|
||
|
validator_addresses = _test_staking_rpc(staking.get_all_validator_addresses)
|
||
5 years ago
|
assert isinstance(validator_addresses, list)
|
||
5 years ago
|
assert len(validator_addresses) > 0
|
||
|
assert test_validator_address in validator_addresses
|
||
|
|
||
|
@pytest.mark.run(order=2)
|
||
|
def test_get_validator_information(setup_blockchain):
|
||
5 years ago
|
info = _test_staking_rpc(staking.get_validator_information, test_validator_address)
|
||
|
assert isinstance(info, dict)
|
||
5 years ago
|
|
||
|
@pytest.mark.run(order=3)
|
||
|
def test_get_all_validator_information(setup_blockchain):
|
||
|
all_validator_information = _test_staking_rpc(staking.get_all_validator_information)
|
||
5 years ago
|
assert isinstance(all_validator_information, list)
|
||
5 years ago
|
assert len(all_validator_information) > 0
|
||
|
|
||
|
@pytest.mark.run(order=4)
|
||
|
def test_get_delegations_by_delegator(setup_blockchain):
|
||
|
delegations = _test_staking_rpc(staking.get_delegations_by_delegator, test_validator_address)
|
||
5 years ago
|
assert isinstance(delegations, list)
|
||
5 years ago
|
assert len(delegations) > 0
|
||
|
|
||
|
@pytest.mark.run(order=5)
|
||
|
def test_get_delegations_by_validator(setup_blockchain):
|
||
|
delegations = _test_staking_rpc(staking.get_delegations_by_validator, test_validator_address)
|
||
5 years ago
|
assert isinstance(delegations, list)
|
||
5 years ago
|
assert len(delegations) > 0
|
||
|
|
||
|
@pytest.mark.run(order=6)
|
||
|
def test_get_current_utility_metrics(setup_blockchain):
|
||
5 years ago
|
metrics = _test_staking_rpc(staking.get_current_utility_metrics)
|
||
|
assert isinstance(metrics, dict)
|
||
5 years ago
|
|
||
|
@pytest.mark.run(order=7)
|
||
|
def test_get_staking_network_info(setup_blockchain):
|
||
5 years ago
|
info = _test_staking_rpc(staking.get_staking_network_info)
|
||
|
assert isinstance(info, dict)
|
||
5 years ago
|
|
||
|
@pytest.mark.run(order=8)
|
||
|
def test_get_super_committees(setup_blockchain):
|
||
5 years ago
|
committee = _test_staking_rpc(staking.get_super_committees)
|
||
|
assert isinstance(committee, dict)
|
||
5 years ago
|
|
||
|
@pytest.mark.run(order=9)
|
||
|
def test_get_raw_median_stake_snapshot(setup_blockchain):
|
||
5 years ago
|
median_stake = _test_staking_rpc(staking.get_raw_median_stake_snapshot)
|
||
|
assert isinstance(median_stake, dict)
|
||
5 years ago
|
|
||
|
@pytest.mark.run(order=10)
|
||
|
def test_get_validator_information_by_block(setup_blockchain):
|
||
|
# Apparently validator information not created until block after create-validator transaction is accepted, so +1 block
|
||
5 years ago
|
info = _test_staking_rpc(staking.get_validator_information_by_block, test_validator_address, setup_blockchain + 1, endpoint=explorer_endpoint)
|
||
|
assert isinstance(info, dict)
|
||
5 years ago
|
|
||
|
@pytest.mark.run(order=11)
|
||
|
def test_get_validator_information_by_block(setup_blockchain):
|
||
|
# Apparently validator information not created until block after create-validator transaction is accepted, so +1 block
|
||
5 years ago
|
info = _test_staking_rpc(staking.get_all_validator_information_by_block, setup_blockchain + 1, endpoint=explorer_endpoint)
|
||
|
assert isinstance(info, list)
|
||
5 years ago
|
|
||
|
@pytest.mark.run(order=12)
|
||
|
def test_get_delegations_by_delegator_by_block(setup_blockchain):
|
||
5 years ago
|
delegations = _test_staking_rpc(staking.get_delegations_by_delegator_by_block, test_validator_address, setup_blockchain + 1, endpoint=explorer_endpoint)
|
||
|
assert isinstance(delegations, list)
|