Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
aljo242 committed Nov 21, 2023
1 parent 96433e4 commit ef715a0
Showing 2 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion x/feemarket/ante/fee.go
Original file line number Diff line number Diff line change
@@ -184,7 +184,7 @@ func checkTxFees(_ sdk.Context, fees sdk.DecCoins, tx sdk.Tx) (feeCoins sdk.Coin
}

tip = feeCoins.Sub(requiredFees...) // tip is whatever is left
feeCoins = requiredFees // set free coins to be ONLY the required amount
feeCoins = requiredFees // set fee coins to be ONLY the required amount
}

priority = getTxPriority(feeCoins, int64(gas))
31 changes: 24 additions & 7 deletions x/feemarket/ante/fee_test.go
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ func TestDeductCoins(t *testing.T) {
}

func TestAnteHandle(t *testing.T) {
// Same data for every test cases
// Same data for every test case
gasLimit := NewTestGasLimit()
validFeeAmount := types.DefaultMinBaseFee.MulRaw(int64(gasLimit))
validFee := sdk.NewCoins(sdk.NewCoin("stake", validFeeAmount))
@@ -64,24 +64,43 @@ func TestAnteHandle(t *testing.T) {
"signer has no funds",
func(suite *AnteTestSuite) TestCaseArgs {
accs := suite.CreateTestAccounts(1)
suite.bankKeeper.On("SendCoinsFromAccountToModule", mock.Anything, accs[0].acc.GetAddress(), types.FeeCollectorName, mock.Anything).Return(sdkerrors.ErrInsufficientFunds)
suite.bankKeeper.On("SendCoinsFromAccountToModule", mock.Anything, accs[0].acc.GetAddress(), types.FeeCollectorName, mock.Anything).Return(sdkerrors.ErrInsufficientFunds).Once()

return TestCaseArgs{
msgs: []sdk.Msg{testdata.NewTestMsg(accs[0].acc.GetAddress())},
msgs: []sdk.Msg{testdata.NewTestMsg(accs[0].acc.GetAddress())},
gasLimit: gasLimit,
feeAmount: validFee,
}
},
false,
false,
sdkerrors.ErrInsufficientFunds,
},
{
"0 gas given should fail",
func(suite *AnteTestSuite) TestCaseArgs {
accs := suite.CreateTestAccounts(1)

return TestCaseArgs{
msgs: []sdk.Msg{testdata.NewTestMsg(accs[0].acc.GetAddress())},
gasLimit: 0,
feeAmount: validFee,
}
},
false,
false,
sdkerrors.ErrInvalidGasLimit,
},
{
"signer has enough funds, should pass",
func(suite *AnteTestSuite) TestCaseArgs {
accs := suite.CreateTestAccounts(1)
suite.bankKeeper.On("SendCoinsFromAccountToModule", mock.Anything, accs[0].acc.GetAddress(), types.FeeCollectorName, mock.Anything).Return(nil)
suite.bankKeeper.On("SendCoinsFromAccountToModule", mock.Anything, accs[0].acc.GetAddress(), types.FeeCollectorName, mock.Anything).Return(nil).Once()

return TestCaseArgs{
msgs: []sdk.Msg{testdata.NewTestMsg(accs[0].acc.GetAddress())},
msgs: []sdk.Msg{testdata.NewTestMsg(accs[0].acc.GetAddress())},
gasLimit: gasLimit,
feeAmount: validFee,
}
},
false,
@@ -95,8 +114,6 @@ func TestAnteHandle(t *testing.T) {
s := SetupTestSuite(t, false)
s.txBuilder = s.clientCtx.TxConfig.NewTxBuilder()
args := tc.malleate(s)
args.feeAmount = validFee
args.gasLimit = gasLimit

s.RunTestCase(t, tc, args)
})

0 comments on commit ef715a0

Please sign in to comment.