From 36330814630291bd29958171d0ecc1e7ac62f9ea Mon Sep 17 00:00:00 2001 From: MD Aleem <72057206+aleem1314@users.noreply.github.com> Date: Tue, 1 Mar 2022 02:18:04 +0530 Subject: [PATCH] fix(cli): `submit-legacy-proposal`: return propoer error if no flag is provided (#11287) ## Description Closes: #10624 --- ### 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... - [ ] 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 - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] 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) --- CHANGELOG.md | 1 + x/gov/client/cli/parse.go | 28 ++++++++++++++++++++++++++++ x/gov/client/cli/tx.go | 8 ++++---- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58d73ee798..7d30f99fb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -173,6 +173,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (types) [\#11004](https://github.com/cosmos/cosmos-sdk/pull/11004) Added mutable versions of many of the sdk.Dec types operations. This improves performance when used by avoiding reallocating a new bigint for each operation. * (x/auth) [\#10880](https://github.com/cosmos/cosmos-sdk/pull/10880) Added a new query to the tx query service that returns a block with transactions fully decoded. * (types) [\#11200](https://github.com/cosmos/cosmos-sdk/pull/11200) Added `Min()` and `Max()` operations on sdk.Coins. +* (gov) [\#11287](https://github.com/cosmos/cosmos-sdk/pull/11287) Fix error message when no flags are provided while executing `submit-legacy-proposal` transaction. ### Bug Fixes diff --git a/x/gov/client/cli/parse.go b/x/gov/client/cli/parse.go index 306b4b10dd..91736f9853 100644 --- a/x/gov/client/cli/parse.go +++ b/x/gov/client/cli/parse.go @@ -19,17 +19,41 @@ type legacyProposal struct { Deposit string } +func (p legacyProposal) validate() error { + if p.Type == "" { + return fmt.Errorf("proposal type is required") + } + + if p.Title == "" { + return fmt.Errorf("proposal title is required") + } + + if p.Description == "" { + return fmt.Errorf("proposal description is required") + } + return nil +} + func parseSubmitLegacyProposalFlags(fs *pflag.FlagSet) (*legacyProposal, error) { proposal := &legacyProposal{} proposalFile, _ := fs.GetString(FlagProposal) 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) proposal.Deposit, _ = fs.GetString(FlagDeposit) + if err := proposal.validate(); err != nil { + return nil, err + } + return proposal, nil } @@ -49,6 +73,10 @@ func parseSubmitLegacyProposalFlags(fs *pflag.FlagSet) (*legacyProposal, error) return nil, err } + if err := proposal.validate(); err != nil { + return nil, err + } + return proposal, nil } diff --git a/x/gov/client/cli/tx.go b/x/gov/client/cli/tx.go index 17c3db75e4..d23d717fd9 100644 --- a/x/gov/client/cli/tx.go +++ b/x/gov/client/cli/tx.go @@ -27,10 +27,10 @@ const ( // Deprecated: only used for v1beta1 legacy proposals. FlagProposalType = "type" // Deprecated: only used for v1beta1 legacy proposals. - FlagDeposit = "deposit" - flagVoter = "voter" - flagDepositor = "depositor" - flagStatus = "status" + FlagDeposit = "deposit" + flagVoter = "voter" + flagDepositor = "depositor" + flagStatus = "status" // Deprecated: only used for v1beta1 legacy proposals. FlagProposal = "proposal" )