diff --git a/modules/light-clients/08-wasm/types/store.go b/modules/light-clients/08-wasm/types/store.go index fbcfd4f00e85..8b85cd97365d 100644 --- a/modules/light-clients/08-wasm/types/store.go +++ b/modules/light-clients/08-wasm/types/store.go @@ -35,6 +35,13 @@ type migrateClientWrappedStore struct { } func newMigrateClientWrappedStore(subjectStore, substituteStore storetypes.KVStore) migrateClientWrappedStore { + if subjectStore == nil { + panic(errors.New("subjectStore must not be nil")) + } + if substituteStore == nil { + panic(errors.New("substituteStore must not be nil")) + } + return migrateClientWrappedStore{ subjectStore: subjectStore, substituteStore: substituteStore, diff --git a/modules/light-clients/08-wasm/types/store_test.go b/modules/light-clients/08-wasm/types/store_test.go index b3e445f0bebe..fd35096787fb 100644 --- a/modules/light-clients/08-wasm/types/store_test.go +++ b/modules/light-clients/08-wasm/types/store_test.go @@ -325,6 +325,55 @@ func (suite *TypesTestSuite) TestMigrateClientWrappedStoreIterators() { } } +func (suite *TypesTestSuite) TestNewMigrateClientWrappedStore() { + // calls suite.SetupWasmWithMockVM() and creates two clients with their respective stores + subjectStore, substituteStore := suite.GetSubjectAndSubstituteStore() + + testCases := []struct { + name string + malleate func() + expPanic bool + }{ + { + "success", + func() {}, + false, + }, + { + "failure: subject store is nil", + func() { + subjectStore = nil + }, + true, + }, + { + "failure: substitute store is nil", + func() { + substituteStore = nil + }, + true, + }, + } + + for _, tc := range testCases { + tc := tc + suite.Run(tc.name, func() { + tc.malleate() + + expPass := !tc.expPanic + if expPass { + suite.Require().NotPanics(func() { + types.NewMigrateProposalWrappedStore(subjectStore, substituteStore) + }) + } else { + suite.Require().Panics(func() { + types.NewMigrateProposalWrappedStore(subjectStore, substituteStore) + }) + } + }) + } +} + func (suite *TypesTestSuite) TestGetClientID() { clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), defaultWasmClientID)