Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A mock isn't compatible with the latest interface #1030

Open
2 of 4 tasks
torao opened this issue Jun 21, 2023 · 0 comments
Open
2 of 4 tasks

A mock isn't compatible with the latest interface #1030

torao opened this issue Jun 21, 2023 · 0 comments
Labels
A: bug Something isn't working priority/minor

Comments

@torao
Copy link
Contributor

torao commented Jun 21, 2023

Summary of Bug

A mock used for testing isn't compatible with the latest interface.

The mock in question is the MockAppModule in tests/mocks/types_module_module.go, which implements BeginBlock() and EndBlock(), which aren't defined in the current AppModule. Unit tests use these methods, so make test will result in a compile error after generating the latest mock with make mocks.

$ make mocks
$ make test
...
# github.com/Finschia/finschia-sdk/types/module_test [github.com/Finschia/finschia-sdk/types/module.test]
types/module/module_test.go:255:26: mockAppModule1.EXPECT().BeginBlock undefined (type *mocks.MockAppModuleMockRecorder has no field or method BeginBlock)
types/module/module_test.go:256:26: mockAppModule2.EXPECT().BeginBlock undefined (type *mocks.MockAppModuleMockRecorder has no field or method BeginBlock)
types/module/module_test.go:274:26: mockAppModule1.EXPECT().EndBlock undefined (type *mocks.MockAppModuleMockRecorder has no field or method EndBlock)
types/module/module_test.go:275:26: mockAppModule2.EXPECT().EndBlock undefined (type *mocks.MockAppModuleMockRecorder has no field or method EndBlock)
types/module/module_test.go:280:26: mockAppModule1.EXPECT().EndBlock undefined (type *mocks.MockAppModuleMockRecorder has no field or method EndBlock)
types/module/module_test.go:281:26: mockAppModule2.EXPECT().EndBlock undefined (type *mocks.MockAppModuleMockRecorder has no field or method EndBlock)

This is why the AppModule definition was changed and merged without make mocks and the old definition mock is considered to be used.

This problem has been caused by cosmos/cosmos-sdk v0.46.x before Finschia/finschia-sdk, since finschia-sdk forked it as is, and appears to be fixed in cosmos-sdk v0.47.0. (Therefore, we can ignore this issue and forbid merging sources that have make mocks and wait to follow cosmos-sdk v0.47.0.)

Version

main, v0.47.0

Steps to Reproduce

By cloning this repository and running make mocks, an auto-generated mock is defined differently.

$ git clone https://github.com/Finschia/finschia-sdk.git 
$ cd finschia-sdk
$ make mocks
$ git diff

The important difference is that the following BeginBlock() and EndBlock() definitions have disappeared.

diff --git a/tests/mocks/types_module_module.go b/tests/mocks/types_module_module.go
index cff731f73..b0e1f8308 100644
--- a/tests/mocks/types_module_module.go
+++ b/tests/mocks/types_module_module.go 
@@ -329,18 +329,6 @@ func (m *MockAppModule) EXPECT() *MockAppModuleMockRecorder {
        return m.recorder
 }
 
-// BeginBlock mocks base method.
-func (m *MockAppModule) BeginBlock(arg0 types0.Context, arg1 ocabci.RequestBeginBlock) {
-       m.ctrl.T.Helper()
-       m.ctrl.Call(m, "BeginBlock", arg0, arg1)
-}
-
-// BeginBlock indicates an expected call of BeginBlock.
-func (mr *MockAppModuleMockRecorder) BeginBlock(arg0, arg1 interface{}) *gomock.Call {
-       mr.mock.ctrl.T.Helper()
-       return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BeginBlock", reflect.TypeOf((*MockAppModule)(nil).BeginBlock), arg0, arg1)
-}
-
 // ConsensusVersion mocks base method.
 func (m *MockAppModule) ConsensusVersion() uint64 {
        m.ctrl.T.Helper()
@@ -369,20 +357,6 @@ func (mr *MockAppModuleMockRecorder) DefaultGenesis(arg0 interface{}) *gomock.Ca
        return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DefaultGenesis", reflect.TypeOf((*MockAppModule)(nil).DefaultGenesis), arg0)
 }
 
-// EndBlock mocks base method.
-func (m *MockAppModule) EndBlock(arg0 types0.Context, arg1 abci.RequestEndBlock) []abci.ValidatorUpdate {
-       m.ctrl.T.Helper()
-       ret := m.ctrl.Call(m, "EndBlock", arg0, arg1)
-       ret0, _ := ret[0].([]abci.ValidatorUpdate)
-       return ret0
-}
-
-// EndBlock indicates an expected call of EndBlock.
-func (mr *MockAppModuleMockRecorder) EndBlock(arg0, arg1 interface{}) *gomock.Call {
-       mr.mock.ctrl.T.Helper()
-       return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EndBlock", reflect.TypeOf((*MockAppModule)(nil).EndBlock), arg0, arg1)
-}
-

Neither BeginBlock() nor EndBlock() is defined in the current AppModule interface from which is MockAppModule is generated.


For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@torao torao added A: bug Something isn't working priority/minor labels Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A: bug Something isn't working priority/minor
Projects
None yet
Development

No branches or pull requests

1 participant