diff --git a/app/evmante_fees.go b/app/evmante_fees.go index da9d9d61c..0e180d7e5 100644 --- a/app/evmante_fees.go +++ b/app/evmante_fees.go @@ -85,7 +85,9 @@ func (empd EthMinGasPriceDecorator) AnteHandle( if fee.LT(requiredFee) { return ctx, errors.Wrapf( errortypes.ErrInsufficientFee, - "provided fee < minimum global fee (%s < %s). Please increase the priority tip (for EIP-1559 txs) or the gas prices (for access list or legacy txs)", //nolint:lll + "provided fee < minimum global fee (%s < %s). "+ + "Please increase the priority tip (for EIP-1559 txs) or the gas prices "+ + "(for access list or legacy txs)", fee.TruncateInt().String(), requiredFee.TruncateInt().String(), ) } diff --git a/app/evmante_fees_test.go b/app/evmante_fees_test.go new file mode 100644 index 000000000..f2ac7238b --- /dev/null +++ b/app/evmante_fees_test.go @@ -0,0 +1,103 @@ +package app_test + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + + "github.com/NibiruChain/nibiru/app" + "github.com/NibiruChain/nibiru/x/evm/evmtest" +) + +func (s *TestSuite) TestEthMinGasPriceDecorator() { + testCases := []struct { + name string + txSetup func(deps *evmtest.TestDeps) sdk.Tx + ctxSetup func(deps *evmtest.TestDeps) + wantErr string + }{ + { + name: "happy: min gas price is 0", + txSetup: func(deps *evmtest.TestDeps) sdk.Tx { + tx := happyCreateContractTx(deps) + return tx + }, + wantErr: "", + }, + { + name: "happy: min gas price is not zero, sufficient fee", + ctxSetup: func(deps *evmtest.TestDeps) { + gasPrice := sdk.NewInt64Coin("unibi", 1) + deps.Ctx = deps.Ctx. + WithMinGasPrices( + sdk.NewDecCoins(sdk.NewDecCoinFromCoin(gasPrice)), + ). + WithIsCheckTx(true) + }, + txSetup: func(deps *evmtest.TestDeps) sdk.Tx { + tx := happyCreateContractTx(deps) + return tx + }, + wantErr: "", + }, + { + name: "sad: insufficient fee", + ctxSetup: func(deps *evmtest.TestDeps) { + gasPrice := sdk.NewInt64Coin("unibi", 2) + deps.Ctx = deps.Ctx. + WithMinGasPrices( + sdk.NewDecCoins(sdk.NewDecCoinFromCoin(gasPrice)), + ). + WithIsCheckTx(true) + }, + txSetup: func(deps *evmtest.TestDeps) sdk.Tx { + tx := happyCreateContractTx(deps) + return tx + }, + wantErr: "insufficient fee", + }, + { + name: "sad: tx with non evm message", + ctxSetup: func(deps *evmtest.TestDeps) { + gasPrice := sdk.NewInt64Coin("unibi", 1) + deps.Ctx = deps.Ctx. + WithMinGasPrices( + sdk.NewDecCoins(sdk.NewDecCoinFromCoin(gasPrice)), + ). + WithIsCheckTx(true) + }, + txSetup: func(deps *evmtest.TestDeps) sdk.Tx { + gasLimit := uint64(10) + fees := sdk.NewCoins(sdk.NewInt64Coin("unibi", int64(gasLimit))) + msg := &banktypes.MsgSend{ + FromAddress: deps.Sender.NibiruAddr.String(), + ToAddress: evmtest.NewEthAccInfo().NibiruAddr.String(), + Amount: sdk.NewCoins(sdk.NewInt64Coin("unibi", 1)), + } + return buildTx(deps, true, msg, gasLimit, fees) + }, + wantErr: "invalid message", + }, + } + + for _, tc := range testCases { + s.Run(tc.name, func() { + deps := evmtest.NewTestDeps() + anteDec := app.NewEthMinGasPriceDecorator(deps.Chain.AppKeepers) + + tx := tc.txSetup(&deps) + + if tc.ctxSetup != nil { + tc.ctxSetup(&deps) + } + + _, err := anteDec.AnteHandle( + deps.Ctx, tx, false, NextNoOpAnteHandler, + ) + if tc.wantErr != "" { + s.Require().ErrorContains(err, tc.wantErr) + return + } + s.Require().NoError(err) + }) + } +}