Skip to content

Commit

Permalink
x/gov: remove alias.go usage (#6432)
Browse files Browse the repository at this point in the history
  • Loading branch information
dauTT committed Jun 13, 2020
1 parent c3ff8c0 commit 1783f5e
Show file tree
Hide file tree
Showing 19 changed files with 130 additions and 275 deletions.
22 changes: 12 additions & 10 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
"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"
Expand Down Expand Up @@ -90,7 +92,7 @@ var (
minttypes.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},
}

Expand Down Expand Up @@ -128,7 +130,7 @@ type SimApp struct {
SlashingKeeper slashingkeeper.Keeper
MintKeeper mintkeeper.Keeper
DistrKeeper distr.Keeper
GovKeeper gov.Keeper
GovKeeper govkeeper.Keeper
CrisisKeeper crisis.Keeper
UpgradeKeeper upgradekeeper.Keeper
ParamsKeeper paramskeeper.Keeper
Expand Down Expand Up @@ -163,7 +165,7 @@ func NewSimApp(
keys := sdk.NewKVStoreKeys(
auth.StoreKey, bank.StoreKey, stakingtypes.StoreKey,
minttypes.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)
Expand All @@ -188,7 +190,7 @@ func NewSimApp(
app.subspaces[minttypes.ModuleName] = app.ParamsKeeper.Subspace(minttypes.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
Expand Down Expand Up @@ -226,13 +228,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,
)

Expand Down Expand Up @@ -300,7 +302,7 @@ func NewSimApp(
upgradetypes.ModuleName, minttypes.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.
Expand All @@ -309,7 +311,7 @@ func NewSimApp(
// can do so safely.
app.mm.SetOrderInitGenesis(
capability.ModuleName, auth.ModuleName, distr.ModuleName, stakingtypes.ModuleName, bank.ModuleName,
slashingtypes.ModuleName, gov.ModuleName, minttypes.ModuleName, crisis.ModuleName,
slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, crisis.ModuleName,
ibc.ModuleName, genutiltypes.ModuleName, evidence.ModuleName, transfer.ModuleName,
)

Expand Down
4 changes: 2 additions & 2 deletions simapp/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
Expand Down Expand Up @@ -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{}},
Expand Down
4 changes: 2 additions & 2 deletions x/distribution/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions x/distribution/client/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions x/distribution/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,7 +26,7 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
&MsgSetWithdrawAddress{},
)
registry.RegisterImplementations(
(*gov.Content)(nil),
(*govtypes.Content)(nil),
&CommunityPoolSpendProposal{},
)
}
Expand Down
13 changes: 7 additions & 6 deletions x/gov/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand All @@ -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"

Expand All @@ -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"
}
Expand Down
39 changes: 20 additions & 19 deletions x/gov/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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],
)
Expand Down Expand Up @@ -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],
)
Expand All @@ -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],
)
Expand Down Expand Up @@ -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],
)
Expand All @@ -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())
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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()

Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
Loading

0 comments on commit 1783f5e

Please sign in to comment.