Skip to content

Commit

Permalink
removing GetPort in favour of GetAllPorts
Browse files Browse the repository at this point in the history
  • Loading branch information
damiannolan committed Oct 7, 2021
1 parent 4923dfc commit b025dd9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
3 changes: 1 addition & 2 deletions modules/apps/27-interchain-accounts/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, state types.GenesisState
func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) *types.GenesisState {
// TODO: Using a range query with KVStorePrefixIterator export all port IDs
// See https://github.com/cosmos/ibc-go/issues/448
portID := keeper.GetPort(ctx, types.PortID)

return &types.GenesisState{
PortId: portID,
PortId: types.PortID,
}
}
17 changes: 14 additions & 3 deletions modules/apps/27-interchain-accounts/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"fmt"
"strings"

baseapp "github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
Expand Down Expand Up @@ -86,10 +87,20 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s-%s", host.ModuleName, types.ModuleName))
}

// GetPort returns the portID for the interchain accounts module. Used in ExportGenesis
func (k Keeper) GetPort(ctx sdk.Context, portID string) string {
// GetAllPorts returns all ports to which the interchain accounts module is bound. Used in ExportGenesis
func (k Keeper) GetAllPorts(ctx sdk.Context) []string {
store := ctx.KVStore(k.storeKey)
return string(store.Get(types.KeyPort(portID)))
iterator := sdk.KVStorePrefixIterator(store, []byte(types.PortKeyPrefix))
defer iterator.Close()

var ports []string
for ; iterator.Valid(); iterator.Next() {
keySplit := strings.Split(string(iterator.Key()), "/")

ports = append(ports, keySplit[1])
}

return ports
}

// BindPort stores the provided portID and binds to it, returning the associated capability
Expand Down
14 changes: 11 additions & 3 deletions modules/apps/27-interchain-accounts/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,17 @@ func (suite *KeeperTestSuite) TestIsBound() {
suite.Require().True(isBound)
}

func (suite *KeeperTestSuite) TestGetPort() {
port := suite.chainA.GetSimApp().ICAKeeper.GetPort(suite.chainA.GetContext(), types.PortID)
suite.Require().Equal(string([]byte{0x01}), port)
func (suite *KeeperTestSuite) TestGetAllPorts() {
suite.SetupTest()
path := NewICAPath(suite.chainA, suite.chainB)
suite.coordinator.SetupConnections(path)

err := SetupICAPath(path, TestOwnerAddress)
suite.Require().NoError(err)

ports := suite.chainA.GetSimApp().ICAKeeper.GetAllPorts(suite.chainA.GetContext())
suite.Require().Contains(ports, types.PortID)
suite.Require().Contains(ports, TestPortID)
}

func (suite *KeeperTestSuite) TestGetInterchainAccountAddress() {
Expand Down

0 comments on commit b025dd9

Please sign in to comment.