Skip to content

Commit

Permalink
Panic when creating wrapped store if substores are nil.
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitrisJim committed Dec 4, 2023
1 parent 783e4e2 commit d99f4a0
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
7 changes: 7 additions & 0 deletions modules/light-clients/08-wasm/types/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
49 changes: 49 additions & 0 deletions modules/light-clients/08-wasm/types/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit d99f4a0

Please sign in to comment.