Skip to content

Commit

Permalink
refactor: modules should implement appmodule.AppModule (cosmos#18252)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt authored Oct 25, 2023
1 parent 139a29e commit 797ae0f
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 12 deletions.
16 changes: 8 additions & 8 deletions baseapp/testutil/mock/mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion scripts/mockgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
mockgen_cmd="mockgen"
$mockgen_cmd -source=baseapp/abci_utils.go -package mock -destination baseapp/testutil/mock/mocks.go
$mockgen_cmd -source=client/account_retriever.go -package mock -destination testutil/mock/account_retriever.go
$mockgen_cmd -package mock -destination store/mock/cosmos_cosmos_db_DB.go github.com/cosmos/cosmos-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
Expand Down
48 changes: 48 additions & 0 deletions testutil/mock/types_mock_appmodule.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions testutil/mock/types_module_module.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions types/module/core_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,26 @@ import (
)

var (
_ appmodule.AppModule = coreAppModuleBasicAdaptor{}

_ AppModuleBasic = coreAppModuleBasicAdaptor{}
_ HasABCIGenesis = coreAppModuleBasicAdaptor{}
_ HasServices = coreAppModuleBasicAdaptor{}
)

// CoreAppModuleBasicAdaptor wraps the core API module as an AppModule that this version
// of the SDK can use.
func CoreAppModuleBasicAdaptor(name string, module appmodule.AppModule) AppModuleBasic {
// 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{
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 {
name string
module appmodule.AppModule
Expand Down Expand Up @@ -195,3 +201,7 @@ func (c coreAppModuleBasicAdaptor) RegisterServices(cfg Configurator) {
}
}
}

func (c coreAppModuleBasicAdaptor) IsOnePerModuleType() {}

func (c coreAppModuleBasicAdaptor) IsAppModule() {}
6 changes: 6 additions & 0 deletions types/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ type HasABCIGenesis interface {
// 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
}

Expand Down Expand Up @@ -288,6 +290,10 @@ func NewManager(modules ...AppModule) *Manager {
modulesStr := make([]string, 0, len(modules))
preBlockModulesStr := make([]string, 0)
for _, module := range modules {
if _, ok := module.(appmodule.AppModule); !ok {
panic(fmt.Sprintf("module %s does not implement appmodule.AppModule", module.Name()))
}

moduleMap[module.Name()] = module
modulesStr = append(modulesStr, module.Name())
if _, ok := module.(appmodule.HasPreBlocker); ok {
Expand Down
14 changes: 14 additions & 0 deletions x/slashing/testutil/expected_keepers_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 797ae0f

Please sign in to comment.