diff --git a/simapp/app.go b/simapp/app.go index f3fa79e40..7e3f8b6bf 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -22,6 +22,8 @@ import ( "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/capability" "github.com/cosmos/cosmos-sdk/x/crisis" + crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper" + crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" distr "github.com/cosmos/cosmos-sdk/x/distribution" distrclient "github.com/cosmos/cosmos-sdk/x/distribution/client" distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" @@ -140,7 +142,7 @@ type SimApp struct { MintKeeper mintkeeper.Keeper DistrKeeper distrkeeper.Keeper GovKeeper govkeeper.Keeper - CrisisKeeper crisis.Keeper + CrisisKeeper crisiskeeper.Keeper UpgradeKeeper upgradekeeper.Keeper ParamsKeeper paramskeeper.Keeper IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly @@ -200,7 +202,7 @@ func NewSimApp( app.subspaces[distrtypes.ModuleName] = app.ParamsKeeper.Subspace(distrtypes.DefaultParamspace) app.subspaces[slashingtypes.ModuleName] = app.ParamsKeeper.Subspace(slashingtypes.DefaultParamspace) app.subspaces[govtypes.ModuleName] = app.ParamsKeeper.Subspace(govtypes.DefaultParamspace).WithKeyTable(govtypes.ParamKeyTable()) - app.subspaces[crisis.ModuleName] = app.ParamsKeeper.Subspace(crisis.DefaultParamspace) + app.subspaces[crisistypes.ModuleName] = app.ParamsKeeper.Subspace(crisistypes.DefaultParamspace) // set the BaseApp's parameter store bApp.SetParamStore(app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(std.ConsensusParamsKeyTable())) @@ -231,8 +233,8 @@ func NewSimApp( app.SlashingKeeper = slashingkeeper.NewKeeper( appCodec, keys[slashingtypes.StoreKey], &stakingKeeper, app.subspaces[slashingtypes.ModuleName], ) - app.CrisisKeeper = crisis.NewKeeper( - app.subspaces[crisis.ModuleName], invCheckPeriod, app.BankKeeper, auth.FeeCollectorName, + app.CrisisKeeper = crisiskeeper.NewKeeper( + app.subspaces[crisistypes.ModuleName], invCheckPeriod, app.BankKeeper, auth.FeeCollectorName, ) app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath) @@ -311,7 +313,7 @@ func NewSimApp( upgradetypes.ModuleName, minttypes.ModuleName, distrtypes.ModuleName, slashingtypes.ModuleName, evidencetypes.ModuleName, stakingtypes.ModuleName, ibchost.ModuleName, ) - app.mm.SetOrderEndBlockers(crisis.ModuleName, govtypes.ModuleName, stakingtypes.ModuleName) + app.mm.SetOrderEndBlockers(crisistypes.ModuleName, govtypes.ModuleName, stakingtypes.ModuleName) // NOTE: The genutils moodule must occur after staking so that pools are // properly initialized with tokens from genesis accounts. @@ -320,7 +322,7 @@ func NewSimApp( // can do so safely. app.mm.SetOrderInitGenesis( capability.ModuleName, auth.ModuleName, distrtypes.ModuleName, stakingtypes.ModuleName, bank.ModuleName, - slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, crisis.ModuleName, + slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, crisistypes.ModuleName, ibchost.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, ibctransfertypes.ModuleName, ) diff --git a/x/crisis/abci.go b/x/crisis/abci.go index 3e5485979..482a069b5 100644 --- a/x/crisis/abci.go +++ b/x/crisis/abci.go @@ -2,10 +2,11 @@ package crisis import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/crisis/keeper" ) // check all registered invariants -func EndBlocker(ctx sdk.Context, k Keeper) { +func EndBlocker(ctx sdk.Context, k keeper.Keeper) { if k.InvCheckPeriod() == 0 || ctx.BlockHeight()%int64(k.InvCheckPeriod()) != 0 { // skip running the invariant check return diff --git a/x/crisis/alias.go b/x/crisis/alias.go deleted file mode 100644 index 7a93ff659..000000000 --- a/x/crisis/alias.go +++ /dev/null @@ -1,35 +0,0 @@ -package crisis - -import ( - "github.com/cosmos/cosmos-sdk/x/crisis/keeper" - "github.com/cosmos/cosmos-sdk/x/crisis/types" -) - -const ( - ModuleName = types.ModuleName - DefaultParamspace = types.DefaultParamspace - EventTypeInvariant = types.EventTypeInvariant - AttributeValueCrisis = types.AttributeValueCrisis - AttributeKeyRoute = types.AttributeKeyRoute -) - -var ( - RegisterCodec = types.RegisterCodec - ErrNoSender = types.ErrNoSender - ErrUnknownInvariant = types.ErrUnknownInvariant - NewGenesisState = types.NewGenesisState - DefaultGenesisState = types.DefaultGenesisState - NewMsgVerifyInvariant = types.NewMsgVerifyInvariant - ParamKeyTable = types.ParamKeyTable - NewInvarRoute = types.NewInvarRoute - NewKeeper = keeper.NewKeeper - ModuleCdc = types.ModuleCdc - ParamStoreKeyConstantFee = types.ParamStoreKeyConstantFee -) - -type ( - GenesisState = types.GenesisState - MsgVerifyInvariant = types.MsgVerifyInvariant - InvarRoute = types.InvarRoute - Keeper = keeper.Keeper -) diff --git a/x/crisis/handler_test.go b/x/crisis/handler_test.go index 31c27cb9d..564b888e3 100644 --- a/x/crisis/handler_test.go +++ b/x/crisis/handler_test.go @@ -13,14 +13,15 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/crisis" + "github.com/cosmos/cosmos-sdk/x/crisis/types" distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) var ( testModuleName = "dummy" - dummyRouteWhichPasses = crisis.NewInvarRoute(testModuleName, "which-passes", func(_ sdk.Context) (string, bool) { return "", false }) - dummyRouteWhichFails = crisis.NewInvarRoute(testModuleName, "which-fails", func(_ sdk.Context) (string, bool) { return "whoops", true }) + dummyRouteWhichPasses = types.NewInvarRoute(testModuleName, "which-passes", func(_ sdk.Context) (string, bool) { return "", false }) + dummyRouteWhichFails = types.NewInvarRoute(testModuleName, "which-fails", func(_ sdk.Context) (string, bool) { return "whoops", true }) ) func createTestApp() (*simapp.SimApp, sdk.Context, []sdk.AccAddress) { @@ -56,9 +57,9 @@ func TestHandleMsgVerifyInvariant(t *testing.T) { msg sdk.Msg expectedResult string }{ - {"bad invariant route", crisis.NewMsgVerifyInvariant(sender, testModuleName, "route-that-doesnt-exist"), "fail"}, - {"invariant broken", crisis.NewMsgVerifyInvariant(sender, testModuleName, dummyRouteWhichFails.Route), "panic"}, - {"invariant passing", crisis.NewMsgVerifyInvariant(sender, testModuleName, dummyRouteWhichPasses.Route), "pass"}, + {"bad invariant route", types.NewMsgVerifyInvariant(sender, testModuleName, "route-that-doesnt-exist"), "fail"}, + {"invariant broken", types.NewMsgVerifyInvariant(sender, testModuleName, dummyRouteWhichFails.Route), "panic"}, + {"invariant passing", types.NewMsgVerifyInvariant(sender, testModuleName, dummyRouteWhichPasses.Route), "pass"}, {"invalid msg", sdk.NewTestMsg(), "fail"}, } @@ -95,7 +96,7 @@ func TestHandleMsgVerifyInvariantWithNotEnoughSenderCoins(t *testing.T) { app.CrisisKeeper.SetConstantFee(ctx, excessCoins) h := crisis.NewHandler(app.CrisisKeeper) - msg := crisis.NewMsgVerifyInvariant(sender, testModuleName, dummyRouteWhichPasses.Route) + msg := types.NewMsgVerifyInvariant(sender, testModuleName, dummyRouteWhichPasses.Route) res, err := h(ctx, msg) require.Error(t, err) @@ -112,7 +113,7 @@ func TestHandleMsgVerifyInvariantWithInvariantBrokenAndNotEnoughPoolCoins(t *tes app.DistrKeeper.SetFeePool(ctx, feePool) h := crisis.NewHandler(app.CrisisKeeper) - msg := crisis.NewMsgVerifyInvariant(sender, testModuleName, dummyRouteWhichFails.Route) + msg := types.NewMsgVerifyInvariant(sender, testModuleName, dummyRouteWhichFails.Route) var res *sdk.Result require.Panics(t, func() { diff --git a/x/crisis/module.go b/x/crisis/module.go index 8bf205202..62e50b91e 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -30,25 +30,25 @@ type AppModuleBasic struct{} // Name returns the crisis module's name. func (AppModuleBasic) Name() string { - return ModuleName + return types.ModuleName } // RegisterCodec registers the crisis 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 crisis // 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 crisis module. func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessage) error { 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 types.ValidateGenesis(data) @@ -87,7 +87,7 @@ func NewAppModule(keeper *keeper.Keeper) AppModule { // Name returns the crisis module's name. func (AppModule) Name() string { - return ModuleName + return types.ModuleName } // RegisterInvariants performs a no-op. @@ -109,7 +109,7 @@ func (am AppModule) RegisterQueryService(grpc.Server) {} // InitGenesis performs genesis initialization for the crisis 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, genesisState)