Skip to content

Commit

Permalink
fix: prevent errors on gas simulations (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
MSalopek committed Apr 17, 2024
1 parent b8d3623 commit 812daf6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
6 changes: 4 additions & 2 deletions x/feemarket/ante/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ func (dfd FeeMarketCheckDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula
if err != nil {
return ctx, errorsmod.Wrapf(err, "error checking fee")
}
priorityCtx := ctx.WithPriority(getTxPriority(fee, int64(gas))).WithMinGasPrices(minGasPrices)
return next(priorityCtx, tx, simulate)
}

newCtx := ctx.WithPriority(getTxPriority(fee, int64(gas))).WithMinGasPrices(minGasPrices)
return next(newCtx, tx, simulate)
ctx = ctx.WithMinGasPrices(minGasPrices)
return next(ctx, tx, simulate)
}

// CheckTxFees implements the logic for the fee market to check if a Tx has provided sufficient
Expand Down
18 changes: 18 additions & 0 deletions x/feemarket/ante/fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,24 @@ func TestAnteHandle(t *testing.T) {
ExpPass: false,
ExpErr: sdkerrors.ErrInvalidGasLimit,
},
// test --gas=auto flag settings
// when --gas=auto is set, cosmos-sdk sets gas=0 and simulate=true
{
Name: "--gas=auto behaviour test",
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: validFee,
}
},
RunAnte: true,
RunPost: false,
Simulate: true,
ExpPass: true,
},
{
Name: "signer has enough funds, should pass",
Malleate: func(suite *antesuite.TestSuite) antesuite.TestCaseArgs {
Expand Down

0 comments on commit 812daf6

Please sign in to comment.