From 5ae8e3538e5d9c9fb1f46408482f5cb14ec806f7 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Wed, 2 Feb 2022 16:45:01 +0100 Subject: [PATCH] chore: adding encoding and txType fields to metadata (#824) * adding encoding and txTypes fields to ica metadata * adapting metadata and validation to support encoding and txTypes fields. updating test cases * renaming field to tx_type * fixing failing tests from merge --- docs/ibc/proto-docs.md | 2 + .../controller/ibc_module_test.go | 4 + .../controller/keeper/account.go | 10 +- .../controller/keeper/handshake_test.go | 54 ++++++- .../controller/keeper/keeper_test.go | 2 + .../host/ibc_module_test.go | 2 + .../host/keeper/handshake_test.go | 26 ++- .../host/keeper/keeper_test.go | 2 + .../27-interchain-accounts/types/metadata.go | 60 ++++++- .../types/metadata.pb.go | 148 +++++++++++++++--- .../types/metadata_test.go | 80 +++++++++- .../interchain_accounts/v1/metadata.proto | 4 + 12 files changed, 366 insertions(+), 28 deletions(-) diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index 667b8b9a4ee..a497c928af1 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -423,6 +423,8 @@ See ICS004: https://github.com/cosmos/ibc/tree/master/spec/core/ics-004-channel- | `controller_connection_id` | [string](#string) | | controller_connection_id is the connection identifier associated with the controller chain | | `host_connection_id` | [string](#string) | | host_connection_id is the connection identifier associated with the host chain | | `address` | [string](#string) | | address defines the interchain account address to be fulfilled upon the OnChanOpenTry handshake step NOTE: the address field is empty on the OnChanOpenInit handshake step | +| `encoding` | [string](#string) | | encoding defines the supported codec format | +| `tx_type` | [string](#string) | | tx_type defines the type of transactions the interchain account can execute | diff --git a/modules/apps/27-interchain-accounts/controller/ibc_module_test.go b/modules/apps/27-interchain-accounts/controller/ibc_module_test.go index 9fd7486cf1a..f2b5d36ac63 100644 --- a/modules/apps/27-interchain-accounts/controller/ibc_module_test.go +++ b/modules/apps/27-interchain-accounts/controller/ibc_module_test.go @@ -35,6 +35,8 @@ var ( Version: icatypes.Version, ControllerConnectionId: ibctesting.FirstConnectionID, HostConnectionId: ibctesting.FirstConnectionID, + Encoding: icatypes.EncodingProtobuf, + TxType: icatypes.TxTypeSDKMultiMsg, })) ) @@ -675,6 +677,8 @@ func (suite *InterchainAccountsTestSuite) TestSingleHostMultipleControllers() { Version: icatypes.Version, ControllerConnectionId: pathCToB.EndpointA.ConnectionID, HostConnectionId: pathCToB.EndpointB.ConnectionID, + Encoding: icatypes.EncodingProtobuf, + TxType: icatypes.TxTypeSDKMultiMsg, })) err = SetupICAPath(pathCToB, TestOwnerAddress) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/account.go b/modules/apps/27-interchain-accounts/controller/keeper/account.go index 143c3a6055e..dd87348876e 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/account.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/account.go @@ -43,7 +43,15 @@ func (k Keeper) RegisterInterchainAccount(ctx sdk.Context, connectionID, owner s } // NOTE: An empty string is provided for accAddress, to be fulfilled upon OnChanOpenTry handshake step - metadata := icatypes.NewMetadata(icatypes.Version, connectionID, connectionEnd.GetCounterparty().GetConnectionID(), "") + metadata := icatypes.NewMetadata( + icatypes.Version, + connectionID, + connectionEnd.GetCounterparty().GetConnectionID(), + "", + icatypes.EncodingProtobuf, + icatypes.TxTypeSDKMultiMsg, + ) + versionBytes, err := icatypes.ModuleCdc.MarshalJSON(&metadata) if err != nil { return err diff --git a/modules/apps/27-interchain-accounts/controller/keeper/handshake_test.go b/modules/apps/27-interchain-accounts/controller/keeper/handshake_test.go index b08a6913aaf..0f1e1af41a0 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/handshake_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/handshake_test.go @@ -60,6 +60,32 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() { }, false, }, + { + "unsupported encoding format", + func() { + metadata.Encoding = "invalid-encoding-format" + + versionBytes, err := icatypes.ModuleCdc.MarshalJSON(&metadata) + suite.Require().NoError(err) + + channel.Version = string(versionBytes) + path.EndpointA.SetChannel(*channel) + }, + false, + }, + { + "unsupported transaction type", + func() { + metadata.TxType = "invalid-tx-types" + + versionBytes, err := icatypes.ModuleCdc.MarshalJSON(&metadata) + suite.Require().NoError(err) + + channel.Version = string(versionBytes) + path.EndpointA.SetChannel(*channel) + }, + false, + }, { "connection not found", func() { @@ -144,7 +170,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() { path.EndpointA.ChannelConfig.PortID = portID // default values - metadata = icatypes.NewMetadata(icatypes.Version, ibctesting.FirstConnectionID, ibctesting.FirstConnectionID, "") + metadata = icatypes.NewMetadata(icatypes.Version, ibctesting.FirstConnectionID, ibctesting.FirstConnectionID, "", icatypes.EncodingProtobuf, icatypes.TxTypeSDKMultiMsg) versionBytes, err := icatypes.ModuleCdc.MarshalJSON(&metadata) suite.Require().NoError(err) @@ -211,6 +237,30 @@ func (suite *KeeperTestSuite) TestOnChanOpenAck() { }, false, }, + { + "unsupported encoding format", + func() { + metadata.Encoding = "invalid-encoding-format" + + versionBytes, err := icatypes.ModuleCdc.MarshalJSON(&metadata) + suite.Require().NoError(err) + + path.EndpointA.Counterparty.ChannelConfig.Version = string(versionBytes) + }, + false, + }, + { + "unsupported transaction type", + func() { + metadata.TxType = "invalid-tx-types" + + versionBytes, err := icatypes.ModuleCdc.MarshalJSON(&metadata) + suite.Require().NoError(err) + + path.EndpointA.Counterparty.ChannelConfig.Version = string(versionBytes) + }, + false, + }, { "invalid account address", func() { @@ -275,7 +325,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenAck() { err = path.EndpointB.ChanOpenTry() suite.Require().NoError(err) - metadata = icatypes.NewMetadata(icatypes.Version, ibctesting.FirstConnectionID, ibctesting.FirstConnectionID, TestAccAddress.String()) + metadata = icatypes.NewMetadata(icatypes.Version, ibctesting.FirstConnectionID, ibctesting.FirstConnectionID, TestAccAddress.String(), icatypes.EncodingProtobuf, icatypes.TxTypeSDKMultiMsg) versionBytes, err := icatypes.ModuleCdc.MarshalJSON(&metadata) suite.Require().NoError(err) 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 eff4ce5fa96..c3e1a48ee0c 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go @@ -30,6 +30,8 @@ var ( Version: icatypes.Version, ControllerConnectionId: ibctesting.FirstConnectionID, HostConnectionId: ibctesting.FirstConnectionID, + Encoding: icatypes.EncodingProtobuf, + TxType: icatypes.TxTypeSDKMultiMsg, })) ) diff --git a/modules/apps/27-interchain-accounts/host/ibc_module_test.go b/modules/apps/27-interchain-accounts/host/ibc_module_test.go index ddf90c6d46c..0b312d34dd6 100644 --- a/modules/apps/27-interchain-accounts/host/ibc_module_test.go +++ b/modules/apps/27-interchain-accounts/host/ibc_module_test.go @@ -37,6 +37,8 @@ var ( Version: icatypes.Version, ControllerConnectionId: ibctesting.FirstConnectionID, HostConnectionId: ibctesting.FirstConnectionID, + Encoding: icatypes.EncodingProtobuf, + TxType: icatypes.TxTypeSDKMultiMsg, })) ) diff --git a/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go b/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go index 6f3dc0d25e1..e920a55f0df 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go @@ -66,6 +66,30 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { }, false, }, + { + "unsupported encoding format", + func() { + metadata.Encoding = "invalid-encoding-format" + + versionBytes, err := icatypes.ModuleCdc.MarshalJSON(&metadata) + suite.Require().NoError(err) + + path.EndpointA.ChannelConfig.Version = string(versionBytes) + }, + false, + }, + { + "unsupported transaction type", + func() { + metadata.TxType = "invalid-tx-types" + + versionBytes, err := icatypes.ModuleCdc.MarshalJSON(&metadata) + suite.Require().NoError(err) + + path.EndpointA.ChannelConfig.Version = string(versionBytes) + }, + false, + }, { "invalid controller connection ID", func() { @@ -141,7 +165,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { path.EndpointB.ChannelID = channeltypes.FormatChannelIdentifier(channelSequence) // default values - metadata = icatypes.NewMetadata(icatypes.Version, ibctesting.FirstConnectionID, ibctesting.FirstConnectionID, "") + metadata = icatypes.NewMetadata(icatypes.Version, ibctesting.FirstConnectionID, ibctesting.FirstConnectionID, "", icatypes.EncodingProtobuf, icatypes.TxTypeSDKMultiMsg) versionBytes, err := icatypes.ModuleCdc.MarshalJSON(&metadata) suite.Require().NoError(err) 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 2b38f6b5e84..96c80c45f99 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go @@ -30,6 +30,8 @@ var ( Version: icatypes.Version, ControllerConnectionId: ibctesting.FirstConnectionID, HostConnectionId: ibctesting.FirstConnectionID, + Encoding: icatypes.EncodingProtobuf, + TxType: icatypes.TxTypeSDKMultiMsg, })) ) diff --git a/modules/apps/27-interchain-accounts/types/metadata.go b/modules/apps/27-interchain-accounts/types/metadata.go index acc1dcb940b..67588e2d809 100644 --- a/modules/apps/27-interchain-accounts/types/metadata.go +++ b/modules/apps/27-interchain-accounts/types/metadata.go @@ -7,18 +7,36 @@ import ( connectiontypes "github.com/cosmos/ibc-go/v3/modules/core/03-connection/types" ) +const ( + // EncodingProtobuf defines the protocol buffers proto3 encoding format + EncodingProtobuf = "proto3" + + // TxTypeSDKMultiMsg defines the multi message transaction type supported by the Cosmos SDK + TxTypeSDKMultiMsg = "sdk_multi_msg" +) + // NewMetadata creates and returns a new ICS27 Metadata instance -func NewMetadata(version, controllerConnectionID, hostConnectionID, accAddress string) Metadata { +func NewMetadata(version, controllerConnectionID, hostConnectionID, accAddress, encoding, txType string) Metadata { return Metadata{ Version: version, ControllerConnectionId: controllerConnectionID, HostConnectionId: hostConnectionID, Address: accAddress, + Encoding: encoding, + TxType: txType, } } // ValidateControllerMetadata performs validation of the provided ICS27 controller metadata parameters func ValidateControllerMetadata(ctx sdk.Context, channelKeeper ChannelKeeper, connectionHops []string, metadata Metadata) error { + if !isSupportedEncoding(metadata.Encoding) { + return sdkerrors.Wrapf(ErrInvalidCodec, "unsupported encoding format %s", metadata.Encoding) + } + + if !isSupportedTxType(metadata.TxType) { + return sdkerrors.Wrapf(ErrUnknownDataType, "unsupported transaction type %s", metadata.TxType) + } + connection, err := channelKeeper.GetConnection(ctx, connectionHops[0]) if err != nil { return err @@ -43,6 +61,14 @@ func ValidateControllerMetadata(ctx sdk.Context, channelKeeper ChannelKeeper, co // ValidateHostMetadata performs validation of the provided ICS27 host metadata parameters func ValidateHostMetadata(ctx sdk.Context, channelKeeper ChannelKeeper, connectionHops []string, metadata Metadata) error { + if !isSupportedEncoding(metadata.Encoding) { + return sdkerrors.Wrapf(ErrInvalidCodec, "unsupported encoding format %s", metadata.Encoding) + } + + if !isSupportedTxType(metadata.TxType) { + return sdkerrors.Wrapf(ErrUnknownDataType, "unsupported transaction type %s", metadata.TxType) + } + connection, err := channelKeeper.GetConnection(ctx, connectionHops[0]) if err != nil { return err @@ -65,6 +91,38 @@ func ValidateHostMetadata(ctx sdk.Context, channelKeeper ChannelKeeper, connecti return nil } +// isSupportedEncoding returns true if the provided encoding is supported, otherwise false +func isSupportedEncoding(encoding string) bool { + for _, enc := range getSupportedEncoding() { + if enc == encoding { + return true + } + } + + return false +} + +// getSupportedEncoding returns a string slice of supported encoding formats +func getSupportedEncoding() []string { + return []string{EncodingProtobuf} +} + +// isSupportedTxType returns true if the provided transaction type is supported, otherwise false +func isSupportedTxType(txType string) bool { + for _, t := range getSupportedTxTypes() { + if t == txType { + return true + } + } + + return false +} + +// getSupportedTxTypes returns a string slice of supported transaction types +func getSupportedTxTypes() []string { + return []string{TxTypeSDKMultiMsg} +} + // validateConnectionParams compares the given the controller and host connection IDs to those set in the provided ICS27 Metadata func validateConnectionParams(metadata Metadata, controllerConnectionID, hostConnectionID string) error { if metadata.ControllerConnectionId != controllerConnectionID { diff --git a/modules/apps/27-interchain-accounts/types/metadata.pb.go b/modules/apps/27-interchain-accounts/types/metadata.pb.go index d3cc1214361..907e8c0c01d 100644 --- a/modules/apps/27-interchain-accounts/types/metadata.pb.go +++ b/modules/apps/27-interchain-accounts/types/metadata.pb.go @@ -35,6 +35,10 @@ type Metadata struct { // address defines the interchain account address to be fulfilled upon the OnChanOpenTry handshake step // NOTE: the address field is empty on the OnChanOpenInit handshake step Address string `protobuf:"bytes,4,opt,name=address,proto3" json:"address,omitempty"` + // encoding defines the supported codec format + Encoding string `protobuf:"bytes,5,opt,name=encoding,proto3" json:"encoding,omitempty"` + // tx_type defines the type of transactions the interchain account can execute + TxType string `protobuf:"bytes,6,opt,name=tx_type,json=txType,proto3" json:"tx_type,omitempty"` } func (m *Metadata) Reset() { *m = Metadata{} } @@ -98,6 +102,20 @@ func (m *Metadata) GetAddress() string { return "" } +func (m *Metadata) GetEncoding() string { + if m != nil { + return m.Encoding + } + return "" +} + +func (m *Metadata) GetTxType() string { + if m != nil { + return m.TxType + } + return "" +} + func init() { proto.RegisterType((*Metadata)(nil), "ibc.applications.interchain_accounts.v1.Metadata") } @@ -107,27 +125,29 @@ func init() { } var fileDescriptor_c29c32e397d1f21e = []byte{ - // 316 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x91, 0xcf, 0x4b, 0xc3, 0x30, - 0x14, 0xc7, 0x57, 0x15, 0xa7, 0x3d, 0x49, 0x11, 0x89, 0x82, 0x99, 0xd4, 0x83, 0x5e, 0xd6, 0x30, - 0x07, 0x0a, 0x1e, 0x27, 0x1e, 0x44, 0xbc, 0xec, 0x28, 0x48, 0x49, 0x5f, 0x42, 0x17, 0x68, 0x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xb5, 0x64, 0xab, 0xfe, 0xc5, 0xb2, 0xec, 0xc5, 0x2f, 0x53, 0xea, - 0x8d, 0xa7, 0xd4, 0x7b, 0x9b, 0x52, 0xef, 0x79, 0x46, 0x1b, 0xe3, 0x19, 0x6d, 0xbc, 0xce, 0x68, - 0xe3, 0xf1, 0x36, 0x55, 0x6e, 0x30, 0x4c, 0x22, 0xc0, 0x9c, 0x01, 0xda, 0x1c, 0x2d, 0x53, 0x09, - 0xb4, 0x53, 0x64, 0x65, 0x97, 0xe5, 0x28, 0x86, 0x99, 0xb4, 0xd5, 0x76, 0x2c, 0xbb, 0xb8, 0x6a, - 0xaf, 0x07, 0xdc, 0x5e, 0x2d, 0xc6, 0x8d, 0x0a, 0x69, 0x93, 0xed, 0xc5, 0x50, 0xbb, 0x1f, 0x01, - 0x00, 0x00, 0xff, 0xff, 0xb0, 0xff, 0x53, 0x4e, 0xcd, 0x01, 0x00, 0x00, + // 349 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x91, 0xcf, 0x4a, 0xeb, 0x40, + 0x18, 0xc5, 0x9b, 0xde, 0x6b, 0x5b, 0x67, 0x25, 0x83, 0xe8, 0x58, 0x30, 0x95, 0xb8, 0xd0, 0x4d, + 0x33, 0xd4, 0x82, 0x82, 0xcb, 0x8a, 0x0b, 0x11, 0x37, 0xc5, 0x95, 0x20, 0x61, 0x32, 0x33, 0xa4, + 0x03, 0xc9, 0x7c, 0x21, 0x33, 0x0d, 0xed, 0x5b, 0xf8, 0x06, 0xbe, 0x8e, 0xcb, 0x2e, 0x5d, 0x15, + 0x69, 0xdf, 0xa0, 0x4f, 0x20, 0x49, 0x6b, 0xeb, 0xdf, 0x5d, 0x4e, 0xce, 0x39, 0xbf, 0x8f, 0xe1, + 0xa0, 0x73, 0x15, 0x72, 0xca, 0xd2, 0x34, 0x56, 0x9c, 0x59, 0x05, 0xda, 0x50, 0xa5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 0xeb, 0xbc, 0xcd, 0x5c, 0xe7, 0x69, 0xee, 0x56, 0x26, 0x73, 0xb7, 0xf2, + 0x3a, 0x77, 0x2b, 0x0f, 0xd7, 0x91, 0xb2, 0x83, 0x61, 0xe8, 0x73, 0x48, 0x28, 0x07, 0x93, 0x80, + 0xa1, 0x2a, 0xe4, 0xed, 0x08, 0x68, 0xde, 0xa5, 0x09, 0x88, 0x61, 0x2c, 0x4d, 0x31, 0xa9, 0xa1, + 0x67, 0x17, 0xed, 0xcd, 0x2a, 0xed, 0xf5, 0x9a, 0xc5, 0x35, 0x13, 0xd6, 0xca, 0x25, 0xba, 0xef, + 0x01, 0x00, 0x00, 0xff, 0xff, 0x6e, 0x74, 0x28, 0x89, 0x02, 0x02, 0x00, 0x00, } func (m *Metadata) Marshal() (dAtA []byte, err error) { @@ -150,6 +170,20 @@ func (m *Metadata) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.TxType) > 0 { + i -= len(m.TxType) + copy(dAtA[i:], m.TxType) + i = encodeVarintMetadata(dAtA, i, uint64(len(m.TxType))) + i-- + dAtA[i] = 0x32 + } + if len(m.Encoding) > 0 { + i -= len(m.Encoding) + copy(dAtA[i:], m.Encoding) + i = encodeVarintMetadata(dAtA, i, uint64(len(m.Encoding))) + i-- + dAtA[i] = 0x2a + } if len(m.Address) > 0 { i -= len(m.Address) copy(dAtA[i:], m.Address) @@ -214,6 +248,14 @@ func (m *Metadata) Size() (n int) { if l > 0 { n += 1 + l + sovMetadata(uint64(l)) } + l = len(m.Encoding) + if l > 0 { + n += 1 + l + sovMetadata(uint64(l)) + } + l = len(m.TxType) + if l > 0 { + n += 1 + l + sovMetadata(uint64(l)) + } return n } @@ -380,6 +422,70 @@ func (m *Metadata) Unmarshal(dAtA []byte) error { } m.Address = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Encoding", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMetadata + } + 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 ErrInvalidLengthMetadata + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthMetadata + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Encoding = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TxType", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMetadata + } + 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 ErrInvalidLengthMetadata + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthMetadata + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.TxType = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipMetadata(dAtA[iNdEx:]) diff --git a/modules/apps/27-interchain-accounts/types/metadata_test.go b/modules/apps/27-interchain-accounts/types/metadata_test.go index 2e569549647..1c53b8f7126 100644 --- a/modules/apps/27-interchain-accounts/types/metadata_test.go +++ b/modules/apps/27-interchain-accounts/types/metadata_test.go @@ -27,10 +27,40 @@ func (suite *TypesTestSuite) TestValidateControllerMetadata() { ControllerConnectionId: ibctesting.FirstConnectionID, HostConnectionId: ibctesting.FirstConnectionID, Address: "", + Encoding: types.EncodingProtobuf, + TxType: types.TxTypeSDKMultiMsg, } }, true, }, + { + "unsupported encoding format", + func() { + metadata = types.Metadata{ + Version: types.Version, + ControllerConnectionId: ibctesting.FirstConnectionID, + HostConnectionId: ibctesting.FirstConnectionID, + Address: TestOwnerAddress, + Encoding: "invalid-encoding-format", + TxType: types.TxTypeSDKMultiMsg, + } + }, + false, + }, + { + "unsupported transaction type", + func() { + metadata = types.Metadata{ + Version: types.Version, + ControllerConnectionId: ibctesting.FirstConnectionID, + HostConnectionId: ibctesting.FirstConnectionID, + Address: TestOwnerAddress, + Encoding: types.EncodingProtobuf, + TxType: "invalid-tx-type", + } + }, + false, + }, { "invalid controller connection", func() { @@ -39,6 +69,8 @@ func (suite *TypesTestSuite) TestValidateControllerMetadata() { ControllerConnectionId: "connection-10", HostConnectionId: ibctesting.FirstConnectionID, Address: TestOwnerAddress, + Encoding: types.EncodingProtobuf, + TxType: types.TxTypeSDKMultiMsg, } }, false, @@ -51,6 +83,8 @@ func (suite *TypesTestSuite) TestValidateControllerMetadata() { ControllerConnectionId: ibctesting.FirstConnectionID, HostConnectionId: "connection-10", Address: TestOwnerAddress, + Encoding: types.EncodingProtobuf, + TxType: types.TxTypeSDKMultiMsg, } }, false, @@ -63,6 +97,8 @@ func (suite *TypesTestSuite) TestValidateControllerMetadata() { ControllerConnectionId: ibctesting.FirstConnectionID, HostConnectionId: ibctesting.FirstConnectionID, Address: " ", + Encoding: types.EncodingProtobuf, + TxType: types.TxTypeSDKMultiMsg, } }, false, @@ -75,6 +111,8 @@ func (suite *TypesTestSuite) TestValidateControllerMetadata() { ControllerConnectionId: ibctesting.FirstConnectionID, HostConnectionId: ibctesting.FirstConnectionID, Address: TestOwnerAddress, + Encoding: types.EncodingProtobuf, + TxType: types.TxTypeSDKMultiMsg, } }, false, @@ -89,7 +127,7 @@ func (suite *TypesTestSuite) TestValidateControllerMetadata() { path := ibctesting.NewPath(suite.chainA, suite.chainB) suite.coordinator.SetupConnections(path) - metadata = types.NewMetadata(types.Version, ibctesting.FirstConnectionID, ibctesting.FirstConnectionID, TestOwnerAddress) + metadata = types.NewMetadata(types.Version, ibctesting.FirstConnectionID, ibctesting.FirstConnectionID, TestOwnerAddress, types.EncodingProtobuf, types.TxTypeSDKMultiMsg) tc.malleate() // malleate mutates test data @@ -131,10 +169,40 @@ func (suite *TypesTestSuite) TestValidateHostMetadata() { ControllerConnectionId: ibctesting.FirstConnectionID, HostConnectionId: ibctesting.FirstConnectionID, Address: "", + Encoding: types.EncodingProtobuf, + TxType: types.TxTypeSDKMultiMsg, } }, true, }, + { + "unsupported encoding format", + func() { + metadata = types.Metadata{ + Version: types.Version, + ControllerConnectionId: ibctesting.FirstConnectionID, + HostConnectionId: ibctesting.FirstConnectionID, + Address: TestOwnerAddress, + Encoding: "invalid-encoding-format", + TxType: types.TxTypeSDKMultiMsg, + } + }, + false, + }, + { + "unsupported transaction type", + func() { + metadata = types.Metadata{ + Version: types.Version, + ControllerConnectionId: ibctesting.FirstConnectionID, + HostConnectionId: ibctesting.FirstConnectionID, + Address: TestOwnerAddress, + Encoding: types.EncodingProtobuf, + TxType: "invalid-tx-type", + } + }, + false, + }, { "invalid controller connection", func() { @@ -143,6 +211,8 @@ func (suite *TypesTestSuite) TestValidateHostMetadata() { ControllerConnectionId: "connection-10", HostConnectionId: ibctesting.FirstConnectionID, Address: TestOwnerAddress, + Encoding: types.EncodingProtobuf, + TxType: types.TxTypeSDKMultiMsg, } }, false, @@ -155,6 +225,8 @@ func (suite *TypesTestSuite) TestValidateHostMetadata() { ControllerConnectionId: ibctesting.FirstConnectionID, HostConnectionId: "connection-10", Address: TestOwnerAddress, + Encoding: types.EncodingProtobuf, + TxType: types.TxTypeSDKMultiMsg, } }, false, @@ -167,6 +239,8 @@ func (suite *TypesTestSuite) TestValidateHostMetadata() { ControllerConnectionId: ibctesting.FirstConnectionID, HostConnectionId: ibctesting.FirstConnectionID, Address: " ", + Encoding: types.EncodingProtobuf, + TxType: types.TxTypeSDKMultiMsg, } }, false, @@ -179,6 +253,8 @@ func (suite *TypesTestSuite) TestValidateHostMetadata() { ControllerConnectionId: ibctesting.FirstConnectionID, HostConnectionId: ibctesting.FirstConnectionID, Address: TestOwnerAddress, + Encoding: types.EncodingProtobuf, + TxType: types.TxTypeSDKMultiMsg, } }, false, @@ -193,7 +269,7 @@ func (suite *TypesTestSuite) TestValidateHostMetadata() { path := ibctesting.NewPath(suite.chainA, suite.chainB) suite.coordinator.SetupConnections(path) - metadata = types.NewMetadata(types.Version, ibctesting.FirstConnectionID, ibctesting.FirstConnectionID, TestOwnerAddress) + metadata = types.NewMetadata(types.Version, ibctesting.FirstConnectionID, ibctesting.FirstConnectionID, TestOwnerAddress, types.EncodingProtobuf, types.TxTypeSDKMultiMsg) tc.malleate() // malleate mutates test data diff --git a/proto/ibc/applications/interchain_accounts/v1/metadata.proto b/proto/ibc/applications/interchain_accounts/v1/metadata.proto index acc338466af..3eab1d04a69 100644 --- a/proto/ibc/applications/interchain_accounts/v1/metadata.proto +++ b/proto/ibc/applications/interchain_accounts/v1/metadata.proto @@ -18,4 +18,8 @@ message Metadata { // address defines the interchain account address to be fulfilled upon the OnChanOpenTry handshake step // NOTE: the address field is empty on the OnChanOpenInit handshake step string address = 4; + // encoding defines the supported codec format + string encoding = 5; + // tx_type defines the type of transactions the interchain account can execute + string tx_type = 6; }