Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 8 additions & 4 deletions modules/apps/transfer/types/forwarding.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ func (fi Forwarding) Validate() error {
return errorsmod.Wrapf(ErrInvalidForwarding, "number of hops in forwarding path cannot exceed %d", MaximumNumberOfForwardingHops)
}

if len(fi.Memo) > MaximumMemoLength {
return errorsmod.Wrapf(ErrInvalidMemo, "memo length cannot exceed %d", MaximumMemoLength)
}

if len(fi.Hops) == 0 && fi.Memo != "" {
return errorsmod.Wrap(ErrInvalidForwarding, "memo specified when forwarding hops is empty")
}

for _, hop := range fi.Hops {
if err := host.PortIdentifierValidator(hop.PortId); err != nil {
return errorsmod.Wrapf(err, "invalid source port ID %s", hop.PortId)
Expand All @@ -31,9 +39,5 @@ func (fi Forwarding) Validate() error {
}
}

if len(fi.Memo) > MaximumMemoLength {
return errorsmod.Wrapf(ErrInvalidMemo, "memo length cannot exceed %d", MaximumMemoLength)
}

return nil
}
5 changes: 5 additions & 0 deletions modules/apps/transfer/types/forwarding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ func TestForwarding_Validate(t *testing.T) {
types.NewForwarding(ibctesting.GenerateString(types.MaximumMemoLength+1), validHop),
types.ErrInvalidMemo,
},
{
"invalid forwarding with empty hops and specified memo",
types.NewForwarding("memo"),
types.ErrInvalidForwarding,
},
{
"invalid forwarding with too short hop port ID",
types.NewForwarding(
Expand Down