A Python library for interacting and working with the Woop blockchain.
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.
 
 
 
pywiki/tests/sdk-pyhmy/test_account.py

116 lines
4.4 KiB

import pytest
import requests
from pyhmy import (
account
)
from pyhmy.rpc import (
exceptions
)
explorer_endpoint = 'http://localhost:9599'
endpoint_shard_one = 'http://localhost:9501'
local_test_address = 'one1zksj3evekayy90xt4psrz8h6j2v3hla4qwz4ur'
test_validator_address = 'one18tvf56zqjkjnak686lwutcp5mqfnvee35xjnhc'
genesis_block_number = 0
test_block_number = 1
fake_shard = 'http://example.com'
def _test_account_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_balance(setup_blockchain):
balance = _test_account_rpc(account.get_balance, local_test_address)
assert isinstance(balance, int)
assert balance > 0
@pytest.mark.run(order=2)
def test_get_balance_by_block(setup_blockchain):
balance = _test_account_rpc(account.get_balance_by_block, local_test_address, genesis_block_number)
assert isinstance(balance, int)
assert balance > 0
@pytest.mark.run(order=3)
def test_get_account_nonce(setup_blockchain):
true_nonce = _test_account_rpc(account.get_account_nonce, local_test_address, test_block_number, endpoint=endpoint_shard_one)
assert isinstance(true_nonce, int)
@pytest.mark.run(order=4)
def test_get_transaction_history(setup_blockchain):
tx_history = _test_account_rpc(account.get_transaction_history, local_test_address, endpoint=explorer_endpoint)
assert isinstance(tx_history, list)
assert len(tx_history) >= 0
@pytest.mark.run(order=5)
def test_get_staking_transaction_history(setup_blockchain):
staking_tx_history = _test_account_rpc(account.get_staking_transaction_history, test_validator_address, endpoint=explorer_endpoint)
assert isinstance(staking_tx_history, list)
assert len(staking_tx_history) > 0
@pytest.mark.run(order=6)
def test_get_balance_on_all_shards(setup_blockchain):
balances = _test_account_rpc(account.get_balance_on_all_shards, local_test_address)
assert isinstance(balances, list)
assert len(balances) == 2
@pytest.mark.run(order=7)
def test_get_total_balance(setup_blockchain):
total_balance = _test_account_rpc(account.get_total_balance, local_test_address)
assert isinstance(total_balance, int)
assert total_balance > 0
@pytest.mark.run(order=0)
def test_is_valid_address():
assert account.is_valid_address('one1zksj3evekayy90xt4psrz8h6j2v3hla4qwz4ur')
assert not account.is_valid_address('one1wje75aedczmj4dwjs0812xcg7vx0dy231cajk0')
@pytest.mark.run(order=8)
def test_get_transaction_count(setup_blockchain):
tx_count = _test_account_rpc(account.get_transaction_count, local_test_address, 'latest')
assert isinstance(tx_count, int)
assert tx_count > 0
@pytest.mark.run(order=9)
def test_get_transactions_count(setup_blockchain):
tx_count = _test_account_rpc(account.get_transactions_count, local_test_address, 'ALL')
@pytest.mark.run(order=10)
def test_get_staking_transactions_count(setup_blockchain):
tx_count = _test_account_rpc(account.get_staking_transactions_count, local_test_address, 'ALL')
assert isinstance(tx_count, int)
@pytest.mark.run(order=10)
def test_errors():
with pytest.raises(exceptions.RPCError):
account.get_balance('', fake_shard)
with pytest.raises(exceptions.RPCError):
account.get_balance_by_block('', 1, fake_shard)
with pytest.raises(exceptions.RPCError):
account.get_account_nonce('', 1, fake_shard)
with pytest.raises(exceptions.RPCError):
account.get_transaction_count('', 1, fake_shard)
with pytest.raises(exceptions.RPCError):
account.get_transactions_count('', 1, fake_shard)
with pytest.raises(exceptions.RPCError):
account.get_transactions_count('', 'ALL', fake_shard)
with pytest.raises(exceptions.RPCError):
account.get_transaction_history('', endpoint=fake_shard)
with pytest.raises(exceptions.RPCError):
account.get_staking_transaction_history('', endpoint=fake_shard)
with pytest.raises(exceptions.RPCError):
account.get_balance_on_all_shards('', endpoint=fake_shard)
with pytest.raises(exceptions.RPCError):
account.get_total_balance('', endpoint=fake_shard)