feat(x/gov): add autocli options for tx (#18036)
This commit is contained in:
parent
c3bc5c82eb
commit
fe99b0c2f8
@ -67,8 +67,9 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
|
||||
### API Breaking Changes
|
||||
|
||||
* (testutil) [#17986](https://github.com/cosmos/cosmos-sdk/pull/17986) `MsgRedelegateExec`, `MsgUnbondExec` has been removed because of AutoCLI migration.
|
||||
* (testutil) [#17868](https://github.com/cosmos/cosmos-sdk/pull/17868) `MsgSendExec` has been removed because of AutoCLI migration.
|
||||
* (x/gov/testutil) [#17986](https://github.com/cosmos/cosmos-sdk/pull/18036) `MsgDeposit` has been removed because of AutoCLI migration.
|
||||
* (x/staking/testutil) [#17986](https://github.com/cosmos/cosmos-sdk/pull/17986) `MsgRedelegateExec`, `MsgUnbondExec` has been removed because of AutoCLI migration.
|
||||
* (x/bank/testutil) [#17868](https://github.com/cosmos/cosmos-sdk/pull/17868) `MsgSendExec` has been removed because of AutoCLI migration.
|
||||
* (x/distribution) [#17657](https://github.com/cosmos/cosmos-sdk/pull/17657) The `FundCommunityPool` and `DistributeFromFeePool` keeper methods are now removed from x/distribution.
|
||||
* (x/distribution) [#17657](https://github.com/cosmos/cosmos-sdk/pull/17657) The distribution module keeper now takes a new argument `PoolKeeper` in addition.
|
||||
* (app) [#17838](https://github.com/cosmos/cosmos-sdk/pull/17838) Params module was removed from simapp and all imports of the params module removed throughout the repo.
|
||||
|
||||
@ -10,6 +10,7 @@ import (
|
||||
"cosmossdk.io/math"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/network"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/client/cli"
|
||||
@ -73,29 +74,29 @@ func (s *DepositTestSuite) TearDownSuite() {
|
||||
|
||||
func (s *DepositTestSuite) TestQueryDepositsWithoutInitialDeposit() {
|
||||
val := s.network.Validators[0]
|
||||
clientCtx := val.ClientCtx
|
||||
|
||||
// submit proposal without initial deposit
|
||||
id := s.submitProposal(val, sdk.NewCoin(s.cfg.BondDenom, math.NewInt(0)), "TestQueryDepositsWithoutInitialDeposit")
|
||||
proposalID := strconv.FormatUint(id, 10)
|
||||
|
||||
// deposit amount
|
||||
depositAmount := sdk.NewCoin(s.cfg.BondDenom, v1.DefaultMinDepositTokens.Add(math.NewInt(50))).String()
|
||||
_, err := govclitestutil.MsgDeposit(clientCtx, val.Address.String(), proposalID, depositAmount)
|
||||
depositAmount := sdk.NewCoin(s.cfg.BondDenom, v1.DefaultMinDepositTokens.Add(math.NewInt(50)))
|
||||
msg := v1.NewMsgDeposit(val.Address, id, sdk.NewCoins(depositAmount))
|
||||
_, err := clitestutil.SubmitTestTx(val.ClientCtx, msg, val.Address, clitestutil.TestTxConfig{})
|
||||
s.Require().NoError(err)
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
|
||||
// query deposit
|
||||
proposalID := strconv.FormatUint(id, 10)
|
||||
deposit := s.queryDeposit(val, proposalID, false, "")
|
||||
s.Require().NotNil(deposit)
|
||||
s.Require().Equal(depositAmount, sdk.Coins(deposit.Deposit.Amount).String())
|
||||
s.Require().Equal(depositAmount.String(), sdk.Coins(deposit.Deposit.Amount).String())
|
||||
|
||||
// query deposits
|
||||
deposits := s.queryDeposits(val, proposalID, false, "")
|
||||
s.Require().NotNil(deposits)
|
||||
s.Require().Len(deposits.Deposits, 1)
|
||||
// verify initial deposit
|
||||
s.Require().Equal(depositAmount, sdk.Coins(deposits.Deposits[0].Amount).String())
|
||||
s.Require().Equal(depositAmount.String(), sdk.Coins(deposits.Deposits[0].Amount).String())
|
||||
}
|
||||
|
||||
func (s *DepositTestSuite) TestQueryDepositsWithInitialDeposit() {
|
||||
|
||||
@ -15,7 +15,6 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/testutil/network"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/client/cli"
|
||||
govclitestutil "github.com/cosmos/cosmos-sdk/x/gov/client/testutil"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
@ -277,269 +276,6 @@ func (s *E2ETestSuite) TestNewCmdSubmitLegacyProposal() {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *E2ETestSuite) TestNewCmdCancelProposal() {
|
||||
val := s.network.Validators[0]
|
||||
val2 := sdk.AccAddress("invalid_acc_addr")
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expectErr bool
|
||||
expectedCode uint32
|
||||
}{
|
||||
{
|
||||
"without proposal id",
|
||||
[]string{
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10))).String()),
|
||||
},
|
||||
true, 0,
|
||||
},
|
||||
{
|
||||
"invalid proposal id",
|
||||
[]string{
|
||||
"asdasd",
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10))).String()),
|
||||
},
|
||||
true, 0,
|
||||
},
|
||||
{
|
||||
"valid proposal-id but invalid proposer",
|
||||
[]string{
|
||||
"4",
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val2),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10))).String()),
|
||||
},
|
||||
true, 0,
|
||||
},
|
||||
{
|
||||
"valid proposer",
|
||||
[]string{
|
||||
"4",
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10))).String()),
|
||||
},
|
||||
false, 0,
|
||||
},
|
||||
{
|
||||
"proposal not exists after cancel",
|
||||
[]string{
|
||||
"4",
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10))).String()),
|
||||
},
|
||||
false, 1,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
var resp sdk.TxResponse
|
||||
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.NewCmdCancelProposal()
|
||||
clientCtx := val.ClientCtx
|
||||
var balRes banktypes.QueryAllBalancesResponse
|
||||
var newBalance banktypes.QueryAllBalancesResponse
|
||||
if !tc.expectErr && tc.expectedCode == 0 {
|
||||
resp, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s", val.APIAddress, val.Address.String()))
|
||||
s.Require().NoError(err)
|
||||
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &balRes)
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
|
||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
|
||||
if tc.expectErr {
|
||||
s.Require().Error(err)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &resp), out.String())
|
||||
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, resp.TxHash, tc.expectedCode))
|
||||
|
||||
if !tc.expectErr && tc.expectedCode == 0 {
|
||||
resp, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s", val.APIAddress, val.Address.String()))
|
||||
s.Require().NoError(err)
|
||||
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &newBalance)
|
||||
s.Require().NoError(err)
|
||||
remainingAmount := v1.DefaultMinDepositTokens.Mul(
|
||||
v1.DefaultProposalCancelRatio.Mul(math.LegacyMustNewDecFromStr("100")).TruncateInt(),
|
||||
).Quo(math.NewIntFromUint64(100))
|
||||
|
||||
// new balance = old balance + remaining amount from proposal deposit - txFee (cancel proposal)
|
||||
txFee := math.NewInt(10)
|
||||
s.Require().True(
|
||||
newBalance.Balances.AmountOf(s.network.Config.BondDenom).Equal(
|
||||
balRes.Balances.AmountOf(s.network.Config.BondDenom).Add(remainingAmount).Sub(txFee),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *E2ETestSuite) TestNewCmdDeposit() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expectErr bool
|
||||
expectedCode uint32
|
||||
}{
|
||||
{
|
||||
"without proposal id",
|
||||
[]string{
|
||||
sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10)).String(), // 10stake
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10))).String()),
|
||||
},
|
||||
true, 0,
|
||||
},
|
||||
{
|
||||
"without deposit amount",
|
||||
[]string{
|
||||
"1",
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10))).String()),
|
||||
},
|
||||
true, 0,
|
||||
},
|
||||
{
|
||||
"deposit on non existing proposal",
|
||||
[]string{
|
||||
"10",
|
||||
sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10)).String(), // 10stake
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10))).String()),
|
||||
},
|
||||
false, 1,
|
||||
},
|
||||
{
|
||||
"deposit on existing proposal",
|
||||
[]string{
|
||||
"1",
|
||||
sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10)).String(), // 10stake
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10))).String()),
|
||||
},
|
||||
false, 0,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
var resp sdk.TxResponse
|
||||
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.NewCmdDeposit()
|
||||
clientCtx := val.ClientCtx
|
||||
|
||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
|
||||
if tc.expectErr {
|
||||
s.Require().Error(err)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
|
||||
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &resp), out.String())
|
||||
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, resp.TxHash, tc.expectedCode))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *E2ETestSuite) TestNewCmdVote() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expectErr bool
|
||||
expectedCode uint32
|
||||
}{
|
||||
{
|
||||
"invalid vote",
|
||||
[]string{},
|
||||
true, 0,
|
||||
},
|
||||
{
|
||||
"vote for invalid proposal",
|
||||
[]string{
|
||||
"10",
|
||||
"yes",
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--metadata=%s", "AQ=="),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10))).String()),
|
||||
},
|
||||
false, 3,
|
||||
},
|
||||
{
|
||||
"valid vote",
|
||||
[]string{
|
||||
"1",
|
||||
"yes",
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10))).String()),
|
||||
},
|
||||
false, 0,
|
||||
},
|
||||
{
|
||||
"valid vote with metadata",
|
||||
[]string{
|
||||
"1",
|
||||
"yes",
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--metadata=%s", "AQ=="),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, math.NewInt(10))).String()),
|
||||
},
|
||||
false, 0,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.NewCmdVote()
|
||||
clientCtx := val.ClientCtx
|
||||
var txResp sdk.TxResponse
|
||||
|
||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
|
||||
|
||||
if tc.expectErr {
|
||||
s.Require().Error(err)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String())
|
||||
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, txResp.TxHash, tc.expectedCode))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *E2ETestSuite) TestNewCmdWeightedVote() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
|
||||
@ -101,12 +101,53 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
|
||||
},
|
||||
Tx: &autocliv1.ServiceCommandDescriptor{
|
||||
Service: govv1.Msg_ServiceDesc.ServiceName,
|
||||
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
|
||||
{
|
||||
RpcMethod: "Deposit",
|
||||
Use: "deposit [proposal-id] [deposit]",
|
||||
Short: "Deposit tokens for an active proposal",
|
||||
Long: fmt.Sprintf(`Submit a deposit for an active proposal. You can find the proposal-id by running "%s query gov proposals"`, version.AppName),
|
||||
Example: fmt.Sprintf(`$ %s tx gov deposit 1 10stake --from mykey`, version.AppName),
|
||||
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
|
||||
{ProtoField: "proposal_id"},
|
||||
{ProtoField: "amount", Varargs: true},
|
||||
},
|
||||
},
|
||||
{
|
||||
RpcMethod: "CancelProposal",
|
||||
Use: "cancel-proposal [proposal-id]",
|
||||
Short: "Cancel governance proposal before the voting period ends. Must be signed by the proposal creator.",
|
||||
Example: fmt.Sprintf(`$ %s tx gov cancel-proposal 1 --from mykey`, version.AppName),
|
||||
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
|
||||
{ProtoField: "proposal_id"},
|
||||
},
|
||||
},
|
||||
{
|
||||
RpcMethod: "Vote",
|
||||
Use: "vote [proposal-id] [option]",
|
||||
Short: "Vote for an active proposal, options: yes/no/no-with-veto/abstain",
|
||||
Long: fmt.Sprintf(`Submit a vote for an active proposal. Use the --metadata to optionally give a reason. You can find the proposal-id by running "%s query gov proposals"`, version.AppName),
|
||||
Example: fmt.Sprintf("$ %s tx gov vote 1 yes --from mykey", version.AppName),
|
||||
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
|
||||
{ProtoField: "proposal_id"},
|
||||
{ProtoField: "option"},
|
||||
},
|
||||
FlagOptions: map[string]*autocliv1.FlagOptions{
|
||||
"metadata": {Name: "metadata", Usage: "Add a description to the vote"},
|
||||
},
|
||||
},
|
||||
{
|
||||
RpcMethod: "UpdateParams",
|
||||
Skip: true, // skipped because authority gated
|
||||
},
|
||||
},
|
||||
// map v1beta1 as a sub-command
|
||||
SubCommands: map[string]*autocliv1.ServiceCommandDescriptor{
|
||||
"v1beta1": {
|
||||
Service: govv1beta1.Msg_ServiceDesc.ServiceName,
|
||||
},
|
||||
},
|
||||
EnhanceCustomCommand: true, // We still have manual commands in gov that we want to keep
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,12 +66,9 @@ func NewTxCmd(legacyPropCmds []*cobra.Command) *cobra.Command {
|
||||
}
|
||||
|
||||
govTxCmd.AddCommand(
|
||||
NewCmdDeposit(),
|
||||
NewCmdVote(),
|
||||
NewCmdWeightedVote(),
|
||||
NewCmdSubmitProposal(),
|
||||
NewCmdDraftProposal(),
|
||||
NewCmdCancelProposal(),
|
||||
|
||||
// Deprecated
|
||||
cmdSubmitLegacyProp,
|
||||
@ -152,42 +149,13 @@ metadata example:
|
||||
return cmd
|
||||
}
|
||||
|
||||
// NewCmdCancelProposal implements submitting a cancel proposal transaction command.
|
||||
func NewCmdCancelProposal() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "cancel-proposal [proposal-id]",
|
||||
Short: "Cancel governance proposal before the voting period ends. Must be signed by the proposal creator.",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Example: fmt.Sprintf(`$ %s tx gov cancel-proposal 1 --from mykey`, version.AppName),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientTxContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// validate that the proposal id is a uint
|
||||
proposalID, err := strconv.ParseUint(args[0], 10, 64)
|
||||
if err != nil {
|
||||
return fmt.Errorf("proposal-id %s not a valid uint, please input a valid proposal-id", args[0])
|
||||
}
|
||||
|
||||
// Get proposer address
|
||||
from := clientCtx.GetFromAddress()
|
||||
msg := v1.NewMsgCancelProposal(proposalID, from.String())
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
},
|
||||
}
|
||||
|
||||
flags.AddTxFlagsToCmd(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// NewCmdSubmitLegacyProposal implements submitting a proposal transaction command.
|
||||
// Deprecated: please use NewCmdSubmitProposal instead.
|
||||
func NewCmdSubmitLegacyProposal() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "submit-legacy-proposal",
|
||||
Short: "Submit a legacy proposal along with an initial deposit",
|
||||
Use: "submit-legacy-proposal",
|
||||
Aliases: []string{"exec-legacy-content"},
|
||||
Short: "Submit a legacy proposal along with an initial deposit",
|
||||
Long: strings.TrimSpace(
|
||||
fmt.Sprintf(`Submit a legacy proposal along with an initial deposit.
|
||||
Proposal title, description, type and deposit can be given directly or through a proposal JSON file.
|
||||
@ -251,114 +219,14 @@ $ %s tx gov submit-legacy-proposal --title="Test Proposal" --description="My awe
|
||||
return cmd
|
||||
}
|
||||
|
||||
// NewCmdDeposit implements depositing tokens for an active proposal.
|
||||
func NewCmdDeposit() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "deposit [proposal-id] [deposit]",
|
||||
Args: cobra.ExactArgs(2),
|
||||
Short: "Deposit tokens for an active proposal",
|
||||
Long: strings.TrimSpace(
|
||||
fmt.Sprintf(`Submit a deposit for an active proposal. You can
|
||||
find the proposal-id by running "%s query gov proposals".
|
||||
|
||||
Example:
|
||||
$ %s tx gov deposit 1 10stake --from mykey
|
||||
`,
|
||||
version.AppName, version.AppName,
|
||||
),
|
||||
),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientTxContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// validate that the proposal id is a uint
|
||||
proposalID, err := strconv.ParseUint(args[0], 10, 64)
|
||||
if err != nil {
|
||||
return fmt.Errorf("proposal-id %s not a valid uint, please input a valid proposal-id", args[0])
|
||||
}
|
||||
|
||||
// Get depositor address
|
||||
from := clientCtx.GetFromAddress()
|
||||
|
||||
// Get amount of coins
|
||||
amount, err := sdk.ParseCoinsNormalized(args[1])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
msg := v1.NewMsgDeposit(from, proposalID, amount)
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
},
|
||||
}
|
||||
|
||||
flags.AddTxFlagsToCmd(cmd)
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// NewCmdVote implements creating a new vote command.
|
||||
func NewCmdVote() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "vote [proposal-id] [option]",
|
||||
Args: cobra.ExactArgs(2),
|
||||
Short: "Vote for an active proposal, options: yes/no/no_with_veto/abstain",
|
||||
Long: strings.TrimSpace(
|
||||
fmt.Sprintf(`Submit a vote for an active proposal. You can
|
||||
find the proposal-id by running "%s query gov proposals".
|
||||
|
||||
Example:
|
||||
$ %s tx gov vote 1 yes --from mykey
|
||||
`,
|
||||
version.AppName, version.AppName,
|
||||
),
|
||||
),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientTxContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Get voting address
|
||||
from := clientCtx.GetFromAddress()
|
||||
|
||||
// validate that the proposal id is a uint
|
||||
proposalID, err := strconv.ParseUint(args[0], 10, 64)
|
||||
if err != nil {
|
||||
return fmt.Errorf("proposal-id %s not a valid int, please input a valid proposal-id", args[0])
|
||||
}
|
||||
|
||||
// Find out which vote option user chose
|
||||
byteVoteOption, err := v1.VoteOptionFromString(govutils.NormalizeVoteOption(args[1]))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
metadata, err := cmd.Flags().GetString(FlagMetadata)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Build vote message and run basic validation
|
||||
msg := v1.NewMsgVote(from, proposalID, byteVoteOption, metadata)
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().String(FlagMetadata, "", "Specify metadata of the vote")
|
||||
flags.AddTxFlagsToCmd(cmd)
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// NewCmdWeightedVote implements creating a new weighted vote command.
|
||||
// TODO(@julienrbrt): remove this once AutoCLI can flatten nested structs.
|
||||
func NewCmdWeightedVote() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "weighted-vote [proposal-id] [weighted-options]",
|
||||
Args: cobra.ExactArgs(2),
|
||||
Short: "Vote for an active proposal, options: yes/no/no_with_veto/abstain",
|
||||
Use: "weighted-vote [proposal-id] [weighted-options]",
|
||||
Aliases: []string{"vote-weighted"},
|
||||
Args: cobra.ExactArgs(2),
|
||||
Short: "Vote for an active proposal, options: yes/no/no-with-veto/abstain",
|
||||
Long: strings.TrimSpace(
|
||||
fmt.Sprintf(`Submit a vote for an active proposal. You can
|
||||
find the proposal-id by running "%s query gov proposals".
|
||||
|
||||
@ -271,149 +271,6 @@ func (s *CLITestSuite) TestNewCmdSubmitLegacyProposal() {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *CLITestSuite) TestNewCmdDeposit() {
|
||||
val := testutil.CreateKeyringAccounts(s.T(), s.kr, 1)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expectErrMsg string
|
||||
}{
|
||||
{
|
||||
"invalid proposal id",
|
||||
[]string{
|
||||
"abc",
|
||||
sdk.NewCoin("stake", sdkmath.NewInt(10)).String(), // 10stake
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val[0].Address.String()),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(10))).String()),
|
||||
},
|
||||
"proposal-id abc not a valid uint, please input a valid proposal-id",
|
||||
},
|
||||
{
|
||||
"without deposit amount",
|
||||
[]string{
|
||||
"1",
|
||||
"invalidCoin",
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val[0].Address.String()),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(10))).String()),
|
||||
},
|
||||
"invalid decimal coin expression: invalidCoin",
|
||||
},
|
||||
{
|
||||
"deposit on a proposal",
|
||||
[]string{
|
||||
"10",
|
||||
sdk.NewCoin("stake", sdkmath.NewInt(10)).String(), // 10stake
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val[0].Address.String()),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(10))).String()),
|
||||
},
|
||||
"",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.NewCmdDeposit()
|
||||
|
||||
out, err := clitestutil.ExecTestCLICmd(s.clientCtx, cmd, tc.args)
|
||||
if tc.expectErrMsg != "" {
|
||||
s.Require().Error(err)
|
||||
s.Require().Contains(err.Error(), tc.expectErrMsg)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
resp := &sdk.TxResponse{}
|
||||
s.Require().NoError(s.clientCtx.Codec.UnmarshalJSON(out.Bytes(), resp), out.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *CLITestSuite) TestNewCmdVote() {
|
||||
val := testutil.CreateKeyringAccounts(s.T(), s.kr, 1)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expectErrMsg string
|
||||
}{
|
||||
{
|
||||
"vote for invalid proposal",
|
||||
[]string{
|
||||
"abc",
|
||||
"yes",
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val[0].Address.String()),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--metadata=%s", "AQ=="),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(10))).String()),
|
||||
},
|
||||
"proposal-id abc not a valid int, please input a valid proposal-id",
|
||||
},
|
||||
{
|
||||
"invalid vote",
|
||||
[]string{
|
||||
"1",
|
||||
"AYE",
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val[0].Address.String()),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(10))).String()),
|
||||
},
|
||||
"'AYE' is not a valid vote option",
|
||||
},
|
||||
{
|
||||
"valid vote",
|
||||
[]string{
|
||||
"1",
|
||||
"yes",
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val[0].Address.String()),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(10))).String()),
|
||||
},
|
||||
"",
|
||||
},
|
||||
{
|
||||
"valid vote with metadata",
|
||||
[]string{
|
||||
"1",
|
||||
"yes",
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val[0].Address.String()),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--metadata=%s", "AQ=="),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(10))).String()),
|
||||
},
|
||||
"",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.NewCmdVote()
|
||||
out, err := clitestutil.ExecTestCLICmd(s.clientCtx, cmd, tc.args)
|
||||
|
||||
if tc.expectErrMsg != "" {
|
||||
s.Require().Error(err)
|
||||
s.Require().Contains(err.Error(), tc.expectErrMsg)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
resp := &sdk.TxResponse{}
|
||||
s.Require().NoError(s.clientCtx.Codec.UnmarshalJSON(out.Bytes(), resp), out.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *CLITestSuite) TestNewCmdWeightedVote() {
|
||||
val := testutil.CreateKeyringAccounts(s.T(), s.kr, 1)
|
||||
|
||||
|
||||
@ -45,16 +45,3 @@ func MsgVote(clientCtx client.Context, from, id, vote string, extraArgs ...strin
|
||||
|
||||
return clitestutil.ExecTestCLICmd(clientCtx, govcli.NewCmdWeightedVote(), args)
|
||||
}
|
||||
|
||||
// MsgDeposit deposits on a proposal
|
||||
func MsgDeposit(clientCtx client.Context, from, id, deposit string, extraArgs ...string) (testutil.BufferWriter, error) {
|
||||
args := append([]string{
|
||||
id,
|
||||
deposit,
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, from),
|
||||
}, commonArgs...)
|
||||
|
||||
args = append(args, extraArgs...)
|
||||
|
||||
return clitestutil.ExecTestCLICmd(clientCtx, govcli.NewCmdDeposit(), args)
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@ func NormalizeVoteOption(option string) string {
|
||||
case "No", "no":
|
||||
return v1beta1.OptionNo.String()
|
||||
|
||||
case "NoWithVeto", "no_with_veto":
|
||||
case "NoWithVeto", "no_with_veto", "no-with-veto":
|
||||
return v1beta1.OptionNoWithVeto.String()
|
||||
|
||||
default:
|
||||
|
||||
@ -21,7 +21,7 @@ const (
|
||||
|
||||
var longAddressError = "address max length is 255"
|
||||
|
||||
func (suite *KeeperTestSuite) TestSubmitProposalReq() {
|
||||
func (suite *KeeperTestSuite) TestMsgSubmitProposal() {
|
||||
suite.reset()
|
||||
govAcct := suite.govKeeper.GetGovernanceAccount(suite.ctx).GetAddress()
|
||||
addrs := suite.addrs
|
||||
@ -253,7 +253,7 @@ func (suite *KeeperTestSuite) TestSubmitProposalReq() {
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *KeeperTestSuite) TestCancelProposalReq() {
|
||||
func (suite *KeeperTestSuite) TestMsgCancelProposal() {
|
||||
govAcct := suite.govKeeper.GetGovernanceAccount(suite.ctx).GetAddress()
|
||||
addrs := suite.addrs
|
||||
proposer := addrs[0]
|
||||
@ -348,7 +348,7 @@ func (suite *KeeperTestSuite) TestCancelProposalReq() {
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *KeeperTestSuite) TestVoteReq() {
|
||||
func (suite *KeeperTestSuite) TestMsgVote() {
|
||||
suite.reset()
|
||||
govAcct := suite.govKeeper.GetGovernanceAccount(suite.ctx).GetAddress()
|
||||
addrs := suite.addrs
|
||||
@ -491,7 +491,7 @@ func (suite *KeeperTestSuite) TestVoteReq() {
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *KeeperTestSuite) TestVoteWeightedReq() {
|
||||
func (suite *KeeperTestSuite) TestMsgVoteWeighted() {
|
||||
suite.reset()
|
||||
govAcct := suite.govKeeper.GetGovernanceAccount(suite.ctx).GetAddress()
|
||||
|
||||
@ -735,7 +735,8 @@ func (suite *KeeperTestSuite) TestVoteWeightedReq() {
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *KeeperTestSuite) TestDepositReq() {
|
||||
func (suite *KeeperTestSuite) TestMsgDeposit() {
|
||||
suite.reset()
|
||||
govAcct := suite.govKeeper.GetGovernanceAccount(suite.ctx).GetAddress()
|
||||
addrs := suite.addrs
|
||||
proposer := addrs[0]
|
||||
|
||||
@ -51,10 +51,11 @@ func NewTxCmd() *cobra.Command {
|
||||
}
|
||||
|
||||
// NewCreateValidatorCmd returns a CLI command handler for creating a MsgCreateValidator transaction.
|
||||
// TODO(@julienrbrt): remove this once AutoCLI can flatten nested structs.
|
||||
func NewCreateValidatorCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "create-validator [path/to/validator.json]",
|
||||
Short: "create new validator initialized with a self-delegation to it",
|
||||
Short: "Create new validator initialized with a self-delegation to it",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Long: `Create a new validator initialized with a self-delegation by submitting a JSON file with the new validator details.`,
|
||||
Example: strings.TrimSpace(
|
||||
@ -114,10 +115,11 @@ where we can get the pubkey using "%s tendermint show-validator"
|
||||
}
|
||||
|
||||
// NewEditValidatorCmd returns a CLI command handler for creating a MsgEditValidator transaction.
|
||||
// TODO(@julienrbrt): remove this once AutoCLI can flatten nested structs.
|
||||
func NewEditValidatorCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "edit-validator",
|
||||
Short: "edit an existing validator account",
|
||||
Short: "Edit an existing validator account",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientTxContext(cmd)
|
||||
if err != nil {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user