Skip to content

Commit

Permalink
Merge PR cosmos#6424: x/mint - remove alias.go usage
Browse files Browse the repository at this point in the history
  • Loading branch information
dauTT authored Jun 13, 2020
1 parent 60f7edf commit 73bdb7d
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 84 deletions.
18 changes: 10 additions & 8 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (
ibcclient "github.com/cosmos/cosmos-sdk/x/ibc/02-client"
port "github.com/cosmos/cosmos-sdk/x/ibc/05-port"
"github.com/cosmos/cosmos-sdk/x/mint"
mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
"github.com/cosmos/cosmos-sdk/x/params"
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
Expand Down Expand Up @@ -84,7 +86,7 @@ var (
maccPerms = map[string][]string{
auth.FeeCollectorName: nil,
distr.ModuleName: nil,
mint.ModuleName: {auth.Minter},
minttypes.ModuleName: {auth.Minter},
stakingtypes.BondedPoolName: {auth.Burner, auth.Staking},
stakingtypes.NotBondedPoolName: {auth.Burner, auth.Staking},
gov.ModuleName: {auth.Burner},
Expand Down Expand Up @@ -123,7 +125,7 @@ type SimApp struct {
CapabilityKeeper *capability.Keeper
StakingKeeper stakingkeeper.Keeper
SlashingKeeper slashingkeeper.Keeper
MintKeeper mint.Keeper
MintKeeper mintkeeper.Keeper
DistrKeeper distr.Keeper
GovKeeper gov.Keeper
CrisisKeeper crisis.Keeper
Expand Down Expand Up @@ -159,7 +161,7 @@ func NewSimApp(

keys := sdk.NewKVStoreKeys(
auth.StoreKey, bank.StoreKey, stakingtypes.StoreKey,
mint.StoreKey, distr.StoreKey, slashingtypes.StoreKey,
minttypes.StoreKey, distr.StoreKey, slashingtypes.StoreKey,
gov.StoreKey, paramstypes.StoreKey, ibc.StoreKey, upgradetypes.StoreKey,
evidence.StoreKey, transfer.StoreKey, capability.StoreKey,
)
Expand All @@ -182,7 +184,7 @@ func NewSimApp(
app.subspaces[auth.ModuleName] = app.ParamsKeeper.Subspace(auth.DefaultParamspace)
app.subspaces[bank.ModuleName] = app.ParamsKeeper.Subspace(bank.DefaultParamspace)
app.subspaces[stakingtypes.ModuleName] = app.ParamsKeeper.Subspace(stakingkeeper.DefaultParamspace)
app.subspaces[mint.ModuleName] = app.ParamsKeeper.Subspace(mint.DefaultParamspace)
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())
Expand All @@ -206,8 +208,8 @@ func NewSimApp(
stakingKeeper := stakingkeeper.NewKeeper(
appCodec, keys[stakingtypes.StoreKey], app.AccountKeeper, app.BankKeeper, app.subspaces[stakingtypes.ModuleName],
)
app.MintKeeper = mint.NewKeeper(
appCodec, keys[mint.StoreKey], app.subspaces[mint.ModuleName], &stakingKeeper,
app.MintKeeper = mintkeeper.NewKeeper(
appCodec, keys[minttypes.StoreKey], app.subspaces[minttypes.ModuleName], &stakingKeeper,
app.AccountKeeper, app.BankKeeper, auth.FeeCollectorName,
)
app.DistrKeeper = distr.NewKeeper(
Expand Down Expand Up @@ -294,7 +296,7 @@ func NewSimApp(
// CanWithdrawInvariant invariant.
// NOTE: staking module is required if HistoricalEntries param > 0
app.mm.SetOrderBeginBlockers(
upgradetypes.ModuleName, mint.ModuleName, distr.ModuleName, slashingtypes.ModuleName,
upgradetypes.ModuleName, minttypes.ModuleName, distr.ModuleName, slashingtypes.ModuleName,
evidence.ModuleName, stakingtypes.ModuleName, ibc.ModuleName,
)
app.mm.SetOrderEndBlockers(crisis.ModuleName, gov.ModuleName, stakingtypes.ModuleName)
Expand All @@ -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, gov.ModuleName, minttypes.ModuleName, crisis.ModuleName,
ibc.ModuleName, genutil.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 @@ -25,7 +25,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/gov"
"github.com/cosmos/cosmos-sdk/x/ibc"
transfer "github.com/cosmos/cosmos-sdk/x/ibc-transfer"
"github.com/cosmos/cosmos-sdk/x/mint"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/cosmos/cosmos-sdk/x/simulation"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
Expand Down Expand Up @@ -155,7 +155,7 @@ func TestAppImportExport(t *testing.T) {
stakingtypes.HistoricalInfoKey,
}}, // ordering may change but it doesn't matter
{app.keys[slashingtypes.StoreKey], newApp.keys[slashingtypes.StoreKey], [][]byte{}},
{app.keys[mint.StoreKey], newApp.keys[mint.StoreKey], [][]byte{}},
{app.keys[minttypes.StoreKey], newApp.keys[minttypes.StoreKey], [][]byte{}},
{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{}},
Expand Down
8 changes: 4 additions & 4 deletions x/distribution/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/cosmos/cosmos-sdk/tests/cli"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/distribution/client/testutil"
"github.com/cosmos/cosmos-sdk/x/mint"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
)

func TestCLIWithdrawRewards(t *testing.T) {
Expand All @@ -22,14 +22,14 @@ func TestCLIWithdrawRewards(t *testing.T) {

genesisState := f.GenesisState()
inflationMin := sdk.MustNewDecFromStr("1.0")
var mintData mint.GenesisState
f.Cdc.UnmarshalJSON(genesisState[mint.ModuleName], &mintData)
var mintData minttypes.GenesisState
f.Cdc.UnmarshalJSON(genesisState[minttypes.ModuleName], &mintData)
mintData.Minter.Inflation = inflationMin
mintData.Params.InflationMin = inflationMin
mintData.Params.InflationMax = sdk.MustNewDecFromStr("1.0")
mintDataBz, err := f.Cdc.MarshalJSON(mintData)
require.NoError(t, err)
genesisState[mint.ModuleName] = mintDataBz
genesisState[minttypes.ModuleName] = mintDataBz

genFile := filepath.Join(f.SimdHome, "config", "genesis.json")
genDoc, err := tmtypes.GenesisDocFromFile(genFile)
Expand Down
3 changes: 2 additions & 1 deletion x/mint/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package mint

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/mint/keeper"
"github.com/cosmos/cosmos-sdk/x/mint/types"
)

// BeginBlocker mints new tokens for the previous block.
func BeginBlocker(ctx sdk.Context, k Keeper) {
func BeginBlocker(ctx sdk.Context, k keeper.Keeper) {
// fetch stored minter & params
minter := k.GetMinter(ctx)
params := k.GetParams(ctx)
Expand Down
48 changes: 0 additions & 48 deletions x/mint/alias.go

This file was deleted.

9 changes: 5 additions & 4 deletions x/mint/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@ package mint

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/mint/keeper"
"github.com/cosmos/cosmos-sdk/x/mint/types"
)

// InitGenesis new mint genesis
func InitGenesis(ctx sdk.Context, keeper Keeper, ak types.AccountKeeper, data GenesisState) {
func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, ak types.AccountKeeper, data types.GenesisState) {
keeper.SetMinter(ctx, data.Minter)
keeper.SetParams(ctx, data.Params)
ak.GetModuleAccount(ctx, ModuleName)
ak.GetModuleAccount(ctx, types.ModuleName)
}

// ExportGenesis returns a GenesisState for a given context and keeper.
func ExportGenesis(ctx sdk.Context, keeper Keeper) GenesisState {
func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) types.GenesisState {
minter := keeper.GetMinter(ctx)
params := keeper.GetParams(ctx)
return NewGenesisState(minter, params)
return types.NewGenesisState(minter, params)
}
25 changes: 13 additions & 12 deletions x/mint/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/mint/client/cli"
"github.com/cosmos/cosmos-sdk/x/mint/client/rest"
"github.com/cosmos/cosmos-sdk/x/mint/keeper"
"github.com/cosmos/cosmos-sdk/x/mint/simulation"
"github.com/cosmos/cosmos-sdk/x/mint/types"
)
Expand All @@ -37,7 +38,7 @@ var _ module.AppModuleBasic = AppModuleBasic{}

// Name returns the mint module's name.
func (AppModuleBasic) Name() string {
return ModuleName
return types.ModuleName
}

// RegisterCodec registers the mint module's types for the given codec.
Expand All @@ -46,17 +47,17 @@ func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {}
// DefaultGenesis returns default genesis state as raw bytes for the mint
// 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 mint 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", ModuleName, err)
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 mint module.
Expand All @@ -78,12 +79,12 @@ func (AppModuleBasic) GetQueryCmd(clientCtx client.Context) *cobra.Command {
type AppModule struct {
AppModuleBasic

keeper Keeper
keeper keeper.Keeper
authKeeper types.AccountKeeper
}

// NewAppModule creates a new AppModule object
func NewAppModule(cdc codec.Marshaler, keeper Keeper, ak types.AccountKeeper) AppModule {
func NewAppModule(cdc codec.Marshaler, keeper keeper.Keeper, ak types.AccountKeeper) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{cdc: cdc},
keeper: keeper,
Expand All @@ -93,7 +94,7 @@ func NewAppModule(cdc codec.Marshaler, keeper Keeper, ak types.AccountKeeper) Ap

// Name returns the mint module's name.
func (AppModule) Name() string {
return ModuleName
return types.ModuleName
}

// RegisterInvariants registers the mint module invariants.
Expand All @@ -104,20 +105,20 @@ func (AppModule) Route() sdk.Route { return sdk.Route{} }

// QuerierRoute returns the mint module's querier route name.
func (AppModule) QuerierRoute() string {
return QuerierRoute
return types.QuerierRoute
}

// NewQuerierHandler returns the mint module sdk.Querier.
func (am AppModule) NewQuerierHandler() sdk.Querier {
return NewQuerier(am.keeper)
return keeper.NewQuerier(am.keeper)
}

func (am AppModule) RegisterQueryService(grpc.Server) {}

// InitGenesis performs genesis initialization for the mint 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.keeper, am.authKeeper, genesisState)
Expand Down Expand Up @@ -163,7 +164,7 @@ func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange {

// RegisterStoreDecoder registers a decoder for mint module's types.
func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) {
sdr[StoreKey] = simulation.NewDecodeStore(am.cdc)
sdr[types.StoreKey] = simulation.NewDecodeStore(am.cdc)
}

// WeightedOperations doesn't return any mint module operation.
Expand Down
10 changes: 5 additions & 5 deletions x/mint/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/mint"
"github.com/cosmos/cosmos-sdk/x/mint/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(mint.ModuleName))
acc := app.AccountKeeper.GetAccount(ctx, auth.NewModuleAddress(types.ModuleName))
require.NotNil(t, acc)
}

0 comments on commit 73bdb7d

Please sign in to comment.