Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

fix(rpc): get_proof test fail because block numbers are not high enough #1239

Merged
merged 5 commits into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions rpc/backend/account_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ func (b *Backend) GetProof(address common.Address, storageKeys []string, blockNr
height := blockNum.Int64()
_, err = b.GetTendermintBlockByNumber(blockNum)
if err != nil {
// Get 'latest' proof if query is in the future
// this imitates geth behavior
height = 0
// the error message imitates geth behavior
return nil, errors.New("header not found")
}
ctx := rpctypes.ContextWithHeight(height)

Expand Down
8 changes: 5 additions & 3 deletions tests/integration_tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
KEYS,
deploy_contract,
send_transaction,
w3_wait_for_block,
w3_wait_for_new_blocks,
wait_for_block,
)


Expand Down Expand Up @@ -178,7 +178,9 @@ def send_and_get_hash(w3, tx_value=10):


def test_get_proof(ethermint, geth):
wait_for_block(ethermint.cosmos_cli(), 3)
# on ethermint the proof query will fail for block numbers <= 2
# so we must wait for several blocks
w3_wait_for_block(ethermint.w3, 3)
eth_rpc = ethermint.w3.provider
geth_rpc = geth.w3.provider
make_same_rpc_calls(
Expand All @@ -192,7 +194,7 @@ def test_get_proof(ethermint, geth):
eth_rpc,
geth_rpc,
"eth_getProof",
["0x57f96e6b86cdefdb3d412547816a82e3e0ebf9d2", ["0x0"], "0x32"],
["0x57f96e6b86cdefdb3d412547816a82e3e0ebf9d2", ["0x0"], "0x1024"],
)

_ = send_and_get_hash(ethermint.w3)
Expand Down
15 changes: 15 additions & 0 deletions tests/integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ def wait_for_block(cli, height, timeout=240):
raise TimeoutError(f"wait for block {height} timeout")


def w3_wait_for_block(w3, height, timeout=240):
for i in range(timeout * 2):
try:
current_height = w3.eth.block_number
except Exception as e:
print(f"get json-rpc block number failed: {e}", file=sys.stderr)
else:
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
Expand Down