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

refactor: making IsBound a public function #425

Merged
merged 5 commits into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Improvements

* [\#383](https://github.com/cosmos/ibc-go/pull/383) Adds helper functions for merging and splitting middleware versions from the underlying app version.
* (modules/core/05-port) [\#288](https://github.com/cosmos/ibc-go/issues/288) Making the 05-port keeper function IsBound public. The IsBound function checks if the provided portID is already binded to a module.

### Features

Expand Down
6 changes: 3 additions & 3 deletions modules/core/05-port/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", "x/"+host.ModuleName+"/"+types.SubModuleName)
}

// isBounded checks a given port ID is already bounded.
func (k Keeper) isBound(ctx sdk.Context, portID string) bool {
// IsBound checks a given port ID is already bounded.
func (k Keeper) IsBound(ctx sdk.Context, portID string) bool {
_, ok := k.scopedKeeper.GetCapability(ctx, host.PortPath(portID))
return ok
}
Expand All @@ -46,7 +46,7 @@ func (k *Keeper) BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capab
panic(err.Error())
}

if k.isBound(ctx, portID) {
if k.IsBound(ctx, portID) {
panic(fmt.Sprintf("port %s is already bound", portID))
}

Expand Down
6 changes: 6 additions & 0 deletions modules/core/05-port/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ func (suite *KeeperTestSuite) TestBind() {
capKey := suite.keeper.BindPort(suite.ctx, validPort)
require.NotNil(suite.T(), capKey, "capabilityKey is nil on valid BindPort")

isBound := suite.keeper.IsBound(suite.ctx, validPort)
require.True(suite.T(), isBound, "port is bound successfully")

isNotBound := suite.keeper.IsBound(suite.ctx, "not-a-port")
require.False(suite.T(), isNotBound, "port is not bound")

// Test that rebinding the same portid causes panic
require.Panics(suite.T(), func() { suite.keeper.BindPort(suite.ctx, validPort) }, "did not panic on re-binding the same port")
}
Expand Down