Skip to content

Commit

Permalink
Don't fail ante handler on simulate tx with no fee
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Warehime committed Jun 16, 2024
1 parent f0997fb commit 092d361
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
15 changes: 10 additions & 5 deletions x/feemarket/ante/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
17 changes: 17 additions & 0 deletions x/feemarket/ante/fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 092d361

Please sign in to comment.