Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a method to check if the scope module already exists in the capability keeper #6716

Merged
merged 7 commits into from
Jul 1, 2024
Merged
2 changes: 2 additions & 0 deletions modules/capability/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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 does not exist")
suite.Require().False(suite.keeper.HasModule("invalid"), "invalid module exists")
}

func (suite *KeeperTestSuite) TestNewCapability() {
sk := suite.keeper.ScopeToModule(bankModuleName)

Expand Down
Loading