From 073a18dc2adc793b0ab0d390644cf39957c4d07a Mon Sep 17 00:00:00 2001 From: HuangYi Date: Fri, 12 Aug 2022 11:13:04 +0800 Subject: [PATCH 1/2] test: make get_proof integration tests more stable it could fail for error "proof queries at height <= 2 are not supported" if the latest block number <= 2 --- tests/integration_tests/test_types.py | 5 +++++ tests/integration_tests/utils.py | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/tests/integration_tests/test_types.py b/tests/integration_tests/test_types.py index a9f53b31d7..7e442a328b 100644 --- a/tests/integration_tests/test_types.py +++ b/tests/integration_tests/test_types.py @@ -12,6 +12,7 @@ deploy_contract, send_transaction, w3_wait_for_new_blocks, + wait_for_block, ) @@ -177,8 +178,10 @@ def send_and_get_hash(w3, tx_value=10): def test_get_proof(ethermint, geth): + wait_for_block(ethermint.cosmos_cli(), 3) eth_rpc = ethermint.w3.provider geth_rpc = geth.w3.provider + print(ethermint.w3.eth.block_number, geth.w3.eth.block_number) make_same_rpc_calls( eth_rpc, geth_rpc, @@ -315,6 +318,8 @@ def test_estimate_gas(ethermint, geth): def make_same_rpc_calls(rpc1, rpc2, method, params): res1 = rpc1.make_request(method, params) res2 = rpc2.make_request(method, params) + print("res1", res1) + print("res2", res2) res, err = same_types(res1, res2) assert res, err diff --git a/tests/integration_tests/utils.py b/tests/integration_tests/utils.py index a2ea48a132..9f27f9fa8f 100644 --- a/tests/integration_tests/utils.py +++ b/tests/integration_tests/utils.py @@ -1,6 +1,7 @@ import json import os import socket +import sys import time from pathlib import Path @@ -75,6 +76,22 @@ def wait_for_new_blocks(cli, n): break +def wait_for_block(cli, height, timeout=240): + for i in range(timeout * 2): + try: + status = cli.status() + except AssertionError as e: + print(f"get sync status failed: {e}", file=sys.stderr) + else: + current_height = int(status["SyncInfo"]["latest_block_height"]) + if current_height >= height: + break + print("current block height", current_height) + time.sleep(0.5) + else: + raise TimeoutError(f"wait for block {height} timeout") + + def deploy_contract(w3, jsonfile, args=(), key=KEYS["validator"]): """ deploy contract and return the deployed contract instance From 21bfa36e8ea03d0360fa8607dca0d890c55c5e26 Mon Sep 17 00:00:00 2001 From: yihuang Date: Fri, 12 Aug 2022 11:15:18 +0800 Subject: [PATCH 2/2] Apply suggestions from code review --- tests/integration_tests/test_types.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/integration_tests/test_types.py b/tests/integration_tests/test_types.py index 7e442a328b..0ec8831ebb 100644 --- a/tests/integration_tests/test_types.py +++ b/tests/integration_tests/test_types.py @@ -181,7 +181,6 @@ def test_get_proof(ethermint, geth): wait_for_block(ethermint.cosmos_cli(), 3) eth_rpc = ethermint.w3.provider geth_rpc = geth.w3.provider - print(ethermint.w3.eth.block_number, geth.w3.eth.block_number) make_same_rpc_calls( eth_rpc, geth_rpc, @@ -318,8 +317,6 @@ def test_estimate_gas(ethermint, geth): def make_same_rpc_calls(rpc1, rpc2, method, params): res1 = rpc1.make_request(method, params) res2 = rpc2.make_request(method, params) - print("res1", res1) - print("res2", res2) res, err = same_types(res1, res2) assert res, err