From e4dcff44d8c4c181074f9ff60387bf5f29caa66f Mon Sep 17 00:00:00 2001 From: trung2891 Date: Tue, 14 Nov 2023 16:56:55 +0700 Subject: [PATCH] set up test --- x/feeburn/alias.go | 9 ++ x/feeburn/ante/antetest/fee_test_setup.go | 108 ++++++++++++++++++++++ x/feeburn/types/params.go | 7 ++ 3 files changed, 124 insertions(+) create mode 100644 x/feeburn/alias.go create mode 100644 x/feeburn/ante/antetest/fee_test_setup.go diff --git a/x/feeburn/alias.go b/x/feeburn/alias.go new file mode 100644 index 00000000..65924357 --- /dev/null +++ b/x/feeburn/alias.go @@ -0,0 +1,9 @@ +package feeburn + +import ( + "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/x/feeburn/types" +) + +const ( + ModuleName = types.ModuleName +) diff --git a/x/feeburn/ante/antetest/fee_test_setup.go b/x/feeburn/ante/antetest/fee_test_setup.go new file mode 100644 index 00000000..5ddf4c6f --- /dev/null +++ b/x/feeburn/ante/antetest/fee_test_setup.go @@ -0,0 +1,108 @@ +package antetest + +import ( + "fmt" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/tx" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + "github.com/cosmos/cosmos-sdk/testutil/testdata" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/tx/signing" + xauthsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" + "github.com/cosmos/cosmos-sdk/x/params/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/stretchr/testify/suite" + tmrand "github.com/tendermint/tendermint/libs/rand" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + + migalooaapp "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/app" + "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/x/feeburn" + feeburnmoduletypes "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/x/feeburn/types" +) + +type IntegrationTestSuite struct { + suite.Suite + + app *migalooaapp.MigalooApp + ctx sdk.Context + clientCtx client.Context + txBuilder client.TxBuilder +} + +func (s *IntegrationTestSuite) SetupTest() { + app := migalooaapp.SetupMigalooAppWithValSet(s.T()) + ctx := app.BaseApp.NewContext(false, tmproto.Header{ + ChainID: fmt.Sprintf("test-chain-%s", tmrand.Str(4)), + Height: 1, + }) + + encodingConfig := migalooaapp.MakeEncodingConfig() + encodingConfig.Amino.RegisterConcrete(&testdata.TestMsg{}, "testdata.TestMsg", nil) + testdata.RegisterInterfaces(encodingConfig.InterfaceRegistry) + + s.app = app + s.ctx = ctx + s.clientCtx = client.Context{}.WithTxConfig(encodingConfig.TxConfig) +} + +func (s *IntegrationTestSuite) SetupTestBurnFeeStore(minGasPrice []sdk.DecCoin, feeBurnParams *feeburnmoduletypes.Params) types.Subspace { + subspace := s.app.GetSubspace(feeburn.ModuleName) + subspace.SetParamSet(s.ctx, feeBurnParams) + + return subspace +} + +// SetupTestStakingSubspace sets uatom as bond denom for the fee tests. +func (s *IntegrationTestSuite) SetupTestStakingSubspace(params stakingtypes.Params) types.Subspace { + s.app.GetSubspace(stakingtypes.ModuleName).SetParamSet(s.ctx, ¶ms) + return s.app.GetSubspace(stakingtypes.ModuleName) +} + +func (s *IntegrationTestSuite) CreateTestTx(privs []cryptotypes.PrivKey, accNums []uint64, accSeqs []uint64, chainID string) (xauthsigning.Tx, error) { + var sigsV2 []signing.SignatureV2 + for i, priv := range privs { + sigV2 := signing.SignatureV2{ + PubKey: priv.PubKey(), + Data: &signing.SingleSignatureData{ + SignMode: s.clientCtx.TxConfig.SignModeHandler().DefaultMode(), + Signature: nil, + }, + Sequence: accSeqs[i], + } + + sigsV2 = append(sigsV2, sigV2) + } + + if err := s.txBuilder.SetSignatures(sigsV2...); err != nil { + return nil, err + } + + sigsV2 = []signing.SignatureV2{} + for i, priv := range privs { + signerData := xauthsigning.SignerData{ + ChainID: chainID, + AccountNumber: accNums[i], + Sequence: accSeqs[i], + } + sigV2, err := tx.SignWithPrivKey( + s.clientCtx.TxConfig.SignModeHandler().DefaultMode(), + signerData, + s.txBuilder, + priv, + s.clientCtx.TxConfig, + accSeqs[i], + ) + if err != nil { + return nil, err + } + + sigsV2 = append(sigsV2, sigV2) + } + + if err := s.txBuilder.SetSignatures(sigsV2...); err != nil { + return nil, err + } + + return s.txBuilder.GetTx(), nil +} diff --git a/x/feeburn/types/params.go b/x/feeburn/types/params.go index 0f4b3a02..ea803ed0 100644 --- a/x/feeburn/types/params.go +++ b/x/feeburn/types/params.go @@ -5,6 +5,8 @@ import ( "strconv" "gopkg.in/yaml.v2" + + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) var ( @@ -29,6 +31,11 @@ func DefaultParams() Params { ) } +// ParamSetPairs get the params.ParamSet +func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{} +} + // Validate validates the set of params func (p Params) Validate() error { return validateTxFeeBurnPercent(p.TxFeeBurnPercent)