Skip to content

Commit

Permalink
Problem: bypass withdrawals root in get block test (#379)
Browse files Browse the repository at this point in the history
add wait to avoid block not found err
  • Loading branch information
mmsqe authored Nov 23, 2023
1 parent 6f3ad29 commit b3fcb10
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
24 changes: 19 additions & 5 deletions tests/integration_tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
send_transaction,
w3_wait_for_block,
w3_wait_for_new_blocks,
wait_for_fn,
)


Expand All @@ -29,8 +30,16 @@ def get_blocks(ethermint_rpc_ws, geth, with_transactions):
w3: Web3 = ethermint_rpc_ws.w3
eth_rpc = w3.provider
geth_rpc = geth.w3.provider
w3_wait_for_new_blocks(w3, 2)

def wait_blk():
res = geth_rpc.make_request("eth_getBlockByNumber", ["0x1", True])
return res["result"]

geth_blk = wait_for_fn("wait_blk", wait_blk)

make_same_rpc_calls(
eth_rpc, geth_rpc, "eth_getBlockByNumber", ["0x0", with_transactions]
eth_rpc, geth_rpc, "eth_getBlockByNumber", ["0x2", with_transactions]
)

make_same_rpc_calls(
Expand All @@ -45,7 +54,7 @@ def get_blocks(ethermint_rpc_ws, geth, with_transactions):
geth_rsp = geth_rpc.make_request(
"eth_getBlockByHash",
[
"0x124d099a1f435d3a6155e5d157ff1078eaefb742435892677ee5b3cb5e6fa055",
geth_blk["hash"],
with_transactions,
],
)
Expand Down Expand Up @@ -328,13 +337,18 @@ def test_fee_history(ethermint_rpc_ws, geth):

def test_estimate_gas(ethermint_rpc_ws, geth):
tx = {"to": ADDRS["community"], "from": ADDRS["validator"]}

w3: Web3 = ethermint_rpc_ws.w3
eth_rpc = w3.provider
geth_rpc = geth.w3.provider

def wait_blk():
res = geth_rpc.make_request("eth_getBlockByNumber", ["0x1", True])
return res["result"]

wait_for_fn("wait_blk", wait_blk)
make_same_rpc_calls(eth_rpc, geth_rpc, "eth_estimateGas", [tx])
make_same_rpc_calls(eth_rpc, geth_rpc, "eth_estimateGas", [tx, "0x0"])
make_same_rpc_calls(eth_rpc, geth_rpc, "eth_estimateGas", [tx, "0x5000"])
make_same_rpc_calls(eth_rpc, geth_rpc, "eth_estimateGas", [tx, "0x1"])
make_same_rpc_calls(eth_rpc, geth_rpc, "eth_estimateGas", [tx, "0x5"])
make_same_rpc_calls(eth_rpc, geth_rpc, "eth_estimateGas", [{}])


Expand Down
11 changes: 11 additions & 0 deletions tests/integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,17 @@ def wait_for_block_time(cli, t):
time.sleep(0.5)


def wait_for_fn(name, fn, *, timeout=240, interval=1):
for i in range(int(timeout / interval)):
result = fn()
print("check", name, result)
if result:
return result
time.sleep(interval)
else:
raise TimeoutError(f"wait for {name} timeout")


def deploy_contract(w3, jsonfile, args=(), key=KEYS["validator"]):
"""
deploy contract and return the deployed contract instance
Expand Down

0 comments on commit b3fcb10

Please sign in to comment.