Skip to content

Commit

Permalink
test(evm): evmante fees test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
onikonychev committed Jun 10, 2024
1 parent 93ca583 commit 52ef738
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/evmante_fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
)
}
Expand Down
103 changes: 103 additions & 0 deletions app/evmante_fees_test.go
Original file line number Diff line number Diff line change
@@ -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)
})
}
}

0 comments on commit 52ef738

Please sign in to comment.