From 8a0469d318f3ff559605580db02213afae1f5076 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Tue, 22 Nov 2022 09:29:46 +0800 Subject: [PATCH 1/9] align result account as ethereum --- rpc/backend/utils.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/rpc/backend/utils.go b/rpc/backend/utils.go index 73dbce652e..79c0c0a512 100644 --- a/rpc/backend/utils.go +++ b/rpc/backend/utils.go @@ -10,6 +10,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" @@ -46,8 +48,15 @@ func (s sortGasAndReward) Less(i, j int) bool { // Todo: include the ability to specify a blockNumber func (b *Backend) getAccountNonce(accAddr common.Address, pending bool, height int64, logger log.Logger) (uint64, error) { queryClient := authtypes.NewQueryClient(b.clientCtx) - res, err := queryClient.Account(types.ContextWithHeight(height), &authtypes.QueryAccountRequest{Address: sdk.AccAddress(accAddr.Bytes()).String()}) + adr := sdk.AccAddress(accAddr.Bytes()).String() + ctx := types.ContextWithHeight(height) + res, err := queryClient.Account(ctx, &authtypes.QueryAccountRequest{Address: adr}) if err != nil { + st, ok := status.FromError(err) + // treat as account doesn't exist yet + if ok && st.Code() == codes.NotFound { + err = nil + } return 0, err } var acc authtypes.AccountI From 6846276338f912ddcec234cfd5e47f17e9eb01b6 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Wed, 23 Nov 2022 09:37:36 +0800 Subject: [PATCH 2/9] add test_get_transaction_count --- tests/integration_tests/test_account.py | 31 +++++++++++++++++++++++++ tests/integration_tests/utils.py | 4 ++-- 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 tests/integration_tests/test_account.py diff --git a/tests/integration_tests/test_account.py b/tests/integration_tests/test_account.py new file mode 100644 index 0000000000..e9ab620db9 --- /dev/null +++ b/tests/integration_tests/test_account.py @@ -0,0 +1,31 @@ +import os + +from eth_account import Account + +from .utils import ADDRS, w3_wait_for_new_blocks + + +def test_get_transaction_count(ethermint): + w3 = ethermint.w3 + blk = hex(w3.eth.block_number) + sender = ADDRS["validator"] + + # derive a new address + account_path = "m/44'/60'/0'/0/1" + mnemonic = os.getenv("COMMUNITY_MNEMONIC") + receiver = (Account.from_mnemonic(mnemonic, account_path=account_path)).address + n0 = w3.eth.get_transaction_count(receiver, blk) + # ensure tnx send in new block + w3_wait_for_new_blocks(w3, 1, sleep=0.1) + txhash = w3.eth.send_transaction( + { + "from": sender, + "to": receiver, + "value": 1000, + } + ) + receipt = w3.eth.wait_for_transaction_receipt(txhash) + assert receipt.status == 1 + [n1, n2] = [w3.eth.get_transaction_count(receiver, b) for b in [blk, "latest"]] + assert n0 == n1 + assert n0 == n2 diff --git a/tests/integration_tests/utils.py b/tests/integration_tests/utils.py index e0cad6d852..2d93148458 100644 --- a/tests/integration_tests/utils.py +++ b/tests/integration_tests/utils.py @@ -63,10 +63,10 @@ def wait_for_port(port, host="127.0.0.1", timeout=40.0): ) from ex -def w3_wait_for_new_blocks(w3, n): +def w3_wait_for_new_blocks(w3, n, sleep=0.5): begin_height = w3.eth.block_number while True: - time.sleep(0.5) + time.sleep(sleep) cur_height = w3.eth.block_number if cur_height - begin_height >= n: break From 523070c238a12b4419c3842d0b0f69d53b8c84ef Mon Sep 17 00:00:00 2001 From: mmsqe Date: Wed, 23 Nov 2022 09:47:59 +0800 Subject: [PATCH 3/9] add change doc --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 524092ce8e..7aad3a3aac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -92,6 +92,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (proto) [#1466](https://github.com/evmos/ethermint/pull/1466) Fix proto scripts and upgrade them to mirror current cosmos-sdk scripts * (rpc) [#1405](https://github.com/evmos/ethermint/pull/1405) Fix uninitialized chain ID field in gRPC requests. * (analytics) [#1434](https://github.com/evmos/ethermint/pull/1434) Remove unbound labels from custom tendermint metrics. +* (rpc) [#1484](https://github.com/evmos/ethermint/pull/1484) Align empty account result for old blocks as ethereum instead of return account not found error. + ## [v0.19.3] - 2022-10-14 From c5a920f28a2ed09c4e3accc15d411bdbdfeb2b43 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Wed, 23 Nov 2022 09:53:54 +0800 Subject: [PATCH 4/9] sync gomod2nix --- gomod2nix.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gomod2nix.toml b/gomod2nix.toml index 976248c459..6b4817adf5 100644 --- a/gomod2nix.toml +++ b/gomod2nix.toml @@ -97,8 +97,8 @@ schema = 3 version = "v1.0.0-alpha8" hash = "sha256-iXzXoS5Kfh5DBy+PhdFWraDWXda/3M4j7j4VECjv4CA=" [mod."github.com/cosmos/cosmos-sdk"] - version = "v0.46.5-0.20221114064055-2114ec42dfa1" - hash = "sha256-swqznmZfl2dlj/8ReJJs0zagFN2xpzF2ehsfVvPbohc=" + version = "v0.46.6" + hash = "sha256-H1VZxZUWXhpXiY3A9smLp09MEGpXmh+XvX6YUiXPcpQ=" [mod."github.com/cosmos/go-bip39"] version = "v1.0.0" hash = "sha256-Qm2aC2vaS8tjtMUbHmlBSagOSqbduEEDwc51qvQaBmA=" From 1386c5485088480676c1ebd585177b6babd5a542 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Wed, 23 Nov 2022 23:44:08 +0800 Subject: [PATCH 5/9] Apply suggestions from code review --- tests/integration_tests/test_account.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration_tests/test_account.py b/tests/integration_tests/test_account.py index e9ab620db9..140fa6aa07 100644 --- a/tests/integration_tests/test_account.py +++ b/tests/integration_tests/test_account.py @@ -15,7 +15,7 @@ def test_get_transaction_count(ethermint): mnemonic = os.getenv("COMMUNITY_MNEMONIC") receiver = (Account.from_mnemonic(mnemonic, account_path=account_path)).address n0 = w3.eth.get_transaction_count(receiver, blk) - # ensure tnx send in new block + # ensure transaction send in new block w3_wait_for_new_blocks(w3, 1, sleep=0.1) txhash = w3.eth.send_transaction( { From 61ebba80edffc0d14894a985fa06386048378603 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Thu, 24 Nov 2022 06:37:12 +0800 Subject: [PATCH 6/9] crosscheck with ws & geth --- tests/integration_tests/test_account.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/integration_tests/test_account.py b/tests/integration_tests/test_account.py index 140fa6aa07..435eff4366 100644 --- a/tests/integration_tests/test_account.py +++ b/tests/integration_tests/test_account.py @@ -1,12 +1,28 @@ import os +import pytest from eth_account import Account from .utils import ADDRS, w3_wait_for_new_blocks -def test_get_transaction_count(ethermint): - w3 = ethermint.w3 +@pytest.fixture(scope="module", params=["ethermint", "ethermint-ws", "geth"]) +def cluster(request, ethermint, geth): + provider = request.param + if provider == "ethermint": + yield ethermint + elif provider == "ethermint-ws": + ethermint_ws = ethermint.copy() + ethermint_ws.use_websocket() + yield ethermint_ws + elif provider == "geth": + yield geth + else: + raise NotImplementedError + + +def test_get_transaction_count(cluster): + w3 = cluster.w3 blk = hex(w3.eth.block_number) sender = ADDRS["validator"] From 58f4404b2bcc41c88bff55648ef52170314b1e27 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Thu, 24 Nov 2022 17:16:35 +0800 Subject: [PATCH 7/9] sync gomod2nix --- gomod2nix.toml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gomod2nix.toml b/gomod2nix.toml index 6b4817adf5..422a118ee7 100644 --- a/gomod2nix.toml +++ b/gomod2nix.toml @@ -362,8 +362,8 @@ schema = 3 version = "v0.0.5" hash = "sha256-/5i70IkH/qSW5KjGzv8aQNKh9tHoz98tqtL0K2DMFn4=" [mod."github.com/onsi/ginkgo/v2"] - version = "v2.5.0" - hash = "sha256-mu8Ry88hLAVv9bcvENfP08dBP/yN1DYZrFf6ejxp8co=" + version = "v2.5.1" + hash = "sha256-VB29+H9k7l6il63oXJvsjamSUhsw/e99iI/BeTCderA=" [mod."github.com/onsi/gomega"] version = "v1.24.1" hash = "sha256-REfxQTDRcO23GnmJfOW8/MmPJf9oE2grVvvGiC1eSbo=" @@ -527,8 +527,8 @@ schema = 3 version = "v0.0.0-20221116193143-41c2ba794472" hash = "sha256-uQuxuOvWRsdMii5M5QresisVd1E+Ss8s2WfR2n7QSXk=" [mod."google.golang.org/grpc"] - version = "v1.50.1" - hash = "sha256-38nk4qIme+fE57SsCqNxtCZnc8fyzzi4Sb60uDTT2KE=" + version = "v1.51.0" + hash = "sha256-RzH5DU13D/ulxxOouIKpdNt8eHdff7mrEnB+JUupbLU=" [mod."google.golang.org/protobuf"] version = "v1.28.2-0.20220831092852-f930b1dc76e8" hash = "sha256-li5hXlXwTJ5LIZ8bVki1AZ6UFI2gXHl33JwdX1dOrtM=" From 5f009aeece196eda008f34a0d0aa96ccfe0fd990 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Federico=20Kunze=20K=C3=BCllmer?= <31522760+fedekunze@users.noreply.github.com> Date: Thu, 24 Nov 2022 15:31:07 +0100 Subject: [PATCH 8/9] Update rpc/backend/utils.go --- rpc/backend/utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpc/backend/utils.go b/rpc/backend/utils.go index 79c0c0a512..506fe64b60 100644 --- a/rpc/backend/utils.go +++ b/rpc/backend/utils.go @@ -55,7 +55,7 @@ func (b *Backend) getAccountNonce(accAddr common.Address, pending bool, height i st, ok := status.FromError(err) // treat as account doesn't exist yet if ok && st.Code() == codes.NotFound { - err = nil + return 0, nil } return 0, err } From e43373466db24479b3cb3117fee8cc0937be2ff1 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Fri, 25 Nov 2022 03:00:08 +0800 Subject: [PATCH 9/9] use session provider --- tests/integration_tests/test_account.py | 63 ++++++++++--------------- 1 file changed, 24 insertions(+), 39 deletions(-) diff --git a/tests/integration_tests/test_account.py b/tests/integration_tests/test_account.py index 435eff4366..612307c5c7 100644 --- a/tests/integration_tests/test_account.py +++ b/tests/integration_tests/test_account.py @@ -1,47 +1,32 @@ import os -import pytest from eth_account import Account from .utils import ADDRS, w3_wait_for_new_blocks -@pytest.fixture(scope="module", params=["ethermint", "ethermint-ws", "geth"]) -def cluster(request, ethermint, geth): - provider = request.param - if provider == "ethermint": - yield ethermint - elif provider == "ethermint-ws": - ethermint_ws = ethermint.copy() - ethermint_ws.use_websocket() - yield ethermint_ws - elif provider == "geth": - yield geth - else: - raise NotImplementedError +def test_get_transaction_count(ethermint_rpc_ws, geth): + for p in [ethermint_rpc_ws, geth]: + w3 = p.w3 + blk = hex(w3.eth.block_number) + sender = ADDRS["validator"] - -def test_get_transaction_count(cluster): - w3 = cluster.w3 - blk = hex(w3.eth.block_number) - sender = ADDRS["validator"] - - # derive a new address - account_path = "m/44'/60'/0'/0/1" - mnemonic = os.getenv("COMMUNITY_MNEMONIC") - receiver = (Account.from_mnemonic(mnemonic, account_path=account_path)).address - n0 = w3.eth.get_transaction_count(receiver, blk) - # ensure transaction send in new block - w3_wait_for_new_blocks(w3, 1, sleep=0.1) - txhash = w3.eth.send_transaction( - { - "from": sender, - "to": receiver, - "value": 1000, - } - ) - receipt = w3.eth.wait_for_transaction_receipt(txhash) - assert receipt.status == 1 - [n1, n2] = [w3.eth.get_transaction_count(receiver, b) for b in [blk, "latest"]] - assert n0 == n1 - assert n0 == n2 + # derive a new address + account_path = "m/44'/60'/0'/0/1" + mnemonic = os.getenv("COMMUNITY_MNEMONIC") + receiver = (Account.from_mnemonic(mnemonic, account_path=account_path)).address + n0 = w3.eth.get_transaction_count(receiver, blk) + # ensure transaction send in new block + w3_wait_for_new_blocks(w3, 1, sleep=0.1) + txhash = w3.eth.send_transaction( + { + "from": sender, + "to": receiver, + "value": 1000, + } + ) + receipt = w3.eth.wait_for_transaction_receipt(txhash) + assert receipt.status == 1 + [n1, n2] = [w3.eth.get_transaction_count(receiver, b) for b in [blk, "latest"]] + assert n0 == n1 + assert n0 == n2