Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added optional packet metadata to the packet and message types #2305

Merged
merged 23 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a9f4f40
added optional packet metadata to the packet and message types
nicolaslara Sep 19, 2022
2254b3d
added docs
nicolaslara Sep 19, 2022
ed80695
Merge branch 'main' into nicolas/packet-metadata-proto
nicolaslara Oct 3, 2022
7c925b9
breaking the api (backports should add a utility function for this)
nicolaslara Oct 3, 2022
1448633
adding nil metadata on all the calls
nicolaslara Oct 3, 2022
71eae26
added metadata to the cli
nicolaslara Oct 3, 2022
2480e13
added events
nicolaslara Oct 3, 2022
bbd1d91
breaking api for FungibleTokenPacketData
nicolaslara Oct 5, 2022
9db4f98
hex encoding metadata
nicolaslara Oct 5, 2022
40709af
added abstraction
nicolaslara Oct 5, 2022
415cc40
Merge branch 'main' into nicolas/packet-metadata-proto
nicolaslara Oct 5, 2022
1497a4a
fixed bad merge
nicolaslara Oct 5, 2022
5faf1db
added tests with metadata
nicolaslara Oct 3, 2022
8eb9bc8
added missing metadata to packet for recv
nicolaslara Oct 5, 2022
dea382f
cleaning up metadata on every test
nicolaslara Oct 7, 2022
f57e0e9
reset metadata
nicolaslara Oct 7, 2022
a9fc91d
Merge branch 'main' into nicolas/packet-metadata-proto
nicolaslara Oct 7, 2022
2095551
added metadata flag
nicolaslara Oct 10, 2022
b697757
Merge branch 'main' into nicolas/packet-metadata-proto
nicolaslara Oct 10, 2022
4415340
lint
nicolaslara Oct 10, 2022
7efb307
Update modules/apps/transfer/client/cli/tx.go
nicolaslara Oct 10, 2022
2f6be14
fixed bad call in tests
nicolaslara Oct 10, 2022
3d0174b
Merge branch 'nicolas/packet-metadata-proto' of github.com:nicolaslar…
nicolaslara Oct 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/apps/transfer/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ order: 5
| fungible_token_packet | denom | {denom} |
| fungible_token_packet | amount | {amount} |
| fungible_token_packet | success | {ackSuccess} |
| fungible_token_packet | metadata | {metadata} |
| denomination_trace | trace_hash | {hex_hash} |

## `OnAcknowledgePacket` callback
Expand All @@ -34,6 +35,7 @@ order: 5
| fungible_token_packet | receiver | {receiver} |
| fungible_token_packet | denom | {denom} |
| fungible_token_packet | amount | {amount} |
| fungible_token_packet | metadata | {metadata} |
| fungible_token_packet | acknowledgement | {ack.String()} |
| fungible_token_packet | success | error | {ack.Response} |

Expand All @@ -45,3 +47,4 @@ order: 5
| fungible_token_packet | refund_receiver | {receiver} |
| fungible_token_packet | denom | {denom} |
| fungible_token_packet | amount | {amount} |
| fungible_token_packet | metadata | {metadata} |
1 change: 1 addition & 0 deletions docs/apps/transfer/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type MsgTransfer struct {
Receiver string
TimeoutHeight ibcexported.Height
TimeoutTimestamp uint64
Metadata []byte
}
```

Expand Down
2 changes: 2 additions & 0 deletions docs/ibc/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -2255,6 +2255,7 @@ https://github.com/cosmos/ibc/tree/master/spec/app/ics-020-fungible-token-transf
| `receiver` | [string](#string) | | the recipient address on the destination chain |
| `timeout_height` | [ibc.core.client.v1.Height](#ibc.core.client.v1.Height) | | Timeout height relative to the current block height. The timeout is disabled when set to 0. |
| `timeout_timestamp` | [uint64](#uint64) | | Timeout timestamp in absolute nanoseconds since unix epoch. The timeout is disabled when set to 0. |
| `metadata` | [bytes](#bytes) | | optional metadata |



Expand Down Expand Up @@ -2311,6 +2312,7 @@ https://github.com/cosmos/ibc/tree/master/spec/app/ics-020-fungible-token-transf
| `amount` | [string](#string) | | the token amount to be transferred |
| `sender` | [string](#string) | | the sender address |
| `receiver` | [string](#string) | | the recipient address on the destination chain |
| `metadata` | [bytes](#bytes) | | optional metadata |



Expand Down
8 changes: 7 additions & 1 deletion modules/apps/transfer/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
flagPacketTimeoutHeight = "packet-timeout-height"
flagPacketTimeoutTimestamp = "packet-timeout-timestamp"
flagAbsoluteTimeouts = "absolute-timeouts"
flagMetadata = "metadata"
nicolaslara marked this conversation as resolved.
Show resolved Hide resolved
)

// NewTransferTxCmd returns the command to create a NewMsgTransfer transaction
Expand Down Expand Up @@ -76,6 +77,11 @@ corresponding to the counterparty channel. Any timeout set to 0 is disabled.`),
return err
}

