Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/gov: remove alias.go usage #6432

Merged
merged 4 commits into from
Jun 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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