Skip to content

Commit

Permalink
chore: x/gov v1 Completeness audit (#11567)
Browse files Browse the repository at this point in the history
## Description

Closes: #11086



---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed 
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
  • Loading branch information
blushi authored Apr 8, 2022
1 parent 47d7477 commit eb607ae
Show file tree
Hide file tree
Showing 14 changed files with 848 additions and 573 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [\#9780](https://github.com/cosmos/cosmos-sdk/pull/9780) Use sigs.k8s.io for yaml, which might lead to minor YAML output changes
* [\#10625](https://github.com/cosmos/cosmos-sdk/pull/10625) Rename `--fee-account` CLI flag to `--fee-granter`
* [\#10684](https://github.com/cosmos/cosmos-sdk/pull/10684) Rename `edit-validator` command's `--moniker` flag to `--new-moniker`
* [\#11116](https://github.com/cosmos/cosmos-sdk/pull/11116) `software-upgrade` and `cancel-software-upgrade` gov proposal commands have changed to `legacy-software-upgrade` and `legacy-cancel-software-upgrade`.
* (authz)[\#11060](https://github.com/cosmos/cosmos-sdk/pull/11060) Changed the default value of the `--expiration` `tx grant` CLI Flag: was now + 1year, update: null (no expire date).

### Improvements
Expand Down
6 changes: 0 additions & 6 deletions x/gov/client/cli/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ func parseSubmitLegacyProposalFlags(fs *pflag.FlagSet) (*legacyProposal, error)

if proposalFile == "" {
proposalType, _ := fs.GetString(FlagProposalType)
title, _ := fs.GetString(FlagTitle)
description, _ := fs.GetString(FlagDescription)
if proposalType == "" && title == "" && description == "" {
return nil, fmt.Errorf("one of the --proposal or (--title, --description and --type) flags are required")
}

proposal.Title, _ = fs.GetString(FlagTitle)
proposal.Description, _ = fs.GetString(FlagDescription)
proposal.Type = govutils.NormalizeProposalType(proposalType)
Expand Down
62 changes: 51 additions & 11 deletions x/gov/client/cli/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,57 @@ func TestParseSubmitLegacyProposalFlags(t *testing.T) {

// no --proposal, only flags
fs.Set(FlagProposal, "")
fs.Set(FlagTitle, proposal1.Title)
fs.Set(FlagDescription, proposal1.Description)
fs.Set(FlagProposalType, proposal1.Type)
fs.Set(FlagDeposit, proposal1.Deposit)
proposal2, err := parseSubmitLegacyProposalFlags(fs)

require.Nil(t, err, "unexpected error")
require.Equal(t, proposal1.Title, proposal2.Title)
require.Equal(t, proposal1.Description, proposal2.Description)
require.Equal(t, proposal1.Type, proposal2.Type)
require.Equal(t, proposal1.Deposit, proposal2.Deposit)
flagTestCases := map[string]struct {
pTitle string
pDescription string
pType string
expErr bool
errMsg string
}{
"valid flags": {
pTitle: proposal1.Title,
pDescription: proposal1.Description,
pType: proposal1.Type,
},
"empty type": {
pTitle: proposal1.Title,
pDescription: proposal1.Description,
expErr: true,
errMsg: "proposal type is required",
},
"empty title": {
pDescription: proposal1.Description,
pType: proposal1.Type,
expErr: true,
errMsg: "proposal title is required",
},
"empty description": {
pTitle: proposal1.Title,
pType: proposal1.Type,
expErr: true,
errMsg: "proposal description is required",
},
}
for name, tc := range flagTestCases {
t.Run(name, func(t *testing.T) {
fs.Set(FlagTitle, tc.pTitle)
fs.Set(FlagDescription, tc.pDescription)
fs.Set(FlagProposalType, tc.pType)
fs.Set(FlagDeposit, proposal1.Deposit)
proposal2, err := parseSubmitLegacyProposalFlags(fs)

if tc.expErr {
require.Error(t, err)
require.Contains(t, err.Error(), tc.errMsg)
} else {
require.NoError(t, err)
require.Equal(t, proposal1.Title, proposal2.Title)
require.Equal(t, proposal1.Description, proposal2.Description)
require.Equal(t, proposal1.Type, proposal2.Type)
require.Equal(t, proposal1.Deposit, proposal2.Deposit)
}
})
}

err = okJSON.Close()
require.Nil(t, err, "unexpected error")
Expand Down
12 changes: 6 additions & 6 deletions x/gov/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const (
FlagProposal = "proposal"
)

// ProposalFlags defines the core required fields of a proposal. It is used to
// ProposalFlags defines the core required fields of a legacy proposal. It is used to
// verify that these values are not provided in conjunction with a JSON proposal
// file.
var ProposalFlags = []string{
Expand All @@ -47,7 +47,7 @@ var ProposalFlags = []string{

// NewTxCmd returns the transaction commands for this module
// governance ModuleClient is slightly different from other ModuleClients in that
// it contains a slice of "proposal" child commands. These commands are respective
// it contains a slice of legacy "proposal" child commands. These commands are respective
// to the proposal type handlers that are implemented in other modules but are mounted
// under the governance CLI (eg. parameter change proposals).
func NewTxCmd(legacyPropCmds []*cobra.Command) *cobra.Command {
Expand Down Expand Up @@ -81,12 +81,12 @@ func NewTxCmd(legacyPropCmds []*cobra.Command) *cobra.Command {
// NewCmdSubmitProposal implements submitting a proposal transaction command.
func NewCmdSubmitProposal() *cobra.Command {
cmd := &cobra.Command{
Use: "submit-proposal",
Short: "Submit a proposal along with some messages and metadata",
Use: "submit-proposal [path/to/proposal.json]",
Short: "Submit a proposal along with some messages, metadata and deposit",
Args: cobra.ExactArgs(1),
Long: strings.TrimSpace(
fmt.Sprintf(`Submit a proposal along with some messages and metadata.
Messages, metadata and deposit are defined in a JSON file.
fmt.Sprintf(`Submit a proposal along with some messages, metadata and deposit.
They should be defined in a JSON file.
Example:
$ %s tx gov submit-proposal path/to/proposal.json
Expand Down
14 changes: 0 additions & 14 deletions x/gov/client/testutil/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,6 @@ var commonArgs = []string{
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(10))).String()),
}

// MsgSubmitProposal creates a tx for submit proposal
func MsgSubmitProposal(clientCtx client.Context, from, title, description, proposalType string, extraArgs ...string) (testutil.BufferWriter, error) {
args := append([]string{
fmt.Sprintf("--%s=%s", govcli.FlagTitle, title),
fmt.Sprintf("--%s=%s", govcli.FlagDescription, description),
fmt.Sprintf("--%s=%s", govcli.FlagProposalType, proposalType),
fmt.Sprintf("--%s=%s", flags.FlagFrom, from),
}, commonArgs...)

args = append(args, extraArgs...)

return clitestutil.ExecTestCLICmd(clientCtx, govcli.NewCmdSubmitProposal(), args)
}

// MsgSubmitLegacyProposal creates a tx for submit legacy proposal
func MsgSubmitLegacyProposal(clientCtx client.Context, from, title, description, proposalType string, extraArgs ...string) (testutil.BufferWriter, error) {
args := append([]string{
Expand Down
Loading

0 comments on commit eb607ae

Please sign in to comment.