Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
co-authored by
Julien Robert
parent
509a228bc4
commit
d23caef6f6
@@ -1,556 +0,0 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/x/group"
|
||||
)
|
||||
|
||||
// QueryCmd returns the cli query commands for the group module.
|
||||
func QueryCmd(name string) *cobra.Command {
|
||||
queryCmd := &cobra.Command{
|
||||
Use: name,
|
||||
Short: "Querying commands for the group module",
|
||||
DisableFlagParsing: true,
|
||||
SuggestionsMinimumDistance: 2,
|
||||
RunE: client.ValidateCmd,
|
||||
}
|
||||
|
||||
queryCmd.AddCommand(
|
||||
QueryGroupInfoCmd(),
|
||||
QueryGroupPolicyInfoCmd(),
|
||||
QueryGroupMembersCmd(),
|
||||
QueryGroupsByAdminCmd(),
|
||||
QueryGroupPoliciesByGroupCmd(),
|
||||
QueryGroupPoliciesByAdminCmd(),
|
||||
QueryProposalCmd(),
|
||||
QueryProposalsByGroupPolicyCmd(),
|
||||
QueryVoteByProposalVoterCmd(),
|
||||
QueryVotesByProposalCmd(),
|
||||
QueryVotesByVoterCmd(),
|
||||
QueryGroupsByMemberCmd(),
|
||||
QueryTallyResultCmd(),
|
||||
QueryGroupsCmd(),
|
||||
)
|
||||
|
||||
return queryCmd
|
||||
}
|
||||
|
||||
// QueryGroupsByMemberCmd creates a CLI command for Query/GroupsByMember.
|
||||
func QueryGroupsByMemberCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "groups-by-member [address]",
|
||||
Short: "Query for groups by member address with pagination flags",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientQueryContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pageReq, err := client.ReadPageRequest(cmd.Flags())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
queryClient := group.NewQueryClient(clientCtx)
|
||||
res, err := queryClient.GroupsByMember(cmd.Context(), &group.QueryGroupsByMemberRequest{
|
||||
Address: args[0],
|
||||
Pagination: pageReq,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return clientCtx.PrintProto(res)
|
||||
},
|
||||
}
|
||||
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
flags.AddPaginationFlagsToCmd(cmd, "groups-by-members")
|
||||
return cmd
|
||||
}
|
||||
|
||||
// QueryGroupInfoCmd creates a CLI command for Query/GroupInfo.
|
||||
func QueryGroupInfoCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "group-info [id]",
|
||||
Short: "Query for group info by group id",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientQueryContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
groupID, err := strconv.ParseUint(args[0], 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
queryClient := group.NewQueryClient(clientCtx)
|
||||
|
||||
res, err := queryClient.GroupInfo(cmd.Context(), &group.QueryGroupInfoRequest{
|
||||
GroupId: groupID,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return clientCtx.PrintProto(res.Info)
|
||||
},
|
||||
}
|
||||
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// QueryGroupPolicyInfoCmd creates a CLI command for Query/GroupPolicyInfo.
|
||||
func QueryGroupPolicyInfoCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "group-policy-info [group-policy-account]",
|
||||
Short: "Query for group policy info by account address of group policy",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientQueryContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
queryClient := group.NewQueryClient(clientCtx)
|
||||
|
||||
res, err := queryClient.GroupPolicyInfo(cmd.Context(), &group.QueryGroupPolicyInfoRequest{
|
||||
Address: args[0],
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return clientCtx.PrintProto(res.Info)
|
||||
},
|
||||
}
|
||||
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// QueryGroupMembersCmd creates a CLI command for Query/GroupMembers.
|
||||
func QueryGroupMembersCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "group-members [id]",
|
||||
Short: "Query for group members by group id with pagination flags",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientQueryContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
groupID, err := strconv.ParseUint(args[0], 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pageReq, err := client.ReadPageRequest(cmd.Flags())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
queryClient := group.NewQueryClient(clientCtx)
|
||||
|
||||
res, err := queryClient.GroupMembers(cmd.Context(), &group.QueryGroupMembersRequest{
|
||||
GroupId: groupID,
|
||||
Pagination: pageReq,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return clientCtx.PrintProto(res)
|
||||
},
|
||||
}
|
||||
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
flags.AddPaginationFlagsToCmd(cmd, "group-members")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// QueryGroupsByAdminCmd creates a CLI command for Query/GroupsByAdmin.
|
||||
func QueryGroupsByAdminCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "groups-by-admin [admin]",
|
||||
Short: "Query for groups by admin account address with pagination flags",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientQueryContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pageReq, err := client.ReadPageRequest(cmd.Flags())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
queryClient := group.NewQueryClient(clientCtx)
|
||||
|
||||
res, err := queryClient.GroupsByAdmin(cmd.Context(), &group.QueryGroupsByAdminRequest{
|
||||
Admin: args[0],
|
||||
Pagination: pageReq,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return clientCtx.PrintProto(res)
|
||||
},
|
||||
}
|
||||
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
flags.AddPaginationFlagsToCmd(cmd, "groups-by-admin")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// QueryGroupPoliciesByGroupCmd creates a CLI command for Query/GroupPoliciesByGroup.
|
||||
func QueryGroupPoliciesByGroupCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "group-policies-by-group [group-id]",
|
||||
Short: "Query for group policies by group id with pagination flags",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientQueryContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
groupID, err := strconv.ParseUint(args[0], 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pageReq, err := client.ReadPageRequest(cmd.Flags())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
queryClient := group.NewQueryClient(clientCtx)
|
||||
|
||||
res, err := queryClient.GroupPoliciesByGroup(cmd.Context(), &group.QueryGroupPoliciesByGroupRequest{
|
||||
GroupId: groupID,
|
||||
Pagination: pageReq,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return clientCtx.PrintProto(res)
|
||||
},
|
||||
}
|
||||
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
flags.AddPaginationFlagsToCmd(cmd, "groups-policies-by-group")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// QueryGroupPoliciesByAdminCmd creates a CLI command for Query/GroupPoliciesByAdmin.
|
||||
func QueryGroupPoliciesByAdminCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "group-policies-by-admin [admin]",
|
||||
Short: "Query for group policies by admin account address with pagination flags",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientQueryContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pageReq, err := client.ReadPageRequest(cmd.Flags())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
queryClient := group.NewQueryClient(clientCtx)
|
||||
|
||||
res, err := queryClient.GroupPoliciesByAdmin(cmd.Context(), &group.QueryGroupPoliciesByAdminRequest{
|
||||
Admin: args[0],
|
||||
Pagination: pageReq,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return clientCtx.PrintProto(res)
|
||||
},
|
||||
}
|
||||
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
flags.AddPaginationFlagsToCmd(cmd, "group-policies-by-admin")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// QueryProposalCmd creates a CLI command for Query/Proposal.
|
||||
func QueryProposalCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "proposal [id]",
|
||||
Short: "Query for proposal by id",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientQueryContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
proposalID, err := strconv.ParseUint(args[0], 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
queryClient := group.NewQueryClient(clientCtx)
|
||||
|
||||
res, err := queryClient.Proposal(cmd.Context(), &group.QueryProposalRequest{
|
||||
ProposalId: proposalID,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return clientCtx.PrintProto(res)
|
||||
},
|
||||
}
|
||||
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// QueryProposalsByGroupPolicyCmd creates a CLI command for Query/ProposalsByGroupPolicy.
|
||||
func QueryProposalsByGroupPolicyCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "proposals-by-group-policy [group-policy-account]",
|
||||
Short: "Query for proposals by account address of group policy with pagination flags",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientQueryContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pageReq, err := client.ReadPageRequest(cmd.Flags())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
queryClient := group.NewQueryClient(clientCtx)
|
||||
|
||||
res, err := queryClient.ProposalsByGroupPolicy(cmd.Context(), &group.QueryProposalsByGroupPolicyRequest{
|
||||
Address: args[0],
|
||||
Pagination: pageReq,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return clientCtx.PrintProto(res)
|
||||
},
|
||||
}
|
||||
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
flags.AddPaginationFlagsToCmd(cmd, "proposals-by-group-policy")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// QueryVoteByProposalVoterCmd creates a CLI command for Query/VoteByProposalVoter.
|
||||
func QueryVoteByProposalVoterCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "vote [proposal-id] [voter]",
|
||||
Short: "Query for vote by proposal id and voter account address",
|
||||
Args: cobra.ExactArgs(2),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientQueryContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
proposalID, err := strconv.ParseUint(args[0], 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
queryClient := group.NewQueryClient(clientCtx)
|
||||
|
||||
res, err := queryClient.VoteByProposalVoter(cmd.Context(), &group.QueryVoteByProposalVoterRequest{
|
||||
ProposalId: proposalID,
|
||||
Voter: args[1],
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return clientCtx.PrintProto(res)
|
||||
},
|
||||
}
|
||||
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// QueryVotesByProposalCmd creates a CLI command for Query/VotesByProposal.
|
||||
func QueryVotesByProposalCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "votes-by-proposal [proposal-id]",
|
||||
Short: "Query for votes by proposal id with pagination flags",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientQueryContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
proposalID, err := strconv.ParseUint(args[0], 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pageReq, err := client.ReadPageRequest(cmd.Flags())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
queryClient := group.NewQueryClient(clientCtx)
|
||||
|
||||
res, err := queryClient.VotesByProposal(cmd.Context(), &group.QueryVotesByProposalRequest{
|
||||
ProposalId: proposalID,
|
||||
Pagination: pageReq,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return clientCtx.PrintProto(res)
|
||||
},
|
||||
}
|
||||
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
flags.AddPaginationFlagsToCmd(cmd, "votes-by-proposal")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// QueryTallyResultCmd creates a CLI command for Query/TallyResult.
|
||||
func QueryTallyResultCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "tally-result [proposal-id]",
|
||||
Short: "Query tally result of proposal",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientQueryContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
proposalID, err := strconv.ParseUint(args[0], 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
queryClient := group.NewQueryClient(clientCtx)
|
||||
|
||||
res, err := queryClient.TallyResult(cmd.Context(), &group.QueryTallyResultRequest{
|
||||
ProposalId: proposalID,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return clientCtx.PrintProto(res)
|
||||
},
|
||||
}
|
||||
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// QueryVotesByVoterCmd creates a CLI command for Query/VotesByVoter.
|
||||
func QueryVotesByVoterCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "votes-by-voter [voter]",
|
||||
Short: "Query for votes by voter account address with pagination flags",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientQueryContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pageReq, err := client.ReadPageRequest(cmd.Flags())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
queryClient := group.NewQueryClient(clientCtx)
|
||||
|
||||
res, err := queryClient.VotesByVoter(cmd.Context(), &group.QueryVotesByVoterRequest{
|
||||
Voter: args[0],
|
||||
Pagination: pageReq,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return clientCtx.PrintProto(res)
|
||||
},
|
||||
}
|
||||
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
flags.AddPaginationFlagsToCmd(cmd, "votes-by-voter")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// QueryGroupsCmd creates a CLI command for Query/Groups.
|
||||
func QueryGroupsCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "groups",
|
||||
Short: "Query for groups present in the state",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientQueryContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pageReq, err := client.ReadPageRequest(cmd.Flags())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
queryClient := group.NewQueryClient(clientCtx)
|
||||
|
||||
res, err := queryClient.Groups(cmd.Context(), &group.QueryGroupsRequest{
|
||||
Pagination: pageReq,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return clientCtx.PrintProto(res)
|
||||
},
|
||||
}
|
||||
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
flags.AddPaginationFlagsToCmd(cmd, "groups")
|
||||
|
||||
return cmd
|
||||
}
|
||||
@@ -1,513 +0,0 @@
|
||||
package cli_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
"github.com/cosmos/cosmos-sdk/x/group/client/cli"
|
||||
)
|
||||
|
||||
func (s *CLITestSuite) TestQueryGroupInfo() {
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expCmdOutput string
|
||||
}{
|
||||
{
|
||||
name: "invalid id",
|
||||
args: []string{"invalid id"},
|
||||
expCmdOutput: `[invalid id]`,
|
||||
},
|
||||
{
|
||||
name: "json output",
|
||||
args: []string{"1", fmt.Sprintf("--%s=json", flags.FlagOutput)},
|
||||
expCmdOutput: `[1 --output=json]`,
|
||||
},
|
||||
{
|
||||
name: "text output",
|
||||
args: []string{"1", fmt.Sprintf("--%s=text", flags.FlagOutput)},
|
||||
expCmdOutput: `[1 --output=text]`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.QueryGroupInfoCmd()
|
||||
|
||||
ctx := svrcmd.CreateExecuteContext(context.Background())
|
||||
|
||||
cmd.SetOut(io.Discard)
|
||||
s.Require().NotNil(cmd)
|
||||
|
||||
cmd.SetContext(ctx)
|
||||
cmd.SetArgs(tc.args)
|
||||
s.Require().NoError(client.SetCmdClientContextHandler(s.baseCtx, cmd))
|
||||
|
||||
s.Require().Contains(fmt.Sprint(cmd), "group-info [id] [] [] Query for group info by group id")
|
||||
s.Require().Contains(fmt.Sprint(cmd), tc.expCmdOutput)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *CLITestSuite) TestQueryGroupPolicyInfo() {
|
||||
accounts := testutil.CreateKeyringAccounts(s.T(), s.kr, 1)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expCmdOutput string
|
||||
}{
|
||||
{
|
||||
name: "json output",
|
||||
args: []string{accounts[0].Address.String(), fmt.Sprintf("--%s=json", flags.FlagOutput)},
|
||||
expCmdOutput: fmt.Sprintf("%s --output=json", accounts[0].Address.String()),
|
||||
},
|
||||
{
|
||||
name: "text output",
|
||||
args: []string{accounts[0].Address.String(), fmt.Sprintf("--%s=text", flags.FlagOutput)},
|
||||
expCmdOutput: fmt.Sprintf("%s --output=text", accounts[0].Address.String()),
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.QueryGroupPolicyInfoCmd()
|
||||
|
||||
ctx := svrcmd.CreateExecuteContext(context.Background())
|
||||
|
||||
cmd.SetOut(io.Discard)
|
||||
s.Require().NotNil(cmd)
|
||||
|
||||
cmd.SetContext(ctx)
|
||||
cmd.SetArgs(tc.args)
|
||||
s.Require().NoError(client.SetCmdClientContextHandler(s.baseCtx, cmd))
|
||||
|
||||
s.Require().Contains(fmt.Sprint(cmd), "group-policy-info [group-policy-account] [] [] Query for group policy info by account address of group policy")
|
||||
s.Require().Contains(fmt.Sprint(cmd), tc.expCmdOutput)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *CLITestSuite) TestQueryGroupMembers() {
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expCmdOutput string
|
||||
}{
|
||||
{
|
||||
name: "json output",
|
||||
args: []string{"1", fmt.Sprintf("--%s=json", flags.FlagOutput)},
|
||||
expCmdOutput: "1 --output=json",
|
||||
},
|
||||
{
|
||||
name: "text output",
|
||||
args: []string{"1", fmt.Sprintf("--%s=text", flags.FlagOutput)},
|
||||
expCmdOutput: "1 --output=text",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.QueryGroupMembersCmd()
|
||||
|
||||
ctx := svrcmd.CreateExecuteContext(context.Background())
|
||||
|
||||
cmd.SetOut(io.Discard)
|
||||
s.Require().NotNil(cmd)
|
||||
|
||||
cmd.SetContext(ctx)
|
||||
cmd.SetArgs(tc.args)
|
||||
s.Require().NoError(client.SetCmdClientContextHandler(s.baseCtx, cmd))
|
||||
|
||||
s.Require().Contains(fmt.Sprint(cmd), "group-members [id] [] [] Query for group members by group id with pagination flags")
|
||||
s.Require().Contains(fmt.Sprint(cmd), tc.expCmdOutput)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *CLITestSuite) TestQueryGroupsByAdmin() {
|
||||
accounts := testutil.CreateKeyringAccounts(s.T(), s.kr, 1)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expCmdOutput string
|
||||
}{
|
||||
{
|
||||
name: "json output",
|
||||
args: []string{accounts[0].Address.String(), fmt.Sprintf("--%s=json", flags.FlagOutput)},
|
||||
expCmdOutput: fmt.Sprintf("%s --output=json", accounts[0].Address.String()),
|
||||
},
|
||||
{
|
||||
name: "text output",
|
||||
args: []string{accounts[0].Address.String(), fmt.Sprintf("--%s=text", flags.FlagOutput)},
|
||||
expCmdOutput: fmt.Sprintf("%s --output=text", accounts[0].Address.String()),
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.QueryGroupsByAdminCmd()
|
||||
|
||||
ctx := svrcmd.CreateExecuteContext(context.Background())
|
||||
|
||||
cmd.SetOut(io.Discard)
|
||||
s.Require().NotNil(cmd)
|
||||
|
||||
cmd.SetContext(ctx)
|
||||
cmd.SetArgs(tc.args)
|
||||
s.Require().NoError(client.SetCmdClientContextHandler(s.baseCtx, cmd))
|
||||
|
||||
s.Require().Contains(fmt.Sprint(cmd), "groups-by-admin [admin] [] [] Query for groups by admin account address with pagination flags")
|
||||
s.Require().Contains(fmt.Sprint(cmd), tc.expCmdOutput)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *CLITestSuite) TestQueryGroupPoliciesByGroup() {
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expCmdOutput string
|
||||
}{
|
||||
{
|
||||
name: "json output",
|
||||
args: []string{"1", fmt.Sprintf("--%s=json", flags.FlagOutput)},
|
||||
expCmdOutput: "1 --output=json",
|
||||
},
|
||||
{
|
||||
name: "text output",
|
||||
args: []string{"1", fmt.Sprintf("--%s=text", flags.FlagOutput)},
|
||||
expCmdOutput: "1 --output=text",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.QueryGroupPoliciesByGroupCmd()
|
||||
|
||||
ctx := svrcmd.CreateExecuteContext(context.Background())
|
||||
|
||||
cmd.SetOut(io.Discard)
|
||||
s.Require().NotNil(cmd)
|
||||
|
||||
cmd.SetContext(ctx)
|
||||
cmd.SetArgs(tc.args)
|
||||
s.Require().NoError(client.SetCmdClientContextHandler(s.baseCtx, cmd))
|
||||
|
||||
s.Require().Contains(fmt.Sprint(cmd), "group-policies-by-group [group-id] [] [] Query for group policies by group id with pagination flags")
|
||||
s.Require().Contains(fmt.Sprint(cmd), tc.expCmdOutput)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *CLITestSuite) TestQueryGroupPoliciesByAdmin() {
|
||||
accounts := testutil.CreateKeyringAccounts(s.T(), s.kr, 1)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expCmdOutput string
|
||||
}{
|
||||
{
|
||||
name: "json output",
|
||||
args: []string{accounts[0].Address.String(), fmt.Sprintf("--%s=json", flags.FlagOutput)},
|
||||
expCmdOutput: fmt.Sprintf("%s --output=json", accounts[0].Address.String()),
|
||||
},
|
||||
{
|
||||
name: "text output",
|
||||
args: []string{accounts[0].Address.String(), fmt.Sprintf("--%s=text", flags.FlagOutput)},
|
||||
expCmdOutput: fmt.Sprintf("%s --output=text", accounts[0].Address.String()),
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.QueryGroupPoliciesByAdminCmd()
|
||||
|
||||
ctx := svrcmd.CreateExecuteContext(context.Background())
|
||||
|
||||
cmd.SetOut(io.Discard)
|
||||
s.Require().NotNil(cmd)
|
||||
|
||||
cmd.SetContext(ctx)
|
||||
cmd.SetArgs(tc.args)
|
||||
s.Require().NoError(client.SetCmdClientContextHandler(s.baseCtx, cmd))
|
||||
|
||||
s.Require().Contains(fmt.Sprint(cmd), "group-policies-by-admin [admin] [] [] Query for group policies by admin account address with pagination flags")
|
||||
s.Require().Contains(fmt.Sprint(cmd), tc.expCmdOutput)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *CLITestSuite) TestQueryProposal() {
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expCmdOutput string
|
||||
}{
|
||||
{
|
||||
name: "json output",
|
||||
args: []string{"1", fmt.Sprintf("--%s=json", flags.FlagOutput)},
|
||||
expCmdOutput: "1 --output=json",
|
||||
},
|
||||
{
|
||||
name: "text output",
|
||||
args: []string{"1", fmt.Sprintf("--%s=text", flags.FlagOutput)},
|
||||
expCmdOutput: "1 --output=text",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.QueryProposalCmd()
|
||||
|
||||
ctx := svrcmd.CreateExecuteContext(context.Background())
|
||||
|
||||
cmd.SetOut(io.Discard)
|
||||
s.Require().NotNil(cmd)
|
||||
|
||||
cmd.SetContext(ctx)
|
||||
cmd.SetArgs(tc.args)
|
||||
s.Require().NoError(client.SetCmdClientContextHandler(s.baseCtx, cmd))
|
||||
|
||||
s.Require().Contains(fmt.Sprint(cmd), "proposal [id] [] [] Query for proposal by id")
|
||||
s.Require().Contains(fmt.Sprint(cmd), tc.expCmdOutput)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *CLITestSuite) TestQueryProposalsByGroupPolicy() {
|
||||
accounts := testutil.CreateKeyringAccounts(s.T(), s.kr, 1)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expCmdOutput string
|
||||
}{
|
||||
{
|
||||
name: "json output",
|
||||
args: []string{accounts[0].Address.String(), fmt.Sprintf("--%s=json", flags.FlagOutput)},
|
||||
expCmdOutput: fmt.Sprintf("%s --output=json", accounts[0].Address.String()),
|
||||
},
|
||||
{
|
||||
name: "text output",
|
||||
args: []string{accounts[0].Address.String(), fmt.Sprintf("--%s=text", flags.FlagOutput)},
|
||||
expCmdOutput: fmt.Sprintf("%s --output=text", accounts[0].Address.String()),
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.QueryProposalsByGroupPolicyCmd()
|
||||
|
||||
ctx := svrcmd.CreateExecuteContext(context.Background())
|
||||
|
||||
cmd.SetOut(io.Discard)
|
||||
s.Require().NotNil(cmd)
|
||||
|
||||
cmd.SetContext(ctx)
|
||||
cmd.SetArgs(tc.args)
|
||||
s.Require().NoError(client.SetCmdClientContextHandler(s.baseCtx, cmd))
|
||||
|
||||
s.Require().Contains(fmt.Sprint(cmd), "proposals-by-group-policy [group-policy-account] [] [] Query for proposals by account address of group policy with pagination flags")
|
||||
s.Require().Contains(fmt.Sprint(cmd), tc.expCmdOutput)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *CLITestSuite) TestQueryVoteByProposalVoter() {
|
||||
accounts := testutil.CreateKeyringAccounts(s.T(), s.kr, 1)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expCmdOutput string
|
||||
}{
|
||||
{
|
||||
name: "json output",
|
||||
args: []string{"1", accounts[0].Address.String(), fmt.Sprintf("--%s=json", flags.FlagOutput)},
|
||||
expCmdOutput: fmt.Sprintf("1 %s --output=json", accounts[0].Address.String()),
|
||||
},
|
||||
{
|
||||
name: "text output",
|
||||
args: []string{"1", accounts[0].Address.String(), fmt.Sprintf("--%s=text", flags.FlagOutput)},
|
||||
expCmdOutput: fmt.Sprintf("1 %s --output=text", accounts[0].Address.String()),
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.QueryVoteByProposalVoterCmd()
|
||||
|
||||
ctx := svrcmd.CreateExecuteContext(context.Background())
|
||||
|
||||
cmd.SetOut(io.Discard)
|
||||
s.Require().NotNil(cmd)
|
||||
|
||||
cmd.SetContext(ctx)
|
||||
cmd.SetArgs(tc.args)
|
||||
s.Require().NoError(client.SetCmdClientContextHandler(s.baseCtx, cmd))
|
||||
|
||||
s.Require().Contains(fmt.Sprint(cmd), "vote [proposal-id] [voter] [] [] Query for vote by proposal id and voter account address")
|
||||
s.Require().Contains(fmt.Sprint(cmd), tc.expCmdOutput)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *CLITestSuite) TestQueryVotesByProposal() {
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expCmdOutput string
|
||||
}{
|
||||
{
|
||||
name: "json output",
|
||||
args: []string{"1", fmt.Sprintf("--%s=json", flags.FlagOutput)},
|
||||
expCmdOutput: "1 --output=json",
|
||||
},
|
||||
{
|
||||
name: "text output",
|
||||
args: []string{"1", fmt.Sprintf("--%s=text", flags.FlagOutput)},
|
||||
expCmdOutput: "1 --output=text",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.QueryVotesByProposalCmd()
|
||||
|
||||
ctx := svrcmd.CreateExecuteContext(context.Background())
|
||||
|
||||
cmd.SetOut(io.Discard)
|
||||
s.Require().NotNil(cmd)
|
||||
|
||||
cmd.SetContext(ctx)
|
||||
cmd.SetArgs(tc.args)
|
||||
s.Require().NoError(client.SetCmdClientContextHandler(s.baseCtx, cmd))
|
||||
|
||||
s.Require().Contains(fmt.Sprint(cmd), "votes-by-proposal [proposal-id] [] [] Query for votes by proposal id with pagination flags")
|
||||
s.Require().Contains(fmt.Sprint(cmd), tc.expCmdOutput)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *CLITestSuite) TestQueryTallyResult() {
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expCmdOutput string
|
||||
}{
|
||||
{
|
||||
name: "json output",
|
||||
args: []string{"1", fmt.Sprintf("--%s=json", flags.FlagOutput)},
|
||||
expCmdOutput: "1 --output=json",
|
||||
},
|
||||
{
|
||||
name: "text output",
|
||||
args: []string{"1", fmt.Sprintf("--%s=text", flags.FlagOutput)},
|
||||
expCmdOutput: "1 --output=text",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.QueryTallyResultCmd()
|
||||
|
||||
ctx := svrcmd.CreateExecuteContext(context.Background())
|
||||
|
||||
cmd.SetOut(io.Discard)
|
||||
s.Require().NotNil(cmd)
|
||||
|
||||
cmd.SetContext(ctx)
|
||||
cmd.SetArgs(tc.args)
|
||||
s.Require().NoError(client.SetCmdClientContextHandler(s.baseCtx, cmd))
|
||||
|
||||
s.Require().Contains(fmt.Sprint(cmd), "tally-result [proposal-id] [] [] Query tally result of proposal")
|
||||
s.Require().Contains(fmt.Sprint(cmd), tc.expCmdOutput)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *CLITestSuite) TestQueryVotesByVoter() {
|
||||
accounts := testutil.CreateKeyringAccounts(s.T(), s.kr, 1)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expCmdOutput string
|
||||
}{
|
||||
{
|
||||
name: "json output",
|
||||
args: []string{accounts[0].Address.String(), fmt.Sprintf("--%s=json", flags.FlagOutput)},
|
||||
expCmdOutput: fmt.Sprintf("%s --output=json", accounts[0].Address.String()),
|
||||
},
|
||||
{
|
||||
name: "text output",
|
||||
args: []string{accounts[0].Address.String(), fmt.Sprintf("--%s=text", flags.FlagOutput)},
|
||||
expCmdOutput: fmt.Sprintf("%s --output=text", accounts[0].Address.String()),
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.QueryVotesByVoterCmd()
|
||||
|
||||
ctx := svrcmd.CreateExecuteContext(context.Background())
|
||||
|
||||
cmd.SetOut(io.Discard)
|
||||
s.Require().NotNil(cmd)
|
||||
|
||||
cmd.SetContext(ctx)
|
||||
cmd.SetArgs(tc.args)
|
||||
s.Require().NoError(client.SetCmdClientContextHandler(s.baseCtx, cmd))
|
||||
|
||||
s.Require().Contains(fmt.Sprint(cmd), "votes-by-voter [voter] [] [] Query for votes by voter account address with pagination flags")
|
||||
s.Require().Contains(fmt.Sprint(cmd), tc.expCmdOutput)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *CLITestSuite) TestQueryGroupsByMembers() {
|
||||
accounts := testutil.CreateKeyringAccounts(s.T(), s.kr, 1)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expCmdOutput string
|
||||
}{
|
||||
{
|
||||
name: "json output",
|
||||
args: []string{accounts[0].Address.String(), fmt.Sprintf("--%s=json", flags.FlagOutput)},
|
||||
expCmdOutput: fmt.Sprintf("%s --output=json", accounts[0].Address.String()),
|
||||
},
|
||||
{
|
||||
name: "text output",
|
||||
args: []string{accounts[0].Address.String(), fmt.Sprintf("--%s=text", flags.FlagOutput)},
|
||||
expCmdOutput: fmt.Sprintf("%s --output=text", accounts[0].Address.String()),
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.QueryGroupsByMemberCmd()
|
||||
|
||||
ctx := svrcmd.CreateExecuteContext(context.Background())
|
||||
|
||||
cmd.SetOut(io.Discard)
|
||||
s.Require().NotNil(cmd)
|
||||
|
||||
cmd.SetContext(ctx)
|
||||
cmd.SetArgs(tc.args)
|
||||
s.Require().NoError(client.SetCmdClientContextHandler(s.baseCtx, cmd))
|
||||
|
||||
s.Require().Contains(fmt.Sprint(cmd), "groups-by-member [address] [] [] Query for groups by member address with pagination flags")
|
||||
s.Require().Contains(fmt.Sprint(cmd), tc.expCmdOutput)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test_ParseCLIProposal(t *testing.T) {
|
||||
func TestParseCLIProposal(t *testing.T) {
|
||||
data := []byte(`{
|
||||
"group_policy_address": "cosmos15r295x4994egvckteam9skazy9kvfvzpak4naf",
|
||||
"messages": [
|
||||
|
||||
@@ -39,6 +39,11 @@ func (k Keeper) getGroupInfo(ctx sdk.Context, id uint64) (group.GroupInfo, error
|
||||
|
||||
// GroupPolicyInfo queries info about a group policy.
|
||||
func (k Keeper) GroupPolicyInfo(goCtx context.Context, request *group.QueryGroupPolicyInfoRequest) (*group.QueryGroupPolicyInfoResponse, error) {
|
||||
_, err := k.accKeeper.AddressCodec().StringToBytes(request.Address)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||
groupPolicyInfo, err := k.getGroupPolicyInfo(ctx, request.Address)
|
||||
if err != nil {
|
||||
|
||||
@@ -3,6 +3,7 @@ package keeper_test
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -25,7 +26,16 @@ import (
|
||||
grouptestutil "github.com/cosmos/cosmos-sdk/x/group/testutil"
|
||||
)
|
||||
|
||||
func initKeeper(t *testing.T) (types.Context, groupkeeper.Keeper, []types.AccAddress, group.QueryClient) {
|
||||
type fixture struct {
|
||||
ctx types.Context
|
||||
keeper groupkeeper.Keeper
|
||||
queryClient group.QueryClient
|
||||
addrs []types.AccAddress
|
||||
defaultGroup *group.MsgCreateGroupWithPolicyResponse
|
||||
}
|
||||
|
||||
func initKeeper(t *testing.T) *fixture {
|
||||
t.Helper()
|
||||
var (
|
||||
groupKeeper groupkeeper.Keeper
|
||||
interfaceRegistry codectypes.InterfaceRegistry
|
||||
@@ -52,80 +62,329 @@ func initKeeper(t *testing.T) (types.Context, groupkeeper.Keeper, []types.AccAdd
|
||||
}
|
||||
accountKeeper.EXPECT().AddressCodec().Return(address.NewBech32Codec("cosmos")).AnyTimes()
|
||||
|
||||
groupKeeper = groupkeeper.NewKeeper(key, encCfg.Codec, bApp.MsgServiceRouter(), accountKeeper, group.DefaultConfig())
|
||||
// group policy expected calls
|
||||
accountKeeper.EXPECT().GetAccount(gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
|
||||
accountKeeper.EXPECT().NewAccount(gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
|
||||
accountKeeper.EXPECT().SetAccount(gomock.Any(), gomock.Any()).AnyTimes()
|
||||
|
||||
groupKeeper = groupkeeper.NewKeeper(key, encCfg.Codec, bApp.MsgServiceRouter(), accountKeeper, group.DefaultConfig())
|
||||
queryHelper := baseapp.NewQueryServerTestHelper(ctx, interfaceRegistry)
|
||||
group.RegisterQueryServer(queryHelper, groupKeeper)
|
||||
queryClient := group.NewQueryClient(queryHelper)
|
||||
|
||||
return ctx, groupKeeper, addrs, queryClient
|
||||
msgGroupAndPolicy := &group.MsgCreateGroupWithPolicy{
|
||||
Admin: addrs[0].String(),
|
||||
Members: []group.MemberRequest{
|
||||
{Address: addrs[1].String(), Weight: "1"},
|
||||
{Address: addrs[3].String(), Weight: "2"},
|
||||
},
|
||||
}
|
||||
err := msgGroupAndPolicy.SetDecisionPolicy(group.NewThresholdDecisionPolicy("2", time.Second, 20))
|
||||
require.NoError(t, err)
|
||||
|
||||
resp, err := groupKeeper.CreateGroupWithPolicy(ctx, msgGroupAndPolicy)
|
||||
require.NoError(t, err)
|
||||
|
||||
return &fixture{
|
||||
ctx: ctx,
|
||||
keeper: groupKeeper,
|
||||
queryClient: queryClient,
|
||||
addrs: addrs,
|
||||
defaultGroup: resp,
|
||||
}
|
||||
}
|
||||
|
||||
func TestQueryGroupInfo(t *testing.T) {
|
||||
fixture := initKeeper(t)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
req group.QueryGroupInfoRequest
|
||||
expErrMsg string
|
||||
}{
|
||||
{
|
||||
name: "invalid req",
|
||||
expErrMsg: "group: not found",
|
||||
},
|
||||
{
|
||||
name: "unknown id",
|
||||
req: group.QueryGroupInfoRequest{GroupId: 20},
|
||||
expErrMsg: "group: not found",
|
||||
},
|
||||
{
|
||||
name: "valid id",
|
||||
req: group.QueryGroupInfoRequest{GroupId: 1},
|
||||
expErrMsg: "",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
_, err := fixture.queryClient.GroupInfo(fixture.ctx, &tc.req)
|
||||
if tc.expErrMsg != "" {
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), tc.expErrMsg)
|
||||
} else {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestQueryGroupPolicyInfo(t *testing.T) {
|
||||
fixture := initKeeper(t)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
req group.QueryGroupPolicyInfoRequest
|
||||
expErrMsg string
|
||||
}{
|
||||
{
|
||||
name: "valid address",
|
||||
req: group.QueryGroupPolicyInfoRequest{Address: fixture.defaultGroup.GroupPolicyAddress},
|
||||
expErrMsg: "",
|
||||
},
|
||||
{
|
||||
name: "unexisting address",
|
||||
req: group.QueryGroupPolicyInfoRequest{Address: fixture.addrs[5].String()},
|
||||
expErrMsg: "group policy: not found",
|
||||
},
|
||||
{
|
||||
name: "invalid address",
|
||||
req: group.QueryGroupPolicyInfoRequest{Address: "invalid address"},
|
||||
expErrMsg: "decoding bech32 failed",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
_, err := fixture.queryClient.GroupPolicyInfo(fixture.ctx, &tc.req)
|
||||
if tc.expErrMsg != "" {
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), tc.expErrMsg)
|
||||
} else {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestQueryGroupMembers(t *testing.T) {
|
||||
fixture := initKeeper(t)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
req group.QueryGroupMembersRequest
|
||||
postRun func(resp *group.QueryGroupMembersResponse)
|
||||
expErrMsg string
|
||||
}{
|
||||
{
|
||||
name: "valid group",
|
||||
req: group.QueryGroupMembersRequest{GroupId: 1},
|
||||
postRun: func(resp *group.QueryGroupMembersResponse) {
|
||||
require.Len(t, resp.Members, 2)
|
||||
},
|
||||
expErrMsg: "",
|
||||
},
|
||||
{
|
||||
name: "unexisting group",
|
||||
req: group.QueryGroupMembersRequest{GroupId: 20},
|
||||
postRun: func(resp *group.QueryGroupMembersResponse) {
|
||||
require.Len(t, resp.Members, 0)
|
||||
},
|
||||
expErrMsg: "",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
resp, err := fixture.queryClient.GroupMembers(fixture.ctx, &tc.req)
|
||||
if tc.expErrMsg != "" {
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), tc.expErrMsg)
|
||||
} else {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
if tc.postRun != nil {
|
||||
tc.postRun(resp)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestQueryGroupsByAdmin(t *testing.T) {
|
||||
fixture := initKeeper(t)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
req group.QueryGroupsByAdminRequest
|
||||
postRun func(resp *group.QueryGroupsByAdminResponse)
|
||||
expErrMsg string
|
||||
}{
|
||||
{
|
||||
name: "valid admin",
|
||||
req: group.QueryGroupsByAdminRequest{Admin: fixture.addrs[0].String()},
|
||||
postRun: func(resp *group.QueryGroupsByAdminResponse) { require.Len(t, resp.Groups, 1) },
|
||||
expErrMsg: "",
|
||||
},
|
||||
{
|
||||
name: "unexisting address",
|
||||
req: group.QueryGroupsByAdminRequest{Admin: fixture.addrs[5].String()},
|
||||
postRun: func(resp *group.QueryGroupsByAdminResponse) { require.Len(t, resp.Groups, 0) },
|
||||
expErrMsg: "",
|
||||
},
|
||||
{
|
||||
name: "invalid address",
|
||||
req: group.QueryGroupsByAdminRequest{Admin: "invalid address"},
|
||||
expErrMsg: "decoding bech32 failed",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
resp, err := fixture.queryClient.GroupsByAdmin(fixture.ctx, &tc.req)
|
||||
if tc.expErrMsg != "" {
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), tc.expErrMsg)
|
||||
} else {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
if tc.postRun != nil {
|
||||
tc.postRun(resp)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestQueryGroupPoliciesByGroup(t *testing.T) {
|
||||
fixture := initKeeper(t)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
req group.QueryGroupPoliciesByGroupRequest
|
||||
postRun func(resp *group.QueryGroupPoliciesByGroupResponse)
|
||||
expErrMsg string
|
||||
}{
|
||||
{
|
||||
name: "valid group",
|
||||
req: group.QueryGroupPoliciesByGroupRequest{GroupId: 1},
|
||||
postRun: func(resp *group.QueryGroupPoliciesByGroupResponse) { require.Len(t, resp.GroupPolicies, 1) },
|
||||
expErrMsg: "",
|
||||
},
|
||||
{
|
||||
name: "unexisting group",
|
||||
req: group.QueryGroupPoliciesByGroupRequest{GroupId: 20},
|
||||
postRun: func(resp *group.QueryGroupPoliciesByGroupResponse) { require.Len(t, resp.GroupPolicies, 0) },
|
||||
expErrMsg: "",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
resp, err := fixture.keeper.GroupPoliciesByGroup(fixture.ctx, &tc.req)
|
||||
if tc.expErrMsg != "" {
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), tc.expErrMsg)
|
||||
} else {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
if tc.postRun != nil {
|
||||
tc.postRun(resp)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestQueryGroupPoliciesByAdmin(t *testing.T) {
|
||||
fixture := initKeeper(t)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
req group.QueryGroupPoliciesByAdminRequest
|
||||
postRun func(resp *group.QueryGroupPoliciesByAdminResponse)
|
||||
expErrMsg string
|
||||
}{
|
||||
{
|
||||
name: "valid admin",
|
||||
req: group.QueryGroupPoliciesByAdminRequest{Admin: fixture.addrs[0].String()},
|
||||
postRun: func(resp *group.QueryGroupPoliciesByAdminResponse) { require.Len(t, resp.GroupPolicies, 1) },
|
||||
expErrMsg: "",
|
||||
},
|
||||
{
|
||||
name: "unexisting address",
|
||||
req: group.QueryGroupPoliciesByAdminRequest{Admin: fixture.addrs[5].String()},
|
||||
postRun: func(resp *group.QueryGroupPoliciesByAdminResponse) { require.Len(t, resp.GroupPolicies, 0) },
|
||||
expErrMsg: "",
|
||||
},
|
||||
{
|
||||
name: "invalid address",
|
||||
req: group.QueryGroupPoliciesByAdminRequest{Admin: "invalid address"},
|
||||
expErrMsg: "decoding bech32 failed",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
resp, err := fixture.keeper.GroupPoliciesByAdmin(fixture.ctx, &tc.req)
|
||||
if tc.expErrMsg != "" {
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), tc.expErrMsg)
|
||||
} else {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
if tc.postRun != nil {
|
||||
tc.postRun(resp)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestQueryGroupsByMember(t *testing.T) {
|
||||
ctx, groupKeeper, addrs, queryClient := initKeeper(t)
|
||||
fixture := initKeeper(t)
|
||||
|
||||
// Initial group, group policy and balance setup
|
||||
members := []group.MemberRequest{
|
||||
{Address: addrs[2].String(), Weight: "1"}, {Address: addrs[3].String(), Weight: "2"},
|
||||
{Address: fixture.addrs[3].String(), Weight: "1"}, {Address: fixture.addrs[4].String(), Weight: "2"},
|
||||
}
|
||||
|
||||
_, err := groupKeeper.CreateGroup(ctx, &group.MsgCreateGroup{
|
||||
Admin: addrs[0].String(),
|
||||
Members: members,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
members = []group.MemberRequest{
|
||||
{Address: addrs[3].String(), Weight: "1"}, {Address: addrs[4].String(), Weight: "2"},
|
||||
}
|
||||
_, err = groupKeeper.CreateGroup(ctx, &group.MsgCreateGroup{
|
||||
Admin: addrs[1].String(),
|
||||
_, err := fixture.keeper.CreateGroup(fixture.ctx, &group.MsgCreateGroup{
|
||||
Admin: fixture.addrs[1].String(),
|
||||
Members: members,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
// not part of any group
|
||||
resp, err := queryClient.GroupsByMember(context.Background(), &group.QueryGroupsByMemberRequest{
|
||||
Address: addrs[5].String(),
|
||||
resp, err := fixture.queryClient.GroupsByMember(context.Background(), &group.QueryGroupsByMemberRequest{
|
||||
Address: fixture.addrs[5].String(),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, resp.Groups, 0)
|
||||
|
||||
// expect one group
|
||||
resp, err = queryClient.GroupsByMember(context.Background(), &group.QueryGroupsByMemberRequest{
|
||||
Address: addrs[4].String(),
|
||||
resp, err = fixture.queryClient.GroupsByMember(context.Background(), &group.QueryGroupsByMemberRequest{
|
||||
Address: fixture.addrs[4].String(),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, resp.Groups, 1)
|
||||
|
||||
// expect two groups
|
||||
resp, err = queryClient.GroupsByMember(context.Background(), &group.QueryGroupsByMemberRequest{
|
||||
Address: addrs[3].String(),
|
||||
resp, err = fixture.queryClient.GroupsByMember(context.Background(), &group.QueryGroupsByMemberRequest{
|
||||
Address: fixture.addrs[3].String(),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, resp.Groups, 2)
|
||||
}
|
||||
|
||||
func TestQueryGroups(t *testing.T) {
|
||||
ctx, groupKeeper, addrs, queryClient := initKeeper(t)
|
||||
fixture := initKeeper(t)
|
||||
|
||||
// Initial group, group policy and balance setup
|
||||
members := []group.MemberRequest{
|
||||
{Address: addrs[1].String(), Weight: "1"},
|
||||
{Address: addrs[3].String(), Weight: "2"},
|
||||
{Address: fixture.addrs[3].String(), Weight: "1"},
|
||||
}
|
||||
|
||||
_, err := groupKeeper.CreateGroup(ctx, &group.MsgCreateGroup{
|
||||
Admin: addrs[0].String(),
|
||||
Members: members,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
members = []group.MemberRequest{
|
||||
{Address: addrs[3].String(), Weight: "1"},
|
||||
}
|
||||
_, err = groupKeeper.CreateGroup(ctx, &group.MsgCreateGroup{
|
||||
Admin: addrs[2].String(),
|
||||
_, err := fixture.keeper.CreateGroup(fixture.ctx, &group.MsgCreateGroup{
|
||||
Admin: fixture.addrs[2].String(),
|
||||
Members: members,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
@@ -157,7 +416,7 @@ func TestQueryGroups(t *testing.T) {
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
resp, err := queryClient.Groups(context.Background(), &group.QueryGroupsRequest{
|
||||
resp, err := fixture.queryClient.Groups(context.Background(), &group.QueryGroupsRequest{
|
||||
Pagination: &query.PageRequest{
|
||||
Limit: tc.itemsPerPage,
|
||||
},
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
package module
|
||||
|
||||
import (
|
||||
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
|
||||
groupv1 "cosmossdk.io/api/cosmos/group/v1"
|
||||
)
|
||||
|
||||
// AutoCLIOptions implements the autocli.HasAutoCLIConfig interface.
|
||||
func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
|
||||
return &autocliv1.ModuleOptions{
|
||||
Query: &autocliv1.ServiceCommandDescriptor{
|
||||
Service: groupv1.Query_ServiceDesc.ServiceName,
|
||||
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
|
||||
{
|
||||
RpcMethod: "GroupInfo",
|
||||
Use: "group-info [group-id]",
|
||||
Short: "Query for group info by group id",
|
||||
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
|
||||
{ProtoField: "group_id"},
|
||||
},
|
||||
},
|
||||
{
|
||||
RpcMethod: "GroupPolicyInfo",
|
||||
Use: "group-policy-info [group-policy-account]",
|
||||
Short: "Query for group policy info by account address of group policy",
|
||||
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
|
||||
{ProtoField: "address"},
|
||||
},
|
||||
},
|
||||
{
|
||||
RpcMethod: "GroupMembers",
|
||||
Use: "group-members [group-id]",
|
||||
Short: "Query for group members by group id",
|
||||
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
|
||||
{ProtoField: "group_id"},
|
||||
},
|
||||
},
|
||||
{
|
||||
RpcMethod: "GroupsByAdmin",
|
||||
Use: "groups-by-admin [admin]",
|
||||
Short: "Query for groups by admin account address",
|
||||
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
|
||||
{ProtoField: "admin"},
|
||||
},
|
||||
},
|
||||
{
|
||||
RpcMethod: "GroupPoliciesByGroup",
|
||||
Use: "group-policies-by-group [group-id]",
|
||||
Short: "Query for group policies by group id",
|
||||
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
|
||||
{ProtoField: "group_id"},
|
||||
},
|
||||
},
|
||||
{
|
||||
RpcMethod: "GroupPoliciesByAdmin",
|
||||
Use: "group-policies-by-admin [admin]",
|
||||
Short: "Query for group policies by admin account address",
|
||||
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
|
||||
{ProtoField: "admin"},
|
||||
},
|
||||
},
|
||||
{
|
||||
RpcMethod: "Proposal",
|
||||
Use: "proposal [proposal-id]",
|
||||
Short: "Query for proposal by id",
|
||||
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
|
||||
{ProtoField: "proposal_id"},
|
||||
},
|
||||
},
|
||||
{
|
||||
RpcMethod: "ProposalsByGroupPolicy",
|
||||
Use: "proposals-by-group-policy [group-policy-account]",
|
||||
Short: "Query for proposals by account address of group policy",
|
||||
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
|
||||
{ProtoField: "address"},
|
||||
},
|
||||
},
|
||||
{
|
||||
RpcMethod: "VoteByProposalVoter",
|
||||
Use: "vote [proposal-id] [voter]",
|
||||
Short: "Query for vote by proposal id and voter account address",
|
||||
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
|
||||
{ProtoField: "proposal_id"},
|
||||
{ProtoField: "voter"},
|
||||
},
|
||||
},
|
||||
{
|
||||
RpcMethod: "VotesByProposal",
|
||||
Use: "votes-by-proposal [proposal-id]",
|
||||
Short: "Query for votes by proposal id",
|
||||
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
|
||||
{ProtoField: "proposal_id"},
|
||||
},
|
||||
},
|
||||
{
|
||||
RpcMethod: "VotesByVoter",
|
||||
Use: "votes-by-voter [voter]",
|
||||
Short: "Query for votes by voter account address",
|
||||
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
|
||||
{ProtoField: "voter"},
|
||||
},
|
||||
},
|
||||
{
|
||||
RpcMethod: "GroupsByMember",
|
||||
Use: "groups-by-member [address]",
|
||||
Short: "Query for groups by member address",
|
||||
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
|
||||
{ProtoField: "address"},
|
||||
},
|
||||
},
|
||||
{
|
||||
RpcMethod: "TallyResult",
|
||||
Use: "tally-result [proposal-id]",
|
||||
Short: "Query tally result of proposal",
|
||||
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
|
||||
{ProtoField: "proposal_id"},
|
||||
},
|
||||
},
|
||||
{
|
||||
RpcMethod: "Groups",
|
||||
Use: "groups",
|
||||
Short: "Query for all groups on chain",
|
||||
},
|
||||
},
|
||||
},
|
||||
Tx: &autocliv1.ServiceCommandDescriptor{
|
||||
Service: groupv1.Query_ServiceDesc.ServiceName,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -91,11 +91,6 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config sdkclient.TxEn
|
||||
return data.Validate()
|
||||
}
|
||||
|
||||
// GetQueryCmd returns the cli query commands for the group module
|
||||
func (a AppModuleBasic) GetQueryCmd() *cobra.Command {
|
||||
return cli.QueryCmd(a.Name())
|
||||
}
|
||||
|
||||
// GetTxCmd returns the transaction commands for the group module
|
||||
func (a AppModuleBasic) GetTxCmd() *cobra.Command {
|
||||
return cli.TxCmd(a.Name(), a.ac)
|
||||
|
||||
Reference in New Issue
Block a user