From deaa01a36ddc98f80a452a673d4573b79ea93aaa Mon Sep 17 00:00:00 2001 From: rustdev Date: Sat, 23 Dec 2023 14:45:15 +0000 Subject: [PATCH] fix all tests in project after adding custom staking. --- app/app.go | 4 +-- app/export.go | 2 +- app/keepers/keepers.go | 64 ++++++++++++++++----------------- app/test_access.go | 2 +- custom/staking/keeper/keeper.go | 17 ++++----- 5 files changed, 44 insertions(+), 45 deletions(-) diff --git a/app/app.go b/app/app.go index fe5e82fe8..9f93a231c 100644 --- a/app/app.go +++ b/app/app.go @@ -361,7 +361,7 @@ func NewComposableApp( mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil), slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(slashingtypes.ModuleName)), distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(distrtypes.ModuleName)), - customstaking.NewAppModule(appCodec, app.CustomStakingKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName)), + customstaking.NewAppModule(appCodec, *app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName)), stakingmiddleware.NewAppModule(appCodec, app.StakingMiddlewareKeeper), authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), upgrade.NewAppModule(app.UpgradeKeeper), @@ -581,7 +581,7 @@ func (app *ComposableApp) GetBaseApp() *baseapp.BaseApp { return app.BaseApp } // GetStakingKeeper implements the TestingApp interface. func (app *ComposableApp) GetStakingKeeper() ibctestingtypes.StakingKeeper { - return app.CustomStakingKeeper + return app.StakingKeeper } // GetIBCKeeper implements the TestingApp interface. diff --git a/app/export.go b/app/export.go index 282f4ff5f..a33330220 100644 --- a/app/export.go +++ b/app/export.go @@ -35,7 +35,7 @@ func (app *ComposableApp) ExportAppStateAndValidators( return servertypes.ExportedApp{}, err } - validators, err := staking.WriteValidators(ctx, app.StakingKeeper) + validators, err := staking.WriteValidators(ctx, &app.StakingKeeper.Keeper) if err != nil { return servertypes.ExportedApp{}, err } diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index b56be110d..c882dc4d8 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -45,7 +45,6 @@ import ( slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" - stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" customstaking "github.com/notional-labs/composable/v6/custom/staking/keeper" @@ -115,31 +114,30 @@ type AppKeepers struct { memKeys map[string]*storetypes.MemoryStoreKey // keepers - AccountKeeper authkeeper.AccountKeeper - BankKeeper custombankkeeper.Keeper - CapabilityKeeper *capabilitykeeper.Keeper - StakingKeeper *stakingkeeper.Keeper - CustomStakingKeeper customstaking.Keeper - SlashingKeeper slashingkeeper.Keeper - MintKeeper mintkeeper.Keeper - DistrKeeper distrkeeper.Keeper - GovKeeper govkeeper.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 - EvidenceKeeper evidencekeeper.Keeper - TransferKeeper ibctransferkeeper.Keeper - ICQKeeper icqkeeper.Keeper - ICAHostKeeper icahostkeeper.Keeper - FeeGrantKeeper feegrantkeeper.Keeper - AuthzKeeper authzkeeper.Keeper - GroupKeeper groupkeeper.Keeper - Wasm08Keeper wasm08Keeper.Keeper // TODO: use this name ? - WasmKeeper wasm.Keeper - IBCHooksKeeper *ibchookskeeper.Keeper - Ics20WasmHooks *ibc_hooks.WasmHooks - HooksICS4Wrapper ibc_hooks.ICS4Middleware + AccountKeeper authkeeper.AccountKeeper + BankKeeper custombankkeeper.Keeper + CapabilityKeeper *capabilitykeeper.Keeper + StakingKeeper *customstaking.Keeper + SlashingKeeper slashingkeeper.Keeper + MintKeeper mintkeeper.Keeper + DistrKeeper distrkeeper.Keeper + GovKeeper govkeeper.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 + EvidenceKeeper evidencekeeper.Keeper + TransferKeeper ibctransferkeeper.Keeper + ICQKeeper icqkeeper.Keeper + ICAHostKeeper icahostkeeper.Keeper + FeeGrantKeeper feegrantkeeper.Keeper + AuthzKeeper authzkeeper.Keeper + GroupKeeper groupkeeper.Keeper + Wasm08Keeper wasm08Keeper.Keeper // TODO: use this name ? + WasmKeeper wasm.Keeper + IBCHooksKeeper *ibchookskeeper.Keeper + Ics20WasmHooks *ibc_hooks.WasmHooks + HooksICS4Wrapper ibc_hooks.ICS4Middleware // make scoped keepers public for test purposes ScopedIBCKeeper capabilitykeeper.ScopedKeeper ScopedTransferKeeper capabilitykeeper.ScopedKeeper @@ -184,8 +182,10 @@ func (appKeepers *AppKeepers) InitNormalKeepers( appKeepers.AccountKeeper, ) - appKeepers.StakingKeeper = stakingkeeper.NewKeeper( - appCodec, appKeepers.keys[stakingtypes.StoreKey], appKeepers.AccountKeeper, appKeepers.BankKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), + appKeepers.StakingMiddlewareKeeper = stakingmiddleware.NewKeeper(appCodec, appKeepers.keys[stakingmiddlewaretypes.StoreKey], authtypes.NewModuleAddress(govtypes.ModuleName).String()) + + appKeepers.StakingKeeper = customstaking.NewKeeper( + appCodec, appKeepers.keys[stakingtypes.StoreKey], appKeepers.AccountKeeper, appKeepers.BankKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), &appKeepers.StakingMiddlewareKeeper, ) appKeepers.MintKeeper = mintkeeper.NewKeeper( @@ -193,11 +193,9 @@ func (appKeepers *AppKeepers) InitNormalKeepers( appKeepers.AccountKeeper, appKeepers.BankKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) - appKeepers.StakingMiddlewareKeeper = stakingmiddleware.NewKeeper(appCodec, appKeepers.keys[stakingmiddlewaretypes.StoreKey], authtypes.NewModuleAddress(govtypes.ModuleName).String()) - - appKeepers.CustomStakingKeeper = customstaking.NewKeeper( - appCodec, *appKeepers.StakingKeeper, &appKeepers.StakingMiddlewareKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), - ) + // appKeepers.CustomStakingKeeper = customstaking.NewKeeper( + // appCodec, *appKeepers.StakingKeeper, &appKeepers.StakingMiddlewareKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), + // ) appKeepers.DistrKeeper = distrkeeper.NewKeeper( appCodec, appKeepers.keys[distrtypes.StoreKey], appKeepers.AccountKeeper, appKeepers.BankKeeper, diff --git a/app/test_access.go b/app/test_access.go index 78a65b7d2..88fb03c52 100644 --- a/app/test_access.go +++ b/app/test_access.go @@ -47,7 +47,7 @@ func (s TestSupport) ScopedTransferKeeper() capabilitykeeper.ScopedKeeper { } func (s TestSupport) StakingKeeper() *stakingkeeper.Keeper { - return s.app.StakingKeeper + return &s.app.StakingKeeper.Keeper } func (s TestSupport) AccountKeeper() authkeeper.AccountKeeper { diff --git a/custom/staking/keeper/keeper.go b/custom/staking/keeper/keeper.go index c1cff8acb..5575c9849 100644 --- a/custom/staking/keeper/keeper.go +++ b/custom/staking/keeper/keeper.go @@ -6,6 +6,7 @@ import ( stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" "github.com/cosmos/cosmos-sdk/x/staking/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" stakingmiddleware "github.com/notional-labs/composable/v6/x/stakingmiddleware/keeper" ) @@ -27,13 +28,11 @@ func (k Keeper) BlockValidatorUpdates(ctx sdk.Context, height int64) []abcicomet // unbonded after the Endblocker (go from Bonded -> Unbonding during // ApplyAndReturnValidatorSetUpdates and then Unbonding -> Unbonded during // UnbondAllMatureValidatorQueue). - println("BlockValidatorUpdates Custom Staking Module") params := k.Stakingmiddleware.GetParams(ctx) - println("BlocksPerEpoch: ", params.BlocksPerEpoch) shouldExecuteBatch := (height % int64(params.BlocksPerEpoch)) == 0 var validatorUpdates []abcicometbft.ValidatorUpdate if shouldExecuteBatch { - println("Should Execute Batch: ", height) + println("Should Execute ApplyAndReturnValidatorSetUpdates at height : ", height) v, err := k.ApplyAndReturnValidatorSetUpdates(ctx) if err != nil { panic(err) @@ -107,15 +106,17 @@ func (k Keeper) BlockValidatorUpdates(ctx sdk.Context, height int64) []abcicomet func NewKeeper( cdc codec.BinaryCodec, - staking stakingkeeper.Keeper, - stakingmiddleware *stakingmiddleware.Keeper, + key storetypes.StoreKey, + ak types.AccountKeeper, + bk types.BankKeeper, authority string, -) Keeper { + stakingmiddleware *stakingmiddleware.Keeper, +) *Keeper { keeper := Keeper{ - Keeper: staking, + Keeper: *stakingkeeper.NewKeeper(cdc, key, ak, bk, authority), authority: authority, Stakingmiddleware: stakingmiddleware, cdc: cdc, } - return keeper + return &keeper }