From 66e8cdbe02074fb1c0582a3c473d8cf7e8f2837c Mon Sep 17 00:00:00 2001 From: yihuang Date: Fri, 12 Aug 2022 11:23:02 +0800 Subject: [PATCH] fix: make get_proof integration tests more stable (#1236) * 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 * Apply suggestions from code review --- tests/integration_tests/test_types.py | 2 ++ tests/integration_tests/utils.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/tests/integration_tests/test_types.py b/tests/integration_tests/test_types.py index a9f53b31..0ec8831e 100644 --- a/tests/integration_tests/test_types.py +++ b/tests/integration_tests/test_types.py @@ -12,6 +12,7 @@ from .utils import ( deploy_contract, send_transaction, w3_wait_for_new_blocks, + wait_for_block, ) @@ -177,6 +178,7 @@ 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 make_same_rpc_calls( diff --git a/tests/integration_tests/utils.py b/tests/integration_tests/utils.py index a2ea48a1..9f27f9fa 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