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

R4R: Add length caps for governance proposal titles and descriptions #3434

Merged
merged 3 commits into from
Jan 29, 2019
Merged
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 PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ IMPROVEMENTS
* Gaia
* [\#3418](https://github.com/cosmos/cosmos-sdk/issues/3418) Add vesting account
genesis validation checks to `GaiaValidateGenesisState`.
* [\#3420](https://github.com/cosmos/cosmos-sdk/issues/3420) Added maximum length to governance proposal descriptions and titles

* SDK

Expand Down
7 changes: 5 additions & 2 deletions x/gov/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const (
TypeMsgDeposit = "deposit"
TypeMsgVote = "vote"
TypeMsgSubmitProposal = "submit_proposal"

MaxDescriptionLength int = 5000
MaxTitleLength int = 140
)

var _, _, _ sdk.Msg = MsgSubmitProposal{}, MsgDeposit{}, MsgVote{}
Expand Down Expand Up @@ -41,10 +44,10 @@ func (msg MsgSubmitProposal) Type() string { return TypeMsgSubmitProposal }

// Implements Msg.
func (msg MsgSubmitProposal) ValidateBasic() sdk.Error {
if len(msg.Title) == 0 {
if len(msg.Title) == 0 || len(msg.Title) > MaxTitleLength {
sunnya97 marked this conversation as resolved.
Show resolved Hide resolved
sunnya97 marked this conversation as resolved.
Show resolved Hide resolved
return ErrInvalidTitle(DefaultCodespace, msg.Title) // TODO: Proper Error
}
if len(msg.Description) == 0 {
if len(msg.Description) == 0 || len(msg.Description) > MaxDescriptionLength {
return ErrInvalidDescription(DefaultCodespace, msg.Description) // TODO: Proper Error
}
if !validProposalType(msg.ProposalType) {
Expand Down
3 changes: 3 additions & 0 deletions x/gov/msgs_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gov

import (
"strings"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -40,6 +41,8 @@ func TestMsgSubmitProposal(t *testing.T) {
{"Test Proposal", "the purpose of this proposal is to test", ProposalTypeText, sdk.AccAddress{}, coinsPos, false},
{"Test Proposal", "the purpose of this proposal is to test", ProposalTypeText, addrs[0], coinsZero, true},
{"Test Proposal", "the purpose of this proposal is to test", ProposalTypeText, addrs[0], coinsMulti, true},
{strings.Repeat("#", MaxTitleLength*2), "the purpose of this proposal is to test", ProposalTypeText, addrs[0], coinsMulti, false},
{"Test Proposal", strings.Repeat("#", MaxDescriptionLength*2), ProposalTypeText, addrs[0], coinsMulti, false},
}

for i, tc := range tests {
Expand Down