Skip to content

Commit

Permalink
feat: add examples of multiple coins for command-line interfaces (#156)
Browse files Browse the repository at this point in the history
* docs: update stake description

* refactor: add more usage examples and update description

* chore: add more test cases, refactor codes, and rename suite.go to suite_test.go

* docs: update the link

* feat: increase code coverage

* test: code coverage

* test: change the file name since coverage counts lines

* revert: test lines

* feat: apply feedbacks

* chore: increase code coverage and remove unused sentinel error
  • Loading branch information
jaybxyz authored Oct 8, 2021
1 parent cac3415 commit f994143
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 125 deletions.
28 changes: 22 additions & 6 deletions x/farming/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,14 @@ func NewStakeCmd() *cobra.Command {
Long: strings.TrimSpace(
fmt.Sprintf(`Stake coins.
To get farming rewards, it is recommended to check which plans are available on a network.
To get farming rewards, you must stake coins that are defined in available plans on a network.
Example:
$ %s tx %s stake 1000poolD35A0CC16EE598F90B044CE296A405BA9C381E38837599D96F2F70C2F02A23A4 --from mykey
$ %s tx %s stake 500poolD35A0CC16EE598F90B044CE296A405BA9C381E38837599D96F2F70C2F02A23A4,500pool93E069B333B5ECEBFE24C6E1437E814003248E0DD7FF8B9F82119F4587449BA5 --from mykey
`,
version.AppName, types.ModuleName,
version.AppName, types.ModuleName,
),
),
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -233,12 +235,14 @@ func NewUnstakeCmd() *cobra.Command {
Long: strings.TrimSpace(
fmt.Sprintf(`Unstake coins.
Note that this action doesn't require any period to unstake your coins.
Note that unstaking doesn't require any period and your accumulated rewards are automatically withdrawn to your wallet.
Example:
$ %s tx %s unstake 500poolD35A0CC16EE598F90B044CE296A405BA9C381E38837599D96F2F70C2F02A23A4 --from mykey
$ %s tx %s unstake 500poolD35A0CC16EE598F90B044CE296A405BA9C381E38837599D96F2F70C2F02A23A4,500pool93E069B333B5ECEBFE24C6E1437E814003248E0DD7FF8B9F82119F4587449BA5 --from mykey
`,
version.AppName, types.ModuleName,
version.AppName, types.ModuleName,
),
),
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -271,14 +275,16 @@ func NewHarvestCmd() *cobra.Command {
Args: cobra.MaximumNArgs(1),
Short: "Harvest farming rewards",
Long: strings.TrimSpace(
fmt.Sprintf(`Harvest farming that the staking coin denoms belong to plans.
fmt.Sprintf(`Harvest farming rewards from the staking coin denoms that are defined in the availble plans.
Example:
$ %s tx %s harvest poolD35A0CC16EE598F90B044CE296A405BA9C381E38837599D96F2F70C2F02A23A4,uatom --from mykey
$ %s tx %s harvest poolD35A0CC16EE598F90B044CE296A405BA9C381E38837599D96F2F70C2F02A23A4 --from mykey
$ %s tx %s harvest poolD35A0CC16EE598F90B044CE296A405BA9C381E38837599D96F2F70C2F02A23A4,pool93E069B333B5ECEBFE24C6E1437E814003248E0DD7FF8B9F82119F4587449BA5 --from mykey
$ %s tx %s harvest --all --from mykey
`,
version.AppName, types.ModuleName,
version.AppName, types.ModuleName,
version.AppName, types.ModuleName,
),
),
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -332,7 +338,17 @@ func NewAdvanceEpochCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "advance-epoch",
Args: cobra.NoArgs,
Short: "advance epoch by one to simulate reward distribution",
Short: "Advance epoch by 1 to simulate reward distribution",
Long: strings.TrimSpace(
fmt.Sprintf(`Advance epoch by 1 to simulate reward distribution.
This message is available for testing purpose and it can only be enabled when you build the binary with "make install-testing" command.
Example:
$ %s tx %s advance-epoch --from mykey
`,
version.AppName, types.ModuleName,
),
),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
Expand Down Expand Up @@ -361,7 +377,7 @@ func GetCmdSubmitPublicPlanProposal() *cobra.Command {
Long: strings.TrimSpace(
fmt.Sprintf(`Submit a a public farming plan along with an initial deposit. You can submit this governance proposal
to add, update, and delete farming plan. The proposal details must be supplied via a JSON file. A JSON file to add plan request proposal is
provided below. For more examples, please refer to https://github.com/tendermint/farming/blob/master/docs/How-To/farming_plans.md
provided below. For more examples, please refer to https://github.com/tendermint/farming/blob/master/docs/Tutorials/demo/plans.md
Example:
$ %s tx gov submit-proposal public-farming-plan <path/to/proposal.json> --from=<key_or_address> --deposit=<deposit_amount>
Expand Down
29 changes: 29 additions & 0 deletions x/farming/client/testutil/cli_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/cosmos/cosmos-sdk/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"
bankcli "github.com/cosmos/cosmos-sdk/x/bank/client/cli"

farmingapp "github.com/tendermint/farming/app"
farmingcli "github.com/tendermint/farming/x/farming/client/cli"
Expand Down Expand Up @@ -78,3 +79,31 @@ func MsgStakeExec(clientCtx client.Context, from string, stakingCoins string,

return clitestutil.ExecTestCLICmd(clientCtx, farmingcli.NewStakeCmd(), args)
}

// MsgAdvanceEpochExec creates a transaction to advance epoch by 1.
func MsgAdvanceEpochExec(clientCtx client.Context, from string,
extraAtgs ...string) (testutil.BufferWriter, error) {

args := append([]string{
fmt.Sprintf("--%s=%s", flags.FlagFrom, from),
}, commonArgs...)

args = append(args, commonArgs...)

return clitestutil.ExecTestCLICmd(clientCtx, farmingcli.NewAdvanceEpochCmd(), args)
}

// MsgSendExec creates a transaction to transfer coins.
func MsgSendExec(clientCtx client.Context, from string, to string, amount string,
extraAtgs ...string) (testutil.BufferWriter, error) {

args := append([]string{
from,
to,
amount,
}, commonArgs...)

args = append(args, commonArgs...)

return clitestutil.ExecTestCLICmd(clientCtx, bankcli.NewSendTxCmd(), args)
}
Loading

0 comments on commit f994143

Please sign in to comment.