diff --git a/x/coredaos/types/msgs.go b/x/coredaos/types/msgs.go index c0f226e7..7e8d71a9 100644 --- a/x/coredaos/types/msgs.go +++ b/x/coredaos/types/msgs.go @@ -7,6 +7,10 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) +const ( + MaxAnnotationLength = 1000 +) + var _, _, _, _, _ sdk.Msg = &MsgAnnotateProposal{}, &MsgEndorseProposal{}, &MsgExtendVotingPeriod{}, &MsgVetoProposal{}, &MsgUpdateParams{} // NewMsgAnnotateProposal creates a new MsgAnnotateProposal instance @@ -36,6 +40,11 @@ func (msg *MsgAnnotateProposal) ValidateBasic() error { if len(msg.Annotation) == 0 { return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "annotation cannot be empty") } + if len(msg.Annotation) > MaxAnnotationLength { + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, + "invalid annotation length; got: %d, max: %d", len(msg.Annotation), MaxAnnotationLength, + ) + } return nil } diff --git a/x/coredaos/types/msgs_test.go b/x/coredaos/types/msgs_test.go index 7e253e0d..83ef1c5c 100644 --- a/x/coredaos/types/msgs_test.go +++ b/x/coredaos/types/msgs_test.go @@ -1,11 +1,13 @@ package types_test import ( + "strings" "testing" "github.com/atomone-hub/atomone/x/coredaos/types" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" ) var addrs = []sdk.AccAddress{ @@ -22,6 +24,7 @@ func TestMsgAnnotateProposal_ValidateBasic(t *testing.T) { }{ {sdk.AccAddress{}, 0, "annotation", false}, {addrs[0], 0, "", false}, + {addrs[0], 0, strings.Repeat("x", 3001), false}, {addrs[0], 0, "annotation", true}, } for i, tc := range tests {