From b34e83a29affa8ad7c1eafe4f4365564f7b99f94 Mon Sep 17 00:00:00 2001 From: Sai Kumar Date: Wed, 18 May 2022 11:27:11 +0530 Subject: [PATCH] chore: address the pr comments --- app/middleware/{eip792.go => eip712.go} | 0 app/middleware/eth.go | 2 +- app/middleware/eth_test.go | 8 -------- app/middleware/middleware.go | 9 +++------ x/evm/keeper/benchmark_test.go | 14 ++++++-------- x/evm/keeper/grpc_query_test.go | 2 +- 6 files changed, 11 insertions(+), 24 deletions(-) rename app/middleware/{eip792.go => eip712.go} (100%) diff --git a/app/middleware/eip792.go b/app/middleware/eip712.go similarity index 100% rename from app/middleware/eip792.go rename to app/middleware/eip712.go diff --git a/app/middleware/eth.go b/app/middleware/eth.go index bdd42e1c..c21b935f 100644 --- a/app/middleware/eth.go +++ b/app/middleware/eth.go @@ -1,7 +1,7 @@ package middleware import ( - context "context" + "context" "errors" "math/big" diff --git a/app/middleware/eth_test.go b/app/middleware/eth_test.go index 3728de02..a68bb546 100644 --- a/app/middleware/eth_test.go +++ b/app/middleware/eth_test.go @@ -16,10 +16,6 @@ import ( ethtypes "github.com/ethereum/go-ethereum/core/types" ) -func nextFn(ctx sdk.Context, _ sdk.Tx, _ bool) (sdk.Context, error) { - return ctx, nil -} - func (suite MiddlewareTestSuite) TestEthSigVerificationDecorator() { txHandler := middleware.ComposeMiddlewares(noopTxHandler, ante.NewEthSigVerificationMiddleware(suite.app.EvmKeeper)) addr, privKey := tests.NewAddrKey() @@ -288,26 +284,22 @@ func (suite MiddlewareTestSuite) TestEthGasConsumeDecorator() { if tc.expPanic { suite.Require().Panics(func() { _, _, _ = txHandler.CheckTx(sdk.WrapSDKContext(suite.ctx.WithIsCheckTx(true).WithGasMeter(sdk.NewGasMeter(1))), txtypes.Request{Tx: tc.tx}, txtypes.RequestCheckTx{}) - }) return } _, _, err := txHandler.CheckTx(sdk.WrapSDKContext(suite.ctx.WithIsCheckTx(true).WithGasMeter(sdk.NewInfiniteGasMeter())), txtypes.Request{Tx: tc.tx}, txtypes.RequestCheckTx{}) - // ctx, err := t.AnteHandle(suite.ctx.WithIsCheckTx(true).WithGasMeter(sdk.NewInfiniteGasMeter()), tc.tx, false, nextFn) if tc.expPass { suite.Require().NoError(err) } else { suite.Require().Error(err) } - // suite.Require().Equal(tc.gasLimit, ctx.GasMeter().Limit()) }) } } func (suite MiddlewareTestSuite) TestCanTransferDecorator() { - // dec := ante.NewCanTransferMiddleware(suite.app.EvmKeeper) txHandler := middleware.ComposeMiddlewares(noopTxHandler, ante.NewCanTransferMiddleware(suite.app.EvmKeeper)) addr, privKey := tests.NewAddrKey() diff --git a/app/middleware/middleware.go b/app/middleware/middleware.go index 6d241dd5..18307966 100644 --- a/app/middleware/middleware.go +++ b/app/middleware/middleware.go @@ -1,7 +1,7 @@ package middleware import ( - context "context" + "context" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -66,10 +66,7 @@ func (txh txRouter) route(req tx.Request) (tx.Handler, error) { return next, nil } } - // // handle as totally normal Cosmos SDK tx - // if _, ok = reqTx.(sdk.Tx); !ok { - // return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid transaction type: %T", reqTx) - // } + // handle as totally normal Cosmos SDK tx return txh.cosmos, nil } @@ -100,7 +97,7 @@ func (txh txRouter) SimulateTx(ctx context.Context, req tx.Request) (res tx.Resp return next.SimulateTx(ctx, req) } -var _ authmiddleware.SignatureVerificationGasConsumer = DefaultSigVerificationGasConsumer +var _ = DefaultSigVerificationGasConsumer // DefaultSigVerificationGasConsumer is the default implementation of SignatureVerificationGasConsumer. It consumes gas // for signature verification based upon the public key type. The cost is fetched from the given params and is matched diff --git a/x/evm/keeper/benchmark_test.go b/x/evm/keeper/benchmark_test.go index 1223737b..9985cfb5 100644 --- a/x/evm/keeper/benchmark_test.go +++ b/x/evm/keeper/benchmark_test.go @@ -7,14 +7,12 @@ import ( "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" - // authante "github.com/cosmos/cosmos-sdk/x/auth/ante" - // authante "github.com/cosmos/cosmos-sdk/x/auth/ante" "github.com/ethereum/go-ethereum/common" + authmiddleware "github.com/cosmos/cosmos-sdk/x/auth/middleware" ethtypes "github.com/ethereum/go-ethereum/core/types" ethermint "github.com/tharsis/ethermint/types" "github.com/tharsis/ethermint/x/evm/types" - authmiddleware "github.com/cosmos/cosmos-sdk/x/auth/middleware" ) func SetupContract(b *testing.B) (*KeeperTestSuite, common.Address) { @@ -65,12 +63,12 @@ func DoBenchmark(b *testing.B, txBuilder TxBuilder) { ctx, _ := suite.ctx.CacheContext() // deduct fee first - // txData, err := types.UnpackTxData(msg.Data) - // require.NoError(b, err) + txData, err := types.UnpackTxData(msg.Data) + require.NoError(b, err) - // fees := sdk.Coins{sdk.NewCoin(suite.EvmDenom(), sdk.NewIntFromBigInt(txData.Fee()))} - // err = authante.DeductFees(suite.app.BankKeeper, suite.ctx, suite.app.AccountKeeper.GetAccount(ctx, msg.GetFrom()), fees) - // require.NoError(b, err) + fees := sdk.Coins{sdk.NewCoin(suite.EvmDenom(), sdk.NewIntFromBigInt(txData.Fee()))} + err = authmiddleware.DeductFees(suite.app.BankKeeper, suite.ctx, suite.app.AccountKeeper.GetAccount(ctx, msg.GetFrom()), fees) + require.NoError(b, err) rsp, err := suite.app.EvmKeeper.EthereumTx(sdk.WrapSDKContext(ctx), msg) require.NoError(b, err) diff --git a/x/evm/keeper/grpc_query_test.go b/x/evm/keeper/grpc_query_test.go index 14550493..690e67b7 100644 --- a/x/evm/keeper/grpc_query_test.go +++ b/x/evm/keeper/grpc_query_test.go @@ -467,7 +467,7 @@ func (suite *KeeperTestSuite) TestQueryValidatorAccount() { for _, tc := range testCases { suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { - // suite.SetupTest() // reset + suite.SetupTest() // reset tc.malleate() ctx := sdk.WrapSDKContext(suite.ctx)