From 99bb365c0d9c724a59c7cf183fbf9f3eaf7a8b4f Mon Sep 17 00:00:00 2001 From: mmsqe Date: Thu, 26 Jan 2023 10:51:18 +0800 Subject: [PATCH] add query future account test --- tests/integration_tests/test_account.py | 49 +++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/tests/integration_tests/test_account.py b/tests/integration_tests/test_account.py index 612307c5c7..26ee51bd4e 100644 --- a/tests/integration_tests/test_account.py +++ b/tests/integration_tests/test_account.py @@ -1,20 +1,50 @@ import os +import pytest from eth_account import Account +from web3 import Web3 +from .network import setup_ethermint from .utils import ADDRS, w3_wait_for_new_blocks +@pytest.fixture(scope="module") +def custom_ethermint(tmp_path_factory): + path = tmp_path_factory.mktemp("account") + yield from setup_ethermint(path, 26700, long_timeout_commit=True) + + +@pytest.fixture(scope="module", params=["ethermint", "ethermint-ws", "geth"]) +def cluster(request, custom_ethermint, geth): + """ + run on ethermint, ethermint websocket and geth + """ + provider = request.param + if provider == "ethermint": + yield custom_ethermint + elif provider == "ethermint-ws": + ethermint_ws = custom_ethermint.copy() + ethermint_ws.use_websocket() + yield ethermint_ws + elif provider == "geth": + yield geth + else: + raise NotImplementedError + + +def derive_new_address(n=1): + # derive a new address + account_path = f"m/44'/60'/0'/0/{n}" + mnemonic = os.getenv("COMMUNITY_MNEMONIC") + return (Account.from_mnemonic(mnemonic, account_path=account_path)).address + def test_get_transaction_count(ethermint_rpc_ws, geth): for p in [ethermint_rpc_ws, geth]: w3 = p.w3 blk = hex(w3.eth.block_number) sender = ADDRS["validator"] - # derive a new address - account_path = "m/44'/60'/0'/0/1" - mnemonic = os.getenv("COMMUNITY_MNEMONIC") - receiver = (Account.from_mnemonic(mnemonic, account_path=account_path)).address + receiver = derive_new_address() n0 = w3.eth.get_transaction_count(receiver, blk) # ensure transaction send in new block w3_wait_for_new_blocks(w3, 1, sleep=0.1) @@ -30,3 +60,14 @@ def test_get_transaction_count(ethermint_rpc_ws, geth): [n1, n2] = [w3.eth.get_transaction_count(receiver, b) for b in [blk, "latest"]] assert n0 == n1 assert n0 == n2 + + +def test_query_future_blk(cluster): + w3: Web3 = cluster.w3 + acc = derive_new_address(2) + current = w3.eth.block_number + future = current + 1000 + with pytest.raises(ValueError) as exc: + w3.eth.get_transaction_count(acc, hex(future)) + print(acc, str(exc)) + assert "-32000" in str(exc)