From 05445b0ff223ff67a66ea8f7acc262c22a9d2abc Mon Sep 17 00:00:00 2001 From: DauTT Date: Fri, 12 Jun 2020 23:47:37 +0200 Subject: [PATCH 1/2] x/gov: remove alias.go usage --- simapp/app.go | 22 +++-- simapp/sim_test.go | 4 +- x/distribution/client/cli/tx.go | 4 +- x/distribution/client/rest/rest.go | 4 +- x/distribution/types/codec.go | 4 +- x/gov/abci.go | 13 +-- x/gov/abci_test.go | 39 ++++---- x/gov/alias.go | 154 ----------------------------- x/gov/client/testutil/helpers.go | 42 ++++---- x/gov/genesis.go | 15 +-- x/gov/genesis_test.go | 17 ++-- x/gov/handler.go | 19 ++-- x/gov/handler_test.go | 3 +- x/gov/module.go | 29 +++--- x/gov/module_test.go | 10 +- x/params/types/proposal/codec.go | 4 +- x/upgrade/abci_test.go | 4 +- x/upgrade/types/codec.go | 4 +- 18 files changed, 123 insertions(+), 268 deletions(-) delete mode 100644 x/gov/alias.go diff --git a/simapp/app.go b/simapp/app.go index 0d88659675c7..1bad8c08b6c0 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -26,6 +26,8 @@ import ( "github.com/cosmos/cosmos-sdk/x/evidence" "github.com/cosmos/cosmos-sdk/x/genutil" "github.com/cosmos/cosmos-sdk/x/gov" + govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/cosmos/cosmos-sdk/x/ibc" transfer "github.com/cosmos/cosmos-sdk/x/ibc-transfer" ibcclient "github.com/cosmos/cosmos-sdk/x/ibc/02-client" @@ -87,7 +89,7 @@ var ( mint.ModuleName: {auth.Minter}, stakingtypes.BondedPoolName: {auth.Burner, auth.Staking}, stakingtypes.NotBondedPoolName: {auth.Burner, auth.Staking}, - gov.ModuleName: {auth.Burner}, + govtypes.ModuleName: {auth.Burner}, transfer.ModuleName: {auth.Minter, auth.Burner}, } @@ -125,7 +127,7 @@ type SimApp struct { SlashingKeeper slashingkeeper.Keeper MintKeeper mint.Keeper DistrKeeper distr.Keeper - GovKeeper gov.Keeper + GovKeeper govkeeper.Keeper CrisisKeeper crisis.Keeper UpgradeKeeper upgradekeeper.Keeper ParamsKeeper paramskeeper.Keeper @@ -160,7 +162,7 @@ func NewSimApp( keys := sdk.NewKVStoreKeys( auth.StoreKey, bank.StoreKey, stakingtypes.StoreKey, mint.StoreKey, distr.StoreKey, slashingtypes.StoreKey, - gov.StoreKey, paramstypes.StoreKey, ibc.StoreKey, upgradetypes.StoreKey, + govtypes.StoreKey, paramstypes.StoreKey, ibc.StoreKey, upgradetypes.StoreKey, evidence.StoreKey, transfer.StoreKey, capability.StoreKey, ) tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey) @@ -185,7 +187,7 @@ func NewSimApp( app.subspaces[mint.ModuleName] = app.ParamsKeeper.Subspace(mint.DefaultParamspace) app.subspaces[distr.ModuleName] = app.ParamsKeeper.Subspace(distr.DefaultParamspace) app.subspaces[slashingtypes.ModuleName] = app.ParamsKeeper.Subspace(slashingtypes.DefaultParamspace) - app.subspaces[gov.ModuleName] = app.ParamsKeeper.Subspace(gov.DefaultParamspace).WithKeyTable(gov.ParamKeyTable()) + app.subspaces[govtypes.ModuleName] = app.ParamsKeeper.Subspace(govtypes.DefaultParamspace).WithKeyTable(govtypes.ParamKeyTable()) app.subspaces[crisis.ModuleName] = app.ParamsKeeper.Subspace(crisis.DefaultParamspace) // set the BaseApp's parameter store @@ -223,13 +225,13 @@ func NewSimApp( app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath) // register the proposal types - govRouter := gov.NewRouter() - govRouter.AddRoute(gov.RouterKey, gov.ProposalHandler). + govRouter := govtypes.NewRouter() + govRouter.AddRoute(govtypes.RouterKey, govtypes.ProposalHandler). AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)). AddRoute(distr.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)). AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)) - app.GovKeeper = gov.NewKeeper( - appCodec, keys[gov.StoreKey], app.subspaces[gov.ModuleName], app.AccountKeeper, app.BankKeeper, + app.GovKeeper = govkeeper.NewKeeper( + appCodec, keys[govtypes.StoreKey], app.subspaces[govtypes.ModuleName], app.AccountKeeper, app.BankKeeper, &stakingKeeper, govRouter, ) @@ -297,7 +299,7 @@ func NewSimApp( upgradetypes.ModuleName, mint.ModuleName, distr.ModuleName, slashingtypes.ModuleName, evidence.ModuleName, stakingtypes.ModuleName, ibc.ModuleName, ) - app.mm.SetOrderEndBlockers(crisis.ModuleName, gov.ModuleName, stakingtypes.ModuleName) + app.mm.SetOrderEndBlockers(crisis.ModuleName, govtypes.ModuleName, stakingtypes.ModuleName) // NOTE: The genutils moodule must occur after staking so that pools are // properly initialized with tokens from genesis accounts. @@ -306,7 +308,7 @@ func NewSimApp( // can do so safely. app.mm.SetOrderInitGenesis( capability.ModuleName, auth.ModuleName, distr.ModuleName, stakingtypes.ModuleName, bank.ModuleName, - slashingtypes.ModuleName, gov.ModuleName, mint.ModuleName, crisis.ModuleName, + slashingtypes.ModuleName, govtypes.ModuleName, mint.ModuleName, crisis.ModuleName, ibc.ModuleName, genutil.ModuleName, evidence.ModuleName, transfer.ModuleName, ) diff --git a/simapp/sim_test.go b/simapp/sim_test.go index 183a7fb329ba..f56ba9c95d67 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -22,7 +22,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/capability" distr "github.com/cosmos/cosmos-sdk/x/distribution" "github.com/cosmos/cosmos-sdk/x/evidence" - "github.com/cosmos/cosmos-sdk/x/gov" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/cosmos/cosmos-sdk/x/ibc" transfer "github.com/cosmos/cosmos-sdk/x/ibc-transfer" "github.com/cosmos/cosmos-sdk/x/mint" @@ -159,7 +159,7 @@ func TestAppImportExport(t *testing.T) { {app.keys[distr.StoreKey], newApp.keys[distr.StoreKey], [][]byte{}}, {app.keys[bank.StoreKey], newApp.keys[bank.StoreKey], [][]byte{bank.BalancesPrefix}}, {app.keys[paramtypes.StoreKey], newApp.keys[paramtypes.StoreKey], [][]byte{}}, - {app.keys[gov.StoreKey], newApp.keys[gov.StoreKey], [][]byte{}}, + {app.keys[govtypes.StoreKey], newApp.keys[govtypes.StoreKey], [][]byte{}}, {app.keys[evidence.StoreKey], newApp.keys[evidence.StoreKey], [][]byte{}}, {app.keys[capability.StoreKey], newApp.keys[capability.StoreKey], [][]byte{}}, {app.keys[ibc.StoreKey], newApp.keys[ibc.StoreKey], [][]byte{}}, diff --git a/x/distribution/client/cli/tx.go b/x/distribution/client/cli/tx.go index 323b3f2d9038..eba522998db0 100644 --- a/x/distribution/client/cli/tx.go +++ b/x/distribution/client/cli/tx.go @@ -15,7 +15,7 @@ import ( "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/distribution/client/common" "github.com/cosmos/cosmos-sdk/x/distribution/types" - "github.com/cosmos/cosmos-sdk/x/gov" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" ) var ( @@ -276,7 +276,7 @@ Where proposal.json contains: if err != nil { return err } - msg, err := gov.NewMsgSubmitProposal(content, deposit, from) + msg, err := govtypes.NewMsgSubmitProposal(content, deposit, from) if err != nil { return err } diff --git a/x/distribution/client/rest/rest.go b/x/distribution/client/rest/rest.go index dde615818522..ef4af014a43f 100644 --- a/x/distribution/client/rest/rest.go +++ b/x/distribution/client/rest/rest.go @@ -10,8 +10,8 @@ import ( "github.com/cosmos/cosmos-sdk/types/rest" authclient "github.com/cosmos/cosmos-sdk/x/auth/client" "github.com/cosmos/cosmos-sdk/x/distribution/types" - "github.com/cosmos/cosmos-sdk/x/gov" govrest "github.com/cosmos/cosmos-sdk/x/gov/client/rest" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" ) func RegisterHandlers(clientCtx client.Context, r *mux.Router) { @@ -48,7 +48,7 @@ func postProposalHandlerFn(clientCtx client.Context) http.HandlerFunc { content := types.NewCommunityPoolSpendProposal(req.Title, req.Description, req.Recipient, req.Amount) - msg, err := gov.NewMsgSubmitProposal(content, req.Deposit, req.Proposer) + msg, err := govtypes.NewMsgSubmitProposal(content, req.Deposit, req.Proposer) if rest.CheckBadRequestError(w, err) { return } diff --git a/x/distribution/types/codec.go b/x/distribution/types/codec.go index 869b8316310e..0e587ce2f1d6 100644 --- a/x/distribution/types/codec.go +++ b/x/distribution/types/codec.go @@ -5,7 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec/types" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/gov" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" ) // RegisterCodec registers the necessary x/distribution interfaces and concrete types @@ -26,7 +26,7 @@ func RegisterInterfaces(registry types.InterfaceRegistry) { &MsgSetWithdrawAddress{}, ) registry.RegisterImplementations( - (*gov.Content)(nil), + (*govtypes.Content)(nil), &CommunityPoolSpendProposal{}, ) } diff --git a/x/gov/abci.go b/x/gov/abci.go index a79f80d1ca4b..b89a661d6548 100644 --- a/x/gov/abci.go +++ b/x/gov/abci.go @@ -4,15 +4,16 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/gov/keeper" "github.com/cosmos/cosmos-sdk/x/gov/types" ) // EndBlocker called every block, process inflation, update validator set. -func EndBlocker(ctx sdk.Context, keeper Keeper) { +func EndBlocker(ctx sdk.Context, keeper keeper.Keeper) { logger := keeper.Logger(ctx) // delete inactive proposal from store and its deposits - keeper.IterateInactiveProposalsQueue(ctx, ctx.BlockHeader().Time, func(proposal Proposal) bool { + keeper.IterateInactiveProposalsQueue(ctx, ctx.BlockHeader().Time, func(proposal types.Proposal) bool { keeper.DeleteProposal(ctx, proposal.ProposalID) keeper.DeleteDeposits(ctx, proposal.ProposalID) @@ -36,7 +37,7 @@ func EndBlocker(ctx sdk.Context, keeper Keeper) { }) // fetch active proposals whose voting periods have ended (are passed the block time) - keeper.IterateActiveProposalsQueue(ctx, ctx.BlockHeader().Time, func(proposal Proposal) bool { + keeper.IterateActiveProposalsQueue(ctx, ctx.BlockHeader().Time, func(proposal types.Proposal) bool { var tagValue, logMsg string passes, burnDeposits, tallyResults := keeper.Tally(ctx, proposal) @@ -56,7 +57,7 @@ func EndBlocker(ctx sdk.Context, keeper Keeper) { // is written and the error message is logged. err := handler(cacheCtx, proposal.GetContent()) if err == nil { - proposal.Status = StatusPassed + proposal.Status = types.StatusPassed tagValue = types.AttributeValueProposalPassed logMsg = "passed" @@ -69,12 +70,12 @@ func EndBlocker(ctx sdk.Context, keeper Keeper) { // write state to the underlying multi-store writeCache() } else { - proposal.Status = StatusFailed + proposal.Status = types.StatusFailed tagValue = types.AttributeValueProposalFailed logMsg = fmt.Sprintf("passed, but failed on execution: %s", err) } } else { - proposal.Status = StatusRejected + proposal.Status = types.StatusRejected tagValue = types.AttributeValueProposalRejected logMsg = "rejected" } diff --git a/x/gov/abci_test.go b/x/gov/abci_test.go index 505b9269fcab..79655c5a06fe 100644 --- a/x/gov/abci_test.go +++ b/x/gov/abci_test.go @@ -10,6 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/gov" + "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/cosmos/cosmos-sdk/x/staking" ) @@ -27,8 +28,8 @@ func TestTickExpiredDepositPeriod(t *testing.T) { require.False(t, inactiveQueue.Valid()) inactiveQueue.Close() - newProposalMsg, err := gov.NewMsgSubmitProposal( - gov.ContentFromProposalType("test", "test", gov.ProposalTypeText), + newProposalMsg, err := types.NewMsgSubmitProposal( + types.ContentFromProposalType("test", "test", types.ProposalTypeText), sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 5)}, addrs[0], ) @@ -79,8 +80,8 @@ func TestTickMultipleExpiredDepositPeriod(t *testing.T) { require.False(t, inactiveQueue.Valid()) inactiveQueue.Close() - newProposalMsg, err := gov.NewMsgSubmitProposal( - gov.ContentFromProposalType("test", "test", gov.ProposalTypeText), + newProposalMsg, err := types.NewMsgSubmitProposal( + types.ContentFromProposalType("test", "test", types.ProposalTypeText), sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 5)}, addrs[0], ) @@ -102,8 +103,8 @@ func TestTickMultipleExpiredDepositPeriod(t *testing.T) { require.False(t, inactiveQueue.Valid()) inactiveQueue.Close() - newProposalMsg2, err := gov.NewMsgSubmitProposal( - gov.ContentFromProposalType("test2", "test2", gov.ProposalTypeText), + newProposalMsg2, err := types.NewMsgSubmitProposal( + types.ContentFromProposalType("test2", "test2", types.ProposalTypeText), sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 5)}, addrs[0], ) @@ -159,8 +160,8 @@ func TestTickPassedDepositPeriod(t *testing.T) { require.False(t, activeQueue.Valid()) activeQueue.Close() - newProposalMsg, err := gov.NewMsgSubmitProposal( - gov.ContentFromProposalType("test2", "test2", gov.ProposalTypeText), + newProposalMsg, err := types.NewMsgSubmitProposal( + types.ContentFromProposalType("test2", "test2", types.ProposalTypeText), sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 5)}, addrs[0], ) @@ -170,7 +171,7 @@ func TestTickPassedDepositPeriod(t *testing.T) { require.NoError(t, err) require.NotNil(t, res) - proposalID := gov.GetProposalIDFromBytes(res.Data) + proposalID := types.GetProposalIDFromBytes(res.Data) inactiveQueue = app.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) require.False(t, inactiveQueue.Valid()) @@ -184,7 +185,7 @@ func TestTickPassedDepositPeriod(t *testing.T) { require.False(t, inactiveQueue.Valid()) inactiveQueue.Close() - newDepositMsg := gov.NewMsgDeposit(addrs[1], proposalID, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 5)}) + newDepositMsg := types.NewMsgDeposit(addrs[1], proposalID, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 5)}) res, err = govHandler(ctx, newDepositMsg) require.NoError(t, err) @@ -215,20 +216,20 @@ func TestTickPassedVotingPeriod(t *testing.T) { activeQueue.Close() proposalCoins := sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, sdk.TokensFromConsensusPower(5))} - newProposalMsg, err := gov.NewMsgSubmitProposal(TestProposal, proposalCoins, addrs[0]) + newProposalMsg, err := types.NewMsgSubmitProposal(TestProposal, proposalCoins, addrs[0]) require.NoError(t, err) res, err := govHandler(ctx, newProposalMsg) require.NoError(t, err) require.NotNil(t, res) - proposalID := gov.GetProposalIDFromBytes(res.Data) + proposalID := types.GetProposalIDFromBytes(res.Data) newHeader := ctx.BlockHeader() newHeader.Time = ctx.BlockHeader().Time.Add(time.Duration(1) * time.Second) ctx = ctx.WithBlockHeader(newHeader) - newDepositMsg := gov.NewMsgDeposit(addrs[1], proposalID, proposalCoins) + newDepositMsg := types.NewMsgDeposit(addrs[1], proposalID, proposalCoins) res, err = govHandler(ctx, newDepositMsg) require.NoError(t, err) @@ -245,10 +246,10 @@ func TestTickPassedVotingPeriod(t *testing.T) { activeQueue = app.GovKeeper.ActiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) require.True(t, activeQueue.Valid()) - activeProposalID := gov.GetProposalIDFromBytes(activeQueue.Value()) + activeProposalID := types.GetProposalIDFromBytes(activeQueue.Value()) proposal, ok := app.GovKeeper.GetProposal(ctx, activeProposalID) require.True(t, ok) - require.Equal(t, gov.StatusVotingPeriod, proposal.Status) + require.Equal(t, types.StatusVotingPeriod, proposal.Status) activeQueue.Close() @@ -285,7 +286,7 @@ func TestProposalPassedEndblocker(t *testing.T) { require.NoError(t, err) proposalCoins := sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, sdk.TokensFromConsensusPower(10))} - newDepositMsg := gov.NewMsgDeposit(addrs[0], proposal.ProposalID, proposalCoins) + newDepositMsg := types.NewMsgDeposit(addrs[0], proposal.ProposalID, proposalCoins) res, err := handler(ctx, newDepositMsg) require.NoError(t, err) @@ -298,7 +299,7 @@ func TestProposalPassedEndblocker(t *testing.T) { deposits := initialModuleAccCoins.Add(proposal.TotalDeposit...).Add(proposalCoins...) require.True(t, moduleAccCoins.IsEqual(deposits)) - err = app.GovKeeper.AddVote(ctx, proposal.ProposalID, addrs[0], gov.OptionYes) + err = app.GovKeeper.AddVote(ctx, proposal.ProposalID, addrs[0], types.OptionYes) require.NoError(t, err) newHeader := ctx.BlockHeader() @@ -337,13 +338,13 @@ func TestEndBlockerProposalHandlerFailed(t *testing.T) { require.NoError(t, err) proposalCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.TokensFromConsensusPower(10))) - newDepositMsg := gov.NewMsgDeposit(addrs[0], proposal.ProposalID, proposalCoins) + newDepositMsg := types.NewMsgDeposit(addrs[0], proposal.ProposalID, proposalCoins) res, err := handler(ctx, newDepositMsg) require.NoError(t, err) require.NotNil(t, res) - err = app.GovKeeper.AddVote(ctx, proposal.ProposalID, addrs[0], gov.OptionYes) + err = app.GovKeeper.AddVote(ctx, proposal.ProposalID, addrs[0], types.OptionYes) require.NoError(t, err) newHeader := ctx.BlockHeader() diff --git a/x/gov/alias.go b/x/gov/alias.go deleted file mode 100644 index af2d3f9ebfe4..000000000000 --- a/x/gov/alias.go +++ /dev/null @@ -1,154 +0,0 @@ -package gov - -import ( - "github.com/cosmos/cosmos-sdk/x/gov/keeper" - "github.com/cosmos/cosmos-sdk/x/gov/types" -) - -const ( - MaxDescriptionLength = types.MaxDescriptionLength - MaxTitleLength = types.MaxTitleLength - DefaultPeriod = types.DefaultPeriod - ModuleName = types.ModuleName - StoreKey = types.StoreKey - RouterKey = types.RouterKey - QuerierRoute = types.QuerierRoute - DefaultParamspace = types.DefaultParamspace - TypeMsgDeposit = types.TypeMsgDeposit - TypeMsgVote = types.TypeMsgVote - TypeMsgSubmitProposal = types.TypeMsgSubmitProposal - StatusNil = types.StatusNil - StatusDepositPeriod = types.StatusDepositPeriod - StatusVotingPeriod = types.StatusVotingPeriod - StatusPassed = types.StatusPassed - StatusRejected = types.StatusRejected - StatusFailed = types.StatusFailed - ProposalTypeText = types.ProposalTypeText - QueryParams = types.QueryParams - QueryProposals = types.QueryProposals - QueryProposal = types.QueryProposal - QueryDeposits = types.QueryDeposits - QueryDeposit = types.QueryDeposit - QueryVotes = types.QueryVotes - QueryVote = types.QueryVote - QueryTally = types.QueryTally - ParamDeposit = types.ParamDeposit - ParamVoting = types.ParamVoting - ParamTallying = types.ParamTallying - OptionEmpty = types.OptionEmpty - OptionYes = types.OptionYes - OptionAbstain = types.OptionAbstain - OptionNo = types.OptionNo - OptionNoWithVeto = types.OptionNoWithVeto -) - -var ( - // functions aliases - RegisterInvariants = keeper.RegisterInvariants - AllInvariants = keeper.AllInvariants - ModuleAccountInvariant = keeper.ModuleAccountInvariant - NewKeeper = keeper.NewKeeper - NewQuerier = keeper.NewQuerier - RegisterCodec = types.RegisterCodec - RegisterProposalTypeCodec = types.RegisterProposalTypeCodec - ValidateAbstract = types.ValidateAbstract - NewDeposit = types.NewDeposit - ErrUnknownProposal = types.ErrUnknownProposal - ErrInactiveProposal = types.ErrInactiveProposal - ErrAlreadyActiveProposal = types.ErrAlreadyActiveProposal - ErrInvalidProposalContent = types.ErrInvalidProposalContent - ErrInvalidProposalType = types.ErrInvalidProposalType - ErrInvalidVote = types.ErrInvalidVote - ErrInvalidGenesis = types.ErrInvalidGenesis - ErrNoProposalHandlerExists = types.ErrNoProposalHandlerExists - NewGenesisState = types.NewGenesisState - DefaultGenesisState = types.DefaultGenesisState - ValidateGenesis = types.ValidateGenesis - GetProposalIDBytes = types.GetProposalIDBytes - GetProposalIDFromBytes = types.GetProposalIDFromBytes - ProposalKey = types.ProposalKey - ActiveProposalByTimeKey = types.ActiveProposalByTimeKey - ActiveProposalQueueKey = types.ActiveProposalQueueKey - InactiveProposalByTimeKey = types.InactiveProposalByTimeKey - InactiveProposalQueueKey = types.InactiveProposalQueueKey - DepositsKey = types.DepositsKey - DepositKey = types.DepositKey - VotesKey = types.VotesKey - VoteKey = types.VoteKey - SplitProposalKey = types.SplitProposalKey - SplitActiveProposalQueueKey = types.SplitActiveProposalQueueKey - SplitInactiveProposalQueueKey = types.SplitInactiveProposalQueueKey - SplitKeyDeposit = types.SplitKeyDeposit - SplitKeyVote = types.SplitKeyVote - NewMsgSubmitProposal = types.NewMsgSubmitProposal - NewMsgDeposit = types.NewMsgDeposit - NewMsgVote = types.NewMsgVote - ParamKeyTable = types.ParamKeyTable - NewDepositParams = types.NewDepositParams - NewTallyParams = types.NewTallyParams - NewVotingParams = types.NewVotingParams - NewParams = types.NewParams - NewProposal = types.NewProposal - NewRouter = types.NewRouter - ProposalStatusFromString = types.ProposalStatusFromString - ValidProposalStatus = types.ValidProposalStatus - NewTextProposal = types.NewTextProposal - RegisterProposalType = types.RegisterProposalType - ContentFromProposalType = types.ContentFromProposalType - IsValidProposalType = types.IsValidProposalType - ProposalHandler = types.ProposalHandler - NewQueryProposalParams = types.NewQueryProposalParams - NewQueryDepositParams = types.NewQueryDepositParams - NewQueryVoteParams = types.NewQueryVoteParams - NewQueryProposalsParams = types.NewQueryProposalsParams - NewValidatorGovInfo = types.NewValidatorGovInfo - NewTallyResult = types.NewTallyResult - NewTallyResultFromMap = types.NewTallyResultFromMap - EmptyTallyResult = types.EmptyTallyResult - NewVote = types.NewVote - VoteOptionFromString = types.VoteOptionFromString - ValidVoteOption = types.ValidVoteOption - - // variable aliases - ModuleCdc = types.ModuleCdc - ProposalsKeyPrefix = types.ProposalsKeyPrefix - ActiveProposalQueuePrefix = types.ActiveProposalQueuePrefix - InactiveProposalQueuePrefix = types.InactiveProposalQueuePrefix - ProposalIDKey = types.ProposalIDKey - DepositsKeyPrefix = types.DepositsKeyPrefix - VotesKeyPrefix = types.VotesKeyPrefix - ParamStoreKeyDepositParams = types.ParamStoreKeyDepositParams - ParamStoreKeyVotingParams = types.ParamStoreKeyVotingParams - ParamStoreKeyTallyParams = types.ParamStoreKeyTallyParams -) - -type ( - Keeper = keeper.Keeper - Content = types.Content - Handler = types.Handler - Deposit = types.Deposit - Deposits = types.Deposits - GenesisState = types.GenesisState - MsgSubmitProposalI = types.MsgSubmitProposalI - MsgSubmitProposal = types.MsgSubmitProposal - MsgDeposit = types.MsgDeposit - MsgVote = types.MsgVote - DepositParams = types.DepositParams - TallyParams = types.TallyParams - VotingParams = types.VotingParams - Params = types.Params - Proposal = types.Proposal - Proposals = types.Proposals - ProposalQueue = types.ProposalQueue - ProposalStatus = types.ProposalStatus - TextProposal = types.TextProposal - QueryProposalParams = types.QueryProposalParams - QueryDepositParams = types.QueryDepositParams - QueryVoteParams = types.QueryVoteParams - QueryProposalsParams = types.QueryProposalsParams - ValidatorGovInfo = types.ValidatorGovInfo - TallyResult = types.TallyResult - Vote = types.Vote - Votes = types.Votes - VoteOption = types.VoteOption -) diff --git a/x/gov/client/testutil/helpers.go b/x/gov/client/testutil/helpers.go index f6be84a5f1aa..1f2abb8e6a5c 100644 --- a/x/gov/client/testutil/helpers.go +++ b/x/gov/client/testutil/helpers.go @@ -10,17 +10,17 @@ import ( "github.com/cosmos/cosmos-sdk/tests" "github.com/cosmos/cosmos-sdk/tests/cli" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/gov" + "github.com/cosmos/cosmos-sdk/x/gov/types" ) //___________________________________________________________________________________ // simcli query gov // QueryGovParamDeposit is simcli query gov param deposit -func QueryGovParamDeposit(f *cli.Fixtures) gov.DepositParams { +func QueryGovParamDeposit(f *cli.Fixtures) types.DepositParams { cmd := fmt.Sprintf("%s query gov param deposit %s", f.SimcliBinary, f.Flags()) out, _ := tests.ExecuteT(f.T, cmd, "") - var depositParam gov.DepositParams + var depositParam types.DepositParams err := f.Cdc.UnmarshalJSON([]byte(out), &depositParam) require.NoError(f.T, err, "out %v\n, err %v", out, err) @@ -28,10 +28,10 @@ func QueryGovParamDeposit(f *cli.Fixtures) gov.DepositParams { } // QueryGovParamVoting is simcli query gov param voting -func QueryGovParamVoting(f *cli.Fixtures) gov.VotingParams { +func QueryGovParamVoting(f *cli.Fixtures) types.VotingParams { cmd := fmt.Sprintf("%s query gov param voting %s", f.SimcliBinary, f.Flags()) out, _ := tests.ExecuteT(f.T, cmd, "") - var votingParam gov.VotingParams + var votingParam types.VotingParams err := f.Cdc.UnmarshalJSON([]byte(out), &votingParam) require.NoError(f.T, err, "out %v\n, err %v", out, err) @@ -39,10 +39,10 @@ func QueryGovParamVoting(f *cli.Fixtures) gov.VotingParams { } // QueryGovParamTallying is simcli query gov param tallying -func QueryGovParamTallying(f *cli.Fixtures) gov.TallyParams { +func QueryGovParamTallying(f *cli.Fixtures) types.TallyParams { cmd := fmt.Sprintf("%s query gov param tallying %s", f.SimcliBinary, f.Flags()) out, _ := tests.ExecuteT(f.T, cmd, "") - var tallyingParam gov.TallyParams + var tallyingParam types.TallyParams err := f.Cdc.UnmarshalJSON([]byte(out), &tallyingParam) require.NoError(f.T, err, "out %v\n, err %v", out, err) @@ -50,10 +50,10 @@ func QueryGovParamTallying(f *cli.Fixtures) gov.TallyParams { } // QueryGovProposal is simcli query gov proposal -func QueryGovProposal(f *cli.Fixtures, proposalID int, flags ...string) gov.Proposal { +func QueryGovProposal(f *cli.Fixtures, proposalID int, flags ...string) types.Proposal { cmd := fmt.Sprintf("%s query gov proposal %d %v", f.SimcliBinary, proposalID, f.Flags()) out, _ := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "") - var proposal gov.Proposal + var proposal types.Proposal err := f.Cdc.UnmarshalJSON([]byte(out), &proposal) require.NoError(f.T, err, "out %v\n, err %v", out, err) @@ -61,14 +61,14 @@ func QueryGovProposal(f *cli.Fixtures, proposalID int, flags ...string) gov.Prop } // QueryGovProposals is simcli query gov proposals -func QueryGovProposals(f *cli.Fixtures, flags ...string) gov.Proposals { +func QueryGovProposals(f *cli.Fixtures, flags ...string) types.Proposals { cmd := fmt.Sprintf("%s query gov proposals %v", f.SimcliBinary, f.Flags()) stdout, stderr := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "") if strings.Contains(stderr, "no matching proposals found") { - return gov.Proposals{} + return types.Proposals{} } require.Empty(f.T, stderr) - var out gov.Proposals + var out types.Proposals err := f.Cdc.UnmarshalJSON([]byte(stdout), &out) require.NoError(f.T, err) @@ -76,10 +76,10 @@ func QueryGovProposals(f *cli.Fixtures, flags ...string) gov.Proposals { } // QueryGovVote is simcli query gov vote -func QueryGovVote(f *cli.Fixtures, proposalID int, voter sdk.AccAddress, flags ...string) gov.Vote { +func QueryGovVote(f *cli.Fixtures, proposalID int, voter sdk.AccAddress, flags ...string) types.Vote { cmd := fmt.Sprintf("%s query gov vote %d %s %v", f.SimcliBinary, proposalID, voter, f.Flags()) out, _ := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "") - var vote gov.Vote + var vote types.Vote err := f.Cdc.UnmarshalJSON([]byte(out), &vote) require.NoError(f.T, err, "out %v\n, err %v", out, err) @@ -87,10 +87,10 @@ func QueryGovVote(f *cli.Fixtures, proposalID int, voter sdk.AccAddress, flags . } // QueryGovVotes is simcli query gov votes -func QueryGovVotes(f *cli.Fixtures, proposalID int, flags ...string) []gov.Vote { +func QueryGovVotes(f *cli.Fixtures, proposalID int, flags ...string) []types.Vote { cmd := fmt.Sprintf("%s query gov votes %d %v", f.SimcliBinary, proposalID, f.Flags()) out, _ := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "") - var votes []gov.Vote + var votes []types.Vote err := f.Cdc.UnmarshalJSON([]byte(out), &votes) require.NoError(f.T, err, "out %v\n, err %v", out, err) @@ -98,10 +98,10 @@ func QueryGovVotes(f *cli.Fixtures, proposalID int, flags ...string) []gov.Vote } // QueryGovDeposit is simcli query gov deposit -func QueryGovDeposit(f *cli.Fixtures, proposalID int, depositor sdk.AccAddress, flags ...string) gov.Deposit { +func QueryGovDeposit(f *cli.Fixtures, proposalID int, depositor sdk.AccAddress, flags ...string) types.Deposit { cmd := fmt.Sprintf("%s query gov deposit %d %s %v", f.SimcliBinary, proposalID, depositor, f.Flags()) out, _ := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "") - var deposit gov.Deposit + var deposit types.Deposit err := f.Cdc.UnmarshalJSON([]byte(out), &deposit) require.NoError(f.T, err, "out %v\n, err %v", out, err) @@ -109,10 +109,10 @@ func QueryGovDeposit(f *cli.Fixtures, proposalID int, depositor sdk.AccAddress, } // QueryGovDeposits is simcli query gov deposits -func QueryGovDeposits(f *cli.Fixtures, propsalID int, flags ...string) []gov.Deposit { +func QueryGovDeposits(f *cli.Fixtures, propsalID int, flags ...string) []types.Deposit { cmd := fmt.Sprintf("%s query gov deposits %d %v", f.SimcliBinary, propsalID, f.Flags()) out, _ := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "") - var deposits []gov.Deposit + var deposits []types.Deposit err := f.Cdc.UnmarshalJSON([]byte(out), &deposits) require.NoError(f.T, err, "out %v\n, err %v", out, err) @@ -138,7 +138,7 @@ func TxGovDeposit(f *cli.Fixtures, proposalID int, from string, amount sdk.Coin, } // TxGovVote is simcli tx gov vote -func TxGovVote(f *cli.Fixtures, proposalID int, option gov.VoteOption, from string, flags ...string) (bool, string, string) { +func TxGovVote(f *cli.Fixtures, proposalID int, option types.VoteOption, from string, flags ...string) (bool, string, string) { cmd := fmt.Sprintf("%s tx gov vote %d %s --keyring-backend=test --from=%s %v", f.SimcliBinary, proposalID, option, from, f.Flags()) return cli.ExecuteWriteRetStdStreams(f.T, cli.AddFlags(cmd, flags), clientkeys.DefaultKeyPass) diff --git a/x/gov/genesis.go b/x/gov/genesis.go index 896b71446ee0..bf2ff27e5d5f 100644 --- a/x/gov/genesis.go +++ b/x/gov/genesis.go @@ -4,11 +4,12 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/gov/keeper" "github.com/cosmos/cosmos-sdk/x/gov/types" ) // InitGenesis - store genesis parameters -func InitGenesis(ctx sdk.Context, ak types.AccountKeeper, bk types.BankKeeper, k Keeper, data GenesisState) { +func InitGenesis(ctx sdk.Context, ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, data types.GenesisState) { k.SetProposalID(ctx, data.StartingProposalID) k.SetDepositParams(ctx, data.DepositParams) k.SetVotingParams(ctx, data.VotingParams) @@ -32,9 +33,9 @@ func InitGenesis(ctx sdk.Context, ak types.AccountKeeper, bk types.BankKeeper, k for _, proposal := range data.Proposals { switch proposal.Status { - case StatusDepositPeriod: + case types.StatusDepositPeriod: k.InsertInactiveProposalQueue(ctx, proposal.ProposalID, proposal.DepositEndTime) - case StatusVotingPeriod: + case types.StatusVotingPeriod: k.InsertActiveProposalQueue(ctx, proposal.ProposalID, proposal.VotingEndTime) } k.SetProposal(ctx, proposal) @@ -51,15 +52,15 @@ func InitGenesis(ctx sdk.Context, ak types.AccountKeeper, bk types.BankKeeper, k } // ExportGenesis - output genesis parameters -func ExportGenesis(ctx sdk.Context, k Keeper) GenesisState { +func ExportGenesis(ctx sdk.Context, k keeper.Keeper) types.GenesisState { startingProposalID, _ := k.GetProposalID(ctx) depositParams := k.GetDepositParams(ctx) votingParams := k.GetVotingParams(ctx) tallyParams := k.GetTallyParams(ctx) proposals := k.GetProposals(ctx) - var proposalsDeposits Deposits - var proposalsVotes Votes + var proposalsDeposits types.Deposits + var proposalsVotes types.Votes for _, proposal := range proposals { deposits := k.GetDeposits(ctx, proposal.ProposalID) proposalsDeposits = append(proposalsDeposits, deposits...) @@ -68,7 +69,7 @@ func ExportGenesis(ctx sdk.Context, k Keeper) GenesisState { proposalsVotes = append(proposalsVotes, votes...) } - return GenesisState{ + return types.GenesisState{ StartingProposalID: startingProposalID, Deposits: proposalsDeposits, Votes: proposalsVotes, diff --git a/x/gov/genesis_test.go b/x/gov/genesis_test.go index 7dacb7a47b88..ba6d5a1f9af4 100644 --- a/x/gov/genesis_test.go +++ b/x/gov/genesis_test.go @@ -13,6 +13,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/gov" + "github.com/cosmos/cosmos-sdk/x/gov/types" ) func TestImportExportQueues(t *testing.T) { @@ -45,8 +46,8 @@ func TestImportExportQueues(t *testing.T) { require.True(t, ok) proposal2, ok = app.GovKeeper.GetProposal(ctx, proposalID2) require.True(t, ok) - require.True(t, proposal1.Status == gov.StatusDepositPeriod) - require.True(t, proposal2.Status == gov.StatusVotingPeriod) + require.True(t, proposal1.Status == types.StatusDepositPeriod) + require.True(t, proposal2.Status == types.StatusVotingPeriod) authGenState := auth.ExportGenesis(ctx, app.AccountKeeper) bankGenState := bank.ExportGenesis(ctx, app.BankKeeper) @@ -57,7 +58,7 @@ func TestImportExportQueues(t *testing.T) { genesisState[auth.ModuleName] = app.AppCodec().MustMarshalJSON(authGenState) genesisState[bank.ModuleName] = app.AppCodec().MustMarshalJSON(bankGenState) - genesisState[gov.ModuleName] = app.AppCodec().MustMarshalJSON(govGenState) + genesisState[types.ModuleName] = app.AppCodec().MustMarshalJSON(govGenState) stateBytes, err := codec.MarshalJSONIndent(app.Codec(), genesisState) if err != nil { @@ -91,8 +92,8 @@ func TestImportExportQueues(t *testing.T) { require.True(t, ok) proposal2, ok = app2.GovKeeper.GetProposal(ctx2, proposalID2) require.True(t, ok) - require.True(t, proposal1.Status == gov.StatusDepositPeriod) - require.True(t, proposal2.Status == gov.StatusVotingPeriod) + require.True(t, proposal1.Status == types.StatusDepositPeriod) + require.True(t, proposal2.Status == types.StatusVotingPeriod) macc := app2.GovKeeper.GetGovernanceAccount(ctx2) require.Equal(t, app2.GovKeeper.GetDepositParams(ctx2).MinDeposit, app2.BankKeeper.GetAllBalances(ctx2, macc.GetAddress())) @@ -105,7 +106,7 @@ func TestImportExportQueues(t *testing.T) { proposal2, ok = app2.GovKeeper.GetProposal(ctx2, proposalID2) require.True(t, ok) - require.True(t, proposal2.Status == gov.StatusRejected) + require.True(t, proposal2.Status == types.StatusRejected) } func TestEqualProposals(t *testing.T) { @@ -131,8 +132,8 @@ func TestEqualProposals(t *testing.T) { require.NotEqual(t, proposal1, proposal2) // Now create two genesis blocks - state1 := gov.GenesisState{Proposals: []gov.Proposal{proposal1}} - state2 := gov.GenesisState{Proposals: []gov.Proposal{proposal2}} + state1 := types.GenesisState{Proposals: []types.Proposal{proposal1}} + state2 := types.GenesisState{Proposals: []types.Proposal{proposal2}} require.NotEqual(t, state1, state2) require.False(t, state1.Equal(state2)) diff --git a/x/gov/handler.go b/x/gov/handler.go index 2805e4f87953..8a0e4a27957b 100644 --- a/x/gov/handler.go +++ b/x/gov/handler.go @@ -5,31 +5,32 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/gov/keeper" "github.com/cosmos/cosmos-sdk/x/gov/types" ) // NewHandler creates an sdk.Handler for all the gov type messages -func NewHandler(keeper Keeper) sdk.Handler { +func NewHandler(keeper keeper.Keeper) sdk.Handler { return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { ctx = ctx.WithEventManager(sdk.NewEventManager()) switch msg := msg.(type) { - case *MsgDeposit: + case *types.MsgDeposit: return handleMsgDeposit(ctx, keeper, msg) - case MsgSubmitProposalI: + case types.MsgSubmitProposalI: return handleMsgSubmitProposal(ctx, keeper, msg) - case *MsgVote: + case *types.MsgVote: return handleMsgVote(ctx, keeper, msg) default: - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", ModuleName, msg) + return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", types.ModuleName, msg) } } } -func handleMsgSubmitProposal(ctx sdk.Context, keeper Keeper, msg MsgSubmitProposalI) (*sdk.Result, error) { +func handleMsgSubmitProposal(ctx sdk.Context, keeper keeper.Keeper, msg types.MsgSubmitProposalI) (*sdk.Result, error) { proposal, err := keeper.SubmitProposal(ctx, msg.GetContent()) if err != nil { return nil, err @@ -58,12 +59,12 @@ func handleMsgSubmitProposal(ctx sdk.Context, keeper Keeper, msg MsgSubmitPropos ctx.EventManager().EmitEvent(submitEvent) return &sdk.Result{ - Data: GetProposalIDBytes(proposal.ProposalID), + Data: types.GetProposalIDBytes(proposal.ProposalID), Events: ctx.EventManager().ABCIEvents(), }, nil } -func handleMsgDeposit(ctx sdk.Context, keeper Keeper, msg *MsgDeposit) (*sdk.Result, error) { +func handleMsgDeposit(ctx sdk.Context, keeper keeper.Keeper, msg *types.MsgDeposit) (*sdk.Result, error) { votingStarted, err := keeper.AddDeposit(ctx, msg.ProposalID, msg.Depositor, msg.Amount) if err != nil { return nil, err @@ -89,7 +90,7 @@ func handleMsgDeposit(ctx sdk.Context, keeper Keeper, msg *MsgDeposit) (*sdk.Res return &sdk.Result{Events: ctx.EventManager().ABCIEvents()}, nil } -func handleMsgVote(ctx sdk.Context, keeper Keeper, msg *MsgVote) (*sdk.Result, error) { +func handleMsgVote(ctx sdk.Context, keeper keeper.Keeper, msg *types.MsgVote) (*sdk.Result, error) { err := keeper.AddVote(ctx, msg.ProposalID, msg.Voter, msg.Option) if err != nil { return nil, err diff --git a/x/gov/handler_test.go b/x/gov/handler_test.go index e52573b1e0f9..c8d0d3a9c756 100644 --- a/x/gov/handler_test.go +++ b/x/gov/handler_test.go @@ -9,10 +9,11 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/gov" + "github.com/cosmos/cosmos-sdk/x/gov/keeper" ) func TestInvalidMsg(t *testing.T) { - k := gov.Keeper{} + k := keeper.Keeper{} h := gov.NewHandler(k) res, err := h(sdk.NewContext(nil, abci.Header{}, false, nil), sdk.NewTestMsg()) diff --git a/x/gov/module.go b/x/gov/module.go index 2a046a98fd37..b1f2ed6ffbf2 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -23,6 +23,7 @@ import ( govclient "github.com/cosmos/cosmos-sdk/x/gov/client" "github.com/cosmos/cosmos-sdk/x/gov/client/cli" "github.com/cosmos/cosmos-sdk/x/gov/client/rest" + "github.com/cosmos/cosmos-sdk/x/gov/keeper" "github.com/cosmos/cosmos-sdk/x/gov/simulation" "github.com/cosmos/cosmos-sdk/x/gov/types" ) @@ -54,23 +55,23 @@ func (AppModuleBasic) Name() string { // RegisterCodec registers the gov module's types for the given codec. func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { - RegisterCodec(cdc) + types.RegisterCodec(cdc) } // DefaultGenesis returns default genesis state as raw bytes for the gov // module. func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { - return cdc.MustMarshalJSON(DefaultGenesisState()) + return cdc.MustMarshalJSON(types.DefaultGenesisState()) } // ValidateGenesis performs genesis state validation for the gov module. func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessage) error { - var data GenesisState + var data types.GenesisState if err := cdc.UnmarshalJSON(bz, &data); err != nil { return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) } - return ValidateGenesis(data) + return types.ValidateGenesis(data) } // RegisterRESTRoutes registers the REST routes for the gov module. @@ -95,7 +96,7 @@ func (a AppModuleBasic) GetTxCmd(clientCtx client.Context) *cobra.Command { // GetQueryCmd returns the root query command for the gov module. func (AppModuleBasic) GetQueryCmd(clientCtx client.Context) *cobra.Command { - return cli.GetQueryCmd(StoreKey, clientCtx.Codec) + return cli.GetQueryCmd(types.StoreKey, clientCtx.Codec) } // RegisterInterfaceTypes implements InterfaceModule.RegisterInterfaceTypes @@ -109,13 +110,13 @@ func (a AppModuleBasic) RegisterInterfaceTypes(registry codectypes.InterfaceRegi type AppModule struct { AppModuleBasic - keeper Keeper + keeper keeper.Keeper accountKeeper types.AccountKeeper bankKeeper types.BankKeeper } // NewAppModule creates a new AppModule object -func NewAppModule(cdc codec.Marshaler, keeper Keeper, ak types.AccountKeeper, bk types.BankKeeper) AppModule { +func NewAppModule(cdc codec.Marshaler, keeper keeper.Keeper, ak types.AccountKeeper, bk types.BankKeeper) AppModule { return AppModule{ AppModuleBasic: AppModuleBasic{cdc: cdc}, keeper: keeper, @@ -126,27 +127,27 @@ func NewAppModule(cdc codec.Marshaler, keeper Keeper, ak types.AccountKeeper, bk // Name returns the gov module's name. func (AppModule) Name() string { - return ModuleName + return types.ModuleName } // RegisterInvariants registers module invariants func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { - RegisterInvariants(ir, am.keeper, am.bankKeeper) + keeper.RegisterInvariants(ir, am.keeper, am.bankKeeper) } // Route returns the message routing key for the gov module. func (am AppModule) Route() sdk.Route { - return sdk.NewRoute(RouterKey, NewHandler(am.keeper)) + return sdk.NewRoute(types.RouterKey, NewHandler(am.keeper)) } // QuerierRoute returns the gov module's querier route name. func (AppModule) QuerierRoute() string { - return QuerierRoute + return types.QuerierRoute } // NewQuerierHandler returns no sdk.Querier. func (am AppModule) NewQuerierHandler() sdk.Querier { - return NewQuerier(am.keeper) + return keeper.NewQuerier(am.keeper) } func (am AppModule) RegisterQueryService(grpc.Server) {} @@ -154,7 +155,7 @@ func (am AppModule) RegisterQueryService(grpc.Server) {} // InitGenesis performs genesis initialization for the gov module. It returns // no validator updates. func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { - var genesisState GenesisState + var genesisState types.GenesisState cdc.MustUnmarshalJSON(data, &genesisState) InitGenesis(ctx, am.accountKeeper, am.bankKeeper, am.keeper, genesisState) return []abci.ValidatorUpdate{} @@ -199,7 +200,7 @@ func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange { // RegisterStoreDecoder registers a decoder for gov module's types func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { - sdr[StoreKey] = simulation.NewDecodeStore(am.cdc) + sdr[types.StoreKey] = simulation.NewDecodeStore(am.cdc) } // WeightedOperations returns the all the gov module operations with their respective weights. diff --git a/x/gov/module_test.go b/x/gov/module_test.go index cb8446e31747..99a7923f31ac 100644 --- a/x/gov/module_test.go +++ b/x/gov/module_test.go @@ -4,24 +4,24 @@ import ( "testing" "github.com/stretchr/testify/require" - "github.com/tendermint/tendermint/abci/types" + abcitypes "github.com/tendermint/tendermint/abci/types" "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/x/auth" - "github.com/cosmos/cosmos-sdk/x/gov" + "github.com/cosmos/cosmos-sdk/x/gov/types" ) func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { app := simapp.Setup(false) - ctx := app.BaseApp.NewContext(false, types.Header{}) + ctx := app.BaseApp.NewContext(false, abcitypes.Header{}) app.InitChain( - types.RequestInitChain{ + abcitypes.RequestInitChain{ AppStateBytes: []byte("{}"), ChainId: "test-chain-id", }, ) - acc := app.AccountKeeper.GetAccount(ctx, auth.NewModuleAddress(gov.ModuleName)) + acc := app.AccountKeeper.GetAccount(ctx, auth.NewModuleAddress(types.ModuleName)) require.NotNil(t, acc) } diff --git a/x/params/types/proposal/codec.go b/x/params/types/proposal/codec.go index 225b0c946dce..a6bae4968ed1 100644 --- a/x/params/types/proposal/codec.go +++ b/x/params/types/proposal/codec.go @@ -3,7 +3,7 @@ package proposal import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/x/gov" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" ) type Codec struct { @@ -35,7 +35,7 @@ func RegisterCodec(cdc *codec.Codec) { func RegisterInterfaces(registry types.InterfaceRegistry) { registry.RegisterImplementations( - (*gov.Content)(nil), + (*govtypes.Content)(nil), &ParameterChangeProposal{}, ) } diff --git a/x/upgrade/abci_test.go b/x/upgrade/abci_test.go index 545b8ee262fe..aa247bdab98f 100644 --- a/x/upgrade/abci_test.go +++ b/x/upgrade/abci_test.go @@ -20,7 +20,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/module" - "github.com/cosmos/cosmos-sdk/x/gov" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/cosmos/cosmos-sdk/x/upgrade" "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" "github.com/cosmos/cosmos-sdk/x/upgrade/types" @@ -30,7 +30,7 @@ type TestSuite struct { module module.AppModule keeper keeper.Keeper querier sdk.Querier - handler gov.Handler + handler govtypes.Handler ctx sdk.Context } diff --git a/x/upgrade/types/codec.go b/x/upgrade/types/codec.go index c363d050f36c..5531085a277b 100644 --- a/x/upgrade/types/codec.go +++ b/x/upgrade/types/codec.go @@ -3,7 +3,7 @@ package types import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/x/gov" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" ) // RegisterCodec registers concrete types on the Amino codec @@ -15,7 +15,7 @@ func RegisterCodec(cdc *codec.Codec) { func RegisterInterfaces(registry types.InterfaceRegistry) { registry.RegisterImplementations( - (*gov.Content)(nil), + (*govtypes.Content)(nil), &SoftwareUpgradeProposal{}, &CancelSoftwareUpgradeProposal{}, ) From cadb29a4fc6a348b0cc948f49d50a0c6a9ca6408 Mon Sep 17 00:00:00 2001 From: DauTT Date: Sat, 13 Jun 2020 00:33:48 +0200 Subject: [PATCH 2/2] Fix cli_text.go --- x/gov/client/cli/cli_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/x/gov/client/cli/cli_test.go b/x/gov/client/cli/cli_test.go index e77a0a241a3d..e01acfb27da9 100644 --- a/x/gov/client/cli/cli_test.go +++ b/x/gov/client/cli/cli_test.go @@ -12,8 +12,8 @@ import ( "github.com/cosmos/cosmos-sdk/tests/cli" sdk "github.com/cosmos/cosmos-sdk/types" banktestutils "github.com/cosmos/cosmos-sdk/x/bank/client/testutil" - "github.com/cosmos/cosmos-sdk/x/gov" "github.com/cosmos/cosmos-sdk/x/gov/client/testutil" + "github.com/cosmos/cosmos-sdk/x/gov/types" ) func TestCLISubmitProposal(t *testing.T) { @@ -65,7 +65,7 @@ func TestCLISubmitProposal(t *testing.T) { // Ensure propsal is directly queryable proposal1 := testutil.QueryGovProposal(f, 1) require.Equal(t, uint64(1), proposal1.ProposalID) - require.Equal(t, gov.StatusDepositPeriod, proposal1.Status) + require.Equal(t, types.StatusDepositPeriod, proposal1.Status) // Ensure query proposals returns properly proposalsQuery = testutil.QueryGovProposals(f) @@ -108,10 +108,10 @@ func TestCLISubmitProposal(t *testing.T) { // Fetch the proposal and ensure it is now in the voting period proposal1 = testutil.QueryGovProposal(f, 1) require.Equal(t, uint64(1), proposal1.ProposalID) - require.Equal(t, gov.StatusVotingPeriod, proposal1.Status) + require.Equal(t, types.StatusVotingPeriod, proposal1.Status) // Test vote generate only - success, stdout, stderr = testutil.TxGovVote(f, 1, gov.OptionYes, fooAddr.String(), "--generate-only") + success, stdout, stderr = testutil.TxGovVote(f, 1, types.OptionYes, fooAddr.String(), "--generate-only") require.True(t, success) require.Empty(t, stderr) msg = cli.UnmarshalStdTx(t, f.Cdc, stdout) @@ -120,19 +120,19 @@ func TestCLISubmitProposal(t *testing.T) { require.Equal(t, 0, len(msg.GetSignatures())) // Vote on the proposal - testutil.TxGovVote(f, 1, gov.OptionYes, cli.KeyFoo, "-y") + testutil.TxGovVote(f, 1, types.OptionYes, cli.KeyFoo, "-y") tests.WaitForNextNBlocksTM(1, f.Port) // Query the vote vote := testutil.QueryGovVote(f, 1, fooAddr) require.Equal(t, uint64(1), vote.ProposalID) - require.Equal(t, gov.OptionYes, vote.Option) + require.Equal(t, types.OptionYes, vote.Option) // Query the votes votes := testutil.QueryGovVotes(f, 1) require.Len(t, votes, 1) require.Equal(t, uint64(1), votes[0].ProposalID) - require.Equal(t, gov.OptionYes, votes[0].Option) + require.Equal(t, types.OptionYes, votes[0].Option) // Ensure events are applied to voting transaction properly searchResult = f.QueryTxs(1, 50, "message.action=vote", fmt.Sprintf("message.sender=%s", fooAddr))