From 35ad1424a12e4385be49b32da41e08a7e0637285 Mon Sep 17 00:00:00 2001 From: beer-1 Date: Wed, 21 Aug 2024 16:56:26 +0900 Subject: [PATCH] fix test --- app/ante/fee_test.go | 21 ++++++++++++++------- x/evm/keeper/params_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 x/evm/keeper/params_test.go diff --git a/app/ante/fee_test.go b/app/ante/fee_test.go index 8bbbc2a..74cb4f7 100644 --- a/app/ante/fee_test.go +++ b/app/ante/fee_test.go @@ -36,28 +36,35 @@ func (suite *AnteTestSuite) Test_NotSpendingGasForTxWithFeeDenom() { tx, err := suite.CreateTestTx(privs, accNums, accSeqs, suite.ctx.ChainID()) suite.Require().NoError(err) - gasMeter := storetypes.NewGasMeter(250000) + gasMeter := storetypes.NewGasMeter(500000) feeAnte.AnteHandle(suite.ctx.WithGasMeter(gasMeter), tx, false, nil) suite.Require().Zero(gasMeter.GasConsumed(), "should not consume gas for fee deduction") // Case 2. fee denom and other denom suite.txBuilder.SetFeeAmount(feeAmount.Add(atomFeeAmount...)) - gasMeter = storetypes.NewGasMeter(250000) + gasMeter = storetypes.NewGasMeter(500000) feeAnte.AnteHandle(suite.ctx.WithGasMeter(gasMeter), tx, false, nil) - suite.Require().NotZero(uint64(1039), "should consume gas for fee deduction") + suite.Require().NotZero(gasMeter.GasConsumed(), "should consume gas for fee deduction") // Case 3. other denom suite.txBuilder.SetFeeAmount(feeAmount.Add(atomFeeAmount...)) - gasMeter = storetypes.NewGasMeter(250000) + gasMeter = storetypes.NewGasMeter(500000) feeAnte.AnteHandle(suite.ctx.WithGasMeter(gasMeter), tx, false, nil) - suite.Require().NotZero(uint64(1039), "should consume gas for fee deduction") + suite.Require().NotZero(gasMeter.GasConsumed(), "should consume gas for fee deduction") // Case 4. no fee suite.txBuilder.SetFeeAmount(sdk.NewCoins()) - gasMeter = storetypes.NewGasMeter(250000) + gasMeter = storetypes.NewGasMeter(500000) feeAnte.AnteHandle(suite.ctx.WithGasMeter(gasMeter), tx, false, nil) - suite.Require().NotZero(uint64(1039), "should consume gas for fee deduction") + suite.Require().NotZero(gasMeter.GasConsumed(), "should consume gas for fee deduction") + + // Case 5. simulate gas consumption + suite.txBuilder.SetFeeAmount(sdk.NewCoins()) + + gasMeter = storetypes.NewGasMeter(500000) + feeAnte.AnteHandle(suite.ctx.WithGasMeter(gasMeter), tx, true, nil) + suite.Require().Greater(gasMeter.GasConsumed(), uint64(250000), "should consume gas for fee deduction") } diff --git a/x/evm/keeper/params_test.go b/x/evm/keeper/params_test.go new file mode 100644 index 0000000..0ff3f8d --- /dev/null +++ b/x/evm/keeper/params_test.go @@ -0,0 +1,26 @@ +package keeper_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + evmtypes "github.com/initia-labs/minievm/x/evm/types" +) + +func Test_GetFeeDenom(t *testing.T) { + ctx, input := createDefaultTestInput(t) + + denom, err := input.EVMKeeper.GetFeeDenom(ctx) + require.NoError(t, err) + require.Equal(t, evmtypes.DefaultParams().FeeDenom, denom) + + err = input.EVMKeeper.Params.Set(ctx, evmtypes.Params{ + FeeDenom: "eth", + }) + require.NoError(t, err) + + denom, err = input.EVMKeeper.GetFeeDenom(ctx) + require.NoError(t, err) + require.Equal(t, "eth", denom) +}