Add length caps for governance proposal titles and descriptions (#3434)
This commit is contained in:
parent
14dcaa6458
commit
172a4510c7
|
@ -45,6 +45,7 @@ IMPROVEMENTS
|
||||||
* Gaia
|
* Gaia
|
||||||
* [\#3418](https://github.com/cosmos/cosmos-sdk/issues/3418) Add vesting account
|
* [\#3418](https://github.com/cosmos/cosmos-sdk/issues/3418) Add vesting account
|
||||||
genesis validation checks to `GaiaValidateGenesisState`.
|
genesis validation checks to `GaiaValidateGenesisState`.
|
||||||
|
* [\#3420](https://github.com/cosmos/cosmos-sdk/issues/3420) Added maximum length to governance proposal descriptions and titles
|
||||||
|
|
||||||
* SDK
|
* SDK
|
||||||
* \#3435 Test that store implementations do not allow nil values
|
* \#3435 Test that store implementations do not allow nil values
|
||||||
|
|
|
@ -46,12 +46,12 @@ func ErrAddressNotStaked(codespace sdk.CodespaceType, address sdk.AccAddress) sd
|
||||||
return sdk.NewError(codespace, CodeAddressNotStaked, fmt.Sprintf("Address %s is not staked and is thus ineligible to vote", address))
|
return sdk.NewError(codespace, CodeAddressNotStaked, fmt.Sprintf("Address %s is not staked and is thus ineligible to vote", address))
|
||||||
}
|
}
|
||||||
|
|
||||||
func ErrInvalidTitle(codespace sdk.CodespaceType, title string) sdk.Error {
|
func ErrInvalidTitle(codespace sdk.CodespaceType, errorMsg string) sdk.Error {
|
||||||
return sdk.NewError(codespace, CodeInvalidTitle, fmt.Sprintf("Proposal Title '%s' is not valid", title))
|
return sdk.NewError(codespace, CodeInvalidTitle, errorMsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ErrInvalidDescription(codespace sdk.CodespaceType, description string) sdk.Error {
|
func ErrInvalidDescription(codespace sdk.CodespaceType, errorMsg string) sdk.Error {
|
||||||
return sdk.NewError(codespace, CodeInvalidDescription, fmt.Sprintf("Proposal Desciption '%s' is not valid", description))
|
return sdk.NewError(codespace, CodeInvalidDescription, errorMsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ErrInvalidProposalType(codespace sdk.CodespaceType, proposalType ProposalKind) sdk.Error {
|
func ErrInvalidProposalType(codespace sdk.CodespaceType, proposalType ProposalKind) sdk.Error {
|
||||||
|
|
|
@ -11,6 +11,9 @@ const (
|
||||||
TypeMsgDeposit = "deposit"
|
TypeMsgDeposit = "deposit"
|
||||||
TypeMsgVote = "vote"
|
TypeMsgVote = "vote"
|
||||||
TypeMsgSubmitProposal = "submit_proposal"
|
TypeMsgSubmitProposal = "submit_proposal"
|
||||||
|
|
||||||
|
MaxDescriptionLength int = 5000
|
||||||
|
MaxTitleLength int = 140
|
||||||
)
|
)
|
||||||
|
|
||||||
var _, _, _ sdk.Msg = MsgSubmitProposal{}, MsgDeposit{}, MsgVote{}
|
var _, _, _ sdk.Msg = MsgSubmitProposal{}, MsgDeposit{}, MsgVote{}
|
||||||
|
@ -42,10 +45,16 @@ func (msg MsgSubmitProposal) Type() string { return TypeMsgSubmitProposal }
|
||||||
// Implements Msg.
|
// Implements Msg.
|
||||||
func (msg MsgSubmitProposal) ValidateBasic() sdk.Error {
|
func (msg MsgSubmitProposal) ValidateBasic() sdk.Error {
|
||||||
if len(msg.Title) == 0 {
|
if len(msg.Title) == 0 {
|
||||||
return ErrInvalidTitle(DefaultCodespace, msg.Title) // TODO: Proper Error
|
return ErrInvalidTitle(DefaultCodespace, "No title present in proposal")
|
||||||
|
}
|
||||||
|
if len(msg.Title) > MaxTitleLength {
|
||||||
|
return ErrInvalidTitle(DefaultCodespace, fmt.Sprintf("Proposal title is longer than max length of %d", MaxTitleLength))
|
||||||
}
|
}
|
||||||
if len(msg.Description) == 0 {
|
if len(msg.Description) == 0 {
|
||||||
return ErrInvalidDescription(DefaultCodespace, msg.Description) // TODO: Proper Error
|
return ErrInvalidDescription(DefaultCodespace, "No description present in proposal")
|
||||||
|
}
|
||||||
|
if len(msg.Description) > MaxDescriptionLength {
|
||||||
|
return ErrInvalidDescription(DefaultCodespace, fmt.Sprintf("Proposal description is longer than max length of %d", MaxDescriptionLength))
|
||||||
}
|
}
|
||||||
if !validProposalType(msg.ProposalType) {
|
if !validProposalType(msg.ProposalType) {
|
||||||
return ErrInvalidProposalType(DefaultCodespace, msg.ProposalType)
|
return ErrInvalidProposalType(DefaultCodespace, msg.ProposalType)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package gov
|
package gov
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -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, 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], coinsZero, true},
|
||||||
{"Test Proposal", "the purpose of this proposal is to test", ProposalTypeText, addrs[0], coinsMulti, 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 {
|
for i, tc := range tests {
|
||||||
|
|
Loading…
Reference in New Issue