From c043dbdeef4929988a02578606f8d8fdf21a3f25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=E1=BA=B7c?= <67097720+expertdicer@users.noreply.github.com> Date: Fri, 14 Apr 2023 14:07:13 +0700 Subject: [PATCH] imp(api)!: make `HasCapability` private (#3303) --- docs/ibc/apps/bindports.md | 2 +- docs/ibc/apps/keeper.md | 4 ++-- .../controller/keeper/account.go | 2 +- .../controller/keeper/genesis.go | 2 +- .../controller/keeper/keeper.go | 4 ++-- .../controller/keeper/keeper_test.go | 13 ------------- .../27-interchain-accounts/host/keeper/genesis.go | 2 +- .../27-interchain-accounts/host/keeper/keeper.go | 4 ++-- .../host/keeper/keeper_test.go | 13 ------------- modules/apps/transfer/keeper/genesis.go | 2 +- modules/apps/transfer/keeper/keeper.go | 4 ++-- 11 files changed, 13 insertions(+), 39 deletions(-) diff --git a/docs/ibc/apps/bindports.md b/docs/ibc/apps/bindports.md index 07bdff224e1..d5c808c4c59 100644 --- a/docs/ibc/apps/bindports.md +++ b/docs/ibc/apps/bindports.md @@ -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.HasCapability(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) diff --git a/docs/ibc/apps/keeper.md b/docs/ibc/apps/keeper.md index f108d0b9f32..5c69cc4f558 100644 --- a/docs/ibc/apps/keeper.md +++ b/docs/ibc/apps/keeper.md @@ -48,8 +48,8 @@ func NewKeeper( } } -// 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 { +// 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 } diff --git a/modules/apps/27-interchain-accounts/controller/keeper/account.go b/modules/apps/27-interchain-accounts/controller/keeper/account.go index 9afa25dfd83..f647569e512 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/account.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/account.go @@ -58,7 +58,7 @@ func (k Keeper) registerInterchainAccount(ctx sdk.Context, connectionID, portID, } switch { - case k.portKeeper.IsBound(ctx, portID) && !k.HasCapability(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): capability := k.BindPort(ctx, portID) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/genesis.go b/modules/apps/27-interchain-accounts/controller/keeper/genesis.go index ca5d37fdcb3..1f35f4c0b7d 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/genesis.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/genesis.go @@ -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.HasCapability(ctx, portID) { + if !keeper.hasCapability(ctx, portID) { capability := keeper.BindPort(ctx, portID) if err := keeper.ClaimCapability(ctx, capability, host.PortPath(portID)); err != nil { panic(fmt.Sprintf("could not claim port capability: %v", err)) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go index 0b2d89b547b..ceeffaa5737 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go @@ -98,8 +98,8 @@ func (k Keeper) BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capabi return k.portKeeper.BindPort(ctx, portID) } -// 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 { +// 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 } diff --git a/modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go b/modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go index b751f876608..e5d444973e5 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go @@ -102,19 +102,6 @@ func TestKeeperTestSuite(t *testing.T) { suite.Run(t, new(KeeperTestSuite)) } -func (suite *KeeperTestSuite) TestHasCapability() { - suite.SetupTest() - - path := NewICAPath(suite.chainA, suite.chainB) - suite.coordinator.SetupConnections(path) - - err := SetupICAPath(path, TestOwnerAddress) - suite.Require().NoError(err) - - hasCapability := suite.chainA.GetSimApp().ICAControllerKeeper.HasCapability(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID) - suite.Require().True(hasCapability) -} - func (suite *KeeperTestSuite) TestGetAllPorts() { suite.SetupTest() diff --git a/modules/apps/27-interchain-accounts/host/keeper/genesis.go b/modules/apps/27-interchain-accounts/host/keeper/genesis.go index b4ba0ed6cf2..4816f957a58 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/genesis.go +++ b/modules/apps/27-interchain-accounts/host/keeper/genesis.go @@ -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.HasCapability(ctx, state.Port) { + if !keeper.hasCapability(ctx, state.Port) { capability := keeper.BindPort(ctx, state.Port) if err := keeper.ClaimCapability(ctx, capability, host.PortPath(state.Port)); err != nil { panic(fmt.Sprintf("could not claim port capability: %v", err)) diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper.go b/modules/apps/27-interchain-accounts/host/keeper/keeper.go index 7d60cc334e6..a922b38cca9 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper.go @@ -78,8 +78,8 @@ func (k Keeper) BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capabi return k.portKeeper.BindPort(ctx, portID) } -// 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 { +// 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 } diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go index 78a83e37644..6a731ef66fc 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go @@ -102,19 +102,6 @@ func TestKeeperTestSuite(t *testing.T) { suite.Run(t, new(KeeperTestSuite)) } -func (suite *KeeperTestSuite) TestHasCapability() { - suite.SetupTest() - - path := NewICAPath(suite.chainA, suite.chainB) - suite.coordinator.SetupConnections(path) - - err := SetupICAPath(path, TestOwnerAddress) - suite.Require().NoError(err) - - hasCapability := suite.chainB.GetSimApp().ICAHostKeeper.HasCapability(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID) - suite.Require().True(hasCapability) -} - func (suite *KeeperTestSuite) TestGetInterchainAccountAddress() { suite.SetupTest() diff --git a/modules/apps/transfer/keeper/genesis.go b/modules/apps/transfer/keeper/genesis.go index 89ce4697624..5a7778341a4 100644 --- a/modules/apps/transfer/keeper/genesis.go +++ b/modules/apps/transfer/keeper/genesis.go @@ -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.HasCapability(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) diff --git a/modules/apps/transfer/keeper/keeper.go b/modules/apps/transfer/keeper/keeper.go index 25da4dd3c95..335be921c33 100644 --- a/modules/apps/transfer/keeper/keeper.go +++ b/modules/apps/transfer/keeper/keeper.go @@ -64,8 +64,8 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", "x/"+exported.ModuleName+"-"+types.ModuleName) } -// HasCapability checks if the transfer module owns the port capability for the desired port -func (k Keeper) HasCapability(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 }