From d7117fdbe9675daf8ebb6e56150c8d5ab73dd0fd Mon Sep 17 00:00:00 2001 From: expertdicer Date: Thu, 16 Mar 2023 12:08:12 +0700 Subject: [PATCH 1/8] make hasCapability private --- .../controller/keeper/account.go | 2 +- .../controller/keeper/export_test.go | 10 ++++++++++ .../controller/keeper/genesis.go | 2 +- .../27-interchain-accounts/controller/keeper/keeper.go | 4 ++-- 4 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 modules/apps/27-interchain-accounts/controller/keeper/export_test.go diff --git a/modules/apps/27-interchain-accounts/controller/keeper/account.go b/modules/apps/27-interchain-accounts/controller/keeper/account.go index 71c6947158d..f4bdcc15ce8 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): cap := k.BindPort(ctx, portID) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/export_test.go b/modules/apps/27-interchain-accounts/controller/keeper/export_test.go new file mode 100644 index 00000000000..c6490b3e1a7 --- /dev/null +++ b/modules/apps/27-interchain-accounts/controller/keeper/export_test.go @@ -0,0 +1,10 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// SetParams sets the total set of params. +func (k Keeper) HasCapability(ctx sdk.Context, portID string) bool { + return k.hasCapability(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 a018d5d8c14..510aed89c3b 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) { 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)) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go index edb9a69299e..6e67d7ce82f 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 } From c11f856194e5628f0ce3990c20896123eae33e24 Mon Sep 17 00:00:00 2001 From: expertdicer Date: Thu, 16 Mar 2023 12:12:22 +0700 Subject: [PATCH 2/8] make hasCapability private --- .../27-interchain-accounts/host/keeper/export_test.go | 10 ++++++++++ .../apps/27-interchain-accounts/host/keeper/genesis.go | 2 +- .../apps/27-interchain-accounts/host/keeper/keeper.go | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 modules/apps/27-interchain-accounts/host/keeper/export_test.go diff --git a/modules/apps/27-interchain-accounts/host/keeper/export_test.go b/modules/apps/27-interchain-accounts/host/keeper/export_test.go new file mode 100644 index 00000000000..c6490b3e1a7 --- /dev/null +++ b/modules/apps/27-interchain-accounts/host/keeper/export_test.go @@ -0,0 +1,10 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// SetParams sets the total set of params. +func (k Keeper) HasCapability(ctx sdk.Context, portID string) bool { + return k.hasCapability(ctx, portID) +} diff --git a/modules/apps/27-interchain-accounts/host/keeper/genesis.go b/modules/apps/27-interchain-accounts/host/keeper/genesis.go index 6a31978d589..41adcca3690 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) { 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)) diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper.go b/modules/apps/27-interchain-accounts/host/keeper/keeper.go index d89a7ecbee5..87da7121831 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper.go @@ -79,7 +79,7 @@ func (k Keeper) BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capabi } // 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 { +func (k Keeper) hasCapability(ctx sdk.Context, portID string) bool { _, ok := k.scopedKeeper.GetCapability(ctx, host.PortPath(portID)) return ok } From 47a6dab898871d056eb853978a54c60a0c461678 Mon Sep 17 00:00:00 2001 From: expertdicer Date: Thu, 16 Mar 2023 12:13:05 +0700 Subject: [PATCH 3/8] make hasCapability private --- modules/apps/27-interchain-accounts/host/keeper/keeper.go | 2 +- modules/apps/transfer/keeper/genesis.go | 2 +- modules/apps/transfer/keeper/keeper.go | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper.go b/modules/apps/27-interchain-accounts/host/keeper/keeper.go index 87da7121831..5b655e2e8a1 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper.go @@ -78,7 +78,7 @@ 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 +// 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/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 49f828f021e..d77b6b673ba 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 } From 1d297827d6b66448ade7c407c3d482e0866183ca Mon Sep 17 00:00:00 2001 From: expertdicer Date: Thu, 16 Mar 2023 12:14:11 +0700 Subject: [PATCH 4/8] make hasCapability private --- docs/ibc/apps/bindports.md | 2 +- docs/ibc/apps/keeper.md | 4 ++-- 2 files changed, 3 insertions(+), 3 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 } From 8955a3613d0519aab8f0e8bc60cb50e298126066 Mon Sep 17 00:00:00 2001 From: expertdicer Date: Mon, 20 Mar 2023 21:14:06 +0700 Subject: [PATCH 5/8] dev docs update --- .../27-interchain-accounts/controller/keeper/export_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/export_test.go b/modules/apps/27-interchain-accounts/controller/keeper/export_test.go index c6490b3e1a7..c6b998f369c 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/export_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/export_test.go @@ -4,7 +4,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -// SetParams sets the total set of params. +// 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 { return k.hasCapability(ctx, portID) } From 6f429f5ff9b82c0baf361dd2c796c987e9ece4c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=E1=BA=B7c?= Date: Thu, 6 Apr 2023 11:09:21 +0700 Subject: [PATCH 6/8] remove unused export test --- .../controller/keeper/export_test.go | 10 ---------- .../controller/keeper/keeper_test.go | 13 ------------- 2 files changed, 23 deletions(-) delete mode 100644 modules/apps/27-interchain-accounts/controller/keeper/export_test.go diff --git a/modules/apps/27-interchain-accounts/controller/keeper/export_test.go b/modules/apps/27-interchain-accounts/controller/keeper/export_test.go deleted file mode 100644 index c6b998f369c..00000000000 --- a/modules/apps/27-interchain-accounts/controller/keeper/export_test.go +++ /dev/null @@ -1,10 +0,0 @@ -package keeper - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" -) - -// 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 { - return k.hasCapability(ctx, portID) -} 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 9f80aa507e0..7e28f14fae8 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go @@ -106,19 +106,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() From f8ff330690c433cdf81b537ff69b442d833a9514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=E1=BA=B7c?= Date: Wed, 12 Apr 2023 11:54:06 +0700 Subject: [PATCH 7/8] lint --- .../apps/27-interchain-accounts/controller/keeper/genesis.go | 4 ++-- modules/apps/27-interchain-accounts/host/keeper/genesis.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/genesis.go b/modules/apps/27-interchain-accounts/controller/keeper/genesis.go index 510aed89c3b..1f35f4c0b7d 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/genesis.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/genesis.go @@ -13,8 +13,8 @@ import ( func InitGenesis(ctx sdk.Context, keeper Keeper, state genesistypes.ControllerGenesisState) { for _, portID := range state.Ports { if !keeper.hasCapability(ctx, portID) { - cap := keeper.BindPort(ctx, portID) - if err := keeper.ClaimCapability(ctx, cap, host.PortPath(portID)); err != nil { + 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/host/keeper/genesis.go b/modules/apps/27-interchain-accounts/host/keeper/genesis.go index 41adcca3690..4816f957a58 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/genesis.go +++ b/modules/apps/27-interchain-accounts/host/keeper/genesis.go @@ -13,8 +13,8 @@ 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) { - cap := keeper.BindPort(ctx, state.Port) - if err := keeper.ClaimCapability(ctx, cap, host.PortPath(state.Port)); err != nil { + 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)) } } From fd52dfda93314ec8b9da25a68786c342c333cd6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=E1=BA=B7c?= Date: Wed, 12 Apr 2023 16:06:31 +0700 Subject: [PATCH 8/8] remove export_test --- .../host/keeper/export_test.go | 10 ---------- .../host/keeper/keeper_test.go | 13 ------------- 2 files changed, 23 deletions(-) delete mode 100644 modules/apps/27-interchain-accounts/host/keeper/export_test.go diff --git a/modules/apps/27-interchain-accounts/host/keeper/export_test.go b/modules/apps/27-interchain-accounts/host/keeper/export_test.go deleted file mode 100644 index c6490b3e1a7..00000000000 --- a/modules/apps/27-interchain-accounts/host/keeper/export_test.go +++ /dev/null @@ -1,10 +0,0 @@ -package keeper - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" -) - -// SetParams sets the total set of params. -func (k Keeper) HasCapability(ctx sdk.Context, portID string) bool { - return k.hasCapability(ctx, portID) -} 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()