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

fix(rpc): align block number input behaviour for eth_getProof #1639

Merged
merged 5 commits into from
Jan 27, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (rpc) [#1613](https:/evmos/ethermint/pull/1613) Change the default json-rpc listen address to localhost.
* (rpc) [#1611](https:/evmos/ethermint/pull/1611) Add missing next fee in fee history, fix wrong oldestBlock and align earliest input as ethereum.
* (proto) [#1586](https:/evmos/ethermint/pull/1586) Avoid duplicate register proto type in `evm` & `feemarket`
* (rpc) [#1639](https:/evmos/ethermint/pull/1639) Align block number input behaviour for `eth_getProof` as Ethereum.

## [v0.20.0] - 2022-12-28

Expand Down
6 changes: 3 additions & 3 deletions rpc/backend/account_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,20 @@ func (suite *BackendTestSuite) TestGetProof() {
RegisterAccount(queryClient, addr, bn.Int64())

// Use the IAVL height if a valid tendermint height is passed in.
ivalHeight := bn.Int64() - 1
iavlHeight := bn.Int64()
RegisterABCIQueryWithOptions(
client,
bn.Int64(),
"store/evm/key",
evmtypes.StateKey(address1, common.HexToHash("0x0").Bytes()),
tmrpcclient.ABCIQueryOptions{Height: ivalHeight, Prove: true},
tmrpcclient.ABCIQueryOptions{Height: iavlHeight, Prove: true},
)
RegisterABCIQueryWithOptions(
client,
bn.Int64(),
"store/acc/key",
authtypes.AddressStoreKey(sdk.AccAddress(address1.Bytes())),
tmrpcclient.ABCIQueryOptions{Height: ivalHeight, Prove: true},
tmrpcclient.ABCIQueryOptions{Height: iavlHeight, Prove: true},
)
},
true,
Expand Down
3 changes: 0 additions & 3 deletions rpc/types/query_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ func (QueryClient) GetProof(clientCtx client.Context, storeKey string, key []byt
return nil, nil, fmt.Errorf("proof queries at height <= 2 are not supported")
}

// Use the IAVL height if a valid tendermint height is passed in.
height--

abciReq := abci.RequestQuery{
Path: fmt.Sprintf("store/%s/key", storeKey),
Data: key,
Expand Down
29 changes: 29 additions & 0 deletions tests/integration_tests/hardhat/contracts/StateContract.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract StateContract {
address payable private owner;
uint256 storedData;

constructor() {
owner = payable(msg.sender);
}

modifier onlyOwner() {
require(msg.sender == owner, "tx sender is not contract owner");
_;
}

function add(uint256 a, uint256 b) public returns (uint256) {
storedData = a + b;
return storedData;
}

function get() public view returns (uint256) {
return storedData;
}

function destruct() public onlyOwner {
selfdestruct(owner);
}
}
41 changes: 41 additions & 0 deletions tests/integration_tests/test_storage_proof.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import pytest

from .network import setup_ethermint
from .utils import CONTRACTS, deploy_contract


@pytest.fixture(scope="module")
def custom_ethermint(tmp_path_factory):
path = tmp_path_factory.mktemp("storage-proof")
yield from setup_ethermint(path, 26800, long_timeout_commit=True)


@pytest.fixture(scope="module", params=["ethermint", "geth"])
def cluster(request, custom_ethermint, geth):
"""
run on both ethermint and geth
"""
provider = request.param
if provider == "ethermint":
yield custom_ethermint
elif provider == "geth":
yield geth
else:
raise NotImplementedError


def test_basic(cluster):
_, res = deploy_contract(
cluster.w3,
CONTRACTS["StateContract"],
)
method = "eth_getProof"
storage_keys = ["0x0", "0x1"]
proof = (
cluster.w3.provider.make_request(
method, [res["contractAddress"], storage_keys, hex(res["blockNumber"])]
)
)["result"]
for proof in proof["storageProof"]:
if proof["key"] == storage_keys[0]:
assert proof["value"] != "0x0"
1 change: 1 addition & 0 deletions tests/integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"BurnGas": "BurnGas.sol",
"TestChainID": "ChainID.sol",
"Mars": "Mars.sol",
"StateContract": "StateContract.sol",
}


Expand Down