diff --git a/x/evmutil/keeper/conversion_test.go b/x/evmutil/keeper/conversion_test.go index f5edc77f..f8d6c4a1 100644 --- a/x/evmutil/keeper/conversion_test.go +++ b/x/evmutil/keeper/conversion_test.go @@ -164,13 +164,17 @@ func (suite *ConversionTestSuite) TestConvertCoinToERC20() { ) suite.Require().NoError(err) + // convert coin to erc20 + ctx := suite.Ctx.WithGasMeter(sdk.NewInfiniteGasMeter()) err = suite.Keeper.ConvertCoinToERC20( - suite.Ctx, + ctx, originAcc, recipientAcc, sdk.NewCoin(pair.Denom, sdk.NewIntFromBigInt(amount)), ) suite.Require().NoError(err) + suite.Require().LessOrEqual(ctx.GasMeter().GasConsumed(), uint64(500000)) + suite.Require().GreaterOrEqual(ctx.GasMeter().GasConsumed(), uint64(50000)) // Source should decrease bal := suite.App.GetBankKeeper().GetBalance(suite.Ctx, originAcc, pair.Denom) @@ -279,15 +283,18 @@ func (suite *ConversionTestSuite) TestConvertERC20ToCoin() { ) suite.Require().NoError(err) + ctx := suite.Ctx.WithGasMeter(sdk.NewInfiniteGasMeter()) convertAmt := sdk.NewInt(50) err = suite.Keeper.ConvertERC20ToCoin( - suite.Ctx, + ctx, userEvmAddr, userAddr, pair.GetAddress(), convertAmt, ) suite.Require().NoError(err) + suite.Require().LessOrEqual(ctx.GasMeter().GasConsumed(), uint64(500000)) + suite.Require().GreaterOrEqual(ctx.GasMeter().GasConsumed(), uint64(50000)) // bank balance should decrease bal := suite.App.GetBankKeeper().GetBalance(suite.Ctx, userAddr, pair.Denom) diff --git a/x/evmutil/keeper/evm.go b/x/evmutil/keeper/evm.go index f91fd521..018cdfc2 100644 --- a/x/evmutil/keeper/evm.go +++ b/x/evmutil/keeper/evm.go @@ -89,6 +89,8 @@ func (k Keeper) CallEVMWithData( return nil, err } + ethGasContext := ctx.WithGasMeter(sdk.NewInfiniteGasMeter()) + // EstimateGas applies the transaction against current block state to get // optimal gas value. Since this is done right before the ApplyMessage // below, it should essentially do the same thing but without affecting @@ -96,7 +98,7 @@ func (k Keeper) CallEVMWithData( // accurate exact amount in this case, as both the chain state and tx used // to estimate and apply are the exact same (ie. no txs between estimate and // apply, tx order is the same, etc.) - gasRes, err := k.evmKeeper.EstimateGas(sdk.WrapSDKContext(ctx), &evmtypes.EthCallRequest{ + gasRes, err := k.evmKeeper.EstimateGas(sdk.WrapSDKContext(ethGasContext), &evmtypes.EthCallRequest{ Args: args, GasCap: config.DefaultGasCap, }) @@ -118,7 +120,7 @@ func (k Keeper) CallEVMWithData( true, // checkNonce ) - res, err := k.evmKeeper.ApplyMessage(ctx, msg, evmtypes.NewNoOpTracer(), true) + res, err := k.evmKeeper.ApplyMessage(ethGasContext, msg, evmtypes.NewNoOpTracer(), true) if err != nil { return nil, err } @@ -127,6 +129,8 @@ func (k Keeper) CallEVMWithData( return nil, sdkerrors.Wrap(evmtypes.ErrVMExecution, res.VmError) } + ctx.GasMeter().ConsumeGas(res.GasUsed, "evm gas consumed") + return res, nil }