From 797ae0fe99cb3762aee960788627a199e7feb6bb Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 25 Oct 2023 14:31:37 +0200 Subject: [PATCH] refactor: modules should implement appmodule.AppModule (#18252) --- baseapp/testutil/mock/mocks.go | 16 +++---- scripts/mockgen.sh | 1 - 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 +++ x/slashing/testutil/expected_keepers_mocks.go | 14 ++++++ 7 files changed, 137 insertions(+), 12 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/scripts/mockgen.sh b/scripts/mockgen.sh index 4b6b30b7a6e5..a82d6e99701e 100755 --- a/scripts/mockgen.sh +++ b/scripts/mockgen.sh @@ -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 diff --git a/testutil/mock/types_mock_appmodule.go b/testutil/mock/types_mock_appmodule.go index 8d3af82f5c27..87682dbf133e 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 b299af134d7d..534fb5f450b1 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 3289846d204e..128fa0c51410 100644 --- a/types/module/core_module.go +++ b/types/module/core_module.go @@ -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 @@ -195,3 +201,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 5980b5b0a857..c83913ae04dc 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 { diff --git a/x/slashing/testutil/expected_keepers_mocks.go b/x/slashing/testutil/expected_keepers_mocks.go index 1c479da554cc..ce16bc841c3e 100644 --- a/x/slashing/testutil/expected_keepers_mocks.go +++ b/x/slashing/testutil/expected_keepers_mocks.go @@ -39,6 +39,20 @@ func (m *MockAccountKeeper) EXPECT() *MockAccountKeeperMockRecorder { return m.recorder } +// AddressCodec mocks base method. +func (m *MockAccountKeeper) AddressCodec() address.Codec { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddressCodec") + ret0, _ := ret[0].(address.Codec) + return ret0 +} + +// AddressCodec indicates an expected call of AddressCodec. +func (mr *MockAccountKeeperMockRecorder) AddressCodec() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddressCodec", reflect.TypeOf((*MockAccountKeeper)(nil).AddressCodec)) +} + // GetAccount mocks base method. func (m *MockAccountKeeper) GetAccount(ctx context.Context, addr types.AccAddress) types.AccountI { m.ctrl.T.Helper()