Skip to content

Commit

Permalink
add method to check if the scope module already exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Pantani committed Jun 27, 2024
1 parent 89a849f commit 4457b44
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions modules/capability/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions modules/capability/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 4457b44

Please sign in to comment.