Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
parent
b0d20bce2b
commit
daaff088e2
@ -11,12 +11,19 @@ import (
|
||||
|
||||
// findSubCommand finds a sub-command of the provided command whose Use
|
||||
// string is or begins with the provided subCmdName.
|
||||
// It verifies the command's aliases as well.
|
||||
func findSubCommand(cmd *cobra.Command, subCmdName string) *cobra.Command {
|
||||
for _, subCmd := range cmd.Commands() {
|
||||
use := subCmd.Use
|
||||
if use == subCmdName || strings.HasPrefix(use, subCmdName+" ") {
|
||||
return subCmd
|
||||
}
|
||||
|
||||
for _, alias := range subCmd.Aliases {
|
||||
if alias == subCmdName || strings.HasPrefix(alias, subCmdName+" ") {
|
||||
return subCmd
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@ go 1.21
|
||||
|
||||
require (
|
||||
cosmossdk.io/api v0.7.1
|
||||
cosmossdk.io/client/v2 v2.0.0-20231005134150-8334eefaaf7c
|
||||
cosmossdk.io/client/v2 v2.0.0-20231009114728-5259373edec8
|
||||
cosmossdk.io/collections v0.4.0 // indirect
|
||||
cosmossdk.io/core v0.11.0
|
||||
cosmossdk.io/depinject v1.0.0-alpha.4
|
||||
@ -14,7 +14,7 @@ require (
|
||||
cosmossdk.io/tools/confix v0.0.0-20230925151519-64e0e8980834
|
||||
cosmossdk.io/x/circuit v0.0.0-20231006095526-33390754f9fe
|
||||
cosmossdk.io/x/evidence v0.0.0-20230925151519-64e0e8980834
|
||||
cosmossdk.io/x/feegrant v0.0.0-20230925151519-64e0e8980834
|
||||
cosmossdk.io/x/feegrant v0.0.0-20231009114728-5259373edec8
|
||||
cosmossdk.io/x/nft v0.0.0-20231006095526-33390754f9fe
|
||||
cosmossdk.io/x/tx v0.10.1-0.20230920120022-6715b5afb59f
|
||||
cosmossdk.io/x/upgrade v0.0.0-20230925151519-64e0e8980834
|
||||
|
||||
@ -189,8 +189,8 @@ cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1V
|
||||
cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M=
|
||||
cosmossdk.io/api v0.7.1 h1:PNQ1xN8+/0hj/sSD0ANqjkgfXFys+bZ5L8Hg7uzoUTU=
|
||||
cosmossdk.io/api v0.7.1/go.mod h1:ure9edhcROIHsngavM6mBLilMGFnfjhV/AaYhEMUkdo=
|
||||
cosmossdk.io/client/v2 v2.0.0-20231005134150-8334eefaaf7c h1:WlbeJazcWL5OAxSIay1DXQ52xUshtsuGmzny+3cYOyE=
|
||||
cosmossdk.io/client/v2 v2.0.0-20231005134150-8334eefaaf7c/go.mod h1:0ycdqzdjVeUdKqgBbaxqSsc1C18GJc3uEF+uphv/MPg=
|
||||
cosmossdk.io/client/v2 v2.0.0-20231009114728-5259373edec8 h1:IEBOxiA/KO2MeKEOwr1AUczynjWmWPooZ3U/naf6kTE=
|
||||
cosmossdk.io/client/v2 v2.0.0-20231009114728-5259373edec8/go.mod h1:VqOuMtieftq2OaX7WhRXjG0mhFih4qzw5JT8fyNlVuE=
|
||||
cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s=
|
||||
cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0=
|
||||
cosmossdk.io/core v0.11.0 h1:vtIafqUi+1ZNAE/oxLOQQ7Oek2n4S48SWLG8h/+wdbo=
|
||||
@ -211,8 +211,8 @@ cosmossdk.io/x/circuit v0.0.0-20231006095526-33390754f9fe h1:xcQTAlbv1l8PBHXI5/x
|
||||
cosmossdk.io/x/circuit v0.0.0-20231006095526-33390754f9fe/go.mod h1:syo6njNlaE1KLXRFd1gZQr/7pMstANp2zMqVUC+u4h4=
|
||||
cosmossdk.io/x/evidence v0.0.0-20230925151519-64e0e8980834 h1:h4ooSV3X5BxEfl3EUbOlXNFMnEc/mXTXF5mdl17CQLg=
|
||||
cosmossdk.io/x/evidence v0.0.0-20230925151519-64e0e8980834/go.mod h1:yUgv71a56ZEJu7c8BXWCliDrQ7Ag+FCZ//rYKw9S93U=
|
||||
cosmossdk.io/x/feegrant v0.0.0-20230925151519-64e0e8980834 h1:hILr/Ve3CKlWwMC3oHFb1er9xWzxbx1UEZytTuGeI8o=
|
||||
cosmossdk.io/x/feegrant v0.0.0-20230925151519-64e0e8980834/go.mod h1:C5DALk9amuP9nd/xCgaQxbn43q695zQ/tXH8b9ugzAs=
|
||||
cosmossdk.io/x/feegrant v0.0.0-20231009114728-5259373edec8 h1:e3JUrisu36fIf+EzppkSeryOocs7oUue4e1IepdhMMI=
|
||||
cosmossdk.io/x/feegrant v0.0.0-20231009114728-5259373edec8/go.mod h1:nnIKdJKz1Os+sOlJHrjgMOh1WAlle0aV7Y+0x434OyI=
|
||||
cosmossdk.io/x/nft v0.0.0-20231006095526-33390754f9fe h1:xDWsbJp/9Tdwh2w8/KT7E0sxb52ASTn1M+UO4pq6kko=
|
||||
cosmossdk.io/x/nft v0.0.0-20231006095526-33390754f9fe/go.mod h1:QQROAXjZWeJzH6dNHUNCPhs7zHrYjknH8gYynf0IvXs=
|
||||
cosmossdk.io/x/tx v0.10.1-0.20230920120022-6715b5afb59f h1:Dkw1pM+jnjK9Pk0CM6JZKLLDaMXWDCHSlLJiHcSmPpg=
|
||||
|
||||
@ -12,7 +12,7 @@ require (
|
||||
cosmossdk.io/simapp v0.0.0-20230620040119-e078f1a49e8b
|
||||
cosmossdk.io/store v1.0.0-rc.0
|
||||
cosmossdk.io/x/evidence v0.0.0-20230925151519-64e0e8980834
|
||||
cosmossdk.io/x/feegrant v0.0.0-20230925151519-64e0e8980834
|
||||
cosmossdk.io/x/feegrant v0.0.0-20231009114728-5259373edec8
|
||||
cosmossdk.io/x/nft v0.0.0-20231006095526-33390754f9fe // indirect
|
||||
cosmossdk.io/x/tx v0.10.1-0.20230920120022-6715b5afb59f
|
||||
cosmossdk.io/x/upgrade v0.0.0-20230925151519-64e0e8980834
|
||||
@ -37,7 +37,7 @@ require (
|
||||
cloud.google.com/go/compute/metadata v0.2.3 // indirect
|
||||
cloud.google.com/go/iam v1.1.1 // indirect
|
||||
cloud.google.com/go/storage v1.30.1 // indirect
|
||||
cosmossdk.io/client/v2 v2.0.0-20231005134150-8334eefaaf7c // indirect
|
||||
cosmossdk.io/client/v2 v2.0.0-20231009114728-5259373edec8 // indirect
|
||||
cosmossdk.io/collections v0.4.0 // indirect
|
||||
cosmossdk.io/x/circuit v0.0.0-20231006095526-33390754f9fe // indirect
|
||||
filippo.io/edwards25519 v1.0.0 // indirect
|
||||
|
||||
@ -189,8 +189,8 @@ cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1V
|
||||
cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M=
|
||||
cosmossdk.io/api v0.7.1 h1:PNQ1xN8+/0hj/sSD0ANqjkgfXFys+bZ5L8Hg7uzoUTU=
|
||||
cosmossdk.io/api v0.7.1/go.mod h1:ure9edhcROIHsngavM6mBLilMGFnfjhV/AaYhEMUkdo=
|
||||
cosmossdk.io/client/v2 v2.0.0-20231005134150-8334eefaaf7c h1:WlbeJazcWL5OAxSIay1DXQ52xUshtsuGmzny+3cYOyE=
|
||||
cosmossdk.io/client/v2 v2.0.0-20231005134150-8334eefaaf7c/go.mod h1:0ycdqzdjVeUdKqgBbaxqSsc1C18GJc3uEF+uphv/MPg=
|
||||
cosmossdk.io/client/v2 v2.0.0-20231009114728-5259373edec8 h1:IEBOxiA/KO2MeKEOwr1AUczynjWmWPooZ3U/naf6kTE=
|
||||
cosmossdk.io/client/v2 v2.0.0-20231009114728-5259373edec8/go.mod h1:VqOuMtieftq2OaX7WhRXjG0mhFih4qzw5JT8fyNlVuE=
|
||||
cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s=
|
||||
cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0=
|
||||
cosmossdk.io/core v0.11.0 h1:vtIafqUi+1ZNAE/oxLOQQ7Oek2n4S48SWLG8h/+wdbo=
|
||||
@ -209,8 +209,8 @@ cosmossdk.io/x/circuit v0.0.0-20231006095526-33390754f9fe h1:xcQTAlbv1l8PBHXI5/x
|
||||
cosmossdk.io/x/circuit v0.0.0-20231006095526-33390754f9fe/go.mod h1:syo6njNlaE1KLXRFd1gZQr/7pMstANp2zMqVUC+u4h4=
|
||||
cosmossdk.io/x/evidence v0.0.0-20230925151519-64e0e8980834 h1:h4ooSV3X5BxEfl3EUbOlXNFMnEc/mXTXF5mdl17CQLg=
|
||||
cosmossdk.io/x/evidence v0.0.0-20230925151519-64e0e8980834/go.mod h1:yUgv71a56ZEJu7c8BXWCliDrQ7Ag+FCZ//rYKw9S93U=
|
||||
cosmossdk.io/x/feegrant v0.0.0-20230925151519-64e0e8980834 h1:hILr/Ve3CKlWwMC3oHFb1er9xWzxbx1UEZytTuGeI8o=
|
||||
cosmossdk.io/x/feegrant v0.0.0-20230925151519-64e0e8980834/go.mod h1:C5DALk9amuP9nd/xCgaQxbn43q695zQ/tXH8b9ugzAs=
|
||||
cosmossdk.io/x/feegrant v0.0.0-20231009114728-5259373edec8 h1:e3JUrisu36fIf+EzppkSeryOocs7oUue4e1IepdhMMI=
|
||||
cosmossdk.io/x/feegrant v0.0.0-20231009114728-5259373edec8/go.mod h1:nnIKdJKz1Os+sOlJHrjgMOh1WAlle0aV7Y+0x434OyI=
|
||||
cosmossdk.io/x/nft v0.0.0-20231006095526-33390754f9fe h1:xDWsbJp/9Tdwh2w8/KT7E0sxb52ASTn1M+UO4pq6kko=
|
||||
cosmossdk.io/x/nft v0.0.0-20231006095526-33390754f9fe/go.mod h1:QQROAXjZWeJzH6dNHUNCPhs7zHrYjknH8gYynf0IvXs=
|
||||
cosmossdk.io/x/tx v0.10.1-0.20230920120022-6715b5afb59f h1:Dkw1pM+jnjK9Pk0CM6JZKLLDaMXWDCHSlLJiHcSmPpg=
|
||||
|
||||
@ -39,17 +39,18 @@ func GetTxCmd(ac address.Codec) *cobra.Command {
|
||||
|
||||
feegrantTxCmd.AddCommand(
|
||||
NewCmdFeeGrant(ac),
|
||||
NewCmdRevokeFeegrant(ac),
|
||||
)
|
||||
|
||||
return feegrantTxCmd
|
||||
}
|
||||
|
||||
// NewCmdFeeGrant returns a CLI command handler to create a MsgGrantAllowance transaction.
|
||||
// This command is more powerful than AutoCLI generated command as it allows a better input validation.
|
||||
func NewCmdFeeGrant(ac address.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "grant [granter_key_or_address] [grantee]",
|
||||
Short: "Grant Fee allowance to an address",
|
||||
Use: "grant [granter_key_or_address] [grantee]",
|
||||
Aliases: []string{"grant-allowance"},
|
||||
Short: "Grant Fee allowance to an address",
|
||||
Long: strings.TrimSpace(
|
||||
fmt.Sprintf(
|
||||
`Grant authorization to pay fees from your address. Note, the '--from' flag is
|
||||
@ -186,42 +187,6 @@ Examples:
|
||||
return cmd
|
||||
}
|
||||
|
||||
// NewCmdRevokeFeegrant returns a CLI command handler to create a MsgRevokeAllowance transaction.
|
||||
func NewCmdRevokeFeegrant(ac address.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "revoke [granter] [grantee]",
|
||||
Short: "revoke fee-grant",
|
||||
Long: strings.TrimSpace(
|
||||
fmt.Sprintf(`revoke fee grant from a granter to a grantee. Note, the '--from' flag is
|
||||
ignored as it is implied from [granter].
|
||||
|
||||
Example:
|
||||
$ %s tx %s revoke cosmos1skj.. cosmos1skj..
|
||||
`, version.AppName, feegrant.ModuleName),
|
||||
),
|
||||
Args: cobra.ExactArgs(2),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cmd.Flags().Set(flags.FlagFrom, args[0])
|
||||
clientCtx, err := client.GetClientTxContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
grantee, err := ac.StringToBytes(args[1])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
msg := feegrant.NewMsgRevokeAllowance(clientCtx.GetFromAddress(), grantee)
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
|
||||
},
|
||||
}
|
||||
|
||||
flags.AddTxFlagsToCmd(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
func getPeriodReset(duration int64) time.Time {
|
||||
return time.Now().Add(getPeriod(duration))
|
||||
}
|
||||
|
||||
@ -428,99 +428,6 @@ func (s *CLITestSuite) TestNewCmdFeeGrant() {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *CLITestSuite) TestNewCmdRevokeFeegrant() {
|
||||
granter := s.addedGranter
|
||||
grantee := s.addedGrantee
|
||||
clientCtx := s.clientCtx
|
||||
|
||||
commonFlags := []string{
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(10))).String()),
|
||||
}
|
||||
|
||||
addressCodec := codecaddress.NewBech32Codec("cosmos")
|
||||
// Create new fee grant specifically to test amino.
|
||||
encodedGrantee := "cosmos16ydaqh0fcnh4qt7a3jme4mmztm2qel5axcpw00"
|
||||
aminoGrantee, err := addressCodec.StringToBytes(encodedGrantee)
|
||||
s.Require().NoError(err)
|
||||
s.createGrant(granter, sdk.AccAddress(aminoGrantee))
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expectErr bool
|
||||
expectedCode uint32
|
||||
respType proto.Message
|
||||
}{
|
||||
{
|
||||
"invalid granter",
|
||||
append(
|
||||
[]string{
|
||||
"wrong_granter",
|
||||
grantee.String(),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, granter),
|
||||
},
|
||||
commonFlags...,
|
||||
),
|
||||
true, 0, nil,
|
||||
},
|
||||
{
|
||||
"invalid grantee",
|
||||
append(
|
||||
[]string{
|
||||
granter.String(),
|
||||
"wrong_grantee",
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, granter),
|
||||
},
|
||||
commonFlags...,
|
||||
),
|
||||
true, 0, nil,
|
||||
},
|
||||
{
|
||||
"Valid revoke",
|
||||
append(
|
||||
[]string{
|
||||
granter.String(),
|
||||
grantee.String(),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, granter),
|
||||
},
|
||||
commonFlags...,
|
||||
),
|
||||
false, 0, &sdk.TxResponse{},
|
||||
},
|
||||
{
|
||||
"Valid revoke with amino",
|
||||
append(
|
||||
[]string{
|
||||
granter.String(),
|
||||
encodedGrantee,
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, granter),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagSignMode, flags.SignModeLegacyAminoJSON),
|
||||
},
|
||||
commonFlags...,
|
||||
),
|
||||
false, 0, &sdk.TxResponse{},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.NewCmdRevokeFeegrant(codecaddress.NewBech32Codec("cosmos"))
|
||||
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(), tc.respType), out.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *CLITestSuite) TestTxWithFeeGrant() {
|
||||
clientCtx := s.clientCtx
|
||||
granter := s.addedGranter
|
||||
|
||||
@ -51,6 +51,20 @@ You can find the fee-grant of a granter and grantee.`),
|
||||
},
|
||||
Tx: &autocliv1.ServiceCommandDescriptor{
|
||||
Service: feegrantv1beta1.Msg_ServiceDesc.ServiceName,
|
||||
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
|
||||
{
|
||||
RpcMethod: "RevokeAllowance",
|
||||
Use: "revoke [granter] [grantee]",
|
||||
Short: "Revoke a fee grant",
|
||||
Long: "Revoke fee grant from a granter to a grantee. Note, the '--from' flag is ignored as it is implied from [granter]",
|
||||
Example: fmt.Sprintf(`$ %s tx feegrant revoke [granter] [grantee]`, version.AppName),
|
||||
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
|
||||
{ProtoField: "granter"},
|
||||
{ProtoField: "grantee"},
|
||||
},
|
||||
},
|
||||
},
|
||||
EnhanceCustomCommand: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user