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..d2b7fcf6589 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 not exist") + suite.Require().False(suite.keeper.HasModule("invalid"), "invalid module exist") +} + func (suite *KeeperTestSuite) TestNewCapability() { sk := suite.keeper.ScopeToModule(bankModuleName)