Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
aljo242 committed Dec 28, 2023
1 parent a30bd39 commit 13bc7bc
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 3 deletions.
2 changes: 1 addition & 1 deletion x/feemarket/post/expected_keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type FeeMarketKeeper interface {

// ConsensusKeeper defines the expected consensus keeper (noalias)
//
//go:generate mockery --name ConsensusKeeper --filename mock_conensus_keeper.go
//go:generate mockery --name ConsensusKeeper --filename mock_consensus_keeper.go
type ConsensusKeeper interface {
Get(ctx sdk.Context) (*tmproto.ConsensusParams, error)
}
7 changes: 5 additions & 2 deletions x/feemarket/post/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,20 @@ func (dfd FeeMarketDeductDecorator) PostHandle(ctx sdk.Context, tx sdk.Tx, simul

consensusParams, err := dfd.consensusParamsKeeper.Get(ctx)
if err != nil {
return ctx, errorsmod.Wrapf(err, "unable to gen consensus params")
return ctx, sdkerrors.ErrKeyNotFound.Wrap(err.Error())
}

maxGas := params.MaxBlockUtilization
if consensusParams.Block.MaxGas < int64(params.MaxBlockUtilization) && consensusParams.Block.MaxGas >= 0 {
maxGas = uint64(consensusParams.Block.MaxGas)
ctx.Logger().Info("using consensus params max gas",
"max gas", maxGas,
)
}

err = state.Update(gas, maxGas)
if err != nil {
return ctx, errorsmod.Wrapf(err, "unable to update fee market state")
return ctx, errorsmod.Wrapf(sdkerrors.ErrTxTooLarge, err.Error())
}

err = dfd.feemarketKeeper.SetState(ctx, state)
Expand Down
67 changes: 67 additions & 0 deletions x/feemarket/post/fee_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package post_test

import (
"errors"
"fmt"
"testing"

testkeeper "github.com/skip-mev/feemarket/testutils/keeper"

"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/stretchr/testify/mock"
Expand Down Expand Up @@ -143,11 +146,73 @@ func TestPostHandle(t *testing.T) {
ExpPass: false,
ExpErr: sdkerrors.ErrInvalidGasLimit,
},
{
Name: "error getting consensus params - should fail",
Malleate: func(s *antesuite.TestSuite) antesuite.TestCaseArgs {
accs := s.CreateTestAccounts(1)
s.MockBankKeeper.On("SendCoinsFromAccountToModule", mock.Anything, accs[0].Account.GetAddress(), types.FeeCollectorName, mock.Anything).Return(nil)
s.MockConsensusParamsKeeper.On("Get", mock.Anything).Return(nil, errors.New("invalid"))

return antesuite.TestCaseArgs{
Msgs: []sdk.Msg{testdata.NewTestMsg(accs[0].Account.GetAddress())},
GasLimit: gasLimit,
FeeAmount: validFee,
}
},
RunAnte: true,
RunPost: true,
Simulate: false,
ExpPass: false,
ExpErr: sdkerrors.ErrKeyNotFound,
},
{
Name: "using consensus params for invalid gas limit (exceeds max gas)",
Malleate: func(s *antesuite.TestSuite) antesuite.TestCaseArgs {
accs := s.CreateTestAccounts(1)
s.MockBankKeeper.On("SendCoinsFromAccountToModule", mock.Anything, accs[0].Account.GetAddress(), types.FeeCollectorName, mock.Anything).Return(nil)
params := testkeeper.ConsensusParams
params.Block.MaxGas = 10 // use tiny gas so that max gas is exceeded
s.MockConsensusParamsKeeper.On("Get", mock.Anything).Return(params, nil)

return antesuite.TestCaseArgs{
Msgs: []sdk.Msg{testdata.NewTestMsg(accs[0].Account.GetAddress())},
GasLimit: gasLimit,
FeeAmount: validFee,
}
},
RunAnte: true,
RunPost: true,
Simulate: false,
ExpPass: false,
ExpErr: sdkerrors.ErrTxTooLarge,
},
{
Name: "using consensus params for max gas override - valid)",
Malleate: func(s *antesuite.TestSuite) antesuite.TestCaseArgs {
accs := s.CreateTestAccounts(1)
s.MockBankKeeper.On("SendCoinsFromAccountToModule", mock.Anything, accs[0].Account.GetAddress(), types.FeeCollectorName, mock.Anything).Return(nil)
params := testkeeper.ConsensusParams
params.Block.MaxGas = int64(gasLimit - 1)
s.MockConsensusParamsKeeper.On("Get", mock.Anything).Return(params, nil)

return antesuite.TestCaseArgs{
Msgs: []sdk.Msg{testdata.NewTestMsg(accs[0].Account.GetAddress())},
GasLimit: gasLimit,
FeeAmount: validFee,
}
},
RunAnte: true,
RunPost: true,
Simulate: false,
ExpPass: true,
ExpErr: nil,
},
{
Name: "signer has enough funds, should pass, no tip",
Malleate: func(s *antesuite.TestSuite) antesuite.TestCaseArgs {
accs := s.CreateTestAccounts(1)
s.MockBankKeeper.On("SendCoinsFromAccountToModule", mock.Anything, accs[0].Account.GetAddress(), types.FeeCollectorName, mock.Anything).Return(nil)
s.MockConsensusParamsKeeper.On("Get", mock.Anything).Return(testkeeper.ConsensusParams, nil)

return antesuite.TestCaseArgs{
Msgs: []sdk.Msg{testdata.NewTestMsg(accs[0].Account.GetAddress())},
Expand All @@ -167,6 +232,7 @@ func TestPostHandle(t *testing.T) {
accs := s.CreateTestAccounts(1)
s.MockBankKeeper.On("SendCoinsFromAccountToModule", mock.Anything, accs[0].Account.GetAddress(), types.FeeCollectorName, mock.Anything).Return(nil)
s.MockBankKeeper.On("SendCoins", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil).Once()
s.MockConsensusParamsKeeper.On("Get", mock.Anything).Return(testkeeper.ConsensusParams, nil)

return antesuite.TestCaseArgs{
Msgs: []sdk.Msg{testdata.NewTestMsg(accs[0].Account.GetAddress())},
Expand All @@ -186,6 +252,7 @@ func TestPostHandle(t *testing.T) {
accs := s.CreateTestAccounts(1)
s.MockBankKeeper.On("SendCoinsFromAccountToModule", mock.Anything, accs[0].Account.GetAddress(), types.FeeCollectorName, mock.Anything).Return(nil)
s.MockBankKeeper.On("SendCoins", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil).Once()
s.MockConsensusParamsKeeper.On("Get", mock.Anything).Return(testkeeper.ConsensusParams, nil)

return antesuite.TestCaseArgs{
Msgs: []sdk.Msg{testdata.NewTestMsg(accs[0].Account.GetAddress())},
Expand Down

0 comments on commit 13bc7bc

Please sign in to comment.