chore: address the pr comments

This commit is contained in:
Sai Kumar 2022-05-18 11:27:11 +05:30
parent d0fba5b727
commit b34e83a29a
6 changed files with 11 additions and 24 deletions

View File

@ -1,7 +1,7 @@
package middleware package middleware
import ( import (
context "context" "context"
"errors" "errors"
"math/big" "math/big"

View File

@ -16,10 +16,6 @@ import (
ethtypes "github.com/ethereum/go-ethereum/core/types" 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() { func (suite MiddlewareTestSuite) TestEthSigVerificationDecorator() {
txHandler := middleware.ComposeMiddlewares(noopTxHandler, ante.NewEthSigVerificationMiddleware(suite.app.EvmKeeper)) txHandler := middleware.ComposeMiddlewares(noopTxHandler, ante.NewEthSigVerificationMiddleware(suite.app.EvmKeeper))
addr, privKey := tests.NewAddrKey() addr, privKey := tests.NewAddrKey()
@ -288,26 +284,22 @@ func (suite MiddlewareTestSuite) TestEthGasConsumeDecorator() {
if tc.expPanic { if tc.expPanic {
suite.Require().Panics(func() { suite.Require().Panics(func() {
_, _, _ = txHandler.CheckTx(sdk.WrapSDKContext(suite.ctx.WithIsCheckTx(true).WithGasMeter(sdk.NewGasMeter(1))), txtypes.Request{Tx: tc.tx}, txtypes.RequestCheckTx{}) _, _, _ = txHandler.CheckTx(sdk.WrapSDKContext(suite.ctx.WithIsCheckTx(true).WithGasMeter(sdk.NewGasMeter(1))), txtypes.Request{Tx: tc.tx}, txtypes.RequestCheckTx{})
}) })
return return
} }
_, _, err := txHandler.CheckTx(sdk.WrapSDKContext(suite.ctx.WithIsCheckTx(true).WithGasMeter(sdk.NewInfiniteGasMeter())), txtypes.Request{Tx: tc.tx}, txtypes.RequestCheckTx{}) _, _, 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 { if tc.expPass {
suite.Require().NoError(err) suite.Require().NoError(err)
} else { } else {
suite.Require().Error(err) suite.Require().Error(err)
} }
// suite.Require().Equal(tc.gasLimit, ctx.GasMeter().Limit())
}) })
} }
} }
func (suite MiddlewareTestSuite) TestCanTransferDecorator() { func (suite MiddlewareTestSuite) TestCanTransferDecorator() {
// dec := ante.NewCanTransferMiddleware(suite.app.EvmKeeper)
txHandler := middleware.ComposeMiddlewares(noopTxHandler, ante.NewCanTransferMiddleware(suite.app.EvmKeeper)) txHandler := middleware.ComposeMiddlewares(noopTxHandler, ante.NewCanTransferMiddleware(suite.app.EvmKeeper))
addr, privKey := tests.NewAddrKey() addr, privKey := tests.NewAddrKey()

View File

@ -1,7 +1,7 @@
package middleware package middleware
import ( import (
context "context" "context"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" 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 return next, nil
} }
} }
// // handle as totally normal Cosmos SDK tx // handle as totally normal Cosmos SDK tx
// if _, ok = reqTx.(sdk.Tx); !ok {
// return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid transaction type: %T", reqTx)
// }
return txh.cosmos, nil 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) return next.SimulateTx(ctx, req)
} }
var _ authmiddleware.SignatureVerificationGasConsumer = DefaultSigVerificationGasConsumer var _ = DefaultSigVerificationGasConsumer
// DefaultSigVerificationGasConsumer is the default implementation of SignatureVerificationGasConsumer. It consumes gas // 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 // for signature verification based upon the public key type. The cost is fetched from the given params and is matched

View File

@ -7,14 +7,12 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
sdk "github.com/cosmos/cosmos-sdk/types" 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" "github.com/ethereum/go-ethereum/common"
authmiddleware "github.com/cosmos/cosmos-sdk/x/auth/middleware"
ethtypes "github.com/ethereum/go-ethereum/core/types" ethtypes "github.com/ethereum/go-ethereum/core/types"
ethermint "github.com/tharsis/ethermint/types" ethermint "github.com/tharsis/ethermint/types"
"github.com/tharsis/ethermint/x/evm/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) { func SetupContract(b *testing.B) (*KeeperTestSuite, common.Address) {
@ -65,12 +63,12 @@ func DoBenchmark(b *testing.B, txBuilder TxBuilder) {
ctx, _ := suite.ctx.CacheContext() ctx, _ := suite.ctx.CacheContext()
// deduct fee first // deduct fee first
// txData, err := types.UnpackTxData(msg.Data) txData, err := types.UnpackTxData(msg.Data)
// require.NoError(b, err) require.NoError(b, err)
// fees := sdk.Coins{sdk.NewCoin(suite.EvmDenom(), sdk.NewIntFromBigInt(txData.Fee()))} 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) err = authmiddleware.DeductFees(suite.app.BankKeeper, suite.ctx, suite.app.AccountKeeper.GetAccount(ctx, msg.GetFrom()), fees)
// require.NoError(b, err) require.NoError(b, err)
rsp, err := suite.app.EvmKeeper.EthereumTx(sdk.WrapSDKContext(ctx), msg) rsp, err := suite.app.EvmKeeper.EthereumTx(sdk.WrapSDKContext(ctx), msg)
require.NoError(b, err) require.NoError(b, err)

View File

@ -467,7 +467,7 @@ func (suite *KeeperTestSuite) TestQueryValidatorAccount() {
for _, tc := range testCases { for _, tc := range testCases {
suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.Run(fmt.Sprintf("Case %s", tc.msg), func() {
// suite.SetupTest() // reset suite.SetupTest() // reset
tc.malleate() tc.malleate()
ctx := sdk.WrapSDKContext(suite.ctx) ctx := sdk.WrapSDKContext(suite.ctx)