From 5e91e1a62a5dcd5a5a319c2fcf6089e57bed305a Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Fri, 8 Oct 2021 11:41:32 +0200 Subject: [PATCH 1/6] initial genesis state draft --- docs/ibc/proto-docs.md | 38 +- .../apps/27-interchain-accounts/genesis.go | 48 +- .../27-interchain-accounts/genesis_test.go | 25 + .../27-interchain-accounts/keeper/keeper.go | 29 +- .../keeper/keeper_test.go | 14 +- .../27-interchain-accounts/types/genesis.go | 13 +- .../types/genesis.pb.go | 617 +++++++++++++++++- .../apps/27-interchain-accounts/types/keys.go | 21 +- .../27-interchain-accounts/types/types.pb.go | 2 +- .../interchain_accounts/v1/genesis.proto | 16 +- .../interchain_accounts/v1/types.proto | 4 +- 11 files changed, 780 insertions(+), 47 deletions(-) create mode 100644 modules/apps/27-interchain-accounts/genesis_test.go diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index 986ffd334f8..fbdb6805ed1 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -9,6 +9,8 @@ - [ibc/applications/interchain_accounts/v1/genesis.proto](#ibc/applications/interchain_accounts/v1/genesis.proto) - [GenesisState](#ibc.applications.interchain_accounts.v1.GenesisState) + - [IdentifiedActiveChannel](#ibc.applications.interchain_accounts.v1.IdentifiedActiveChannel) + - [IdentifiedInterchainAccount](#ibc.applications.interchain_accounts.v1.IdentifiedInterchainAccount) - [ibc/applications/interchain_accounts/v1/query.proto](#ibc/applications/interchain_accounts/v1/query.proto) - [QueryInterchainAccountAddressRequest](#ibc.applications.interchain_accounts.v1.QueryInterchainAccountAddressRequest) @@ -317,9 +319,43 @@ An InterchainAccount is defined as a BaseAccount & the address of the account ow GenesisState defines the interchain_account genesis state +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `active_channels` | [IdentifiedActiveChannel](#ibc.applications.interchain_accounts.v1.IdentifiedActiveChannel) | repeated | | +| `interchain_accounts` | [IdentifiedInterchainAccount](#ibc.applications.interchain_accounts.v1.IdentifiedInterchainAccount) | repeated | | +| `ports` | [string](#string) | repeated | | + + + + + + + + +### IdentifiedActiveChannel +IdentifiedActiveChannel + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `port_id` | [string](#string) | | | +| `channel_id` | [string](#string) | | | + + + + + + + + +### IdentifiedInterchainAccount +IdentifiedInterchainAccount + + | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | `port_id` | [string](#string) | | | +| `account_address` | [string](#string) | | | @@ -416,7 +452,7 @@ Body of a tx for an ics27 IBC packet ### InterchainAccountPacketData -InterchainAccountPacketData is comprised of araw transaction,type of transaction and optional memo field. +InterchainAccountPacketData is comprised of a raw transaction, type of transaction and optional memo field. | Field | Type | Label | Description | diff --git a/modules/apps/27-interchain-accounts/genesis.go b/modules/apps/27-interchain-accounts/genesis.go index 0fd975ace00..601dbad285c 100644 --- a/modules/apps/27-interchain-accounts/genesis.go +++ b/modules/apps/27-interchain-accounts/genesis.go @@ -12,19 +12,51 @@ import ( // InitGenesis initializes the interchain accounts application state from a provided genesis state func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, state types.GenesisState) { - if !keeper.IsBound(ctx, state.PortId) { - cap := keeper.BindPort(ctx, state.PortId) - if err := keeper.ClaimCapability(ctx, cap, host.PortPath(state.PortId)); err != nil { - panic(fmt.Sprintf("could not claim port capability: %v", err)) + for _, portID := range state.Ports { + if !keeper.IsBound(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)) + } } } + + for _, ch := range state.ActiveChannels { + keeper.SetActiveChannel(ctx, ch.PortId, ch.ChannelId) + } + + for _, acc := range state.InterchainAccounts { + keeper.SetInterchainAccountAddress(ctx, acc.PortId, acc.AccountAddress) + } } -// ExportGenesis exports transfer module's portID into its geneis state +// ExportGenesis returns the interchain accounts exported genesis func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) *types.GenesisState { - portID := keeper.GetPort(ctx) + var ( + activeChannels []*types.IdentifiedActiveChannel + interchainAccounts []*types.IdentifiedInterchainAccount + ) + + ports := keeper.GetAllPorts(ctx) + for _, portID := range ports { + if channelID, found := keeper.GetActiveChannel(ctx, portID); found { + activeChan := &types.IdentifiedActiveChannel{ + PortId: portID, + ChannelId: channelID, + } - return &types.GenesisState{ - PortId: portID, + activeChannels = append(activeChannels, activeChan) + } + + if accountAddr, found := keeper.GetInterchainAccountAddress(ctx, portID); found { + interchainAcc := &types.IdentifiedInterchainAccount{ + PortId: portID, + AccountAddress: accountAddr, + } + + interchainAccounts = append(interchainAccounts, interchainAcc) + } } + + return types.NewGenesisState(ports, activeChannels, interchainAccounts) } diff --git a/modules/apps/27-interchain-accounts/genesis_test.go b/modules/apps/27-interchain-accounts/genesis_test.go new file mode 100644 index 00000000000..66497820a2e --- /dev/null +++ b/modules/apps/27-interchain-accounts/genesis_test.go @@ -0,0 +1,25 @@ +package interchain_accounts_test + +import ( + ica "github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts" + "github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types" +) + +func (suite *InterchainAccountsTestSuite) TestExportGenesis() { + suite.SetupTest() + path := NewICAPath(suite.chainA, suite.chainB) + suite.coordinator.SetupConnections(path) + + err := SetupICAPath(path, TestOwnerAddress) + suite.Require().NoError(err) + + genesisState := ica.ExportGenesis(suite.chainA.GetContext(), suite.chainA.GetSimApp().ICAKeeper) + + suite.Require().Equal([]string{types.PortID, TestPortID}, genesisState.GetPorts()) + + suite.Require().Equal(path.EndpointA.ChannelID, genesisState.ActiveChannels[0].ChannelId) + suite.Require().Equal(path.EndpointA.ChannelConfig.PortID, genesisState.ActiveChannels[0].PortId) + + suite.Require().Equal(TestAccAddress.String(), genesisState.InterchainAccounts[0].AccountAddress) + suite.Require().Equal(path.EndpointA.ChannelConfig.PortID, genesisState.InterchainAccounts[0].PortId) +} diff --git a/modules/apps/27-interchain-accounts/keeper/keeper.go b/modules/apps/27-interchain-accounts/keeper/keeper.go index 63b3e82fcea..74322b60ea3 100644 --- a/modules/apps/27-interchain-accounts/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/keeper/keeper.go @@ -2,6 +2,7 @@ package keeper import ( "fmt" + "strings" baseapp "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" @@ -86,16 +87,32 @@ 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) string { +// GetAllPorts returns all bound ports for the interchain accounts module. Used in ExportGenesis +func (k Keeper) GetAllPorts(ctx sdk.Context) []string { store := ctx.KVStore(k.storeKey) - return string(store.Get([]byte(types.PortKey))) + 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 +} + +// HasPort returns true if the provided portID is found in state, otherwise false +func (k Keeper) HasPort(ctx sdk.Context, portID string) bool { + store := ctx.KVStore(k.storeKey) + return store.Has(types.KeyPort(portID)) } // BindPort stores the provided portID and binds to it, returning the associated capability func (k Keeper) BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capability { store := ctx.KVStore(k.storeKey) - store.Set([]byte(types.PortKey), []byte(portID)) + store.Set(types.KeyPort(portID), []byte{0x01}) return k.portKeeper.BindPort(ctx, portID) } @@ -117,9 +134,9 @@ func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability } // GetActiveChannel retrieves the active channelID from the store keyed by the provided portID -func (k Keeper) GetActiveChannel(ctx sdk.Context, portId string) (string, bool) { +func (k Keeper) GetActiveChannel(ctx sdk.Context, portID string) (string, bool) { store := ctx.KVStore(k.storeKey) - key := types.KeyActiveChannel(portId) + key := types.KeyActiveChannel(portID) if !store.Has(key) { return "", false diff --git a/modules/apps/27-interchain-accounts/keeper/keeper_test.go b/modules/apps/27-interchain-accounts/keeper/keeper_test.go index 0c407e88121..307451fd14b 100644 --- a/modules/apps/27-interchain-accounts/keeper/keeper_test.go +++ b/modules/apps/27-interchain-accounts/keeper/keeper_test.go @@ -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()) - suite.Require().Equal(types.PortID, 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() { diff --git a/modules/apps/27-interchain-accounts/types/genesis.go b/modules/apps/27-interchain-accounts/types/genesis.go index e3a9bab7949..88a2d1e19ef 100644 --- a/modules/apps/27-interchain-accounts/types/genesis.go +++ b/modules/apps/27-interchain-accounts/types/genesis.go @@ -1,7 +1,18 @@ package types +// DefaultGenesis creates and returns the default interchain accounts GenesisState +// The default GenesisState includes the standard port identifier to which all host chains must bind func DefaultGenesis() *GenesisState { return &GenesisState{ - PortId: PortID, + Ports: []string{PortID}, + } +} + +// NewGenesisState creates a returns a new GenesisState instance +func NewGenesisState(ports []string, channels []*IdentifiedActiveChannel, accounts []*IdentifiedInterchainAccount) *GenesisState { + return &GenesisState{ + ActiveChannels: channels, + InterchainAccounts: accounts, + Ports: ports, } } diff --git a/modules/apps/27-interchain-accounts/types/genesis.pb.go b/modules/apps/27-interchain-accounts/types/genesis.pb.go index 44661c274c4..6411cef11a2 100644 --- a/modules/apps/27-interchain-accounts/types/genesis.pb.go +++ b/modules/apps/27-interchain-accounts/types/genesis.pb.go @@ -25,7 +25,9 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // GenesisState defines the interchain_account genesis state type GenesisState struct { - PortId string `protobuf:"bytes,1,opt,name=port_id,json=portId,proto3" json:"port_id,omitempty" yaml:"port_id"` + ActiveChannels []*IdentifiedActiveChannel `protobuf:"bytes,1,rep,name=active_channels,json=activeChannels,proto3" json:"active_channels,omitempty"` + InterchainAccounts []*IdentifiedInterchainAccount `protobuf:"bytes,2,rep,name=interchain_accounts,json=interchainAccounts,proto3" json:"interchain_accounts,omitempty"` + Ports []string `protobuf:"bytes,3,rep,name=ports,proto3" json:"ports,omitempty"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -61,15 +63,137 @@ func (m *GenesisState) XXX_DiscardUnknown() { var xxx_messageInfo_GenesisState proto.InternalMessageInfo -func (m *GenesisState) GetPortId() string { +func (m *GenesisState) GetActiveChannels() []*IdentifiedActiveChannel { + if m != nil { + return m.ActiveChannels + } + return nil +} + +func (m *GenesisState) GetInterchainAccounts() []*IdentifiedInterchainAccount { + if m != nil { + return m.InterchainAccounts + } + return nil +} + +func (m *GenesisState) GetPorts() []string { + if m != nil { + return m.Ports + } + return nil +} + +// IdentifiedActiveChannel +type IdentifiedActiveChannel struct { + PortId string `protobuf:"bytes,1,opt,name=port_id,json=portId,proto3" json:"port_id,omitempty"` + ChannelId string `protobuf:"bytes,2,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` +} + +func (m *IdentifiedActiveChannel) Reset() { *m = IdentifiedActiveChannel{} } +func (m *IdentifiedActiveChannel) String() string { return proto.CompactTextString(m) } +func (*IdentifiedActiveChannel) ProtoMessage() {} +func (*IdentifiedActiveChannel) Descriptor() ([]byte, []int) { + return fileDescriptor_629b3ced0911516b, []int{1} +} +func (m *IdentifiedActiveChannel) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *IdentifiedActiveChannel) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_IdentifiedActiveChannel.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *IdentifiedActiveChannel) XXX_Merge(src proto.Message) { + xxx_messageInfo_IdentifiedActiveChannel.Merge(m, src) +} +func (m *IdentifiedActiveChannel) XXX_Size() int { + return m.Size() +} +func (m *IdentifiedActiveChannel) XXX_DiscardUnknown() { + xxx_messageInfo_IdentifiedActiveChannel.DiscardUnknown(m) +} + +var xxx_messageInfo_IdentifiedActiveChannel proto.InternalMessageInfo + +func (m *IdentifiedActiveChannel) GetPortId() string { if m != nil { return m.PortId } return "" } +func (m *IdentifiedActiveChannel) GetChannelId() string { + if m != nil { + return m.ChannelId + } + return "" +} + +// IdentifiedInterchainAccount +type IdentifiedInterchainAccount struct { + PortId string `protobuf:"bytes,1,opt,name=port_id,json=portId,proto3" json:"port_id,omitempty"` + AccountAddress string `protobuf:"bytes,2,opt,name=account_address,json=accountAddress,proto3" json:"account_address,omitempty"` +} + +func (m *IdentifiedInterchainAccount) Reset() { *m = IdentifiedInterchainAccount{} } +func (m *IdentifiedInterchainAccount) String() string { return proto.CompactTextString(m) } +func (*IdentifiedInterchainAccount) ProtoMessage() {} +func (*IdentifiedInterchainAccount) Descriptor() ([]byte, []int) { + return fileDescriptor_629b3ced0911516b, []int{2} +} +func (m *IdentifiedInterchainAccount) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *IdentifiedInterchainAccount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_IdentifiedInterchainAccount.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *IdentifiedInterchainAccount) XXX_Merge(src proto.Message) { + xxx_messageInfo_IdentifiedInterchainAccount.Merge(m, src) +} +func (m *IdentifiedInterchainAccount) XXX_Size() int { + return m.Size() +} +func (m *IdentifiedInterchainAccount) XXX_DiscardUnknown() { + xxx_messageInfo_IdentifiedInterchainAccount.DiscardUnknown(m) +} + +var xxx_messageInfo_IdentifiedInterchainAccount proto.InternalMessageInfo + +func (m *IdentifiedInterchainAccount) GetPortId() string { + if m != nil { + return m.PortId + } + return "" +} + +func (m *IdentifiedInterchainAccount) GetAccountAddress() string { + if m != nil { + return m.AccountAddress + } + return "" +} + func init() { proto.RegisterType((*GenesisState)(nil), "ibc.applications.interchain_accounts.v1.GenesisState") + proto.RegisterType((*IdentifiedActiveChannel)(nil), "ibc.applications.interchain_accounts.v1.IdentifiedActiveChannel") + proto.RegisterType((*IdentifiedInterchainAccount)(nil), "ibc.applications.interchain_accounts.v1.IdentifiedInterchainAccount") } func init() { @@ -77,23 +201,30 @@ func init() { } var fileDescriptor_629b3ced0911516b = []byte{ - // 244 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x32, 0xcd, 0x4c, 0x4a, 0xd6, - 0x4f, 0x2c, 0x28, 0xc8, 0xc9, 0x4c, 0x4e, 0x2c, 0xc9, 0xcc, 0xcf, 0x2b, 0xd6, 0xcf, 0xcc, 0x2b, - 0x49, 0x2d, 0x4a, 0xce, 0x48, 0xcc, 0xcc, 0x8b, 0x4f, 0x4c, 0x4e, 0xce, 0x2f, 0xcd, 0x2b, 0x29, - 0xd6, 0x2f, 0x33, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, - 0xc9, 0x17, 0x52, 0xcf, 0x4c, 0x4a, 0xd6, 0x43, 0xd6, 0xa6, 0x87, 0x45, 0x9b, 0x5e, 0x99, 0xa1, - 0x94, 0x48, 0x7a, 0x7e, 0x7a, 0x3e, 0x58, 0x8f, 0x3e, 0x88, 0x05, 0xd1, 0xae, 0x64, 0xcd, 0xc5, - 0xe3, 0x0e, 0x31, 0x2f, 0xb8, 0x24, 0xb1, 0x24, 0x55, 0x48, 0x9b, 0x8b, 0xbd, 0x20, 0xbf, 0xa8, - 0x24, 0x3e, 0x33, 0x45, 0x82, 0x51, 0x81, 0x51, 0x83, 0xd3, 0x49, 0xe8, 0xd3, 0x3d, 0x79, 0xbe, - 0xca, 0xc4, 0xdc, 0x1c, 0x2b, 0x25, 0xa8, 0x84, 0x52, 0x10, 0x1b, 0x88, 0xe5, 0x99, 0xe2, 0x14, - 0x7f, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, - 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0xae, 0xe9, 0x99, 0x25, 0x19, - 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0xc9, 0xf9, 0xc5, 0xb9, 0xf9, 0xc5, 0xfa, 0x99, 0x49, - 0xc9, 0xba, 0xe9, 0xf9, 0xfa, 0x65, 0x46, 0xfa, 0xb9, 0xf9, 0x29, 0xa5, 0x39, 0xa9, 0xc5, 0x20, - 0xcf, 0x16, 0xeb, 0x1b, 0x99, 0xeb, 0x22, 0x1c, 0xac, 0x0b, 0xf7, 0x67, 0x49, 0x65, 0x41, 0x6a, - 0x71, 0x12, 0x1b, 0xd8, 0x91, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0xdc, 0xe5, 0x36, 0xd4, - 0x1c, 0x01, 0x00, 0x00, + // 367 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x92, 0xcd, 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96, 0xed, 0xce, 0x3f, 0xd1, 0xce, 0xdf, 0x15, 0xcc, 0xab, 0x7c, 0x60, + 0xc3, 0x5b, 0x09, 0xed, 0x1e, 0xf9, 0x92, 0xe8, 0xd4, 0xa0, 0xd3, 0x1a, 0xb4, 0xc6, 0x9d, 0xa0, + 0x0a, 0x86, 0x57, 0xa4, 0x7f, 0x64, 0x6e, 0xbb, 0x4f, 0xbe, 0x16, 0x35, 0x21, 0x08, 0xc7, 0x1a, + 0x58, 0xe3, 0x4e, 0xd0, 0x2e, 0x42, 0x5f, 0xd8, 0x7f, 0x08, 0xa9, 0x97, 0x54, 0xe4, 0x9a, 0x65, + 0xae, 0x53, 0x2b, 0xbe, 0x18, 0x86, 0xe4, 0xf7, 0x3b, 0xb3, 0x1d, 0xc7, 0x8e, 0x8a, 0x2f, 0x28, + 0x6b, 0x42, 0x26, 0x44, 0x2a, 0x11, 0x6b, 0x76, 0xb7, 0x96, 0xe7, 0x95, 0x7a, 0x1a, 0x3e, 0x6e, + 0x5c, 0x6b, 0xbd, 0x71, 0xad, 0xe7, 0x8d, 0x6b, 0x3d, 0x6c, 0xdd, 0xc6, 0x7a, 0xeb, 0x36, 0x9e, + 0xb6, 0x6e, 0xe3, 0xe6, 0x22, 0x06, 0xb3, 0xc8, 0x22, 0x8f, 0xeb, 0x15, 0xe5, 0x1a, 0x57, 0x1a, + 0x29, 0x44, 0x7c, 0x12, 0x6b, 0x9a, 0xcf, 0xe8, 0x4a, 0x8b, 0x6c, 0x29, 0xb1, 0x38, 0x36, 0xa4, + 0xb3, 0xff, 0x93, 0xd7, 0x1d, 0x4d, 0x76, 0x77, 0x66, 0xee, 0x12, 0x89, 0x51, 0xbb, 0x3c, 0x92, + 0xbf, 0x2f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x26, 0xbc, 0xdb, 0x6f, 0x9c, 0x02, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -116,6 +247,110 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.Ports) > 0 { + for iNdEx := len(m.Ports) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Ports[iNdEx]) + copy(dAtA[i:], m.Ports[iNdEx]) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.Ports[iNdEx]))) + i-- + dAtA[i] = 0x1a + } + } + if len(m.InterchainAccounts) > 0 { + for iNdEx := len(m.InterchainAccounts) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.InterchainAccounts[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.ActiveChannels) > 0 { + for iNdEx := len(m.ActiveChannels) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.ActiveChannels[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *IdentifiedActiveChannel) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *IdentifiedActiveChannel) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *IdentifiedActiveChannel) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ChannelId) > 0 { + i -= len(m.ChannelId) + copy(dAtA[i:], m.ChannelId) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.ChannelId))) + i-- + dAtA[i] = 0x12 + } + if len(m.PortId) > 0 { + i -= len(m.PortId) + copy(dAtA[i:], m.PortId) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.PortId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *IdentifiedInterchainAccount) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *IdentifiedInterchainAccount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *IdentifiedInterchainAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.AccountAddress) > 0 { + i -= len(m.AccountAddress) + copy(dAtA[i:], m.AccountAddress) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.AccountAddress))) + i-- + dAtA[i] = 0x12 + } if len(m.PortId) > 0 { i -= len(m.PortId) copy(dAtA[i:], m.PortId) @@ -138,6 +373,33 @@ func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { return base } func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.ActiveChannels) > 0 { + for _, e := range m.ActiveChannels { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.InterchainAccounts) > 0 { + for _, e := range m.InterchainAccounts { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.Ports) > 0 { + for _, s := range m.Ports { + l = len(s) + n += 1 + l + sovGenesis(uint64(l)) + } + } + return n +} + +func (m *IdentifiedActiveChannel) Size() (n int) { if m == nil { return 0 } @@ -147,6 +409,27 @@ func (m *GenesisState) Size() (n int) { if l > 0 { n += 1 + l + sovGenesis(uint64(l)) } + l = len(m.ChannelId) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + return n +} + +func (m *IdentifiedInterchainAccount) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.PortId) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + l = len(m.AccountAddress) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } return n } @@ -185,6 +468,270 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ActiveChannels", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ActiveChannels = append(m.ActiveChannels, &IdentifiedActiveChannel{}) + if err := m.ActiveChannels[len(m.ActiveChannels)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field InterchainAccounts", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.InterchainAccounts = append(m.InterchainAccounts, &IdentifiedInterchainAccount{}) + if err := m.InterchainAccounts[len(m.InterchainAccounts)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Ports", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Ports = append(m.Ports, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *IdentifiedActiveChannel) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: IdentifiedActiveChannel: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: IdentifiedActiveChannel: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PortId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PortId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChannelId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChannelId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *IdentifiedInterchainAccount) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: IdentifiedInterchainAccount: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: IdentifiedInterchainAccount: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { case 1: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field PortId", wireType) @@ -217,6 +764,38 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { } m.PortId = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AccountAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.AccountAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/modules/apps/27-interchain-accounts/types/keys.go b/modules/apps/27-interchain-accounts/types/keys.go index d8e3e1c1ec4..a71f6c0c32c 100644 --- a/modules/apps/27-interchain-accounts/types/keys.go +++ b/modules/apps/27-interchain-accounts/types/keys.go @@ -38,8 +38,14 @@ const ( ) var ( - // PortKey defines the key to store the port ID in store - PortKey = []byte{0x01} + // ActiveChannelKeyPrefix defines the key prefix used to store active channels + ActiveChannelKeyPrefix = "activeChannel" + + // OwnerKeyPrefix defines the key prefix used to store interchain accounts + OwnerKeyPrefix = "owner" + + // PortKeyPrefix defines the key prefix used to store ports + PortKeyPrefix = "port" ) // NewVersion returns a complete version string in the format: VersionPrefix + Delimter + AccAddress @@ -49,12 +55,17 @@ func NewAppVersion(versionPrefix, accAddr string) string { // KeyActiveChannel creates and returns a new key used for active channels store operations func KeyActiveChannel(portID string) []byte { - return []byte(fmt.Sprintf("activeChannel/%s", portID)) + return []byte(fmt.Sprintf("%s/%s", ActiveChannelKeyPrefix, portID)) } -// KeyOwnerAccount creates and returns a new key used for owner account store operations +// KeyOwnerAccount creates and returns a new key used for interchain account store operations func KeyOwnerAccount(portID string) []byte { - return []byte(fmt.Sprintf("owner/%s", portID)) + return []byte(fmt.Sprintf("%s/%s", OwnerKeyPrefix, portID)) +} + +// KeyPort creates and returns a new key used for port store operations +func KeyPort(portID string) []byte { + return []byte(fmt.Sprintf("%s/%s", PortKeyPrefix, portID)) } // ParseControllerConnSequence attempts to parse the controller connection sequence from the provided port identifier diff --git a/modules/apps/27-interchain-accounts/types/types.pb.go b/modules/apps/27-interchain-accounts/types/types.pb.go index 38aa8249c28..347c3958457 100644 --- a/modules/apps/27-interchain-accounts/types/types.pb.go +++ b/modules/apps/27-interchain-accounts/types/types.pb.go @@ -95,7 +95,7 @@ func (m *IBCTxBody) GetMessages() []*types.Any { return nil } -// InterchainAccountPacketData is comprised of araw transaction,type of transaction and optional memo field. +// InterchainAccountPacketData is comprised of a raw transaction, type of transaction and optional memo field. type InterchainAccountPacketData struct { Type Type `protobuf:"varint,1,opt,name=type,proto3,enum=ibc.applications.interchain_accounts.v1.Type" json:"type,omitempty"` Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` diff --git a/proto/ibc/applications/interchain_accounts/v1/genesis.proto b/proto/ibc/applications/interchain_accounts/v1/genesis.proto index 001eeb00a6c..da254554172 100644 --- a/proto/ibc/applications/interchain_accounts/v1/genesis.proto +++ b/proto/ibc/applications/interchain_accounts/v1/genesis.proto @@ -7,5 +7,19 @@ import "gogoproto/gogo.proto"; // GenesisState defines the interchain_account genesis state message GenesisState { - string port_id = 1 [(gogoproto.moretags) = "yaml:\"port_id\""]; + repeated IdentifiedActiveChannel active_channels = 1; + repeated IdentifiedInterchainAccount interchain_accounts = 2; + repeated string ports = 3; +} + +// IdentifiedActiveChannel +message IdentifiedActiveChannel { + string port_id = 1; + string channel_id = 2; +} + +// IdentifiedInterchainAccount +message IdentifiedInterchainAccount { + string port_id = 1; + string account_address = 2; } diff --git a/proto/ibc/applications/interchain_accounts/v1/types.proto b/proto/ibc/applications/interchain_accounts/v1/types.proto index 758c2539072..0013610c150 100644 --- a/proto/ibc/applications/interchain_accounts/v1/types.proto +++ b/proto/ibc/applications/interchain_accounts/v1/types.proto @@ -21,7 +21,7 @@ enum Type { // InterchainAccountPacketData is comprised of a raw transaction, type of transaction and optional memo field. message InterchainAccountPacketData { - Type type = 1; - bytes data = 2; + Type type = 1; + bytes data = 2; string memo = 3; } From 23b49f8498e512c1e901b5e1a02b0349d9f3c4cf Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Fri, 8 Oct 2021 15:31:19 +0200 Subject: [PATCH 2/6] updating protos --- docs/ibc/proto-docs.md | 32 ++-- .../apps/27-interchain-accounts/genesis.go | 8 +- .../27-interchain-accounts/genesis_test.go | 30 ++++ .../27-interchain-accounts/types/genesis.go | 2 +- .../types/genesis.pb.go | 162 +++++++++--------- .../interchain_accounts/v1/genesis.proto | 14 +- 6 files changed, 139 insertions(+), 109 deletions(-) diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index fbdb6805ed1..1946ea74e0f 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -8,9 +8,9 @@ - [InterchainAccount](#ibc.applications.interchain_accounts.v1.InterchainAccount) - [ibc/applications/interchain_accounts/v1/genesis.proto](#ibc/applications/interchain_accounts/v1/genesis.proto) + - [ActiveChannel](#ibc.applications.interchain_accounts.v1.ActiveChannel) - [GenesisState](#ibc.applications.interchain_accounts.v1.GenesisState) - - [IdentifiedActiveChannel](#ibc.applications.interchain_accounts.v1.IdentifiedActiveChannel) - - [IdentifiedInterchainAccount](#ibc.applications.interchain_accounts.v1.IdentifiedInterchainAccount) + - [RegisteredInterchainAccount](#ibc.applications.interchain_accounts.v1.RegisteredInterchainAccount) - [ibc/applications/interchain_accounts/v1/query.proto](#ibc/applications/interchain_accounts/v1/query.proto) - [QueryInterchainAccountAddressRequest](#ibc.applications.interchain_accounts.v1.QueryInterchainAccountAddressRequest) @@ -313,43 +313,43 @@ An InterchainAccount is defined as a BaseAccount & the address of the account ow - + -### GenesisState -GenesisState defines the interchain_account genesis state +### ActiveChannel +ActiveChannel contains a pairing of port ID and channel ID for an active interchain accounts channel | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `active_channels` | [IdentifiedActiveChannel](#ibc.applications.interchain_accounts.v1.IdentifiedActiveChannel) | repeated | | -| `interchain_accounts` | [IdentifiedInterchainAccount](#ibc.applications.interchain_accounts.v1.IdentifiedInterchainAccount) | repeated | | -| `ports` | [string](#string) | repeated | | +| `port_id` | [string](#string) | | | +| `channel_id` | [string](#string) | | | - + -### IdentifiedActiveChannel -IdentifiedActiveChannel +### GenesisState +GenesisState defines the interchain accounts genesis state | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `port_id` | [string](#string) | | | -| `channel_id` | [string](#string) | | | +| `active_channels` | [ActiveChannel](#ibc.applications.interchain_accounts.v1.ActiveChannel) | repeated | | +| `interchain_accounts` | [RegisteredInterchainAccount](#ibc.applications.interchain_accounts.v1.RegisteredInterchainAccount) | repeated | | +| `ports` | [string](#string) | repeated | | - + -### IdentifiedInterchainAccount -IdentifiedInterchainAccount +### RegisteredInterchainAccount +RegisteredInterchainAccount contains a pairing of controller port ID and associated interchain account address | Field | Type | Label | Description | diff --git a/modules/apps/27-interchain-accounts/genesis.go b/modules/apps/27-interchain-accounts/genesis.go index 601dbad285c..b6b6d8d1b98 100644 --- a/modules/apps/27-interchain-accounts/genesis.go +++ b/modules/apps/27-interchain-accounts/genesis.go @@ -33,14 +33,14 @@ func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, state types.GenesisState // ExportGenesis returns the interchain accounts exported genesis func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) *types.GenesisState { var ( - activeChannels []*types.IdentifiedActiveChannel - interchainAccounts []*types.IdentifiedInterchainAccount + activeChannels []*types.ActiveChannel + interchainAccounts []*types.RegisteredInterchainAccount ) ports := keeper.GetAllPorts(ctx) for _, portID := range ports { if channelID, found := keeper.GetActiveChannel(ctx, portID); found { - activeChan := &types.IdentifiedActiveChannel{ + activeChan := &types.ActiveChannel{ PortId: portID, ChannelId: channelID, } @@ -49,7 +49,7 @@ func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) *types.GenesisState { } if accountAddr, found := keeper.GetInterchainAccountAddress(ctx, portID); found { - interchainAcc := &types.IdentifiedInterchainAccount{ + interchainAcc := &types.RegisteredInterchainAccount{ PortId: portID, AccountAddress: accountAddr, } diff --git a/modules/apps/27-interchain-accounts/genesis_test.go b/modules/apps/27-interchain-accounts/genesis_test.go index 66497820a2e..4c54dcf916e 100644 --- a/modules/apps/27-interchain-accounts/genesis_test.go +++ b/modules/apps/27-interchain-accounts/genesis_test.go @@ -5,6 +5,36 @@ import ( "github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types" ) +func (suite *InterchainAccountsTestSuite) TestInitGenesis() { + suite.SetupTest() + + genesisState := types.GenesisState{ + Ports: []string{types.PortID, TestPortID}, + ActiveChannels: []*types.ActiveChannel{ + { + PortId: TestPortID, + ChannelId: "channel-0", + }, + }, + InterchainAccounts: []*types.RegisteredInterchainAccount{ + { + PortId: TestPortID, + AccountAddress: TestAccAddress.String(), + }, + }, + } + + ica.InitGenesis(suite.chainA.GetContext(), suite.chainA.GetSimApp().ICAKeeper, genesisState) + + channelID, found := suite.chainA.GetSimApp().ICAKeeper.GetActiveChannel(suite.chainA.GetContext(), TestPortID) + suite.Require().True(found) + suite.Require().Equal("channel-0", channelID) + + accountAdrr, found := suite.chainA.GetSimApp().ICAKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), TestPortID) + suite.Require().True(found) + suite.Require().Equal(TestAccAddress.String(), accountAdrr) +} + func (suite *InterchainAccountsTestSuite) TestExportGenesis() { suite.SetupTest() path := NewICAPath(suite.chainA, suite.chainB) diff --git a/modules/apps/27-interchain-accounts/types/genesis.go b/modules/apps/27-interchain-accounts/types/genesis.go index 88a2d1e19ef..f98ce12caa6 100644 --- a/modules/apps/27-interchain-accounts/types/genesis.go +++ b/modules/apps/27-interchain-accounts/types/genesis.go @@ -9,7 +9,7 @@ func DefaultGenesis() *GenesisState { } // NewGenesisState creates a returns a new GenesisState instance -func NewGenesisState(ports []string, channels []*IdentifiedActiveChannel, accounts []*IdentifiedInterchainAccount) *GenesisState { +func NewGenesisState(ports []string, channels []*ActiveChannel, accounts []*RegisteredInterchainAccount) *GenesisState { return &GenesisState{ ActiveChannels: channels, InterchainAccounts: accounts, diff --git a/modules/apps/27-interchain-accounts/types/genesis.pb.go b/modules/apps/27-interchain-accounts/types/genesis.pb.go index 6411cef11a2..f2e030581f6 100644 --- a/modules/apps/27-interchain-accounts/types/genesis.pb.go +++ b/modules/apps/27-interchain-accounts/types/genesis.pb.go @@ -23,10 +23,10 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// GenesisState defines the interchain_account genesis state +// GenesisState defines the interchain accounts genesis state type GenesisState struct { - ActiveChannels []*IdentifiedActiveChannel `protobuf:"bytes,1,rep,name=active_channels,json=activeChannels,proto3" json:"active_channels,omitempty"` - InterchainAccounts []*IdentifiedInterchainAccount `protobuf:"bytes,2,rep,name=interchain_accounts,json=interchainAccounts,proto3" json:"interchain_accounts,omitempty"` + ActiveChannels []*ActiveChannel `protobuf:"bytes,1,rep,name=active_channels,json=activeChannels,proto3" json:"active_channels,omitempty"` + InterchainAccounts []*RegisteredInterchainAccount `protobuf:"bytes,2,rep,name=interchain_accounts,json=interchainAccounts,proto3" json:"interchain_accounts,omitempty"` Ports []string `protobuf:"bytes,3,rep,name=ports,proto3" json:"ports,omitempty"` } @@ -63,14 +63,14 @@ func (m *GenesisState) XXX_DiscardUnknown() { var xxx_messageInfo_GenesisState proto.InternalMessageInfo -func (m *GenesisState) GetActiveChannels() []*IdentifiedActiveChannel { +func (m *GenesisState) GetActiveChannels() []*ActiveChannel { if m != nil { return m.ActiveChannels } return nil } -func (m *GenesisState) GetInterchainAccounts() []*IdentifiedInterchainAccount { +func (m *GenesisState) GetInterchainAccounts() []*RegisteredInterchainAccount { if m != nil { return m.InterchainAccounts } @@ -84,24 +84,24 @@ func (m *GenesisState) GetPorts() []string { return nil } -// IdentifiedActiveChannel -type IdentifiedActiveChannel struct { +// ActiveChannel contains a pairing of port ID and channel ID for an active interchain accounts channel +type ActiveChannel struct { PortId string `protobuf:"bytes,1,opt,name=port_id,json=portId,proto3" json:"port_id,omitempty"` ChannelId string `protobuf:"bytes,2,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` } -func (m *IdentifiedActiveChannel) Reset() { *m = IdentifiedActiveChannel{} } -func (m *IdentifiedActiveChannel) String() string { return proto.CompactTextString(m) } -func (*IdentifiedActiveChannel) ProtoMessage() {} -func (*IdentifiedActiveChannel) Descriptor() ([]byte, []int) { +func (m *ActiveChannel) Reset() { *m = ActiveChannel{} } +func (m *ActiveChannel) String() string { return proto.CompactTextString(m) } +func (*ActiveChannel) ProtoMessage() {} +func (*ActiveChannel) Descriptor() ([]byte, []int) { return fileDescriptor_629b3ced0911516b, []int{1} } -func (m *IdentifiedActiveChannel) XXX_Unmarshal(b []byte) error { +func (m *ActiveChannel) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *IdentifiedActiveChannel) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *ActiveChannel) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_IdentifiedActiveChannel.Marshal(b, m, deterministic) + return xxx_messageInfo_ActiveChannel.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -111,50 +111,50 @@ func (m *IdentifiedActiveChannel) XXX_Marshal(b []byte, deterministic bool) ([]b return b[:n], nil } } -func (m *IdentifiedActiveChannel) XXX_Merge(src proto.Message) { - xxx_messageInfo_IdentifiedActiveChannel.Merge(m, src) +func (m *ActiveChannel) XXX_Merge(src proto.Message) { + xxx_messageInfo_ActiveChannel.Merge(m, src) } -func (m *IdentifiedActiveChannel) XXX_Size() int { +func (m *ActiveChannel) XXX_Size() int { return m.Size() } -func (m *IdentifiedActiveChannel) XXX_DiscardUnknown() { - xxx_messageInfo_IdentifiedActiveChannel.DiscardUnknown(m) +func (m *ActiveChannel) XXX_DiscardUnknown() { + xxx_messageInfo_ActiveChannel.DiscardUnknown(m) } -var xxx_messageInfo_IdentifiedActiveChannel proto.InternalMessageInfo +var xxx_messageInfo_ActiveChannel proto.InternalMessageInfo -func (m *IdentifiedActiveChannel) GetPortId() string { +func (m *ActiveChannel) GetPortId() string { if m != nil { return m.PortId } return "" } -func (m *IdentifiedActiveChannel) GetChannelId() string { +func (m *ActiveChannel) GetChannelId() string { if m != nil { return m.ChannelId } return "" } -// IdentifiedInterchainAccount -type IdentifiedInterchainAccount struct { +// RegisteredInterchainAccount contains a pairing of controller port ID and associated interchain account address +type RegisteredInterchainAccount struct { PortId string `protobuf:"bytes,1,opt,name=port_id,json=portId,proto3" json:"port_id,omitempty"` AccountAddress string `protobuf:"bytes,2,opt,name=account_address,json=accountAddress,proto3" json:"account_address,omitempty"` } -func (m *IdentifiedInterchainAccount) Reset() { *m = IdentifiedInterchainAccount{} } -func (m *IdentifiedInterchainAccount) String() string { return proto.CompactTextString(m) } -func (*IdentifiedInterchainAccount) ProtoMessage() {} -func (*IdentifiedInterchainAccount) Descriptor() ([]byte, []int) { +func (m *RegisteredInterchainAccount) Reset() { *m = RegisteredInterchainAccount{} } +func (m *RegisteredInterchainAccount) String() string { return proto.CompactTextString(m) } +func (*RegisteredInterchainAccount) ProtoMessage() {} +func (*RegisteredInterchainAccount) Descriptor() ([]byte, []int) { return fileDescriptor_629b3ced0911516b, []int{2} } -func (m *IdentifiedInterchainAccount) XXX_Unmarshal(b []byte) error { +func (m *RegisteredInterchainAccount) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *IdentifiedInterchainAccount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *RegisteredInterchainAccount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_IdentifiedInterchainAccount.Marshal(b, m, deterministic) + return xxx_messageInfo_RegisteredInterchainAccount.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -164,26 +164,26 @@ func (m *IdentifiedInterchainAccount) XXX_Marshal(b []byte, deterministic bool) return b[:n], nil } } -func (m *IdentifiedInterchainAccount) XXX_Merge(src proto.Message) { - xxx_messageInfo_IdentifiedInterchainAccount.Merge(m, src) +func (m *RegisteredInterchainAccount) XXX_Merge(src proto.Message) { + xxx_messageInfo_RegisteredInterchainAccount.Merge(m, src) } -func (m *IdentifiedInterchainAccount) XXX_Size() int { +func (m *RegisteredInterchainAccount) XXX_Size() int { return m.Size() } -func (m *IdentifiedInterchainAccount) XXX_DiscardUnknown() { - xxx_messageInfo_IdentifiedInterchainAccount.DiscardUnknown(m) +func (m *RegisteredInterchainAccount) XXX_DiscardUnknown() { + xxx_messageInfo_RegisteredInterchainAccount.DiscardUnknown(m) } -var xxx_messageInfo_IdentifiedInterchainAccount proto.InternalMessageInfo +var xxx_messageInfo_RegisteredInterchainAccount proto.InternalMessageInfo -func (m *IdentifiedInterchainAccount) GetPortId() string { +func (m *RegisteredInterchainAccount) GetPortId() string { if m != nil { return m.PortId } return "" } -func (m *IdentifiedInterchainAccount) GetAccountAddress() string { +func (m *RegisteredInterchainAccount) GetAccountAddress() string { if m != nil { return m.AccountAddress } @@ -192,8 +192,8 @@ func (m *IdentifiedInterchainAccount) GetAccountAddress() string { func init() { proto.RegisterType((*GenesisState)(nil), "ibc.applications.interchain_accounts.v1.GenesisState") - proto.RegisterType((*IdentifiedActiveChannel)(nil), "ibc.applications.interchain_accounts.v1.IdentifiedActiveChannel") - proto.RegisterType((*IdentifiedInterchainAccount)(nil), "ibc.applications.interchain_accounts.v1.IdentifiedInterchainAccount") + proto.RegisterType((*ActiveChannel)(nil), "ibc.applications.interchain_accounts.v1.ActiveChannel") + proto.RegisterType((*RegisteredInterchainAccount)(nil), "ibc.applications.interchain_accounts.v1.RegisteredInterchainAccount") } func init() { @@ -201,30 +201,30 @@ func init() { } var fileDescriptor_629b3ced0911516b = []byte{ - // 367 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x92, 0xcd, 0x6a, 0xdb, 0x40, - 0x10, 0xc7, 0x2d, 0x9b, 0xba, 0x78, 0x5b, 0x5c, 0x50, 0x0d, 0x16, 0x2d, 0x15, 0xc6, 0x17, 0xfb, - 0x62, 0x2d, 0x76, 0x29, 0xbd, 0xc6, 0xf9, 0x20, 0xe8, 0x18, 0xe5, 0x96, 0x8b, 0x58, 0xed, 0x6e, - 0xe4, 0x01, 0x7b, 0x57, 0x68, 0x56, 0x82, 0xbc, 0x40, 0xce, 0x79, 0xac, 0x1c, 0x7d, 0xcc, 0x31, - 0xd8, 0x2f, 0x12, 0xf4, 0x81, 0x63, 0x82, 0x1d, 0x42, 0x6e, 0x3b, 0xff, 0x99, 0xff, 0x6f, 0x86, - 0xd9, 0x21, 0xff, 0x20, 0xe2, 0x94, 0x25, 0xc9, 0x12, 0x38, 0x33, 0xa0, 0x15, 0x52, 0x50, 0x46, - 0xa6, 0x7c, 0xc1, 0x40, 0x85, 0x8c, 0x73, 0x9d, 0x29, 0x83, 0x34, 0x9f, 0xd2, 0x58, 0x2a, 0x89, - 0x80, 0x5e, 0x92, 0x6a, 0xa3, 0xed, 0x11, 0x44, 0xdc, 0xdb, 0xb7, 0x79, 0x07, 0x6c, 0x5e, 0x3e, - 0xfd, 0xd5, 0x8b, 0x75, 0xac, 0x4b, 0x0f, 0x2d, 0x5e, 0x95, 0x7d, 0x78, 0xdf, 0x24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x44, 0x7c, 0x12, 0x6b, 0x9a, 0xcf, 0xe8, 0x4a, 0x8b, 0x6c, 0x29, 0xb1, 0x38, 0x36, 0xa4, - 0xb3, 0xff, 0x93, 0xd7, 0x1d, 0x4d, 0x76, 0x77, 0x66, 0xee, 0x12, 0x89, 0x51, 0xbb, 0x3c, 0x92, - 0xbf, 0x2f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x26, 0xbc, 0xdb, 0x6f, 0x9c, 0x02, 0x00, 0x00, + // 363 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xcf, 0x6a, 0x2a, 0x31, + 0x14, 0xc6, 0x1d, 0xe5, 0x7a, 0x31, 0xf7, 0x5e, 0x2f, 0x4c, 0x85, 0x0e, 0x2d, 0x1d, 0xc4, 0x8d, + 0x6e, 0x4c, 0xd0, 0xd2, 0x76, 0x6d, 0xff, 0x20, 0x6e, 0xa7, 0xbb, 0x6e, 0x42, 0x26, 0x09, 0x63, + 0x40, 0x93, 0x61, 0x4e, 0x66, 0xa0, 0x6f, 0xd1, 0xc7, 0xea, 0xd2, 0x65, 0x97, 0x45, 0x5f, 0xa3, + 0x8b, 0x32, 0x7f, 0xb0, 0xb6, 0xd8, 0xe2, 0x2e, 0xe7, 0xfb, 0xf2, 0x3b, 0xe7, 0x70, 0xf8, 0xd0, + 0x85, 0x0a, 0x39, 0x61, 0x71, 0xbc, 0x50, 0x9c, 0x59, 0x65, 0x34, 0x10, 0xa5, 0xad, 0x4c, 0xf8, + 0x9c, 0x29, 0x4d, 0x19, 0xe7, 0x26, 0xd5, 0x16, 0x48, 0x36, 0x22, 0x91, 0xd4, 0x12, 0x14, 0xe0, + 0x38, 0x31, 0xd6, 0xb8, 0x7d, 0x15, 0x72, 0xbc, 0x8b, 0xe1, 0x3d, 0x18, 0xce, 0x46, 0x27, 0x9d, + 0xc8, 0x44, 0xa6, 0x60, 0x48, 0x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xd2, 0x00, 0x51, 0x21, 0x1f, + 0x46, 0x86, 0x64, 0x63, 0xb2, 0x34, 0x22, 0x5d, 0x48, 0xc8, 0x83, 0x05, 0x64, 0x7c, 0x35, 0xfc, + 0xb8, 0xcc, 0x70, 0x9b, 0x29, 0xfb, 0x18, 0x4b, 0x08, 0x9b, 0x45, 0x20, 0xce, 0xdf, 0x03, 0x00, + 0x00, 0xff, 0xff, 0x8b, 0x69, 0xf9, 0x67, 0x88, 0x02, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -287,7 +287,7 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *IdentifiedActiveChannel) Marshal() (dAtA []byte, err error) { +func (m *ActiveChannel) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -297,12 +297,12 @@ func (m *IdentifiedActiveChannel) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *IdentifiedActiveChannel) MarshalTo(dAtA []byte) (int, error) { +func (m *ActiveChannel) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *IdentifiedActiveChannel) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *ActiveChannel) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -324,7 +324,7 @@ func (m *IdentifiedActiveChannel) MarshalToSizedBuffer(dAtA []byte) (int, error) return len(dAtA) - i, nil } -func (m *IdentifiedInterchainAccount) Marshal() (dAtA []byte, err error) { +func (m *RegisteredInterchainAccount) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -334,12 +334,12 @@ func (m *IdentifiedInterchainAccount) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *IdentifiedInterchainAccount) MarshalTo(dAtA []byte) (int, error) { +func (m *RegisteredInterchainAccount) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *IdentifiedInterchainAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *RegisteredInterchainAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -399,7 +399,7 @@ func (m *GenesisState) Size() (n int) { return n } -func (m *IdentifiedActiveChannel) Size() (n int) { +func (m *ActiveChannel) Size() (n int) { if m == nil { return 0 } @@ -416,7 +416,7 @@ func (m *IdentifiedActiveChannel) Size() (n int) { return n } -func (m *IdentifiedInterchainAccount) Size() (n int) { +func (m *RegisteredInterchainAccount) Size() (n int) { if m == nil { return 0 } @@ -497,7 +497,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.ActiveChannels = append(m.ActiveChannels, &IdentifiedActiveChannel{}) + m.ActiveChannels = append(m.ActiveChannels, &ActiveChannel{}) if err := m.ActiveChannels[len(m.ActiveChannels)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -531,7 +531,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.InterchainAccounts = append(m.InterchainAccounts, &IdentifiedInterchainAccount{}) + m.InterchainAccounts = append(m.InterchainAccounts, &RegisteredInterchainAccount{}) if err := m.InterchainAccounts[len(m.InterchainAccounts)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -589,7 +589,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { } return nil } -func (m *IdentifiedActiveChannel) Unmarshal(dAtA []byte) error { +func (m *ActiveChannel) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -612,10 +612,10 @@ func (m *IdentifiedActiveChannel) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: IdentifiedActiveChannel: wiretype end group for non-group") + return fmt.Errorf("proto: ActiveChannel: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: IdentifiedActiveChannel: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: ActiveChannel: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -703,7 +703,7 @@ func (m *IdentifiedActiveChannel) Unmarshal(dAtA []byte) error { } return nil } -func (m *IdentifiedInterchainAccount) Unmarshal(dAtA []byte) error { +func (m *RegisteredInterchainAccount) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -726,10 +726,10 @@ func (m *IdentifiedInterchainAccount) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: IdentifiedInterchainAccount: wiretype end group for non-group") + return fmt.Errorf("proto: RegisteredInterchainAccount: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: IdentifiedInterchainAccount: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: RegisteredInterchainAccount: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: diff --git a/proto/ibc/applications/interchain_accounts/v1/genesis.proto b/proto/ibc/applications/interchain_accounts/v1/genesis.proto index da254554172..609f287d6ad 100644 --- a/proto/ibc/applications/interchain_accounts/v1/genesis.proto +++ b/proto/ibc/applications/interchain_accounts/v1/genesis.proto @@ -5,21 +5,21 @@ option go_package = "github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-acco import "gogoproto/gogo.proto"; -// GenesisState defines the interchain_account genesis state +// GenesisState defines the interchain accounts genesis state message GenesisState { - repeated IdentifiedActiveChannel active_channels = 1; - repeated IdentifiedInterchainAccount interchain_accounts = 2; + repeated ActiveChannel active_channels = 1; + repeated RegisteredInterchainAccount interchain_accounts = 2; repeated string ports = 3; } -// IdentifiedActiveChannel -message IdentifiedActiveChannel { +// ActiveChannel contains a pairing of port ID and channel ID for an active interchain accounts channel +message ActiveChannel { string port_id = 1; string channel_id = 2; } -// IdentifiedInterchainAccount -message IdentifiedInterchainAccount { +// RegisteredInterchainAccount contains a pairing of controller port ID and associated interchain account address +message RegisteredInterchainAccount { string port_id = 1; string account_address = 2; } From 49dcfbfb43acfd08a74bcc9fa3436eb23c457a07 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Fri, 8 Oct 2021 16:21:32 +0200 Subject: [PATCH 3/6] including yaml tags, sorting proto file structure --- .../types/genesis.pb.go | 64 ++++++++++--------- .../interchain_accounts/v1/account.proto | 5 +- .../interchain_accounts/v1/genesis.proto | 13 ++-- .../interchain_accounts/v1/query.proto | 5 +- .../interchain_accounts/v1/types.proto | 4 +- 5 files changed, 50 insertions(+), 41 deletions(-) diff --git a/modules/apps/27-interchain-accounts/types/genesis.pb.go b/modules/apps/27-interchain-accounts/types/genesis.pb.go index f2e030581f6..32d38337ac1 100644 --- a/modules/apps/27-interchain-accounts/types/genesis.pb.go +++ b/modules/apps/27-interchain-accounts/types/genesis.pb.go @@ -25,8 +25,8 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // GenesisState defines the interchain accounts genesis state type GenesisState struct { - ActiveChannels []*ActiveChannel `protobuf:"bytes,1,rep,name=active_channels,json=activeChannels,proto3" json:"active_channels,omitempty"` - InterchainAccounts []*RegisteredInterchainAccount `protobuf:"bytes,2,rep,name=interchain_accounts,json=interchainAccounts,proto3" json:"interchain_accounts,omitempty"` + ActiveChannels []*ActiveChannel `protobuf:"bytes,1,rep,name=active_channels,json=activeChannels,proto3" json:"active_channels,omitempty" yaml:"active_channels"` + InterchainAccounts []*RegisteredInterchainAccount `protobuf:"bytes,2,rep,name=interchain_accounts,json=interchainAccounts,proto3" json:"interchain_accounts,omitempty" yaml:"interchain_accounts"` Ports []string `protobuf:"bytes,3,rep,name=ports,proto3" json:"ports,omitempty"` } @@ -86,8 +86,8 @@ func (m *GenesisState) GetPorts() []string { // ActiveChannel contains a pairing of port ID and channel ID for an active interchain accounts channel type ActiveChannel struct { - PortId string `protobuf:"bytes,1,opt,name=port_id,json=portId,proto3" json:"port_id,omitempty"` - ChannelId string `protobuf:"bytes,2,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` + PortId string `protobuf:"bytes,1,opt,name=port_id,json=portId,proto3" json:"port_id,omitempty" yaml:"port_id"` + ChannelId string `protobuf:"bytes,2,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty" yaml:"channel_id"` } func (m *ActiveChannel) Reset() { *m = ActiveChannel{} } @@ -139,8 +139,8 @@ func (m *ActiveChannel) GetChannelId() string { // RegisteredInterchainAccount contains a pairing of controller port ID and associated interchain account address type RegisteredInterchainAccount struct { - PortId string `protobuf:"bytes,1,opt,name=port_id,json=portId,proto3" json:"port_id,omitempty"` - AccountAddress string `protobuf:"bytes,2,opt,name=account_address,json=accountAddress,proto3" json:"account_address,omitempty"` + PortId string `protobuf:"bytes,1,opt,name=port_id,json=portId,proto3" json:"port_id,omitempty" yaml:"port_id"` + AccountAddress string `protobuf:"bytes,2,opt,name=account_address,json=accountAddress,proto3" json:"account_address,omitempty" yaml:"account_address"` } func (m *RegisteredInterchainAccount) Reset() { *m = RegisteredInterchainAccount{} } @@ -201,30 +201,34 @@ func init() { } var fileDescriptor_629b3ced0911516b = []byte{ - // 363 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xcf, 0x6a, 0x2a, 0x31, - 0x14, 0xc6, 0x1d, 0xe5, 0x7a, 0x31, 0xf7, 0x5e, 0x2f, 0x4c, 0x85, 0x0e, 0x2d, 0x1d, 0xc4, 0x8d, - 0x6e, 0x4c, 0xd0, 0xd2, 0x76, 0x6d, 0xff, 0x20, 0x6e, 0xa7, 0xbb, 0x6e, 0x42, 0x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3d, 0x46, 0xbf, 0x73, 0x87, 0x2a, 0xe1, 0x39, 0x5d, 0x67, 0xd0, 0x0a, - 0x9a, 0x79, 0x39, 0x13, 0xee, 0x19, 0x42, 0xd5, 0x41, 0x72, 0xaf, 0x5e, 0x78, 0xad, 0x4a, 0x99, - 0x89, 0x1e, 0x45, 0xa7, 0x3f, 0x6c, 0xf4, 0x7d, 0xdb, 0x7e, 0x7e, 0xee, 0xe2, 0x0f, 0x65, 0x42, - 0x24, 0x12, 0xa0, 0xea, 0xdd, 0xae, 0xe4, 0x49, 0xa9, 0x5e, 0xd3, 0xe7, 0xb5, 0xef, 0xac, 0xd6, - 0xbe, 0xf3, 0xba, 0xf6, 0x9d, 0xa7, 0x8d, 0x5f, 0x5b, 0x6d, 0xfc, 0xda, 0xcb, 0xc6, 0xaf, 0x3d, - 0xdc, 0x45, 0xca, 0xce, 0xd3, 0x10, 0x73, 0xb3, 0x24, 0xdc, 0xc0, 0xd2, 0x00, 0x51, 0x21, 0x1f, - 0x46, 0x86, 0x64, 0x63, 0xb2, 0x34, 0x22, 0x5d, 0x48, 0xc8, 0x83, 0x05, 0x64, 0x7c, 0x35, 0xfc, - 0xb8, 0xcc, 0x70, 0x9b, 0x29, 0xfb, 0x18, 0x4b, 0x08, 0x9b, 0x45, 0x20, 0xce, 0xdf, 0x03, 0x00, - 0x00, 0xff, 0xff, 0x8b, 0x69, 0xf9, 0x67, 0x88, 0x02, 0x00, 0x00, + // 426 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x92, 0x4f, 0x8b, 0x13, 0x31, + 0x18, 0xc6, 0x9b, 0x16, 0x57, 0x1a, 0x75, 0xc5, 0xb8, 0x4a, 0xa9, 0x30, 0x2d, 0xb9, 0x58, 0x90, + 0x4e, 0xd8, 0xfa, 0x0f, 0xbc, 0xb5, 0xab, 0x48, 0xaf, 0xe3, 0xcd, 0xcb, 0x90, 0x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3a, 0xb2, 0x93, 0xfa, 0xfa, 0x5f, 0x00, 0x00, 0x00, + 0xff, 0xff, 0xc5, 0x32, 0x06, 0x92, 0x21, 0x03, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { diff --git a/proto/ibc/applications/interchain_accounts/v1/account.proto b/proto/ibc/applications/interchain_accounts/v1/account.proto index a94519cd6ac..b7af89b502b 100644 --- a/proto/ibc/applications/interchain_accounts/v1/account.proto +++ b/proto/ibc/applications/interchain_accounts/v1/account.proto @@ -1,12 +1,13 @@ syntax = "proto3"; + package ibc.applications.interchain_accounts.v1; +option go_package = "github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types"; + import "cosmos_proto/cosmos.proto"; import "gogoproto/gogo.proto"; import "cosmos/auth/v1beta1/auth.proto"; -option go_package = "github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types"; - // An InterchainAccount is defined as a BaseAccount & the address of the account owner on the controller chain message InterchainAccount { option (gogoproto.goproto_getters) = false; diff --git a/proto/ibc/applications/interchain_accounts/v1/genesis.proto b/proto/ibc/applications/interchain_accounts/v1/genesis.proto index 609f287d6ad..5645e726a3d 100644 --- a/proto/ibc/applications/interchain_accounts/v1/genesis.proto +++ b/proto/ibc/applications/interchain_accounts/v1/genesis.proto @@ -1,4 +1,5 @@ syntax = "proto3"; + package ibc.applications.interchain_accounts.v1; option go_package = "github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types"; @@ -7,19 +8,19 @@ import "gogoproto/gogo.proto"; // GenesisState defines the interchain accounts genesis state message GenesisState { - repeated ActiveChannel active_channels = 1; - repeated RegisteredInterchainAccount interchain_accounts = 2; + repeated ActiveChannel active_channels = 1 [(gogoproto.moretags) = "yaml:\"active_channels\""]; + repeated RegisteredInterchainAccount interchain_accounts = 2 [(gogoproto.moretags) = "yaml:\"interchain_accounts\""]; repeated string ports = 3; } // ActiveChannel contains a pairing of port ID and channel ID for an active interchain accounts channel message ActiveChannel { - string port_id = 1; - string channel_id = 2; + string port_id = 1 [(gogoproto.moretags) = "yaml:\"port_id\""]; + string channel_id = 2 [(gogoproto.moretags) = "yaml:\"channel_id\""]; } // RegisteredInterchainAccount contains a pairing of controller port ID and associated interchain account address message RegisteredInterchainAccount { - string port_id = 1; - string account_address = 2; + string port_id = 1 [(gogoproto.moretags) = "yaml:\"port_id\""]; + string account_address = 2 [(gogoproto.moretags) = "yaml:\"account_address\""]; } diff --git a/proto/ibc/applications/interchain_accounts/v1/query.proto b/proto/ibc/applications/interchain_accounts/v1/query.proto index 160912b0610..a3b77506794 100644 --- a/proto/ibc/applications/interchain_accounts/v1/query.proto +++ b/proto/ibc/applications/interchain_accounts/v1/query.proto @@ -1,12 +1,13 @@ syntax = "proto3"; + package ibc.applications.interchain_accounts.v1; +option go_package = "github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types"; + import "gogoproto/gogo.proto"; import "google/api/annotations.proto"; import "ibc/applications/interchain_accounts/v1/account.proto"; -option go_package = "github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types"; - // Query defines the gRPC querier service. service Query { // Query to get the address of an interchain account diff --git a/proto/ibc/applications/interchain_accounts/v1/types.proto b/proto/ibc/applications/interchain_accounts/v1/types.proto index 0013610c150..73f7e227eab 100644 --- a/proto/ibc/applications/interchain_accounts/v1/types.proto +++ b/proto/ibc/applications/interchain_accounts/v1/types.proto @@ -1,9 +1,11 @@ syntax = "proto3"; + package ibc.applications.interchain_accounts.v1; +option go_package = "github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types"; + import "google/protobuf/any.proto"; import "gogoproto/gogo.proto"; -option go_package = "github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types"; // Body of a tx for an ics27 IBC packet message IBCTxBody { From b577e81a6f6523ae78df0dbd4f6d08fc1e5f71c8 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Mon, 11 Oct 2021 15:30:04 +0200 Subject: [PATCH 4/6] updating to use range queries for active channels/interchain accounts --- .../apps/27-interchain-accounts/genesis.go | 30 ++--------- .../27-interchain-accounts/keeper/keeper.go | 47 ++++++++++++++--- .../keeper/keeper_test.go | 52 +++++++++++++++++++ 3 files changed, 97 insertions(+), 32 deletions(-) diff --git a/modules/apps/27-interchain-accounts/genesis.go b/modules/apps/27-interchain-accounts/genesis.go index b6b6d8d1b98..ec1d650f990 100644 --- a/modules/apps/27-interchain-accounts/genesis.go +++ b/modules/apps/27-interchain-accounts/genesis.go @@ -32,31 +32,9 @@ func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, state types.GenesisState // ExportGenesis returns the interchain accounts exported genesis func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) *types.GenesisState { - var ( - activeChannels []*types.ActiveChannel - interchainAccounts []*types.RegisteredInterchainAccount + return types.NewGenesisState( + keeper.GetAllPorts(ctx), + keeper.GetAllActiveChannels(ctx), + keeper.GetAllInterchainAccounts(ctx), ) - - ports := keeper.GetAllPorts(ctx) - for _, portID := range ports { - if channelID, found := keeper.GetActiveChannel(ctx, portID); found { - activeChan := &types.ActiveChannel{ - PortId: portID, - ChannelId: channelID, - } - - activeChannels = append(activeChannels, activeChan) - } - - if accountAddr, found := keeper.GetInterchainAccountAddress(ctx, portID); found { - interchainAcc := &types.RegisteredInterchainAccount{ - PortId: portID, - AccountAddress: accountAddr, - } - - interchainAccounts = append(interchainAccounts, interchainAcc) - } - } - - return types.NewGenesisState(ports, activeChannels, interchainAccounts) } diff --git a/modules/apps/27-interchain-accounts/keeper/keeper.go b/modules/apps/27-interchain-accounts/keeper/keeper.go index 5eccb83f35d..f4cf9253c4f 100644 --- a/modules/apps/27-interchain-accounts/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/keeper/keeper.go @@ -100,12 +100,6 @@ func (k Keeper) GetAllPorts(ctx sdk.Context) []string { return ports } -// HasPort returns true if the provided portID is found in state, otherwise false -func (k Keeper) HasPort(ctx sdk.Context, portID string) bool { - store := ctx.KVStore(k.storeKey) - return store.Has(types.KeyPort(portID)) -} - // BindPort stores the provided portID and binds to it, returning the associated capability func (k Keeper) BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capability { store := ctx.KVStore(k.storeKey) @@ -142,6 +136,27 @@ func (k Keeper) GetActiveChannel(ctx sdk.Context, portID string) (string, bool) return string(store.Get(key)), true } +// GetAllActiveChannels returns a list of all active interchain accounts channels and their associated port identifiers +func (k Keeper) GetAllActiveChannels(ctx sdk.Context) []*types.ActiveChannel { + store := ctx.KVStore(k.storeKey) + iterator := sdk.KVStorePrefixIterator(store, []byte(types.ActiveChannelKeyPrefix)) + defer iterator.Close() + + var activeChannels []*types.ActiveChannel + for ; iterator.Valid(); iterator.Next() { + keySplit := strings.Split(string(iterator.Key()), "/") + + ch := &types.ActiveChannel{ + PortId: keySplit[1], + ChannelId: string(iterator.Value()), + } + + activeChannels = append(activeChannels, ch) + } + + return activeChannels +} + // SetActiveChannel stores the active channelID, keyed by the provided portID func (k Keeper) SetActiveChannel(ctx sdk.Context, portID, channelID string) { store := ctx.KVStore(k.storeKey) @@ -172,6 +187,26 @@ func (k Keeper) GetInterchainAccountAddress(ctx sdk.Context, portID string) (str return string(store.Get(key)), true } +// GetAllInterchainAccounts returns a list of all registered interchain account addresses and their associated controller port identifiers +func (k Keeper) GetAllInterchainAccounts(ctx sdk.Context) []*types.RegisteredInterchainAccount { + store := ctx.KVStore(k.storeKey) + iterator := sdk.KVStorePrefixIterator(store, []byte(types.OwnerKeyPrefix)) + + var interchainAccounts []*types.RegisteredInterchainAccount + for ; iterator.Valid(); iterator.Next() { + keySplit := strings.Split(string(iterator.Key()), "/") + + acc := &types.RegisteredInterchainAccount{ + PortId: keySplit[1], + AccountAddress: string(iterator.Value()), + } + + interchainAccounts = append(interchainAccounts, acc) + } + + return interchainAccounts +} + // SetInterchainAccountAddress stores the InterchainAccount address, keyed by the associated portID func (k Keeper) SetInterchainAccountAddress(ctx sdk.Context, portID string, address string) { store := ctx.KVStore(k.storeKey) diff --git a/modules/apps/27-interchain-accounts/keeper/keeper_test.go b/modules/apps/27-interchain-accounts/keeper/keeper_test.go index 307451fd14b..c4b685e72e7 100644 --- a/modules/apps/27-interchain-accounts/keeper/keeper_test.go +++ b/modules/apps/27-interchain-accounts/keeper/keeper_test.go @@ -141,6 +141,58 @@ func (suite *KeeperTestSuite) TestGetInterchainAccountAddress() { suite.Require().Empty(retrievedAddr) } +func (suite *KeeperTestSuite) TestGetAllActiveChannels() { + suite.SetupTest() + path := NewICAPath(suite.chainA, suite.chainB) + suite.coordinator.SetupConnections(path) + + err := SetupICAPath(path, TestOwnerAddress) + suite.Require().NoError(err) + + suite.chainA.GetSimApp().ICAKeeper.SetActiveChannel(suite.chainA.GetContext(), "testing-port", "testing-channel") + + expectedChannels := []*types.ActiveChannel{ + { + PortId: TestPortID, + ChannelId: path.EndpointA.ChannelID, + }, + { + PortId: "testing-port", + ChannelId: "testing-channel", + }, + } + + activeChannels := suite.chainA.GetSimApp().ICAKeeper.GetAllActiveChannels(suite.chainA.GetContext()) + suite.Require().Len(activeChannels, len(expectedChannels)) + suite.Require().Equal(expectedChannels, activeChannels) +} + +func (suite *KeeperTestSuite) TestGetAllInterchainAccounts() { + suite.SetupTest() + path := NewICAPath(suite.chainA, suite.chainB) + suite.coordinator.SetupConnections(path) + + err := SetupICAPath(path, TestOwnerAddress) + suite.Require().NoError(err) + + suite.chainA.GetSimApp().ICAKeeper.SetInterchainAccountAddress(suite.chainA.GetContext(), "testing-port", "testing-acc-addr") + + expectedAccounts := []*types.RegisteredInterchainAccount{ + { + PortId: TestPortID, + AccountAddress: TestAccAddress.String(), + }, + { + PortId: "testing-port", + AccountAddress: "testing-acc-addr", + }, + } + + interchainAccounts := suite.chainA.GetSimApp().ICAKeeper.GetAllInterchainAccounts(suite.chainA.GetContext()) + suite.Require().Len(interchainAccounts, len(expectedAccounts)) + suite.Require().Equal(expectedAccounts, interchainAccounts) +} + func (suite *KeeperTestSuite) TestIsActiveChannel() { suite.SetupTest() // reset path := NewICAPath(suite.chainA, suite.chainB) From 48bfa02d200cf309beaacbf333c22664a55b65a9 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Mon, 11 Oct 2021 15:42:12 +0200 Subject: [PATCH 5/6] updating GetAllPorts test --- modules/apps/27-interchain-accounts/keeper/keeper_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/apps/27-interchain-accounts/keeper/keeper_test.go b/modules/apps/27-interchain-accounts/keeper/keeper_test.go index c4b685e72e7..3fecc294c32 100644 --- a/modules/apps/27-interchain-accounts/keeper/keeper_test.go +++ b/modules/apps/27-interchain-accounts/keeper/keeper_test.go @@ -116,9 +116,11 @@ func (suite *KeeperTestSuite) TestGetAllPorts() { err := SetupICAPath(path, TestOwnerAddress) suite.Require().NoError(err) + expectedPorts := []string{types.PortID, TestPortID} + ports := suite.chainA.GetSimApp().ICAKeeper.GetAllPorts(suite.chainA.GetContext()) - suite.Require().Contains(ports, types.PortID) - suite.Require().Contains(ports, TestPortID) + suite.Require().Len(ports, len(expectedPorts)) + suite.Require().Equal(expectedPorts, ports) } func (suite *KeeperTestSuite) TestGetInterchainAccountAddress() { From f48428f72be1c6a1b6f5ac8862b4eb7fff4080a0 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Wed, 3 Nov 2021 14:35:40 +0100 Subject: [PATCH 6/6] moving test strings to expected vars --- .../27-interchain-accounts/genesis_test.go | 8 +++-- .../keeper/keeper_test.go | 34 +++++++++++++------ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/modules/apps/27-interchain-accounts/genesis_test.go b/modules/apps/27-interchain-accounts/genesis_test.go index 4c54dcf916e..513e56b8477 100644 --- a/modules/apps/27-interchain-accounts/genesis_test.go +++ b/modules/apps/27-interchain-accounts/genesis_test.go @@ -6,6 +6,10 @@ import ( ) func (suite *InterchainAccountsTestSuite) TestInitGenesis() { + var ( + expectedChannelID string = "channel-0" + ) + suite.SetupTest() genesisState := types.GenesisState{ @@ -13,7 +17,7 @@ func (suite *InterchainAccountsTestSuite) TestInitGenesis() { ActiveChannels: []*types.ActiveChannel{ { PortId: TestPortID, - ChannelId: "channel-0", + ChannelId: expectedChannelID, }, }, InterchainAccounts: []*types.RegisteredInterchainAccount{ @@ -28,7 +32,7 @@ func (suite *InterchainAccountsTestSuite) TestInitGenesis() { channelID, found := suite.chainA.GetSimApp().ICAKeeper.GetActiveChannel(suite.chainA.GetContext(), TestPortID) suite.Require().True(found) - suite.Require().Equal("channel-0", channelID) + suite.Require().Equal(expectedChannelID, channelID) accountAdrr, found := suite.chainA.GetSimApp().ICAKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), TestPortID) suite.Require().True(found) diff --git a/modules/apps/27-interchain-accounts/keeper/keeper_test.go b/modules/apps/27-interchain-accounts/keeper/keeper_test.go index 3fecc294c32..88aa3419598 100644 --- a/modules/apps/27-interchain-accounts/keeper/keeper_test.go +++ b/modules/apps/27-interchain-accounts/keeper/keeper_test.go @@ -144,6 +144,11 @@ func (suite *KeeperTestSuite) TestGetInterchainAccountAddress() { } func (suite *KeeperTestSuite) TestGetAllActiveChannels() { + var ( + expectedChannelID string = "test-channel" + expectedPortID string = "test-port" + ) + suite.SetupTest() path := NewICAPath(suite.chainA, suite.chainB) suite.coordinator.SetupConnections(path) @@ -151,7 +156,7 @@ func (suite *KeeperTestSuite) TestGetAllActiveChannels() { err := SetupICAPath(path, TestOwnerAddress) suite.Require().NoError(err) - suite.chainA.GetSimApp().ICAKeeper.SetActiveChannel(suite.chainA.GetContext(), "testing-port", "testing-channel") + suite.chainA.GetSimApp().ICAKeeper.SetActiveChannel(suite.chainA.GetContext(), expectedPortID, expectedChannelID) expectedChannels := []*types.ActiveChannel{ { @@ -159,8 +164,8 @@ func (suite *KeeperTestSuite) TestGetAllActiveChannels() { ChannelId: path.EndpointA.ChannelID, }, { - PortId: "testing-port", - ChannelId: "testing-channel", + PortId: expectedPortID, + ChannelId: expectedChannelID, }, } @@ -170,6 +175,11 @@ func (suite *KeeperTestSuite) TestGetAllActiveChannels() { } func (suite *KeeperTestSuite) TestGetAllInterchainAccounts() { + var ( + expectedAccAddr string = "test-acc-addr" + expectedPortID string = "test-port" + ) + suite.SetupTest() path := NewICAPath(suite.chainA, suite.chainB) suite.coordinator.SetupConnections(path) @@ -177,7 +187,7 @@ func (suite *KeeperTestSuite) TestGetAllInterchainAccounts() { err := SetupICAPath(path, TestOwnerAddress) suite.Require().NoError(err) - suite.chainA.GetSimApp().ICAKeeper.SetInterchainAccountAddress(suite.chainA.GetContext(), "testing-port", "testing-acc-addr") + suite.chainA.GetSimApp().ICAKeeper.SetInterchainAccountAddress(suite.chainA.GetContext(), expectedPortID, expectedAccAddr) expectedAccounts := []*types.RegisteredInterchainAccount{ { @@ -185,8 +195,8 @@ func (suite *KeeperTestSuite) TestGetAllInterchainAccounts() { AccountAddress: TestAccAddress.String(), }, { - PortId: "testing-port", - AccountAddress: "testing-acc-addr", + PortId: expectedPortID, + AccountAddress: expectedAccAddr, }, } @@ -210,12 +220,16 @@ func (suite *KeeperTestSuite) TestIsActiveChannel() { } func (suite *KeeperTestSuite) TestSetInterchainAccountAddress() { - expectedAddr, portID := "address", "port" - suite.chainA.GetSimApp().ICAKeeper.SetInterchainAccountAddress(suite.chainA.GetContext(), portID, expectedAddr) + var ( + expectedAccAddr string = "test-acc-addr" + expectedPortID string = "test-port" + ) + + suite.chainA.GetSimApp().ICAKeeper.SetInterchainAccountAddress(suite.chainA.GetContext(), expectedPortID, expectedAccAddr) - retrievedAddr, found := suite.chainA.GetSimApp().ICAKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), portID) + retrievedAddr, found := suite.chainA.GetSimApp().ICAKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), expectedPortID) suite.Require().True(found) - suite.Require().Equal(expectedAddr, retrievedAddr) + suite.Require().Equal(expectedAccAddr, retrievedAddr) } func (suite *KeeperTestSuite) SetupICAPath(path *ibctesting.Path, owner string) error {