Skip to content

Commit

Permalink
add memo length validation
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-axner committed Oct 12, 2021
1 parent 17b6cda commit d25ea67
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions modules/apps/27-interchain-accounts/types/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

const MaxMemoCharLength = 256

// ValidateBasic performs basic validation of the interchain account packet data.
// The memo may be empty.
func (iapd InterchainAccountPacketData) ValidateBasic() error {
if iapd.Data == nil {
return sdkerrors.Wrap(ErrInvalidOutgoingData, "packet data cannot be empty")
}

if len(iapd.Memo) > MaxMemoCharLength {
return sdkerrors.Wrapf(ErrInvalidOutgoingData, "packet data memo cannot be greater than %d characters", MaxMemoCharLength)
}
// TODO: add type validation when data type enum supports unspecified type

return nil
Expand Down
11 changes: 11 additions & 0 deletions modules/apps/27-interchain-accounts/types/packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types"
)

var largeMemo = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum"

func (suite *TypesTestSuite) TestValidateBasic() {
testCases := []struct {
name string
Expand Down Expand Up @@ -36,6 +38,15 @@ func (suite *TypesTestSuite) TestValidateBasic() {
},
false,
},
{
"memo too large",
types.InterchainAccountPacketData{
Type: types.EXECUTE_TX,
Data: []byte("data"),
Memo: largeMemo,
},
false,
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit d25ea67

Please sign in to comment.