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

fix: align empty account result for old blocks as ethereum #1484

Merged
merged 12 commits into from
Nov 25, 2022
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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="
Expand Down
11 changes: 10 additions & 1 deletion rpc/backend/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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})
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
st, ok := status.FromError(err)
// treat as account doesn't exist yet
if ok && st.Code() == codes.NotFound {
err = nil
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
}
return 0, err
}
var acc authtypes.AccountI
Expand Down
31 changes: 31 additions & 0 deletions tests/integration_tests/test_account.py
Original file line number Diff line number Diff line change
@@ -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):
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
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
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
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
4 changes: 2 additions & 2 deletions tests/integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down