Skip to content

Commit

Permalink
Rename IsBound to HasCapability (#3253)
Browse files Browse the repository at this point in the history
## Description



closes: #828


### Commit Message / Changelog Entry

```bash
imp(api!): rename `IsBound` to `HasCapability` for IBC application modules
```

see the [guidelines](https://github.com/cosmos/ibc-go/blob/main/docs/dev/pull-requests.md#commit-messages) for commit messages. (view raw markdown for examples)




---

Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

- [ ] Targeted PR against correct branch (see [CONTRIBUTING.md](https://github.com/cosmos/ibc-go/blob/main/docs/dev/pull-requests.md#pull-request-targeting)).
- [x] Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
- [x] Code follows the [module structure standards](https://github.com/cosmos/cosmos-sdk/blob/main/docs/docs/building-modules/10-structure.md) and [Go style guide](../docs/dev/go-style-guide.md).
- [ ] Wrote unit and integration [tests](https://github.com/cosmos/ibc-go/blob/main/testing/README.md#ibc-testing-package).
- [ ] Updated relevant documentation (`docs/`) or specification (`x/<module>/spec/`).
- [ ] Added relevant `godoc` [comments](https://blog.golang.org/godoc-documenting-go-code).
- [ ] Provide a [commit message](https://github.com/cosmos/ibc-go/blob/main/docs/dev/pull-requests.md#commit-messages) to be used for the changelog entry in the PR description for review.
- [ ] Re-reviewed `Files changed` in the Github PR explorer.
- [ ] Review `Codecov Report` in the comment section below once CI passes.
  • Loading branch information
expertdicer authored Mar 14, 2023
1 parent 1bdb0e9 commit be4c2d0
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion docs/ibc/apps.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, state types.GenesisState

// Only try to bind to port if it is not already bound, since we may already own
// port capability from capability InitGenesis
if !isBound(ctx, state.PortID) {
if !hasCapability(ctx, state.PortID) {
// module binds to desired ports on InitChain
// and claims returned capabilities
cap1 := keeper.IBCPortKeeper.BindPort(ctx, port1)
Expand Down
2 changes: 1 addition & 1 deletion docs/ibc/apps/bindports.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Currently, ports must be bound on app initialization. In order to bind modules t
// Only try to bind to port if it is not already bound, since we may already own
// port capability from capability InitGenesis
if !k.IsBound(ctx, state.PortId) {
if !k.HasCapability(ctx, state.PortId) {
// transfer module binds to the transfer port on InitChain
// and claims the returned capability
err := k.BindPort(ctx, state.PortId)
Expand Down
4 changes: 2 additions & 2 deletions docs/ibc/apps/keeper.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func NewKeeper(
}
}

// IsBound checks if the IBC app module is already bound to the desired port
func (k Keeper) IsBound(ctx sdk.Context, portID string) bool {
// HasCapability checks if the IBC app module owns the port capability for the desired port
func (k Keeper) HasCapability(ctx sdk.Context, portID string) bool {
_, ok := k.scopedKeeper.GetCapability(ctx, host.PortPath(portID))
return ok
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (k Keeper) registerInterchainAccount(ctx sdk.Context, connectionID, portID,
}

switch {
case k.portKeeper.IsBound(ctx, portID) && !k.IsBound(ctx, portID):
case k.portKeeper.IsBound(ctx, portID) && !k.HasCapability(ctx, portID):
return "", errorsmod.Wrapf(icatypes.ErrPortAlreadyBound, "another module has claimed capability for and bound port with portID: %s", portID)
case !k.portKeeper.IsBound(ctx, portID):
cap := k.BindPort(ctx, portID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// InitGenesis initializes the interchain accounts controller application state from a provided genesis state
func InitGenesis(ctx sdk.Context, keeper Keeper, state genesistypes.ControllerGenesisState) {
for _, portID := range state.Ports {
if !keeper.IsBound(ctx, portID) {
if !keeper.HasCapability(ctx, portID) {
cap := keeper.BindPort(ctx, portID)
if err := keeper.ClaimCapability(ctx, cap, host.PortPath(portID)); err != nil {
panic(fmt.Sprintf("could not claim port capability: %v", err))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ func (k Keeper) BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capabi
return k.portKeeper.BindPort(ctx, portID)
}

// IsBound checks if the interchain account controller module is already bound to the desired port
func (k Keeper) IsBound(ctx sdk.Context, portID string) bool {
// HasCapability checks if the interchain account controller module owns the port capability for the desired port
func (k Keeper) HasCapability(ctx sdk.Context, portID string) bool {
_, ok := k.scopedKeeper.GetCapability(ctx, host.PortPath(portID))
return ok
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(KeeperTestSuite))
}

func (suite *KeeperTestSuite) TestIsBound() {
func (suite *KeeperTestSuite) TestHasCapability() {
suite.SetupTest()

path := NewICAPath(suite.chainA, suite.chainB)
Expand All @@ -115,8 +115,8 @@ func (suite *KeeperTestSuite) TestIsBound() {
err := SetupICAPath(path, TestOwnerAddress)
suite.Require().NoError(err)

isBound := suite.chainA.GetSimApp().ICAControllerKeeper.IsBound(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID)
suite.Require().True(isBound)
hasCapability := suite.chainA.GetSimApp().ICAControllerKeeper.HasCapability(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID)
suite.Require().True(hasCapability)
}

func (suite *KeeperTestSuite) TestGetAllPorts() {
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/27-interchain-accounts/host/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

// InitGenesis initializes the interchain accounts host application state from a provided genesis state
func InitGenesis(ctx sdk.Context, keeper Keeper, state genesistypes.HostGenesisState) {
if !keeper.IsBound(ctx, state.Port) {
if !keeper.HasCapability(ctx, state.Port) {
cap := keeper.BindPort(ctx, state.Port)
if err := keeper.ClaimCapability(ctx, cap, host.PortPath(state.Port)); err != nil {
panic(fmt.Sprintf("could not claim port capability: %v", err))
Expand Down
4 changes: 2 additions & 2 deletions modules/apps/27-interchain-accounts/host/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ func (k Keeper) BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capabi
return k.portKeeper.BindPort(ctx, portID)
}

// IsBound checks if the interchain account host module is already bound to the desired port
func (k Keeper) IsBound(ctx sdk.Context, portID string) bool {
// HasCapability checks if the interchain account host module owns the port capability for the desired port
func (k Keeper) HasCapability(ctx sdk.Context, portID string) bool {
_, ok := k.scopedKeeper.GetCapability(ctx, host.PortPath(portID))
return ok
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(KeeperTestSuite))
}

func (suite *KeeperTestSuite) TestIsBound() {
func (suite *KeeperTestSuite) TestHasCapability() {
suite.SetupTest()

path := NewICAPath(suite.chainA, suite.chainB)
Expand All @@ -115,8 +115,8 @@ func (suite *KeeperTestSuite) TestIsBound() {
err := SetupICAPath(path, TestOwnerAddress)
suite.Require().NoError(err)

isBound := suite.chainB.GetSimApp().ICAHostKeeper.IsBound(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID)
suite.Require().True(isBound)
hasCapability := suite.chainB.GetSimApp().ICAHostKeeper.HasCapability(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID)
suite.Require().True(hasCapability)
}

func (suite *KeeperTestSuite) TestGetInterchainAccountAddress() {
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/transfer/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) {

// Only try to bind to port if it is not already bound, since we may already own
// port capability from capability InitGenesis
if !k.IsBound(ctx, state.PortId) {
if !k.HasCapability(ctx, state.PortId) {
// transfer module binds to the transfer port on InitChain
// and claims the returned capability
err := k.BindPort(ctx, state.PortId)
Expand Down
4 changes: 2 additions & 2 deletions modules/apps/transfer/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", "x/"+exported.ModuleName+"-"+types.ModuleName)
}

// IsBound checks if the transfer module is already bound to the desired port
func (k Keeper) IsBound(ctx sdk.Context, portID string) bool {
// HasCapability checks if the transfer module owns the port capability for the desired port
func (k Keeper) HasCapability(ctx sdk.Context, portID string) bool {
_, ok := k.scopedKeeper.GetCapability(ctx, host.PortPath(portID))
return ok
}
Expand Down

0 comments on commit be4c2d0

Please sign in to comment.