From b42023e4e1d2c7370573c5c78262bbeae903e6c3 Mon Sep 17 00:00:00 2001 From: Eric Warehime Date: Sat, 15 Jun 2024 21:03:12 -0700 Subject: [PATCH] Don't fail ante handler on simulate tx with no fee (#120) (cherry picked from commit d2f4f3b78a5a522d459258241238e3d05726a549) --- x/feemarket/ante/fee.go | 15 ++++++++++----- x/feemarket/ante/fee_test.go | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/x/feemarket/ante/fee.go b/x/feemarket/ante/fee.go index 84b944a..912624b 100644 --- a/x/feemarket/ante/fee.go +++ b/x/feemarket/ante/fee.go @@ -95,14 +95,19 @@ func (dfd feeMarketCheckDecorator) anteHandle(ctx sdk.Context, tx sdk.Tx, simula feeCoins := feeTx.GetFee() gas := feeTx.GetGas() // use provided gas limit - if len(feeCoins) != 1 { - if len(feeCoins) == 0 { - return ctx, errorsmod.Wrapf(feemarkettypes.ErrNoFeeCoins, "got length %d", len(feeCoins)) - } + if len(feeCoins) == 0 && !simulate { + return ctx, errorsmod.Wrapf(feemarkettypes.ErrNoFeeCoins, "got length %d", len(feeCoins)) + } + if len(feeCoins) > 1 { return ctx, errorsmod.Wrapf(feemarkettypes.ErrTooManyFeeCoins, "got length %d", len(feeCoins)) } - feeCoin := feeCoins[0] + var feeCoin sdk.Coin + if simulate && len(feeCoins) == 0 { + feeCoin = sdk.NewCoin(params.FeeDenom, sdkmath.NewInt(0)) + } else { + feeCoin = feeCoins[0] + } feeGas := int64(feeTx.GetGas()) minGasPrice, err := dfd.feemarketKeeper.GetMinGasPrice(ctx, feeCoin.GetDenom()) diff --git a/x/feemarket/ante/fee_test.go b/x/feemarket/ante/fee_test.go index b170d53..c520035 100644 --- a/x/feemarket/ante/fee_test.go +++ b/x/feemarket/ante/fee_test.go @@ -76,6 +76,23 @@ func TestAnteHandle(t *testing.T) { ExpPass: false, ExpErr: sdkerrors.ErrOutOfGas, }, + { + Name: "0 gas given should pass in simulate", + Malleate: func(suite *antesuite.TestSuite) antesuite.TestCaseArgs { + accs := suite.CreateTestAccounts(1) + + return antesuite.TestCaseArgs{ + Msgs: []sdk.Msg{testdata.NewTestMsg(accs[0].Account.GetAddress())}, + GasLimit: 0, + FeeAmount: nil, + } + }, + RunAnte: true, + RunPost: false, + Simulate: true, + ExpPass: true, + ExpErr: nil, + }, { Name: "signer has enough funds, should pass", Malleate: func(suite *antesuite.TestSuite) antesuite.TestCaseArgs {