From 7cc1c351d2e4dd0174a3b3f72e388896cf8c2af9 Mon Sep 17 00:00:00 2001 From: Likhita Polavarapu <78951027+likhita-809@users.noreply.github.com> Date: Sat, 24 Dec 2022 04:43:54 +0530 Subject: [PATCH] refactor: x/group audit changes (#14278) --- api/cosmos/group/v1/query.pulsar.go | 4 +- api/cosmos/group/v1/query_grpc.pb.go | 12 +- api/cosmos/group/v1/tx.pulsar.go | 6 +- api/cosmos/group/v1/types.pulsar.go | 10 +- proto/cosmos/group/v1/query.proto | 31 +- proto/cosmos/group/v1/tx.proto | 7 +- proto/cosmos/group/v1/types.proto | 10 +- x/group/client/cli/prompt.go | 8 +- x/group/client/cli/query.go | 5 +- x/group/client/cli/query_test.go | 513 +++++++++++++++++++++++++++ x/group/client/cli/tx.go | 4 +- x/group/client/cli/tx_test.go | 18 +- x/group/client/cli/util.go | 2 + x/group/codec.go | 1 + x/group/genesis.go | 2 + x/group/keeper/genesis.go | 2 + x/group/keeper/grpc_query.go | 15 +- x/group/keeper/keeper_test.go | 3 + x/group/module/abci.go | 2 + x/group/msgs.go | 14 +- x/group/proposal.go | 2 + x/group/query.pb.go | 16 +- x/group/tx.pb.go | 6 +- x/group/types.go | 18 + x/group/types.pb.go | 10 +- 25 files changed, 636 insertions(+), 85 deletions(-) create mode 100644 x/group/client/cli/query_test.go diff --git a/api/cosmos/group/v1/query.pulsar.go b/api/cosmos/group/v1/query.pulsar.go index a281a95ce4..57235d65e7 100644 --- a/api/cosmos/group/v1/query.pulsar.go +++ b/api/cosmos/group/v1/query.pulsar.go @@ -12878,7 +12878,7 @@ type QueryGroupInfoResponse struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - // info is the GroupInfo for the group. + // info is the GroupInfo of the group. Info *GroupInfo `protobuf:"bytes,1,opt,name=info,proto3" json:"info,omitempty"` } @@ -12952,7 +12952,7 @@ type QueryGroupPolicyInfoResponse struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - // info is the GroupPolicyInfo for the group policy. + // info is the GroupPolicyInfo of the group policy. Info *GroupPolicyInfo `protobuf:"bytes,1,opt,name=info,proto3" json:"info,omitempty"` } diff --git a/api/cosmos/group/v1/query_grpc.pb.go b/api/cosmos/group/v1/query_grpc.pb.go index b9da9a6107..65c4419607 100644 --- a/api/cosmos/group/v1/query_grpc.pb.go +++ b/api/cosmos/group/v1/query_grpc.pb.go @@ -26,13 +26,13 @@ type QueryClient interface { GroupInfo(ctx context.Context, in *QueryGroupInfoRequest, opts ...grpc.CallOption) (*QueryGroupInfoResponse, error) // GroupPolicyInfo queries group policy info based on account address of group policy. GroupPolicyInfo(ctx context.Context, in *QueryGroupPolicyInfoRequest, opts ...grpc.CallOption) (*QueryGroupPolicyInfoResponse, error) - // GroupMembers queries members of a group + // GroupMembers queries members of a group by group id. GroupMembers(ctx context.Context, in *QueryGroupMembersRequest, opts ...grpc.CallOption) (*QueryGroupMembersResponse, error) // GroupsByAdmin queries groups by admin address. GroupsByAdmin(ctx context.Context, in *QueryGroupsByAdminRequest, opts ...grpc.CallOption) (*QueryGroupsByAdminResponse, error) // GroupPoliciesByGroup queries group policies by group id. GroupPoliciesByGroup(ctx context.Context, in *QueryGroupPoliciesByGroupRequest, opts ...grpc.CallOption) (*QueryGroupPoliciesByGroupResponse, error) - // GroupsByAdmin queries group policies by admin address. + // GroupPoliciesByAdmin queries group policies by admin address. GroupPoliciesByAdmin(ctx context.Context, in *QueryGroupPoliciesByAdminRequest, opts ...grpc.CallOption) (*QueryGroupPoliciesByAdminResponse, error) // Proposal queries a proposal based on proposal id. Proposal(ctx context.Context, in *QueryProposalRequest, opts ...grpc.CallOption) (*QueryProposalResponse, error) @@ -40,7 +40,7 @@ type QueryClient interface { ProposalsByGroupPolicy(ctx context.Context, in *QueryProposalsByGroupPolicyRequest, opts ...grpc.CallOption) (*QueryProposalsByGroupPolicyResponse, error) // VoteByProposalVoter queries a vote by proposal id and voter. VoteByProposalVoter(ctx context.Context, in *QueryVoteByProposalVoterRequest, opts ...grpc.CallOption) (*QueryVoteByProposalVoterResponse, error) - // VotesByProposal queries a vote by proposal. + // VotesByProposal queries a vote by proposal id. VotesByProposal(ctx context.Context, in *QueryVotesByProposalRequest, opts ...grpc.CallOption) (*QueryVotesByProposalResponse, error) // VotesByVoter queries a vote by voter. VotesByVoter(ctx context.Context, in *QueryVotesByVoterRequest, opts ...grpc.CallOption) (*QueryVotesByVoterResponse, error) @@ -187,13 +187,13 @@ type QueryServer interface { GroupInfo(context.Context, *QueryGroupInfoRequest) (*QueryGroupInfoResponse, error) // GroupPolicyInfo queries group policy info based on account address of group policy. GroupPolicyInfo(context.Context, *QueryGroupPolicyInfoRequest) (*QueryGroupPolicyInfoResponse, error) - // GroupMembers queries members of a group + // GroupMembers queries members of a group by group id. GroupMembers(context.Context, *QueryGroupMembersRequest) (*QueryGroupMembersResponse, error) // GroupsByAdmin queries groups by admin address. GroupsByAdmin(context.Context, *QueryGroupsByAdminRequest) (*QueryGroupsByAdminResponse, error) // GroupPoliciesByGroup queries group policies by group id. GroupPoliciesByGroup(context.Context, *QueryGroupPoliciesByGroupRequest) (*QueryGroupPoliciesByGroupResponse, error) - // GroupsByAdmin queries group policies by admin address. + // GroupPoliciesByAdmin queries group policies by admin address. GroupPoliciesByAdmin(context.Context, *QueryGroupPoliciesByAdminRequest) (*QueryGroupPoliciesByAdminResponse, error) // Proposal queries a proposal based on proposal id. Proposal(context.Context, *QueryProposalRequest) (*QueryProposalResponse, error) @@ -201,7 +201,7 @@ type QueryServer interface { ProposalsByGroupPolicy(context.Context, *QueryProposalsByGroupPolicyRequest) (*QueryProposalsByGroupPolicyResponse, error) // VoteByProposalVoter queries a vote by proposal id and voter. VoteByProposalVoter(context.Context, *QueryVoteByProposalVoterRequest) (*QueryVoteByProposalVoterResponse, error) - // VotesByProposal queries a vote by proposal. + // VotesByProposal queries a vote by proposal id. VotesByProposal(context.Context, *QueryVotesByProposalRequest) (*QueryVotesByProposalResponse, error) // VotesByVoter queries a vote by voter. VotesByVoter(context.Context, *QueryVotesByVoterRequest) (*QueryVotesByVoterResponse, error) diff --git a/api/cosmos/group/v1/tx.pulsar.go b/api/cosmos/group/v1/tx.pulsar.go index 2d9b105c8c..6de7bcb63e 100644 --- a/api/cosmos/group/v1/tx.pulsar.go +++ b/api/cosmos/group/v1/tx.pulsar.go @@ -14339,7 +14339,7 @@ type MsgUpdateGroupPolicyMetadata struct { Admin string `protobuf:"bytes,1,opt,name=admin,proto3" json:"admin,omitempty"` // group_policy_address is the account address of group policy. GroupPolicyAddress string `protobuf:"bytes,2,opt,name=group_policy_address,json=groupPolicyAddress,proto3" json:"group_policy_address,omitempty"` - // metadata is the updated group policy metadata. + // metadata is the group policy metadata to be updated. Metadata string `protobuf:"bytes,3,opt,name=metadata,proto3" json:"metadata,omitempty"` } @@ -14422,7 +14422,7 @@ type MsgSubmitProposal struct { // proposers are the account addresses of the proposers. // Proposers signatures will be counted as yes votes. Proposers []string `protobuf:"bytes,2,rep,name=proposers,proto3" json:"proposers,omitempty"` - // metadata is any arbitrary metadata to attached to the proposal. + // metadata is any arbitrary metadata attached to the proposal. Metadata string `protobuf:"bytes,3,opt,name=metadata,proto3" json:"metadata,omitempty"` // messages is a list of `sdk.Msg`s that will be executed if the proposal passes. Messages []*anypb.Any `protobuf:"bytes,4,rep,name=messages,proto3" json:"messages,omitempty"` @@ -14609,7 +14609,7 @@ type MsgVote struct { Voter string `protobuf:"bytes,2,opt,name=voter,proto3" json:"voter,omitempty"` // option is the voter's choice on the proposal. Option VoteOption `protobuf:"varint,3,opt,name=option,proto3,enum=cosmos.group.v1.VoteOption" json:"option,omitempty"` - // metadata is any arbitrary metadata to attached to the vote. + // metadata is any arbitrary metadata attached to the vote. Metadata string `protobuf:"bytes,4,opt,name=metadata,proto3" json:"metadata,omitempty"` // exec defines whether the proposal should be executed // immediately after voting or not. diff --git a/api/cosmos/group/v1/types.pulsar.go b/api/cosmos/group/v1/types.pulsar.go index 392c826184..b7dc2df137 100644 --- a/api/cosmos/group/v1/types.pulsar.go +++ b/api/cosmos/group/v1/types.pulsar.go @@ -7534,7 +7534,7 @@ func (x *MemberRequest) GetMetadata() string { // ThresholdDecisionPolicy is a decision policy where a proposal passes when it // satisfies the two following conditions: -// 1. The sum of all `YES` voters' weights is greater or equal than the defined +// 1. The sum of all `YES` voter's weights is greater or equal than the defined // `threshold`. // 2. The voting and execution periods of the proposal respect the parameters // given by `windows`. @@ -7595,7 +7595,7 @@ type PercentageDecisionPolicy struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - // percentage is the minimum percentage the weighted sum of `YES` votes must + // percentage is the minimum percentage of the weighted sum of `YES` votes must // meet for a proposal to succeed. Percentage string `protobuf:"bytes,1,opt,name=percentage,proto3" json:"percentage,omitempty"` // windows defines the different windows for voting and execution. @@ -7836,7 +7836,7 @@ type GroupPolicyInfo struct { GroupId uint64 `protobuf:"varint,2,opt,name=group_id,json=groupId,proto3" json:"group_id,omitempty"` // admin is the account address of the group admin. Admin string `protobuf:"bytes,3,opt,name=admin,proto3" json:"admin,omitempty"` - // metadata is any arbitrary metadata to attached to the group policy. + // metadata is any arbitrary metadata attached to the group policy. Metadata string `protobuf:"bytes,4,opt,name=metadata,proto3" json:"metadata,omitempty"` // version is used to track changes to a group's GroupPolicyInfo structure that // would create a different result on a running proposal. @@ -7929,7 +7929,7 @@ type Proposal struct { Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` // group_policy_address is the account address of group policy. GroupPolicyAddress string `protobuf:"bytes,2,opt,name=group_policy_address,json=groupPolicyAddress,proto3" json:"group_policy_address,omitempty"` - // metadata is any arbitrary metadata to attached to the proposal. + // metadata is any arbitrary metadata attached to the proposal. Metadata string `protobuf:"bytes,3,opt,name=metadata,proto3" json:"metadata,omitempty"` // proposers are the account addresses of the proposers. Proposers []string `protobuf:"bytes,4,rep,name=proposers,proto3" json:"proposers,omitempty"` @@ -8142,7 +8142,7 @@ type Vote struct { Voter string `protobuf:"bytes,2,opt,name=voter,proto3" json:"voter,omitempty"` // option is the voter's choice on the proposal. Option VoteOption `protobuf:"varint,3,opt,name=option,proto3,enum=cosmos.group.v1.VoteOption" json:"option,omitempty"` - // metadata is any arbitrary metadata to attached to the vote. + // metadata is any arbitrary metadata attached to the vote. Metadata string `protobuf:"bytes,4,opt,name=metadata,proto3" json:"metadata,omitempty"` // submit_time is the timestamp when the vote was submitted. SubmitTime *timestamppb.Timestamp `protobuf:"bytes,5,opt,name=submit_time,json=submitTime,proto3" json:"submit_time,omitempty"` diff --git a/proto/cosmos/group/v1/query.proto b/proto/cosmos/group/v1/query.proto index 7f69f99c6a..2cabc8e8f3 100644 --- a/proto/cosmos/group/v1/query.proto +++ b/proto/cosmos/group/v1/query.proto @@ -25,7 +25,7 @@ service Query { option (google.api.http).get = "/cosmos/group/v1/group_policy_info/{address}"; }; - // GroupMembers queries members of a group + // GroupMembers queries members of a group by group id. rpc GroupMembers(QueryGroupMembersRequest) returns (QueryGroupMembersResponse) { option (google.api.http).get = "/cosmos/group/v1/group_members/{group_id}"; }; @@ -40,7 +40,7 @@ service Query { option (google.api.http).get = "/cosmos/group/v1/group_policies_by_group/{group_id}"; }; - // GroupsByAdmin queries group policies by admin address. + // GroupPoliciesByAdmin queries group policies by admin address. rpc GroupPoliciesByAdmin(QueryGroupPoliciesByAdminRequest) returns (QueryGroupPoliciesByAdminResponse) { option (google.api.http).get = "/cosmos/group/v1/group_policies_by_admin/{admin}"; }; @@ -60,7 +60,7 @@ service Query { option (google.api.http).get = "/cosmos/group/v1/vote_by_proposal_voter/{proposal_id}/{voter}"; }; - // VotesByProposal queries a vote by proposal. + // VotesByProposal queries a vote by proposal id. rpc VotesByProposal(QueryVotesByProposalRequest) returns (QueryVotesByProposalResponse) { option (google.api.http).get = "/cosmos/group/v1/votes_by_proposal/{proposal_id}"; }; @@ -87,35 +87,30 @@ service Query { // QueryGroupInfoRequest is the Query/GroupInfo request type. message QueryGroupInfoRequest { - // group_id is the unique ID of the group. uint64 group_id = 1; } // QueryGroupInfoResponse is the Query/GroupInfo response type. message QueryGroupInfoResponse { - - // info is the GroupInfo for the group. + // info is the GroupInfo of the group. GroupInfo info = 1; } // QueryGroupPolicyInfoRequest is the Query/GroupPolicyInfo request type. message QueryGroupPolicyInfoRequest { - // address is the account address of the group policy. string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; } // QueryGroupPolicyInfoResponse is the Query/GroupPolicyInfo response type. message QueryGroupPolicyInfoResponse { - - // info is the GroupPolicyInfo for the group policy. + // info is the GroupPolicyInfo of the group policy. GroupPolicyInfo info = 1; } // QueryGroupMembersRequest is the Query/GroupMembers request type. message QueryGroupMembersRequest { - // group_id is the unique ID of the group. uint64 group_id = 1; @@ -125,7 +120,6 @@ message QueryGroupMembersRequest { // QueryGroupMembersResponse is the Query/GroupMembersResponse response type. message QueryGroupMembersResponse { - // members are the members of the group with given group_id. repeated GroupMember members = 1; @@ -135,7 +129,6 @@ message QueryGroupMembersResponse { // QueryGroupsByAdminRequest is the Query/GroupsByAdmin request type. message QueryGroupsByAdminRequest { - // admin is the account address of a group's admin. string admin = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; @@ -145,7 +138,6 @@ message QueryGroupsByAdminRequest { // QueryGroupsByAdminResponse is the Query/GroupsByAdminResponse response type. message QueryGroupsByAdminResponse { - // groups are the groups info with the provided admin. repeated GroupInfo groups = 1; @@ -155,7 +147,6 @@ message QueryGroupsByAdminResponse { // QueryGroupPoliciesByGroupRequest is the Query/GroupPoliciesByGroup request type. message QueryGroupPoliciesByGroupRequest { - // group_id is the unique ID of the group policy's group. uint64 group_id = 1; @@ -165,7 +156,6 @@ message QueryGroupPoliciesByGroupRequest { // QueryGroupPoliciesByGroupResponse is the Query/GroupPoliciesByGroup response type. message QueryGroupPoliciesByGroupResponse { - // group_policies are the group policies info associated with the provided group. repeated GroupPolicyInfo group_policies = 1; @@ -175,7 +165,6 @@ message QueryGroupPoliciesByGroupResponse { // QueryGroupPoliciesByAdminRequest is the Query/GroupPoliciesByAdmin request type. message QueryGroupPoliciesByAdminRequest { - // admin is the admin address of the group policy. string admin = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; @@ -185,7 +174,6 @@ message QueryGroupPoliciesByAdminRequest { // QueryGroupPoliciesByAdminResponse is the Query/GroupPoliciesByAdmin response type. message QueryGroupPoliciesByAdminResponse { - // group_policies are the group policies info with provided admin. repeated GroupPolicyInfo group_policies = 1; @@ -195,21 +183,18 @@ message QueryGroupPoliciesByAdminResponse { // QueryProposalRequest is the Query/Proposal request type. message QueryProposalRequest { - // proposal_id is the unique ID of a proposal. uint64 proposal_id = 1; } // QueryProposalResponse is the Query/Proposal response type. message QueryProposalResponse { - // proposal is the proposal info. Proposal proposal = 1; } // QueryProposalsByGroupPolicyRequest is the Query/ProposalByGroupPolicy request type. message QueryProposalsByGroupPolicyRequest { - // address is the account address of the group policy related to proposals. string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; @@ -219,7 +204,6 @@ message QueryProposalsByGroupPolicyRequest { // QueryProposalsByGroupPolicyResponse is the Query/ProposalByGroupPolicy response type. message QueryProposalsByGroupPolicyResponse { - // proposals are the proposals with given group policy. repeated Proposal proposals = 1; @@ -229,7 +213,6 @@ message QueryProposalsByGroupPolicyResponse { // QueryVoteByProposalVoterRequest is the Query/VoteByProposalVoter request type. message QueryVoteByProposalVoterRequest { - // proposal_id is the unique ID of a proposal. uint64 proposal_id = 1; @@ -239,14 +222,12 @@ message QueryVoteByProposalVoterRequest { // QueryVoteByProposalVoterResponse is the Query/VoteByProposalVoter response type. message QueryVoteByProposalVoterResponse { - // vote is the vote with given proposal_id and voter. Vote vote = 1; } // QueryVotesByProposalRequest is the Query/VotesByProposal request type. message QueryVotesByProposalRequest { - // proposal_id is the unique ID of a proposal. uint64 proposal_id = 1; @@ -256,7 +237,6 @@ message QueryVotesByProposalRequest { // QueryVotesByProposalResponse is the Query/VotesByProposal response type. message QueryVotesByProposalResponse { - // votes are the list of votes for given proposal_id. repeated Vote votes = 1; @@ -275,7 +255,6 @@ message QueryVotesByVoterRequest { // QueryVotesByVoterResponse is the Query/VotesByVoter response type. message QueryVotesByVoterResponse { - // votes are the list of votes by given voter. repeated Vote votes = 1; diff --git a/proto/cosmos/group/v1/tx.proto b/proto/cosmos/group/v1/tx.proto index cf8a278863..67e489d972 100644 --- a/proto/cosmos/group/v1/tx.proto +++ b/proto/cosmos/group/v1/tx.proto @@ -257,7 +257,7 @@ message MsgUpdateGroupPolicyMetadata { // group_policy_address is the account address of group policy. string group_policy_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"]; - // metadata is the updated group policy metadata. + // metadata is the group policy metadata to be updated. string metadata = 3; } @@ -296,7 +296,7 @@ message MsgSubmitProposal { // Proposers signatures will be counted as yes votes. repeated string proposers = 2; - // metadata is any arbitrary metadata to attached to the proposal. + // metadata is any arbitrary metadata attached to the proposal. string metadata = 3; // messages is a list of `sdk.Msg`s that will be executed if the proposal passes. @@ -337,13 +337,14 @@ message MsgVote { // proposal is the unique ID of the proposal. uint64 proposal_id = 1; + // voter is the voter account address. string voter = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // option is the voter's choice on the proposal. VoteOption option = 3; - // metadata is any arbitrary metadata to attached to the vote. + // metadata is any arbitrary metadata attached to the vote. string metadata = 4; // exec defines whether the proposal should be executed diff --git a/proto/cosmos/group/v1/types.proto b/proto/cosmos/group/v1/types.proto index 6891f54613..c5f05e2005 100644 --- a/proto/cosmos/group/v1/types.proto +++ b/proto/cosmos/group/v1/types.proto @@ -47,7 +47,7 @@ message MemberRequest { // ThresholdDecisionPolicy is a decision policy where a proposal passes when it // satisfies the two following conditions: -// 1. The sum of all `YES` voters' weights is greater or equal than the defined +// 1. The sum of all `YES` voter's weights is greater or equal than the defined // `threshold`. // 2. The voting and execution periods of the proposal respect the parameters // given by `windows`. @@ -73,7 +73,7 @@ message PercentageDecisionPolicy { option (cosmos_proto.implements_interface) = "DecisionPolicy"; option (amino.name) = "cosmos-sdk/PercentageDecisionPolicy"; - // percentage is the minimum percentage the weighted sum of `YES` votes must + // percentage is the minimum percentage of the weighted sum of `YES` votes must // meet for a proposal to succeed. string percentage = 1; @@ -174,7 +174,7 @@ message GroupPolicyInfo { // admin is the account address of the group admin. string admin = 3 [(cosmos_proto.scalar) = "cosmos.AddressString"]; - // metadata is any arbitrary metadata to attached to the group policy. + // metadata is any arbitrary metadata attached to the group policy. string metadata = 4; // version is used to track changes to a group's GroupPolicyInfo structure that @@ -202,7 +202,7 @@ message Proposal { // group_policy_address is the account address of group policy. string group_policy_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"]; - // metadata is any arbitrary metadata to attached to the proposal. + // metadata is any arbitrary metadata attached to the proposal. string metadata = 3; // proposers are the account addresses of the proposers. @@ -319,7 +319,7 @@ message Vote { // option is the voter's choice on the proposal. VoteOption option = 3; - // metadata is any arbitrary metadata to attached to the vote. + // metadata is any arbitrary metadata attached to the vote. string metadata = 4; // submit_time is the timestamp when the vote was submitted. diff --git a/x/group/client/cli/prompt.go b/x/group/client/cli/prompt.go index b8e446df56..11fabe8665 100644 --- a/x/group/client/cli/prompt.go +++ b/x/group/client/cli/prompt.go @@ -6,14 +6,15 @@ import ( "os" "sort" + "github.com/manifoldco/promptui" + "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - "github.com/manifoldco/promptui" - "github.com/spf13/cobra" ) const ( @@ -28,7 +29,7 @@ type proposalType struct { Msg sdk.Msg } -// Prompt the proposal type values and return the proposal and its metadata +// Prompt the proposal type values and return the proposal and its metadata. func (p *proposalType) Prompt(cdc codec.Codec) (*Proposal, govtypes.ProposalMetadata, error) { proposal := &Proposal{} @@ -146,6 +147,7 @@ func NewCmdDraftProposal() *cobra.Command { return cmd } +// writeFile writes the input to the file. func writeFile(fileName string, input any) error { raw, err := json.MarshalIndent(input, "", " ") if err != nil { diff --git a/x/group/client/cli/query.go b/x/group/client/cli/query.go index 1535566f52..85041f9d2f 100644 --- a/x/group/client/cli/query.go +++ b/x/group/client/cli/query.go @@ -3,10 +3,11 @@ 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" - "github.com/spf13/cobra" ) // QueryCmd returns the cli query commands for the group module. @@ -434,7 +435,7 @@ func QueryVotesByProposalCmd() *cobra.Command { return cmd } -// QueryVotesByProposalCmd creates a CLI command for Query/TallyResult. +// QueryTallyResultCmd creates a CLI command for Query/TallyResult. func QueryTallyResultCmd() *cobra.Command { cmd := &cobra.Command{ Use: "tally-result [proposal-id]", diff --git a/x/group/client/cli/query_test.go b/x/group/client/cli/query_test.go new file mode 100644 index 0000000000..5e9735abab --- /dev/null +++ b/x/group/client/cli/query_test.go @@ -0,0 +1,513 @@ +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) + }) + } +} diff --git a/x/group/client/cli/tx.go b/x/group/client/cli/tx.go index 54a7efb7c2..1231afc743 100644 --- a/x/group/client/cli/tx.go +++ b/x/group/client/cli/tx.go @@ -508,7 +508,7 @@ func MsgUpdateGroupPolicyDecisionPolicyCmd() *cobra.Command { return cmd } -// MsgUpdateGroupPolicyMetadataCmd creates a CLI command for Msg/MsgUpdateGroupPolicyMetadata. +// MsgUpdateGroupPolicyMetadataCmd creates a CLI command for Msg/UpdateGroupPolicyMetadata. func MsgUpdateGroupPolicyMetadataCmd() *cobra.Command { cmd := &cobra.Command{ Use: "update-group-policy-metadata [admin] [group-policy-account] [new-metadata]", @@ -736,7 +736,7 @@ Parameters: return cmd } -// MsgExecCmd creates a CLI command for Msg/MsgExec. +// MsgExecCmd creates a CLI command for Msg/Exec. func MsgExecCmd() *cobra.Command { cmd := &cobra.Command{ Use: "exec [proposal-id]", diff --git a/x/group/client/cli/tx_test.go b/x/group/client/cli/tx_test.go index 58106dba2c..8c5f6977c2 100644 --- a/x/group/client/cli/tx_test.go +++ b/x/group/client/cli/tx_test.go @@ -36,10 +36,10 @@ var tooLongMetadata = strings.Repeat("A", 256) type CLITestSuite struct { suite.Suite - kr keyring.Keyring - encCfg testutilmod.TestEncodingConfig - baseCtx client.Context - + kr keyring.Keyring + encCfg testutilmod.TestEncodingConfig + baseCtx client.Context + clientCtx client.Context group *group.GroupInfo commonFlags []string } @@ -77,10 +77,10 @@ func (s *CLITestSuite) SetupSuite() { }) return s.baseCtx.WithClient(c) } - clientCtx := ctxGen().WithOutput(&outBuf) + s.clientCtx = ctxGen().WithOutput(&outBuf) // create a new account - info, _, err := clientCtx.Keyring.NewMnemonic("NewValidator", keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1) + info, _, err := s.clientCtx.Keyring.NewMnemonic("NewValidator", keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1) s.Require().NoError(err) pk, err := info.GetPubKey() @@ -88,7 +88,7 @@ func (s *CLITestSuite) SetupSuite() { account := sdk.AccAddress(pk.Address()) _, err = clitestutil.MsgSendExec( - clientCtx, + s.clientCtx, val.Address, account, sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(2000))), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), @@ -110,7 +110,7 @@ func (s *CLITestSuite) SetupSuite() { ] }`, val.Address.String(), memberWeight, validMetadata) validMembersFile := testutil.WriteToNewTempFile(s.T(), validMembers) - out, err := clitestutil.ExecTestCLICmd(clientCtx, groupcli.MsgCreateGroupCmd(), + out, err := clitestutil.ExecTestCLICmd(s.clientCtx, groupcli.MsgCreateGroupCmd(), append( []string{ val.Address.String(), @@ -123,7 +123,7 @@ func (s *CLITestSuite) SetupSuite() { s.Require().NoError(err, out.String()) txResp := sdk.TxResponse{} - s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String()) + s.Require().NoError(s.clientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String()) s.Require().Equal(uint32(0), txResp.Code, out.String()) s.group = &group.GroupInfo{Id: 1, Admin: val.Address.String(), Metadata: validMetadata, TotalWeight: "3", Version: 1} diff --git a/x/group/client/cli/util.go b/x/group/client/cli/util.go index 801ee686ed..c5ff61cca7 100644 --- a/x/group/client/cli/util.go +++ b/x/group/client/cli/util.go @@ -10,6 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/group" ) +// parseDecisionPolicy reads and parses the decision policy. func parseDecisionPolicy(cdc codec.Codec, decisionPolicyFile string) (group.DecisionPolicy, error) { if decisionPolicyFile == "" { return nil, fmt.Errorf("decision policy is required") @@ -28,6 +29,7 @@ func parseDecisionPolicy(cdc codec.Codec, decisionPolicyFile string) (group.Deci return policy, nil } +// parseMembers reads and parses the members. func parseMembers(membersFile string) ([]group.MemberRequest, error) { members := group.MemberRequests{} diff --git a/x/group/codec.go b/x/group/codec.go index ef7f34e1f8..8e89a7da1e 100644 --- a/x/group/codec.go +++ b/x/group/codec.go @@ -35,6 +35,7 @@ func RegisterLegacyAminoCodec(cdc *codectypes.LegacyAmino) { legacy.RegisterAminoMsg(cdc, &MsgLeaveGroup{}, "cosmos-sdk/group/MsgLeaveGroup") } +// RegisterInterfaces registers the interfaces types with the interface registry. func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { registry.RegisterImplementations((*sdk.Msg)(nil), &MsgCreateGroup{}, diff --git a/x/group/genesis.go b/x/group/genesis.go index 0c1c0c7d73..51c64424ac 100644 --- a/x/group/genesis.go +++ b/x/group/genesis.go @@ -12,6 +12,8 @@ func NewGenesisState() *GenesisState { return &GenesisState{} } +// Validate performs basic genesis state validation returning an error upon any +// failure. func (s GenesisState) Validate() error { groups := make(map[uint64]GroupInfo) groupPolicies := make(map[string]GroupPolicyInfo) diff --git a/x/group/keeper/genesis.go b/x/group/keeper/genesis.go index 2e0766ed71..02027b6e74 100644 --- a/x/group/keeper/genesis.go +++ b/x/group/keeper/genesis.go @@ -11,6 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/group" ) +// InitGenesis initializes the group module's genesis state. func (k Keeper) InitGenesis(ctx types.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { var genesisState group.GenesisState cdc.MustUnmarshalJSON(data, &genesisState) @@ -42,6 +43,7 @@ func (k Keeper) InitGenesis(ctx types.Context, cdc codec.JSONCodec, data json.Ra return []abci.ValidatorUpdate{} } +// ExportGenesis returns the group module's exported genesis. func (k Keeper) ExportGenesis(ctx types.Context, cdc codec.JSONCodec) *group.GenesisState { genesisState := group.NewGenesisState() diff --git a/x/group/keeper/grpc_query.go b/x/group/keeper/grpc_query.go index ff26844dde..a314eb7a86 100644 --- a/x/group/keeper/grpc_query.go +++ b/x/group/keeper/grpc_query.go @@ -28,6 +28,7 @@ func (k Keeper) GroupInfo(goCtx context.Context, request *group.QueryGroupInfoRe return &group.QueryGroupInfoResponse{Info: &groupInfo}, nil } +// getGroupInfo gets the group info of the given group id. func (k Keeper) getGroupInfo(ctx sdk.Context, id uint64) (group.GroupInfo, error) { var obj group.GroupInfo _, err := k.groupTable.GetOne(ctx.KVStore(k.key), id, &obj) @@ -45,6 +46,7 @@ func (k Keeper) GroupPolicyInfo(goCtx context.Context, request *group.QueryGroup return &group.QueryGroupPolicyInfoResponse{Info: &groupPolicyInfo}, nil } +// getGroupPolicyInfo gets the group policy info of the given account address. func (k Keeper) getGroupPolicyInfo(ctx sdk.Context, accountAddress string) (group.GroupPolicyInfo, error) { var obj group.GroupPolicyInfo return obj, k.groupPolicyTable.GetOne(ctx.KVStore(k.key), orm.PrimaryKey(&group.GroupPolicyInfo{Address: accountAddress}), &obj) @@ -71,6 +73,7 @@ func (k Keeper) GroupMembers(goCtx context.Context, request *group.QueryGroupMem }, nil } +// getGroupMembers returns an iterator for the given group id and page request. func (k Keeper) getGroupMembers(ctx sdk.Context, id uint64, pageRequest *query.PageRequest) (orm.Iterator, error) { return k.groupMemberByGroupIndex.GetPaginated(ctx.KVStore(k.key), id, pageRequest) } @@ -99,6 +102,7 @@ func (k Keeper) GroupsByAdmin(goCtx context.Context, request *group.QueryGroupsB }, nil } +// getGroupsByAdmin returns an iterator for the given admin account address and page request. func (k Keeper) getGroupsByAdmin(ctx sdk.Context, admin sdk.AccAddress, pageRequest *query.PageRequest) (orm.Iterator, error) { return k.groupByAdminIndex.GetPaginated(ctx.KVStore(k.key), admin.Bytes(), pageRequest) } @@ -124,6 +128,7 @@ func (k Keeper) GroupPoliciesByGroup(goCtx context.Context, request *group.Query }, nil } +// getGroupPoliciesByGroup returns an iterator for the given group id and page request. func (k Keeper) getGroupPoliciesByGroup(ctx sdk.Context, id uint64, pageRequest *query.PageRequest) (orm.Iterator, error) { return k.groupPolicyByGroupIndex.GetPaginated(ctx.KVStore(k.key), id, pageRequest) } @@ -153,6 +158,7 @@ func (k Keeper) GroupPoliciesByAdmin(goCtx context.Context, request *group.Query }, nil } +// getGroupPoliciesByAdmin returns an iterator for the given admin account address and page request. func (k Keeper) getGroupPoliciesByAdmin(ctx sdk.Context, admin sdk.AccAddress, pageRequest *query.PageRequest) (orm.Iterator, error) { return k.groupPolicyByAdminIndex.GetPaginated(ctx.KVStore(k.key), admin.Bytes(), pageRequest) } @@ -169,7 +175,7 @@ func (k Keeper) Proposal(goCtx context.Context, request *group.QueryProposalRequ return &group.QueryProposalResponse{Proposal: &proposal}, nil } -// Proposal queries all proposals of a group policy. +// ProposalsByGroupPolicy queries all proposals of a group policy. func (k Keeper) ProposalsByGroupPolicy(goCtx context.Context, request *group.QueryProposalsByGroupPolicyRequest) (*group.QueryProposalsByGroupPolicyResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) addr, err := sdk.AccAddressFromBech32(request.Address) @@ -193,10 +199,12 @@ func (k Keeper) ProposalsByGroupPolicy(goCtx context.Context, request *group.Que }, nil } +// getProposalsByGroupPolicy returns an iterator for the given account address and page request. func (k Keeper) getProposalsByGroupPolicy(ctx sdk.Context, account sdk.AccAddress, pageRequest *query.PageRequest) (orm.Iterator, error) { return k.proposalByGroupPolicyIndex.GetPaginated(ctx.KVStore(k.key), account.Bytes(), pageRequest) } +// getProposal gets the proposal info of the given proposal id. func (k Keeper) getProposal(ctx sdk.Context, proposalID uint64) (group.Proposal, error) { var p group.Proposal if _, err := k.proposalTable.GetOne(ctx.KVStore(k.key), proposalID, &p); err != nil { @@ -243,7 +251,7 @@ func (k Keeper) VotesByProposal(goCtx context.Context, request *group.QueryVotes }, nil } -// VotesByProposal queries all votes of a voter. +// VotesByVoter queries all votes of a voter. func (k Keeper) VotesByVoter(goCtx context.Context, request *group.QueryVotesByVoterRequest) (*group.QueryVotesByVoterResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) addr, err := sdk.AccAddressFromBech32(request.Voter) @@ -305,15 +313,18 @@ func (k Keeper) GroupsByMember(goCtx context.Context, request *group.QueryGroups }, nil } +// getVote gets the vote info for the given proposal id and voter address. func (k Keeper) getVote(ctx sdk.Context, proposalID uint64, voter sdk.AccAddress) (group.Vote, error) { var v group.Vote return v, k.voteTable.GetOne(ctx.KVStore(k.key), orm.PrimaryKey(&group.Vote{ProposalId: proposalID, Voter: voter.String()}), &v) } +// getVotesByProposal returns an iterator for the given proposal id and page request. func (k Keeper) getVotesByProposal(ctx sdk.Context, proposalID uint64, pageRequest *query.PageRequest) (orm.Iterator, error) { return k.voteByProposalIndex.GetPaginated(ctx.KVStore(k.key), proposalID, pageRequest) } +// getVotesByVoter returns an iterator for the given voter address and page request. func (k Keeper) getVotesByVoter(ctx sdk.Context, voter sdk.AccAddress, pageRequest *query.PageRequest) (orm.Iterator, error) { return k.voteByVoterIndex.GetPaginated(ctx.KVStore(k.key), voter.Bytes(), pageRequest) } diff --git a/x/group/keeper/keeper_test.go b/x/group/keeper/keeper_test.go index f8c24db880..2c4cb91849 100644 --- a/x/group/keeper/keeper_test.go +++ b/x/group/keeper/keeper_test.go @@ -106,6 +106,9 @@ func (s *TestSuite) SetupTest() { s.Require().NoError(err) s.setNextAccount() + groupSeq := s.groupKeeper.GetGroupSequence(s.sdkCtx) + s.Require().Equal(groupSeq, uint64(1)) + policyRes, err := s.groupKeeper.CreateGroupPolicy(s.ctx, policyReq) s.Require().NoError(err) s.policy = policy diff --git a/x/group/module/abci.go b/x/group/module/abci.go index 22809b61d6..02cee6517e 100644 --- a/x/group/module/abci.go +++ b/x/group/module/abci.go @@ -5,6 +5,8 @@ import ( "github.com/cosmos/cosmos-sdk/x/group/keeper" ) +// EndBlocker called at every block, updates proposal's `FinalTallyResult` and +// prunes expired proposals. func EndBlocker(ctx sdk.Context, k keeper.Keeper) { if err := k.TallyProposalsAtVPEnd(ctx); err != nil { panic(err) diff --git a/x/group/msgs.go b/x/group/msgs.go index 700d33975a..dcaf7ab6ad 100644 --- a/x/group/msgs.go +++ b/x/group/msgs.go @@ -82,7 +82,7 @@ func (m MsgUpdateGroupAdmin) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{admin} } -// ValidateBasic does a sanity check on the provided data +// ValidateBasic does a sanity check on the provided data. func (m MsgUpdateGroupAdmin) ValidateBasic() error { if m.GroupId == 0 { return sdkerrors.Wrap(errors.ErrEmpty, "group id") @@ -104,6 +104,7 @@ func (m MsgUpdateGroupAdmin) ValidateBasic() error { return nil } +// GetGroupID gets the group id of the MsgUpdateGroupAdmin. func (m *MsgUpdateGroupAdmin) GetGroupID() uint64 { return m.GroupId } @@ -143,6 +144,7 @@ func (m MsgUpdateGroupMetadata) ValidateBasic() error { return nil } +// GetGroupID gets the group id of the MsgUpdateGroupMetadata. func (m *MsgUpdateGroupMetadata) GetGroupID() uint64 { return m.GroupId } @@ -191,6 +193,7 @@ func (m MsgUpdateGroupMembers) ValidateBasic() error { return nil } +// GetGroupID gets the group id of the MsgUpdateGroupMembers. func (m *MsgUpdateGroupMembers) GetGroupID() uint64 { return m.GroupId } @@ -216,6 +219,7 @@ func NewMsgCreateGroupWithPolicy(admin string, members []MemberRequest, groupMet return m, nil } +// GetDecisionPolicy gets the decision policy of MsgCreateGroupWithPolicy. func (m *MsgCreateGroupWithPolicy) GetDecisionPolicy() (DecisionPolicy, error) { decisionPolicy, ok := m.DecisionPolicy.GetCachedValue().(DecisionPolicy) if !ok { @@ -224,6 +228,7 @@ func (m *MsgCreateGroupWithPolicy) GetDecisionPolicy() (DecisionPolicy, error) { return decisionPolicy, nil } +// SetDecisionPolicy sets the decision policy for MsgCreateGroupWithPolicy. func (m *MsgCreateGroupWithPolicy) SetDecisionPolicy(decisionPolicy DecisionPolicy) error { any, err := types.NewAnyWithValue(decisionPolicy) if err != nil { @@ -382,6 +387,7 @@ func NewMsgUpdateGroupPolicyDecisionPolicy(admin sdk.AccAddress, address sdk.Acc return m, nil } +// SetDecisionPolicy sets the decision policy for MsgUpdateGroupPolicyDecisionPolicy. func (m *MsgUpdateGroupPolicyDecisionPolicy) SetDecisionPolicy(decisionPolicy DecisionPolicy) error { msg, ok := decisionPolicy.(proto.Message) if !ok { @@ -441,6 +447,7 @@ func (m MsgUpdateGroupPolicyDecisionPolicy) ValidateBasic() error { return nil } +// GetDecisionPolicy gets the decision policy of MsgUpdateGroupPolicyDecisionPolicy. func (m *MsgUpdateGroupPolicyDecisionPolicy) GetDecisionPolicy() (DecisionPolicy, error) { decisionPolicy, ok := m.DecisionPolicy.GetCachedValue().(DecisionPolicy) if !ok { @@ -512,18 +519,22 @@ func NewMsgCreateGroupPolicy(admin sdk.AccAddress, group uint64, metadata string return m, nil } +// GetAdmin gets the admin of MsgCreateGroupPolicy. func (m *MsgCreateGroupPolicy) GetAdmin() string { return m.Admin } +// GetGroupID gets the group id of MsgCreateGroupPolicy. func (m *MsgCreateGroupPolicy) GetGroupID() uint64 { return m.GroupId } +// GetMetadata gets the metadata of MsgCreateGroupPolicy. func (m *MsgCreateGroupPolicy) GetMetadata() string { return m.Metadata } +// GetDecisionPolicy gets the decision policy of MsgCreateGroupPolicy. func (m *MsgCreateGroupPolicy) GetDecisionPolicy() (DecisionPolicy, error) { decisionPolicy, ok := m.DecisionPolicy.GetCachedValue().(DecisionPolicy) if !ok { @@ -532,6 +543,7 @@ func (m *MsgCreateGroupPolicy) GetDecisionPolicy() (DecisionPolicy, error) { return decisionPolicy, nil } +// SetDecisionPolicy sets the decision policy of MsgCreateGroupPolicy. func (m *MsgCreateGroupPolicy) SetDecisionPolicy(decisionPolicy DecisionPolicy) error { any, err := types.NewAnyWithValue(decisionPolicy) if err != nil { diff --git a/x/group/proposal.go b/x/group/proposal.go index 3b3870af28..a47ee5115c 100644 --- a/x/group/proposal.go +++ b/x/group/proposal.go @@ -6,10 +6,12 @@ import ( "github.com/cosmos/cosmos-sdk/types/tx" ) +// GetMsgs unpacks p.Messages Any's into sdk.Msg's func (p *Proposal) GetMsgs() ([]sdk.Msg, error) { return tx.GetMsgs(p.Messages, "proposal") } +// SetMsgs packs msgs into Any's func (p *Proposal) SetMsgs(msgs []sdk.Msg) error { anys, err := tx.SetMsgs(msgs) if err != nil { diff --git a/x/group/query.pb.go b/x/group/query.pb.go index e0eb895704..1ba62f788f 100644 --- a/x/group/query.pb.go +++ b/x/group/query.pb.go @@ -80,7 +80,7 @@ func (m *QueryGroupInfoRequest) GetGroupId() uint64 { // QueryGroupInfoResponse is the Query/GroupInfo response type. type QueryGroupInfoResponse struct { - // info is the GroupInfo for the group. + // info is the GroupInfo of the group. Info *GroupInfo `protobuf:"bytes,1,opt,name=info,proto3" json:"info,omitempty"` } @@ -172,7 +172,7 @@ func (m *QueryGroupPolicyInfoRequest) GetAddress() string { // QueryGroupPolicyInfoResponse is the Query/GroupPolicyInfo response type. type QueryGroupPolicyInfoResponse struct { - // info is the GroupPolicyInfo for the group policy. + // info is the GroupPolicyInfo of the group policy. Info *GroupPolicyInfo `protobuf:"bytes,1,opt,name=info,proto3" json:"info,omitempty"` } @@ -1512,13 +1512,13 @@ type QueryClient interface { GroupInfo(ctx context.Context, in *QueryGroupInfoRequest, opts ...grpc.CallOption) (*QueryGroupInfoResponse, error) // GroupPolicyInfo queries group policy info based on account address of group policy. GroupPolicyInfo(ctx context.Context, in *QueryGroupPolicyInfoRequest, opts ...grpc.CallOption) (*QueryGroupPolicyInfoResponse, error) - // GroupMembers queries members of a group + // GroupMembers queries members of a group by group id. GroupMembers(ctx context.Context, in *QueryGroupMembersRequest, opts ...grpc.CallOption) (*QueryGroupMembersResponse, error) // GroupsByAdmin queries groups by admin address. GroupsByAdmin(ctx context.Context, in *QueryGroupsByAdminRequest, opts ...grpc.CallOption) (*QueryGroupsByAdminResponse, error) // GroupPoliciesByGroup queries group policies by group id. GroupPoliciesByGroup(ctx context.Context, in *QueryGroupPoliciesByGroupRequest, opts ...grpc.CallOption) (*QueryGroupPoliciesByGroupResponse, error) - // GroupsByAdmin queries group policies by admin address. + // GroupPoliciesByAdmin queries group policies by admin address. GroupPoliciesByAdmin(ctx context.Context, in *QueryGroupPoliciesByAdminRequest, opts ...grpc.CallOption) (*QueryGroupPoliciesByAdminResponse, error) // Proposal queries a proposal based on proposal id. Proposal(ctx context.Context, in *QueryProposalRequest, opts ...grpc.CallOption) (*QueryProposalResponse, error) @@ -1526,7 +1526,7 @@ type QueryClient interface { ProposalsByGroupPolicy(ctx context.Context, in *QueryProposalsByGroupPolicyRequest, opts ...grpc.CallOption) (*QueryProposalsByGroupPolicyResponse, error) // VoteByProposalVoter queries a vote by proposal id and voter. VoteByProposalVoter(ctx context.Context, in *QueryVoteByProposalVoterRequest, opts ...grpc.CallOption) (*QueryVoteByProposalVoterResponse, error) - // VotesByProposal queries a vote by proposal. + // VotesByProposal queries a vote by proposal id. VotesByProposal(ctx context.Context, in *QueryVotesByProposalRequest, opts ...grpc.CallOption) (*QueryVotesByProposalResponse, error) // VotesByVoter queries a vote by voter. VotesByVoter(ctx context.Context, in *QueryVotesByVoterRequest, opts ...grpc.CallOption) (*QueryVotesByVoterResponse, error) @@ -1671,13 +1671,13 @@ type QueryServer interface { GroupInfo(context.Context, *QueryGroupInfoRequest) (*QueryGroupInfoResponse, error) // GroupPolicyInfo queries group policy info based on account address of group policy. GroupPolicyInfo(context.Context, *QueryGroupPolicyInfoRequest) (*QueryGroupPolicyInfoResponse, error) - // GroupMembers queries members of a group + // GroupMembers queries members of a group by group id. GroupMembers(context.Context, *QueryGroupMembersRequest) (*QueryGroupMembersResponse, error) // GroupsByAdmin queries groups by admin address. GroupsByAdmin(context.Context, *QueryGroupsByAdminRequest) (*QueryGroupsByAdminResponse, error) // GroupPoliciesByGroup queries group policies by group id. GroupPoliciesByGroup(context.Context, *QueryGroupPoliciesByGroupRequest) (*QueryGroupPoliciesByGroupResponse, error) - // GroupsByAdmin queries group policies by admin address. + // GroupPoliciesByAdmin queries group policies by admin address. GroupPoliciesByAdmin(context.Context, *QueryGroupPoliciesByAdminRequest) (*QueryGroupPoliciesByAdminResponse, error) // Proposal queries a proposal based on proposal id. Proposal(context.Context, *QueryProposalRequest) (*QueryProposalResponse, error) @@ -1685,7 +1685,7 @@ type QueryServer interface { ProposalsByGroupPolicy(context.Context, *QueryProposalsByGroupPolicyRequest) (*QueryProposalsByGroupPolicyResponse, error) // VoteByProposalVoter queries a vote by proposal id and voter. VoteByProposalVoter(context.Context, *QueryVoteByProposalVoterRequest) (*QueryVoteByProposalVoterResponse, error) - // VotesByProposal queries a vote by proposal. + // VotesByProposal queries a vote by proposal id. VotesByProposal(context.Context, *QueryVotesByProposalRequest) (*QueryVotesByProposalResponse, error) // VotesByVoter queries a vote by voter. VotesByVoter(context.Context, *QueryVotesByVoterRequest) (*QueryVotesByVoterResponse, error) diff --git a/x/group/tx.pb.go b/x/group/tx.pb.go index c472341c6a..a7b8a9b596 100644 --- a/x/group/tx.pb.go +++ b/x/group/tx.pb.go @@ -865,7 +865,7 @@ type MsgUpdateGroupPolicyMetadata struct { Admin string `protobuf:"bytes,1,opt,name=admin,proto3" json:"admin,omitempty"` // group_policy_address is the account address of group policy. GroupPolicyAddress string `protobuf:"bytes,2,opt,name=group_policy_address,json=groupPolicyAddress,proto3" json:"group_policy_address,omitempty"` - // metadata is the updated group policy metadata. + // metadata is the group policy metadata to be updated. Metadata string `protobuf:"bytes,3,opt,name=metadata,proto3" json:"metadata,omitempty"` } @@ -967,7 +967,7 @@ type MsgSubmitProposal struct { // proposers are the account addresses of the proposers. // Proposers signatures will be counted as yes votes. Proposers []string `protobuf:"bytes,2,rep,name=proposers,proto3" json:"proposers,omitempty"` - // metadata is any arbitrary metadata to attached to the proposal. + // metadata is any arbitrary metadata attached to the proposal. Metadata string `protobuf:"bytes,3,opt,name=metadata,proto3" json:"metadata,omitempty"` // messages is a list of `sdk.Msg`s that will be executed if the proposal passes. Messages []*types.Any `protobuf:"bytes,4,rep,name=messages,proto3" json:"messages,omitempty"` @@ -1156,7 +1156,7 @@ type MsgVote struct { Voter string `protobuf:"bytes,2,opt,name=voter,proto3" json:"voter,omitempty"` // option is the voter's choice on the proposal. Option VoteOption `protobuf:"varint,3,opt,name=option,proto3,enum=cosmos.group.v1.VoteOption" json:"option,omitempty"` - // metadata is any arbitrary metadata to attached to the vote. + // metadata is any arbitrary metadata attached to the vote. Metadata string `protobuf:"bytes,4,opt,name=metadata,proto3" json:"metadata,omitempty"` // exec defines whether the proposal should be executed // immediately after voting or not. diff --git a/x/group/types.go b/x/group/types.go index af3c93cd38..750921d8d5 100644 --- a/x/group/types.go +++ b/x/group/types.go @@ -53,14 +53,17 @@ func NewThresholdDecisionPolicy(threshold string, votingPeriod time.Duration, mi return &ThresholdDecisionPolicy{threshold, &DecisionPolicyWindows{votingPeriod, minExecutionPeriod}} } +// GetVotingPeriod returns the voitng period of ThresholdDecisionPolicy func (p ThresholdDecisionPolicy) GetVotingPeriod() time.Duration { return p.Windows.VotingPeriod } +// GetMinExecutionPeriod returns the minimum execution period of ThresholdDecisionPolicy func (p ThresholdDecisionPolicy) GetMinExecutionPeriod() time.Duration { return p.Windows.MinExecutionPeriod } +// ValidateBasic does basic validation on ThresholdDecisionPolicy func (p ThresholdDecisionPolicy) ValidateBasic() error { if _, err := math.NewPositiveDecFromString(p.Threshold); err != nil { return sdkerrors.Wrap(err, "threshold") @@ -155,14 +158,17 @@ func NewPercentageDecisionPolicy(percentage string, votingPeriod time.Duration, return &PercentageDecisionPolicy{percentage, &DecisionPolicyWindows{votingPeriod, executionPeriod}} } +// GetVotingPeriod returns the voitng period of PercentageDecisionPolicy func (p PercentageDecisionPolicy) GetVotingPeriod() time.Duration { return p.Windows.VotingPeriod } +// GetMinExecutionPeriod returns the minimum execution period of PercentageDecisionPolicy func (p PercentageDecisionPolicy) GetMinExecutionPeriod() time.Duration { return p.Windows.MinExecutionPeriod } +// ValidateBasic does basic validation on PercentageDecisionPolicy func (p PercentageDecisionPolicy) ValidateBasic() error { percentage, err := math.NewPositiveDecFromString(p.Percentage) if err != nil { @@ -179,6 +185,7 @@ func (p PercentageDecisionPolicy) ValidateBasic() error { return nil } +// Validate validates the policy against the group. func (p *PercentageDecisionPolicy) Validate(g GroupInfo, config Config) error { if p.Windows.MinExecutionPeriod > p.Windows.VotingPeriod+config.MaxExecutionPeriod { return sdkerrors.Wrap(errors.ErrInvalid, "min_execution_period should be smaller than voting_period + max_execution_period") @@ -255,6 +262,7 @@ func NewGroupPolicyInfo(address sdk.AccAddress, group uint64, admin sdk.AccAddre return p, nil } +// SetDecisionPolicy sets the decision policy for GroupPolicyInfo. func (g *GroupPolicyInfo) SetDecisionPolicy(decisionPolicy DecisionPolicy) error { any, err := codectypes.NewAnyWithValue(decisionPolicy) if err != nil { @@ -264,6 +272,7 @@ func (g *GroupPolicyInfo) SetDecisionPolicy(decisionPolicy DecisionPolicy) error return nil } +// GetDecisionPolicy gets the decision policy of GroupPolicyInfo func (g GroupPolicyInfo) GetDecisionPolicy() (DecisionPolicy, error) { decisionPolicy, ok := g.DecisionPolicy.GetCachedValue().(DecisionPolicy) if !ok { @@ -283,6 +292,7 @@ func (g GroupInfo) PrimaryKeyFields() []interface{} { return []interface{}{g.Id} } +// ValidateBasic does basic validation on group info. func (g GroupInfo) ValidateBasic() error { if g.Id == 0 { return sdkerrors.Wrap(errors.ErrEmpty, "group's GroupId") @@ -312,6 +322,7 @@ func (g Proposal) PrimaryKeyFields() []interface{} { return []interface{}{g.Id} } +// ValidateBasic does basic validation on group policy info. func (g GroupPolicyInfo) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(g.Admin) if err != nil { @@ -345,6 +356,7 @@ func (g GroupMember) PrimaryKeyFields() []interface{} { return []interface{}{g.GroupId, addr.Bytes()} } +// ValidateBasic does basic validation on group member. func (g GroupMember) ValidateBasic() error { if g.GroupId == 0 { return sdkerrors.Wrap(errors.ErrEmpty, "group member's group id") @@ -369,6 +381,7 @@ func MemberToMemberRequest(m *Member) MemberRequest { } } +// ValidateBasic does basic validation on proposal. func (g Proposal) ValidateBasic() error { if g.Id == 0 { return sdkerrors.Wrap(errors.ErrEmpty, "proposal id") @@ -410,6 +423,7 @@ func (v Vote) PrimaryKeyFields() []interface{} { var _ orm.Validateable = Vote{} +// ValidateBasic does basic validation on vote. func (v Vote) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(v.Voter) if err != nil { @@ -504,6 +518,7 @@ func (t *TallyResult) operation(vote Vote, weight string, op operation) error { return nil } +// GetYesCount returns the number of yes counts from tally result. func (t TallyResult) GetYesCount() (math.Dec, error) { yesCount, err := math.NewNonNegativeDecFromString(t.YesCount) if err != nil { @@ -512,6 +527,7 @@ func (t TallyResult) GetYesCount() (math.Dec, error) { return yesCount, nil } +// GetNoCount returns the number of no counts from tally result. func (t TallyResult) GetNoCount() (math.Dec, error) { noCount, err := math.NewNonNegativeDecFromString(t.NoCount) if err != nil { @@ -520,6 +536,7 @@ func (t TallyResult) GetNoCount() (math.Dec, error) { return noCount, nil } +// GetAbstainCount returns the number of abstain counts from tally result. func (t TallyResult) GetAbstainCount() (math.Dec, error) { abstainCount, err := math.NewNonNegativeDecFromString(t.AbstainCount) if err != nil { @@ -528,6 +545,7 @@ func (t TallyResult) GetAbstainCount() (math.Dec, error) { return abstainCount, nil } +// GetNoWithVetoCount returns the number of no with veto counts from tally result. func (t TallyResult) GetNoWithVetoCount() (math.Dec, error) { vetoCount, err := math.NewNonNegativeDecFromString(t.NoWithVetoCount) if err != nil { diff --git a/x/group/types.pb.go b/x/group/types.pb.go index b328ddddee..41436d1fcc 100644 --- a/x/group/types.pb.go +++ b/x/group/types.pb.go @@ -298,7 +298,7 @@ func (m *MemberRequest) GetMetadata() string { // ThresholdDecisionPolicy is a decision policy where a proposal passes when it // satisfies the two following conditions: -// 1. The sum of all `YES` voters' weights is greater or equal than the defined +// 1. The sum of all `YES` voter's weights is greater or equal than the defined // `threshold`. // 2. The voting and execution periods of the proposal respect the parameters // given by `windows`. @@ -364,7 +364,7 @@ func (m *ThresholdDecisionPolicy) GetWindows() *DecisionPolicyWindows { // 2. The voting and execution periods of the proposal respect the parameters // given by `windows`. type PercentageDecisionPolicy struct { - // percentage is the minimum percentage the weighted sum of `YES` votes must + // percentage is the minimum percentage of the weighted sum of `YES` votes must // meet for a proposal to succeed. Percentage string `protobuf:"bytes,1,opt,name=percentage,proto3" json:"percentage,omitempty"` // windows defines the different windows for voting and execution. @@ -641,7 +641,7 @@ type GroupPolicyInfo struct { GroupId uint64 `protobuf:"varint,2,opt,name=group_id,json=groupId,proto3" json:"group_id,omitempty"` // admin is the account address of the group admin. Admin string `protobuf:"bytes,3,opt,name=admin,proto3" json:"admin,omitempty"` - // metadata is any arbitrary metadata to attached to the group policy. + // metadata is any arbitrary metadata attached to the group policy. Metadata string `protobuf:"bytes,4,opt,name=metadata,proto3" json:"metadata,omitempty"` // version is used to track changes to a group's GroupPolicyInfo structure that // would create a different result on a running proposal. @@ -694,7 +694,7 @@ type Proposal struct { Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` // group_policy_address is the account address of group policy. GroupPolicyAddress string `protobuf:"bytes,2,opt,name=group_policy_address,json=groupPolicyAddress,proto3" json:"group_policy_address,omitempty"` - // metadata is any arbitrary metadata to attached to the proposal. + // metadata is any arbitrary metadata attached to the proposal. Metadata string `protobuf:"bytes,3,opt,name=metadata,proto3" json:"metadata,omitempty"` // proposers are the account addresses of the proposers. Proposers []string `protobuf:"bytes,4,rep,name=proposers,proto3" json:"proposers,omitempty"` @@ -813,7 +813,7 @@ type Vote struct { Voter string `protobuf:"bytes,2,opt,name=voter,proto3" json:"voter,omitempty"` // option is the voter's choice on the proposal. Option VoteOption `protobuf:"varint,3,opt,name=option,proto3,enum=cosmos.group.v1.VoteOption" json:"option,omitempty"` - // metadata is any arbitrary metadata to attached to the vote. + // metadata is any arbitrary metadata attached to the vote. Metadata string `protobuf:"bytes,4,opt,name=metadata,proto3" json:"metadata,omitempty"` // submit_time is the timestamp when the vote was submitted. SubmitTime time.Time `protobuf:"bytes,5,opt,name=submit_time,json=submitTime,proto3,stdtime" json:"submit_time"`