Skip to content

Commit

Permalink
feat!: make gov proposals with not sdk.Msgs invalid (#315)
Browse files Browse the repository at this point in the history
* feat!: make proposals with no sdk.Msgs invalid

* docs

Co-authored-by: Rootul P <rootulp@gmail.com>

* error msg

Co-authored-by: Rootul P <rootulp@gmail.com>

* docs: add diff in the spec

---------

Co-authored-by: Rootul P <rootulp@gmail.com>
  • Loading branch information
evan-forbes and rootulp authored May 4, 2023
1 parent 63bf627 commit 2bae88b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions x/gov/spec/03_messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ must be registered in the app's `MsgServiceRouter`. Each of these messages must
have one signer, namely the gov module account. And finally, the metadata length
must not be larger than the `maxMetadataLen` config passed into the gov keeper.

NOTE DIFF FROM UPSTREAM: All proposals must have at least one `sdk.Msg` in the `messages` field.

**State modifications:**

* Generate new `proposalID`
Expand Down
6 changes: 3 additions & 3 deletions x/gov/types/v1/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ func (m MsgSubmitProposal) ValidateBasic() error {
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, deposit.String())
}

// Check that either metadata or Msgs length is non nil.
if len(m.Messages) == 0 && len(m.Metadata) == 0 {
return sdkerrors.Wrap(types.ErrNoProposalMsgs, "either metadata or Msgs length must be non-nil")
// Check if no Messages are proposed
if len(m.Messages) == 0 {
return sdkerrors.Wrap(types.ErrNoProposalMsgs, "Msgs length must be non-zero")
}

msgs, err := m.GetMsgs()
Expand Down
4 changes: 2 additions & 2 deletions x/gov/types/v1/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/stretchr/testify/require"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/gov/types/v1"
v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
)

Expand Down Expand Up @@ -151,7 +151,7 @@ func TestMsgSubmitProposal_ValidateBasic(t *testing.T) {
{"invalid addr", "", coinsPos, []sdk.Msg{msg1}, metadata, true},
{"empty msgs and metadata", addrs[0].String(), coinsPos, nil, "", true},
{"invalid msg", addrs[0].String(), coinsPos, []sdk.Msg{msg1, msg2}, metadata, true},
{"valid with no Msg", addrs[0].String(), coinsPos, nil, metadata, false},
{"invalid with no Msg", addrs[0].String(), coinsPos, nil, metadata, true},
{"valid with no metadata", addrs[0].String(), coinsPos, []sdk.Msg{msg1}, "", false},
{"valid with everything", addrs[0].String(), coinsPos, []sdk.Msg{msg1}, metadata, false},
}
Expand Down

0 comments on commit 2bae88b

Please sign in to comment.