Skip to content

Commit

Permalink
Do not panic when getting params.
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitrisJim committed Jun 1, 2023
1 parent adb29be commit 4ef0dc9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
4 changes: 2 additions & 2 deletions modules/core/03-connection/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ func (k Keeper) addConnectionToClient(ctx sdk.Context, clientID, connectionID st
func (k Keeper) GetParams(ctx sdk.Context) types.Params {
store := ctx.KVStore(k.storeKey)
bz := store.Get([]byte(types.ParamsKey))
if bz == nil { // only panic on unset params and not on empty params
panic("controller params are not set in store")
if len(bz) == 0 {
return types.Params{}
}

var params types.Params
Expand Down
6 changes: 2 additions & 4 deletions modules/core/03-connection/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,12 @@ func (suite *KeeperTestSuite) TestParams() {
}
}

// TestUnsetParams tests that trying to get params that are not set panics.
// TestUnsetParams tests that trying to get params that are not set results in empty params.
func (suite *KeeperTestSuite) TestUnsetParams() {
suite.SetupTest()
ctx := suite.chainA.GetContext()
store := ctx.KVStore(suite.chainA.GetSimApp().GetKey(exported.StoreKey))
store.Delete([]byte(types.ParamsKey))

suite.Require().Panics(func() {
suite.chainA.GetSimApp().IBCKeeper.ConnectionKeeper.GetParams(ctx)
})
suite.Require().Equal(suite.chainA.GetSimApp().IBCKeeper.ConnectionKeeper.GetParams(ctx), types.Params{})
}

0 comments on commit 4ef0dc9

Please sign in to comment.