metadataStr, err := cmd.Flags().GetString(flagMetadata)
if err != nil {
return err
}

// if the timeouts are not absolute, retrieve latest block height and block timestamp
// for the consensus state connected to the destination port/channel
if !absoluteTimeouts {
Expand Down Expand Up @@ -111,7 +117,7 @@ corresponding to the counterparty channel. Any timeout set to 0 is disabled.`),
}

msg := types.NewMsgTransfer(
srcPort, srcChannel, coin, sender, receiver, timeoutHeight, timeoutTimestamp,
srcPort, srcChannel, coin, sender, receiver, timeoutHeight, timeoutTimestamp, []byte(metadataStr),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to pass in as metadata some serialized protocol buffer data, for example? Or is it expected that the metadata should only be string information?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it should be bytes on those functions too. That give users more flexibility. I can make the change

Copy link
Contributor

@crodriguezvega crodriguezvega Oct 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks in advance! Yes, I think that generalization will be good to have.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohh wait, looked at this in detail now. We're already using bytes everywhere else, and I think it makes more sense to keep it as string in the CLI so that it's easy to write/use. We could use hex encoded bytes, but for 99% of the cases we'd end up making it harder for the users.

I think if they really need bytes, they can create the message manually and pass it via grpc.

)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
Expand Down
3 changes: 3 additions & 0 deletions modules/apps/transfer/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ func (im IBCModule) OnRecvPacket(
sdk.NewAttribute(types.AttributeKeyReceiver, data.Receiver),
sdk.NewAttribute(types.AttributeKeyDenom, data.Denom),
sdk.NewAttribute(types.AttributeKeyAmount, data.Amount),
sdk.NewAttribute(types.AttributeKeyMetadata, string(data.Metadata)),
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
sdk.NewAttribute(types.AttributeKeyAckSuccess, fmt.Sprintf("%t", ack.Success())),
}

Expand Down Expand Up @@ -240,6 +241,7 @@ func (im IBCModule) OnAcknowledgementPacket(
sdk.NewAttribute(types.AttributeKeyReceiver, data.Receiver),
sdk.NewAttribute(types.AttributeKeyDenom, data.Denom),
sdk.NewAttribute(types.AttributeKeyAmount, data.Amount),
sdk.NewAttribute(types.AttributeKeyMetadata, string(data.Metadata)),
nicolaslara marked this conversation as resolved.
Show resolved Hide resolved
sdk.NewAttribute(types.AttributeKeyAck, ack.String()),
),
)
Expand Down Expand Up @@ -286,6 +288,7 @@ func (im IBCModule) OnTimeoutPacket(
sdk.NewAttribute(types.AttributeKeyRefundReceiver, data.Sender),
sdk.NewAttribute(types.AttributeKeyRefundDenom, data.Denom),
sdk.NewAttribute(types.AttributeKeyRefundAmount, data.Amount),
sdk.NewAttribute(types.AttributeKeyMetadata, string(data.Metadata)),
),
)

Expand Down
3 changes: 2 additions & 1 deletion modules/apps/transfer/keeper/mbt_relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,8 @@ func (suite *KeeperTestSuite) TestModelBasedRelay() {
sender,
tc.packet.Data.Receiver,
clienttypes.NewHeight(1, 110),
0)
0,
nil)
}
case "OnRecvPacket":
err = suite.chainB.GetSimApp().TransferKeeper.OnRecvPacket(suite.chainB.GetContext(), packet, tc.packet.Data)
Expand Down
4 changes: 2 additions & 2 deletions modules/apps/transfer/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keeper

import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"
nicolaslara marked this conversation as resolved.
Show resolved Hide resolved

"github.com/cosmos/ibc-go/v6/modules/apps/transfer/types"
Expand All @@ -19,8 +18,9 @@ func (k Keeper) Transfer(goCtx context.Context, msg *types.MsgTransfer) (*types.
return nil, err
}

if err := k.sendTransfer(
if err := k.SendTransfer(
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
ctx, msg.SourcePort, msg.SourceChannel, msg.Token, sender, msg.Receiver, msg.TimeoutHeight, msg.TimeoutTimestamp,
msg.Metadata,
); err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions modules/apps/transfer/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func (suite *KeeperTestSuite) TestMsgTransfer() {
path.EndpointA.ChannelID,
coin, suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(),
suite.chainB.GetTimeoutHeight(), 0, // only use timeout height
[]byte("custom metadata"),
)

tc.malleate()
Expand Down
28 changes: 3 additions & 25 deletions modules/apps/transfer/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,29 +59,7 @@ func (k Keeper) SendTransfer(
receiver string,
timeoutHeight clienttypes.Height,
timeoutTimestamp uint64,
) error {
return k.sendTransfer(
ctx,
sourcePort,
sourceChannel,
token,
sender,
receiver,
timeoutHeight,
timeoutTimestamp,
)
}

// sendTransfer handles transfer sending logic.
func (k Keeper) sendTransfer(
ctx sdk.Context,
sourcePort,
sourceChannel string,
token sdk.Coin,
sender sdk.AccAddress,
receiver string,
timeoutHeight clienttypes.Height,
timeoutTimestamp uint64,
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
metadata []byte,
) error {
if !k.GetSendEnabled(ctx) {
return types.ErrSendDisabled
Expand Down Expand Up @@ -171,8 +149,8 @@ func (k Keeper) sendTransfer(
}
}

packetData := types.NewFungibleTokenPacketData(
fullDenomPath, token.Amount.String(), sender.String(), receiver,
packetData := types.NewFungibleTokenPacketDataWithMetadata(
fullDenomPath, token.Amount.String(), sender.String(), receiver, metadata,
)

packet := channeltypes.NewPacket(
Expand Down
7 changes: 4 additions & 3 deletions modules/apps/transfer/keeper/relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (suite *KeeperTestSuite) TestSendTransfer() {
if !tc.sendFromSource {
// send coin from chainB to chainA
coinFromBToA := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))
transferMsg := types.NewMsgTransfer(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, coinFromBToA, suite.chainB.SenderAccount.GetAddress().String(), suite.chainA.SenderAccount.GetAddress().String(), clienttypes.NewHeight(1, 110), 0)
transferMsg := types.NewMsgTransfer(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, coinFromBToA, suite.chainB.SenderAccount.GetAddress().String(), suite.chainA.SenderAccount.GetAddress().String(), clienttypes.NewHeight(1, 110), 0, nil)
_, err = suite.chainB.SendMsgs(transferMsg)
suite.Require().NoError(err) // message committed

Expand All @@ -143,6 +143,7 @@ func (suite *KeeperTestSuite) TestSendTransfer() {
err = suite.chainA.GetSimApp().TransferKeeper.SendTransfer(
suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, amount,
sender, suite.chainB.SenderAccount.GetAddress().String(), suite.chainB.GetTimeoutHeight(), 0,
nil,
)

if tc.expPass {
Expand Down Expand Up @@ -219,7 +220,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
if tc.recvIsSource {
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
// send coin from chainB to chainA, receive them, acknowledge them, and send back to chainB
coinFromBToA := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))
transferMsg := types.NewMsgTransfer(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, coinFromBToA, suite.chainB.SenderAccount.GetAddress().String(), suite.chainA.SenderAccount.GetAddress().String(), clienttypes.NewHeight(1, 110), 0)
transferMsg := types.NewMsgTransfer(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, coinFromBToA, suite.chainB.SenderAccount.GetAddress().String(), suite.chainA.SenderAccount.GetAddress().String(), clienttypes.NewHeight(1, 110), 0, nil)
res, err := suite.chainB.SendMsgs(transferMsg)
suite.Require().NoError(err) // message committed

Expand All @@ -238,7 +239,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
}

// send coin from chainA to chainB
transferMsg := types.NewMsgTransfer(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, sdk.NewCoin(trace.IBCDenom(), amount), suite.chainA.SenderAccount.GetAddress().String(), receiver, clienttypes.NewHeight(1, 110), 0)
transferMsg := types.NewMsgTransfer(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, sdk.NewCoin(trace.IBCDenom(), amount), suite.chainA.SenderAccount.GetAddress().String(), receiver, clienttypes.NewHeight(1, 110), 0, nil)
_, err := suite.chainA.SendMsgs(transferMsg)
suite.Require().NoError(err) // message committed

Expand Down
6 changes: 3 additions & 3 deletions modules/apps/transfer/transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (suite *TransferTestSuite) TestHandleMsgTransfer() {
coinToSendToB := sdk.NewCoin(sdk.DefaultBondDenom, amount)

// send from chainA to chainB
msg := types.NewMsgTransfer(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, coinToSendToB, suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), timeoutHeight, 0)
msg := types.NewMsgTransfer(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, coinToSendToB, suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), timeoutHeight, 0, nil)
res, err := suite.chainA.SendMsgs(msg)
suite.Require().NoError(err) // message committed

Expand All @@ -80,7 +80,7 @@ func (suite *TransferTestSuite) TestHandleMsgTransfer() {
suite.coordinator.Setup(pathBtoC)

// send from chainB to chainC
msg = types.NewMsgTransfer(pathBtoC.EndpointA.ChannelConfig.PortID, pathBtoC.EndpointA.ChannelID, coinSentFromAToB, suite.chainB.SenderAccount.GetAddress().String(), suite.chainC.SenderAccount.GetAddress().String(), timeoutHeight, 0)
msg = types.NewMsgTransfer(pathBtoC.EndpointA.ChannelConfig.PortID, pathBtoC.EndpointA.ChannelID, coinSentFromAToB, suite.chainB.SenderAccount.GetAddress().String(), suite.chainC.SenderAccount.GetAddress().String(), timeoutHeight, 0, nil)
res, err = suite.chainB.SendMsgs(msg)
suite.Require().NoError(err) // message committed

Expand All @@ -104,7 +104,7 @@ func (suite *TransferTestSuite) TestHandleMsgTransfer() {
suite.Require().Zero(balance.Amount.Int64())

// send from chainC back to chainB
msg = types.NewMsgTransfer(pathBtoC.EndpointB.ChannelConfig.PortID, pathBtoC.EndpointB.ChannelID, coinSentFromBToC, suite.chainC.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), timeoutHeight, 0)
msg = types.NewMsgTransfer(pathBtoC.EndpointB.ChannelConfig.PortID, pathBtoC.EndpointB.ChannelID, coinSentFromBToC, suite.chainC.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), timeoutHeight, 0, nil)
res, err = suite.chainC.SendMsgs(msg)
suite.Require().NoError(err) // message committed

Expand Down
1 change: 1 addition & 0 deletions modules/apps/transfer/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ const (
AttributeKeyAck = "acknowledgement"
AttributeKeyAckError = "error"
AttributeKeyTraceHash = "trace_hash"
AttributeKeyMetadata = "amount"
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
)
2 changes: 2 additions & 0 deletions modules/apps/transfer/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func NewMsgTransfer(
sourcePort, sourceChannel string,
token sdk.Coin, sender, receiver string,
timeoutHeight clienttypes.Height, timeoutTimestamp uint64,
metadata []byte,
) *MsgTransfer {
return &MsgTransfer{
SourcePort: sourcePort,
Expand All @@ -31,6 +32,7 @@ func NewMsgTransfer(
Receiver: receiver,
TimeoutHeight: timeoutHeight,
TimeoutTimestamp: timeoutTimestamp,
Metadata: metadata,
}
}

Expand Down
36 changes: 18 additions & 18 deletions modules/apps/transfer/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@ var (

// TestMsgTransferRoute tests Route for MsgTransfer
func TestMsgTransferRoute(t *testing.T) {
msg := NewMsgTransfer(validPort, validChannel, coin, addr1, addr2, timeoutHeight, 0)
msg := NewMsgTransfer(validPort, validChannel, coin, addr1, addr2, timeoutHeight, 0, nil)

require.Equal(t, RouterKey, msg.Route())
}

// TestMsgTransferType tests Type for MsgTransfer
func TestMsgTransferType(t *testing.T) {
msg := NewMsgTransfer(validPort, validChannel, coin, addr1, addr2, timeoutHeight, 0)
msg := NewMsgTransfer(validPort, validChannel, coin, addr1, addr2, timeoutHeight, 0, nil)

require.Equal(t, "transfer", msg.Type())
}

func TestMsgTransferGetSignBytes(t *testing.T) {
msg := NewMsgTransfer(validPort, validChannel, coin, addr1, addr2, timeoutHeight, 0)
msg := NewMsgTransfer(validPort, validChannel, coin, addr1, addr2, timeoutHeight, 0, nil)
expected := fmt.Sprintf(`{"type":"cosmos-sdk/MsgTransfer","value":{"receiver":"%s","sender":"%s","source_channel":"testchannel","source_port":"testportid","timeout_height":{"revision_height":"10"},"token":{"amount":"100","denom":"atom"}}}`, addr2, addr1)
require.NotPanics(t, func() {
res := msg.GetSignBytes()
Expand All @@ -69,20 +69,20 @@ func TestMsgTransferValidation(t *testing.T) {
msg *MsgTransfer
expPass bool
}{
{"valid msg with base denom", NewMsgTransfer(validPort, validChannel, coin, addr1, addr2, timeoutHeight, 0), true},
{"valid msg with trace hash", NewMsgTransfer(validPort, validChannel, ibcCoin, addr1, addr2, timeoutHeight, 0), true},
{"invalid ibc denom", NewMsgTransfer(validPort, validChannel, invalidIBCCoin, addr1, addr2, timeoutHeight, 0), false},
{"too short port id", NewMsgTransfer(invalidShortPort, validChannel, coin, addr1, addr2, timeoutHeight, 0), false},
{"too long port id", NewMsgTransfer(invalidLongPort, validChannel, coin, addr1, addr2, timeoutHeight, 0), false},
{"port id contains non-alpha", NewMsgTransfer(invalidPort, validChannel, coin, addr1, addr2, timeoutHeight, 0), false},
{"too short channel id", NewMsgTransfer(validPort, invalidShortChannel, coin, addr1, addr2, timeoutHeight, 0), false},
{"too long channel id", NewMsgTransfer(validPort, invalidLongChannel, coin, addr1, addr2, timeoutHeight, 0), false},
{"channel id contains non-alpha", NewMsgTransfer(validPort, invalidChannel, coin, addr1, addr2, timeoutHeight, 0), false},
{"invalid denom", NewMsgTransfer(validPort, validChannel, invalidDenomCoin, addr1, addr2, timeoutHeight, 0), false},
{"zero coin", NewMsgTransfer(validPort, validChannel, zeroCoin, addr1, addr2, timeoutHeight, 0), false},
{"missing sender address", NewMsgTransfer(validPort, validChannel, coin, emptyAddr, addr2, timeoutHeight, 0), false},
{"missing recipient address", NewMsgTransfer(validPort, validChannel, coin, addr1, "", timeoutHeight, 0), false},
{"empty coin", NewMsgTransfer(validPort, validChannel, sdk.Coin{}, addr1, addr2, timeoutHeight, 0), false},
{"valid msg with base denom", NewMsgTransfer(validPort, validChannel, coin, addr1, addr2, timeoutHeight, 0, nil), true},
{"valid msg with trace hash", NewMsgTransfer(validPort, validChannel, ibcCoin, addr1, addr2, timeoutHeight, 0, nil), true},
{"invalid ibc denom", NewMsgTransfer(validPort, validChannel, invalidIBCCoin, addr1, addr2, timeoutHeight, 0, nil), false},
{"too short port id", NewMsgTransfer(invalidShortPort, validChannel, coin, addr1, addr2, timeoutHeight, 0, nil), false},
{"too long port id", NewMsgTransfer(invalidLongPort, validChannel, coin, addr1, addr2, timeoutHeight, 0, nil), false},
{"port id contains non-alpha", NewMsgTransfer(invalidPort, validChannel, coin, addr1, addr2, timeoutHeight, 0, nil), false},
{"too short channel id", NewMsgTransfer(validPort, invalidShortChannel, coin, addr1, addr2, timeoutHeight, 0, nil), false},
{"too long channel id", NewMsgTransfer(validPort, invalidLongChannel, coin, addr1, addr2, timeoutHeight, 0, nil), false},
{"channel id contains non-alpha", NewMsgTransfer(validPort, invalidChannel, coin, addr1, addr2, timeoutHeight, 0, nil), false},
{"invalid denom", NewMsgTransfer(validPort, validChannel, invalidDenomCoin, addr1, addr2, timeoutHeight, 0, nil), false},
{"zero coin", NewMsgTransfer(validPort, validChannel, zeroCoin, addr1, addr2, timeoutHeight, 0, nil), false},
{"missing sender address", NewMsgTransfer(validPort, validChannel, coin, emptyAddr, addr2, timeoutHeight, 0, nil), false},
{"missing recipient address", NewMsgTransfer(validPort, validChannel, coin, addr1, "", timeoutHeight, 0, nil), false},
{"empty coin", NewMsgTransfer(validPort, validChannel, sdk.Coin{}, addr1, addr2, timeoutHeight, 0, nil), false},
}

for i, tc := range testCases {
Expand All @@ -99,7 +99,7 @@ func TestMsgTransferValidation(t *testing.T) {
func TestMsgTransferGetSigners(t *testing.T) {
addr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address())

msg := NewMsgTransfer(validPort, validChannel, coin, addr.String(), addr2, timeoutHeight, 0)
msg := NewMsgTransfer(validPort, validChannel, coin, addr.String(), addr2, timeoutHeight, 0, nil)
res := msg.GetSigners()

require.Equal(t, []sdk.AccAddress{addr}, res)
Expand Down
14 changes: 14 additions & 0 deletions modules/apps/transfer/types/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ func NewFungibleTokenPacketData(
}
}

func NewFungibleTokenPacketDataWithMetadata(
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
nicolaslara marked this conversation as resolved.
Show resolved Hide resolved
denom string, amount string,
sender, receiver string,
metadata []byte,
) FungibleTokenPacketData {
return FungibleTokenPacketData{
Denom: denom,
Amount: amount,
Sender: sender,
Receiver: receiver,
Metadata: metadata,
}
}

// ValidateBasic is used for validating the token transfer.
// NOTE: The addresses formats are not validated as the sender and recipient can have different
// formats defined by their corresponding chains that are not known to IBC.
Expand Down
Loading