From 301ceca874dc8dbc417d6677f7c35e1d2e8f14e9 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 25 Oct 2023 12:55:55 +0000 Subject: [PATCH] refactor: modules should implement appmodule.AppModule (backport #18252) (#18255) Co-authored-by: Julien Robert --- baseapp/testutil/mock/mocks.go | 16 ++++----- testutil/mock/types_mock_appmodule.go | 48 +++++++++++++++++++++++++++ testutil/mock/types_module_module.go | 48 +++++++++++++++++++++++++++ types/module/core_module.go | 16 +++++++-- types/module/module.go | 6 ++++ 5 files changed, 123 insertions(+), 11 deletions(-) diff --git a/baseapp/testutil/mock/mocks.go b/baseapp/testutil/mock/mocks.go index bf6359cec639..85d1cdeaf6d5 100644 --- a/baseapp/testutil/mock/mocks.go +++ b/baseapp/testutil/mock/mocks.go @@ -207,29 +207,29 @@ func (mr *MockTxSelectorMockRecorder) Clear() *gomock.Call { } // SelectTxForProposal mocks base method. -func (m *MockTxSelector) SelectTxForProposal(maxTxBytes, maxBlockGas uint64, memTx types.Tx, txBz []byte) bool { +func (m *MockTxSelector) SelectTxForProposal(ctx context.Context, maxTxBytes, maxBlockGas uint64, memTx types.Tx, txBz []byte) bool { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SelectTxForProposal", maxTxBytes, maxBlockGas, memTx, txBz) + ret := m.ctrl.Call(m, "SelectTxForProposal", ctx, maxTxBytes, maxBlockGas, memTx, txBz) ret0, _ := ret[0].(bool) return ret0 } // SelectTxForProposal indicates an expected call of SelectTxForProposal. -func (mr *MockTxSelectorMockRecorder) SelectTxForProposal(maxTxBytes, maxBlockGas, memTx, txBz interface{}) *gomock.Call { +func (mr *MockTxSelectorMockRecorder) SelectTxForProposal(ctx, maxTxBytes, maxBlockGas, memTx, txBz interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SelectTxForProposal", reflect.TypeOf((*MockTxSelector)(nil).SelectTxForProposal), maxTxBytes, maxBlockGas, memTx, txBz) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SelectTxForProposal", reflect.TypeOf((*MockTxSelector)(nil).SelectTxForProposal), ctx, maxTxBytes, maxBlockGas, memTx, txBz) } // SelectedTxs mocks base method. -func (m *MockTxSelector) SelectedTxs() [][]byte { +func (m *MockTxSelector) SelectedTxs(ctx context.Context) [][]byte { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SelectedTxs") + ret := m.ctrl.Call(m, "SelectedTxs", ctx) ret0, _ := ret[0].([][]byte) return ret0 } // SelectedTxs indicates an expected call of SelectedTxs. -func (mr *MockTxSelectorMockRecorder) SelectedTxs() *gomock.Call { +func (mr *MockTxSelectorMockRecorder) SelectedTxs(ctx interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SelectedTxs", reflect.TypeOf((*MockTxSelector)(nil).SelectedTxs)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SelectedTxs", reflect.TypeOf((*MockTxSelector)(nil).SelectedTxs), ctx) } diff --git a/testutil/mock/types_mock_appmodule.go b/testutil/mock/types_mock_appmodule.go index 48cc6f49a35a..8336f707da23 100644 --- a/testutil/mock/types_mock_appmodule.go +++ b/testutil/mock/types_mock_appmodule.go @@ -112,6 +112,30 @@ func (mr *MockAppModuleWithAllExtensionsMockRecorder) InitGenesis(arg0, arg1, ar return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InitGenesis", reflect.TypeOf((*MockAppModuleWithAllExtensions)(nil).InitGenesis), arg0, arg1, arg2) } +// IsAppModule mocks base method. +func (m *MockAppModuleWithAllExtensions) IsAppModule() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "IsAppModule") +} + +// IsAppModule indicates an expected call of IsAppModule. +func (mr *MockAppModuleWithAllExtensionsMockRecorder) IsAppModule() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsAppModule", reflect.TypeOf((*MockAppModuleWithAllExtensions)(nil).IsAppModule)) +} + +// IsOnePerModuleType mocks base method. +func (m *MockAppModuleWithAllExtensions) IsOnePerModuleType() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "IsOnePerModuleType") +} + +// IsOnePerModuleType indicates an expected call of IsOnePerModuleType. +func (mr *MockAppModuleWithAllExtensionsMockRecorder) IsOnePerModuleType() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsOnePerModuleType", reflect.TypeOf((*MockAppModuleWithAllExtensions)(nil).IsOnePerModuleType)) +} + // Name mocks base method. func (m *MockAppModuleWithAllExtensions) Name() string { m.ctrl.T.Helper() @@ -294,6 +318,30 @@ func (mr *MockAppModuleWithAllExtensionsABCIMockRecorder) InitGenesis(arg0, arg1 return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InitGenesis", reflect.TypeOf((*MockAppModuleWithAllExtensionsABCI)(nil).InitGenesis), arg0, arg1, arg2) } +// IsAppModule mocks base method. +func (m *MockAppModuleWithAllExtensionsABCI) IsAppModule() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "IsAppModule") +} + +// IsAppModule indicates an expected call of IsAppModule. +func (mr *MockAppModuleWithAllExtensionsABCIMockRecorder) IsAppModule() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsAppModule", reflect.TypeOf((*MockAppModuleWithAllExtensionsABCI)(nil).IsAppModule)) +} + +// IsOnePerModuleType mocks base method. +func (m *MockAppModuleWithAllExtensionsABCI) IsOnePerModuleType() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "IsOnePerModuleType") +} + +// IsOnePerModuleType indicates an expected call of IsOnePerModuleType. +func (mr *MockAppModuleWithAllExtensionsABCIMockRecorder) IsOnePerModuleType() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsOnePerModuleType", reflect.TypeOf((*MockAppModuleWithAllExtensionsABCI)(nil).IsOnePerModuleType)) +} + // Name mocks base method. func (m *MockAppModuleWithAllExtensionsABCI) Name() string { m.ctrl.T.Helper() diff --git a/testutil/mock/types_module_module.go b/testutil/mock/types_module_module.go index 804beeb20018..b86f7ef22dd3 100644 --- a/testutil/mock/types_module_module.go +++ b/testutil/mock/types_module_module.go @@ -359,6 +359,30 @@ func (m *MockAppModule) EXPECT() *MockAppModuleMockRecorder { return m.recorder } +// 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() @@ -554,6 +578,30 @@ func (mr *MockHasABCIEndBlockMockRecorder) EndBlock(arg0 interface{}) *gomock.Ca return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EndBlock", reflect.TypeOf((*MockHasABCIEndBlock)(nil).EndBlock), arg0) } +// IsAppModule mocks base method. +func (m *MockHasABCIEndBlock) IsAppModule() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "IsAppModule") +} + +// IsAppModule indicates an expected call of IsAppModule. +func (mr *MockHasABCIEndBlockMockRecorder) IsAppModule() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsAppModule", reflect.TypeOf((*MockHasABCIEndBlock)(nil).IsAppModule)) +} + +// IsOnePerModuleType mocks base method. +func (m *MockHasABCIEndBlock) IsOnePerModuleType() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "IsOnePerModuleType") +} + +// IsOnePerModuleType indicates an expected call of IsOnePerModuleType. +func (mr *MockHasABCIEndBlockMockRecorder) IsOnePerModuleType() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsOnePerModuleType", reflect.TypeOf((*MockHasABCIEndBlock)(nil).IsOnePerModuleType)) +} + // Name mocks base method. func (m *MockHasABCIEndBlock) Name() string { m.ctrl.T.Helper() diff --git a/types/module/core_module.go b/types/module/core_module.go index 1060edde4357..3b9616de3a75 100644 --- a/types/module/core_module.go +++ b/types/module/core_module.go @@ -18,20 +18,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 @@ -194,3 +200,7 @@ func (c coreAppModuleBasicAdaptor) RegisterServices(cfg Configurator) { } } } + +func (c coreAppModuleBasicAdaptor) IsOnePerModuleType() {} + +func (c coreAppModuleBasicAdaptor) IsAppModule() {} diff --git a/types/module/module.go b/types/module/module.go index 57bd49307672..432d51b5fde9 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -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 } @@ -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 {