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
This commit is contained in:
yihuang 2022-08-12 11:23:02 +08:00 committed by GitHub
parent 77ed4aa754
commit 66e8cdbe02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -12,6 +12,7 @@ from .utils import (
deploy_contract, deploy_contract,
send_transaction, send_transaction,
w3_wait_for_new_blocks, 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): def test_get_proof(ethermint, geth):
wait_for_block(ethermint.cosmos_cli(), 3)
eth_rpc = ethermint.w3.provider eth_rpc = ethermint.w3.provider
geth_rpc = geth.w3.provider geth_rpc = geth.w3.provider
make_same_rpc_calls( make_same_rpc_calls(

View File

@ -1,6 +1,7 @@
import json import json
import os import os
import socket import socket
import sys
import time import time
from pathlib import Path from pathlib import Path
@ -75,6 +76,22 @@ def wait_for_new_blocks(cli, n):
break 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"]): def deploy_contract(w3, jsonfile, args=(), key=KEYS["validator"]):
""" """
deploy contract and return the deployed contract instance deploy contract and return the deployed contract instance