Skip to content

Commit

Permalink
Add the count authorization back into the authz grant command. Mark v…
Browse files Browse the repository at this point in the history
…0.50.5-pio-3 in the changelog. (#609)

* Add the count authorization back into the authz grant command.

* Add changelog entry and mark v0.50.5-pio-3 in the changelog.

* Add a nothing entry to the changelog under unreleased.

* Add some unit tests for the additions.
  • Loading branch information
SpicyLemon authored Apr 15, 2024
1 parent 6e4cf88 commit 7232a55
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 10 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased Provenance]

* nothing

## [v0.50.5-pio-3](https://github.com/provenance-io/cosmos-sdk/releases/tag/v0.50.5-pio-3) - 2024-04-15

### Improvements

* [#609](https://github.com/provenance-io/cosmos-sdk/pull/609) Allow creation of count authorizations via command line.

### Full Commit History

* https://github.com/provenance-io/cosmos-sdk/compare/v0.50.5-pio-2..v0.50.5-pio-3
* https://github.com/provenance-io/cosmos-sdk/compare/v0.50.5..v0.50.5-pio-3

---

## [v0.50.5-pio-2](https://github.com/provenance-io/cosmos-sdk/releases/tag/v0.50.5-pio-2) - 2024-03-28

### Improvements
Expand Down
38 changes: 28 additions & 10 deletions x/authz/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ import (

// Flag names and values
const (
FlagSpendLimit = "spend-limit"
FlagMsgType = "msg-type"
FlagExpiration = "expiration"
FlagAllowedValidators = "allowed-validators"
FlagDenyValidators = "deny-validators"
FlagAllowList = "allow-list"
delegate = "delegate"
redelegate = "redelegate"
unbond = "unbond"
FlagSpendLimit = "spend-limit"
FlagMsgType = "msg-type"
FlagExpiration = "expiration"
FlagAllowedValidators = "allowed-validators"
FlagDenyValidators = "deny-validators"
FlagAllowedAuthorizations = "allowed-authorizations"
FlagAllowList = "allow-list"
delegate = "delegate"
redelegate = "redelegate"
unbond = "unbond"
)

// GetTxCmd returns the transaction commands for this module
Expand All @@ -57,7 +58,7 @@ func GetTxCmd(ac address.Codec) *cobra.Command {
// NewCmdGrantAuthorization returns a CLI command handler for creating a MsgGrant transaction.
func NewCmdGrantAuthorization(ac address.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "grant <grantee> <authorization_type=\"send\"|\"generic\"|\"delegate\"|\"unbond\"|\"redelegate\"> --from <granter>",
Use: "grant <grantee> <\"count\"|\"send\"|\"generic\"|\"delegate\"|\"unbond\"|\"redelegate\"> --from <granter>",
Short: "Grant authorization to an address",
Long: strings.TrimSpace(
fmt.Sprintf(`create a new grant authorization to an address to execute a transaction on your behalf:
Expand Down Expand Up @@ -85,6 +86,22 @@ Examples:

var authorization authz.Authorization
switch args[1] {
case "count":
msgType, err := cmd.Flags().GetString(FlagMsgType)
if err != nil {
return err
}

allowedAuthorizations, err := cmd.Flags().GetInt32(FlagAllowedAuthorizations)
if err != nil {
return err
}

if allowedAuthorizations <= 0 {
return fmt.Errorf("--%s must be greater than 0", FlagAllowedAuthorizations)
}

authorization = authz.NewCountAuthorization(msgType, allowedAuthorizations)
case "send":
limit, err := cmd.Flags().GetString(FlagSpendLimit)
if err != nil {
Expand Down Expand Up @@ -213,6 +230,7 @@ Examples:
cmd.Flags().StringSlice(FlagDenyValidators, []string{}, "Deny validators addresses separated by ,")
cmd.Flags().StringSlice(FlagAllowList, []string{}, "Allowed addresses grantee is allowed to send funds separated by ,")
cmd.Flags().Int64(FlagExpiration, 0, "Expire time as Unix timestamp. Set zero (0) for no expiry. Default is 0.")
cmd.Flags().Int32(FlagAllowedAuthorizations, 0, "Allowed authorizations for a Count Authorization")
return cmd
}

Expand Down
35 changes: 35 additions & 0 deletions x/authz/client/cli/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,41 @@ func (s *CLITestSuite) TestCLITxGrantAuthorization() {
false,
"",
},
{
name: "invalid count authorization: no allowed authorizations",
args: []string{
grantee.String(),
"count",
fmt.Sprintf("--%s=%s", cli.FlagMsgType, typeMsgVote),
},
expectErr: true,
expErrMsg: "--allowed-authorizations must be greater than 0",
},
{
name: "invalid count authorization: negative allowed authorizations",
args: []string{
grantee.String(),
"count",
fmt.Sprintf("--%s=%s", cli.FlagMsgType, typeMsgVote),
"--allowed-authorizations", "-3",
},
expectErr: true,
expErrMsg: "--allowed-authorizations must be greater than 0",
},
{
name: "valid count authorization",
args: []string{
grantee.String(),
"count",
fmt.Sprintf("--%s=%s", cli.FlagMsgType, typeMsgVote),
"--allowed-authorizations", "3",
fmt.Sprintf("--%s=%s", flags.FlagFrom, val[0].Address.String()),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%d", cli.FlagExpiration, twoHours),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(10))).String()),
},
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit 7232a55

Please sign in to comment.