From 60ec34aab6fad903e6c2c9656e50017c11309199 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 8 Nov 2022 10:44:04 -0500 Subject: [PATCH 01/19] refactor!: migrate to core appmodule.AppModule extension interfaces --- types/module/module.go | 125 +++++++++++++++++++++++++++--------- x/auth/module.go | 5 +- x/auth/vesting/module.go | 12 +++- x/authz/module/module.go | 13 +++- x/bank/module.go | 12 +++- x/capability/module.go | 12 +++- x/consensus/module.go | 12 +++- x/crisis/module.go | 12 +++- x/distribution/module.go | 12 +++- x/evidence/module.go | 12 +++- x/feegrant/module/module.go | 13 +++- x/genutil/module.go | 13 +++- x/gov/module.go | 13 +++- x/group/module/module.go | 13 +++- x/mint/module.go | 13 +++- x/nft/module/module.go | 14 +++- x/params/module.go | 13 +++- x/slashing/module.go | 12 +++- x/staking/module.go | 12 +++- x/upgrade/module.go | 14 +++- 20 files changed, 289 insertions(+), 68 deletions(-) diff --git a/types/module/module.go b/types/module/module.go index 45356e239915..588904a42a55 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -33,6 +33,7 @@ import ( "fmt" "sort" + "cosmossdk.io/core/appmodule" "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" @@ -47,12 +48,11 @@ import ( // AppModuleBasic is the standard form for basic non-dependant elements of an application module. type AppModuleBasic interface { - Name() string + HasName RegisterLegacyAminoCodec(*codec.LegacyAmino) RegisterInterfaces(codectypes.InterfaceRegistry) - DefaultGenesis(codec.JSONCodec) json.RawMessage - ValidateGenesis(codec.JSONCodec, client.TxEncodingConfig, json.RawMessage) error + HasGenesisBasics // client functionality RegisterGRPCGatewayRoutes(client.Context, *runtime.ServeMux) @@ -60,6 +60,15 @@ type AppModuleBasic interface { GetQueryCmd() *cobra.Command } +type HasName interface { + Name() string +} + +type HasGenesisBasics interface { + DefaultGenesis(codec.JSONCodec) json.RawMessage + ValidateGenesis(codec.JSONCodec, client.TxEncodingConfig, json.RawMessage) error +} + // BasicManager is a collection of AppModuleBasic type BasicManager map[string]AppModuleBasic @@ -143,21 +152,38 @@ func (bm BasicManager) AddQueryCommands(rootQueryCmd *cobra.Command) { // AppModuleGenesis is the standard form for an application module genesis functions type AppModuleGenesis interface { AppModuleBasic + HasGenesis +} +type HasGenesis interface { + HasGenesisBasics InitGenesis(sdk.Context, codec.JSONCodec, json.RawMessage) []abci.ValidatorUpdate ExportGenesis(sdk.Context, codec.JSONCodec) json.RawMessage } -// AppModule is the standard form for an application module +// Deprecated: AppModule is the legacy form for an application module. Most of +// its functionality has been moved to extension interfaces based off of +// appmodule.AppModule. type AppModule interface { - AppModuleGenesis + appmodule.AppModule + // HasName allows the module to provide its own name for legacy purposes. + // Newer apps should specify the name for their modules using a map + // (see NewManagerFromMap). + HasName +} + +type HasRegisterInvariants interface { // registers RegisterInvariants(sdk.InvariantRegistry) +} +type HasRegisterServices interface { // RegisterServices allows a module to register services RegisterServices(Configurator) +} +type HasConsensusVersion interface { // ConsensusVersion is a sequence number for state-breaking change of the // module. It should be incremented on each consensus-breaking change // introduced by the module. To avoid wrong/empty versions, the initial version @@ -189,6 +215,12 @@ func NewGenesisOnlyAppModule(amg AppModuleGenesis) AppModule { } } +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. +func (GenesisOnlyAppModule) IsOnePerModuleType() {} + +// IsAppModule implements the appmodule.AppModule interface. +func (GenesisOnlyAppModule) IsAppModule() {} + // RegisterInvariants is a placeholder function register no invariants func (GenesisOnlyAppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} @@ -212,7 +244,7 @@ func (GenesisOnlyAppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []ab // Manager defines a module manager that provides the high level utility for managing and executing // operations for a group of modules type Manager struct { - Modules map[string]AppModule + Modules map[string]appmodule.AppModule OrderInitGenesis []string OrderExportGenesis []string OrderBeginBlockers []string @@ -220,9 +252,9 @@ type Manager struct { OrderMigrations []string } -// NewManager creates a new Manager object +// Deprecated: NewManager creates a new Manager object func NewManager(modules ...AppModule) *Manager { - moduleMap := make(map[string]AppModule) + moduleMap := make(map[string]appmodule.AppModule) modulesStr := make([]string, 0, len(modules)) for _, module := range modules { moduleMap[module.Name()] = module @@ -238,6 +270,22 @@ func NewManager(modules ...AppModule) *Manager { } } +// NewManager creates a new Manager object +func NewManagerFromMap(moduleMap map[string]appmodule.AppModule) *Manager { + modulesStr := make([]string, 0, len(moduleMap)) + for name := range moduleMap { + modulesStr = append(modulesStr, name) + } + + return &Manager{ + Modules: moduleMap, + OrderInitGenesis: modulesStr, + OrderExportGenesis: modulesStr, + OrderBeginBlockers: modulesStr, + OrderEndBlockers: modulesStr, + } +} + // SetOrderInitGenesis sets the order of init genesis calls func (m *Manager) SetOrderInitGenesis(moduleNames ...string) { m.assertNoForgottenModules("SetOrderInitGenesis", moduleNames) @@ -273,7 +321,9 @@ func (m *Manager) SetOrderMigrations(moduleNames ...string) { func (m *Manager) RegisterInvariants(ir sdk.InvariantRegistry) { modules := maps.Values(m.Modules) for _, module := range modules { - module.RegisterInvariants(ir) + if module, ok := module.(HasRegisterInvariants); ok { + module.RegisterInvariants(ir) + } } } @@ -281,7 +331,9 @@ func (m *Manager) RegisterInvariants(ir sdk.InvariantRegistry) { func (m *Manager) RegisterServices(cfg Configurator) { modules := maps.Values(m.Modules) for _, module := range modules { - module.RegisterServices(cfg) + if module, ok := module.(HasRegisterServices); ok { + module.RegisterServices(cfg) + } } } @@ -295,17 +347,20 @@ func (m *Manager) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, genesisData if genesisData[moduleName] == nil { continue } - ctx.Logger().Debug("running initialization for module", "module", moduleName) - moduleValUpdates := m.Modules[moduleName].InitGenesis(ctx, cdc, genesisData[moduleName]) + if module, ok := m.Modules[moduleName].(HasGenesis); ok { + ctx.Logger().Debug("running initialization for module", "module", moduleName) - // use these validator updates if provided, the module manager assumes - // only one module will update the validator set - if len(moduleValUpdates) > 0 { - if len(validatorUpdates) > 0 { - panic("validator InitGenesis updates already set by a previous module") + moduleValUpdates := module.InitGenesis(ctx, cdc, genesisData[moduleName]) + + // use these validator updates if provided, the module manager assumes + // only one module will update the validator set + if len(moduleValUpdates) > 0 { + if len(validatorUpdates) > 0 { + panic("validator InitGenesis updates already set by a previous module") + } + validatorUpdates = moduleValUpdates } - validatorUpdates = moduleValUpdates } } @@ -329,7 +384,9 @@ func (m *Manager) ExportGenesisForModules(ctx sdk.Context, cdc codec.JSONCodec, genesisData := make(map[string]json.RawMessage) if len(modulesToExport) == 0 { for _, moduleName := range m.OrderExportGenesis { - genesisData[moduleName] = m.Modules[moduleName].ExportGenesis(ctx, cdc) + if module, ok := m.Modules[moduleName].(HasGenesis); ok { + genesisData[moduleName] = module.ExportGenesis(ctx, cdc) + } } return genesisData @@ -341,7 +398,9 @@ func (m *Manager) ExportGenesisForModules(ctx sdk.Context, cdc codec.JSONCodec, } for _, moduleName := range modulesToExport { - genesisData[moduleName] = m.Modules[moduleName].ExportGenesis(ctx, cdc) + if module, ok := m.Modules[moduleName].(HasGenesis); ok { + genesisData[moduleName] = module.ExportGenesis(ctx, cdc) + } } return genesisData @@ -450,7 +509,10 @@ func (m Manager) RunMigrations(ctx sdk.Context, cfg Configurator, fromVM Version for _, moduleName := range modules { module := m.Modules[moduleName] fromVersion, exists := fromVM[moduleName] - toVersion := module.ConsensusVersion() + toVersion := uint64(0) + if module, ok := module.(HasConsensusVersion); ok { + toVersion = module.ConsensusVersion() + } // We run migration if the module is specified in `fromVM`. // Otherwise we run InitGenesis. @@ -467,11 +529,13 @@ func (m Manager) RunMigrations(ctx sdk.Context, cfg Configurator, fromVM Version } } else { ctx.Logger().Info(fmt.Sprintf("adding a new module: %s", moduleName)) - moduleValUpdates := module.InitGenesis(ctx, c.cdc, module.DefaultGenesis(c.cdc)) - // The module manager assumes only one module will update the - // validator set, and it can't be a new module. - if len(moduleValUpdates) > 0 { - return nil, sdkerrors.Wrapf(sdkerrors.ErrLogic, "validator InitGenesis update is already set by another module") + if module, ok := m.Modules[moduleName].(HasGenesis); ok { + moduleValUpdates := module.InitGenesis(ctx, c.cdc, module.DefaultGenesis(c.cdc)) + // The module manager assumes only one module will update the + // validator set, and it can't be a new module. + if len(moduleValUpdates) > 0 { + return nil, sdkerrors.Wrapf(sdkerrors.ErrLogic, "validator InitGenesis update is already set by another module") + } } } @@ -533,9 +597,12 @@ func (m *Manager) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) abci.Respo // GetVersionMap gets consensus version from all modules func (m *Manager) GetVersionMap() VersionMap { vermap := make(VersionMap) - for _, v := range m.Modules { - version := v.ConsensusVersion() - name := v.Name() + for name, v := range m.Modules { + version := uint64(0) + if v, ok := v.(HasConsensusVersion); ok { + version = v.ConsensusVersion() + } + name := name vermap[name] = version } diff --git a/x/auth/module.go b/x/auth/module.go index 8cab7194d429..9c9e4873a4fe 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -230,8 +230,7 @@ type AuthOutputs struct { depinject.Out AccountKeeper keeper.AccountKeeper - Module runtime.AppModuleWrapper - NewAppModule appmodule.AppModule + Module appmodule.AppModule } func ProvideModule(in AuthInputs) AuthOutputs { @@ -257,5 +256,5 @@ func ProvideModule(in AuthInputs) AuthOutputs { k := keeper.NewAccountKeeper(in.Cdc, in.Key, in.AccountI, maccPerms, in.Config.Bech32Prefix, authority.String()) m := NewAppModule(in.Cdc, k, in.RandomGenesisAccountsFn, in.LegacySubspace) - return AuthOutputs{AccountKeeper: k, Module: runtime.WrapAppModule(m), NewAppModule: m} + return AuthOutputs{AccountKeeper: k, Module: m} } diff --git a/x/auth/vesting/module.go b/x/auth/vesting/module.go index 8168447da9cf..a71e7cf41f15 100644 --- a/x/auth/vesting/module.go +++ b/x/auth/vesting/module.go @@ -91,6 +91,14 @@ func NewAppModule(ak keeper.AccountKeeper, bk types.BankKeeper) AppModule { } } +var _ appmodule.AppModule = AppModule{} + +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. +func (am AppModule) IsOnePerModuleType() {} + +// IsAppModule implements the appmodule.AppModule interface. +func (am AppModule) IsAppModule() {} + // RegisterInvariants performs a no-op; there are no invariants to enforce. func (AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} @@ -136,11 +144,11 @@ type VestingInputs struct { type VestingOutputs struct { depinject.Out - Module runtime.AppModuleWrapper + Module appmodule.AppModule } func ProvideModule(in VestingInputs) VestingOutputs { m := NewAppModule(in.AccountKeeper, in.BankKeeper) - return VestingOutputs{Module: runtime.WrapAppModule(m)} + return VestingOutputs{Module: m} } diff --git a/x/authz/module/module.go b/x/authz/module/module.go index 6e30bcbca68a..4622e9bebc1a 100644 --- a/x/authz/module/module.go +++ b/x/authz/module/module.go @@ -13,6 +13,7 @@ import ( "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" + "github.com/cosmos/cosmos-sdk/baseapp" sdkclient "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" @@ -120,6 +121,14 @@ func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak authz.AccountKeeper, } } +var _ appmodule.AppModule = AppModule{} + +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. +func (am AppModule) IsOnePerModuleType() {} + +// IsAppModule implements the appmodule.AppModule interface. +func (am AppModule) IsAppModule() {} + // Name returns the authz module's name. func (AppModule) Name() string { return authz.ModuleName @@ -185,13 +194,13 @@ type AuthzOutputs struct { depinject.Out AuthzKeeper keeper.Keeper - Module runtime.AppModuleWrapper + Module appmodule.AppModule } func ProvideModule(in AuthzInputs) AuthzOutputs { k := keeper.NewKeeper(in.Key, in.Cdc, in.MsgServiceRouter, in.AccountKeeper) m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.BankKeeper, in.Registry) - return AuthzOutputs{AuthzKeeper: k, Module: runtime.WrapAppModule(m)} + return AuthzOutputs{AuthzKeeper: k, Module: m} } // ____________________________________________________________________________ diff --git a/x/bank/module.go b/x/bank/module.go index 70d3ec4a33d3..fab8c9c7b640 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -108,6 +108,14 @@ type AppModule struct { legacySubspace exported.Subspace } +var _ appmodule.AppModule = AppModule{} + +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. +func (am AppModule) IsOnePerModuleType() {} + +// IsAppModule implements the appmodule.AppModule interface. +func (am AppModule) IsAppModule() {} + // RegisterServices registers module services. func (am AppModule) RegisterServices(cfg module.Configurator) { types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) @@ -222,7 +230,7 @@ type BankOutputs struct { depinject.Out BankKeeper keeper.BaseKeeper - Module runtime.AppModuleWrapper + Module appmodule.AppModule } func ProvideModule(in BankInputs) BankOutputs { @@ -257,5 +265,5 @@ func ProvideModule(in BankInputs) BankOutputs { ) m := NewAppModule(in.Cdc, bankKeeper, in.AccountKeeper, in.LegacySubspace) - return BankOutputs{BankKeeper: bankKeeper, Module: runtime.WrapAppModule(m)} + return BankOutputs{BankKeeper: bankKeeper, Module: m} } diff --git a/x/capability/module.go b/x/capability/module.go index 843eb3f6e778..cc223588d15c 100644 --- a/x/capability/module.go +++ b/x/capability/module.go @@ -104,6 +104,14 @@ func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, sealKeeper bool) AppMod } } +var _ appmodule.AppModule = AppModule{} + +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. +func (am AppModule) IsOnePerModuleType() {} + +// IsAppModule implements the appmodule.AppModule interface. +func (am AppModule) IsAppModule() {} + // Name returns the capability module's name. func (am AppModule) Name() string { return am.AppModuleBasic.Name() @@ -200,7 +208,7 @@ type CapabilityOutputs struct { depinject.Out CapabilityKeeper *keeper.Keeper - Module runtime.AppModuleWrapper + Module appmodule.AppModule } func ProvideModule(in CapabilityInputs) CapabilityOutputs { @@ -209,6 +217,6 @@ func ProvideModule(in CapabilityInputs) CapabilityOutputs { return CapabilityOutputs{ CapabilityKeeper: k, - Module: runtime.WrapAppModule(m), + Module: m, } } diff --git a/x/consensus/module.go b/x/consensus/module.go index b79317690b3d..8afe08940585 100644 --- a/x/consensus/module.go +++ b/x/consensus/module.go @@ -85,6 +85,14 @@ type AppModule struct { keeper keeper.Keeper } +var _ appmodule.AppModule = AppModule{} + +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. +func (am AppModule) IsOnePerModuleType() {} + +// IsAppModule implements the appmodule.AppModule interface. +func (am AppModule) IsAppModule() {} + // RegisterServices registers module services. func (am AppModule) RegisterServices(cfg module.Configurator) { types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) @@ -143,7 +151,7 @@ type ConsensusParamOutputs struct { depinject.Out Keeper keeper.Keeper - Module runtime.AppModuleWrapper + Module appmodule.AppModule BaseAppOption runtime.BaseAppOption } @@ -162,7 +170,7 @@ func ProvideModule(in ConsensusParamInputs) ConsensusParamOutputs { return ConsensusParamOutputs{ Keeper: k, - Module: runtime.WrapAppModule(m), + Module: m, BaseAppOption: baseappOpt, } } diff --git a/x/crisis/module.go b/x/crisis/module.go index 292fb0f24487..010cb061ee34 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -120,6 +120,14 @@ func NewAppModule(keeper *keeper.Keeper, skipGenesisInvariants bool, ss exported } } +var _ appmodule.AppModule = AppModule{} + +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. +func (am AppModule) IsOnePerModuleType() {} + +// IsAppModule implements the appmodule.AppModule interface. +func (am AppModule) IsAppModule() {} + // AddModuleInitFlags implements servertypes.ModuleInitFlags interface. func AddModuleInitFlags(startCmd *cobra.Command) { startCmd.Flags().Bool(FlagSkipGenesisInvariants, false, "Skip x/crisis invariants check on startup") @@ -201,7 +209,7 @@ type CrisisInputs struct { type CrisisOutputs struct { depinject.Out - Module runtime.AppModuleWrapper + Module appmodule.AppModule CrisisKeeper *keeper.Keeper } @@ -242,5 +250,5 @@ func ProvideModule(in CrisisInputs) CrisisOutputs { m := NewAppModule(k, skipGenesisInvariants, in.LegacySubspace) - return CrisisOutputs{CrisisKeeper: k, Module: runtime.WrapAppModule(m)} + return CrisisOutputs{CrisisKeeper: k, Module: m} } diff --git a/x/distribution/module.go b/x/distribution/module.go index 211c56d9cd85..4d1602d1201f 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -121,6 +121,14 @@ func NewAppModule( } } +var _ appmodule.AppModule = AppModule{} + +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. +func (am AppModule) IsOnePerModuleType() {} + +// IsAppModule implements the appmodule.AppModule interface. +func (am AppModule) IsAppModule() {} + // Name returns the distribution module's name. func (AppModule) Name() string { return types.ModuleName @@ -228,7 +236,7 @@ type DistrOutputs struct { depinject.Out DistrKeeper keeper.Keeper - Module runtime.AppModuleWrapper + Module appmodule.AppModule Hooks staking.StakingHooksWrapper } @@ -258,7 +266,7 @@ func ProvideModule(in DistrInputs) DistrOutputs { return DistrOutputs{ DistrKeeper: k, - Module: runtime.WrapAppModule(m), + Module: m, Hooks: staking.StakingHooksWrapper{StakingHooks: k.Hooks()}, } } diff --git a/x/evidence/module.go b/x/evidence/module.go index fdda380bd071..fe01af735b6c 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -123,6 +123,14 @@ func NewAppModule(keeper keeper.Keeper) AppModule { } } +var _ appmodule.AppModule = AppModule{} + +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. +func (am AppModule) IsOnePerModuleType() {} + +// IsAppModule implements the appmodule.AppModule interface. +func (am AppModule) IsAppModule() {} + // Name returns the evidence module's name. func (am AppModule) Name() string { return am.AppModuleBasic.Name() @@ -214,12 +222,12 @@ type EvidenceOutputs struct { depinject.Out EvidenceKeeper keeper.Keeper - Module runtime.AppModuleWrapper + Module appmodule.AppModule } func ProvideModule(in EvidenceInputs) EvidenceOutputs { k := keeper.NewKeeper(in.Cdc, in.Key, in.StakingKeeper, in.SlashingKeeper) m := NewAppModule(*k) - return EvidenceOutputs{EvidenceKeeper: *k, Module: runtime.WrapAppModule(m)} + return EvidenceOutputs{EvidenceKeeper: *k, Module: m} } diff --git a/x/feegrant/module/module.go b/x/feegrant/module/module.go index bf60e2e5bfb8..c588c0575bb2 100644 --- a/x/feegrant/module/module.go +++ b/x/feegrant/module/module.go @@ -14,6 +14,7 @@ import ( modulev1 "cosmossdk.io/api/cosmos/feegrant/module/v1" "cosmossdk.io/depinject" + sdkclient "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -128,6 +129,14 @@ func NewAppModule(cdc codec.Codec, ak feegrant.AccountKeeper, bk feegrant.BankKe } } +var _ appmodule.AppModule = AppModule{} + +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. +func (am AppModule) IsOnePerModuleType() {} + +// IsAppModule implements the appmodule.AppModule interface. +func (am AppModule) IsAppModule() {} + // Name returns the feegrant module's name. func (AppModule) Name() string { return feegrant.ModuleName @@ -192,10 +201,10 @@ type FeegrantInputs struct { Registry cdctypes.InterfaceRegistry } -func ProvideModule(in FeegrantInputs) (keeper.Keeper, runtime.AppModuleWrapper) { +func ProvideModule(in FeegrantInputs) (keeper.Keeper, appmodule.AppModule) { k := keeper.NewKeeper(in.Cdc, in.Key, in.AccountKeeper) m := NewAppModule(in.Cdc, in.AccountKeeper, in.BankKeeper, k, in.Registry) - return k, runtime.WrapAppModule(m) + return k, m } // AppModuleSimulation functions diff --git a/x/genutil/module.go b/x/genutil/module.go index 4fea22ca52c3..f9724c141179 100644 --- a/x/genutil/module.go +++ b/x/genutil/module.go @@ -12,6 +12,7 @@ import ( "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -98,6 +99,14 @@ func NewAppModule(accountKeeper types.AccountKeeper, }) } +var _ appmodule.AppModule = AppModule{} + +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. +func (AppModule) IsOnePerModuleType() {} + +// IsAppModule implements the appmodule.AppModule interface. +func (AppModule) IsAppModule() {} + // InitGenesis performs genesis initialization for the genutil module. func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { var genesisState types.GenesisState @@ -137,7 +146,7 @@ type GenutilInputs struct { Config client.TxConfig } -func ProvideModule(in GenutilInputs) runtime.AppModuleWrapper { +func ProvideModule(in GenutilInputs) appmodule.AppModule { m := NewAppModule(in.AccountKeeper, in.StakingKeeper, in.DeliverTx, in.Config) - return runtime.WrapAppModule(m) + return m } diff --git a/x/gov/module.go b/x/gov/module.go index e8b051c5bfbb..50c13c1cad66 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -17,6 +17,7 @@ import ( modulev1 "cosmossdk.io/api/cosmos/gov/module/v1" "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" @@ -147,6 +148,14 @@ func NewAppModule( } } +var _ appmodule.AppModule = AppModule{} + +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. +func (am AppModule) IsOnePerModuleType() {} + +// IsAppModule implements the appmodule.AppModule interface. +func (am AppModule) IsAppModule() {} + func init() { appmodule.Register( &modulev1.Module{}, @@ -178,7 +187,7 @@ type GovInputs struct { type GovOutputs struct { depinject.Out - Module runtime.AppModuleWrapper + Module appmodule.AppModule Keeper *keeper.Keeper HandlerRoute v1beta1.HandlerRoute } @@ -208,7 +217,7 @@ func ProvideModule(in GovInputs) GovOutputs { m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.BankKeeper, in.LegacySubspace) hr := v1beta1.HandlerRoute{Handler: v1beta1.ProposalHandler, RouteKey: govtypes.RouterKey} - return GovOutputs{Module: runtime.WrapAppModule(m), Keeper: k, HandlerRoute: hr} + return GovOutputs{Module: m, Keeper: k, HandlerRoute: hr} } func ProvideKeyTable() paramtypes.KeyTable { diff --git a/x/group/module/module.go b/x/group/module/module.go index 89fe103a6c44..a4f905f641a9 100644 --- a/x/group/module/module.go +++ b/x/group/module/module.go @@ -13,6 +13,7 @@ import ( modulev1 "cosmossdk.io/api/cosmos/group/module/v1" "cosmossdk.io/depinject" + "github.com/cosmos/cosmos-sdk/baseapp" sdkclient "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" @@ -53,6 +54,14 @@ func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak group.AccountKeeper, } } +var _ appmodule.AppModule = AppModule{} + +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. +func (am AppModule) IsOnePerModuleType() {} + +// IsAppModule implements the appmodule.AppModule interface. +func (am AppModule) IsAppModule() {} + type AppModuleBasic struct { cdc codec.Codec } @@ -211,7 +220,7 @@ type GroupOutputs struct { depinject.Out GroupKeeper keeper.Keeper - Module runtime.AppModuleWrapper + Module appmodule.AppModule } func ProvideModule(in GroupInputs) GroupOutputs { @@ -223,5 +232,5 @@ func ProvideModule(in GroupInputs) GroupOutputs { k := keeper.NewKeeper(in.Key, in.Cdc, in.MsgServiceRouter, in.AccountKeeper, group.Config{MaxExecutionPeriod: in.Config.MaxExecutionPeriod.AsDuration(), MaxMetadataLen: in.Config.MaxMetadataLen}) m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.BankKeeper, in.Registry) - return GroupOutputs{GroupKeeper: k, Module: runtime.WrapAppModule(m)} + return GroupOutputs{GroupKeeper: k, Module: m} } diff --git a/x/mint/module.go b/x/mint/module.go index 5724ef3787db..4cf4711fec07 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -13,6 +13,7 @@ import ( "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -129,6 +130,14 @@ func NewAppModule( } } +var _ appmodule.AppModule = AppModule{} + +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. +func (am AppModule) IsOnePerModuleType() {} + +// IsAppModule implements the appmodule.AppModule interface. +func (am AppModule) IsAppModule() {} + // Name returns the mint module's name. func (AppModule) Name() string { return types.ModuleName @@ -232,7 +241,7 @@ type MintOutputs struct { depinject.Out MintKeeper keeper.Keeper - Module runtime.AppModuleWrapper + Module appmodule.AppModule } func ProvideModule(in MintInputs) MintOutputs { @@ -260,5 +269,5 @@ func ProvideModule(in MintInputs) MintOutputs { // when no inflation calculation function is provided it will use the default types.DefaultInflationCalculationFn m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.InflationCalculationFn, in.LegacySubspace) - return MintOutputs{MintKeeper: k, Module: runtime.WrapAppModule(m)} + return MintOutputs{MintKeeper: k, Module: m} } diff --git a/x/nft/module/module.go b/x/nft/module/module.go index 9bbb20d1f437..bd85e71b4500 100644 --- a/x/nft/module/module.go +++ b/x/nft/module/module.go @@ -10,6 +10,7 @@ import ( "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" + sdkclient "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -21,6 +22,7 @@ import ( simtypes "github.com/cosmos/cosmos-sdk/types/simulation" modulev1 "cosmossdk.io/api/cosmos/nft/module/v1" + "github.com/cosmos/cosmos-sdk/x/nft" "github.com/cosmos/cosmos-sdk/x/nft/client/cli" "github.com/cosmos/cosmos-sdk/x/nft/keeper" @@ -112,6 +114,14 @@ func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak nft.AccountKeeper, b } } +var _ appmodule.AppModule = AppModule{} + +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. +func (am AppModule) IsOnePerModuleType() {} + +// IsAppModule implements the appmodule.AppModule interface. +func (am AppModule) IsAppModule() {} + // Name returns the nft module's name. func (AppModule) Name() string { return nft.ModuleName @@ -201,12 +211,12 @@ type NftOutputs struct { depinject.Out NFTKeeper keeper.Keeper - Module runtime.AppModuleWrapper + Module appmodule.AppModule } func ProvideModule(in NftInputs) NftOutputs { k := keeper.NewKeeper(in.Key, in.Cdc, in.AccountKeeper, in.BankKeeper) m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.BankKeeper, in.Registry) - return NftOutputs{NFTKeeper: k, Module: runtime.WrapAppModule(m)} + return NftOutputs{NFTKeeper: k, Module: m} } diff --git a/x/params/module.go b/x/params/module.go index d0a3a3a0c4da..96ea866c8728 100644 --- a/x/params/module.go +++ b/x/params/module.go @@ -13,6 +13,7 @@ import ( modulev1 "cosmossdk.io/api/cosmos/params/module/v1" "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" + "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/client" @@ -90,6 +91,14 @@ func NewAppModule(k keeper.Keeper) AppModule { } } +var _ appmodule.AppModule = AppModule{} + +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. +func (am AppModule) IsOnePerModuleType() {} + +// IsAppModule implements the appmodule.AppModule interface. +func (am AppModule) IsAppModule() {} + func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} // InitGenesis performs a no-op. @@ -158,14 +167,14 @@ type ParamsOutputs struct { depinject.Out ParamsKeeper keeper.Keeper - Module runtime.AppModuleWrapper + Module appmodule.AppModule GovHandler govv1beta1.HandlerRoute } func ProvideModule(in ParamsInputs) ParamsOutputs { k := keeper.NewKeeper(in.Cdc, in.LegacyAmino, in.KvStoreKey, in.TransientStoreKey) - m := runtime.WrapAppModule(NewAppModule(k)) + m := NewAppModule(k) govHandler := govv1beta1.HandlerRoute{RouteKey: proposal.RouterKey, Handler: NewParamChangeProposalHandler(k)} return ParamsOutputs{ParamsKeeper: k, Module: m, GovHandler: govHandler} diff --git a/x/slashing/module.go b/x/slashing/module.go index 80fe2828d396..63b8b05e5c05 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -120,6 +120,14 @@ func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak types.AccountKeeper, } } +var _ appmodule.AppModule = AppModule{} + +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. +func (am AppModule) IsOnePerModuleType() {} + +// IsAppModule implements the appmodule.AppModule interface. +func (am AppModule) IsAppModule() {} + // Name returns the slashing module's name. func (AppModule) Name() string { return types.ModuleName @@ -230,7 +238,7 @@ type SlashingOutputs struct { depinject.Out Keeper keeper.Keeper - Module runtime.AppModuleWrapper + Module appmodule.AppModule Hooks staking.StakingHooksWrapper } @@ -245,7 +253,7 @@ func ProvideModule(in SlashingInputs) SlashingOutputs { m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.BankKeeper, in.StakingKeeper, in.LegacySubspace) return SlashingOutputs{ Keeper: k, - Module: runtime.WrapAppModule(m), + Module: m, Hooks: staking.StakingHooksWrapper{StakingHooks: k.Hooks()}, } } diff --git a/x/staking/module.go b/x/staking/module.go index 9b89afa21d8e..356c4c50eae7 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -128,6 +128,14 @@ func NewAppModule( } } +var _ appmodule.AppModule = AppModule{} + +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. +func (am AppModule) IsOnePerModuleType() {} + +// IsAppModule implements the appmodule.AppModule interface. +func (am AppModule) IsAppModule() {} + // Name returns the staking module's name. func (AppModule) Name() string { return types.ModuleName @@ -215,7 +223,7 @@ type StakingOutputs struct { depinject.Out StakingKeeper *keeper.Keeper - Module runtime.AppModuleWrapper + Module appmodule.AppModule } func ProvideModule(in StakingInputs) StakingOutputs { @@ -233,7 +241,7 @@ func ProvideModule(in StakingInputs) StakingOutputs { authority.String(), ) m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.BankKeeper, in.LegacySubspace) - return StakingOutputs{StakingKeeper: k, Module: runtime.WrapAppModule(m)} + return StakingOutputs{StakingKeeper: k, Module: m} } func InvokeSetStakingHooks( diff --git a/x/upgrade/module.go b/x/upgrade/module.go index 505214ac8e36..203e723edc4a 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -14,6 +14,7 @@ import ( "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" @@ -28,6 +29,7 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" modulev1 "cosmossdk.io/api/cosmos/upgrade/module/v1" + "github.com/cosmos/cosmos-sdk/x/upgrade/client/cli" "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" "github.com/cosmos/cosmos-sdk/x/upgrade/types" @@ -94,6 +96,14 @@ func NewAppModule(keeper keeper.Keeper) AppModule { } } +var _ appmodule.AppModule = AppModule{} + +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. +func (am AppModule) IsOnePerModuleType() {} + +// IsAppModule implements the appmodule.AppModule interface. +func (am AppModule) IsAppModule() {} + // RegisterInvariants does nothing, there are no invariants to enforce func (AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} @@ -167,7 +177,7 @@ type UpgradeOutputs struct { depinject.Out UpgradeKeeper keeper.Keeper - Module runtime.AppModuleWrapper + Module appmodule.AppModule GovHandler govv1beta1.HandlerRoute } @@ -196,5 +206,5 @@ func ProvideModule(in UpgradeInputs) UpgradeOutputs { m := NewAppModule(k) gh := govv1beta1.HandlerRoute{RouteKey: types.RouterKey, Handler: NewSoftwareUpgradeProposalHandler(k)} - return UpgradeOutputs{UpgradeKeeper: k, Module: runtime.WrapAppModule(m), GovHandler: gh} + return UpgradeOutputs{UpgradeKeeper: k, Module: m, GovHandler: gh} } From 1ceb653f0c4652533f6d5ae098afac01c44f70d7 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 8 Nov 2022 10:50:29 -0500 Subject: [PATCH 02/19] fix build errors --- runtime/module.go | 7 ++----- runtime/services/autocli.go | 5 ++--- types/module/module.go | 8 ++++---- types/module/simulation.go | 4 +++- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/runtime/module.go b/runtime/module.go index cff6092a822e..3a9a5e7caf68 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -81,15 +81,12 @@ type AppInputs struct { AppConfig *appv1alpha1.Config Config *runtimev1alpha1.Module AppBuilder *AppBuilder - Modules map[string]AppModuleWrapper + Modules map[string]appmodule.AppModule BaseAppOptions []BaseAppOption } func SetupAppBuilder(inputs AppInputs) { - mm := &module.Manager{Modules: map[string]module.AppModule{}} - for name, wrapper := range inputs.Modules { - mm.Modules[name] = wrapper.AppModule - } + mm := module.NewManagerFromMap(inputs.Modules) app := inputs.AppBuilder.app app.baseAppOptions = inputs.BaseAppOptions app.config = inputs.Config diff --git a/runtime/services/autocli.go b/runtime/services/autocli.go index 5f684e550627..65b2ee550e1e 100644 --- a/runtime/services/autocli.go +++ b/runtime/services/autocli.go @@ -4,8 +4,7 @@ import ( "context" autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" - - "github.com/cosmos/cosmos-sdk/types/module" + "cosmossdk.io/core/appmodule" ) // AutoCLIQueryService implements the cosmos.autocli.v1.Query service. @@ -15,7 +14,7 @@ type AutoCLIQueryService struct { moduleOptions map[string]*autocliv1.ModuleOptions } -func NewAutoCLIQueryService(appModules map[string]module.AppModule) *AutoCLIQueryService { +func NewAutoCLIQueryService(appModules map[string]appmodule.AppModule) *AutoCLIQueryService { moduleOptions := map[string]*autocliv1.ModuleOptions{} for modName, mod := range appModules { if autoCliMod, ok := mod.(interface { diff --git a/types/module/module.go b/types/module/module.go index 588904a42a55..e438471191c6 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -60,6 +60,9 @@ type AppModuleBasic interface { GetQueryCmd() *cobra.Command } +// HasName allows the module to provide its own name for legacy purposes. +// Newer apps should specify the name for their modules using a map +// (see NewManagerFromMap). type HasName interface { Name() string } @@ -167,10 +170,7 @@ type HasGenesis interface { type AppModule interface { appmodule.AppModule - // HasName allows the module to provide its own name for legacy purposes. - // Newer apps should specify the name for their modules using a map - // (see NewManagerFromMap). - HasName + AppModuleBasic } type HasRegisterInvariants interface { diff --git a/types/module/simulation.go b/types/module/simulation.go index 28f9b3b1cce8..bc4dd3df6c53 100644 --- a/types/module/simulation.go +++ b/types/module/simulation.go @@ -6,7 +6,9 @@ import ( "sort" "time" + "cosmossdk.io/core/appmodule" sdkmath "cosmossdk.io/math" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/simulation" @@ -51,7 +53,7 @@ func NewSimulationManager(modules ...AppModuleSimulation) *SimulationManager { // with the same moduleName. // Then it attempts to cast every provided AppModule into an AppModuleSimulation. // If the cast succeeds, its included, otherwise it is excluded. -func NewSimulationManagerFromAppModules(modules map[string]AppModule, overrideModules map[string]AppModuleSimulation) *SimulationManager { +func NewSimulationManagerFromAppModules(modules map[string]appmodule.AppModule, overrideModules map[string]AppModuleSimulation) *SimulationManager { simModules := []AppModuleSimulation{} appModuleNamesSorted := make([]string, 0, len(modules)) for moduleName := range modules { From 251500d1f765a472d66c2f4137ecd384d9ae1c1d Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 8 Nov 2022 13:46:53 -0500 Subject: [PATCH 03/19] docs --- types/module/module.go | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/types/module/module.go b/types/module/module.go index e438471191c6..fb9b808c67e9 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -52,7 +52,7 @@ type AppModuleBasic interface { RegisterLegacyAminoCodec(*codec.LegacyAmino) RegisterInterfaces(codectypes.InterfaceRegistry) - HasGenesisBasics + LegacyGenesisBasics // client functionality RegisterGRPCGatewayRoutes(client.Context, *runtime.ServeMux) @@ -67,7 +67,8 @@ type HasName interface { Name() string } -type HasGenesisBasics interface { +// LegacyGenesisBasics is the legacy interface for stateless genesis methods. +type LegacyGenesisBasics interface { DefaultGenesis(codec.JSONCodec) json.RawMessage ValidateGenesis(codec.JSONCodec, client.TxEncodingConfig, json.RawMessage) error } @@ -155,11 +156,12 @@ func (bm BasicManager) AddQueryCommands(rootQueryCmd *cobra.Command) { // AppModuleGenesis is the standard form for an application module genesis functions type AppModuleGenesis interface { AppModuleBasic - HasGenesis + LegacyGenesis } -type HasGenesis interface { - HasGenesisBasics +// LegacyGenesis is the legacy interface for stateful genesis methods. +type LegacyGenesis interface { + LegacyGenesisBasics InitGenesis(sdk.Context, codec.JSONCodec, json.RawMessage) []abci.ValidatorUpdate ExportGenesis(sdk.Context, codec.JSONCodec) json.RawMessage } @@ -173,16 +175,19 @@ type AppModule interface { AppModuleBasic } +// HasRegisterInvariants is the interface for registering invariants. type HasRegisterInvariants interface { - // registers + // RegisterInvariants registers module invariants. RegisterInvariants(sdk.InvariantRegistry) } -type HasRegisterServices interface { - // RegisterServices allows a module to register services +// LegacyRegisterServices is the legacy method for modules to register services. +type LegacyRegisterServices interface { + // RegisterServices allows a module to register services. RegisterServices(Configurator) } +// HasConsensusVersion is the interface for declaring a module consensus version. type HasConsensusVersion interface { // ConsensusVersion is a sequence number for state-breaking change of the // module. It should be incremented on each consensus-breaking change @@ -252,7 +257,8 @@ type Manager struct { OrderMigrations []string } -// Deprecated: NewManager creates a new Manager object +// Deprecated: NewManager creates a new Manager object. NewManagerFromMap should +// be preferred. func NewManager(modules ...AppModule) *Manager { moduleMap := make(map[string]appmodule.AppModule) modulesStr := make([]string, 0, len(modules)) @@ -270,7 +276,8 @@ func NewManager(modules ...AppModule) *Manager { } } -// NewManager creates a new Manager object +// NewManagerFromMap creates a new Manager object from a map of modules. It +// should be used instead of NewManager for new apps. func NewManagerFromMap(moduleMap map[string]appmodule.AppModule) *Manager { modulesStr := make([]string, 0, len(moduleMap)) for name := range moduleMap { @@ -331,7 +338,7 @@ func (m *Manager) RegisterInvariants(ir sdk.InvariantRegistry) { func (m *Manager) RegisterServices(cfg Configurator) { modules := maps.Values(m.Modules) for _, module := range modules { - if module, ok := module.(HasRegisterServices); ok { + if module, ok := module.(LegacyRegisterServices); ok { module.RegisterServices(cfg) } } @@ -348,7 +355,7 @@ func (m *Manager) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, genesisData continue } - if module, ok := m.Modules[moduleName].(HasGenesis); ok { + if module, ok := m.Modules[moduleName].(LegacyGenesis); ok { ctx.Logger().Debug("running initialization for module", "module", moduleName) moduleValUpdates := module.InitGenesis(ctx, cdc, genesisData[moduleName]) @@ -384,7 +391,7 @@ func (m *Manager) ExportGenesisForModules(ctx sdk.Context, cdc codec.JSONCodec, genesisData := make(map[string]json.RawMessage) if len(modulesToExport) == 0 { for _, moduleName := range m.OrderExportGenesis { - if module, ok := m.Modules[moduleName].(HasGenesis); ok { + if module, ok := m.Modules[moduleName].(LegacyGenesis); ok { genesisData[moduleName] = module.ExportGenesis(ctx, cdc) } } @@ -398,7 +405,7 @@ func (m *Manager) ExportGenesisForModules(ctx sdk.Context, cdc codec.JSONCodec, } for _, moduleName := range modulesToExport { - if module, ok := m.Modules[moduleName].(HasGenesis); ok { + if module, ok := m.Modules[moduleName].(LegacyGenesis); ok { genesisData[moduleName] = module.ExportGenesis(ctx, cdc) } } @@ -529,7 +536,7 @@ func (m Manager) RunMigrations(ctx sdk.Context, cfg Configurator, fromVM Version } } else { ctx.Logger().Info(fmt.Sprintf("adding a new module: %s", moduleName)) - if module, ok := m.Modules[moduleName].(HasGenesis); ok { + if module, ok := m.Modules[moduleName].(LegacyGenesis); ok { moduleValUpdates := module.InitGenesis(ctx, c.cdc, module.DefaultGenesis(c.cdc)) // The module manager assumes only one module will update the // validator set, and it can't be a new module. From f05222af63cb5cdb1b7b2eeac209054e4e3d3bcf Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 8 Nov 2022 14:08:57 -0500 Subject: [PATCH 04/19] test fixes --- simapp/app_test.go | 14 +- testutil/mock/types_module_module.go | 502 +++++++++++++++++---------- 2 files changed, 333 insertions(+), 183 deletions(-) diff --git a/simapp/app_test.go b/simapp/app_test.go index af92cbe077a0..f8483a64e155 100644 --- a/simapp/app_test.go +++ b/simapp/app_test.go @@ -81,12 +81,14 @@ func TestRunMigrations(t *testing.T) { // // The loop below is the same as calling `RegisterServices` on // ModuleManager, except that we skip x/bank. - for _, module := range app.ModuleManager.Modules { - if module.Name() == banktypes.ModuleName { + for name, mod := range app.ModuleManager.Modules { + if name == banktypes.ModuleName { continue } - module.RegisterServices(configurator) + if mod, ok := mod.(module.LegacyRegisterServices); ok { + mod.RegisterServices(configurator) + } } // Initialize the chain @@ -209,8 +211,6 @@ func TestInitGenesisOnMigration(t *testing.T) { mockModule := mock.NewMockAppModule(mockCtrl) mockDefaultGenesis := json.RawMessage(`{"key": "value"}`) mockModule.EXPECT().DefaultGenesis(gomock.Eq(app.appCodec)).Times(1).Return(mockDefaultGenesis) - mockModule.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(app.appCodec), gomock.Eq(mockDefaultGenesis)).Times(1).Return(nil) - mockModule.EXPECT().ConsensusVersion().Times(1).Return(uint64(0)) app.ModuleManager.Modules["mock"] = mockModule @@ -252,7 +252,9 @@ func TestUpgradeStateOnGenesis(t *testing.T) { ctx := app.NewContext(false, tmproto.Header{}) vm := app.UpgradeKeeper.GetModuleVersionMap(ctx) for v, i := range app.ModuleManager.Modules { - require.Equal(t, vm[v], i.ConsensusVersion()) + if i, ok := i.(module.HasConsensusVersion); ok { + require.Equal(t, vm[v], i.ConsensusVersion()) + } } require.NotNil(t, app.UpgradeKeeper.GetVersionSetter()) diff --git a/testutil/mock/types_module_module.go b/testutil/mock/types_module_module.go index ab7ff4299ac4..0c6b1b434d18 100644 --- a/testutil/mock/types_module_module.go +++ b/testutil/mock/types_module_module.go @@ -148,6 +148,94 @@ func (mr *MockAppModuleBasicMockRecorder) ValidateGenesis(arg0, arg1, arg2 inter return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesis", reflect.TypeOf((*MockAppModuleBasic)(nil).ValidateGenesis), arg0, arg1, arg2) } +// MockHasName is a mock of HasName interface. +type MockHasName struct { + ctrl *gomock.Controller + recorder *MockHasNameMockRecorder +} + +// MockHasNameMockRecorder is the mock recorder for MockHasName. +type MockHasNameMockRecorder struct { + mock *MockHasName +} + +// NewMockHasName creates a new mock instance. +func NewMockHasName(ctrl *gomock.Controller) *MockHasName { + mock := &MockHasName{ctrl: ctrl} + mock.recorder = &MockHasNameMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockHasName) EXPECT() *MockHasNameMockRecorder { + return m.recorder +} + +// Name mocks base method. +func (m *MockHasName) Name() string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Name") + ret0, _ := ret[0].(string) + return ret0 +} + +// Name indicates an expected call of Name. +func (mr *MockHasNameMockRecorder) Name() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockHasName)(nil).Name)) +} + +// MockLegacyGenesisBasics is a mock of LegacyGenesisBasics interface. +type MockLegacyGenesisBasics struct { + ctrl *gomock.Controller + recorder *MockLegacyGenesisBasicsMockRecorder +} + +// MockLegacyGenesisBasicsMockRecorder is the mock recorder for MockLegacyGenesisBasics. +type MockLegacyGenesisBasicsMockRecorder struct { + mock *MockLegacyGenesisBasics +} + +// NewMockLegacyGenesisBasics creates a new mock instance. +func NewMockLegacyGenesisBasics(ctrl *gomock.Controller) *MockLegacyGenesisBasics { + mock := &MockLegacyGenesisBasics{ctrl: ctrl} + mock.recorder = &MockLegacyGenesisBasicsMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockLegacyGenesisBasics) EXPECT() *MockLegacyGenesisBasicsMockRecorder { + return m.recorder +} + +// DefaultGenesis mocks base method. +func (m *MockLegacyGenesisBasics) DefaultGenesis(arg0 codec.JSONCodec) json.RawMessage { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DefaultGenesis", arg0) + ret0, _ := ret[0].(json.RawMessage) + return ret0 +} + +// DefaultGenesis indicates an expected call of DefaultGenesis. +func (mr *MockLegacyGenesisBasicsMockRecorder) DefaultGenesis(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DefaultGenesis", reflect.TypeOf((*MockLegacyGenesisBasics)(nil).DefaultGenesis), arg0) +} + +// ValidateGenesis mocks base method. +func (m *MockLegacyGenesisBasics) ValidateGenesis(arg0 codec.JSONCodec, arg1 client.TxEncodingConfig, arg2 json.RawMessage) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ValidateGenesis", arg0, arg1, arg2) + ret0, _ := ret[0].(error) + return ret0 +} + +// ValidateGenesis indicates an expected call of ValidateGenesis. +func (mr *MockLegacyGenesisBasicsMockRecorder) ValidateGenesis(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesis", reflect.TypeOf((*MockLegacyGenesisBasics)(nil).ValidateGenesis), arg0, arg1, arg2) +} + // MockAppModuleGenesis is a mock of AppModuleGenesis interface. type MockAppModuleGenesis struct { ctrl *gomock.Controller @@ -305,6 +393,85 @@ func (mr *MockAppModuleGenesisMockRecorder) ValidateGenesis(arg0, arg1, arg2 int return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesis", reflect.TypeOf((*MockAppModuleGenesis)(nil).ValidateGenesis), arg0, arg1, arg2) } +// MockLegacyGenesis is a mock of LegacyGenesis interface. +type MockLegacyGenesis struct { + ctrl *gomock.Controller + recorder *MockLegacyGenesisMockRecorder +} + +// MockLegacyGenesisMockRecorder is the mock recorder for MockLegacyGenesis. +type MockLegacyGenesisMockRecorder struct { + mock *MockLegacyGenesis +} + +// NewMockLegacyGenesis creates a new mock instance. +func NewMockLegacyGenesis(ctrl *gomock.Controller) *MockLegacyGenesis { + mock := &MockLegacyGenesis{ctrl: ctrl} + mock.recorder = &MockLegacyGenesisMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockLegacyGenesis) EXPECT() *MockLegacyGenesisMockRecorder { + return m.recorder +} + +// DefaultGenesis mocks base method. +func (m *MockLegacyGenesis) DefaultGenesis(arg0 codec.JSONCodec) json.RawMessage { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DefaultGenesis", arg0) + ret0, _ := ret[0].(json.RawMessage) + return ret0 +} + +// DefaultGenesis indicates an expected call of DefaultGenesis. +func (mr *MockLegacyGenesisMockRecorder) DefaultGenesis(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DefaultGenesis", reflect.TypeOf((*MockLegacyGenesis)(nil).DefaultGenesis), arg0) +} + +// ExportGenesis mocks base method. +func (m *MockLegacyGenesis) ExportGenesis(arg0 types0.Context, arg1 codec.JSONCodec) json.RawMessage { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ExportGenesis", arg0, arg1) + ret0, _ := ret[0].(json.RawMessage) + return ret0 +} + +// ExportGenesis indicates an expected call of ExportGenesis. +func (mr *MockLegacyGenesisMockRecorder) ExportGenesis(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExportGenesis", reflect.TypeOf((*MockLegacyGenesis)(nil).ExportGenesis), arg0, arg1) +} + +// InitGenesis mocks base method. +func (m *MockLegacyGenesis) InitGenesis(arg0 types0.Context, arg1 codec.JSONCodec, arg2 json.RawMessage) []types1.ValidatorUpdate { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "InitGenesis", arg0, arg1, arg2) + ret0, _ := ret[0].([]types1.ValidatorUpdate) + return ret0 +} + +// InitGenesis indicates an expected call of InitGenesis. +func (mr *MockLegacyGenesisMockRecorder) InitGenesis(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InitGenesis", reflect.TypeOf((*MockLegacyGenesis)(nil).InitGenesis), arg0, arg1, arg2) +} + +// ValidateGenesis mocks base method. +func (m *MockLegacyGenesis) ValidateGenesis(arg0 codec.JSONCodec, arg1 client.TxEncodingConfig, arg2 json.RawMessage) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ValidateGenesis", arg0, arg1, arg2) + ret0, _ := ret[0].(error) + return ret0 +} + +// ValidateGenesis indicates an expected call of ValidateGenesis. +func (mr *MockLegacyGenesisMockRecorder) ValidateGenesis(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesis", reflect.TypeOf((*MockLegacyGenesis)(nil).ValidateGenesis), arg0, arg1, arg2) +} + // MockAppModule is a mock of AppModule interface. type MockAppModule struct { ctrl *gomock.Controller @@ -328,20 +495,6 @@ func (m *MockAppModule) EXPECT() *MockAppModuleMockRecorder { return m.recorder } -// ConsensusVersion mocks base method. -func (m *MockAppModule) ConsensusVersion() uint64 { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ConsensusVersion") - ret0, _ := ret[0].(uint64) - return ret0 -} - -// ConsensusVersion indicates an expected call of ConsensusVersion. -func (mr *MockAppModuleMockRecorder) ConsensusVersion() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConsensusVersion", reflect.TypeOf((*MockAppModule)(nil).ConsensusVersion)) -} - // DefaultGenesis mocks base method. func (m *MockAppModule) DefaultGenesis(arg0 codec.JSONCodec) json.RawMessage { m.ctrl.T.Helper() @@ -356,20 +509,6 @@ func (mr *MockAppModuleMockRecorder) DefaultGenesis(arg0 interface{}) *gomock.Ca return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DefaultGenesis", reflect.TypeOf((*MockAppModule)(nil).DefaultGenesis), arg0) } -// ExportGenesis mocks base method. -func (m *MockAppModule) ExportGenesis(arg0 types0.Context, arg1 codec.JSONCodec) json.RawMessage { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ExportGenesis", arg0, arg1) - ret0, _ := ret[0].(json.RawMessage) - return ret0 -} - -// ExportGenesis indicates an expected call of ExportGenesis. -func (mr *MockAppModuleMockRecorder) ExportGenesis(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExportGenesis", reflect.TypeOf((*MockAppModule)(nil).ExportGenesis), arg0, arg1) -} - // GetQueryCmd mocks base method. func (m *MockAppModule) GetQueryCmd() *cobra.Command { m.ctrl.T.Helper() @@ -398,18 +537,28 @@ func (mr *MockAppModuleMockRecorder) GetTxCmd() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTxCmd", reflect.TypeOf((*MockAppModule)(nil).GetTxCmd)) } -// InitGenesis mocks base method. -func (m *MockAppModule) InitGenesis(arg0 types0.Context, arg1 codec.JSONCodec, arg2 json.RawMessage) []types1.ValidatorUpdate { +// IsAppModule mocks base method. +func (m *MockAppModule) IsAppModule() { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "InitGenesis", arg0, arg1, arg2) - ret0, _ := ret[0].([]types1.ValidatorUpdate) - return ret0 + m.ctrl.Call(m, "IsAppModule") } -// InitGenesis indicates an expected call of InitGenesis. -func (mr *MockAppModuleMockRecorder) InitGenesis(arg0, arg1, arg2 interface{}) *gomock.Call { +// IsAppModule indicates an expected call of IsAppModule. +func (mr *MockAppModuleMockRecorder) IsAppModule() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsAppModule", reflect.TypeOf((*MockAppModule)(nil).IsAppModule)) +} + +// IsOnePerModuleType mocks base method. +func (m *MockAppModule) IsOnePerModuleType() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "IsOnePerModuleType") +} + +// IsOnePerModuleType indicates an expected call of IsOnePerModuleType. +func (mr *MockAppModuleMockRecorder) IsOnePerModuleType() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InitGenesis", reflect.TypeOf((*MockAppModule)(nil).InitGenesis), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsOnePerModuleType", reflect.TypeOf((*MockAppModule)(nil).IsOnePerModuleType)) } // Name mocks base method. @@ -450,54 +599,137 @@ func (mr *MockAppModuleMockRecorder) RegisterInterfaces(arg0 interface{}) *gomoc return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInterfaces", reflect.TypeOf((*MockAppModule)(nil).RegisterInterfaces), arg0) } +// RegisterLegacyAminoCodec mocks base method. +func (m *MockAppModule) RegisterLegacyAminoCodec(arg0 *codec.LegacyAmino) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterLegacyAminoCodec", arg0) +} + +// RegisterLegacyAminoCodec indicates an expected call of RegisterLegacyAminoCodec. +func (mr *MockAppModuleMockRecorder) RegisterLegacyAminoCodec(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterLegacyAminoCodec", reflect.TypeOf((*MockAppModule)(nil).RegisterLegacyAminoCodec), arg0) +} + +// ValidateGenesis mocks base method. +func (m *MockAppModule) ValidateGenesis(arg0 codec.JSONCodec, arg1 client.TxEncodingConfig, arg2 json.RawMessage) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ValidateGenesis", arg0, arg1, arg2) + ret0, _ := ret[0].(error) + return ret0 +} + +// ValidateGenesis indicates an expected call of ValidateGenesis. +func (mr *MockAppModuleMockRecorder) ValidateGenesis(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesis", reflect.TypeOf((*MockAppModule)(nil).ValidateGenesis), arg0, arg1, arg2) +} + +// MockHasRegisterInvariants is a mock of HasRegisterInvariants interface. +type MockHasRegisterInvariants struct { + ctrl *gomock.Controller + recorder *MockHasRegisterInvariantsMockRecorder +} + +// MockHasRegisterInvariantsMockRecorder is the mock recorder for MockHasRegisterInvariants. +type MockHasRegisterInvariantsMockRecorder struct { + mock *MockHasRegisterInvariants +} + +// NewMockHasRegisterInvariants creates a new mock instance. +func NewMockHasRegisterInvariants(ctrl *gomock.Controller) *MockHasRegisterInvariants { + mock := &MockHasRegisterInvariants{ctrl: ctrl} + mock.recorder = &MockHasRegisterInvariantsMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockHasRegisterInvariants) EXPECT() *MockHasRegisterInvariantsMockRecorder { + return m.recorder +} + // RegisterInvariants mocks base method. -func (m *MockAppModule) RegisterInvariants(arg0 types0.InvariantRegistry) { +func (m *MockHasRegisterInvariants) RegisterInvariants(arg0 types0.InvariantRegistry) { m.ctrl.T.Helper() m.ctrl.Call(m, "RegisterInvariants", arg0) } // RegisterInvariants indicates an expected call of RegisterInvariants. -func (mr *MockAppModuleMockRecorder) RegisterInvariants(arg0 interface{}) *gomock.Call { +func (mr *MockHasRegisterInvariantsMockRecorder) RegisterInvariants(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInvariants", reflect.TypeOf((*MockAppModule)(nil).RegisterInvariants), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInvariants", reflect.TypeOf((*MockHasRegisterInvariants)(nil).RegisterInvariants), arg0) } -// RegisterLegacyAminoCodec mocks base method. -func (m *MockAppModule) RegisterLegacyAminoCodec(arg0 *codec.LegacyAmino) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "RegisterLegacyAminoCodec", arg0) +// MockLegacyRegisterServices is a mock of LegacyRegisterServices interface. +type MockLegacyRegisterServices struct { + ctrl *gomock.Controller + recorder *MockLegacyRegisterServicesMockRecorder } -// RegisterLegacyAminoCodec indicates an expected call of RegisterLegacyAminoCodec. -func (mr *MockAppModuleMockRecorder) RegisterLegacyAminoCodec(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterLegacyAminoCodec", reflect.TypeOf((*MockAppModule)(nil).RegisterLegacyAminoCodec), arg0) +// MockLegacyRegisterServicesMockRecorder is the mock recorder for MockLegacyRegisterServices. +type MockLegacyRegisterServicesMockRecorder struct { + mock *MockLegacyRegisterServices +} + +// NewMockLegacyRegisterServices creates a new mock instance. +func NewMockLegacyRegisterServices(ctrl *gomock.Controller) *MockLegacyRegisterServices { + mock := &MockLegacyRegisterServices{ctrl: ctrl} + mock.recorder = &MockLegacyRegisterServicesMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockLegacyRegisterServices) EXPECT() *MockLegacyRegisterServicesMockRecorder { + return m.recorder } // RegisterServices mocks base method. -func (m *MockAppModule) RegisterServices(arg0 module.Configurator) { +func (m *MockLegacyRegisterServices) RegisterServices(arg0 module.Configurator) { m.ctrl.T.Helper() m.ctrl.Call(m, "RegisterServices", arg0) } // RegisterServices indicates an expected call of RegisterServices. -func (mr *MockAppModuleMockRecorder) RegisterServices(arg0 interface{}) *gomock.Call { +func (mr *MockLegacyRegisterServicesMockRecorder) RegisterServices(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterServices", reflect.TypeOf((*MockAppModule)(nil).RegisterServices), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterServices", reflect.TypeOf((*MockLegacyRegisterServices)(nil).RegisterServices), arg0) } -// ValidateGenesis mocks base method. -func (m *MockAppModule) ValidateGenesis(arg0 codec.JSONCodec, arg1 client.TxEncodingConfig, arg2 json.RawMessage) error { +// MockHasConsensusVersion is a mock of HasConsensusVersion interface. +type MockHasConsensusVersion struct { + ctrl *gomock.Controller + recorder *MockHasConsensusVersionMockRecorder +} + +// MockHasConsensusVersionMockRecorder is the mock recorder for MockHasConsensusVersion. +type MockHasConsensusVersionMockRecorder struct { + mock *MockHasConsensusVersion +} + +// NewMockHasConsensusVersion creates a new mock instance. +func NewMockHasConsensusVersion(ctrl *gomock.Controller) *MockHasConsensusVersion { + mock := &MockHasConsensusVersion{ctrl: ctrl} + mock.recorder = &MockHasConsensusVersionMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockHasConsensusVersion) EXPECT() *MockHasConsensusVersionMockRecorder { + return m.recorder +} + +// ConsensusVersion mocks base method. +func (m *MockHasConsensusVersion) ConsensusVersion() uint64 { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ValidateGenesis", arg0, arg1, arg2) - ret0, _ := ret[0].(error) + ret := m.ctrl.Call(m, "ConsensusVersion") + ret0, _ := ret[0].(uint64) return ret0 } -// ValidateGenesis indicates an expected call of ValidateGenesis. -func (mr *MockAppModuleMockRecorder) ValidateGenesis(arg0, arg1, arg2 interface{}) *gomock.Call { +// ConsensusVersion indicates an expected call of ConsensusVersion. +func (mr *MockHasConsensusVersionMockRecorder) ConsensusVersion() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesis", reflect.TypeOf((*MockAppModule)(nil).ValidateGenesis), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConsensusVersion", reflect.TypeOf((*MockHasConsensusVersion)(nil).ConsensusVersion)) } // MockBeginBlockAppModule is a mock of BeginBlockAppModule interface. @@ -535,20 +767,6 @@ func (mr *MockBeginBlockAppModuleMockRecorder) BeginBlock(arg0, arg1 interface{} return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BeginBlock", reflect.TypeOf((*MockBeginBlockAppModule)(nil).BeginBlock), arg0, arg1) } -// ConsensusVersion mocks base method. -func (m *MockBeginBlockAppModule) ConsensusVersion() uint64 { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ConsensusVersion") - ret0, _ := ret[0].(uint64) - return ret0 -} - -// ConsensusVersion indicates an expected call of ConsensusVersion. -func (mr *MockBeginBlockAppModuleMockRecorder) ConsensusVersion() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConsensusVersion", reflect.TypeOf((*MockBeginBlockAppModule)(nil).ConsensusVersion)) -} - // DefaultGenesis mocks base method. func (m *MockBeginBlockAppModule) DefaultGenesis(arg0 codec.JSONCodec) json.RawMessage { m.ctrl.T.Helper() @@ -563,20 +781,6 @@ func (mr *MockBeginBlockAppModuleMockRecorder) DefaultGenesis(arg0 interface{}) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DefaultGenesis", reflect.TypeOf((*MockBeginBlockAppModule)(nil).DefaultGenesis), arg0) } -// ExportGenesis mocks base method. -func (m *MockBeginBlockAppModule) ExportGenesis(arg0 types0.Context, arg1 codec.JSONCodec) json.RawMessage { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ExportGenesis", arg0, arg1) - ret0, _ := ret[0].(json.RawMessage) - return ret0 -} - -// ExportGenesis indicates an expected call of ExportGenesis. -func (mr *MockBeginBlockAppModuleMockRecorder) ExportGenesis(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExportGenesis", reflect.TypeOf((*MockBeginBlockAppModule)(nil).ExportGenesis), arg0, arg1) -} - // GetQueryCmd mocks base method. func (m *MockBeginBlockAppModule) GetQueryCmd() *cobra.Command { m.ctrl.T.Helper() @@ -605,18 +809,28 @@ func (mr *MockBeginBlockAppModuleMockRecorder) GetTxCmd() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTxCmd", reflect.TypeOf((*MockBeginBlockAppModule)(nil).GetTxCmd)) } -// InitGenesis mocks base method. -func (m *MockBeginBlockAppModule) InitGenesis(arg0 types0.Context, arg1 codec.JSONCodec, arg2 json.RawMessage) []types1.ValidatorUpdate { +// IsAppModule mocks base method. +func (m *MockBeginBlockAppModule) IsAppModule() { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "InitGenesis", arg0, arg1, arg2) - ret0, _ := ret[0].([]types1.ValidatorUpdate) - return ret0 + m.ctrl.Call(m, "IsAppModule") } -// InitGenesis indicates an expected call of InitGenesis. -func (mr *MockBeginBlockAppModuleMockRecorder) InitGenesis(arg0, arg1, arg2 interface{}) *gomock.Call { +// IsAppModule indicates an expected call of IsAppModule. +func (mr *MockBeginBlockAppModuleMockRecorder) IsAppModule() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InitGenesis", reflect.TypeOf((*MockBeginBlockAppModule)(nil).InitGenesis), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsAppModule", reflect.TypeOf((*MockBeginBlockAppModule)(nil).IsAppModule)) +} + +// IsOnePerModuleType mocks base method. +func (m *MockBeginBlockAppModule) IsOnePerModuleType() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "IsOnePerModuleType") +} + +// IsOnePerModuleType indicates an expected call of IsOnePerModuleType. +func (mr *MockBeginBlockAppModuleMockRecorder) IsOnePerModuleType() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsOnePerModuleType", reflect.TypeOf((*MockBeginBlockAppModule)(nil).IsOnePerModuleType)) } // Name mocks base method. @@ -657,18 +871,6 @@ func (mr *MockBeginBlockAppModuleMockRecorder) RegisterInterfaces(arg0 interface return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInterfaces", reflect.TypeOf((*MockBeginBlockAppModule)(nil).RegisterInterfaces), arg0) } -// RegisterInvariants mocks base method. -func (m *MockBeginBlockAppModule) RegisterInvariants(arg0 types0.InvariantRegistry) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "RegisterInvariants", arg0) -} - -// RegisterInvariants indicates an expected call of RegisterInvariants. -func (mr *MockBeginBlockAppModuleMockRecorder) RegisterInvariants(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInvariants", reflect.TypeOf((*MockBeginBlockAppModule)(nil).RegisterInvariants), arg0) -} - // RegisterLegacyAminoCodec mocks base method. func (m *MockBeginBlockAppModule) RegisterLegacyAminoCodec(arg0 *codec.LegacyAmino) { m.ctrl.T.Helper() @@ -681,18 +883,6 @@ func (mr *MockBeginBlockAppModuleMockRecorder) RegisterLegacyAminoCodec(arg0 int return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterLegacyAminoCodec", reflect.TypeOf((*MockBeginBlockAppModule)(nil).RegisterLegacyAminoCodec), arg0) } -// RegisterServices mocks base method. -func (m *MockBeginBlockAppModule) RegisterServices(arg0 module.Configurator) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "RegisterServices", arg0) -} - -// RegisterServices indicates an expected call of RegisterServices. -func (mr *MockBeginBlockAppModuleMockRecorder) RegisterServices(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterServices", reflect.TypeOf((*MockBeginBlockAppModule)(nil).RegisterServices), arg0) -} - // ValidateGenesis mocks base method. func (m *MockBeginBlockAppModule) ValidateGenesis(arg0 codec.JSONCodec, arg1 client.TxEncodingConfig, arg2 json.RawMessage) error { m.ctrl.T.Helper() @@ -730,20 +920,6 @@ func (m *MockEndBlockAppModule) EXPECT() *MockEndBlockAppModuleMockRecorder { return m.recorder } -// ConsensusVersion mocks base method. -func (m *MockEndBlockAppModule) ConsensusVersion() uint64 { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ConsensusVersion") - ret0, _ := ret[0].(uint64) - return ret0 -} - -// ConsensusVersion indicates an expected call of ConsensusVersion. -func (mr *MockEndBlockAppModuleMockRecorder) ConsensusVersion() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConsensusVersion", reflect.TypeOf((*MockEndBlockAppModule)(nil).ConsensusVersion)) -} - // DefaultGenesis mocks base method. func (m *MockEndBlockAppModule) DefaultGenesis(arg0 codec.JSONCodec) json.RawMessage { m.ctrl.T.Helper() @@ -772,20 +948,6 @@ func (mr *MockEndBlockAppModuleMockRecorder) EndBlock(arg0, arg1 interface{}) *g return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EndBlock", reflect.TypeOf((*MockEndBlockAppModule)(nil).EndBlock), arg0, arg1) } -// ExportGenesis mocks base method. -func (m *MockEndBlockAppModule) ExportGenesis(arg0 types0.Context, arg1 codec.JSONCodec) json.RawMessage { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ExportGenesis", arg0, arg1) - ret0, _ := ret[0].(json.RawMessage) - return ret0 -} - -// ExportGenesis indicates an expected call of ExportGenesis. -func (mr *MockEndBlockAppModuleMockRecorder) ExportGenesis(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExportGenesis", reflect.TypeOf((*MockEndBlockAppModule)(nil).ExportGenesis), arg0, arg1) -} - // GetQueryCmd mocks base method. func (m *MockEndBlockAppModule) GetQueryCmd() *cobra.Command { m.ctrl.T.Helper() @@ -814,18 +976,28 @@ func (mr *MockEndBlockAppModuleMockRecorder) GetTxCmd() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTxCmd", reflect.TypeOf((*MockEndBlockAppModule)(nil).GetTxCmd)) } -// InitGenesis mocks base method. -func (m *MockEndBlockAppModule) InitGenesis(arg0 types0.Context, arg1 codec.JSONCodec, arg2 json.RawMessage) []types1.ValidatorUpdate { +// IsAppModule mocks base method. +func (m *MockEndBlockAppModule) IsAppModule() { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "InitGenesis", arg0, arg1, arg2) - ret0, _ := ret[0].([]types1.ValidatorUpdate) - return ret0 + m.ctrl.Call(m, "IsAppModule") } -// InitGenesis indicates an expected call of InitGenesis. -func (mr *MockEndBlockAppModuleMockRecorder) InitGenesis(arg0, arg1, arg2 interface{}) *gomock.Call { +// IsAppModule indicates an expected call of IsAppModule. +func (mr *MockEndBlockAppModuleMockRecorder) IsAppModule() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsAppModule", reflect.TypeOf((*MockEndBlockAppModule)(nil).IsAppModule)) +} + +// IsOnePerModuleType mocks base method. +func (m *MockEndBlockAppModule) IsOnePerModuleType() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "IsOnePerModuleType") +} + +// IsOnePerModuleType indicates an expected call of IsOnePerModuleType. +func (mr *MockEndBlockAppModuleMockRecorder) IsOnePerModuleType() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InitGenesis", reflect.TypeOf((*MockEndBlockAppModule)(nil).InitGenesis), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsOnePerModuleType", reflect.TypeOf((*MockEndBlockAppModule)(nil).IsOnePerModuleType)) } // Name mocks base method. @@ -866,18 +1038,6 @@ func (mr *MockEndBlockAppModuleMockRecorder) RegisterInterfaces(arg0 interface{} return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInterfaces", reflect.TypeOf((*MockEndBlockAppModule)(nil).RegisterInterfaces), arg0) } -// RegisterInvariants mocks base method. -func (m *MockEndBlockAppModule) RegisterInvariants(arg0 types0.InvariantRegistry) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "RegisterInvariants", arg0) -} - -// RegisterInvariants indicates an expected call of RegisterInvariants. -func (mr *MockEndBlockAppModuleMockRecorder) RegisterInvariants(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInvariants", reflect.TypeOf((*MockEndBlockAppModule)(nil).RegisterInvariants), arg0) -} - // RegisterLegacyAminoCodec mocks base method. func (m *MockEndBlockAppModule) RegisterLegacyAminoCodec(arg0 *codec.LegacyAmino) { m.ctrl.T.Helper() @@ -890,18 +1050,6 @@ func (mr *MockEndBlockAppModuleMockRecorder) RegisterLegacyAminoCodec(arg0 inter return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterLegacyAminoCodec", reflect.TypeOf((*MockEndBlockAppModule)(nil).RegisterLegacyAminoCodec), arg0) } -// RegisterServices mocks base method. -func (m *MockEndBlockAppModule) RegisterServices(arg0 module.Configurator) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "RegisterServices", arg0) -} - -// RegisterServices indicates an expected call of RegisterServices. -func (mr *MockEndBlockAppModuleMockRecorder) RegisterServices(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterServices", reflect.TypeOf((*MockEndBlockAppModule)(nil).RegisterServices), arg0) -} - // ValidateGenesis mocks base method. func (m *MockEndBlockAppModule) ValidateGenesis(arg0 codec.JSONCodec, arg1 client.TxEncodingConfig, arg2 json.RawMessage) error { m.ctrl.T.Helper() From 62bfd3edb3a446e45969cab18a5efc97b5ed57fd Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 8 Nov 2022 14:20:54 -0500 Subject: [PATCH 05/19] CHANGELOG.md, UPGRADING.md --- CHANGELOG.md | 3 ++- UPGRADING.md | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ece425deebb..5dddbeef82d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -155,7 +155,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/gov) [#13160](https://github.com/cosmos/cosmos-sdk/pull/13160) Remove custom marshaling of proposl and voteoption. * (types) [#13430](https://github.com/cosmos/cosmos-sdk/pull/13430) Remove unused code `ResponseCheckTx` and `ResponseDeliverTx` * (store) [#13529](https://github.com/cosmos/cosmos-sdk/pull/13529) Add method `LatestVersion` to `MultiStore` interface, add method `SetQueryMultiStore` to baesapp to support alternative `MultiStore` implementation for query service. -* (pruning) [#13609]](https://github.com/cosmos/cosmos-sdk/pull/13609) Move pruning pacakge to be under store pacakge +* (pruning) [#13609]](https://github.com/cosmos/cosmos-sdk/pull/13609) Move pruning package to be under store package +* [#13794](https://github.com/cosmos/cosmos-sdk/pull/13794) Deprecate `types/module.AppModule` and `types/module.NewManager` in favor of `cosmossdk.io/core/appmodule.AppModule` and `types/module.NewManagerFromMap` ### CLI Breaking Changes diff --git a/UPGRADING.md b/UPGRADING.md index 2af2239be991..b87d8ffa6834 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -18,7 +18,24 @@ is typically found in `RegisterAPIRoutes`. ### AppModule Interface -Remove `Querier`, `Route` and `LegacyQuerier` from the app module interface. This removes and fully deprecates all legacy queriers. All modules no longer support the REST API previously known as the LCD, and the `sdk.Msg#Route` method won't be used anymore. +The `AppModule` interface is being refactored into `cosmossdk.io/core` and is now fully composed of extension interfaces +based off of the `cosmossdk.io/core/appmodule.AppModule` tag interface. All `AppModule` implementations must now implement +this tag interface which very simply of the following code: + +```go +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. +func (AppModule) IsOnePerModuleType() {} + +// IsAppModule implements the appmodule.AppModule interface. +func (AppModule) IsAppModule() {} +``` + +Support for the `AppModule` `Querier`, `Route` and `LegacyQuerier` methods has been entirely removed. +This removes and fully deprecates all legacy queriers. All modules no longer support the REST API previously known as +the LCD, and the `sdk.Msg#Route` method won't be used anymore. + +Most other existing `AppModule` methods are supported as is, although new stable extension interfaces are being added to +`cosmossdk.io/core`. ### SimApp From 5344498c362e48119d0d038473fda2ba3def244e Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 8 Nov 2022 14:25:40 -0500 Subject: [PATCH 06/19] docs --- UPGRADING.md | 2 +- types/module/module.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/UPGRADING.md b/UPGRADING.md index b87d8ffa6834..4db1f6a6e8f3 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -20,7 +20,7 @@ is typically found in `RegisterAPIRoutes`. The `AppModule` interface is being refactored into `cosmossdk.io/core` and is now fully composed of extension interfaces based off of the `cosmossdk.io/core/appmodule.AppModule` tag interface. All `AppModule` implementations must now implement -this tag interface which very simply of the following code: +this tag interface which consists of the following code: ```go // IsOnePerModuleType implements the depinject.OnePerModuleType interface. diff --git a/types/module/module.go b/types/module/module.go index fb9b808c67e9..7e284fe420f0 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -62,7 +62,7 @@ type AppModuleBasic interface { // HasName allows the module to provide its own name for legacy purposes. // Newer apps should specify the name for their modules using a map -// (see NewManagerFromMap). +// using NewManagerFromMap. type HasName interface { Name() string } @@ -168,7 +168,7 @@ type LegacyGenesis interface { // Deprecated: AppModule is the legacy form for an application module. Most of // its functionality has been moved to extension interfaces based off of -// appmodule.AppModule. +// cosmossdk.io/core/appmodule.AppModule. type AppModule interface { appmodule.AppModule @@ -276,7 +276,7 @@ func NewManager(modules ...AppModule) *Manager { } } -// NewManagerFromMap creates a new Manager object from a map of modules. It +// NewManagerFromMap creates a new Manager object from a map of module names to module implementations. It // should be used instead of NewManager for new apps. func NewManagerFromMap(moduleMap map[string]appmodule.AppModule) *Manager { modulesStr := make([]string, 0, len(moduleMap)) From 05c662ea5edcb41595de48599070c277ca18aef2 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 9 Nov 2022 10:04:27 -0500 Subject: [PATCH 07/19] WIP --- types/module/module.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/types/module/module.go b/types/module/module.go index 7e284fe420f0..6d51d6e5debe 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -170,8 +170,6 @@ type LegacyGenesis interface { // its functionality has been moved to extension interfaces based off of // cosmossdk.io/core/appmodule.AppModule. type AppModule interface { - appmodule.AppModule - AppModuleBasic } @@ -249,7 +247,7 @@ func (GenesisOnlyAppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []ab // Manager defines a module manager that provides the high level utility for managing and executing // operations for a group of modules type Manager struct { - Modules map[string]appmodule.AppModule + Modules map[string]interface{} OrderInitGenesis []string OrderExportGenesis []string OrderBeginBlockers []string @@ -260,7 +258,7 @@ type Manager struct { // Deprecated: NewManager creates a new Manager object. NewManagerFromMap should // be preferred. func NewManager(modules ...AppModule) *Manager { - moduleMap := make(map[string]appmodule.AppModule) + moduleMap := make(map[string]interface{}) modulesStr := make([]string, 0, len(modules)) for _, module := range modules { moduleMap[module.Name()] = module @@ -279,13 +277,15 @@ func NewManager(modules ...AppModule) *Manager { // NewManagerFromMap creates a new Manager object from a map of module names to module implementations. It // should be used instead of NewManager for new apps. func NewManagerFromMap(moduleMap map[string]appmodule.AppModule) *Manager { - modulesStr := make([]string, 0, len(moduleMap)) - for name := range moduleMap { + simpleModuleMap := make(map[string]interface{}) + modulesStr := make([]string, 0, len(simpleModuleMap)) + for name, module := range moduleMap { + simpleModuleMap[name] = module modulesStr = append(modulesStr, name) } return &Manager{ - Modules: moduleMap, + Modules: simpleModuleMap, OrderInitGenesis: modulesStr, OrderExportGenesis: modulesStr, OrderBeginBlockers: modulesStr, From 75f6f730e989cc03abb26cec4c8f54c92a1bdcde Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 9 Nov 2022 10:05:46 -0500 Subject: [PATCH 08/19] revert --- api/cosmos/tx/v1beta1/service.pulsar.go | 9 ++++----- api/tendermint/crypto/proof.pulsar.go | 9 ++++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/api/cosmos/tx/v1beta1/service.pulsar.go b/api/cosmos/tx/v1beta1/service.pulsar.go index 1cd5d76cbd2c..f5f01047dac4 100644 --- a/api/cosmos/tx/v1beta1/service.pulsar.go +++ b/api/cosmos/tx/v1beta1/service.pulsar.go @@ -2,19 +2,18 @@ package txv1beta1 import ( - fmt "fmt" - io "io" - reflect "reflect" - sync "sync" - v1beta11 "cosmossdk.io/api/cosmos/base/abci/v1beta1" v1beta1 "cosmossdk.io/api/cosmos/base/query/v1beta1" types "cosmossdk.io/api/tendermint/types" + fmt "fmt" runtime "github.com/cosmos/cosmos-proto/runtime" _ "google.golang.org/genproto/googleapis/api/annotations" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoiface "google.golang.org/protobuf/runtime/protoiface" protoimpl "google.golang.org/protobuf/runtime/protoimpl" + io "io" + reflect "reflect" + sync "sync" ) var _ protoreflect.List = (*_GetTxsEventRequest_1_list)(nil) diff --git a/api/tendermint/crypto/proof.pulsar.go b/api/tendermint/crypto/proof.pulsar.go index 1923145531a6..a3128844e44e 100644 --- a/api/tendermint/crypto/proof.pulsar.go +++ b/api/tendermint/crypto/proof.pulsar.go @@ -3,15 +3,14 @@ package crypto import ( fmt "fmt" - io "io" - reflect "reflect" - sync "sync" - runtime "github.com/cosmos/cosmos-proto/runtime" _ "github.com/cosmos/gogoproto/gogoproto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoiface "google.golang.org/protobuf/runtime/protoiface" protoimpl "google.golang.org/protobuf/runtime/protoimpl" + io "io" + reflect "reflect" + sync "sync" ) var _ protoreflect.List = (*_Proof_4_list)(nil) @@ -2920,7 +2919,7 @@ func (x *DominoOp) GetOutput() string { } // ProofOp defines an operation used for calculating Merkle root -// The data could be arbitrary format, providing necessary data +// The data could be arbitrary format, providing nessecary data // for example neighbouring node hash type ProofOp struct { state protoimpl.MessageState From dd52b7f9ad4ec8bc1b5359dc63b31829fe157eb4 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 9 Nov 2022 10:13:02 -0500 Subject: [PATCH 09/19] remove breaking changes --- runtime/services/autocli.go | 42 +++++++++++++++++++------------------ types/module/module.go | 2 +- types/module/simulation.go | 3 +-- x/genutil/module.go | 2 +- x/gov/module.go | 6 ------ 5 files changed, 25 insertions(+), 30 deletions(-) diff --git a/runtime/services/autocli.go b/runtime/services/autocli.go index 763ea8ce71d9..1777bf8fced3 100644 --- a/runtime/services/autocli.go +++ b/runtime/services/autocli.go @@ -17,7 +17,7 @@ type AutoCLIQueryService struct { moduleOptions map[string]*autocliv1.ModuleOptions } -func NewAutoCLIQueryService(appModules map[string]appmodule.AppModule) *AutoCLIQueryService { +func NewAutoCLIQueryService(appModules map[string]interface{}) *AutoCLIQueryService { moduleOptions := map[string]*autocliv1.ModuleOptions{} for modName, mod := range appModules { if autoCliMod, ok := mod.(interface { @@ -25,29 +25,31 @@ func NewAutoCLIQueryService(appModules map[string]appmodule.AppModule) *AutoCLIQ }); ok { moduleOptions[modName] = autoCliMod.AutoCLIOptions() } else { - // try to auto-discover options based on the last msg and query - // services registered for the module - cfg := &autocliConfigurator{} - mod.RegisterServices(cfg) - modOptions := &autocliv1.ModuleOptions{} - haveServices := false - - if cfg.msgServer.serviceName != "" { - haveServices = true - modOptions.Tx = &autocliv1.ServiceCommandDescriptor{ - Service: cfg.msgServer.serviceName, + if mod, ok := mod.(module.LegacyRegisterServices); ok { + // try to auto-discover options based on the last msg and query + // services registered for the module + cfg := &autocliConfigurator{} + mod.RegisterServices(cfg) + modOptions := &autocliv1.ModuleOptions{} + haveServices := false + + if cfg.msgServer.serviceName != "" { + haveServices = true + modOptions.Tx = &autocliv1.ServiceCommandDescriptor{ + Service: cfg.msgServer.serviceName, + } } - } - if cfg.queryServer.serviceName != "" { - haveServices = true - modOptions.Query = &autocliv1.ServiceCommandDescriptor{ - Service: cfg.queryServer.serviceName, + if cfg.queryServer.serviceName != "" { + haveServices = true + modOptions.Query = &autocliv1.ServiceCommandDescriptor{ + Service: cfg.queryServer.serviceName, + } } - } - if haveServices { - moduleOptions[modName] = modOptions + if haveServices { + moduleOptions[modName] = modOptions + } } } } diff --git a/types/module/module.go b/types/module/module.go index 6d51d6e5debe..dc49cf0bb350 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -212,7 +212,7 @@ type GenesisOnlyAppModule struct { } // NewGenesisOnlyAppModule creates a new GenesisOnlyAppModule object -func NewGenesisOnlyAppModule(amg AppModuleGenesis) AppModule { +func NewGenesisOnlyAppModule(amg AppModuleGenesis) GenesisOnlyAppModule { return GenesisOnlyAppModule{ AppModuleGenesis: amg, } diff --git a/types/module/simulation.go b/types/module/simulation.go index bc4dd3df6c53..e7acb7e0cd80 100644 --- a/types/module/simulation.go +++ b/types/module/simulation.go @@ -6,7 +6,6 @@ import ( "sort" "time" - "cosmossdk.io/core/appmodule" sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/codec" @@ -53,7 +52,7 @@ func NewSimulationManager(modules ...AppModuleSimulation) *SimulationManager { // with the same moduleName. // Then it attempts to cast every provided AppModule into an AppModuleSimulation. // If the cast succeeds, its included, otherwise it is excluded. -func NewSimulationManagerFromAppModules(modules map[string]appmodule.AppModule, overrideModules map[string]AppModuleSimulation) *SimulationManager { +func NewSimulationManagerFromAppModules(modules map[string]interface{}, overrideModules map[string]AppModuleSimulation) *SimulationManager { simModules := []AppModuleSimulation{} appModuleNamesSorted := make([]string, 0, len(modules)) for moduleName := range modules { diff --git a/x/genutil/module.go b/x/genutil/module.go index f9724c141179..631da886aaa0 100644 --- a/x/genutil/module.go +++ b/x/genutil/module.go @@ -89,7 +89,7 @@ type AppModule struct { func NewAppModule(accountKeeper types.AccountKeeper, stakingKeeper types.StakingKeeper, deliverTx deliverTxfn, txEncodingConfig client.TxEncodingConfig, -) module.AppModule { +) module.GenesisOnlyAppModule { return module.NewGenesisOnlyAppModule(AppModule{ AppModuleBasic: AppModuleBasic{}, accountKeeper: accountKeeper, diff --git a/x/gov/module.go b/x/gov/module.go index ebc3be492453..50c13c1cad66 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -122,12 +122,6 @@ func (a AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry v1beta1.RegisterInterfaces(registry) } -// IsOnePerModuleType implements the depinject.OnePerModuleType interface. -func (am AppModule) IsOnePerModuleType() {} - -// IsAppModule implements the appmodule.AppModule interface. -func (am AppModule) IsAppModule() {} - // AppModule implements an application module for the gov module. type AppModule struct { AppModuleBasic From 7f66cd152ac6a5b4c6fbc552212d6e96fe58a619 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 9 Nov 2022 10:23:13 -0500 Subject: [PATCH 10/19] update docs, naming --- CHANGELOG.md | 6 +- UPGRADING.md | 23 +--- runtime/services/autocli.go | 2 +- simapp/app_test.go | 2 +- testutil/mock/types_module_module.go | 180 ++++++++------------------- types/module/module.go | 40 +++--- 6 files changed, 86 insertions(+), 167 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 148987643614..b23cf4f0d4e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -88,6 +88,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [#13781](https://github.com/cosmos/cosmos-sdk/pull/13781) Remove `client/keys.KeysCdc`. * [#13803](https://github.com/cosmos/cosmos-sdk/pull/13803) Add an error log if iavl set operation failed. * [#13802](https://github.com/cosmos/cosmos-sdk/pull/13802) Add --output-document flag to the export CLI command to allow writing genesis state to a file. +* [#13794](https://github.com/cosmos/cosmos-sdk/pull/13794) `types/module.Manager` now supports the +`cosmossdk.io/core/appmodule.AppModule` API via the new `NewManagerFromMap` constructor. ### State Machine Breaking @@ -159,7 +161,9 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (types) [#13430](https://github.com/cosmos/cosmos-sdk/pull/13430) Remove unused code `ResponseCheckTx` and `ResponseDeliverTx` * (store) [#13529](https://github.com/cosmos/cosmos-sdk/pull/13529) Add method `LatestVersion` to `MultiStore` interface, add method `SetQueryMultiStore` to baesapp to support alternative `MultiStore` implementation for query service. * (pruning) [#13609]](https://github.com/cosmos/cosmos-sdk/pull/13609) Move pruning package to be under store package -* [#13794](https://github.com/cosmos/cosmos-sdk/pull/13794) Deprecate `types/module.AppModule` and `types/module.NewManager` in favor of `cosmossdk.io/core/appmodule.AppModule` and `types/module.NewManagerFromMap` +* [#13794](https://github.com/cosmos/cosmos-sdk/pull/13794) Most methods on `types/module.AppModule` have been moved to +extension interfaces. `module.Manager.Modules` is now of type `map[string]interface{}` to support in parallel the new +`cosmossdk.io/core/appmodule.AppModule` API. ### CLI Breaking Changes diff --git a/UPGRADING.md b/UPGRADING.md index 4db1f6a6e8f3..955d67b8854e 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -18,24 +18,13 @@ is typically found in `RegisterAPIRoutes`. ### AppModule Interface -The `AppModule` interface is being refactored into `cosmossdk.io/core` and is now fully composed of extension interfaces -based off of the `cosmossdk.io/core/appmodule.AppModule` tag interface. All `AppModule` implementations must now implement -this tag interface which consists of the following code: +Support for the `AppModule` `Querier`, `Route` and `LegacyQuerier` methods has been entirely removed from the `AppModule` +interface. This removes and fully deprecates all legacy queriers. All modules no longer support the REST API previously +known as the LCD, and the `sdk.Msg#Route` method won't be used anymore. -```go -// IsOnePerModuleType implements the depinject.OnePerModuleType interface. -func (AppModule) IsOnePerModuleType() {} - -// IsAppModule implements the appmodule.AppModule interface. -func (AppModule) IsAppModule() {} -``` - -Support for the `AppModule` `Querier`, `Route` and `LegacyQuerier` methods has been entirely removed. -This removes and fully deprecates all legacy queriers. All modules no longer support the REST API previously known as -the LCD, and the `sdk.Msg#Route` method won't be used anymore. - -Most other existing `AppModule` methods are supported as is, although new stable extension interfaces are being added to -`cosmossdk.io/core`. +Most other existing `AppModule` methods have been moved to extension interfaces in preparation for the migration +to the `cosmossdk.io/core/appmodule` API in the next release. Most `AppModule` implementations should not be broken +by this change. ### SimApp diff --git a/runtime/services/autocli.go b/runtime/services/autocli.go index 1777bf8fced3..01ba84a3a6cc 100644 --- a/runtime/services/autocli.go +++ b/runtime/services/autocli.go @@ -25,7 +25,7 @@ func NewAutoCLIQueryService(appModules map[string]interface{}) *AutoCLIQueryServ }); ok { moduleOptions[modName] = autoCliMod.AutoCLIOptions() } else { - if mod, ok := mod.(module.LegacyRegisterServices); ok { + if mod, ok := mod.(module.HasRegisterSerices); ok { // try to auto-discover options based on the last msg and query // services registered for the module cfg := &autocliConfigurator{} diff --git a/simapp/app_test.go b/simapp/app_test.go index f8483a64e155..875fcfb8816f 100644 --- a/simapp/app_test.go +++ b/simapp/app_test.go @@ -86,7 +86,7 @@ func TestRunMigrations(t *testing.T) { continue } - if mod, ok := mod.(module.LegacyRegisterServices); ok { + if mod, ok := mod.(module.HasRegisterSerices); ok { mod.RegisterServices(configurator) } } diff --git a/testutil/mock/types_module_module.go b/testutil/mock/types_module_module.go index 0c6b1b434d18..579b30755bdd 100644 --- a/testutil/mock/types_module_module.go +++ b/testutil/mock/types_module_module.go @@ -185,31 +185,31 @@ func (mr *MockHasNameMockRecorder) Name() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockHasName)(nil).Name)) } -// MockLegacyGenesisBasics is a mock of LegacyGenesisBasics interface. -type MockLegacyGenesisBasics struct { +// MockHasGenesisBasics is a mock of HasGenesisBasics interface. +type MockHasGenesisBasics struct { ctrl *gomock.Controller - recorder *MockLegacyGenesisBasicsMockRecorder + recorder *MockHasGenesisBasicsMockRecorder } -// MockLegacyGenesisBasicsMockRecorder is the mock recorder for MockLegacyGenesisBasics. -type MockLegacyGenesisBasicsMockRecorder struct { - mock *MockLegacyGenesisBasics +// MockHasGenesisBasicsMockRecorder is the mock recorder for MockHasGenesisBasics. +type MockHasGenesisBasicsMockRecorder struct { + mock *MockHasGenesisBasics } -// NewMockLegacyGenesisBasics creates a new mock instance. -func NewMockLegacyGenesisBasics(ctrl *gomock.Controller) *MockLegacyGenesisBasics { - mock := &MockLegacyGenesisBasics{ctrl: ctrl} - mock.recorder = &MockLegacyGenesisBasicsMockRecorder{mock} +// NewMockHasGenesisBasics creates a new mock instance. +func NewMockHasGenesisBasics(ctrl *gomock.Controller) *MockHasGenesisBasics { + mock := &MockHasGenesisBasics{ctrl: ctrl} + mock.recorder = &MockHasGenesisBasicsMockRecorder{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockLegacyGenesisBasics) EXPECT() *MockLegacyGenesisBasicsMockRecorder { +func (m *MockHasGenesisBasics) EXPECT() *MockHasGenesisBasicsMockRecorder { return m.recorder } // DefaultGenesis mocks base method. -func (m *MockLegacyGenesisBasics) DefaultGenesis(arg0 codec.JSONCodec) json.RawMessage { +func (m *MockHasGenesisBasics) DefaultGenesis(arg0 codec.JSONCodec) json.RawMessage { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "DefaultGenesis", arg0) ret0, _ := ret[0].(json.RawMessage) @@ -217,13 +217,13 @@ func (m *MockLegacyGenesisBasics) DefaultGenesis(arg0 codec.JSONCodec) json.RawM } // DefaultGenesis indicates an expected call of DefaultGenesis. -func (mr *MockLegacyGenesisBasicsMockRecorder) DefaultGenesis(arg0 interface{}) *gomock.Call { +func (mr *MockHasGenesisBasicsMockRecorder) DefaultGenesis(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DefaultGenesis", reflect.TypeOf((*MockLegacyGenesisBasics)(nil).DefaultGenesis), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DefaultGenesis", reflect.TypeOf((*MockHasGenesisBasics)(nil).DefaultGenesis), arg0) } // ValidateGenesis mocks base method. -func (m *MockLegacyGenesisBasics) ValidateGenesis(arg0 codec.JSONCodec, arg1 client.TxEncodingConfig, arg2 json.RawMessage) error { +func (m *MockHasGenesisBasics) ValidateGenesis(arg0 codec.JSONCodec, arg1 client.TxEncodingConfig, arg2 json.RawMessage) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ValidateGenesis", arg0, arg1, arg2) ret0, _ := ret[0].(error) @@ -231,9 +231,9 @@ func (m *MockLegacyGenesisBasics) ValidateGenesis(arg0 codec.JSONCodec, arg1 cli } // ValidateGenesis indicates an expected call of ValidateGenesis. -func (mr *MockLegacyGenesisBasicsMockRecorder) ValidateGenesis(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockHasGenesisBasicsMockRecorder) ValidateGenesis(arg0, arg1, arg2 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesis", reflect.TypeOf((*MockLegacyGenesisBasics)(nil).ValidateGenesis), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesis", reflect.TypeOf((*MockHasGenesisBasics)(nil).ValidateGenesis), arg0, arg1, arg2) } // MockAppModuleGenesis is a mock of AppModuleGenesis interface. @@ -393,31 +393,31 @@ func (mr *MockAppModuleGenesisMockRecorder) ValidateGenesis(arg0, arg1, arg2 int return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesis", reflect.TypeOf((*MockAppModuleGenesis)(nil).ValidateGenesis), arg0, arg1, arg2) } -// MockLegacyGenesis is a mock of LegacyGenesis interface. -type MockLegacyGenesis struct { +// MockHasGenesis is a mock of HasGenesis interface. +type MockHasGenesis struct { ctrl *gomock.Controller - recorder *MockLegacyGenesisMockRecorder + recorder *MockHasGenesisMockRecorder } -// MockLegacyGenesisMockRecorder is the mock recorder for MockLegacyGenesis. -type MockLegacyGenesisMockRecorder struct { - mock *MockLegacyGenesis +// MockHasGenesisMockRecorder is the mock recorder for MockHasGenesis. +type MockHasGenesisMockRecorder struct { + mock *MockHasGenesis } -// NewMockLegacyGenesis creates a new mock instance. -func NewMockLegacyGenesis(ctrl *gomock.Controller) *MockLegacyGenesis { - mock := &MockLegacyGenesis{ctrl: ctrl} - mock.recorder = &MockLegacyGenesisMockRecorder{mock} +// NewMockHasGenesis creates a new mock instance. +func NewMockHasGenesis(ctrl *gomock.Controller) *MockHasGenesis { + mock := &MockHasGenesis{ctrl: ctrl} + mock.recorder = &MockHasGenesisMockRecorder{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockLegacyGenesis) EXPECT() *MockLegacyGenesisMockRecorder { +func (m *MockHasGenesis) EXPECT() *MockHasGenesisMockRecorder { return m.recorder } // DefaultGenesis mocks base method. -func (m *MockLegacyGenesis) DefaultGenesis(arg0 codec.JSONCodec) json.RawMessage { +func (m *MockHasGenesis) DefaultGenesis(arg0 codec.JSONCodec) json.RawMessage { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "DefaultGenesis", arg0) ret0, _ := ret[0].(json.RawMessage) @@ -425,13 +425,13 @@ func (m *MockLegacyGenesis) DefaultGenesis(arg0 codec.JSONCodec) json.RawMessage } // DefaultGenesis indicates an expected call of DefaultGenesis. -func (mr *MockLegacyGenesisMockRecorder) DefaultGenesis(arg0 interface{}) *gomock.Call { +func (mr *MockHasGenesisMockRecorder) DefaultGenesis(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DefaultGenesis", reflect.TypeOf((*MockLegacyGenesis)(nil).DefaultGenesis), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DefaultGenesis", reflect.TypeOf((*MockHasGenesis)(nil).DefaultGenesis), arg0) } // ExportGenesis mocks base method. -func (m *MockLegacyGenesis) ExportGenesis(arg0 types0.Context, arg1 codec.JSONCodec) json.RawMessage { +func (m *MockHasGenesis) ExportGenesis(arg0 types0.Context, arg1 codec.JSONCodec) json.RawMessage { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ExportGenesis", arg0, arg1) ret0, _ := ret[0].(json.RawMessage) @@ -439,13 +439,13 @@ func (m *MockLegacyGenesis) ExportGenesis(arg0 types0.Context, arg1 codec.JSONCo } // ExportGenesis indicates an expected call of ExportGenesis. -func (mr *MockLegacyGenesisMockRecorder) ExportGenesis(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockHasGenesisMockRecorder) ExportGenesis(arg0, arg1 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExportGenesis", reflect.TypeOf((*MockLegacyGenesis)(nil).ExportGenesis), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExportGenesis", reflect.TypeOf((*MockHasGenesis)(nil).ExportGenesis), arg0, arg1) } // InitGenesis mocks base method. -func (m *MockLegacyGenesis) InitGenesis(arg0 types0.Context, arg1 codec.JSONCodec, arg2 json.RawMessage) []types1.ValidatorUpdate { +func (m *MockHasGenesis) InitGenesis(arg0 types0.Context, arg1 codec.JSONCodec, arg2 json.RawMessage) []types1.ValidatorUpdate { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "InitGenesis", arg0, arg1, arg2) ret0, _ := ret[0].([]types1.ValidatorUpdate) @@ -453,13 +453,13 @@ func (m *MockLegacyGenesis) InitGenesis(arg0 types0.Context, arg1 codec.JSONCode } // InitGenesis indicates an expected call of InitGenesis. -func (mr *MockLegacyGenesisMockRecorder) InitGenesis(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockHasGenesisMockRecorder) InitGenesis(arg0, arg1, arg2 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InitGenesis", reflect.TypeOf((*MockLegacyGenesis)(nil).InitGenesis), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InitGenesis", reflect.TypeOf((*MockHasGenesis)(nil).InitGenesis), arg0, arg1, arg2) } // ValidateGenesis mocks base method. -func (m *MockLegacyGenesis) ValidateGenesis(arg0 codec.JSONCodec, arg1 client.TxEncodingConfig, arg2 json.RawMessage) error { +func (m *MockHasGenesis) ValidateGenesis(arg0 codec.JSONCodec, arg1 client.TxEncodingConfig, arg2 json.RawMessage) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ValidateGenesis", arg0, arg1, arg2) ret0, _ := ret[0].(error) @@ -467,9 +467,9 @@ func (m *MockLegacyGenesis) ValidateGenesis(arg0 codec.JSONCodec, arg1 client.Tx } // ValidateGenesis indicates an expected call of ValidateGenesis. -func (mr *MockLegacyGenesisMockRecorder) ValidateGenesis(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockHasGenesisMockRecorder) ValidateGenesis(arg0, arg1, arg2 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesis", reflect.TypeOf((*MockLegacyGenesis)(nil).ValidateGenesis), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesis", reflect.TypeOf((*MockHasGenesis)(nil).ValidateGenesis), arg0, arg1, arg2) } // MockAppModule is a mock of AppModule interface. @@ -537,30 +537,6 @@ func (mr *MockAppModuleMockRecorder) GetTxCmd() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTxCmd", reflect.TypeOf((*MockAppModule)(nil).GetTxCmd)) } -// IsAppModule mocks base method. -func (m *MockAppModule) IsAppModule() { - m.ctrl.T.Helper() - m.ctrl.Call(m, "IsAppModule") -} - -// IsAppModule indicates an expected call of IsAppModule. -func (mr *MockAppModuleMockRecorder) IsAppModule() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsAppModule", reflect.TypeOf((*MockAppModule)(nil).IsAppModule)) -} - -// IsOnePerModuleType mocks base method. -func (m *MockAppModule) IsOnePerModuleType() { - m.ctrl.T.Helper() - m.ctrl.Call(m, "IsOnePerModuleType") -} - -// IsOnePerModuleType indicates an expected call of IsOnePerModuleType. -func (mr *MockAppModuleMockRecorder) IsOnePerModuleType() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsOnePerModuleType", reflect.TypeOf((*MockAppModule)(nil).IsOnePerModuleType)) -} - // Name mocks base method. func (m *MockAppModule) Name() string { m.ctrl.T.Helper() @@ -660,39 +636,39 @@ func (mr *MockHasRegisterInvariantsMockRecorder) RegisterInvariants(arg0 interfa return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInvariants", reflect.TypeOf((*MockHasRegisterInvariants)(nil).RegisterInvariants), arg0) } -// MockLegacyRegisterServices is a mock of LegacyRegisterServices interface. -type MockLegacyRegisterServices struct { +// MockHasRegisterSerices is a mock of HasRegisterSerices interface. +type MockHasRegisterSerices struct { ctrl *gomock.Controller - recorder *MockLegacyRegisterServicesMockRecorder + recorder *MockHasRegisterSericesMockRecorder } -// MockLegacyRegisterServicesMockRecorder is the mock recorder for MockLegacyRegisterServices. -type MockLegacyRegisterServicesMockRecorder struct { - mock *MockLegacyRegisterServices +// MockHasRegisterSericesMockRecorder is the mock recorder for MockHasRegisterSerices. +type MockHasRegisterSericesMockRecorder struct { + mock *MockHasRegisterSerices } -// NewMockLegacyRegisterServices creates a new mock instance. -func NewMockLegacyRegisterServices(ctrl *gomock.Controller) *MockLegacyRegisterServices { - mock := &MockLegacyRegisterServices{ctrl: ctrl} - mock.recorder = &MockLegacyRegisterServicesMockRecorder{mock} +// NewMockHasRegisterSerices creates a new mock instance. +func NewMockHasRegisterSerices(ctrl *gomock.Controller) *MockHasRegisterSerices { + mock := &MockHasRegisterSerices{ctrl: ctrl} + mock.recorder = &MockHasRegisterSericesMockRecorder{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockLegacyRegisterServices) EXPECT() *MockLegacyRegisterServicesMockRecorder { +func (m *MockHasRegisterSerices) EXPECT() *MockHasRegisterSericesMockRecorder { return m.recorder } // RegisterServices mocks base method. -func (m *MockLegacyRegisterServices) RegisterServices(arg0 module.Configurator) { +func (m *MockHasRegisterSerices) RegisterServices(arg0 module.Configurator) { m.ctrl.T.Helper() m.ctrl.Call(m, "RegisterServices", arg0) } // RegisterServices indicates an expected call of RegisterServices. -func (mr *MockLegacyRegisterServicesMockRecorder) RegisterServices(arg0 interface{}) *gomock.Call { +func (mr *MockHasRegisterSericesMockRecorder) RegisterServices(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterServices", reflect.TypeOf((*MockLegacyRegisterServices)(nil).RegisterServices), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterServices", reflect.TypeOf((*MockHasRegisterSerices)(nil).RegisterServices), arg0) } // MockHasConsensusVersion is a mock of HasConsensusVersion interface. @@ -809,30 +785,6 @@ func (mr *MockBeginBlockAppModuleMockRecorder) GetTxCmd() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTxCmd", reflect.TypeOf((*MockBeginBlockAppModule)(nil).GetTxCmd)) } -// IsAppModule mocks base method. -func (m *MockBeginBlockAppModule) IsAppModule() { - m.ctrl.T.Helper() - m.ctrl.Call(m, "IsAppModule") -} - -// IsAppModule indicates an expected call of IsAppModule. -func (mr *MockBeginBlockAppModuleMockRecorder) IsAppModule() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsAppModule", reflect.TypeOf((*MockBeginBlockAppModule)(nil).IsAppModule)) -} - -// IsOnePerModuleType mocks base method. -func (m *MockBeginBlockAppModule) IsOnePerModuleType() { - m.ctrl.T.Helper() - m.ctrl.Call(m, "IsOnePerModuleType") -} - -// IsOnePerModuleType indicates an expected call of IsOnePerModuleType. -func (mr *MockBeginBlockAppModuleMockRecorder) IsOnePerModuleType() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsOnePerModuleType", reflect.TypeOf((*MockBeginBlockAppModule)(nil).IsOnePerModuleType)) -} - // Name mocks base method. func (m *MockBeginBlockAppModule) Name() string { m.ctrl.T.Helper() @@ -976,30 +928,6 @@ func (mr *MockEndBlockAppModuleMockRecorder) GetTxCmd() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTxCmd", reflect.TypeOf((*MockEndBlockAppModule)(nil).GetTxCmd)) } -// IsAppModule mocks base method. -func (m *MockEndBlockAppModule) IsAppModule() { - m.ctrl.T.Helper() - m.ctrl.Call(m, "IsAppModule") -} - -// IsAppModule indicates an expected call of IsAppModule. -func (mr *MockEndBlockAppModuleMockRecorder) IsAppModule() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsAppModule", reflect.TypeOf((*MockEndBlockAppModule)(nil).IsAppModule)) -} - -// IsOnePerModuleType mocks base method. -func (m *MockEndBlockAppModule) IsOnePerModuleType() { - m.ctrl.T.Helper() - m.ctrl.Call(m, "IsOnePerModuleType") -} - -// IsOnePerModuleType indicates an expected call of IsOnePerModuleType. -func (mr *MockEndBlockAppModuleMockRecorder) IsOnePerModuleType() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsOnePerModuleType", reflect.TypeOf((*MockEndBlockAppModule)(nil).IsOnePerModuleType)) -} - // Name mocks base method. func (m *MockEndBlockAppModule) Name() string { m.ctrl.T.Helper() diff --git a/types/module/module.go b/types/module/module.go index dc49cf0bb350..2ad0a3f18992 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -52,7 +52,7 @@ type AppModuleBasic interface { RegisterLegacyAminoCodec(*codec.LegacyAmino) RegisterInterfaces(codectypes.InterfaceRegistry) - LegacyGenesisBasics + HasGenesisBasics // client functionality RegisterGRPCGatewayRoutes(client.Context, *runtime.ServeMux) @@ -68,7 +68,7 @@ type HasName interface { } // LegacyGenesisBasics is the legacy interface for stateless genesis methods. -type LegacyGenesisBasics interface { +type HasGenesisBasics interface { DefaultGenesis(codec.JSONCodec) json.RawMessage ValidateGenesis(codec.JSONCodec, client.TxEncodingConfig, json.RawMessage) error } @@ -156,19 +156,18 @@ func (bm BasicManager) AddQueryCommands(rootQueryCmd *cobra.Command) { // AppModuleGenesis is the standard form for an application module genesis functions type AppModuleGenesis interface { AppModuleBasic - LegacyGenesis + HasGenesis } -// LegacyGenesis is the legacy interface for stateful genesis methods. -type LegacyGenesis interface { - LegacyGenesisBasics +// HasGenesis is the extension interface for stateful genesis methods. +type HasGenesis interface { + HasGenesisBasics InitGenesis(sdk.Context, codec.JSONCodec, json.RawMessage) []abci.ValidatorUpdate ExportGenesis(sdk.Context, codec.JSONCodec) json.RawMessage } -// Deprecated: AppModule is the legacy form for an application module. Most of -// its functionality has been moved to extension interfaces based off of -// cosmossdk.io/core/appmodule.AppModule. +// AppModule is the form for an application module. Most of +// its functionality has been moved to extension interfaces. type AppModule interface { AppModuleBasic } @@ -179,8 +178,8 @@ type HasRegisterInvariants interface { RegisterInvariants(sdk.InvariantRegistry) } -// LegacyRegisterServices is the legacy method for modules to register services. -type LegacyRegisterServices interface { +// HasRegisterSerices is the interface for modules to register services. +type HasRegisterSerices interface { // RegisterServices allows a module to register services. RegisterServices(Configurator) } @@ -247,7 +246,7 @@ func (GenesisOnlyAppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []ab // Manager defines a module manager that provides the high level utility for managing and executing // operations for a group of modules type Manager struct { - Modules map[string]interface{} + Modules map[string]interface{} // interface{} is used now to support the legacy AppModule as well as new core appmodule.AppModule. OrderInitGenesis []string OrderExportGenesis []string OrderBeginBlockers []string @@ -255,8 +254,7 @@ type Manager struct { OrderMigrations []string } -// Deprecated: NewManager creates a new Manager object. NewManagerFromMap should -// be preferred. +// NewManager creates a new Manager object. func NewManager(modules ...AppModule) *Manager { moduleMap := make(map[string]interface{}) modulesStr := make([]string, 0, len(modules)) @@ -274,8 +272,8 @@ func NewManager(modules ...AppModule) *Manager { } } -// NewManagerFromMap creates a new Manager object from a map of module names to module implementations. It -// should be used instead of NewManager for new apps. +// NewManagerFromMap creates a new Manager object from a map of module names to module implementations. +// This method should be used for apps and modules which have migrated to the cosmossdk.io/core.appmodule.AppModule API. func NewManagerFromMap(moduleMap map[string]appmodule.AppModule) *Manager { simpleModuleMap := make(map[string]interface{}) modulesStr := make([]string, 0, len(simpleModuleMap)) @@ -338,7 +336,7 @@ func (m *Manager) RegisterInvariants(ir sdk.InvariantRegistry) { func (m *Manager) RegisterServices(cfg Configurator) { modules := maps.Values(m.Modules) for _, module := range modules { - if module, ok := module.(LegacyRegisterServices); ok { + if module, ok := module.(HasRegisterSerices); ok { module.RegisterServices(cfg) } } @@ -355,7 +353,7 @@ func (m *Manager) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, genesisData continue } - if module, ok := m.Modules[moduleName].(LegacyGenesis); ok { + if module, ok := m.Modules[moduleName].(HasGenesis); ok { ctx.Logger().Debug("running initialization for module", "module", moduleName) moduleValUpdates := module.InitGenesis(ctx, cdc, genesisData[moduleName]) @@ -391,7 +389,7 @@ func (m *Manager) ExportGenesisForModules(ctx sdk.Context, cdc codec.JSONCodec, genesisData := make(map[string]json.RawMessage) if len(modulesToExport) == 0 { for _, moduleName := range m.OrderExportGenesis { - if module, ok := m.Modules[moduleName].(LegacyGenesis); ok { + if module, ok := m.Modules[moduleName].(HasGenesis); ok { genesisData[moduleName] = module.ExportGenesis(ctx, cdc) } } @@ -405,7 +403,7 @@ func (m *Manager) ExportGenesisForModules(ctx sdk.Context, cdc codec.JSONCodec, } for _, moduleName := range modulesToExport { - if module, ok := m.Modules[moduleName].(LegacyGenesis); ok { + if module, ok := m.Modules[moduleName].(HasGenesis); ok { genesisData[moduleName] = module.ExportGenesis(ctx, cdc) } } @@ -536,7 +534,7 @@ func (m Manager) RunMigrations(ctx sdk.Context, cfg Configurator, fromVM Version } } else { ctx.Logger().Info(fmt.Sprintf("adding a new module: %s", moduleName)) - if module, ok := m.Modules[moduleName].(LegacyGenesis); ok { + if module, ok := m.Modules[moduleName].(HasGenesis); ok { moduleValUpdates := module.InitGenesis(ctx, c.cdc, module.DefaultGenesis(c.cdc)) // The module manager assumes only one module will update the // validator set, and it can't be a new module. From 65145686fb885610a25e7b7478b11e8ba65bdcc7 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Fri, 11 Nov 2022 13:58:56 -0500 Subject: [PATCH 11/19] update docs --- docs/docs/building-modules/14-depinject.md | 5 ++++- runtime/wrappers.go | 15 --------------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/docs/docs/building-modules/14-depinject.md b/docs/docs/building-modules/14-depinject.md index f1c402bf3f92..012ee5ba0267 100644 --- a/docs/docs/building-modules/14-depinject.md +++ b/docs/docs/building-modules/14-depinject.md @@ -106,12 +106,15 @@ All methods, structs and their fields must be public for `depinject`. https://github.com/cosmos/cosmos-sdk/blob/main/x/group/module/module.go#L210-L215 ``` -5. Create a function named `ProvideModule` (as called in 1.) and use the inputs for instantitating the module outputs. +5. Create a function named `ProvideModule` (as called in 1.) and use the inputs for instantiating the module outputs. ```go reference https://github.com/cosmos/cosmos-sdk/blob/main/x/group/module/module.go#L217-L227 ``` +The `ProvideModule` function should return an instance of `cosmossdk.io/core/appmodule.AppModule` which implements +one or more app module extension interfaces for initializing the module. + Following is the complete app wiring configuration for `group`: ```go reference diff --git a/runtime/wrappers.go b/runtime/wrappers.go index 4b98825736f0..ea914fc44598 100644 --- a/runtime/wrappers.go +++ b/runtime/wrappers.go @@ -2,21 +2,6 @@ package runtime import "github.com/cosmos/cosmos-sdk/types/module" -// AppModuleWrapper is a type used for injecting a module.AppModule into a -// container so that it can be used by the runtime module. -type AppModuleWrapper struct { - module.AppModule -} - -// WrapAppModule wraps a module.AppModule so that it can be injected into -// a container for use by the runtime module. -func WrapAppModule(appModule module.AppModule) AppModuleWrapper { - return AppModuleWrapper{AppModule: appModule} -} - -// IsOnePerModuleType identifies this type as a depinject.OnePerModuleType. -func (AppModuleWrapper) IsOnePerModuleType() {} - // AppModuleBasicWrapper is a type used for injecting a module.AppModuleBasic // into a container so that it can be used by the runtime module. type AppModuleBasicWrapper struct { From c90384e348b49076616c865f3ac6b59ec7b9075f Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Fri, 11 Nov 2022 14:02:11 -0500 Subject: [PATCH 12/19] Update types/module/module.go Co-authored-by: Amaury <1293565+amaurym@users.noreply.github.com> --- types/module/module.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/module/module.go b/types/module/module.go index 2ad0a3f18992..743ba4aca7fb 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -178,8 +178,8 @@ type HasRegisterInvariants interface { RegisterInvariants(sdk.InvariantRegistry) } -// HasRegisterSerices is the interface for modules to register services. -type HasRegisterSerices interface { +// HasRegisterServices is the interface for modules to register services. +type HasRegisterServices interface { // RegisterServices allows a module to register services. RegisterServices(Configurator) } From cebb336889d9f8133550b9b8db5e5a5ca87e6d88 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Fri, 11 Nov 2022 14:02:23 -0500 Subject: [PATCH 13/19] Update types/module/module.go Co-authored-by: Amaury <1293565+amaurym@users.noreply.github.com> --- types/module/module.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/module/module.go b/types/module/module.go index 743ba4aca7fb..68cda0ef3969 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -67,7 +67,7 @@ type HasName interface { Name() string } -// LegacyGenesisBasics is the legacy interface for stateless genesis methods. +// HasGenesisBasics is the legacy interface for stateless genesis methods. type HasGenesisBasics interface { DefaultGenesis(codec.JSONCodec) json.RawMessage ValidateGenesis(codec.JSONCodec, client.TxEncodingConfig, json.RawMessage) error From 13c77ada81ddf2fafe1ff64e1b0e828982ca1fc5 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Fri, 11 Nov 2022 14:02:56 -0500 Subject: [PATCH 14/19] Update types/module/module.go Co-authored-by: Amaury <1293565+amaurym@users.noreply.github.com> --- types/module/module.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/module/module.go b/types/module/module.go index 68cda0ef3969..f3108034a67c 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -173,7 +173,7 @@ type AppModule interface { } // HasRegisterInvariants is the interface for registering invariants. -type HasRegisterInvariants interface { +type HasInvariants interface { // RegisterInvariants registers module invariants. RegisterInvariants(sdk.InvariantRegistry) } From 04450d5c501008144da6103d2878af2ff7bae134 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Fri, 11 Nov 2022 14:04:53 -0500 Subject: [PATCH 15/19] address review comments --- runtime/services/autocli.go | 42 ++++++++++++++++++------------------- types/module/module.go | 10 ++++----- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/runtime/services/autocli.go b/runtime/services/autocli.go index 01ba84a3a6cc..2e67c37ec6e7 100644 --- a/runtime/services/autocli.go +++ b/runtime/services/autocli.go @@ -24,32 +24,30 @@ func NewAutoCLIQueryService(appModules map[string]interface{}) *AutoCLIQueryServ AutoCLIOptions() *autocliv1.ModuleOptions }); ok { moduleOptions[modName] = autoCliMod.AutoCLIOptions() - } else { - if mod, ok := mod.(module.HasRegisterSerices); ok { - // try to auto-discover options based on the last msg and query - // services registered for the module - cfg := &autocliConfigurator{} - mod.RegisterServices(cfg) - modOptions := &autocliv1.ModuleOptions{} - haveServices := false - - if cfg.msgServer.serviceName != "" { - haveServices = true - modOptions.Tx = &autocliv1.ServiceCommandDescriptor{ - Service: cfg.msgServer.serviceName, - } + } else if mod, ok := mod.(module.HasServices); ok { + // try to auto-discover options based on the last msg and query + // services registered for the module + cfg := &autocliConfigurator{} + mod.RegisterServices(cfg) + modOptions := &autocliv1.ModuleOptions{} + haveServices := false + + if cfg.msgServer.serviceName != "" { + haveServices = true + modOptions.Tx = &autocliv1.ServiceCommandDescriptor{ + Service: cfg.msgServer.serviceName, } + } - if cfg.queryServer.serviceName != "" { - haveServices = true - modOptions.Query = &autocliv1.ServiceCommandDescriptor{ - Service: cfg.queryServer.serviceName, - } + if cfg.queryServer.serviceName != "" { + haveServices = true + modOptions.Query = &autocliv1.ServiceCommandDescriptor{ + Service: cfg.queryServer.serviceName, } + } - if haveServices { - moduleOptions[modName] = modOptions - } + if haveServices { + moduleOptions[modName] = modOptions } } } diff --git a/types/module/module.go b/types/module/module.go index f3108034a67c..7e5da87ba11d 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -172,14 +172,14 @@ type AppModule interface { AppModuleBasic } -// HasRegisterInvariants is the interface for registering invariants. +// HasInvariants is the interface for registering invariants. type HasInvariants interface { // RegisterInvariants registers module invariants. RegisterInvariants(sdk.InvariantRegistry) } -// HasRegisterServices is the interface for modules to register services. -type HasRegisterServices interface { +// HasServices is the interface for modules to register services. +type HasServices interface { // RegisterServices allows a module to register services. RegisterServices(Configurator) } @@ -326,7 +326,7 @@ func (m *Manager) SetOrderMigrations(moduleNames ...string) { func (m *Manager) RegisterInvariants(ir sdk.InvariantRegistry) { modules := maps.Values(m.Modules) for _, module := range modules { - if module, ok := module.(HasRegisterInvariants); ok { + if module, ok := module.(HasInvariants); ok { module.RegisterInvariants(ir) } } @@ -336,7 +336,7 @@ func (m *Manager) RegisterInvariants(ir sdk.InvariantRegistry) { func (m *Manager) RegisterServices(cfg Configurator) { modules := maps.Values(m.Modules) for _, module := range modules { - if module, ok := module.(HasRegisterSerices); ok { + if module, ok := module.(HasServices); ok { module.RegisterServices(cfg) } } From 408c65934969fd2bbf9ec700679915cb67276669 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Fri, 11 Nov 2022 14:14:07 -0500 Subject: [PATCH 16/19] remove ModuleBasicWrapper --- docs/docs/building-modules/14-depinject.md | 12 ++------ runtime/module.go | 33 ++++++++++++---------- runtime/wrappers.go | 18 ------------ x/auth/module.go | 10 +------ x/auth/vesting/module.go | 7 +---- x/authz/module/module.go | 10 +------ x/bank/module.go | 10 ++----- x/capability/module.go | 11 ++------ x/consensus/module.go | 6 +--- x/crisis/module.go | 7 +---- x/distribution/module.go | 7 +---- x/evidence/module.go | 7 +---- x/feegrant/module/module.go | 11 ++------ x/genutil/module.go | 7 +---- x/gov/module.go | 7 +---- x/group/module/module.go | 10 +------ x/mint/module.go | 7 +---- x/nft/module/module.go | 7 +---- x/params/module.go | 7 ----- x/slashing/module.go | 10 +------ x/staking/module.go | 7 +---- x/upgrade/module.go | 7 +---- 22 files changed, 42 insertions(+), 176 deletions(-) delete mode 100644 runtime/wrappers.go diff --git a/docs/docs/building-modules/14-depinject.md b/docs/docs/building-modules/14-depinject.md index 012ee5ba0267..c5ae142fd996 100644 --- a/docs/docs/building-modules/14-depinject.md +++ b/docs/docs/building-modules/14-depinject.md @@ -81,13 +81,7 @@ All methods, structs and their fields must be public for `depinject`. https://github.com/cosmos/cosmos-sdk/blob/main/x/group/module/module.go#L184-L192 ``` -2. `ProvideModuleBasic` is calls `WrapAppModuleBasic` for wrapping the module `AppModuleBasic`, so that it can be injected and used by the runtime module. - - ```go reference - https://github.com/cosmos/cosmos-sdk/blob/main/x/group/module/module.go#L194-L196 - ``` - -3. Define a struct that inherits `depinject.In` and define the module inputs (i.e. module dependencies): +2. Define a struct that inherits `depinject.In` and define the module inputs (i.e. module dependencies): * `depinject` provides the right dependencies to the module. * `depinject` also checks that all dependencies are provided. @@ -99,14 +93,14 @@ All methods, structs and their fields must be public for `depinject`. https://github.com/cosmos/cosmos-sdk/blob/main/x/group/module/module.go#L198-L208 ``` -4. Define the module outputs with a public struct that inherits `depinject.Out`: +3. Define the module outputs with a public struct that inherits `depinject.Out`: The module outputs are the dependencies that the module provides to other modules. It is usually the module itself and its keeper. ```go reference https://github.com/cosmos/cosmos-sdk/blob/main/x/group/module/module.go#L210-L215 ``` -5. Create a function named `ProvideModule` (as called in 1.) and use the inputs for instantiating the module outputs. +4. Create a function named `ProvideModule` (as called in 1.) and use the inputs for instantiating the module outputs. ```go reference https://github.com/cosmos/cosmos-sdk/blob/main/x/group/module/module.go#L217-L227 diff --git a/runtime/module.go b/runtime/module.go index 3a9a5e7caf68..d19f8df801c0 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -28,7 +28,7 @@ func (b BaseAppOption) IsManyPerContainerType() {} func init() { appmodule.Register(&runtimev1alpha1.Module{}, appmodule.Provide( - Provide, + ProvideApp, ProvideKVStoreKey, ProvideTransientStoreKey, ProvideMemoryStoreKey, @@ -38,7 +38,7 @@ func init() { ) } -func Provide(moduleBasics map[string]AppModuleBasicWrapper) ( +func ProvideApp() ( codectypes.InterfaceRegistry, codec.Codec, *codec.LegacyAmino, @@ -49,13 +49,6 @@ func Provide(moduleBasics map[string]AppModuleBasicWrapper) ( interfaceRegistry := codectypes.NewInterfaceRegistry() amino := codec.NewLegacyAmino() - // build codecs - basicManager := module.BasicManager{} - for name, wrapper := range moduleBasics { - basicManager[name] = wrapper - wrapper.RegisterInterfaces(interfaceRegistry) - wrapper.RegisterLegacyAminoCodec(amino) - } std.RegisterInterfaces(interfaceRegistry) std.RegisterLegacyAminoCodec(amino) @@ -67,7 +60,7 @@ func Provide(moduleBasics map[string]AppModuleBasicWrapper) ( interfaceRegistry: interfaceRegistry, cdc: cdc, amino: amino, - basicManager: basicManager, + basicManager: module.BasicManager{}, msgServiceRouter: msgServiceRouter, }, } @@ -78,11 +71,13 @@ func Provide(moduleBasics map[string]AppModuleBasicWrapper) ( type AppInputs struct { depinject.In - AppConfig *appv1alpha1.Config - Config *runtimev1alpha1.Module - AppBuilder *AppBuilder - Modules map[string]appmodule.AppModule - BaseAppOptions []BaseAppOption + AppConfig *appv1alpha1.Config + Config *runtimev1alpha1.Module + AppBuilder *AppBuilder + Modules map[string]appmodule.AppModule + BaseAppOptions []BaseAppOption + InterfaceRegistry codectypes.InterfaceRegistry + LegacyAmino *codec.LegacyAmino } func SetupAppBuilder(inputs AppInputs) { @@ -92,6 +87,14 @@ func SetupAppBuilder(inputs AppInputs) { app.config = inputs.Config app.ModuleManager = mm app.appConfig = inputs.AppConfig + + for name, mod := range inputs.Modules { + if basicMod, ok := mod.(module.AppModuleBasic); ok { + app.basicManager[name] = basicMod + basicMod.RegisterInterfaces(inputs.InterfaceRegistry) + basicMod.RegisterLegacyAminoCodec(inputs.LegacyAmino) + } + } } func registerStoreKey(wrapper *AppBuilder, key storetypes.StoreKey) { diff --git a/runtime/wrappers.go b/runtime/wrappers.go deleted file mode 100644 index ea914fc44598..000000000000 --- a/runtime/wrappers.go +++ /dev/null @@ -1,18 +0,0 @@ -package runtime - -import "github.com/cosmos/cosmos-sdk/types/module" - -// AppModuleBasicWrapper is a type used for injecting a module.AppModuleBasic -// into a container so that it can be used by the runtime module. -type AppModuleBasicWrapper struct { - module.AppModuleBasic -} - -// WrapAppModuleBasic wraps a module.AppModuleBasic so that it can be injected into -// a container for use by the runtime module. -func WrapAppModuleBasic(basic module.AppModuleBasic) AppModuleBasicWrapper { - return AppModuleBasicWrapper{AppModuleBasic: basic} -} - -// IsOnePerModuleType identifies this type as a depinject.OnePerModuleType. -func (AppModuleBasicWrapper) IsOnePerModuleType() {} diff --git a/x/auth/module.go b/x/auth/module.go index a278e9ca3247..3d62fd6fa9fd 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -18,7 +18,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/runtime" store "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" @@ -195,17 +194,10 @@ func (AppModule) WeightedOperations(_ module.SimulationState) []simtypes.Weighte func init() { appmodule.Register(&modulev1.Module{}, - appmodule.Provide( - ProvideModuleBasic, - ProvideModule, - ), + appmodule.Provide(ProvideModule), ) } -func ProvideModuleBasic() runtime.AppModuleBasicWrapper { - return runtime.WrapAppModuleBasic(AppModuleBasic{}) -} - type AuthInputs struct { depinject.In diff --git a/x/auth/vesting/module.go b/x/auth/vesting/module.go index a71e7cf41f15..f74cac7141e6 100644 --- a/x/auth/vesting/module.go +++ b/x/auth/vesting/module.go @@ -12,7 +12,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/runtime" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" @@ -126,14 +125,10 @@ func (AppModule) ConsensusVersion() uint64 { return 1 } func init() { appmodule.Register(&modulev1.Module{}, - appmodule.Provide(ProvideModuleBasic, ProvideModule), + appmodule.Provide(ProvideModule), ) } -func ProvideModuleBasic() runtime.AppModuleBasicWrapper { - return runtime.WrapAppModuleBasic(AppModuleBasic{}) -} - type VestingInputs struct { depinject.In diff --git a/x/authz/module/module.go b/x/authz/module/module.go index 4622e9bebc1a..16e4e7d84b27 100644 --- a/x/authz/module/module.go +++ b/x/authz/module/module.go @@ -18,7 +18,6 @@ import ( sdkclient "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/runtime" store "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -168,17 +167,10 @@ func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { func init() { appmodule.Register( &modulev1.Module{}, - appmodule.Provide( - ProvideModuleBasic, - ProvideModule, - ), + appmodule.Provide(ProvideModule), ) } -func ProvideModuleBasic() runtime.AppModuleBasicWrapper { - return runtime.WrapAppModuleBasic(AppModuleBasic{}) -} - type AuthzInputs struct { depinject.In diff --git a/x/bank/module.go b/x/bank/module.go index fab8c9c7b640..16e522a57350 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -18,7 +18,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/runtime" store "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" @@ -204,13 +203,8 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp func init() { appmodule.Register(&modulev1.Module{}, - appmodule.Provide( - ProvideModuleBasic, - ProvideModule)) -} - -func ProvideModuleBasic() runtime.AppModuleBasicWrapper { - return runtime.WrapAppModuleBasic(AppModuleBasic{}) + appmodule.Provide(ProvideModule), + ) } type BankInputs struct { diff --git a/x/capability/module.go b/x/capability/module.go index cc223588d15c..8971e9e8d4ca 100644 --- a/x/capability/module.go +++ b/x/capability/module.go @@ -18,7 +18,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/runtime" store "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" @@ -184,14 +183,8 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp func init() { appmodule.Register(&modulev1.Module{}, - appmodule.Provide( - ProvideModuleBasic, - ProvideModule, - )) -} - -func ProvideModuleBasic() runtime.AppModuleBasicWrapper { - return runtime.WrapAppModuleBasic(AppModuleBasic{}) + appmodule.Provide(ProvideModule), + ) } type CapabilityInputs struct { diff --git a/x/consensus/module.go b/x/consensus/module.go index 8afe08940585..dc72c6f34520 100644 --- a/x/consensus/module.go +++ b/x/consensus/module.go @@ -131,14 +131,10 @@ func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {} func init() { appmodule.Register( &modulev1.Module{}, - appmodule.Provide(ProvideModuleBasic, ProvideModule), + appmodule.Provide(ProvideModule), ) } -func ProvideModuleBasic() runtime.AppModuleBasicWrapper { - return runtime.WrapAppModuleBasic(AppModuleBasic{}) -} - type ConsensusParamInputs struct { depinject.In diff --git a/x/crisis/module.go b/x/crisis/module.go index 010cb061ee34..0e8676e95018 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -17,7 +17,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/server" servertypes "github.com/cosmos/cosmos-sdk/server/types" store "github.com/cosmos/cosmos-sdk/store/types" @@ -188,7 +187,7 @@ func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.Val func init() { appmodule.Register( &modulev1.Module{}, - appmodule.Provide(ProvideModuleBasic, ProvideModule), + appmodule.Provide(ProvideModule), ) } @@ -213,10 +212,6 @@ type CrisisOutputs struct { CrisisKeeper *keeper.Keeper } -func ProvideModuleBasic() runtime.AppModuleBasicWrapper { - return runtime.WrapAppModuleBasic(AppModuleBasic{}) -} - func ProvideModule(in CrisisInputs) CrisisOutputs { var invalidCheckPeriod uint if in.AppOpts != nil { diff --git a/x/distribution/module.go b/x/distribution/module.go index 4d1602d1201f..432e3a851f91 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -16,7 +16,6 @@ import ( sdkclient "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/runtime" store "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" @@ -209,14 +208,10 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp func init() { appmodule.Register(&modulev1.Module{}, - appmodule.Provide(ProvideModuleBasic, ProvideModule), + appmodule.Provide(ProvideModule), ) } -func ProvideModuleBasic() runtime.AppModuleBasicWrapper { - return runtime.WrapAppModuleBasic(AppModuleBasic{}) -} - type DistrInputs struct { depinject.In diff --git a/x/evidence/module.go b/x/evidence/module.go index fe01af735b6c..2348a67f13e3 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -16,7 +16,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/runtime" store "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" @@ -200,14 +199,10 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp func init() { appmodule.Register(&modulev1.Module{}, - appmodule.Provide(ProvideModuleBasic, ProvideModule), + appmodule.Provide(ProvideModule), ) } -func ProvideModuleBasic() runtime.AppModuleBasicWrapper { - return runtime.WrapAppModuleBasic(AppModuleBasic{}) -} - type EvidenceInputs struct { depinject.In diff --git a/x/feegrant/module/module.go b/x/feegrant/module/module.go index c588c0575bb2..f9c462fcafb2 100644 --- a/x/feegrant/module/module.go +++ b/x/feegrant/module/module.go @@ -18,7 +18,6 @@ import ( sdkclient "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/runtime" store "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -181,14 +180,8 @@ func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.Val func init() { appmodule.Register(&modulev1.Module{}, - appmodule.Provide( - ProvideModuleBasic, - ProvideModule, - )) -} - -func ProvideModuleBasic() runtime.AppModuleBasicWrapper { - return runtime.WrapAppModuleBasic(AppModuleBasic{}) + appmodule.Provide(ProvideModule), + ) } type FeegrantInputs struct { diff --git a/x/genutil/module.go b/x/genutil/module.go index 631da886aaa0..a4f660ee42f4 100644 --- a/x/genutil/module.go +++ b/x/genutil/module.go @@ -16,7 +16,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/runtime" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/genutil/types" @@ -129,14 +128,10 @@ func (AppModule) ConsensusVersion() uint64 { return 1 } func init() { appmodule.Register(&modulev1.Module{}, - appmodule.Provide(ProvideModuleBasic, ProvideModule), + appmodule.Provide(ProvideModule), ) } -func ProvideModuleBasic() runtime.AppModuleBasicWrapper { - return runtime.WrapAppModuleBasic(AppModuleBasic{}) -} - type GenutilInputs struct { depinject.In diff --git a/x/gov/module.go b/x/gov/module.go index 50c13c1cad66..b33ade55c2a0 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -22,7 +22,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/runtime" store "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" @@ -159,14 +158,10 @@ func (am AppModule) IsAppModule() {} func init() { appmodule.Register( &modulev1.Module{}, - appmodule.Provide(ProvideModuleBasic, ProvideModule, ProvideKeyTable), + appmodule.Provide(ProvideModule, ProvideKeyTable), appmodule.Invoke(InvokeAddRoutes, InvokeSetHooks)) } -func ProvideModuleBasic() runtime.AppModuleBasicWrapper { - return runtime.WrapAppModuleBasic(AppModuleBasic{}) -} - type GovInputs struct { depinject.In diff --git a/x/group/module/module.go b/x/group/module/module.go index a4f905f641a9..75b1a6be657b 100644 --- a/x/group/module/module.go +++ b/x/group/module/module.go @@ -18,7 +18,6 @@ import ( sdkclient "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/runtime" store "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" @@ -193,17 +192,10 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp func init() { appmodule.Register( &modulev1.Module{}, - appmodule.Provide( - ProvideModuleBasic, - ProvideModule, - ), + appmodule.Provide(ProvideModule), ) } -func ProvideModuleBasic() runtime.AppModuleBasicWrapper { - return runtime.WrapAppModuleBasic(AppModuleBasic{}) -} - type GroupInputs struct { depinject.In diff --git a/x/mint/module.go b/x/mint/module.go index 4cf4711fec07..d47763708536 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -17,7 +17,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/runtime" store "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" @@ -212,14 +211,10 @@ func (AppModule) WeightedOperations(_ module.SimulationState) []simtypes.Weighte func init() { appmodule.Register(&modulev1.Module{}, - appmodule.Provide(ProvideModuleBasic, ProvideModule), + appmodule.Provide(ProvideModule), ) } -func ProvideModuleBasic() runtime.AppModuleBasicWrapper { - return runtime.WrapAppModuleBasic(AppModuleBasic{}) -} - type MintInputs struct { depinject.In diff --git a/x/nft/module/module.go b/x/nft/module/module.go index bd85e71b4500..d4036f55faaa 100644 --- a/x/nft/module/module.go +++ b/x/nft/module/module.go @@ -14,7 +14,6 @@ import ( sdkclient "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/runtime" store "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -188,14 +187,10 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp func init() { appmodule.Register(&modulev1.Module{}, - appmodule.Provide(ProvideModuleBasic, ProvideModule), + appmodule.Provide(ProvideModule), ) } -func ProvideModuleBasic() runtime.AppModuleBasicWrapper { - return runtime.WrapAppModuleBasic(AppModuleBasic{}) -} - type NftInputs struct { depinject.In diff --git a/x/params/module.go b/x/params/module.go index 96ea866c8728..90e7976ae659 100644 --- a/x/params/module.go +++ b/x/params/module.go @@ -14,8 +14,6 @@ import ( "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" - "github.com/cosmos/cosmos-sdk/runtime" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -144,16 +142,11 @@ func (AppModule) ConsensusVersion() uint64 { return 1 } func init() { appmodule.Register(&modulev1.Module{}, appmodule.Provide( - ProvideModuleBasic, ProvideModule, ProvideSubspace, )) } -func ProvideModuleBasic() runtime.AppModuleBasicWrapper { - return runtime.WrapAppModuleBasic(AppModuleBasic{}) -} - type ParamsInputs struct { depinject.In diff --git a/x/slashing/module.go b/x/slashing/module.go index 63b8b05e5c05..a18a2c8ea015 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -16,7 +16,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/runtime" store "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" @@ -207,17 +206,10 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp func init() { appmodule.Register( &modulev1.Module{}, - appmodule.Provide( - ProvideModuleBasic, - ProvideModule, - ), + appmodule.Provide(ProvideModule), ) } -func ProvideModuleBasic() runtime.AppModuleBasicWrapper { - return runtime.WrapAppModuleBasic(AppModuleBasic{}) -} - type SlashingInputs struct { depinject.In diff --git a/x/staking/module.go b/x/staking/module.go index 356c4c50eae7..d693d47eb3f8 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -22,7 +22,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/runtime" store "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" @@ -196,15 +195,11 @@ func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.Val func init() { appmodule.Register( &modulev1.Module{}, - appmodule.Provide(ProvideModuleBasic, ProvideModule), + appmodule.Provide(ProvideModule), appmodule.Invoke(InvokeSetStakingHooks), ) } -func ProvideModuleBasic() runtime.AppModuleBasicWrapper { - return runtime.WrapAppModuleBasic(AppModuleBasic{}) -} - type StakingInputs struct { depinject.In diff --git a/x/upgrade/module.go b/x/upgrade/module.go index 203e723edc4a..9f60995c95e3 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -19,7 +19,6 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/server" servertypes "github.com/cosmos/cosmos-sdk/server/types" store "github.com/cosmos/cosmos-sdk/store/types" @@ -155,14 +154,10 @@ func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { func init() { appmodule.Register(&modulev1.Module{}, - appmodule.Provide(ProvideModuleBasic, ProvideModule), + appmodule.Provide(ProvideModule), ) } -func ProvideModuleBasic() runtime.AppModuleBasicWrapper { - return runtime.WrapAppModuleBasic(AppModuleBasic{}) -} - type UpgradeInputs struct { depinject.In From 7a99acbf37b0cef7792200a829ea96117a228e44 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Mon, 14 Nov 2022 10:30:31 -0500 Subject: [PATCH 17/19] fix test failures --- simapp/app_test.go | 2 +- types/module/module_int_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/simapp/app_test.go b/simapp/app_test.go index 875fcfb8816f..ac6794950f86 100644 --- a/simapp/app_test.go +++ b/simapp/app_test.go @@ -86,7 +86,7 @@ func TestRunMigrations(t *testing.T) { continue } - if mod, ok := mod.(module.HasRegisterSerices); ok { + if mod, ok := mod.(module.HasServices); ok { mod.RegisterServices(configurator) } } diff --git a/types/module/module_int_test.go b/types/module/module_int_test.go index 3301a9926d6a..13bf6aa97c05 100644 --- a/types/module/module_int_test.go +++ b/types/module/module_int_test.go @@ -17,7 +17,7 @@ type TestSuite struct { func (s TestSuite) TestAssertNoForgottenModules() { m := Manager{ - Modules: map[string]AppModule{"a": nil, "b": nil}, + Modules: map[string]interface{}{"a": nil, "b": nil}, } tcs := []struct { name string @@ -39,7 +39,7 @@ func (s TestSuite) TestAssertNoForgottenModules() { func (s TestSuite) TestModuleNames() { m := Manager{ - Modules: map[string]AppModule{"a": nil, "b": nil}, + Modules: map[string]interface{}{"a": nil, "b": nil}, } ms := m.ModuleNames() sort.Strings(ms) From 213865237fe3433df04f8c47b602e63e726ba70e Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Mon, 14 Nov 2022 14:36:33 -0500 Subject: [PATCH 18/19] fix mock tests --- scripts/mockgen.sh | 1 + testutil/mock/types_mock_appmodule.go | 241 ++++++++++++++++++++++++++ testutil/mock/types_module_module.go | 56 +++--- types/module/mock_appmodule_test.go | 15 ++ types/module/module_test.go | 16 +- 5 files changed, 293 insertions(+), 36 deletions(-) create mode 100644 testutil/mock/types_mock_appmodule.go create mode 100644 types/module/mock_appmodule_test.go diff --git a/scripts/mockgen.sh b/scripts/mockgen.sh index d32956c6cb42..6022c03db699 100755 --- a/scripts/mockgen.sh +++ b/scripts/mockgen.sh @@ -4,6 +4,7 @@ mockgen_cmd="mockgen" $mockgen_cmd -source=client/account_retriever.go -package mock -destination testutil/mock/account_retriever.go $mockgen_cmd -package mock -destination testutil/mock/tendermint_tm_db_DB.go github.com/tendermint/tm-db DB $mockgen_cmd -source=types/module/module.go -package mock -destination testutil/mock/types_module_module.go +$mockgen_cmd -source=types/module/mock_appmodule_test.go -package mock -destination testutil/mock/types_mock_appmodule.go $mockgen_cmd -source=types/invariant.go -package mock -destination testutil/mock/types_invariant.go $mockgen_cmd -package mock -destination testutil/mock/grpc_server.go github.com/cosmos/gogoproto/grpc Server $mockgen_cmd -package mock -destination testutil/mock/tendermint_tendermint_libs_log_DB.go github.com/tendermint/tendermint/libs/log Logger diff --git a/testutil/mock/types_mock_appmodule.go b/testutil/mock/types_mock_appmodule.go new file mode 100644 index 000000000000..06e12df03c9f --- /dev/null +++ b/testutil/mock/types_mock_appmodule.go @@ -0,0 +1,241 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: types/module/mock_appmodule_test.go + +// Package mock is a generated GoMock package. +package mock + +import ( + json "encoding/json" + reflect "reflect" + + client "github.com/cosmos/cosmos-sdk/client" + codec "github.com/cosmos/cosmos-sdk/codec" + types "github.com/cosmos/cosmos-sdk/codec/types" + types0 "github.com/cosmos/cosmos-sdk/types" + module "github.com/cosmos/cosmos-sdk/types/module" + gomock "github.com/golang/mock/gomock" + runtime "github.com/grpc-ecosystem/grpc-gateway/runtime" + cobra "github.com/spf13/cobra" + types1 "github.com/tendermint/tendermint/abci/types" +) + +// MockAppModuleWithAllExtensions is a mock of AppModuleWithAllExtensions interface. +type MockAppModuleWithAllExtensions struct { + ctrl *gomock.Controller + recorder *MockAppModuleWithAllExtensionsMockRecorder +} + +// MockAppModuleWithAllExtensionsMockRecorder is the mock recorder for MockAppModuleWithAllExtensions. +type MockAppModuleWithAllExtensionsMockRecorder struct { + mock *MockAppModuleWithAllExtensions +} + +// NewMockAppModuleWithAllExtensions creates a new mock instance. +func NewMockAppModuleWithAllExtensions(ctrl *gomock.Controller) *MockAppModuleWithAllExtensions { + mock := &MockAppModuleWithAllExtensions{ctrl: ctrl} + mock.recorder = &MockAppModuleWithAllExtensionsMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockAppModuleWithAllExtensions) EXPECT() *MockAppModuleWithAllExtensionsMockRecorder { + return m.recorder +} + +// BeginBlock mocks base method. +func (m *MockAppModuleWithAllExtensions) BeginBlock(arg0 types0.Context, arg1 types1.RequestBeginBlock) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "BeginBlock", arg0, arg1) +} + +// BeginBlock indicates an expected call of BeginBlock. +func (mr *MockAppModuleWithAllExtensionsMockRecorder) BeginBlock(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BeginBlock", reflect.TypeOf((*MockAppModuleWithAllExtensions)(nil).BeginBlock), arg0, arg1) +} + +// ConsensusVersion mocks base method. +func (m *MockAppModuleWithAllExtensions) ConsensusVersion() uint64 { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ConsensusVersion") + ret0, _ := ret[0].(uint64) + return ret0 +} + +// ConsensusVersion indicates an expected call of ConsensusVersion. +func (mr *MockAppModuleWithAllExtensionsMockRecorder) ConsensusVersion() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConsensusVersion", reflect.TypeOf((*MockAppModuleWithAllExtensions)(nil).ConsensusVersion)) +} + +// DefaultGenesis mocks base method. +func (m *MockAppModuleWithAllExtensions) DefaultGenesis(arg0 codec.JSONCodec) json.RawMessage { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DefaultGenesis", arg0) + ret0, _ := ret[0].(json.RawMessage) + return ret0 +} + +// DefaultGenesis indicates an expected call of DefaultGenesis. +func (mr *MockAppModuleWithAllExtensionsMockRecorder) DefaultGenesis(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DefaultGenesis", reflect.TypeOf((*MockAppModuleWithAllExtensions)(nil).DefaultGenesis), arg0) +} + +// EndBlock mocks base method. +func (m *MockAppModuleWithAllExtensions) EndBlock(arg0 types0.Context, arg1 types1.RequestEndBlock) []types1.ValidatorUpdate { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "EndBlock", arg0, arg1) + ret0, _ := ret[0].([]types1.ValidatorUpdate) + return ret0 +} + +// EndBlock indicates an expected call of EndBlock. +func (mr *MockAppModuleWithAllExtensionsMockRecorder) EndBlock(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EndBlock", reflect.TypeOf((*MockAppModuleWithAllExtensions)(nil).EndBlock), arg0, arg1) +} + +// ExportGenesis mocks base method. +func (m *MockAppModuleWithAllExtensions) ExportGenesis(arg0 types0.Context, arg1 codec.JSONCodec) json.RawMessage { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ExportGenesis", arg0, arg1) + ret0, _ := ret[0].(json.RawMessage) + return ret0 +} + +// ExportGenesis indicates an expected call of ExportGenesis. +func (mr *MockAppModuleWithAllExtensionsMockRecorder) ExportGenesis(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExportGenesis", reflect.TypeOf((*MockAppModuleWithAllExtensions)(nil).ExportGenesis), arg0, arg1) +} + +// GetQueryCmd mocks base method. +func (m *MockAppModuleWithAllExtensions) GetQueryCmd() *cobra.Command { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetQueryCmd") + ret0, _ := ret[0].(*cobra.Command) + return ret0 +} + +// GetQueryCmd indicates an expected call of GetQueryCmd. +func (mr *MockAppModuleWithAllExtensionsMockRecorder) GetQueryCmd() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetQueryCmd", reflect.TypeOf((*MockAppModuleWithAllExtensions)(nil).GetQueryCmd)) +} + +// GetTxCmd mocks base method. +func (m *MockAppModuleWithAllExtensions) GetTxCmd() *cobra.Command { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetTxCmd") + ret0, _ := ret[0].(*cobra.Command) + return ret0 +} + +// GetTxCmd indicates an expected call of GetTxCmd. +func (mr *MockAppModuleWithAllExtensionsMockRecorder) GetTxCmd() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTxCmd", reflect.TypeOf((*MockAppModuleWithAllExtensions)(nil).GetTxCmd)) +} + +// InitGenesis mocks base method. +func (m *MockAppModuleWithAllExtensions) InitGenesis(arg0 types0.Context, arg1 codec.JSONCodec, arg2 json.RawMessage) []types1.ValidatorUpdate { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "InitGenesis", arg0, arg1, arg2) + ret0, _ := ret[0].([]types1.ValidatorUpdate) + return ret0 +} + +// InitGenesis indicates an expected call of InitGenesis. +func (mr *MockAppModuleWithAllExtensionsMockRecorder) InitGenesis(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InitGenesis", reflect.TypeOf((*MockAppModuleWithAllExtensions)(nil).InitGenesis), arg0, arg1, arg2) +} + +// Name mocks base method. +func (m *MockAppModuleWithAllExtensions) Name() string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Name") + ret0, _ := ret[0].(string) + return ret0 +} + +// Name indicates an expected call of Name. +func (mr *MockAppModuleWithAllExtensionsMockRecorder) Name() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockAppModuleWithAllExtensions)(nil).Name)) +} + +// RegisterGRPCGatewayRoutes mocks base method. +func (m *MockAppModuleWithAllExtensions) RegisterGRPCGatewayRoutes(arg0 client.Context, arg1 *runtime.ServeMux) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterGRPCGatewayRoutes", arg0, arg1) +} + +// RegisterGRPCGatewayRoutes indicates an expected call of RegisterGRPCGatewayRoutes. +func (mr *MockAppModuleWithAllExtensionsMockRecorder) RegisterGRPCGatewayRoutes(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterGRPCGatewayRoutes", reflect.TypeOf((*MockAppModuleWithAllExtensions)(nil).RegisterGRPCGatewayRoutes), arg0, arg1) +} + +// RegisterInterfaces mocks base method. +func (m *MockAppModuleWithAllExtensions) RegisterInterfaces(arg0 types.InterfaceRegistry) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterInterfaces", arg0) +} + +// RegisterInterfaces indicates an expected call of RegisterInterfaces. +func (mr *MockAppModuleWithAllExtensionsMockRecorder) RegisterInterfaces(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInterfaces", reflect.TypeOf((*MockAppModuleWithAllExtensions)(nil).RegisterInterfaces), arg0) +} + +// RegisterInvariants mocks base method. +func (m *MockAppModuleWithAllExtensions) RegisterInvariants(arg0 types0.InvariantRegistry) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterInvariants", arg0) +} + +// RegisterInvariants indicates an expected call of RegisterInvariants. +func (mr *MockAppModuleWithAllExtensionsMockRecorder) RegisterInvariants(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInvariants", reflect.TypeOf((*MockAppModuleWithAllExtensions)(nil).RegisterInvariants), arg0) +} + +// RegisterLegacyAminoCodec mocks base method. +func (m *MockAppModuleWithAllExtensions) RegisterLegacyAminoCodec(arg0 *codec.LegacyAmino) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterLegacyAminoCodec", arg0) +} + +// RegisterLegacyAminoCodec indicates an expected call of RegisterLegacyAminoCodec. +func (mr *MockAppModuleWithAllExtensionsMockRecorder) RegisterLegacyAminoCodec(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterLegacyAminoCodec", reflect.TypeOf((*MockAppModuleWithAllExtensions)(nil).RegisterLegacyAminoCodec), arg0) +} + +// RegisterServices mocks base method. +func (m *MockAppModuleWithAllExtensions) RegisterServices(arg0 module.Configurator) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterServices", arg0) +} + +// RegisterServices indicates an expected call of RegisterServices. +func (mr *MockAppModuleWithAllExtensionsMockRecorder) RegisterServices(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterServices", reflect.TypeOf((*MockAppModuleWithAllExtensions)(nil).RegisterServices), arg0) +} + +// ValidateGenesis mocks base method. +func (m *MockAppModuleWithAllExtensions) ValidateGenesis(arg0 codec.JSONCodec, arg1 client.TxEncodingConfig, arg2 json.RawMessage) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ValidateGenesis", arg0, arg1, arg2) + ret0, _ := ret[0].(error) + return ret0 +} + +// ValidateGenesis indicates an expected call of ValidateGenesis. +func (mr *MockAppModuleWithAllExtensionsMockRecorder) ValidateGenesis(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesis", reflect.TypeOf((*MockAppModuleWithAllExtensions)(nil).ValidateGenesis), arg0, arg1, arg2) +} diff --git a/testutil/mock/types_module_module.go b/testutil/mock/types_module_module.go index 579b30755bdd..b00e8b8c4d59 100644 --- a/testutil/mock/types_module_module.go +++ b/testutil/mock/types_module_module.go @@ -601,74 +601,74 @@ func (mr *MockAppModuleMockRecorder) ValidateGenesis(arg0, arg1, arg2 interface{ return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesis", reflect.TypeOf((*MockAppModule)(nil).ValidateGenesis), arg0, arg1, arg2) } -// MockHasRegisterInvariants is a mock of HasRegisterInvariants interface. -type MockHasRegisterInvariants struct { +// MockHasInvariants is a mock of HasInvariants interface. +type MockHasInvariants struct { ctrl *gomock.Controller - recorder *MockHasRegisterInvariantsMockRecorder + recorder *MockHasInvariantsMockRecorder } -// MockHasRegisterInvariantsMockRecorder is the mock recorder for MockHasRegisterInvariants. -type MockHasRegisterInvariantsMockRecorder struct { - mock *MockHasRegisterInvariants +// MockHasInvariantsMockRecorder is the mock recorder for MockHasInvariants. +type MockHasInvariantsMockRecorder struct { + mock *MockHasInvariants } -// NewMockHasRegisterInvariants creates a new mock instance. -func NewMockHasRegisterInvariants(ctrl *gomock.Controller) *MockHasRegisterInvariants { - mock := &MockHasRegisterInvariants{ctrl: ctrl} - mock.recorder = &MockHasRegisterInvariantsMockRecorder{mock} +// NewMockHasInvariants creates a new mock instance. +func NewMockHasInvariants(ctrl *gomock.Controller) *MockHasInvariants { + mock := &MockHasInvariants{ctrl: ctrl} + mock.recorder = &MockHasInvariantsMockRecorder{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockHasRegisterInvariants) EXPECT() *MockHasRegisterInvariantsMockRecorder { +func (m *MockHasInvariants) EXPECT() *MockHasInvariantsMockRecorder { return m.recorder } // RegisterInvariants mocks base method. -func (m *MockHasRegisterInvariants) RegisterInvariants(arg0 types0.InvariantRegistry) { +func (m *MockHasInvariants) RegisterInvariants(arg0 types0.InvariantRegistry) { m.ctrl.T.Helper() m.ctrl.Call(m, "RegisterInvariants", arg0) } // RegisterInvariants indicates an expected call of RegisterInvariants. -func (mr *MockHasRegisterInvariantsMockRecorder) RegisterInvariants(arg0 interface{}) *gomock.Call { +func (mr *MockHasInvariantsMockRecorder) RegisterInvariants(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInvariants", reflect.TypeOf((*MockHasRegisterInvariants)(nil).RegisterInvariants), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInvariants", reflect.TypeOf((*MockHasInvariants)(nil).RegisterInvariants), arg0) } -// MockHasRegisterSerices is a mock of HasRegisterSerices interface. -type MockHasRegisterSerices struct { +// MockHasServices is a mock of HasServices interface. +type MockHasServices struct { ctrl *gomock.Controller - recorder *MockHasRegisterSericesMockRecorder + recorder *MockHasServicesMockRecorder } -// MockHasRegisterSericesMockRecorder is the mock recorder for MockHasRegisterSerices. -type MockHasRegisterSericesMockRecorder struct { - mock *MockHasRegisterSerices +// MockHasServicesMockRecorder is the mock recorder for MockHasServices. +type MockHasServicesMockRecorder struct { + mock *MockHasServices } -// NewMockHasRegisterSerices creates a new mock instance. -func NewMockHasRegisterSerices(ctrl *gomock.Controller) *MockHasRegisterSerices { - mock := &MockHasRegisterSerices{ctrl: ctrl} - mock.recorder = &MockHasRegisterSericesMockRecorder{mock} +// NewMockHasServices creates a new mock instance. +func NewMockHasServices(ctrl *gomock.Controller) *MockHasServices { + mock := &MockHasServices{ctrl: ctrl} + mock.recorder = &MockHasServicesMockRecorder{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockHasRegisterSerices) EXPECT() *MockHasRegisterSericesMockRecorder { +func (m *MockHasServices) EXPECT() *MockHasServicesMockRecorder { return m.recorder } // RegisterServices mocks base method. -func (m *MockHasRegisterSerices) RegisterServices(arg0 module.Configurator) { +func (m *MockHasServices) RegisterServices(arg0 module.Configurator) { m.ctrl.T.Helper() m.ctrl.Call(m, "RegisterServices", arg0) } // RegisterServices indicates an expected call of RegisterServices. -func (mr *MockHasRegisterSericesMockRecorder) RegisterServices(arg0 interface{}) *gomock.Call { +func (mr *MockHasServicesMockRecorder) RegisterServices(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterServices", reflect.TypeOf((*MockHasRegisterSerices)(nil).RegisterServices), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterServices", reflect.TypeOf((*MockHasServices)(nil).RegisterServices), arg0) } // MockHasConsensusVersion is a mock of HasConsensusVersion interface. diff --git a/types/module/mock_appmodule_test.go b/types/module/mock_appmodule_test.go new file mode 100644 index 000000000000..e16363f1fde1 --- /dev/null +++ b/types/module/mock_appmodule_test.go @@ -0,0 +1,15 @@ +package module_test + +import "github.com/cosmos/cosmos-sdk/types/module" + +// AppModuleWithAllExtensions is solely here for the purpose of generating +// mocks to be used in module tests. +type AppModuleWithAllExtensions interface { + module.AppModule + module.HasServices + module.HasGenesis + module.HasInvariants + module.HasConsensusVersion + module.BeginBlockAppModule + module.EndBlockAppModule +} diff --git a/types/module/module_test.go b/types/module/module_test.go index dd6ad46b88e8..7d9bab2a6046 100644 --- a/types/module/module_test.go +++ b/types/module/module_test.go @@ -107,8 +107,8 @@ func TestManager_RegisterInvariants(t *testing.T) { mockCtrl := gomock.NewController(t) t.Cleanup(mockCtrl.Finish) - mockAppModule1 := mock.NewMockAppModule(mockCtrl) - mockAppModule2 := mock.NewMockAppModule(mockCtrl) + mockAppModule1 := mock.NewMockAppModuleWithAllExtensions(mockCtrl) + mockAppModule2 := mock.NewMockAppModuleWithAllExtensions(mockCtrl) mockAppModule1.EXPECT().Name().Times(2).Return("module1") mockAppModule2.EXPECT().Name().Times(2).Return("module2") mm := module.NewManager(mockAppModule1, mockAppModule2) @@ -126,8 +126,8 @@ func TestManager_RegisterQueryServices(t *testing.T) { mockCtrl := gomock.NewController(t) t.Cleanup(mockCtrl.Finish) - mockAppModule1 := mock.NewMockAppModule(mockCtrl) - mockAppModule2 := mock.NewMockAppModule(mockCtrl) + mockAppModule1 := mock.NewMockAppModuleWithAllExtensions(mockCtrl) + mockAppModule2 := mock.NewMockAppModuleWithAllExtensions(mockCtrl) mockAppModule1.EXPECT().Name().Times(2).Return("module1") mockAppModule2.EXPECT().Name().Times(2).Return("module2") mm := module.NewManager(mockAppModule1, mockAppModule2) @@ -149,8 +149,8 @@ func TestManager_InitGenesis(t *testing.T) { mockCtrl := gomock.NewController(t) t.Cleanup(mockCtrl.Finish) - mockAppModule1 := mock.NewMockAppModule(mockCtrl) - mockAppModule2 := mock.NewMockAppModule(mockCtrl) + mockAppModule1 := mock.NewMockAppModuleWithAllExtensions(mockCtrl) + mockAppModule2 := mock.NewMockAppModuleWithAllExtensions(mockCtrl) mockAppModule1.EXPECT().Name().Times(2).Return("module1") mockAppModule2.EXPECT().Name().Times(2).Return("module2") mm := module.NewManager(mockAppModule1, mockAppModule2) @@ -180,8 +180,8 @@ func TestManager_ExportGenesis(t *testing.T) { mockCtrl := gomock.NewController(t) t.Cleanup(mockCtrl.Finish) - mockAppModule1 := mock.NewMockAppModule(mockCtrl) - mockAppModule2 := mock.NewMockAppModule(mockCtrl) + mockAppModule1 := mock.NewMockAppModuleWithAllExtensions(mockCtrl) + mockAppModule2 := mock.NewMockAppModuleWithAllExtensions(mockCtrl) mockAppModule1.EXPECT().Name().Times(2).Return("module1") mockAppModule2.EXPECT().Name().Times(2).Return("module2") mm := module.NewManager(mockAppModule1, mockAppModule2) From 893d37d25ef88af5c408fd065dc3d9ce2d0b9a22 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Mon, 14 Nov 2022 16:03:18 -0500 Subject: [PATCH 19/19] fix tests --- simapp/app_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/simapp/app_test.go b/simapp/app_test.go index ac6794950f86..e9175e9bb2f3 100644 --- a/simapp/app_test.go +++ b/simapp/app_test.go @@ -208,9 +208,11 @@ func TestInitGenesisOnMigration(t *testing.T) { // adding during a migration. mockCtrl := gomock.NewController(t) t.Cleanup(mockCtrl.Finish) - mockModule := mock.NewMockAppModule(mockCtrl) + mockModule := mock.NewMockAppModuleWithAllExtensions(mockCtrl) mockDefaultGenesis := json.RawMessage(`{"key": "value"}`) mockModule.EXPECT().DefaultGenesis(gomock.Eq(app.appCodec)).Times(1).Return(mockDefaultGenesis) + mockModule.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(app.appCodec), gomock.Eq(mockDefaultGenesis)).Times(1).Return(nil) + mockModule.EXPECT().ConsensusVersion().Times(1).Return(uint64(0)) app.ModuleManager.Modules["mock"] = mockModule