Skip to content

Commit b025dd9

Browse files
committed
removing GetPort in favour of GetAllPorts
1 parent 4923dfc commit b025dd9

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

modules/apps/27-interchain-accounts/genesis.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, state types.GenesisState
2424
func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) *types.GenesisState {
2525
// TODO: Using a range query with KVStorePrefixIterator export all port IDs
2626
// See https://github.com/cosmos/ibc-go/issues/448
27-
portID := keeper.GetPort(ctx, types.PortID)
2827

2928
return &types.GenesisState{
30-
PortId: portID,
29+
PortId: types.PortID,
3130
}
3231
}

modules/apps/27-interchain-accounts/keeper/keeper.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package keeper
22

33
import (
44
"fmt"
5+
"strings"
56

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

89-
// GetPort returns the portID for the interchain accounts module. Used in ExportGenesis
90-
func (k Keeper) GetPort(ctx sdk.Context, portID string) string {
90+
// GetAllPorts returns all ports to which the interchain accounts module is bound. Used in ExportGenesis
91+
func (k Keeper) GetAllPorts(ctx sdk.Context) []string {
9192
store := ctx.KVStore(k.storeKey)
92-
return string(store.Get(types.KeyPort(portID)))
93+
iterator := sdk.KVStorePrefixIterator(store, []byte(types.PortKeyPrefix))
94+
defer iterator.Close()
95+
96+
var ports []string
97+
for ; iterator.Valid(); iterator.Next() {
98+
keySplit := strings.Split(string(iterator.Key()), "/")
99+
100+
ports = append(ports, keySplit[1])
101+
}
102+
103+
return ports
93104
}
94105

95106
// BindPort stores the provided portID and binds to it, returning the associated capability

modules/apps/27-interchain-accounts/keeper/keeper_test.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,17 @@ func (suite *KeeperTestSuite) TestIsBound() {
108108
suite.Require().True(isBound)
109109
}
110110

111-
func (suite *KeeperTestSuite) TestGetPort() {
112-
port := suite.chainA.GetSimApp().ICAKeeper.GetPort(suite.chainA.GetContext(), types.PortID)
113-
suite.Require().Equal(string([]byte{0x01}), port)
111+
func (suite *KeeperTestSuite) TestGetAllPorts() {
112+
suite.SetupTest()
113+
path := NewICAPath(suite.chainA, suite.chainB)
114+
suite.coordinator.SetupConnections(path)
115+
116+
err := SetupICAPath(path, TestOwnerAddress)
117+
suite.Require().NoError(err)
118+
119+
ports := suite.chainA.GetSimApp().ICAKeeper.GetAllPorts(suite.chainA.GetContext())
120+
suite.Require().Contains(ports, types.PortID)
121+
suite.Require().Contains(ports, TestPortID)
114122
}
115123

116124
func (suite *KeeperTestSuite) TestGetInterchainAccountAddress() {

0 commit comments

Comments
 (0)