Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Fix missing ICA controller configuration [#257](https://github.com/atomone-hub/atomone/pull/257)
- Fix wrapper converters for `x/gov` [#276](https://github.com/atomone-hub/atomone/pull/276)
- Add min-stake filtering for cosmos-sdk votes in the gov ante handler [#279](https://github.com/atomone-hub/atomone/pull/279)
- Missing `MsgAnnotateProposal` annotation length validation [#307](https://github.com/atomone-hub/atomone/pull/307)

### DEPENDENCIES

Expand Down
9 changes: 9 additions & 0 deletions x/coredaos/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

const (
MaxAnnotationLength = 1000
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it enough?
I know it's simpler this way, but also maybe a constant is not ideal and should be a param instead. Just thinking out loud here, thoughts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Most length limits are constants, so I did the same here. Do you think it is different for a proposal annotation ?

)

var _, _, _, _, _ sdk.Msg = &MsgAnnotateProposal{}, &MsgEndorseProposal{}, &MsgExtendVotingPeriod{}, &MsgVetoProposal{}, &MsgUpdateParams{}

// NewMsgAnnotateProposal creates a new MsgAnnotateProposal instance
Expand Down Expand Up @@ -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
}

Expand Down
5 changes: 4 additions & 1 deletion x/coredaos/types/msgs_test.go
Original file line number Diff line number Diff line change
@@ -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{
Expand All @@ -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 {
Expand Down
Loading