Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Don't fail ante handler on simulate tx with no fee #120

Merged
merged 1 commit into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading