refactor!: kill basic manager (#19512)

This commit is contained in:
Julien Robert
2024-02-22 14:44:49 +00:00
committed by GitHub
parent d1d3bf0620
commit b304cf7556
170 changed files with 1629 additions and 2324 deletions
+26 -30
View File
@@ -19,33 +19,31 @@ import (
)
var (
_ appmodule.AppModule = coreAppModuleBasicAdaptor{}
_ appmodule.AppModule = coreAppModuleAdaptor{}
_ AppModuleBasic = coreAppModuleBasicAdaptor{}
_ HasABCIGenesis = coreAppModuleBasicAdaptor{}
_ HasServices = coreAppModuleBasicAdaptor{}
_ HasName = coreAppModuleAdaptor{}
_ HasAminoCodec = coreAppModuleAdaptor{}
_ HasGRPCGateway = coreAppModuleAdaptor{}
_ HasRegisterInterfaces = coreAppModuleAdaptor{}
_ HasABCIGenesis = coreAppModuleAdaptor{}
_ HasServices = coreAppModuleAdaptor{}
)
// CoreAppModuleAdaptor wraps the core API module as an AppModule that this version of the SDK can use.
func CoreAppModuleAdaptor(name string, module appmodule.AppModule) AppModule {
return coreAppModuleBasicAdaptor{
return coreAppModuleAdaptor{
name: name,
module: module,
}
}
// CoreAppModuleBasicAdaptor wraps the core API module as an AppModule that this version of the SDK can use.
func CoreAppModuleBasicAdaptor(name string, module appmodule.AppModule) AppModule {
return CoreAppModuleAdaptor(name, module)
}
type coreAppModuleBasicAdaptor struct {
type coreAppModuleAdaptor struct {
name string
module appmodule.AppModule
}
// DefaultGenesis implements HasGenesis
func (c coreAppModuleBasicAdaptor) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
func (c coreAppModuleAdaptor) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
if mod, ok := c.module.(appmodule.HasGenesis); ok {
target := genesis.RawJSONTarget{}
err := mod.DefaultGenesis(target.Target())
@@ -69,7 +67,7 @@ func (c coreAppModuleBasicAdaptor) DefaultGenesis(cdc codec.JSONCodec) json.RawM
}
// ValidateGenesis implements HasGenesis
func (c coreAppModuleBasicAdaptor) ValidateGenesis(cdc codec.JSONCodec, txConfig client.TxEncodingConfig, bz json.RawMessage) error {
func (c coreAppModuleAdaptor) ValidateGenesis(cdc codec.JSONCodec, txConfig client.TxEncodingConfig, bz json.RawMessage) error {
if mod, ok := c.module.(appmodule.HasGenesis); ok {
source, err := genesis.SourceFromRawJSON(bz)
if err != nil {
@@ -89,7 +87,7 @@ func (c coreAppModuleBasicAdaptor) ValidateGenesis(cdc codec.JSONCodec, txConfig
}
// ExportGenesis implements HasGenesis
func (c coreAppModuleBasicAdaptor) ExportGenesis(ctx context.Context, cdc codec.JSONCodec) json.RawMessage {
func (c coreAppModuleAdaptor) ExportGenesis(ctx context.Context, cdc codec.JSONCodec) json.RawMessage {
if module, ok := c.module.(appmodule.HasGenesis); ok {
ctx := sdk.UnwrapSDKContext(ctx).WithGasMeter(storetypes.NewInfiniteGasMeter()) // avoid race conditions
target := genesis.RawJSONTarget{}
@@ -114,7 +112,7 @@ func (c coreAppModuleBasicAdaptor) ExportGenesis(ctx context.Context, cdc codec.
}
// InitGenesis implements HasGenesis
func (c coreAppModuleBasicAdaptor) InitGenesis(ctx context.Context, cdc codec.JSONCodec, bz json.RawMessage) []abci.ValidatorUpdate {
func (c coreAppModuleAdaptor) InitGenesis(ctx context.Context, cdc codec.JSONCodec, bz json.RawMessage) []abci.ValidatorUpdate {
if module, ok := c.module.(appmodule.HasGenesis); ok {
// core API genesis
source, err := genesis.SourceFromRawJSON(bz)
@@ -138,13 +136,12 @@ func (c coreAppModuleBasicAdaptor) InitGenesis(ctx context.Context, cdc codec.JS
return nil
}
// Name implements AppModuleBasic
func (c coreAppModuleBasicAdaptor) Name() string {
// Name implements HasName
func (c coreAppModuleAdaptor) Name() string {
return c.name
}
// GetQueryCmd implements AppModuleBasic
func (c coreAppModuleBasicAdaptor) GetQueryCmd() *cobra.Command {
func (c coreAppModuleAdaptor) GetQueryCmd() *cobra.Command {
if mod, ok := c.module.(interface {
GetQueryCmd() *cobra.Command
}); ok {
@@ -154,8 +151,7 @@ func (c coreAppModuleBasicAdaptor) GetQueryCmd() *cobra.Command {
return nil
}
// GetTxCmd implements AppModuleBasic
func (c coreAppModuleBasicAdaptor) GetTxCmd() *cobra.Command {
func (c coreAppModuleAdaptor) GetTxCmd() *cobra.Command {
if mod, ok := c.module.(interface {
GetTxCmd() *cobra.Command
}); ok {
@@ -165,8 +161,8 @@ func (c coreAppModuleBasicAdaptor) GetTxCmd() *cobra.Command {
return nil
}
// RegisterGRPCGatewayRoutes implements AppModuleBasic
func (c coreAppModuleBasicAdaptor) RegisterGRPCGatewayRoutes(ctx client.Context, mux *runtime.ServeMux) {
// RegisterGRPCGatewayRoutes implements HasGRPCGateway
func (c coreAppModuleAdaptor) RegisterGRPCGatewayRoutes(ctx client.Context, mux *runtime.ServeMux) {
if mod, ok := c.module.(interface {
RegisterGRPCGatewayRoutes(context client.Context, mux *runtime.ServeMux)
}); ok {
@@ -174,8 +170,8 @@ func (c coreAppModuleBasicAdaptor) RegisterGRPCGatewayRoutes(ctx client.Context,
}
}
// RegisterInterfaces implements AppModuleBasic
func (c coreAppModuleBasicAdaptor) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
// RegisterInterfaces implements HasRegisterInterfaces
func (c coreAppModuleAdaptor) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
if mod, ok := c.module.(interface {
RegisterInterfaces(registry codectypes.InterfaceRegistry)
}); ok {
@@ -183,8 +179,8 @@ func (c coreAppModuleBasicAdaptor) RegisterInterfaces(registry codectypes.Interf
}
}
// RegisterLegacyAminoCodec implements AppModuleBasic
func (c coreAppModuleBasicAdaptor) RegisterLegacyAminoCodec(amino *codec.LegacyAmino) {
// RegisterLegacyAminoCodec implements HasAminoCodec
func (c coreAppModuleAdaptor) RegisterLegacyAminoCodec(amino *codec.LegacyAmino) {
if mod, ok := c.module.(interface {
RegisterLegacyAminoCodec(amino *codec.LegacyAmino)
}); ok {
@@ -193,7 +189,7 @@ func (c coreAppModuleBasicAdaptor) RegisterLegacyAminoCodec(amino *codec.LegacyA
}
// RegisterServices implements HasServices
func (c coreAppModuleBasicAdaptor) RegisterServices(cfg Configurator) {
func (c coreAppModuleAdaptor) RegisterServices(cfg Configurator) {
if module, ok := c.module.(appmodule.HasServices); ok {
err := module.RegisterServices(cfg)
if err != nil {
@@ -209,6 +205,6 @@ func (c coreAppModuleBasicAdaptor) RegisterServices(cfg Configurator) {
}
}
func (c coreAppModuleBasicAdaptor) IsOnePerModuleType() {}
func (c coreAppModuleAdaptor) IsOnePerModuleType() {}
func (c coreAppModuleBasicAdaptor) IsAppModule() {}
func (c coreAppModuleAdaptor) IsAppModule() {}
+108 -160
View File
@@ -1,7 +1,6 @@
/*
Package module contains application module patterns and associated "manager" functionality.
The module pattern has been broken down by:
- independent module functionality (AppModuleBasic)
- inter-dependent module simulation functionality (AppModuleSimulation)
- inter-dependent module full functionality (AppModule)
@@ -11,14 +10,7 @@ module keepers are dependent on each other, thus in order to access the full
set of module functionality we need to define all the keepers/params-store/keys
etc. This full set of advanced functionality is defined by the AppModule interface.
Independent module functions are separated to allow for the construction of the
basic application structures required early on in the application definition
and used to enable the definition of full module functionality later in the
process. This separation is necessary, however we still want to allow for a
high level pattern for modules to follow - for instance, such that we don't
have to manually register all of the codecs for all the modules. This basic
procedure as well as other basic patterns are handled through the use of
BasicManager.
Independent module functions of modules can be accessed through a non instantiated AppModule.
Lastly the interface for genesis functionality (HasGenesis & HasABCIGenesis) has been
separated out from full module functionality (AppModule) so that modules which
@@ -51,12 +43,22 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
// AppModuleBasic is the standard form for basic non-dependant elements of an application module.
// Deprecated: use the embed extension interfaces instead, when needed.
type AppModuleBasic interface {
HasName
RegisterLegacyAminoCodec(*codec.LegacyAmino)
RegisterInterfaces(types.InterfaceRegistry)
RegisterGRPCGatewayRoutes(client.Context, *runtime.ServeMux)
HasRegisterInterfaces
HasGRPCGateway
HasAminoCodec
}
// AppModule is the form for an application module. Most of
// its functionality has been moved to extension interfaces.
// Deprecated: use appmodule.AppModule with a combination of extension interfaces interfaces instead.
type AppModule interface {
appmodule.AppModule
HasName
HasRegisterInterfaces
}
// HasName allows the module to provide its own name for legacy purposes.
@@ -68,117 +70,26 @@ type HasName interface {
// HasGenesisBasics is the legacy interface for stateless genesis methods.
type HasGenesisBasics interface {
HasName
DefaultGenesis(codec.JSONCodec) json.RawMessage
ValidateGenesis(codec.JSONCodec, client.TxEncodingConfig, json.RawMessage) error
}
// BasicManager is a collection of AppModuleBasic
type BasicManager map[string]AppModuleBasic
// NewBasicManager creates a new BasicManager object
func NewBasicManager(modules ...AppModuleBasic) BasicManager {
moduleMap := make(map[string]AppModuleBasic)
for _, module := range modules {
moduleMap[module.Name()] = module
}
return moduleMap
// HasAminoCodec is the interface for modules that have amino codec registration.
// Deprecated: modules should not need to register their own amino codecs.
type HasAminoCodec interface {
RegisterLegacyAminoCodec(*codec.LegacyAmino)
}
// NewBasicManagerFromManager creates a new BasicManager from a Manager
// The BasicManager will contain all AppModuleBasic from the AppModule Manager
// Module's AppModuleBasic can be overridden by passing a custom AppModuleBasic map
func NewBasicManagerFromManager(manager *Manager, customModuleBasics map[string]AppModuleBasic) BasicManager {
moduleMap := make(map[string]AppModuleBasic)
for name, module := range manager.Modules {
if customBasicMod, ok := customModuleBasics[name]; ok {
moduleMap[name] = customBasicMod
continue
}
if appModule, ok := module.(appmodule.AppModule); ok {
moduleMap[name] = CoreAppModuleBasicAdaptor(name, appModule)
continue
}
if basicMod, ok := module.(AppModuleBasic); ok {
moduleMap[name] = basicMod
}
}
return moduleMap
// HasRegisterInterfaces is the interface for modules to register their msg types.
type HasRegisterInterfaces interface {
RegisterInterfaces(types.InterfaceRegistry)
}
// RegisterLegacyAminoCodec registers all module codecs
func (bm BasicManager) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
for _, b := range bm {
b.RegisterLegacyAminoCodec(cdc)
}
}
// RegisterInterfaces registers all module interface types
func (bm BasicManager) RegisterInterfaces(registry types.InterfaceRegistry) {
for _, m := range bm {
m.RegisterInterfaces(registry)
}
}
// DefaultGenesis provides default genesis information for all modules
func (bm BasicManager) DefaultGenesis(cdc codec.JSONCodec) map[string]json.RawMessage {
genesisData := make(map[string]json.RawMessage)
for _, b := range bm {
if mod, ok := b.(HasGenesisBasics); ok {
genesisData[b.Name()] = mod.DefaultGenesis(cdc)
}
}
return genesisData
}
// ValidateGenesis performs genesis state validation for all modules
func (bm BasicManager) ValidateGenesis(cdc codec.JSONCodec, txEncCfg client.TxEncodingConfig, genesisData map[string]json.RawMessage) error {
for _, b := range bm {
// first check if the module is an adapted Core API Module
if mod, ok := b.(HasGenesisBasics); ok {
if err := mod.ValidateGenesis(cdc, txEncCfg, genesisData[b.Name()]); err != nil {
return err
}
}
}
return nil
}
// RegisterGRPCGatewayRoutes registers all module rest routes
func (bm BasicManager) RegisterGRPCGatewayRoutes(clientCtx client.Context, rtr *runtime.ServeMux) {
for _, b := range bm {
b.RegisterGRPCGatewayRoutes(clientCtx, rtr)
}
}
// AddTxCommands adds all tx commands to the rootTxCmd.
func (bm BasicManager) AddTxCommands(rootTxCmd *cobra.Command) {
for _, b := range bm {
if mod, ok := b.(interface {
GetTxCmd() *cobra.Command
}); ok {
if cmd := mod.GetTxCmd(); cmd != nil {
rootTxCmd.AddCommand(cmd)
}
}
}
}
// AddQueryCommands adds all query commands to the rootQueryCmd.
func (bm BasicManager) AddQueryCommands(rootQueryCmd *cobra.Command) {
for _, b := range bm {
if mod, ok := b.(interface {
GetQueryCmd() *cobra.Command
}); ok {
if cmd := mod.GetQueryCmd(); cmd != nil {
rootQueryCmd.AddCommand(cmd)
}
}
}
// HasGRPCGateway is the interface for modules to register their gRPC gateway routes.
type HasGRPCGateway interface {
RegisterGRPCGatewayRoutes(client.Context, *runtime.ServeMux)
}
// HasGenesis is the extension interface for stateful genesis methods.
@@ -195,15 +106,6 @@ type HasABCIGenesis interface {
ExportGenesis(context.Context, codec.JSONCodec) json.RawMessage
}
// AppModule is the form for an application module. Most of
// its functionality has been moved to extension interfaces.
// Deprecated: use appmodule.AppModule with a combination of extension interfaes interfaces instead.
type AppModule interface {
appmodule.AppModule
AppModuleBasic
}
// HasInvariants is the interface for registering invariants.
type HasInvariants interface {
// RegisterInvariants registers module invariants.
@@ -235,41 +137,6 @@ type HasABCIEndBlock interface {
EndBlock(context.Context) ([]abci.ValidatorUpdate, error)
}
var (
_ appmodule.AppModule = (*GenesisOnlyAppModule)(nil)
_ AppModuleBasic = (*GenesisOnlyAppModule)(nil)
)
// genesisOnlyModule is an interface need to return GenesisOnlyAppModule struct in order to wrap two interfaces
type genesisOnlyModule interface {
AppModuleBasic
HasABCIGenesis
}
// GenesisOnlyAppModule is an AppModule that only has import/export functionality
type GenesisOnlyAppModule struct {
genesisOnlyModule
}
// NewGenesisOnlyAppModule creates a new GenesisOnlyAppModule object
func NewGenesisOnlyAppModule(amg genesisOnlyModule) GenesisOnlyAppModule {
return GenesisOnlyAppModule{
genesisOnlyModule: amg,
}
}
// 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) {}
// ConsensusVersion implements AppModule/ConsensusVersion.
func (gam GenesisOnlyAppModule) ConsensusVersion() uint64 { return 1 }
// Manager defines a module manager that provides the high level utility for managing and executing
// operations for a group of modules
type Manager struct {
@@ -444,6 +311,87 @@ func (m *Manager) SetOrderMigrations(moduleNames ...string) {
m.OrderMigrations = moduleNames
}
// RegisterLegacyAminoCodec registers all module codecs
func (m *Manager) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
for _, b := range m.Modules {
if mod, ok := b.(HasAminoCodec); ok {
mod.RegisterLegacyAminoCodec(cdc)
}
}
}
// RegisterInterfaces registers all module interface types
func (m *Manager) RegisterInterfaces(registry types.InterfaceRegistry) {
for _, b := range m.Modules {
if mod, ok := b.(HasRegisterInterfaces); ok {
mod.RegisterInterfaces(registry)
}
}
}
// DefaultGenesis provides default genesis information for all modules
func (m *Manager) DefaultGenesis(cdc codec.JSONCodec) map[string]json.RawMessage {
genesisData := make(map[string]json.RawMessage)
for _, b := range m.Modules {
if mod, ok := b.(HasGenesisBasics); ok {
genesisData[mod.Name()] = mod.DefaultGenesis(cdc)
} else if mod, ok := b.(HasName); ok {
genesisData[mod.Name()] = []byte("{}")
}
}
return genesisData
}
// ValidateGenesis performs genesis state validation for all modules
func (m *Manager) ValidateGenesis(cdc codec.JSONCodec, txEncCfg client.TxEncodingConfig, genesisData map[string]json.RawMessage) error {
for _, b := range m.Modules {
// first check if the module is an adapted Core API Module
if mod, ok := b.(HasGenesisBasics); ok {
if err := mod.ValidateGenesis(cdc, txEncCfg, genesisData[mod.Name()]); err != nil {
return err
}
}
}
return nil
}
// RegisterGRPCGatewayRoutes registers all module rest routes
func (m *Manager) RegisterGRPCGatewayRoutes(clientCtx client.Context, rtr *runtime.ServeMux) {
for _, b := range m.Modules {
if mod, ok := b.(HasGRPCGateway); ok {
mod.RegisterGRPCGatewayRoutes(clientCtx, rtr)
}
}
}
// AddTxCommands adds all tx commands to the rootTxCmd.
func (m *Manager) AddTxCommands(rootTxCmd *cobra.Command) {
for _, b := range m.Modules {
if mod, ok := b.(interface {
GetTxCmd() *cobra.Command
}); ok {
if cmd := mod.GetTxCmd(); cmd != nil {
rootTxCmd.AddCommand(cmd)
}
}
}
}
// AddQueryCommands adds all query commands to the rootQueryCmd.
func (m *Manager) AddQueryCommands(rootQueryCmd *cobra.Command) {
for _, b := range m.Modules {
if mod, ok := b.(interface {
GetQueryCmd() *cobra.Command
}); ok {
if cmd := mod.GetQueryCmd(); cmd != nil {
rootQueryCmd.AddCommand(cmd)
}
}
}
}
// RegisterInvariants registers all module invariants
func (m *Manager) RegisterInvariants(ir sdk.InvariantRegistry) {
for _, module := range m.Modules {
+7 -67
View File
@@ -32,66 +32,6 @@ func (MockCoreAppModule) GetQueryCmd() *cobra.Command {
}
}
func TestBasicManager(t *testing.T) {
mockCtrl := gomock.NewController(t)
t.Cleanup(mockCtrl.Finish)
legacyAmino := codec.NewLegacyAmino()
interfaceRegistry := types.NewInterfaceRegistry()
cdc := codec.NewProtoCodec(interfaceRegistry)
// Test with a legacy module, a mock core module that doesn't return anything,
// and a core module defined in this file
expDefaultGenesis := map[string]json.RawMessage{
"mockAppModuleBasic1": json.RawMessage(``),
"mockCoreAppModule2": json.RawMessage(`null`),
"mockCoreAppModule3": json.RawMessage(`{
"someField": "someKey"
}`),
}
// legacy module
mockAppModuleBasic1 := mock.NewMockAppModuleWithAllExtensions(mockCtrl)
mockAppModuleBasic1.EXPECT().Name().AnyTimes().Return("mockAppModuleBasic1")
mockAppModuleBasic1.EXPECT().DefaultGenesis(gomock.Eq(cdc)).Times(1).Return(json.RawMessage(``))
// Allow ValidateGenesis to be called any times because other module can fail before this one is called.
mockAppModuleBasic1.EXPECT().ValidateGenesis(gomock.Eq(cdc), gomock.Eq(nil), gomock.Eq(expDefaultGenesis["mockAppModuleBasic1"])).AnyTimes().Return(nil)
mockAppModuleBasic1.EXPECT().RegisterLegacyAminoCodec(gomock.Eq(legacyAmino)).Times(1)
mockAppModuleBasic1.EXPECT().RegisterInterfaces(gomock.Eq(interfaceRegistry)).Times(1)
// mock core API module
mockCoreAppModule2 := mock.NewMockCoreAppModule(mockCtrl)
mockCoreAppModule2.EXPECT().DefaultGenesis(gomock.Any()).AnyTimes().Return(nil)
mockCoreAppModule2.EXPECT().ValidateGenesis(gomock.Any()).AnyTimes().Return(nil)
mockAppModule2 := module.CoreAppModuleBasicAdaptor("mockCoreAppModule2", mockCoreAppModule2)
// mock core API module (but all methods are implemented)
mockCoreAppModule3 := module.CoreAppModuleBasicAdaptor("mockCoreAppModule3", MockCoreAppModule{})
mm := module.NewBasicManager(mockAppModuleBasic1, mockAppModule2, mockCoreAppModule3)
require.Equal(t, mockAppModuleBasic1, mm["mockAppModuleBasic1"])
require.Equal(t, mockAppModule2, mm["mockCoreAppModule2"])
require.Equal(t, mockCoreAppModule3, mm["mockCoreAppModule3"])
mm.RegisterLegacyAminoCodec(legacyAmino)
mm.RegisterInterfaces(interfaceRegistry)
require.Equal(t, expDefaultGenesis, mm.DefaultGenesis(cdc))
var data map[string]string
require.Equal(t, map[string]string(nil), data)
require.ErrorIs(t, mm.ValidateGenesis(cdc, nil, expDefaultGenesis), errFoo)
mockCmd := &cobra.Command{Use: "root"}
mm.AddTxCommands(mockCmd)
mm.AddQueryCommands(mockCmd)
require.Equal(t, 1, len(mockCmd.Commands()))
// validate genesis returns nil
require.Nil(t, module.NewBasicManager().ValidateGenesis(cdc, nil, expDefaultGenesis))
}
func TestAssertNoForgottenModules(t *testing.T) {
mockCtrl := gomock.NewController(t)
t.Cleanup(mockCtrl.Finish)
@@ -101,7 +41,7 @@ func TestAssertNoForgottenModules(t *testing.T) {
mockAppModule1.EXPECT().Name().Times(2).Return("module1")
mm := module.NewManager(
mockAppModule1,
module.CoreAppModuleBasicAdaptor("module3", mockAppModule3),
module.CoreAppModuleAdaptor("module3", mockAppModule3),
)
require.NotNil(t, mm)
require.Equal(t, 2, len(mm.Modules))
@@ -131,7 +71,7 @@ func TestManagerOrderSetters(t *testing.T) {
mockAppModule1.EXPECT().Name().Times(2).Return("module1")
mockAppModule2.EXPECT().Name().Times(2).Return("module2")
mm := module.NewManager(mockAppModule1, mockAppModule2, module.CoreAppModuleBasicAdaptor("module3", mockAppModule3))
mm := module.NewManager(mockAppModule1, mockAppModule2, module.CoreAppModuleAdaptor("module3", mockAppModule3))
require.NotNil(t, mm)
require.Equal(t, 3, len(mm.Modules))
@@ -174,7 +114,7 @@ func TestManager_RegisterInvariants(t *testing.T) {
mockAppModule1.EXPECT().Name().Times(2).Return("module1")
mockAppModule2.EXPECT().Name().Times(2).Return("module2")
// TODO: This is not working for Core API modules yet
mm := module.NewManager(mockAppModule1, mockAppModule2, module.CoreAppModuleBasicAdaptor("mockAppModule3", mockAppModule3))
mm := module.NewManager(mockAppModule1, mockAppModule2, module.CoreAppModuleAdaptor("mockAppModule3", mockAppModule3))
require.NotNil(t, mm)
require.Equal(t, 3, len(mm.Modules))
@@ -195,7 +135,7 @@ func TestManager_RegisterQueryServices(t *testing.T) {
mockAppModule1.EXPECT().Name().Times(2).Return("module1")
mockAppModule2.EXPECT().Name().Times(2).Return("module2")
// TODO: This is not working for Core API modules yet
mm := module.NewManager(mockAppModule1, mockAppModule2, module.CoreAppModuleBasicAdaptor("mockAppModule3", mockAppModule3))
mm := module.NewManager(mockAppModule1, mockAppModule2, module.CoreAppModuleAdaptor("mockAppModule3", mockAppModule3))
require.NotNil(t, mm)
require.Equal(t, 3, len(mm.Modules))
@@ -227,7 +167,7 @@ func TestManager_InitGenesis(t *testing.T) {
mockAppModule3 := mock.NewMockCoreAppModule(mockCtrl)
mockAppModule1.EXPECT().Name().Times(2).Return("module1")
mockAppModule2.EXPECT().Name().Times(4).Return("module2")
mm := module.NewManager(mockAppModule1, mockAppModule2, module.CoreAppModuleBasicAdaptor("module3", mockAppModule3))
mm := module.NewManager(mockAppModule1, mockAppModule2, module.CoreAppModuleAdaptor("module3", mockAppModule3))
require.NotNil(t, mm)
require.Equal(t, 3, len(mm.Modules))
@@ -261,7 +201,7 @@ func TestManager_InitGenesis(t *testing.T) {
// happy path
mm2 := module.NewManager(mockAppModuleABCI1, mockAppModule2, module.CoreAppModuleBasicAdaptor("module3", mockAppModule3))
mm2 := module.NewManager(mockAppModuleABCI1, mockAppModule2, module.CoreAppModuleAdaptor("module3", mockAppModule3))
mockAppModuleABCI1.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(cdc), gomock.Eq(genesisData["module1"])).Times(1).Return([]abci.ValidatorUpdate{{}})
mockAppModule2.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(cdc), gomock.Eq(genesisData["module2"])).Times(1)
mockAppModule3.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Any()).Times(1).Return(nil)
@@ -278,7 +218,7 @@ func TestManager_ExportGenesis(t *testing.T) {
mockCoreAppModule := MockCoreAppModule{}
mockAppModule1.EXPECT().Name().Times(2).Return("module1")
mockAppModule2.EXPECT().Name().Times(2).Return("module2")
mm := module.NewManager(mockAppModule1, mockAppModule2, module.CoreAppModuleBasicAdaptor("mockCoreAppModule", mockCoreAppModule))
mm := module.NewManager(mockAppModule1, mockAppModule2, module.CoreAppModuleAdaptor("mockCoreAppModule", mockCoreAppModule))
require.NotNil(t, mm)
require.Equal(t, 3, len(mm.Modules))
+3 -4
View File
@@ -12,7 +12,7 @@ import (
)
// TestEncodingConfig defines an encoding configuration that is used for testing
// purposes. Note, MakeTestEncodingConfig takes a series of AppModuleBasic types
// purposes. Note, MakeTestEncodingConfig takes a series of AppModule types
// which should only contain the relevant module being tested and any potential
// dependencies.
type TestEncodingConfig struct {
@@ -22,7 +22,7 @@ type TestEncodingConfig struct {
Amino *codec.LegacyAmino
}
func MakeTestEncodingConfig(modules ...module.AppModuleBasic) TestEncodingConfig {
func MakeTestEncodingConfig(modules ...module.AppModule) TestEncodingConfig {
aminoCodec := codec.NewLegacyAmino()
interfaceRegistry := testutil.CodecOptions{}.NewInterfaceRegistry()
codec := codec.NewProtoCodec(interfaceRegistry)
@@ -34,8 +34,7 @@ func MakeTestEncodingConfig(modules ...module.AppModuleBasic) TestEncodingConfig
Amino: aminoCodec,
}
mb := module.NewBasicManager(modules...)
mb := module.NewManager(modules...)
std.RegisterLegacyAminoCodec(encCfg.Amino)
std.RegisterInterfaces(encCfg.InterfaceRegistry)
mb.RegisterLegacyAminoCodec(encCfg.Amino)