From e31e3a01c2ffd3a2af6c62fbaa01b0841bb3a0d1 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Thu, 30 Nov 2023 14:44:51 -0500 Subject: [PATCH] fix --- tests/integration/integration_test.go | 21 +++++++++++++++--- tests/integration/setup.go | 30 ++++++++++++++++++------- tests/integration/suite.go | 32 ++++++++++++++++++--------- x/feemarket/ante/fee.go | 10 +++++++-- x/feemarket/post/fee.go | 10 +++++++++ 5 files changed, 79 insertions(+), 24 deletions(-) diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go index 6acf54a..d0c4bc9 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -4,6 +4,8 @@ import ( "fmt" "testing" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module/testutil" interchaintest "github.com/strangelove-ventures/interchaintest/v7" "github.com/strangelove-ventures/interchaintest/v7/chain/cosmos" @@ -32,8 +34,21 @@ var ( genesisKV = []cosmos.GenesisKV{ { - Key: "app_state.feemarket.params", - Value: feemarkettypes.DefaultParams(), + Key: "app_state.feemarket.params", + Value: feemarkettypes.NewParams( + feemarkettypes.DefaultWindow, + feemarkettypes.DefaultAlpha, + feemarkettypes.DefaultBeta, + feemarkettypes.DefaultTheta, + feemarkettypes.DefaultDelta, + feemarkettypes.DefaultTargetBlockSize, + feemarkettypes.DefaultMaxBlockSize, + sdk.NewInt(1000), + feemarkettypes.DefaultMinLearningRate, + feemarkettypes.DefaultMaxLearningRate, + feemarkettypes.DefaultFeeDenom, + true, + ), }, } @@ -62,7 +77,7 @@ var ( Bech32Prefix: "cosmos", CoinType: "118", GasAdjustment: gasAdjustment, - GasPrices: fmt.Sprintf("200%s", denom), + GasPrices: fmt.Sprintf("50%s", denom), TrustingPeriod: "48h", NoHostMount: noHostMount, ModifyGenesis: cosmos.ModifyGenesis(genesisKV), diff --git a/tests/integration/setup.go b/tests/integration/setup.go index 771f69b..6f7bda2 100644 --- a/tests/integration/setup.go +++ b/tests/integration/setup.go @@ -7,15 +7,17 @@ import ( "encoding/hex" "encoding/json" "fmt" - "github.com/strangelove-ventures/interchaintest/v7" "io" "math/rand" "os" "path" + "strconv" "strings" "testing" "time" + "github.com/strangelove-ventures/interchaintest/v7" + rpctypes "github.com/cometbft/cometbft/rpc/core/types" comettypes "github.com/cometbft/cometbft/types" "github.com/cosmos/cosmos-sdk/client" @@ -352,7 +354,7 @@ func (s *TestSuite) keyringDirFromNode() string { } // SendCoins creates a executes a SendCoins message and broadcasts the transaction. -func (s *TestSuite) SendCoins(ctx context.Context, chain *cosmos.CosmosChain, keyName, sender, receiver string, amt, fees sdk.Coins) (string, error) { +func (s *TestSuite) SendCoins(ctx context.Context, chain *cosmos.CosmosChain, keyName, sender, receiver string, amt, fees sdk.Coins, gas int64) (string, error) { resp, err := s.ExecTx( ctx, chain, @@ -364,6 +366,8 @@ func (s *TestSuite) SendCoins(ctx context.Context, chain *cosmos.CosmosChain, ke amt.String(), "--fees", fees.String(), + "--gas", + strconv.FormatInt(gas, 10), ) return resp, err @@ -392,12 +396,10 @@ func (s *TestSuite) GetAndFundTestUserWithMnemonic( interchaintest.FaucetAccountKeyName, user.FormattedAddress(), sdk.NewCoins(sdk.NewCoin(chainCfg.Denom, sdk.NewInt(amount))), - sdk.NewCoins(sdk.NewCoin(chainCfg.Denom, sdk.NewInt(200000000000))), + sdk.NewCoins(sdk.NewCoin(chainCfg.Denom, sdk.NewInt(1000000000000))), + 1000000, ) - - if err != nil { - return nil, fmt.Errorf("failed to get funds from faucet: %w", err) - } + s.Require().NoError(err, "failed to get funds from faucet") return user, nil } @@ -434,7 +436,19 @@ func (s *TestSuite) GetAndFundTestUsers( func (s *TestSuite) ExecTx(ctx context.Context, chain *cosmos.CosmosChain, keyName string, command ...string) (string, error) { node := chain.FullNodes[0] - return node.ExecTx(ctx, keyName, command...) + + resp, err := node.ExecTx(ctx, keyName, command...) + s.Require().NoError(err) + + height, err := chain.Height(context.Background()) + s.Require().NoError(err) + s.WaitForHeight(chain, height+1) + + stdout, stderr, err := chain.FullNodes[0].ExecQuery(ctx, "tx", resp, "--type", "hash") + s.Require().NoError(err) + s.Require().Nil(stderr) + + return string(stdout), nil } // RandLowerCaseLetterString returns a lowercase letter string of given length diff --git a/tests/integration/suite.go b/tests/integration/suite.go index 6e3f237..d98a254 100644 --- a/tests/integration/suite.go +++ b/tests/integration/suite.go @@ -2,6 +2,7 @@ package integration import ( "context" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keyring" sdk "github.com/cosmos/cosmos-sdk/types" @@ -13,7 +14,7 @@ import ( ) const ( - initBalance = 1000000000000 + initBalance = 10000000000000 ) // TestSuite runs the feemarket integration test-suite against a given interchaintest specification @@ -137,6 +138,8 @@ func (s *TestSuite) TestQueryState() { func (s *TestSuite) TestSendTxUpdating() { s.SetupSubTest() + ctx := context.Background() + // cast chain to cosmos-chain cosmosChain, ok := s.chain.(*cosmos.CosmosChain) s.Require().True(ok) @@ -144,15 +147,22 @@ func (s *TestSuite) TestSendTxUpdating() { nodes := cosmosChain.Nodes() s.Require().True(len(nodes) > 0) - // make params query to first node - resp, _, err := nodes[0].ExecQuery(context.Background(), "auth", "account", s.user1.FormattedAddress()) - s.Require().NoError(err) - - s.T().Log(string(resp)) - - // make params query to first node - resp, _, err = nodes[0].ExecQuery(context.Background(), "bank", "balances", s.user1.FormattedAddress()) - s.Require().NoError(err) + state := s.QueryState() + params := s.QueryParams() - s.T().Log(string(resp)) + gas := int64(1000000) + minBaseFee := sdk.NewCoins(sdk.NewCoin(params.FeeDenom, state.MinBaseFee.MulRaw(gas))) + + // send with the exact expected fee + _, err := s.SendCoins( + ctx, + cosmosChain, + s.user1.KeyName(), + s.user1.FormattedAddress(), + s.user2.FormattedAddress(), + sdk.NewCoins(sdk.NewCoin(cosmosChain.Config().Denom, sdk.NewInt(10000))), + minBaseFee, + gas, + ) + s.Require().NoError(err, s.user1.FormattedAddress(), s.user2.FormattedAddress()) } diff --git a/x/feemarket/ante/fee.go b/x/feemarket/ante/fee.go index 53dc0e9..170dc4b 100644 --- a/x/feemarket/ante/fee.go +++ b/x/feemarket/ante/fee.go @@ -49,10 +49,16 @@ func (dfd FeeMarketCheckDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula fee := feeTx.GetFee() gas := feeTx.GetGas() // use provided gas limit + ctx.Logger().Info("fee deduct ante handle", + "min gas prices", minGasPrices, + "fee", fee, + "gas limit", gas, + ) + if !simulate { fee, _, err = CheckTxFees(minGasPrices, feeTx, gas) if err != nil { - return ctx, err + return ctx, errorsmod.Wrapf(err, "error checking fee") } } @@ -82,7 +88,7 @@ func CheckTxFees(minFees sdk.Coins, feeTx sdk.FeeTx, gas uint64) (feeCoins sdk.C } if !feeCoins.IsAnyGTE(requiredFees) { - return nil, nil, sdkerrors.ErrInsufficientFee.Wrapf("got: %s required: %s", feeCoins, requiredFees) + return nil, nil, sdkerrors.ErrInsufficientFee.Wrapf("got: %s required: %s, minGasPrices: %s, gas: %d", feeCoins, requiredFees, minGasPrices, gas) } tip = feeCoins.Sub(minFees...) // tip is the difference between feeCoins and the min fees diff --git a/x/feemarket/post/fee.go b/x/feemarket/post/fee.go index 425c607..b7aacb0 100644 --- a/x/feemarket/post/fee.go +++ b/x/feemarket/post/fee.go @@ -63,6 +63,11 @@ func (dfd FeeMarketDeductDecorator) PostHandle(ctx sdk.Context, tx sdk.Tx, simul fee := feeTx.GetFee() gas := ctx.GasMeter().GasConsumed() // use context gas consumed + ctx.Logger().Info("fee deduct post handle", + "min gas prices", minGasPrices, + "gas consumed", gas, + ) + if !simulate { fee, tip, err = ante.CheckTxFees(minGasPrices, feeTx, gas) if err != nil { @@ -70,6 +75,11 @@ func (dfd FeeMarketDeductDecorator) PostHandle(ctx sdk.Context, tx sdk.Tx, simul } } + ctx.Logger().Info("fee deduct post handle", + "fee", fee, + "tip", tip, + ) + if err := dfd.DeductFeeAndTip(ctx, tx, fee, tip); err != nil { return ctx, err }