Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ori committed Jun 15, 2022
1 parent 9ec25dd commit ff5e228
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions x/evm/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ func (k Keeper) EthCall(c context.Context, req *types.EthCallRequest) (*types.Ms
if types.IsLondon(ethCfg, ctx.BlockHeight()) {
baseFee = k.feeMarketKeeper.GetBaseFee(ctx)
}
nonce := k.GetNonce(args.GetFrom())
args.Nonce = (*hexutil.Uint64)(&nonce)

msg, err := args.ToMessage(req.GasCap, baseFee)
if err != nil {
Expand Down Expand Up @@ -297,6 +299,9 @@ func (k Keeper) EstimateGas(c context.Context, req *types.EthCallRequest) (*type
baseFee = k.feeMarketKeeper.GetBaseFee(ctx)
}

nonce := k.GetNonce(args.GetFrom())
args.Nonce = (*hexutil.Uint64)(&nonce)

// Create a helper to check if a gas allowance results in an executable transaction
executable := func(gas uint64) (vmerror bool, rsp *types.MsgEthereumTxResponse, err error) {
args.Gas = (*hexutil.Uint64)(&gas)
Expand Down
35 changes: 35 additions & 0 deletions x/evm/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package keeper_test
import (
"encoding/json"
"fmt"
"github.com/tharsis/ethermint/crypto/ethsecp256k1"
"github.com/tharsis/ethermint/server/config"
"math/big"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -855,3 +857,36 @@ func (suite *KeeperTestSuite) TestTraceBlock() {

suite.dynamicTxFee = false // reset flag
}

func (suite *KeeperTestSuite) TestNonceInQuery() {
suite.SetupTest()
priv, err := ethsecp256k1.GenerateKey()
suite.Require().NoError(err)
address := common.BytesToAddress(priv.PubKey().Address().Bytes())
suite.Require().Equal(uint64(0), suite.app.EvmKeeper.GetNonce(address))
supply := sdk.NewIntWithDecimal(1000, 18).BigInt()

// accupy nonce 0
_ = suite.DeployTestContract(suite.T(), address, supply)

// do an EthCall/EstimateGas with nonce 0
ctorArgs, err := types.ERC20Contract.ABI.Pack("", address, supply)
data := append(types.ERC20Contract.Bin, ctorArgs...)
args, err := json.Marshal(&types.TransactionArgs{
From: &address,
Data: (*hexutil.Bytes)(&data),
})
suite.Require().NoError(err)

_, err = suite.queryClient.EstimateGas(sdk.WrapSDKContext(suite.ctx), &types.EthCallRequest{
Args: args,
GasCap: uint64(config.DefaultGasCap),
})
suite.Require().NoError(err)

_, err = suite.queryClient.EthCall(sdk.WrapSDKContext(suite.ctx), &types.EthCallRequest{
Args: args,
GasCap: uint64(config.DefaultGasCap),
})
suite.Require().NoError(err)
}

0 comments on commit ff5e228

Please sign in to comment.