From 272cb1504fc99dc76cdbf5fa45e72e1033c44f28 Mon Sep 17 00:00:00 2001 From: dreamer Date: Tue, 2 Jul 2024 17:52:06 +0800 Subject: [PATCH 1/3] refactor code --- modules/coinswap/depinject.go | 15 ++++++--- modules/farm/depinject.go | 18 ++++++++--- modules/htlc/depinject.go | 18 ++++++++--- modules/mt/depinject.go | 17 +++++++--- modules/nft/depinject.go | 15 ++++++--- modules/nft/module.go | 2 +- modules/oracle/depinject.go | 17 +++++++--- modules/random/depinject.go | 15 ++++++--- modules/random/handler.go | 28 ---------------- modules/record/depinject.go | 14 +++++--- modules/service/depinject.go | 21 +++++++++--- modules/token/depinject.go | 12 +++---- modules/token/genesis_test.go | 60 ----------------------------------- 13 files changed, 120 insertions(+), 132 deletions(-) delete mode 100644 modules/random/handler.go delete mode 100644 modules/token/genesis_test.go diff --git a/modules/coinswap/depinject.go b/modules/coinswap/depinject.go index fd027d9d..33b167a9 100644 --- a/modules/coinswap/depinject.go +++ b/modules/coinswap/depinject.go @@ -21,6 +21,7 @@ func init() { ) } +// ProvideKeyTable provides module's KVStore keys func ProvideKeyTable() types.KeyTable { return types.ParamKeyTable() } @@ -33,7 +34,8 @@ func (am AppModule) IsOnePerModuleType() {} // IsAppModule implements the appmodule.AppModule interface. func (am AppModule) IsAppModule() {} -type CoinswapInputs struct { +// Inputs define the module inputs for the depinject. +type Inputs struct { depinject.In Config *modulev1.Module @@ -47,14 +49,19 @@ type CoinswapInputs struct { LegacySubspace types.Subspace `optional:"true"` } -type CoinswapOutputs struct { +// Outputs define the module outputs for the depinject. +type Outputs struct { depinject.Out CoinswapKeeper keeper.Keeper Module appmodule.AppModule } -func ProvideModule(in CoinswapInputs) CoinswapOutputs { +// ProvideModule creates and returns the coinswap module with the specified inputs. +// +// It takes Inputs as the parameter, which includes the configuration, codec, key, account keeper, bank keeper, and legacy subspace. +// It returns Outputs containing the coinswap keeper and the app module. +func ProvideModule(in Inputs) Outputs { // default to governance authority if not provided authority := authtypes.NewModuleAddress(govtypes.ModuleName) if in.Config.Authority != "" { @@ -71,5 +78,5 @@ func ProvideModule(in CoinswapInputs) CoinswapOutputs { ) m := NewAppModule(in.Cdc, keeper, in.AccountKeeper, in.BankKeeper, in.LegacySubspace) - return CoinswapOutputs{CoinswapKeeper: keeper, Module: m} + return Outputs{CoinswapKeeper: keeper, Module: m} } diff --git a/modules/farm/depinject.go b/modules/farm/depinject.go index bfb7655c..7a9a97c1 100644 --- a/modules/farm/depinject.go +++ b/modules/farm/depinject.go @@ -21,6 +21,10 @@ func init() { ) } +// ProvideKeyTable returns the KeyTable for the farm module's parameters. +// +// No parameters. +// Returns a types.KeyTable. func ProvideKeyTable() types.KeyTable { return types.ParamKeyTable() } @@ -33,7 +37,8 @@ func (am AppModule) IsOnePerModuleType() {} // IsAppModule implements the appmodule.AppModule interface. func (am AppModule) IsAppModule() {} -type FarmInputs struct { +// Inputs define the module inputs for the depinject. +type Inputs struct { depinject.In Config *modulev1.Module @@ -50,14 +55,19 @@ type FarmInputs struct { LegacySubspace types.Subspace `optional:"true"` } -type FarmOutputs struct { +// Outputs define the module outputs for the depinject. +type Outputs struct { depinject.Out FarmKeeper keeper.Keeper Module appmodule.AppModule } -func ProvideModule(in FarmInputs) FarmOutputs { +// ProvideModule creates and returns the farm module with the specified inputs. +// +// It takes Inputs as the parameter, which includes the configuration, codec, key, account keeper, bank keeper, governance keeper, coinswap keeper, and legacy subspace. +// It returns Outputs containing the farm keeper and the app module. +func ProvideModule(in Inputs) Outputs { // default to governance authority if not provided authority := authtypes.NewModuleAddress(govtypes.ModuleName) if in.Config.Authority != "" { @@ -78,5 +88,5 @@ func ProvideModule(in FarmInputs) FarmOutputs { ) m := NewAppModule(in.Cdc, keeper, in.AccountKeeper, in.BankKeeper, in.LegacySubspace) - return FarmOutputs{FarmKeeper: keeper, Module: m} + return Outputs{FarmKeeper: keeper, Module: m} } diff --git a/modules/htlc/depinject.go b/modules/htlc/depinject.go index 1b0ac44b..409471c9 100644 --- a/modules/htlc/depinject.go +++ b/modules/htlc/depinject.go @@ -20,6 +20,10 @@ func init() { ) } +// ProvideKeyTable returns the key table for the htlc module. +// +// No parameters. +// Returns a types.KeyTable. func ProvideKeyTable() types.KeyTable { return types.ParamKeyTable() } @@ -32,7 +36,8 @@ func (am AppModule) IsOnePerModuleType() {} // IsAppModule implements the appmodule.AppModule interface. func (am AppModule) IsAppModule() {} -type HTLCInputs struct { +// Inputs define the module inputs for the depinject. +type Inputs struct { depinject.In Config *modulev1.Module @@ -46,14 +51,19 @@ type HTLCInputs struct { LegacySubspace types.Subspace `optional:"true"` } -type HTLCOutputs struct { +// Outputs define the module outputs for the depinject. +type Outputs struct { depinject.Out HTLCKeeper keeper.Keeper Module appmodule.AppModule } -func ProvideModule(in HTLCInputs) HTLCOutputs { +// ProvideModule creates and returns the HTLC module with the specified inputs. +// +// It takes Inputs as the parameter, which includes the configuration, codec, key, account keeper, and bank keeper. +// It returns Outputs containing the HTLC keeper and the app module. +func ProvideModule(in Inputs) Outputs { // default to governance authority if not provided authority := authtypes.NewModuleAddress(govtypes.ModuleName) if in.Config.Authority != "" { @@ -69,5 +79,5 @@ func ProvideModule(in HTLCInputs) HTLCOutputs { ) m := NewAppModule(in.Cdc, keeper, in.AccountKeeper, in.BankKeeper, in.LegacySubspace) - return HTLCOutputs{HTLCKeeper: keeper, Module: m} + return Outputs{HTLCKeeper: keeper, Module: m} } diff --git a/modules/mt/depinject.go b/modules/mt/depinject.go index 97b43709..8dbe8687 100644 --- a/modules/mt/depinject.go +++ b/modules/mt/depinject.go @@ -26,7 +26,8 @@ func (am AppModule) IsOnePerModuleType() {} // IsAppModule implements the appmodule.AppModule interface. func (am AppModule) IsAppModule() {} -type MTInputs struct { +// Inputs define the module inputs for the depinject. +type Inputs struct { depinject.In Config *modulev1.Module @@ -37,19 +38,27 @@ type MTInputs struct { BankKeeper types.BankKeeper } -type MTOutputs struct { +// Outputs define the module outputs for the depinject. +type Outputs struct { depinject.Out MTKeeper keeper.Keeper Module appmodule.AppModule } -func ProvideModule(in MTInputs) MTOutputs { +// ProvideModule creates a new MTKeeper and AppModule using the provided inputs and returns the Outputs. +// +// Parameters: +// - in: the Inputs struct containing the necessary dependencies for creating the MTKeeper and AppModule. +// +// Returns: +// - Outputs: the struct containing the MTKeeper and AppModule. +func ProvideModule(in Inputs) Outputs { keeper := keeper.NewKeeper( in.Cdc, in.Key, ) m := NewAppModule(in.Cdc, keeper, in.AccountKeeper, in.BankKeeper) - return MTOutputs{MTKeeper: keeper, Module: m} + return Outputs{MTKeeper: keeper, Module: m} } diff --git a/modules/nft/depinject.go b/modules/nft/depinject.go index 70fa1403..bfe83971 100644 --- a/modules/nft/depinject.go +++ b/modules/nft/depinject.go @@ -1,4 +1,4 @@ -package module +package nft import ( "cosmossdk.io/core/appmodule" @@ -26,7 +26,8 @@ func (am AppModule) IsOnePerModuleType() {} // IsAppModule implements the appmodule.AppModule interface. func (am AppModule) IsAppModule() {} -type NFTInputs struct { +// Inputs define the arguments used to instantiate an app module. +type Inputs struct { depinject.In Config *modulev1.Module @@ -37,14 +38,18 @@ type NFTInputs struct { BankKeeper types.BankKeeper } -type NFTOutputs struct { +// Outputs define the read-only arguments return by depinject. +type Outputs struct { depinject.Out NFTKeeper keeper.Keeper Module appmodule.AppModule } -func ProvideModule(in NFTInputs) NFTOutputs { +// ProvideModule provides a module for the NFT with the given inputs and returns the NFT keeper and module. +// +// Takes Inputs as input parameters and returns Outputs. +func ProvideModule(in Inputs) Outputs { keeper := keeper.NewKeeper( in.Cdc, in.Key, @@ -53,5 +58,5 @@ func ProvideModule(in NFTInputs) NFTOutputs { ) m := NewAppModule(in.Cdc, keeper, in.AccountKeeper, in.BankKeeper) - return NFTOutputs{NFTKeeper: keeper, Module: m} + return Outputs{NFTKeeper: keeper, Module: m} } diff --git a/modules/nft/module.go b/modules/nft/module.go index 6aa350fb..da5a507e 100644 --- a/modules/nft/module.go +++ b/modules/nft/module.go @@ -1,4 +1,4 @@ -package module +package nft import ( "context" diff --git a/modules/oracle/depinject.go b/modules/oracle/depinject.go index 04a494ea..75a4d1a8 100644 --- a/modules/oracle/depinject.go +++ b/modules/oracle/depinject.go @@ -26,7 +26,8 @@ func (am AppModule) IsOnePerModuleType() {} // IsAppModule implements the appmodule.AppModule interface. func (am AppModule) IsAppModule() {} -type OracleInputs struct { +// Inputs define the module inputs for the depinject. +type Inputs struct { depinject.In Config *modulev1.Module @@ -38,14 +39,22 @@ type OracleInputs struct { ServiceKeeper types.ServiceKeeper } -type OracleOutputs struct { +// Outputs define the module outputs for the depinject. +type Outputs struct { depinject.Out OracleKeeper keeper.Keeper Module appmodule.AppModule } -func ProvideModule(in OracleInputs) OracleOutputs { +// ProvideModule creates a new OracleKeeper and AppModule using the provided inputs and returns the Outputs. +// +// Parameters: +// - in: the Inputs struct containing the necessary dependencies for creating the OracleKeeper and AppModule. +// +// Returns: +// - Outputs: the struct containing the OracleKeeper and AppModule. +func ProvideModule(in Inputs) Outputs { keeper := keeper.NewKeeper( in.Cdc, in.Key, @@ -53,5 +62,5 @@ func ProvideModule(in OracleInputs) OracleOutputs { ) m := NewAppModule(in.Cdc, keeper, in.AccountKeeper, in.BankKeeper) - return OracleOutputs{OracleKeeper: keeper, Module: m} + return Outputs{OracleKeeper: keeper, Module: m} } diff --git a/modules/random/depinject.go b/modules/random/depinject.go index de9c2471..14e160a2 100644 --- a/modules/random/depinject.go +++ b/modules/random/depinject.go @@ -26,7 +26,8 @@ func (am AppModule) IsOnePerModuleType() {} // IsAppModule implements the appmodule.AppModule interface. func (am AppModule) IsAppModule() {} -type RandomInputs struct { +// Inputs define the module inputs for the depinject. +type Inputs struct { depinject.In Config *modulev1.Module @@ -38,14 +39,20 @@ type RandomInputs struct { ServiceKeeper types.ServiceKeeper } -type RandomOutputs struct { +// Outputs define the module outputs for the depinject. +type Outputs struct { depinject.Out RandomKeeper keeper.Keeper Module appmodule.AppModule } -func ProvideModule(in RandomInputs) RandomOutputs { +// ProvideModule creates a new AppModule and returns the Outputs. +// +// - in: the Inputs struct containing the necessary dependencies for creating the AppModule. +// Returns: +// - Outputs: the struct containing the RandomKeeper and AppModule. +func ProvideModule(in Inputs) Outputs { keeper := keeper.NewKeeper( in.Cdc, in.Key, @@ -54,5 +61,5 @@ func ProvideModule(in RandomInputs) RandomOutputs { ) m := NewAppModule(in.Cdc, keeper, in.AccountKeeper, in.BankKeeper) - return RandomOutputs{RandomKeeper: keeper, Module: m} + return Outputs{RandomKeeper: keeper, Module: m} } diff --git a/modules/random/handler.go b/modules/random/handler.go deleted file mode 100644 index f619193c..00000000 --- a/modules/random/handler.go +++ /dev/null @@ -1,28 +0,0 @@ -package random - -import ( - errorsmod "cosmossdk.io/errors" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - - "mods.irisnet.org/modules/random/keeper" - "mods.irisnet.org/modules/random/types" -) - -// NewHandler returns a handler for all random msgs -func NewHandler(k keeper.Keeper) sdk.Handler { - msgServer := keeper.NewMsgServerImpl(k) - - return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { - ctx = ctx.WithEventManager(sdk.NewEventManager()) - - switch msg := msg.(type) { - case *types.MsgRequestRandom: - res, err := msgServer.RequestRandom(sdk.WrapSDKContext(ctx), msg) - return sdk.WrapServiceResult(ctx, res, err) - - default: - return nil, errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", types.ModuleName, msg) - } - } -} diff --git a/modules/record/depinject.go b/modules/record/depinject.go index 97a11e61..0c7f83d4 100644 --- a/modules/record/depinject.go +++ b/modules/record/depinject.go @@ -26,7 +26,8 @@ func (am AppModule) IsOnePerModuleType() {} // IsAppModule implements the appmodule.AppModule interface. func (am AppModule) IsAppModule() {} -type RecordInputs struct { +// Inputs define the module inputs for the depinject. +type Inputs struct { depinject.In Config *modulev1.Module @@ -37,19 +38,24 @@ type RecordInputs struct { BankKeeper types.BankKeeper } -type RecordOutputs struct { +// Outputs define the module outputs for the depinject. +type Outputs struct { depinject.Out RecordKeeper keeper.Keeper Module appmodule.AppModule } -func ProvideModule(in RecordInputs) RecordOutputs { +// ProvideModule creates and returns the record module with the specified inputs. +// +// Takes Inputs as the parameter, which includes the codec, key, account keeper, and bank keeper. +// Returns Outputs containing the record keeper and the app module. +func ProvideModule(in Inputs) Outputs { keeper := keeper.NewKeeper( in.Cdc, in.Key, ) m := NewAppModule(in.Cdc, keeper, in.AccountKeeper, in.BankKeeper) - return RecordOutputs{RecordKeeper: keeper, Module: m} + return Outputs{RecordKeeper: keeper, Module: m} } diff --git a/modules/service/depinject.go b/modules/service/depinject.go index 6a7909e3..a067540f 100644 --- a/modules/service/depinject.go +++ b/modules/service/depinject.go @@ -21,6 +21,13 @@ func init() { ) } +// ProvideKeyTable returns the KeyTable for the service module. +// +// It calls the ParamKeyTable function from the types package to retrieve the KeyTable. +// The KeyTable is used to register parameter sets for the service module. +// +// Returns: +// - types.KeyTable: The KeyTable for the service module. func ProvideKeyTable() types.KeyTable { return types.ParamKeyTable() } @@ -33,7 +40,8 @@ func (am AppModule) IsOnePerModuleType() {} // IsAppModule implements the appmodule.AppModule interface. func (am AppModule) IsAppModule() {} -type ServiceInputs struct { +// Inputs define the module inputs for the depinject. +type Inputs struct { depinject.In Config *modulev1.Module @@ -47,14 +55,19 @@ type ServiceInputs struct { LegacySubspace types.Subspace `optional:"true"` } -type ServiceOutputs struct { +// Outputs define the module outputs for the depinject. +type Outputs struct { depinject.Out ServiceKeeper keeper.Keeper Module appmodule.AppModule } -func ProvideModule(in ServiceInputs) ServiceOutputs { +// ProvideModule creates and returns the HTLC module with the specified inputs. +// +// It takes Inputs as the parameter, which includes the configuration, codec, key, account keeper, and bank keeper. +// It returns Outputs containing the HTLC keeper and the app module. +func ProvideModule(in Inputs) Outputs { // default to governance authority if not provided authority := authtypes.NewModuleAddress(govtypes.ModuleName) if in.Config.Authority != "" { @@ -71,5 +84,5 @@ func ProvideModule(in ServiceInputs) ServiceOutputs { ) m := NewAppModule(in.Cdc, keeper, in.AccountKeeper, in.BankKeeper, in.LegacySubspace) - return ServiceOutputs{ServiceKeeper: keeper, Module: m} + return Outputs{ServiceKeeper: keeper, Module: m} } diff --git a/modules/token/depinject.go b/modules/token/depinject.go index 2f3b81a3..5c1bde07 100644 --- a/modules/token/depinject.go +++ b/modules/token/depinject.go @@ -35,8 +35,8 @@ func (am AppModule) IsOnePerModuleType() {} // IsAppModule implements the appmodule.AppModule interface. func (am AppModule) IsAppModule() {} -// TokenInputs is the input of the Token module -type TokenInputs struct { +// Inputs is the input of the Token module +type Inputs struct { depinject.In Config *modulev1.Module @@ -52,8 +52,8 @@ type TokenInputs struct { LegacySubspace types.Subspace `optional:"true"` } -// TokenOutputs is the output of the Token module -type TokenOutputs struct { +// Outputs is the output of the Token module +type Outputs struct { depinject.Out TokenKeeper keeper.Keeper @@ -63,7 +63,7 @@ type TokenOutputs struct { // ProvideModule provides a module for the token with the given inputs and returns the token keeper and module. // // Takes TokenInputs as input parameters and returns TokenOutputs. -func ProvideModule(in TokenInputs) TokenOutputs { +func ProvideModule(in Inputs) Outputs { // default to governance authority if not provided authority := authtypes.NewModuleAddress(govtypes.ModuleName) if in.Config.Authority != "" { @@ -82,5 +82,5 @@ func ProvideModule(in TokenInputs) TokenOutputs { ) m := NewAppModule(in.Cdc, keeper, in.AccountKeeper, in.BankKeeper, in.LegacySubspace) - return TokenOutputs{TokenKeeper: keeper, Module: m} + return Outputs{TokenKeeper: keeper, Module: m} } diff --git a/modules/token/genesis_test.go b/modules/token/genesis_test.go deleted file mode 100644 index fdb5fea5..00000000 --- a/modules/token/genesis_test.go +++ /dev/null @@ -1,60 +0,0 @@ -package token_test - -// import ( -// "testing" - -// "github.com/stretchr/testify/require" - -// "github.com/cometbft/cometbft/crypto/tmhash" -// tmproto "github.com/cometbft/cometbft/proto/tendermint/types" - -// sdk "github.com/cosmos/cosmos-sdk/types" - -// "mods.irisnet.org/modules/token" -// "mods.irisnet.org/simapp" -// v1 "mods.irisnet.org/modules/token/types/v1" -// ) - -// func TestExportGenesis(t *testing.T) { -// app := simapp.Setup(t, false) - -// ctx := app.BaseApp.NewContext(false, tmproto.Header{}) - -// // export genesis -// genesisState := token.ExportGenesis(ctx, app.TokenKeeper) - -// require.Equal(t, v1.DefaultParams(), genesisState.Params) -// for _, token := range genesisState.Tokens { -// require.Equal(t, token, v1.GetNativeToken()) -// } -// } - -// func TestInitGenesis(t *testing.T) { -// app := simapp.Setup(t, false) - -// ctx := app.BaseApp.NewContext(false, tmproto.Header{}) - -// // add token -// addr := sdk.AccAddress(tmhash.SumTruncated([]byte("addr1"))) -// ft := v1.NewToken("btc", "Bitcoin Network", "satoshi", 1, 1, 1, true, addr) - -// burnCoins := []sdk.Coin{ -// {Denom: ft.MinUnit, Amount: sdk.NewInt(1000)}, -// } -// genesis := v1.GenesisState{ -// Params: v1.DefaultParams(), -// Tokens: []v1.Token{ft}, -// BurnedCoins: burnCoins, -// } - -// // initialize genesis -// token.InitGenesis(ctx, app.TokenKeeper, genesis) - -// // query all tokens -// var tokens = app.TokenKeeper.GetTokens(ctx, nil) -// require.Equal(t, len(tokens), 2) -// require.Equal(t, tokens[0], &ft) - -// var coins = app.TokenKeeper.GetAllBurnCoin(ctx) -// require.Equal(t, burnCoins, coins) -// } From e903d9f18b0dd7a0d8a64056c320daae0de51bff Mon Sep 17 00:00:00 2001 From: dreamer Date: Tue, 2 Jul 2024 17:53:34 +0800 Subject: [PATCH 2/3] fix github action --- .github/workflows/test.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 994ec174..6d5c8907 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,8 +4,6 @@ on: paths: - '**/*.go' - '**/*.mod' - paths-ignore: - - '**/*' # 忽略其他所有文件 jobs: test-unit: name: Test Units From 14ac05aaa3fa99c473e1d35a0ecd82a5b3fba427 Mon Sep 17 00:00:00 2001 From: dreamer Date: Wed, 3 Jul 2024 10:42:23 +0800 Subject: [PATCH 3/3] refactor test --- e2e/random/query.go | 3 +-- e2e/random/tx.go | 3 +-- e2e/service/query.go | 3 +-- e2e/service/tx.go | 3 +-- e2e/suite.go | 47 ++++++++++++++++++++++++-------------------- 5 files changed, 30 insertions(+), 29 deletions(-) diff --git a/e2e/random/query.go b/e2e/random/query.go index 50c2a360..6b64d646 100644 --- a/e2e/random/query.go +++ b/e2e/random/query.go @@ -28,7 +28,7 @@ type QueryTestSuite struct { // SetupSuite sets up test suite func (s *QueryTestSuite) SetupSuite() { - s.SetModifyConfigFn(func(cfg *network.Config) { + s.SetupSuiteWithModifyConfigFn(func(cfg *network.Config) { var serviceGenState servicetypes.GenesisState cfg.Codec.MustUnmarshalJSON(cfg.GenesisState[servicetypes.ModuleName], &serviceGenState) @@ -43,7 +43,6 @@ func (s *QueryTestSuite) SetupSuite() { ) cfg.GenesisState[servicetypes.ModuleName] = cfg.Codec.MustMarshalJSON(&serviceGenState) }) - s.TestSuite.SetupSuite() } // TestQueryCmd tests all query command in the nft module diff --git a/e2e/random/tx.go b/e2e/random/tx.go index 17f1753c..b401aa3a 100644 --- a/e2e/random/tx.go +++ b/e2e/random/tx.go @@ -27,7 +27,7 @@ type TxTestSuite struct { // SetupSuite sets up test suite func (s *TxTestSuite) SetupSuite() { - s.SetModifyConfigFn(func(cfg *network.Config) { + s.SetupSuiteWithModifyConfigFn(func(cfg *network.Config) { var serviceGenState servicetypes.GenesisState cfg.Codec.MustUnmarshalJSON(cfg.GenesisState[servicetypes.ModuleName], &serviceGenState) @@ -42,7 +42,6 @@ func (s *TxTestSuite) SetupSuite() { ) cfg.GenesisState[servicetypes.ModuleName] = cfg.Codec.MustMarshalJSON(&serviceGenState) }) - s.TestSuite.SetupSuite() } // TestTxCmd tests all tx command in the nft module diff --git a/e2e/service/query.go b/e2e/service/query.go index 7c4b1724..529477b0 100644 --- a/e2e/service/query.go +++ b/e2e/service/query.go @@ -27,7 +27,7 @@ type QueryTestSuite struct { // SetupSuite sets up test suite func (s *QueryTestSuite) SetupSuite() { - s.SetModifyConfigFn(func(cfg *network.Config) { + s.SetupSuiteWithModifyConfigFn(func(cfg *network.Config) { var serviceGenesisState servicetypes.GenesisState cfg.Codec.MustUnmarshalJSON(cfg.GenesisState[servicetypes.ModuleName], &serviceGenesisState) @@ -36,7 +36,6 @@ func (s *QueryTestSuite) SetupSuite() { cfg.GenesisState[servicetypes.ModuleName] = cfg.Codec.MustMarshalJSON(&serviceGenesisState) cfg.NumValidators = 1 }) - s.TestSuite.SetupSuite() } // TestQueryCmd tests all query command in the service module diff --git a/e2e/service/tx.go b/e2e/service/tx.go index da6bfbaf..d2b98895 100644 --- a/e2e/service/tx.go +++ b/e2e/service/tx.go @@ -27,7 +27,7 @@ type TxTestSuite struct { // SetupSuite sets up test suite func (s *TxTestSuite) SetupSuite() { - s.SetModifyConfigFn(func(cfg *network.Config) { + s.SetupSuiteWithModifyConfigFn(func(cfg *network.Config) { var serviceGenesisState servicetypes.GenesisState cfg.Codec.MustUnmarshalJSON(cfg.GenesisState[servicetypes.ModuleName], &serviceGenesisState) @@ -36,7 +36,6 @@ func (s *TxTestSuite) SetupSuite() { cfg.GenesisState[servicetypes.ModuleName] = cfg.Codec.MustMarshalJSON(&serviceGenesisState) cfg.NumValidators = 1 }) - s.TestSuite.SetupSuite() } // TestQueryCmd tests all query command in the service module diff --git a/e2e/suite.go b/e2e/suite.go index 3d59f8f2..df47efaf 100644 --- a/e2e/suite.go +++ b/e2e/suite.go @@ -15,39 +15,44 @@ type ModifyConfigFn = func(cfg *network.Config) type TestSuite struct { suite.Suite simapp.Network - modifyConfigFn ModifyConfigFn + } -// SetupSuite creates a new network for integration tests -func (s *TestSuite) SetupSuite() { +// SetupSuiteWithModifyConfigFn sets up the end-to-end test suite with the given modifyConfigFn. +// +// Parameters: +// - modifyConfigFn: A function that modifies the config for the test suite. +// +// Return type: None. +func (s *TestSuite) SetupSuiteWithModifyConfigFn(modifyConfigFn ModifyConfigFn) { s.T().Log("setting up e2e test suite") - depInjectOptions := simapp.DepinjectOptions{ - Config: AppConfig, - Providers: []interface{}{ - keeper.ProvideMockEVM(), - keeper.ProvideMockICS20(), - }, - } - if s.modifyConfigFn == nil { - s.Network = simapp.SetupNetwork(s.T(), depInjectOptions) - return - } - - cfg, err := simapp.NewConfig(depInjectOptions) + cfg, err := simapp.NewConfig(s.DepinjectOptions()) s.Require().NoError(err) - s.modifyConfigFn(&cfg) + modifyConfigFn(&cfg) s.Network = simapp.SetupNetworkWithConfig(s.T(), cfg) } +// SetupSuite creates a new network for integration tests +func (s *TestSuite) SetupSuite() { + s.T().Log("setting up e2e test suite") + s.Network = simapp.SetupNetwork(s.T(), s.DepinjectOptions()) +} + // TearDownSuite tears down the integration test suite func (s *TestSuite) TearDownSuite() { s.T().Log("tearing down e2e test suite") s.Network.Cleanup() } -// SetModifyConfigFn sets the modify config function -func (s *TestSuite) SetModifyConfigFn(fn ModifyConfigFn) { - s.modifyConfigFn = fn -} +// DepinjectOptions returns the depinject options for the test suite +func (s *TestSuite) DepinjectOptions() simapp.DepinjectOptions { + return simapp.DepinjectOptions{ + Config: AppConfig, + Providers: []interface{}{ + keeper.ProvideMockEVM(), + keeper.ProvideMockICS20(), + }, + } +} \ No newline at end of file