Skip to content

Commit

Permalink
chore: x/gov Audit changes (backport #16822) (#16844)
Browse files Browse the repository at this point in the history
Co-authored-by: Likhita Polavarapu <78951027+likhita-809@users.noreply.github.com>
  • Loading branch information
mergify[bot] and likhita-809 authored Jul 5, 2023
1 parent 565b1e9 commit 73aa872
Show file tree
Hide file tree
Showing 23 changed files with 72 additions and 97 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ linters-settings:
gofumpt:
extra-rules: true
dogsled:
max-blank-identifiers: 5
max-blank-identifiers: 6
maligned:
suggest-new: true
nolintlint:
Expand Down
2 changes: 1 addition & 1 deletion api/cosmos/gov/v1/gov.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions api/cosmos/gov/v1/query_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions api/cosmos/gov/v1/tx.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions api/cosmos/gov/v1beta1/genesis.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions api/cosmos/gov/v1beta1/query_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/cosmos/gov/v1/gov.proto
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ message Vote {
// options is the weighted vote options.
repeated WeightedVoteOption options = 4;

// metadata is any arbitrary metadata to attached to the vote.
// metadata is any arbitrary metadata attached to the vote.
// the recommended format of the metadata is to be found here: https://docs.cosmos.network/v0.47/modules/gov#vote-5
string metadata = 5;
}
Expand Down
3 changes: 1 addition & 2 deletions proto/cosmos/gov/v1/query.proto
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

// Since: cosmos-sdk 0.46
syntax = "proto3";
package cosmos.gov.v1;
Expand Down Expand Up @@ -42,7 +41,7 @@ service Query {
option (google.api.http).get = "/cosmos/gov/v1/params/{params_type}";
}

// Deposit queries single deposit information based proposalID, depositAddr.
// Deposit queries single deposit information based on proposalID, depositAddr.
rpc Deposit(QueryDepositRequest) returns (QueryDepositResponse) {
option (google.api.http).get = "/cosmos/gov/v1/proposals/{proposal_id}/deposits/{depositor}";
}
Expand Down
5 changes: 4 additions & 1 deletion proto/cosmos/gov/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ message MsgSubmitProposal {
// Since: cosmos-sdk 0.47
string summary = 6;

// expedided defines if the proposal is expedited or not
// expedited defines if the proposal is expedited or not
//
// Since: cosmos-sdk 0.50
bool expedited = 7;
Expand Down Expand Up @@ -193,7 +193,9 @@ message MsgUpdateParamsResponse {}
message MsgCancelProposal {
option (cosmos.msg.v1.signer) = "proposer";

// proposal_id defines the unique id of the proposal.
uint64 proposal_id = 1 [(gogoproto.jsontag) = "proposal_id"];
// proposer is the account address of the proposer.
string proposer = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

Expand All @@ -202,6 +204,7 @@ message MsgCancelProposal {
//
// Since: cosmos-sdk 0.50
message MsgCancelProposalResponse {
// proposal_id defines the unique id of the proposal.
uint64 proposal_id = 1 [(gogoproto.jsontag) = "proposal_id"];
// canceled_time is the time when proposal is canceled.
google.protobuf.Timestamp canceled_time = 2 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
Expand Down
6 changes: 3 additions & 3 deletions proto/cosmos/gov/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ message GenesisState {
// proposals defines all the proposals present at genesis.
repeated Proposal proposals = 4
[(gogoproto.castrepeated) = "Proposals", (gogoproto.nullable) = false, (amino.dont_omitempty) = true];
// params defines all the parameters of related to deposit.
// deposit_params defines all the parameters related to deposit.
DepositParams deposit_params = 5 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
// params defines all the parameters of related to voting.
// voting_params defines all the parameters related to voting.
VotingParams voting_params = 6 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
// params defines all the parameters of related to tally.
// tally_params defines all the parameters related to tally.
TallyParams tally_params = 7 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
}
2 changes: 1 addition & 1 deletion proto/cosmos/gov/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ service Query {
option (google.api.http).get = "/cosmos/gov/v1beta1/params/{params_type}";
}

// Deposit queries single deposit information based proposalID, depositAddr.
// Deposit queries single deposit information based on proposalID, depositor address.
rpc Deposit(QueryDepositRequest) returns (QueryDepositResponse) {
option (google.api.http).get = "/cosmos/gov/v1beta1/proposals/{proposal_id}/deposits/{depositor}";
}
Expand Down
2 changes: 1 addition & 1 deletion proto/cosmos/gov/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import "amino/amino.proto";

option go_package = "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1";

// Msg defines the bank Msg service.
// Msg defines the gov Msg service.
service Msg {
option (cosmos.msg.v1.service) = true;

Expand Down
2 changes: 2 additions & 0 deletions x/gov/keeper/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ func setupGovKeeper(t *testing.T) (
govKeeper.SetLegacyRouter(govRouter)
err := govKeeper.Params.Set(ctx, v1.DefaultParams())
require.NoError(t, err)
err = govKeeper.Constitution.Set(ctx, "constitution")
require.NoError(t, err)

// Register all handlers for the MegServiceRouter.
msr.SetInterfaceRegistry(encCfg.InterfaceRegistry)
Expand Down
11 changes: 11 additions & 0 deletions x/gov/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ func (suite *KeeperTestSuite) TestGRPCQueryProposal() {
}
}

func (suite *KeeperTestSuite) TestGRPCQueryConstitution() {
suite.reset()
queryClient := suite.queryClient

expRes := &v1.QueryConstitutionResponse{Constitution: "constitution"}

constitution, err := queryClient.Constitution(gocontext.Background(), &v1.QueryConstitutionRequest{})
suite.Require().NoError(err)
suite.Require().Equal(expRes, constitution)
}

func (suite *KeeperTestSuite) TestLegacyGRPCQueryProposal() {
suite.reset()
ctx, queryClient, addrs := suite.ctx, suite.legacyQueryClient, suite.addrs
Expand Down
20 changes: 20 additions & 0 deletions x/gov/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,26 @@ func TestProposalQueues(t *testing.T) {
require.True(t, has)
}

func TestSetHooks(t *testing.T) {
govKeeper, _, _, _, _, _, _ := setupGovKeeper(t)
require.Empty(t, govKeeper.Hooks())

govHooksReceiver := MockGovHooksReceiver{}
govKeeper.SetHooks(types.NewMultiGovHooks(&govHooksReceiver))
require.NotNil(t, govKeeper.Hooks())
require.Panics(t, func() {
govKeeper.SetHooks(&govHooksReceiver)
})
}

func TestGetGovGovernanceAndModuleAccountAddress(t *testing.T) {
govKeeper, authKeeper, _, _, _, _, ctx := setupGovKeeper(t)
mAcc := authKeeper.GetModuleAccount(ctx, "gov")
require.Equal(t, mAcc, govKeeper.GetGovernanceAccount(ctx))
mAddr := authKeeper.GetModuleAddress("gov")
require.Equal(t, mAddr, govKeeper.ModuleAccountAddress())
}

func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(KeeperTestSuite))
}
2 changes: 1 addition & 1 deletion x/gov/keeper/vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (keeper Keeper) AddVote(ctx context.Context, proposalID uint64, voterAddr s
return nil
}

// deleteVotes deletes the all votes from a given proposalID.
// deleteVotes deletes all the votes from a given proposalID.
func (keeper Keeper) deleteVotes(ctx context.Context, proposalID uint64) error {
rng := collections.NewPrefixedPairRange[uint64, sdk.AccAddress](proposalID)
err := keeper.Votes.Clear(ctx, rng)
Expand Down
2 changes: 1 addition & 1 deletion x/gov/types/v1/gov.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 0 additions & 42 deletions x/gov/types/v1/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ func (m *MsgSubmitProposal) SetMsgs(msgs []sdk.Msg) error {
return nil
}

// GetSigners returns the expected signers for a MsgSubmitProposal.
func (m MsgSubmitProposal) GetSigners() []sdk.AccAddress {
proposer, _ := sdk.AccAddressFromBech32(m.Proposer)
return []sdk.AccAddress{proposer}
}

// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
func (m MsgSubmitProposal) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
return sdktx.UnpackInterfaces(unpacker, m.Messages)
Expand All @@ -71,34 +65,16 @@ func NewMsgDeposit(depositor sdk.AccAddress, proposalID uint64, amount sdk.Coins
return &MsgDeposit{proposalID, depositor.String(), amount}
}

// GetSigners returns the expected signers for a MsgDeposit.
func (msg MsgDeposit) GetSigners() []sdk.AccAddress {
depositor, _ := sdk.AccAddressFromBech32(msg.Depositor)
return []sdk.AccAddress{depositor}
}

// NewMsgVote creates a message to cast a vote on an active proposal
func NewMsgVote(voter sdk.AccAddress, proposalID uint64, option VoteOption, metadata string) *MsgVote {
return &MsgVote{proposalID, voter.String(), option, metadata}
}

// GetSigners returns the expected signers for a MsgVote.
func (msg MsgVote) GetSigners() []sdk.AccAddress {
voter, _ := sdk.AccAddressFromBech32(msg.Voter)
return []sdk.AccAddress{voter}
}

// NewMsgVoteWeighted creates a message to cast a vote on an active proposal
func NewMsgVoteWeighted(voter sdk.AccAddress, proposalID uint64, options WeightedVoteOptions, metadata string) *MsgVoteWeighted {
return &MsgVoteWeighted{proposalID, voter.String(), options, metadata}
}

// GetSigners returns the expected signers for a MsgVoteWeighted.
func (msg MsgVoteWeighted) GetSigners() []sdk.AccAddress {
voter, _ := sdk.AccAddressFromBech32(msg.Voter)
return []sdk.AccAddress{voter}
}

// NewMsgExecLegacyContent creates a new MsgExecLegacyContent instance.
func NewMsgExecLegacyContent(content *codectypes.Any, authority string) *MsgExecLegacyContent {
return &MsgExecLegacyContent{
Expand All @@ -107,12 +83,6 @@ func NewMsgExecLegacyContent(content *codectypes.Any, authority string) *MsgExec
}
}

// GetSigners returns the expected signers for a MsgExecLegacyContent.
func (c MsgExecLegacyContent) GetSigners() []sdk.AccAddress {
authority, _ := sdk.AccAddressFromBech32(c.Authority)
return []sdk.AccAddress{authority}
}

// ValidateBasic implements the sdk.Msg interface.
func (c MsgExecLegacyContent) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(c.Authority)
Expand All @@ -129,22 +99,10 @@ func (c MsgExecLegacyContent) UnpackInterfaces(unpacker codectypes.AnyUnpacker)
return unpacker.UnpackAny(c.Content, &content)
}

// GetSigners returns the expected signers for a MsgUpdateParams.
func (msg MsgUpdateParams) GetSigners() []sdk.AccAddress {
authority, _ := sdk.AccAddressFromBech32(msg.Authority)
return []sdk.AccAddress{authority}
}

// NewMsgCancelProposal creates a new MsgCancelProposal instance.
func NewMsgCancelProposal(proposalID uint64, proposer string) *MsgCancelProposal {
return &MsgCancelProposal{
ProposalId: proposalID,
Proposer: proposer,
}
}

// GetSigners implements Msg
func (msg MsgCancelProposal) GetSigners() []sdk.AccAddress {
proposer, _ := sdk.AccAddressFromBech32(msg.Proposer)
return []sdk.AccAddress{proposer}
}
4 changes: 2 additions & 2 deletions x/gov/types/v1/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions x/gov/types/v1/tx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions x/gov/types/v1beta1/genesis.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 73aa872

Please sign in to comment.