Skip to content

Commit

Permalink
fix: align empty account result for old blocks as ethereum (evmos#1484)…
Browse files Browse the repository at this point in the history
… (#221)

* align result account as ethereum

* add test_get_transaction_count

* add change doc

* sync gomod2nix

* Apply suggestions from code review

* crosscheck with ws & geth

* sync gomod2nix

* Update rpc/backend/utils.go

* use session provider

Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
  • Loading branch information
mmsqe and fedekunze authored Mar 14, 2023
1 parent 44a41ad commit 48c2a72
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (rpc) [#1392](https://github.com/evmos/ethermint/pull/1392) Allow fill the proposer address in json-rpc through tendermint api, and pass explicitly to grpc query handler.
* (rpc) [#1405](https://github.com/evmos/ethermint/pull/1405) Pass chain-id to grpc query through request, otherwise it's not initialized if abci event don't happens.
* (rpc) [#1431](https://github.com/evmos/ethermint/pull/1431) Align hex-strings proof fields in `eth_getProof` as Ethereum.
* (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.
* (rpc) [#1503](https://github.com/evmos/ethermint/pull/1503) Fix block hashes returned on JSON-RPC filter `eth_newBlockFilter`.
running transaction in `ReCheckMode`
* (rpc) [#1591](https://github.com/evmos/ethermint/pull/1591) Fix block number returned in opcode for debug trace related api.
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})
if err != nil {
st, ok := status.FromError(err)
// treat as account doesn't exist yet
if ok && st.Code() == codes.NotFound {
return 0, nil
}
return 0, err
}
var acc authtypes.AccountI
Expand Down
26 changes: 26 additions & 0 deletions tests/integration_tests/test_account.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from .utils import ADDRS, derive_new_account, w3_wait_for_new_blocks


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"]

# derive a new address
receiver = derive_new_account().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

0 comments on commit 48c2a72

Please sign in to comment.