diff --git a/modules/capability/CHANGELOG.md b/modules/capability/CHANGELOG.md index f0ee998d580..b58e88afb56 100644 --- a/modules/capability/CHANGELOG.md +++ b/modules/capability/CHANGELOG.md @@ -41,6 +41,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +* [\#6716](https://github.com/cosmos/ibc-go/pull/6716) Add `HasModule` to capability keeper to allow checking if a scoped module already exists. + ### Features ### Bug Fixes diff --git a/modules/capability/keeper/keeper.go b/modules/capability/keeper/keeper.go index 2e663b536fc..5d856c5e64b 100644 --- a/modules/capability/keeper/keeper.go +++ b/modules/capability/keeper/keeper.go @@ -66,6 +66,12 @@ func NewKeeper(cdc codec.BinaryCodec, storeKey, memKey storetypes.StoreKey) *Kee } } +// HasModule checks if the module name already has a ScopedKeeper. +func (k *Keeper) HasModule(moduleName string) bool { + _, ok := k.scopedModules[moduleName] + return ok +} + // ScopeToModule attempts to create and return a ScopedKeeper for a given module // by name. It will panic if the keeper is already sealed or if the module name // already has a ScopedKeeper. diff --git a/modules/capability/keeper/keeper_test.go b/modules/capability/keeper/keeper_test.go index 7585da92c20..c2cd70597dc 100644 --- a/modules/capability/keeper/keeper_test.go +++ b/modules/capability/keeper/keeper_test.go @@ -76,6 +76,12 @@ func (suite *KeeperTestSuite) TestSeal() { }) } +func (suite *KeeperTestSuite) TestHasModule() { + _ = suite.keeper.ScopeToModule(bankModuleName) + suite.Require().True(suite.keeper.HasModule(bankModuleName), "bank module does not exist") + suite.Require().False(suite.keeper.HasModule("invalid"), "invalid module exists") +} + func (suite *KeeperTestSuite) TestNewCapability() { sk := suite.keeper.ScopeToModule(bankModuleName)