diff --git a/CHANGELOG.md b/CHANGELOG.md index f5fd1725d2d8..3d23427aa35a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -120,6 +120,7 @@ be used to retrieve the actual proposal `Content`. Also the `NewMsgSubmitProposa * (client) [\#6290](https://github.com/cosmos/cosmos-sdk/pull/6290) `CLIContext` is renamed to `Context`. `Context` and all related methods have been moved from package context to client. * (modules) [\#6326](https://github.com/cosmos/cosmos-sdk/pull/6326) `AppModuleBasic.GetQueryCmd` now takes a single `CLIContext` parameter. * (modules) [\#6336](https://github.com/cosmos/cosmos-sdk/pull/6336) `AppModuleBasic.RegisterQueryService` method was added to support gRPC queries, and `QuerierRoute` and `NewQuerierHandler` were deprecated. +* (modules) [\#6311](https://github.com/cosmos/cosmos-sdk/issues/6311) Remove `alias.go` usage Migration guide: diff --git a/simapp/app.go b/simapp/app.go index 6c3d3f75d533..0d88659675c7 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -40,6 +40,8 @@ import ( slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/cosmos/cosmos-sdk/x/upgrade" upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client" upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" @@ -80,13 +82,13 @@ var ( // module account permissions maccPerms = map[string][]string{ - auth.FeeCollectorName: nil, - distr.ModuleName: nil, - mint.ModuleName: {auth.Minter}, - staking.BondedPoolName: {auth.Burner, auth.Staking}, - staking.NotBondedPoolName: {auth.Burner, auth.Staking}, - gov.ModuleName: {auth.Burner}, - transfer.ModuleName: {auth.Minter, auth.Burner}, + auth.FeeCollectorName: nil, + distr.ModuleName: nil, + mint.ModuleName: {auth.Minter}, + stakingtypes.BondedPoolName: {auth.Burner, auth.Staking}, + stakingtypes.NotBondedPoolName: {auth.Burner, auth.Staking}, + gov.ModuleName: {auth.Burner}, + transfer.ModuleName: {auth.Minter, auth.Burner}, } // module accounts that are allowed to receive tokens @@ -119,7 +121,7 @@ type SimApp struct { AccountKeeper auth.AccountKeeper BankKeeper bank.Keeper CapabilityKeeper *capability.Keeper - StakingKeeper staking.Keeper + StakingKeeper stakingkeeper.Keeper SlashingKeeper slashingkeeper.Keeper MintKeeper mint.Keeper DistrKeeper distr.Keeper @@ -156,7 +158,7 @@ func NewSimApp( bApp.SetAppVersion(version.Version) keys := sdk.NewKVStoreKeys( - auth.StoreKey, bank.StoreKey, staking.StoreKey, + auth.StoreKey, bank.StoreKey, stakingtypes.StoreKey, mint.StoreKey, distr.StoreKey, slashingtypes.StoreKey, gov.StoreKey, paramstypes.StoreKey, ibc.StoreKey, upgradetypes.StoreKey, evidence.StoreKey, transfer.StoreKey, capability.StoreKey, @@ -179,7 +181,7 @@ func NewSimApp( app.ParamsKeeper = paramskeeper.NewKeeper(appCodec, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey]) app.subspaces[auth.ModuleName] = app.ParamsKeeper.Subspace(auth.DefaultParamspace) app.subspaces[bank.ModuleName] = app.ParamsKeeper.Subspace(bank.DefaultParamspace) - app.subspaces[staking.ModuleName] = app.ParamsKeeper.Subspace(staking.DefaultParamspace) + app.subspaces[stakingtypes.ModuleName] = app.ParamsKeeper.Subspace(stakingkeeper.DefaultParamspace) app.subspaces[mint.ModuleName] = app.ParamsKeeper.Subspace(mint.DefaultParamspace) app.subspaces[distr.ModuleName] = app.ParamsKeeper.Subspace(distr.DefaultParamspace) app.subspaces[slashingtypes.ModuleName] = app.ParamsKeeper.Subspace(slashingtypes.DefaultParamspace) @@ -201,8 +203,8 @@ func NewSimApp( app.BankKeeper = bank.NewBaseKeeper( appCodec, keys[bank.StoreKey], app.AccountKeeper, app.subspaces[bank.ModuleName], app.BlacklistedAccAddrs(), ) - stakingKeeper := staking.NewKeeper( - appCodec, keys[staking.StoreKey], app.AccountKeeper, app.BankKeeper, app.subspaces[staking.ModuleName], + 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, @@ -234,7 +236,7 @@ func NewSimApp( // register the staking hooks // NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks app.StakingKeeper = *stakingKeeper.SetHooks( - staking.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()), + stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()), ) // Create IBC Keeper @@ -293,9 +295,9 @@ func NewSimApp( // NOTE: staking module is required if HistoricalEntries param > 0 app.mm.SetOrderBeginBlockers( upgradetypes.ModuleName, mint.ModuleName, distr.ModuleName, slashingtypes.ModuleName, - evidence.ModuleName, staking.ModuleName, ibc.ModuleName, + evidence.ModuleName, stakingtypes.ModuleName, ibc.ModuleName, ) - app.mm.SetOrderEndBlockers(crisis.ModuleName, gov.ModuleName, staking.ModuleName) + app.mm.SetOrderEndBlockers(crisis.ModuleName, gov.ModuleName, stakingtypes.ModuleName) // NOTE: The genutils moodule must occur after staking so that pools are // properly initialized with tokens from genesis accounts. @@ -303,7 +305,7 @@ func NewSimApp( // so that other modules that want to create or claim capabilities afterwards in InitChain // can do so safely. app.mm.SetOrderInitGenesis( - capability.ModuleName, auth.ModuleName, distr.ModuleName, staking.ModuleName, bank.ModuleName, + capability.ModuleName, auth.ModuleName, distr.ModuleName, stakingtypes.ModuleName, bank.ModuleName, slashingtypes.ModuleName, gov.ModuleName, mint.ModuleName, crisis.ModuleName, ibc.ModuleName, genutil.ModuleName, evidence.ModuleName, transfer.ModuleName, ) diff --git a/simapp/export.go b/simapp/export.go index 78a46a9660fc..363bc13954a5 100644 --- a/simapp/export.go +++ b/simapp/export.go @@ -12,6 +12,7 @@ import ( slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" "github.com/cosmos/cosmos-sdk/x/staking/exported" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) // ExportAppStateAndValidators exports the state of the application for a genesis @@ -109,7 +110,7 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailWhiteList []str /* Handle staking state. */ // iterate through redelegations, reset creation height - app.StakingKeeper.IterateRedelegations(ctx, func(_ int64, red staking.Redelegation) (stop bool) { + app.StakingKeeper.IterateRedelegations(ctx, func(_ int64, red stakingtypes.Redelegation) (stop bool) { for i := range red.Entries { red.Entries[i].CreationHeight = 0 } @@ -118,7 +119,7 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailWhiteList []str }) // iterate through unbonding delegations, reset creation height - app.StakingKeeper.IterateUnbondingDelegations(ctx, func(_ int64, ubd staking.UnbondingDelegation) (stop bool) { + app.StakingKeeper.IterateUnbondingDelegations(ctx, func(_ int64, ubd stakingtypes.UnbondingDelegation) (stop bool) { for i := range ubd.Entries { ubd.Entries[i].CreationHeight = 0 } @@ -128,8 +129,8 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailWhiteList []str // Iterate through validators by power descending, reset bond heights, and // update bond intra-tx counters. - store := ctx.KVStore(app.keys[staking.StoreKey]) - iter := sdk.KVStoreReversePrefixIterator(store, staking.ValidatorsKey) + store := ctx.KVStore(app.keys[stakingtypes.StoreKey]) + iter := sdk.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey) counter := int16(0) for ; iter.Valid(); iter.Next() { diff --git a/x/bank/bench_test.go b/x/bank/bench_test.go index a66e8d593d61..5910c300ce9e 100644 --- a/x/bank/bench_test.go +++ b/x/bank/bench_test.go @@ -10,10 +10,10 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/cosmos/cosmos-sdk/x/staking" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) -var moduleAccAddr = auth.NewModuleAddress(staking.BondedPoolName) +var moduleAccAddr = auth.NewModuleAddress(stakingtypes.BondedPoolName) func BenchmarkOneBankSendTxPerBlock(b *testing.B) { // Add an account at genesis diff --git a/x/capability/keeper/keeper_test.go b/x/capability/keeper/keeper_test.go index d74eb6b32a53..6d4317882cd9 100644 --- a/x/capability/keeper/keeper_test.go +++ b/x/capability/keeper/keeper_test.go @@ -13,7 +13,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/capability" "github.com/cosmos/cosmos-sdk/x/capability/keeper" "github.com/cosmos/cosmos-sdk/x/capability/types" - "github.com/cosmos/cosmos-sdk/x/staking" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) type KeeperTestSuite struct { @@ -69,7 +69,7 @@ func (suite *KeeperTestSuite) TestInitializeAndSeal() { }) suite.Require().Panics(func() { - _ = suite.keeper.ScopeToModule(staking.ModuleName) + _ = suite.keeper.ScopeToModule(stakingtypes.ModuleName) }) } @@ -106,7 +106,7 @@ func (suite *KeeperTestSuite) TestOriginalCapabilityKeeper() { func (suite *KeeperTestSuite) TestAuthenticateCapability() { sk1 := suite.keeper.ScopeToModule(bank.ModuleName) - sk2 := suite.keeper.ScopeToModule(staking.ModuleName) + sk2 := suite.keeper.ScopeToModule(stakingtypes.ModuleName) cap1, err := sk1.NewCapability(suite.ctx, "transfer") suite.Require().NoError(err) @@ -141,7 +141,7 @@ func (suite *KeeperTestSuite) TestAuthenticateCapability() { func (suite *KeeperTestSuite) TestClaimCapability() { sk1 := suite.keeper.ScopeToModule(bank.ModuleName) - sk2 := suite.keeper.ScopeToModule(staking.ModuleName) + sk2 := suite.keeper.ScopeToModule(stakingtypes.ModuleName) cap, err := sk1.NewCapability(suite.ctx, "transfer") suite.Require().NoError(err) @@ -161,7 +161,7 @@ func (suite *KeeperTestSuite) TestClaimCapability() { func (suite *KeeperTestSuite) TestGetOwners() { sk1 := suite.keeper.ScopeToModule(bank.ModuleName) - sk2 := suite.keeper.ScopeToModule(staking.ModuleName) + sk2 := suite.keeper.ScopeToModule(stakingtypes.ModuleName) sk3 := suite.keeper.ScopeToModule("foo") sks := []keeper.ScopedKeeper{sk1, sk2, sk3} @@ -173,7 +173,7 @@ func (suite *KeeperTestSuite) TestGetOwners() { suite.Require().NoError(sk2.ClaimCapability(suite.ctx, cap, "transfer")) suite.Require().NoError(sk3.ClaimCapability(suite.ctx, cap, "transfer")) - expectedOrder := []string{bank.ModuleName, "foo", staking.ModuleName} + expectedOrder := []string{bank.ModuleName, "foo", stakingtypes.ModuleName} // Ensure all scoped keepers can get owners for _, sk := range sks { owners, ok := sk.GetOwners(suite.ctx, "transfer") @@ -199,7 +199,7 @@ func (suite *KeeperTestSuite) TestGetOwners() { suite.Require().Nil(err, "could not release capability") // new expected order and scoped capabilities - expectedOrder = []string{bank.ModuleName, staking.ModuleName} + expectedOrder = []string{bank.ModuleName, stakingtypes.ModuleName} sks = []keeper.ScopedKeeper{sk1, sk2} // Ensure all scoped keepers can get owners @@ -226,7 +226,7 @@ func (suite *KeeperTestSuite) TestGetOwners() { func (suite *KeeperTestSuite) TestReleaseCapability() { sk1 := suite.keeper.ScopeToModule(bank.ModuleName) - sk2 := suite.keeper.ScopeToModule(staking.ModuleName) + sk2 := suite.keeper.ScopeToModule(stakingtypes.ModuleName) cap1, err := sk1.NewCapability(suite.ctx, "transfer") suite.Require().NoError(err) diff --git a/x/crisis/handler_test.go b/x/crisis/handler_test.go index 72f114bc425b..f12acf5c1dc1 100644 --- a/x/crisis/handler_test.go +++ b/x/crisis/handler_test.go @@ -14,7 +14,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/crisis" distr "github.com/cosmos/cosmos-sdk/x/distribution" - "github.com/cosmos/cosmos-sdk/x/staking" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) var ( @@ -30,7 +30,7 @@ func createTestApp() (*simapp.SimApp, sdk.Context, []sdk.AccAddress) { constantFee := sdk.NewInt64Coin(sdk.DefaultBondDenom, 10) app.CrisisKeeper.SetConstantFee(ctx, constantFee) - app.StakingKeeper.SetParams(ctx, staking.DefaultParams()) + app.StakingKeeper.SetParams(ctx, stakingtypes.DefaultParams()) app.CrisisKeeper.RegisterRoute(testModuleName, dummyRouteWhichPasses.Route, dummyRouteWhichPasses.Invar) app.CrisisKeeper.RegisterRoute(testModuleName, dummyRouteWhichFails.Route, dummyRouteWhichFails.Invar) diff --git a/x/distribution/keeper/allocation_test.go b/x/distribution/keeper/allocation_test.go index 93df14c37cd8..726498c60c6d 100644 --- a/x/distribution/keeper/allocation_test.go +++ b/x/distribution/keeper/allocation_test.go @@ -11,6 +11,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/staking" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) func TestAllocateTokensToValidatorWithCommission(t *testing.T) { @@ -23,10 +24,10 @@ func TestAllocateTokensToValidatorWithCommission(t *testing.T) { sh := staking.NewHandler(app.StakingKeeper) // create validator with 50% commission - commission := staking.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0)) - msg := staking.NewMsgCreateValidator( + commission := stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0)) + msg := stakingtypes.NewMsgCreateValidator( sdk.ValAddress(addrs[0]), valConsPk1, - sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)), staking.Description{}, commission, sdk.OneInt(), + sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)), stakingtypes.Description{}, commission, sdk.OneInt(), ) res, err := sh(ctx, msg) @@ -60,18 +61,18 @@ func TestAllocateTokensToManyValidators(t *testing.T) { valAddrs := simapp.ConvertAddrsToValAddrs(addrs) // create validator with 50% commission - commission := staking.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0)) - msg := staking.NewMsgCreateValidator(valAddrs[0], valConsPk1, - sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)), staking.Description{}, commission, sdk.OneInt()) + commission := stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0)) + msg := stakingtypes.NewMsgCreateValidator(valAddrs[0], valConsPk1, + sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)), stakingtypes.Description{}, commission, sdk.OneInt()) res, err := sh(ctx, msg) require.NoError(t, err) require.NotNil(t, res) // create second validator with 0% commission - commission = staking.NewCommissionRates(sdk.NewDec(0), sdk.NewDec(0), sdk.NewDec(0)) - msg = staking.NewMsgCreateValidator(valAddrs[1], valConsPk2, - sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)), staking.Description{}, commission, sdk.OneInt()) + commission = stakingtypes.NewCommissionRates(sdk.NewDec(0), sdk.NewDec(0), sdk.NewDec(0)) + msg = stakingtypes.NewMsgCreateValidator(valAddrs[1], valConsPk2, + sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)), stakingtypes.Description{}, commission, sdk.OneInt()) res, err = sh(ctx, msg) require.NoError(t, err) @@ -140,25 +141,25 @@ func TestAllocateTokensTruncation(t *testing.T) { sh := staking.NewHandler(app.StakingKeeper) // create validator with 10% commission - commission := staking.NewCommissionRates(sdk.NewDecWithPrec(1, 1), sdk.NewDecWithPrec(1, 1), sdk.NewDec(0)) - msg := staking.NewMsgCreateValidator(valAddrs[0], valConsPk1, - sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(110)), staking.Description{}, commission, sdk.OneInt()) + commission := stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(1, 1), sdk.NewDecWithPrec(1, 1), sdk.NewDec(0)) + msg := stakingtypes.NewMsgCreateValidator(valAddrs[0], valConsPk1, + sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(110)), stakingtypes.Description{}, commission, sdk.OneInt()) res, err := sh(ctx, msg) require.NoError(t, err) require.NotNil(t, res) // create second validator with 10% commission - commission = staking.NewCommissionRates(sdk.NewDecWithPrec(1, 1), sdk.NewDecWithPrec(1, 1), sdk.NewDec(0)) - msg = staking.NewMsgCreateValidator(valAddrs[1], valConsPk2, - sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)), staking.Description{}, commission, sdk.OneInt()) + commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(1, 1), sdk.NewDecWithPrec(1, 1), sdk.NewDec(0)) + msg = stakingtypes.NewMsgCreateValidator(valAddrs[1], valConsPk2, + sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)), stakingtypes.Description{}, commission, sdk.OneInt()) res, err = sh(ctx, msg) require.NoError(t, err) require.NotNil(t, res) // create third validator with 10% commission - commission = staking.NewCommissionRates(sdk.NewDecWithPrec(1, 1), sdk.NewDecWithPrec(1, 1), sdk.NewDec(0)) - msg = staking.NewMsgCreateValidator(valAddrs[2], valConsPk3, - sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)), staking.Description{}, commission, sdk.OneInt()) + commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(1, 1), sdk.NewDecWithPrec(1, 1), sdk.NewDec(0)) + msg = stakingtypes.NewMsgCreateValidator(valAddrs[2], valConsPk3, + sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)), stakingtypes.Description{}, commission, sdk.OneInt()) res, err = sh(ctx, msg) require.NoError(t, err) require.NotNil(t, res) diff --git a/x/distribution/keeper/delegation_test.go b/x/distribution/keeper/delegation_test.go index 4ff953ea03f6..8b66b58bb914 100644 --- a/x/distribution/keeper/delegation_test.go +++ b/x/distribution/keeper/delegation_test.go @@ -10,6 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/staking" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) func TestCalculateRewardsBasic(t *testing.T) { @@ -22,9 +23,9 @@ func TestCalculateRewardsBasic(t *testing.T) { valAddrs := simapp.ConvertAddrsToValAddrs(addr) // create validator with 50% commission - commission := staking.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0)) - msg := staking.NewMsgCreateValidator( - valAddrs[0], valConsPk1, sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)), staking.Description{}, commission, sdk.OneInt(), + commission := stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0)) + msg := stakingtypes.NewMsgCreateValidator( + valAddrs[0], valConsPk1, sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)), stakingtypes.Description{}, commission, sdk.OneInt(), ) res, err := sh(ctx, msg) @@ -84,11 +85,11 @@ func TestCalculateRewardsAfterSlash(t *testing.T) { sh := staking.NewHandler(app.StakingKeeper) // create validator with 50% commission - commission := staking.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0)) + commission := stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0)) valPower := int64(100) valTokens := sdk.TokensFromConsensusPower(valPower) - msg := staking.NewMsgCreateValidator(valAddrs[0], valConsPk1, - sdk.NewCoin(sdk.DefaultBondDenom, valTokens), staking.Description{}, commission, sdk.OneInt()) + msg := stakingtypes.NewMsgCreateValidator(valAddrs[0], valConsPk1, + sdk.NewCoin(sdk.DefaultBondDenom, valTokens), stakingtypes.Description{}, commission, sdk.OneInt()) res, err := sh(ctx, msg) require.NoError(t, err) @@ -155,9 +156,9 @@ func TestCalculateRewardsAfterManySlashes(t *testing.T) { // create validator with 50% commission power := int64(100) valTokens := sdk.TokensFromConsensusPower(power) - commission := staking.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0)) - msg := staking.NewMsgCreateValidator(valAddrs[0], valConsPk1, - sdk.NewCoin(sdk.DefaultBondDenom, valTokens), staking.Description{}, commission, sdk.OneInt()) + commission := stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0)) + msg := stakingtypes.NewMsgCreateValidator(valAddrs[0], valConsPk1, + sdk.NewCoin(sdk.DefaultBondDenom, valTokens), stakingtypes.Description{}, commission, sdk.OneInt()) res, err := sh(ctx, msg) require.NoError(t, err) @@ -235,9 +236,9 @@ func TestCalculateRewardsMultiDelegator(t *testing.T) { valAddrs := simapp.ConvertAddrsToValAddrs(addr) // create validator with 50% commission - commission := staking.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0)) - msg := staking.NewMsgCreateValidator(valAddrs[0], valConsPk1, - sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)), staking.Description{}, commission, sdk.OneInt()) + commission := stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0)) + msg := stakingtypes.NewMsgCreateValidator(valAddrs[0], valConsPk1, + sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)), stakingtypes.Description{}, commission, sdk.OneInt()) res, err := sh(ctx, msg) require.NoError(t, err) @@ -259,7 +260,7 @@ func TestCalculateRewardsMultiDelegator(t *testing.T) { app.DistrKeeper.AllocateTokensToValidator(ctx, val, tokens) // second delegation - msg2 := staking.NewMsgDelegate(sdk.AccAddress(valAddrs[1]), valAddrs[0], sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))) + msg2 := stakingtypes.NewMsgDelegate(sdk.AccAddress(valAddrs[1]), valAddrs[0], sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))) res, err = sh(ctx, msg2) require.NoError(t, err) @@ -317,11 +318,11 @@ func TestWithdrawDelegationRewardsBasic(t *testing.T) { // create validator with 50% commission power := int64(100) valTokens := sdk.TokensFromConsensusPower(power) - commission := staking.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0)) - msg := staking.NewMsgCreateValidator( + commission := stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0)) + msg := stakingtypes.NewMsgCreateValidator( valAddrs[0], valConsPk1, sdk.NewCoin(sdk.DefaultBondDenom, valTokens), - staking.Description{}, commission, sdk.OneInt(), + stakingtypes.Description{}, commission, sdk.OneInt(), ) res, err := sh(ctx, msg) @@ -391,9 +392,9 @@ func TestCalculateRewardsAfterManySlashesInSameBlock(t *testing.T) { // create validator with 50% commission power := int64(100) valTokens := sdk.TokensFromConsensusPower(power) - commission := staking.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0)) - msg := staking.NewMsgCreateValidator(valAddrs[0], valConsPk1, - sdk.NewCoin(sdk.DefaultBondDenom, valTokens), staking.Description{}, commission, sdk.OneInt()) + commission := stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0)) + msg := stakingtypes.NewMsgCreateValidator(valAddrs[0], valConsPk1, + sdk.NewCoin(sdk.DefaultBondDenom, valTokens), stakingtypes.Description{}, commission, sdk.OneInt()) res, err := sh(ctx, msg) require.NoError(t, err) @@ -463,11 +464,11 @@ func TestCalculateRewardsMultiDelegatorMultiSlash(t *testing.T) { valAddrs := simapp.ConvertAddrsToValAddrs(addr) // create validator with 50% commission - commission := staking.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0)) + commission := stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0)) power := int64(100) valTokens := sdk.TokensFromConsensusPower(power) - msg := staking.NewMsgCreateValidator(valAddrs[0], valConsPk1, - sdk.NewCoin(sdk.DefaultBondDenom, valTokens), staking.Description{}, commission, sdk.OneInt()) + msg := stakingtypes.NewMsgCreateValidator(valAddrs[0], valConsPk1, + sdk.NewCoin(sdk.DefaultBondDenom, valTokens), stakingtypes.Description{}, commission, sdk.OneInt()) res, err := sh(ctx, msg) require.NoError(t, err) @@ -495,7 +496,7 @@ func TestCalculateRewardsMultiDelegatorMultiSlash(t *testing.T) { // second delegation delTokens := sdk.TokensFromConsensusPower(100) - msg2 := staking.NewMsgDelegate(sdk.AccAddress(valAddrs[1]), valAddrs[0], + msg2 := stakingtypes.NewMsgDelegate(sdk.AccAddress(valAddrs[1]), valAddrs[0], sdk.NewCoin(sdk.DefaultBondDenom, delTokens)) res, err = sh(ctx, msg2) @@ -560,9 +561,9 @@ func TestCalculateRewardsMultiDelegatorMultWithdraw(t *testing.T) { tokens := sdk.DecCoins{sdk.NewDecCoinFromDec(sdk.DefaultBondDenom, sdk.NewDec(initial))} // create validator with 50% commission - commission := staking.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0)) - msg := staking.NewMsgCreateValidator(valAddrs[0], valConsPk1, - sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)), staking.Description{}, commission, sdk.OneInt()) + commission := stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0)) + msg := stakingtypes.NewMsgCreateValidator(valAddrs[0], valConsPk1, + sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)), stakingtypes.Description{}, commission, sdk.OneInt()) res, err := sh(ctx, msg) require.NoError(t, err) @@ -585,7 +586,7 @@ func TestCalculateRewardsMultiDelegatorMultWithdraw(t *testing.T) { require.Equal(t, uint64(2), app.DistrKeeper.GetValidatorHistoricalReferenceCount(ctx)) // second delegation - msg2 := staking.NewMsgDelegate(sdk.AccAddress(valAddrs[1]), valAddrs[0], sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))) + msg2 := stakingtypes.NewMsgDelegate(sdk.AccAddress(valAddrs[1]), valAddrs[0], sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))) res, err = sh(ctx, msg2) require.NoError(t, err) require.NotNil(t, res) diff --git a/x/distribution/keeper/querier_test.go b/x/distribution/keeper/querier_test.go index 0bf292f11858..1b6f42973c80 100644 --- a/x/distribution/keeper/querier_test.go +++ b/x/distribution/keeper/querier_test.go @@ -14,6 +14,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/distribution/keeper" "github.com/cosmos/cosmos-sdk/x/distribution/types" "github.com/cosmos/cosmos-sdk/x/staking" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) const custom = "custom" @@ -168,9 +169,9 @@ func TestQueries(t *testing.T) { // test delegation rewards query sh := staking.NewHandler(app.StakingKeeper) - comm := staking.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0)) - msg := staking.NewMsgCreateValidator( - valOpAddr1, valConsPk1, sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)), staking.Description{}, comm, sdk.OneInt(), + comm := stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0)) + msg := stakingtypes.NewMsgCreateValidator( + valOpAddr1, valConsPk1, sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)), stakingtypes.Description{}, comm, sdk.OneInt(), ) res, err := sh(ctx, msg) diff --git a/x/distribution/types/expected_keepers.go b/x/distribution/types/expected_keepers.go index 7a6d134d0f86..c83464dea7ff 100644 --- a/x/distribution/types/expected_keepers.go +++ b/x/distribution/types/expected_keepers.go @@ -3,8 +3,8 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/cosmos/cosmos-sdk/x/staking" stakingexported "github.com/cosmos/cosmos-sdk/x/staking/exported" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) // AccountKeeper defines the expected account keeper used for simulations (noalias) @@ -66,7 +66,7 @@ type StakingKeeper interface { GetLastTotalPower(ctx sdk.Context) sdk.Int GetLastValidatorPower(ctx sdk.Context, valAddr sdk.ValAddress) int64 - GetAllSDKDelegations(ctx sdk.Context) []staking.Delegation + GetAllSDKDelegations(ctx sdk.Context) []stakingtypes.Delegation } // StakingHooks event hooks for staking validator object (noalias) diff --git a/x/evidence/keeper/infraction_test.go b/x/evidence/keeper/infraction_test.go index 6c2506f1d295..c510ea9025b2 100644 --- a/x/evidence/keeper/infraction_test.go +++ b/x/evidence/keeper/infraction_test.go @@ -6,15 +6,16 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/evidence/types" "github.com/cosmos/cosmos-sdk/x/staking" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/tendermint/tendermint/crypto" ) -func newTestMsgCreateValidator(address sdk.ValAddress, pubKey crypto.PubKey, amt sdk.Int) *staking.MsgCreateValidator { - commission := staking.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()) - return staking.NewMsgCreateValidator( +func newTestMsgCreateValidator(address sdk.ValAddress, pubKey crypto.PubKey, amt sdk.Int) *stakingtypes.MsgCreateValidator { + commission := stakingtypes.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()) + return stakingtypes.NewMsgCreateValidator( address, pubKey, sdk.NewCoin(sdk.DefaultBondDenom, amt), - staking.Description{}, commission, sdk.OneInt(), + stakingtypes.Description{}, commission, sdk.OneInt(), ) } @@ -78,7 +79,7 @@ func (suite *KeeperTestSuite) TestHandleDoubleSign() { del, _ := suite.app.StakingKeeper.GetDelegation(ctx, sdk.AccAddress(operatorAddr), operatorAddr) validator, _ := suite.app.StakingKeeper.GetValidator(ctx, operatorAddr) totalBond := validator.TokensFromShares(del.GetShares()).TruncateInt() - msgUnbond := staking.NewMsgUndelegate(sdk.AccAddress(operatorAddr), operatorAddr, sdk.NewCoin(stakingParams.BondDenom, totalBond)) + msgUnbond := stakingtypes.NewMsgUndelegate(sdk.AccAddress(operatorAddr), operatorAddr, sdk.NewCoin(stakingParams.BondDenom, totalBond)) res, err = staking.NewHandler(suite.app.StakingKeeper)(ctx, msgUnbond) suite.NoError(err) suite.NotNil(res) diff --git a/x/gov/common_test.go b/x/gov/common_test.go index acb8e8cec4cb..81bfd32fd85b 100644 --- a/x/gov/common_test.go +++ b/x/gov/common_test.go @@ -12,14 +12,14 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/gov/types" - "github.com/cosmos/cosmos-sdk/x/staking" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) var ( valTokens = sdk.TokensFromConsensusPower(42) TestProposal = types.NewTextProposal("Test", "description") - TestDescription = staking.NewDescription("T", "E", "S", "T", "Z") - TestCommissionRates = staking.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()) + TestDescription = stakingtypes.NewDescription("T", "E", "S", "T", "Z") + TestCommissionRates = stakingtypes.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()) ) // SortAddresses - Sorts Addresses @@ -84,7 +84,7 @@ func createValidators(t *testing.T, stakingHandler sdk.Handler, ctx sdk.Context, for i := 0; i < len(addrs); i++ { valTokens := sdk.TokensFromConsensusPower(powerAmt[i]) - valCreateMsg := staking.NewMsgCreateValidator( + valCreateMsg := stakingtypes.NewMsgCreateValidator( addrs[i], pubkeys[i], sdk.NewCoin(sdk.DefaultBondDenom, valTokens), TestDescription, TestCommissionRates, sdk.OneInt(), ) diff --git a/x/gov/keeper/common_test.go b/x/gov/keeper/common_test.go index 2cac40eb6223..461e4fe0be67 100644 --- a/x/gov/keeper/common_test.go +++ b/x/gov/keeper/common_test.go @@ -5,6 +5,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/cosmos/cosmos-sdk/x/staking" + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) var ( @@ -17,17 +19,17 @@ func createValidators(ctx sdk.Context, app *simapp.SimApp, powers []int64) ([]sd pks := simapp.CreateTestPubKeys(5) appCodec, _ := simapp.MakeCodecs() - app.StakingKeeper = staking.NewKeeper( + app.StakingKeeper = stakingkeeper.NewKeeper( appCodec, - app.GetKey(staking.StoreKey), + app.GetKey(stakingtypes.StoreKey), app.AccountKeeper, app.BankKeeper, - app.GetSubspace(staking.ModuleName), + app.GetSubspace(stakingtypes.ModuleName), ) - val1 := staking.NewValidator(valAddrs[0], pks[0], staking.Description{}) - val2 := staking.NewValidator(valAddrs[1], pks[1], staking.Description{}) - val3 := staking.NewValidator(valAddrs[2], pks[2], staking.Description{}) + val1 := stakingtypes.NewValidator(valAddrs[0], pks[0], stakingtypes.Description{}) + val2 := stakingtypes.NewValidator(valAddrs[1], pks[1], stakingtypes.Description{}) + val3 := stakingtypes.NewValidator(valAddrs[2], pks[2], stakingtypes.Description{}) app.StakingKeeper.SetValidator(ctx, val1) app.StakingKeeper.SetValidator(ctx, val2) diff --git a/x/ibc-transfer/handler_test.go b/x/ibc-transfer/handler_test.go index 7eafc98977ab..767735594c4e 100644 --- a/x/ibc-transfer/handler_test.go +++ b/x/ibc-transfer/handler_test.go @@ -23,7 +23,7 @@ import ( commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" - "github.com/cosmos/cosmos-sdk/x/staking" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) // define constants used for testing @@ -172,13 +172,13 @@ func (chain *TestChain) CreateClient(client *TestChain) error { // Set HistoricalInfo on client chain after Commit ctxClient := client.GetContext() - validator := staking.NewValidator( - sdk.ValAddress(client.Vals.Validators[0].Address), client.Vals.Validators[0].PubKey, staking.Description{}, + validator := stakingtypes.NewValidator( + sdk.ValAddress(client.Vals.Validators[0].Address), client.Vals.Validators[0].PubKey, stakingtypes.Description{}, ) validator.Status = sdk.Bonded validator.Tokens = sdk.NewInt(1000000) // get one voting power - validators := []staking.Validator{validator} - histInfo := staking.HistoricalInfo{ + validators := []stakingtypes.Validator{validator} + histInfo := stakingtypes.HistoricalInfo{ Header: abci.Header{ AppHash: commitID.Hash, }, @@ -234,13 +234,13 @@ func (chain *TestChain) updateClient(client *TestChain) { // Set HistoricalInfo on client chain after Commit ctxClient := client.GetContext() - validator := staking.NewValidator( - sdk.ValAddress(client.Vals.Validators[0].Address), client.Vals.Validators[0].PubKey, staking.Description{}, + validator := stakingtypes.NewValidator( + sdk.ValAddress(client.Vals.Validators[0].Address), client.Vals.Validators[0].PubKey, stakingtypes.Description{}, ) validator.Status = sdk.Bonded validator.Tokens = sdk.NewInt(1000000) - validators := []staking.Validator{validator} - histInfo := staking.HistoricalInfo{ + validators := []stakingtypes.Validator{validator} + histInfo := stakingtypes.HistoricalInfo{ Header: abci.Header{ AppHash: commitID.Hash, }, diff --git a/x/ibc-transfer/keeper/keeper_test.go b/x/ibc-transfer/keeper/keeper_test.go index 558e5a93a06d..dd9f44e4ae84 100644 --- a/x/ibc-transfer/keeper/keeper_test.go +++ b/x/ibc-transfer/keeper/keeper_test.go @@ -21,7 +21,7 @@ import ( commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" - "github.com/cosmos/cosmos-sdk/x/staking" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) // define constants used for testing @@ -147,13 +147,13 @@ func (chain *TestChain) CreateClient(client *TestChain) error { // Set HistoricalInfo on client chain after Commit ctxClient := client.GetContext() - validator := staking.NewValidator( - sdk.ValAddress(client.Vals.Validators[0].Address), client.Vals.Validators[0].PubKey, staking.Description{}, + validator := stakingtypes.NewValidator( + sdk.ValAddress(client.Vals.Validators[0].Address), client.Vals.Validators[0].PubKey, stakingtypes.Description{}, ) validator.Status = sdk.Bonded validator.Tokens = sdk.NewInt(1000000) // get one voting power - validators := []staking.Validator{validator} - histInfo := staking.HistoricalInfo{ + validators := []stakingtypes.Validator{validator} + histInfo := stakingtypes.HistoricalInfo{ Header: abci.Header{ AppHash: commitID.Hash, }, @@ -209,13 +209,13 @@ func (chain *TestChain) updateClient(client *TestChain) { // Set HistoricalInfo on client chain after Commit ctxClient := client.GetContext() - validator := staking.NewValidator( - sdk.ValAddress(client.Vals.Validators[0].Address), client.Vals.Validators[0].PubKey, staking.Description{}, + validator := stakingtypes.NewValidator( + sdk.ValAddress(client.Vals.Validators[0].Address), client.Vals.Validators[0].PubKey, stakingtypes.Description{}, ) validator.Status = sdk.Bonded validator.Tokens = sdk.NewInt(1000000) - validators := []staking.Validator{validator} - histInfo := staking.HistoricalInfo{ + validators := []stakingtypes.Validator{validator} + histInfo := stakingtypes.HistoricalInfo{ Header: abci.Header{ AppHash: commitID.Hash, }, diff --git a/x/ibc/02-client/keeper/keeper_test.go b/x/ibc/02-client/keeper/keeper_test.go index 1c4562849869..2153a255d58f 100644 --- a/x/ibc/02-client/keeper/keeper_test.go +++ b/x/ibc/02-client/keeper/keeper_test.go @@ -19,7 +19,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types" ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" - "github.com/cosmos/cosmos-sdk/x/staking" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) const ( @@ -71,17 +71,17 @@ func (suite *KeeperTestSuite) SetupTest() { ValidatorSet: suite.valSet, } - var validators staking.Validators + var validators stakingtypes.Validators for i := 1; i < 11; i++ { privVal := tmtypes.NewMockPV() pk, err := privVal.GetPubKey() suite.Require().NoError(err) - val := staking.NewValidator(sdk.ValAddress(pk.Address()), pk, staking.Description{}) + val := stakingtypes.NewValidator(sdk.ValAddress(pk.Address()), pk, stakingtypes.Description{}) val.Status = sdk.Bonded val.Tokens = sdk.NewInt(rand.Int63()) validators = append(validators, val) - app.StakingKeeper.SetHistoricalInfo(suite.ctx, int64(i), staking.NewHistoricalInfo(suite.ctx.BlockHeader(), validators)) + app.StakingKeeper.SetHistoricalInfo(suite.ctx, int64(i), stakingtypes.NewHistoricalInfo(suite.ctx.BlockHeader(), validators)) } } diff --git a/x/ibc/03-connection/keeper/keeper_test.go b/x/ibc/03-connection/keeper/keeper_test.go index 1ca414e8c568..63adc41b57d3 100644 --- a/x/ibc/03-connection/keeper/keeper_test.go +++ b/x/ibc/03-connection/keeper/keeper_test.go @@ -21,7 +21,7 @@ import ( commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" - "github.com/cosmos/cosmos-sdk/x/staking" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) const ( @@ -240,13 +240,13 @@ func (chain *TestChain) CreateClient(client *TestChain) error { // Set HistoricalInfo on client chain after Commit ctxClient := client.GetContext() - validator := staking.NewValidator( - sdk.ValAddress(client.Vals.Validators[0].Address), client.Vals.Validators[0].PubKey, staking.Description{}, + validator := stakingtypes.NewValidator( + sdk.ValAddress(client.Vals.Validators[0].Address), client.Vals.Validators[0].PubKey, stakingtypes.Description{}, ) validator.Status = sdk.Bonded validator.Tokens = sdk.NewInt(1000000) // get one voting power - validators := []staking.Validator{validator} - histInfo := staking.HistoricalInfo{ + validators := []stakingtypes.Validator{validator} + histInfo := stakingtypes.HistoricalInfo{ Header: abci.Header{ Time: client.Header.Time, AppHash: commitID.Hash, @@ -256,7 +256,7 @@ func (chain *TestChain) CreateClient(client *TestChain) error { client.App.StakingKeeper.SetHistoricalInfo(ctxClient, client.Header.SignedHeader.Header.Height, histInfo) // also set staking params - stakingParams := staking.DefaultParams() + stakingParams := stakingtypes.DefaultParams() stakingParams.HistoricalEntries = 10 client.App.StakingKeeper.SetParams(ctxClient, stakingParams) @@ -314,13 +314,13 @@ func (chain *TestChain) updateClient(client *TestChain) { // Set HistoricalInfo on client chain after Commit ctxClient := client.GetContext() - validator := staking.NewValidator( - sdk.ValAddress(client.Vals.Validators[0].Address), client.Vals.Validators[0].PubKey, staking.Description{}, + validator := stakingtypes.NewValidator( + sdk.ValAddress(client.Vals.Validators[0].Address), client.Vals.Validators[0].PubKey, stakingtypes.Description{}, ) validator.Status = sdk.Bonded validator.Tokens = sdk.NewInt(1000000) - validators := []staking.Validator{validator} - histInfo := staking.HistoricalInfo{ + validators := []stakingtypes.Validator{validator} + histInfo := stakingtypes.HistoricalInfo{ Header: abci.Header{ Time: client.Header.Time, AppHash: commitID.Hash, diff --git a/x/ibc/04-channel/keeper/keeper_test.go b/x/ibc/04-channel/keeper/keeper_test.go index e2c7a81059f6..52cff3065ec9 100644 --- a/x/ibc/04-channel/keeper/keeper_test.go +++ b/x/ibc/04-channel/keeper/keeper_test.go @@ -20,7 +20,7 @@ import ( host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ibckeeper "github.com/cosmos/cosmos-sdk/x/ibc/keeper" - "github.com/cosmos/cosmos-sdk/x/staking" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) // define constants used for testing @@ -363,13 +363,13 @@ func (chain *TestChain) CreateClient(client *TestChain) error { // Set HistoricalInfo on client chain after Commit ctxClient := client.GetContext() - validator := staking.NewValidator( - sdk.ValAddress(client.Vals.Validators[0].Address), client.Vals.Validators[0].PubKey, staking.Description{}, + validator := stakingtypes.NewValidator( + sdk.ValAddress(client.Vals.Validators[0].Address), client.Vals.Validators[0].PubKey, stakingtypes.Description{}, ) validator.Status = sdk.Bonded validator.Tokens = sdk.NewInt(1000000) // get one voting power - validators := []staking.Validator{validator} - histInfo := staking.HistoricalInfo{ + validators := []stakingtypes.Validator{validator} + histInfo := stakingtypes.HistoricalInfo{ Header: abci.Header{ AppHash: commitID.Hash, }, @@ -424,13 +424,13 @@ func (chain *TestChain) updateClient(client *TestChain) { // Set HistoricalInfo on client chain after Commit ctxClient := client.GetContext() - validator := staking.NewValidator( - sdk.ValAddress(client.Vals.Validators[0].Address), client.Vals.Validators[0].PubKey, staking.Description{}, + validator := stakingtypes.NewValidator( + sdk.ValAddress(client.Vals.Validators[0].Address), client.Vals.Validators[0].PubKey, stakingtypes.Description{}, ) validator.Status = sdk.Bonded validator.Tokens = sdk.NewInt(1000000) - validators := []staking.Validator{validator} - histInfo := staking.HistoricalInfo{ + validators := []stakingtypes.Validator{validator} + histInfo := stakingtypes.HistoricalInfo{ Header: abci.Header{ AppHash: commitID.Hash, }, diff --git a/x/ibc/ante/ante_test.go b/x/ibc/ante/ante_test.go index 46b1021cad5d..f7991035e013 100644 --- a/x/ibc/ante/ante_test.go +++ b/x/ibc/ante/ante_test.go @@ -20,7 +20,7 @@ import ( ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" - "github.com/cosmos/cosmos-sdk/x/staking" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" "github.com/cosmos/cosmos-sdk/x/ibc/ante" @@ -225,13 +225,13 @@ func (chain *TestChain) CreateClient(client *TestChain) error { // Set HistoricalInfo on client chain after Commit ctxClient := client.GetContext() - validator := staking.NewValidator( - sdk.ValAddress(client.Vals.Validators[0].Address), client.Vals.Validators[0].PubKey, staking.Description{}, + validator := stakingtypes.NewValidator( + sdk.ValAddress(client.Vals.Validators[0].Address), client.Vals.Validators[0].PubKey, stakingtypes.Description{}, ) validator.Status = sdk.Bonded validator.Tokens = sdk.NewInt(1000000) // get one voting power - validators := []staking.Validator{validator} - histInfo := staking.HistoricalInfo{ + validators := []stakingtypes.Validator{validator} + histInfo := stakingtypes.HistoricalInfo{ Header: abci.Header{ AppHash: commitID.Hash, }, @@ -286,13 +286,13 @@ func (chain *TestChain) updateClient(client *TestChain) { // Set HistoricalInfo on client chain after Commit ctxClient := client.GetContext() - validator := staking.NewValidator( - sdk.ValAddress(client.Vals.Validators[0].Address), client.Vals.Validators[0].PubKey, staking.Description{}, + validator := stakingtypes.NewValidator( + sdk.ValAddress(client.Vals.Validators[0].Address), client.Vals.Validators[0].PubKey, stakingtypes.Description{}, ) validator.Status = sdk.Bonded validator.Tokens = sdk.NewInt(1000000) - validators := []staking.Validator{validator} - histInfo := staking.HistoricalInfo{ + validators := []stakingtypes.Validator{validator} + histInfo := stakingtypes.HistoricalInfo{ Header: abci.Header{ AppHash: commitID.Hash, }, diff --git a/x/slashing/app_test.go b/x/slashing/app_test.go index cc1f3ba171a4..400c5b712eef 100644 --- a/x/slashing/app_test.go +++ b/x/slashing/app_test.go @@ -14,7 +14,7 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/slashing/types" - "github.com/cosmos/cosmos-sdk/x/staking" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) var ( @@ -22,7 +22,7 @@ var ( addr1 = sdk.AccAddress(priv1.PubKey().Address()) ) -func checkValidator(t *testing.T, app *simapp.SimApp, _ sdk.AccAddress, expFound bool) staking.Validator { +func checkValidator(t *testing.T, app *simapp.SimApp, _ sdk.AccAddress, expFound bool) stakingtypes.Validator { ctxCheck := app.BaseApp.NewContext(true, abci.Header{}) validator, found := app.StakingKeeper.GetValidator(ctxCheck, sdk.ValAddress(addr1)) require.Equal(t, expFound, found) @@ -56,10 +56,10 @@ func TestSlashingMsgs(t *testing.T) { app := simapp.SetupWithGenesisAccounts(accs, balances...) simapp.CheckBalance(t, app, addr1, sdk.Coins{genCoin}) - description := staking.NewDescription("foo_moniker", "", "", "", "") - commission := staking.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()) + description := stakingtypes.NewDescription("foo_moniker", "", "", "", "") + commission := stakingtypes.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()) - createValidatorMsg := staking.NewMsgCreateValidator( + createValidatorMsg := stakingtypes.NewMsgCreateValidator( sdk.ValAddress(addr1), priv1.PubKey(), bondCoin, description, commission, sdk.OneInt(), ) diff --git a/x/slashing/handler_test.go b/x/slashing/handler_test.go index 2d03ff62faf9..23d6ba609369 100644 --- a/x/slashing/handler_test.go +++ b/x/slashing/handler_test.go @@ -15,6 +15,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/slashing/keeper" "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) func TestCannotUnjailUnlessJailed(t *testing.T) { @@ -74,7 +75,7 @@ func TestCannotUnjailUnlessMeetMinSelfDelegation(t *testing.T) { ) unbondAmt := sdk.NewCoin(app.StakingKeeper.GetParams(ctx).BondDenom, sdk.OneInt()) - undelegateMsg := staking.NewMsgUndelegate(sdk.AccAddress(addr), addr, unbondAmt) + undelegateMsg := stakingtypes.NewMsgUndelegate(sdk.AccAddress(addr), addr, unbondAmt) res, err = staking.NewHandler(app.StakingKeeper)(ctx, undelegateMsg) require.NoError(t, err) require.NotNil(t, res) @@ -127,7 +128,7 @@ func TestJailedValidatorDelegations(t *testing.T) { unbondAmt := sdk.NewCoin(app.StakingKeeper.GetParams(ctx).BondDenom, bondAmount) // unbond validator total self-delegations (which should jail the validator) - msgUndelegate := staking.NewMsgUndelegate(sdk.AccAddress(valAddr), valAddr, unbondAmt) + msgUndelegate := stakingtypes.NewMsgUndelegate(sdk.AccAddress(valAddr), valAddr, unbondAmt) res, err = staking.NewHandler(app.StakingKeeper)(ctx, msgUndelegate) require.NoError(t, err) require.NotNil(t, res) diff --git a/x/slashing/keeper/keeper_test.go b/x/slashing/keeper/keeper_test.go index cd09211fa8f0..1a305728e5f8 100644 --- a/x/slashing/keeper/keeper_test.go +++ b/x/slashing/keeper/keeper_test.go @@ -11,6 +11,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/slashing/keeper" "github.com/cosmos/cosmos-sdk/x/staking" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) func TestUnJailNotBonded(t *testing.T) { @@ -56,7 +57,7 @@ func TestUnJailNotBonded(t *testing.T) { require.Equal(t, sdk.BondStatusUnbonded, validator.GetStatus().String()) // unbond below minimum self-delegation - msgUnbond := staking.NewMsgUndelegate(sdk.AccAddress(addr), addr, sdk.NewCoin(p.BondDenom, sdk.TokensFromConsensusPower(1))) + msgUnbond := stakingtypes.NewMsgUndelegate(sdk.AccAddress(addr), addr, sdk.NewCoin(p.BondDenom, sdk.TokensFromConsensusPower(1))) res, err = sh(ctx, msgUnbond) require.NoError(t, err) require.NotNil(t, res) @@ -76,7 +77,7 @@ func TestUnJailNotBonded(t *testing.T) { ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) // bond to meet minimum self-delegation - msgBond := staking.NewMsgDelegate(sdk.AccAddress(addr), addr, sdk.NewCoin(p.BondDenom, sdk.TokensFromConsensusPower(1))) + msgBond := stakingtypes.NewMsgDelegate(sdk.AccAddress(addr), addr, sdk.NewCoin(p.BondDenom, sdk.TokensFromConsensusPower(1))) res, err = sh(ctx, msgBond) require.NoError(t, err) require.NotNil(t, res) diff --git a/x/slashing/keeper/test_common.go b/x/slashing/keeper/test_common.go index fd8cbdb4dd7b..f9edb4febec7 100644 --- a/x/slashing/keeper/test_common.go +++ b/x/slashing/keeper/test_common.go @@ -7,7 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/slashing/types" - "github.com/cosmos/cosmos-sdk/x/staking" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) // TODO remove dependencies on staking (should only refer to validator set type from sdk) @@ -26,16 +26,16 @@ func TestParams() types.Params { return params } -func NewTestMsgCreateValidator(address sdk.ValAddress, pubKey crypto.PubKey, amt sdk.Int) *staking.MsgCreateValidator { - commission := staking.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()) +func NewTestMsgCreateValidator(address sdk.ValAddress, pubKey crypto.PubKey, amt sdk.Int) *stakingtypes.MsgCreateValidator { + commission := stakingtypes.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()) - return staking.NewMsgCreateValidator( + return stakingtypes.NewMsgCreateValidator( address, pubKey, sdk.NewCoin(sdk.DefaultBondDenom, amt), - staking.Description{}, commission, sdk.OneInt(), + stakingtypes.Description{}, commission, sdk.OneInt(), ) } -func NewTestMsgDelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, delAmount sdk.Int) *staking.MsgDelegate { +func NewTestMsgDelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, delAmount sdk.Int) *stakingtypes.MsgDelegate { amount := sdk.NewCoin(sdk.DefaultBondDenom, delAmount) - return staking.NewMsgDelegate(delAddr, valAddr, amount) + return stakingtypes.NewMsgDelegate(delAddr, valAddr, amount) } diff --git a/x/staking/alias.go b/x/staking/alias.go deleted file mode 100644 index 416922b72f98..000000000000 --- a/x/staking/alias.go +++ /dev/null @@ -1,239 +0,0 @@ -package staking - -import ( - "github.com/cosmos/cosmos-sdk/x/staking/exported" - "github.com/cosmos/cosmos-sdk/x/staking/keeper" - "github.com/cosmos/cosmos-sdk/x/staking/types" -) - -const ( - DefaultParamspace = keeper.DefaultParamspace - ModuleName = types.ModuleName - StoreKey = types.StoreKey - QuerierRoute = types.QuerierRoute - RouterKey = types.RouterKey - DefaultUnbondingTime = types.DefaultUnbondingTime - DefaultMaxValidators = types.DefaultMaxValidators - DefaultMaxEntries = types.DefaultMaxEntries - NotBondedPoolName = types.NotBondedPoolName - BondedPoolName = types.BondedPoolName - QueryValidators = types.QueryValidators - QueryValidator = types.QueryValidator - QueryDelegatorDelegations = types.QueryDelegatorDelegations - QueryDelegatorUnbondingDelegations = types.QueryDelegatorUnbondingDelegations - QueryRedelegations = types.QueryRedelegations - QueryValidatorDelegations = types.QueryValidatorDelegations - QueryValidatorRedelegations = types.QueryValidatorRedelegations - QueryValidatorUnbondingDelegations = types.QueryValidatorUnbondingDelegations - QueryDelegation = types.QueryDelegation - QueryUnbondingDelegation = types.QueryUnbondingDelegation - QueryDelegatorValidators = types.QueryDelegatorValidators - QueryDelegatorValidator = types.QueryDelegatorValidator - QueryPool = types.QueryPool - QueryParameters = types.QueryParameters - QueryHistoricalInfo = types.QueryHistoricalInfo - MaxMonikerLength = types.MaxMonikerLength - MaxIdentityLength = types.MaxIdentityLength - MaxWebsiteLength = types.MaxWebsiteLength - MaxDetailsLength = types.MaxDetailsLength - DoNotModifyDesc = types.DoNotModifyDesc -) - -var ( - // functions aliases - RegisterInvariants = keeper.RegisterInvariants - AllInvariants = keeper.AllInvariants - ModuleAccountInvariants = keeper.ModuleAccountInvariants - NonNegativePowerInvariant = keeper.NonNegativePowerInvariant - PositiveDelegationInvariant = keeper.PositiveDelegationInvariant - DelegatorSharesInvariant = keeper.DelegatorSharesInvariant - NewKeeper = keeper.NewKeeper - ParamKeyTable = keeper.ParamKeyTable - NewQuerier = keeper.NewQuerier - RegisterCodec = types.RegisterCodec - NewCommissionRates = types.NewCommissionRates - NewCommission = types.NewCommission - NewCommissionWithTime = types.NewCommissionWithTime - NewDelegation = types.NewDelegation - MustMarshalDelegation = types.MustMarshalDelegation - MustUnmarshalDelegation = types.MustUnmarshalDelegation - UnmarshalDelegation = types.UnmarshalDelegation - NewUnbondingDelegation = types.NewUnbondingDelegation - NewUnbondingDelegationEntry = types.NewUnbondingDelegationEntry - MustMarshalUBD = types.MustMarshalUBD - MustUnmarshalUBD = types.MustUnmarshalUBD - UnmarshalUBD = types.UnmarshalUBD - NewRedelegation = types.NewRedelegation - NewRedelegationEntry = types.NewRedelegationEntry - MustMarshalRED = types.MustMarshalRED - MustUnmarshalRED = types.MustUnmarshalRED - UnmarshalRED = types.UnmarshalRED - NewDelegationResp = types.NewDelegationResp - NewRedelegationResponse = types.NewRedelegationResponse - NewRedelegationEntryResponse = types.NewRedelegationEntryResponse - NewHistoricalInfo = types.NewHistoricalInfo - MustMarshalHistoricalInfo = types.MustMarshalHistoricalInfo - MustUnmarshalHistoricalInfo = types.MustUnmarshalHistoricalInfo - UnmarshalHistoricalInfo = types.UnmarshalHistoricalInfo - ErrEmptyValidatorAddr = types.ErrEmptyValidatorAddr - ErrBadValidatorAddr = types.ErrBadValidatorAddr - ErrNoValidatorFound = types.ErrNoValidatorFound - ErrValidatorOwnerExists = types.ErrValidatorOwnerExists - ErrValidatorPubKeyExists = types.ErrValidatorPubKeyExists - ErrValidatorPubKeyTypeNotSupported = types.ErrValidatorPubKeyTypeNotSupported - ErrValidatorJailed = types.ErrValidatorJailed - ErrBadRemoveValidator = types.ErrBadRemoveValidator - ErrCommissionNegative = types.ErrCommissionNegative - ErrCommissionHuge = types.ErrCommissionHuge - ErrCommissionGTMaxRate = types.ErrCommissionGTMaxRate - ErrCommissionUpdateTime = types.ErrCommissionUpdateTime - ErrCommissionChangeRateNegative = types.ErrCommissionChangeRateNegative - ErrCommissionChangeRateGTMaxRate = types.ErrCommissionChangeRateGTMaxRate - ErrCommissionGTMaxChangeRate = types.ErrCommissionGTMaxChangeRate - ErrSelfDelegationBelowMinimum = types.ErrSelfDelegationBelowMinimum - ErrMinSelfDelegationInvalid = types.ErrMinSelfDelegationInvalid - ErrMinSelfDelegationDecreased = types.ErrMinSelfDelegationDecreased - ErrEmptyDelegatorAddr = types.ErrEmptyDelegatorAddr - ErrBadDenom = types.ErrBadDenom - ErrBadDelegationAddr = types.ErrBadDelegationAddr - ErrBadDelegationAmount = types.ErrBadDelegationAmount - ErrNoDelegation = types.ErrNoDelegation - ErrBadDelegatorAddr = types.ErrBadDelegatorAddr - ErrNoDelegatorForAddress = types.ErrNoDelegatorForAddress - ErrInsufficientShares = types.ErrInsufficientShares - ErrDelegationValidatorEmpty = types.ErrDelegationValidatorEmpty - ErrNotEnoughDelegationShares = types.ErrNotEnoughDelegationShares - ErrBadSharesAmount = types.ErrBadSharesAmount - ErrBadSharesPercent = types.ErrBadSharesPercent - ErrNotMature = types.ErrNotMature - ErrNoUnbondingDelegation = types.ErrNoUnbondingDelegation - ErrMaxUnbondingDelegationEntries = types.ErrMaxUnbondingDelegationEntries - ErrBadRedelegationAddr = types.ErrBadRedelegationAddr - ErrNoRedelegation = types.ErrNoRedelegation - ErrSelfRedelegation = types.ErrSelfRedelegation - ErrTinyRedelegationAmount = types.ErrTinyRedelegationAmount - ErrBadRedelegationDst = types.ErrBadRedelegationDst - ErrTransitiveRedelegation = types.ErrTransitiveRedelegation - ErrMaxRedelegationEntries = types.ErrMaxRedelegationEntries - ErrDelegatorShareExRateInvalid = types.ErrDelegatorShareExRateInvalid - ErrBothShareMsgsGiven = types.ErrBothShareMsgsGiven - ErrNeitherShareMsgsGiven = types.ErrNeitherShareMsgsGiven - ErrInvalidHistoricalInfo = types.ErrInvalidHistoricalInfo - ErrNoHistoricalInfo = types.ErrNoHistoricalInfo - ErrEmptyValidatorPubKey = types.ErrEmptyValidatorPubKey - NewGenesisState = types.NewGenesisState - DefaultGenesisState = types.DefaultGenesisState - NewMultiStakingHooks = types.NewMultiStakingHooks - GetValidatorKey = types.GetValidatorKey - GetValidatorByConsAddrKey = types.GetValidatorByConsAddrKey - AddressFromLastValidatorPowerKey = types.AddressFromLastValidatorPowerKey - GetValidatorsByPowerIndexKey = types.GetValidatorsByPowerIndexKey - GetLastValidatorPowerKey = types.GetLastValidatorPowerKey - ParseValidatorPowerRankKey = types.ParseValidatorPowerRankKey - GetValidatorQueueTimeKey = types.GetValidatorQueueTimeKey - GetDelegationKey = types.GetDelegationKey - GetDelegationsKey = types.GetDelegationsKey - GetUBDKey = types.GetUBDKey - GetUBDByValIndexKey = types.GetUBDByValIndexKey - GetUBDKeyFromValIndexKey = types.GetUBDKeyFromValIndexKey - GetUBDsKey = types.GetUBDsKey - GetUBDsByValIndexKey = types.GetUBDsByValIndexKey - GetUnbondingDelegationTimeKey = types.GetUnbondingDelegationTimeKey - GetREDKey = types.GetREDKey - GetREDByValSrcIndexKey = types.GetREDByValSrcIndexKey - GetREDByValDstIndexKey = types.GetREDByValDstIndexKey - GetREDKeyFromValSrcIndexKey = types.GetREDKeyFromValSrcIndexKey - GetREDKeyFromValDstIndexKey = types.GetREDKeyFromValDstIndexKey - GetRedelegationTimeKey = types.GetRedelegationTimeKey - GetREDsKey = types.GetREDsKey - GetREDsFromValSrcIndexKey = types.GetREDsFromValSrcIndexKey - GetREDsToValDstIndexKey = types.GetREDsToValDstIndexKey - GetREDsByDelToValDstIndexKey = types.GetREDsByDelToValDstIndexKey - GetHistoricalInfoKey = types.GetHistoricalInfoKey - NewMsgCreateValidator = types.NewMsgCreateValidator - NewMsgEditValidator = types.NewMsgEditValidator - NewMsgDelegate = types.NewMsgDelegate - NewMsgBeginRedelegate = types.NewMsgBeginRedelegate - NewMsgUndelegate = types.NewMsgUndelegate - NewParams = types.NewParams - DefaultParams = types.DefaultParams - MustUnmarshalParams = types.MustUnmarshalParams - UnmarshalParams = types.UnmarshalParams - NewPool = types.NewPool - NewQueryDelegatorParams = types.NewQueryDelegatorParams - NewQueryValidatorParams = types.NewQueryValidatorParams - NewQueryBondsParams = types.NewQueryBondsParams - NewQueryRedelegationParams = types.NewQueryRedelegationParams - NewQueryValidatorsParams = types.NewQueryValidatorsParams - NewQueryHistoricalInfoParams = types.NewQueryHistoricalInfoParams - NewValidator = types.NewValidator - MustMarshalValidator = types.MustMarshalValidator - MustUnmarshalValidator = types.MustUnmarshalValidator - UnmarshalValidator = types.UnmarshalValidator - NewDescription = types.NewDescription - - // variable aliases - ModuleCdc = types.ModuleCdc - LastValidatorPowerKey = types.LastValidatorPowerKey - LastTotalPowerKey = types.LastTotalPowerKey - ValidatorsKey = types.ValidatorsKey - ValidatorsByConsAddrKey = types.ValidatorsByConsAddrKey - ValidatorsByPowerIndexKey = types.ValidatorsByPowerIndexKey - DelegationKey = types.DelegationKey - UnbondingDelegationKey = types.UnbondingDelegationKey - UnbondingDelegationByValIndexKey = types.UnbondingDelegationByValIndexKey - RedelegationKey = types.RedelegationKey - RedelegationByValSrcIndexKey = types.RedelegationByValSrcIndexKey - RedelegationByValDstIndexKey = types.RedelegationByValDstIndexKey - UnbondingQueueKey = types.UnbondingQueueKey - RedelegationQueueKey = types.RedelegationQueueKey - ValidatorQueueKey = types.ValidatorQueueKey - HistoricalInfoKey = types.HistoricalInfoKey - KeyUnbondingTime = types.KeyUnbondingTime - KeyMaxValidators = types.KeyMaxValidators - KeyMaxEntries = types.KeyMaxEntries - KeyBondDenom = types.KeyBondDenom -) - -type ( - Keeper = keeper.Keeper - Commission = types.Commission - CommissionRates = types.CommissionRates - DVPair = types.DVPair - DVVTriplet = types.DVVTriplet - Delegation = types.Delegation - Delegations = types.Delegations - UnbondingDelegation = types.UnbondingDelegation - UnbondingDelegationEntry = types.UnbondingDelegationEntry - UnbondingDelegations = types.UnbondingDelegations - Redelegation = types.Redelegation - RedelegationEntry = types.RedelegationEntry - Redelegations = types.Redelegations - HistoricalInfo = types.HistoricalInfo - DelegationResponse = types.DelegationResponse - DelegationResponses = types.DelegationResponses - RedelegationResponse = types.RedelegationResponse - RedelegationEntryResponse = types.RedelegationEntryResponse - RedelegationResponses = types.RedelegationResponses - GenesisState = types.GenesisState - LastValidatorPower = types.LastValidatorPower - MultiStakingHooks = types.MultiStakingHooks - MsgCreateValidator = types.MsgCreateValidator - MsgEditValidator = types.MsgEditValidator - MsgDelegate = types.MsgDelegate - MsgBeginRedelegate = types.MsgBeginRedelegate - MsgUndelegate = types.MsgUndelegate - Params = types.Params - Pool = types.Pool - QueryDelegatorParams = types.QueryDelegatorParams - QueryValidatorParams = types.QueryValidatorParams - QueryBondsParams = types.QueryBondsParams - QueryRedelegationParams = types.QueryRedelegationParams - QueryValidatorsParams = types.QueryValidatorsParams - QueryHistoricalInfoParams = types.QueryHistoricalInfoParams - Validator = types.Validator - Validators = types.Validators - Description = types.Description - DelegationI = exported.DelegationI - ValidatorI = exported.ValidatorI -) diff --git a/x/staking/app_test.go b/x/staking/app_test.go index 635898ee923d..6cc5a2083160 100644 --- a/x/staking/app_test.go +++ b/x/staking/app_test.go @@ -10,10 +10,10 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/bank" - "github.com/cosmos/cosmos-sdk/x/staking" + "github.com/cosmos/cosmos-sdk/x/staking/types" ) -func checkValidator(t *testing.T, app *simapp.SimApp, addr sdk.ValAddress, expFound bool) staking.Validator { +func checkValidator(t *testing.T, app *simapp.SimApp, addr sdk.ValAddress, expFound bool) types.Validator { ctxCheck := app.BaseApp.NewContext(true, abci.Header{}) validator, found := app.StakingKeeper.GetValidator(ctxCheck, addr) @@ -63,8 +63,8 @@ func TestStakingMsgs(t *testing.T) { simapp.CheckBalance(t, app, addr2, sdk.Coins{genCoin}) // create validator - description := staking.NewDescription("foo_moniker", "", "", "", "") - createValidatorMsg := staking.NewMsgCreateValidator( + description := types.NewDescription("foo_moniker", "", "", "", "") + createValidatorMsg := types.NewMsgCreateValidator( sdk.ValAddress(addr1), priv1.PubKey(), bondCoin, description, commissionRates, sdk.OneInt(), ) @@ -85,8 +85,8 @@ func TestStakingMsgs(t *testing.T) { app.BeginBlock(abci.RequestBeginBlock{Header: header}) // edit the validator - description = staking.NewDescription("bar_moniker", "", "", "", "") - editValidatorMsg := staking.NewMsgEditValidator(sdk.ValAddress(addr1), description, nil, nil) + description = types.NewDescription("bar_moniker", "", "", "", "") + editValidatorMsg := types.NewMsgEditValidator(sdk.ValAddress(addr1), description, nil, nil) header = abci.Header{Height: app.LastBlockHeight() + 1} _, _, err = simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, []sdk.Msg{editValidatorMsg}, []uint64{0}, []uint64{1}, true, true, priv1) @@ -97,7 +97,7 @@ func TestStakingMsgs(t *testing.T) { // delegate simapp.CheckBalance(t, app, addr2, sdk.Coins{genCoin}) - delegateMsg := staking.NewMsgDelegate(addr2, sdk.ValAddress(addr1), bondCoin) + delegateMsg := types.NewMsgDelegate(addr2, sdk.ValAddress(addr1), bondCoin) header = abci.Header{Height: app.LastBlockHeight() + 1} _, _, err = simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, []sdk.Msg{delegateMsg}, []uint64{1}, []uint64{0}, true, true, priv2) @@ -107,7 +107,7 @@ func TestStakingMsgs(t *testing.T) { checkDelegation(t, app, addr2, sdk.ValAddress(addr1), true, bondTokens.ToDec()) // begin unbonding - beginUnbondingMsg := staking.NewMsgUndelegate(addr2, sdk.ValAddress(addr1), bondCoin) + beginUnbondingMsg := types.NewMsgUndelegate(addr2, sdk.ValAddress(addr1), bondCoin) header = abci.Header{Height: app.LastBlockHeight() + 1} _, _, err = simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, []sdk.Msg{beginUnbondingMsg}, []uint64{1}, []uint64{1}, true, true, priv2) require.NoError(t, err) diff --git a/x/staking/client/testutil/helpers.go b/x/staking/client/testutil/helpers.go index b9694d2e93d5..7a0ddffb8eb0 100644 --- a/x/staking/client/testutil/helpers.go +++ b/x/staking/client/testutil/helpers.go @@ -9,7 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/tests" "github.com/cosmos/cosmos-sdk/tests/cli" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/staking" + "github.com/cosmos/cosmos-sdk/x/staking/types" ) // TxStakingCreateValidator is simcli tx staking create-validator @@ -31,11 +31,11 @@ func TxStakingUnbond(f *cli.Fixtures, from, shares string, validator sdk.ValAddr } // QueryStakingValidator is simcli query staking validator -func QueryStakingValidator(f *cli.Fixtures, valAddr sdk.ValAddress, flags ...string) staking.Validator { +func QueryStakingValidator(f *cli.Fixtures, valAddr sdk.ValAddress, flags ...string) types.Validator { cmd := fmt.Sprintf("%s query staking validator %s %v", f.SimcliBinary, valAddr, f.Flags()) out, _ := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "") - var validator staking.Validator + var validator types.Validator err := f.Cdc.UnmarshalJSON([]byte(out), &validator) require.NoError(f.T, err, "out %v\n, err %v", out, err) @@ -44,11 +44,11 @@ func QueryStakingValidator(f *cli.Fixtures, valAddr sdk.ValAddress, flags ...str } // QueryStakingUnbondingDelegationsFrom is simcli query staking unbonding-delegations-from -func QueryStakingUnbondingDelegationsFrom(f *cli.Fixtures, valAddr sdk.ValAddress, flags ...string) []staking.UnbondingDelegation { +func QueryStakingUnbondingDelegationsFrom(f *cli.Fixtures, valAddr sdk.ValAddress, flags ...string) []types.UnbondingDelegation { cmd := fmt.Sprintf("%s query staking unbonding-delegations-from %s %v", f.SimcliBinary, valAddr, f.Flags()) out, _ := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "") - var ubds []staking.UnbondingDelegation + var ubds []types.UnbondingDelegation err := f.Cdc.UnmarshalJSON([]byte(out), &ubds) require.NoError(f.T, err, "out %v\n, err %v", out, err) @@ -57,11 +57,11 @@ func QueryStakingUnbondingDelegationsFrom(f *cli.Fixtures, valAddr sdk.ValAddres } // QueryStakingDelegationsTo is simcli query staking delegations-to -func QueryStakingDelegationsTo(f *cli.Fixtures, valAddr sdk.ValAddress, flags ...string) []staking.Delegation { +func QueryStakingDelegationsTo(f *cli.Fixtures, valAddr sdk.ValAddress, flags ...string) []types.Delegation { cmd := fmt.Sprintf("%s query staking delegations-to %s %v", f.SimcliBinary, valAddr, f.Flags()) out, _ := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "") - var delegations []staking.Delegation + var delegations []types.Delegation err := f.Cdc.UnmarshalJSON([]byte(out), &delegations) require.NoError(f.T, err, "out %v\n, err %v", out, err) @@ -70,11 +70,11 @@ func QueryStakingDelegationsTo(f *cli.Fixtures, valAddr sdk.ValAddress, flags .. } // QueryStakingPool is simcli query staking pool -func QueryStakingPool(f *cli.Fixtures, flags ...string) staking.Pool { +func QueryStakingPool(f *cli.Fixtures, flags ...string) types.Pool { cmd := fmt.Sprintf("%s query staking pool %v", f.SimcliBinary, f.Flags()) out, _ := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "") - var pool staking.Pool + var pool types.Pool err := f.Cdc.UnmarshalJSON([]byte(out), &pool) require.NoError(f.T, err, "out %v\n, err %v", out, err) @@ -83,11 +83,11 @@ func QueryStakingPool(f *cli.Fixtures, flags ...string) staking.Pool { } // QueryStakingParameters is simcli query staking parameters -func QueryStakingParameters(f *cli.Fixtures, flags ...string) staking.Params { +func QueryStakingParameters(f *cli.Fixtures, flags ...string) types.Params { cmd := fmt.Sprintf("%s query staking params %v", f.SimcliBinary, f.Flags()) out, _ := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "") - var params staking.Params + var params types.Params err := f.Cdc.UnmarshalJSON([]byte(out), ¶ms) require.NoError(f.T, err, "out %v\n, err %v", out, err) diff --git a/x/staking/common_test.go b/x/staking/common_test.go index 772a936ff6bb..a19969df7eaa 100644 --- a/x/staking/common_test.go +++ b/x/staking/common_test.go @@ -8,7 +8,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/staking" "github.com/cosmos/cosmos-sdk/x/staking/keeper" "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -20,20 +19,20 @@ var ( priv2 = secp256k1.GenPrivKey() addr2 = sdk.AccAddress(priv2.PubKey().Address()) - commissionRates = staking.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()) + commissionRates = types.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()) PKs = simapp.CreateTestPubKeys(500) ) -func NewTestMsgCreateValidator(address sdk.ValAddress, pubKey crypto.PubKey, amt sdk.Int) *staking.MsgCreateValidator { +func NewTestMsgCreateValidator(address sdk.ValAddress, pubKey crypto.PubKey, amt sdk.Int) *types.MsgCreateValidator { return types.NewMsgCreateValidator( - address, pubKey, sdk.NewCoin(sdk.DefaultBondDenom, amt), staking.Description{}, commissionRates, sdk.OneInt(), + address, pubKey, sdk.NewCoin(sdk.DefaultBondDenom, amt), types.Description{}, commissionRates, sdk.OneInt(), ) } -func NewTestMsgDelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amt sdk.Int) *staking.MsgDelegate { +func NewTestMsgDelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amt sdk.Int) *types.MsgDelegate { amount := sdk.NewCoin(sdk.DefaultBondDenom, amt) - return staking.NewMsgDelegate(delAddr, valAddr, amount) + return types.NewMsgDelegate(delAddr, valAddr, amount) } // getBaseSimappWithCustomKeeper Returns a simapp with custom StakingKeeper @@ -46,10 +45,10 @@ func getBaseSimappWithCustomKeeper() (*codec.Codec, *simapp.SimApp, sdk.Context) app.StakingKeeper = keeper.NewKeeper( appCodec, - app.GetKey(staking.StoreKey), + app.GetKey(types.StoreKey), app.AccountKeeper, app.BankKeeper, - app.GetSubspace(staking.ModuleName), + app.GetSubspace(types.ModuleName), ) app.StakingKeeper.SetParams(ctx, types.DefaultParams()) diff --git a/x/staking/genesis.go b/x/staking/genesis.go index 1fda9769d97c..8bd5ef6d6911 100644 --- a/x/staking/genesis.go +++ b/x/staking/genesis.go @@ -8,6 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/staking/exported" + "github.com/cosmos/cosmos-sdk/x/staking/keeper" "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -17,7 +18,7 @@ import ( // data. Finally, it updates the bonded validators. // Returns final validator set after applying all declaration and delegations func InitGenesis( - ctx sdk.Context, keeper Keeper, accountKeeper types.AccountKeeper, + ctx sdk.Context, keeper keeper.Keeper, accountKeeper types.AccountKeeper, bankKeeper types.BankKeeper, data types.GenesisState, ) (res []abci.ValidatorUpdate) { bondedTokens := sdk.ZeroInt() @@ -146,7 +147,7 @@ func InitGenesis( // ExportGenesis returns a GenesisState for a given context and keeper. The // GenesisState will contain the pool, params, validators, and bonds found in // the keeper. -func ExportGenesis(ctx sdk.Context, keeper Keeper) types.GenesisState { +func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) types.GenesisState { var unbondingDelegations []types.UnbondingDelegation keeper.IterateUnbondingDelegations(ctx, func(_ int64, ubd types.UnbondingDelegation) (stop bool) { @@ -181,7 +182,7 @@ func ExportGenesis(ctx sdk.Context, keeper Keeper) types.GenesisState { } // WriteValidators returns a slice of bonded genesis validators. -func WriteValidators(ctx sdk.Context, keeper Keeper) (vals []tmtypes.GenesisValidator) { +func WriteValidators(ctx sdk.Context, keeper keeper.Keeper) (vals []tmtypes.GenesisValidator) { keeper.IterateLastValidators(ctx, func(_ int64, validator exported.ValidatorI) (stop bool) { vals = append(vals, tmtypes.GenesisValidator{ PubKey: validator.GetConsPubKey(), diff --git a/x/staking/handler.go b/x/staking/handler.go index c7157d30b97f..71efc39fd112 100644 --- a/x/staking/handler.go +++ b/x/staking/handler.go @@ -34,7 +34,7 @@ func NewHandler(k keeper.Keeper) sdk.Handler { return handleMsgUndelegate(ctx, msg, k) default: - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", ModuleName, msg) + return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", types.ModuleName, msg) } } } @@ -45,7 +45,7 @@ func NewHandler(k keeper.Keeper) sdk.Handler { func handleMsgCreateValidator(ctx sdk.Context, msg *types.MsgCreateValidator, k keeper.Keeper) (*sdk.Result, error) { // check to see if the pubkey or sender has been registered before if _, found := k.GetValidator(ctx, msg.ValidatorAddress); found { - return nil, ErrValidatorOwnerExists + return nil, types.ErrValidatorOwnerExists } pk, err := sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, msg.Pubkey) @@ -54,11 +54,11 @@ func handleMsgCreateValidator(ctx sdk.Context, msg *types.MsgCreateValidator, k } if _, found := k.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(pk)); found { - return nil, ErrValidatorPubKeyExists + return nil, types.ErrValidatorPubKeyExists } if msg.Value.Denom != k.BondDenom(ctx) { - return nil, ErrBadDenom + return nil, types.ErrBadDenom } if _, err := msg.Description.EnsureLength(); err != nil { @@ -71,14 +71,14 @@ func handleMsgCreateValidator(ctx sdk.Context, msg *types.MsgCreateValidator, k if !tmstrings.StringInSlice(tmPubKey.Type, cp.Validator.PubKeyTypes) { return nil, sdkerrors.Wrapf( - ErrValidatorPubKeyTypeNotSupported, + types.ErrValidatorPubKeyTypeNotSupported, "got: %s, expected: %s", tmPubKey.Type, cp.Validator.PubKeyTypes, ) } } - validator := NewValidator(msg.ValidatorAddress, pk, msg.Description) - commission := NewCommissionWithTime( + validator := types.NewValidator(msg.ValidatorAddress, pk, msg.Description) + commission := types.NewCommissionWithTime( msg.Commission.Rate, msg.Commission.MaxRate, msg.Commission.MaxChangeRate, ctx.BlockHeader().Time, ) @@ -125,7 +125,7 @@ func handleMsgEditValidator(ctx sdk.Context, msg *types.MsgEditValidator, k keep // validator must already be registered validator, found := k.GetValidator(ctx, msg.ValidatorAddress) if !found { - return nil, ErrNoValidatorFound + return nil, types.ErrNoValidatorFound } // replace all editable fields (clients should autofill existing values) @@ -150,11 +150,11 @@ func handleMsgEditValidator(ctx sdk.Context, msg *types.MsgEditValidator, k keep if msg.MinSelfDelegation != nil { if !msg.MinSelfDelegation.GT(validator.MinSelfDelegation) { - return nil, ErrMinSelfDelegationDecreased + return nil, types.ErrMinSelfDelegationDecreased } if msg.MinSelfDelegation.GT(validator.Tokens) { - return nil, ErrSelfDelegationBelowMinimum + return nil, types.ErrSelfDelegationBelowMinimum } validator.MinSelfDelegation = (*msg.MinSelfDelegation) @@ -181,11 +181,11 @@ func handleMsgEditValidator(ctx sdk.Context, msg *types.MsgEditValidator, k keep func handleMsgDelegate(ctx sdk.Context, msg *types.MsgDelegate, k keeper.Keeper) (*sdk.Result, error) { validator, found := k.GetValidator(ctx, msg.ValidatorAddress) if !found { - return nil, ErrNoValidatorFound + return nil, types.ErrNoValidatorFound } if msg.Amount.Denom != k.BondDenom(ctx) { - return nil, ErrBadDenom + return nil, types.ErrBadDenom } // NOTE: source funds are always unbonded @@ -219,7 +219,7 @@ func handleMsgUndelegate(ctx sdk.Context, msg *types.MsgUndelegate, k keeper.Kee } if msg.Amount.Denom != k.BondDenom(ctx) { - return nil, ErrBadDenom + return nil, types.ErrBadDenom } completionTime, err := k.Undelegate(ctx, msg.DelegatorAddress, msg.ValidatorAddress, shares) @@ -229,7 +229,7 @@ func handleMsgUndelegate(ctx sdk.Context, msg *types.MsgUndelegate, k keeper.Kee ts, err := gogotypes.TimestampProto(completionTime) if err != nil { - return nil, ErrBadRedelegationAddr + return nil, types.ErrBadRedelegationAddr } completionTimeBz := types.ModuleCdc.MustMarshalBinaryLengthPrefixed(ts) @@ -259,7 +259,7 @@ func handleMsgBeginRedelegate(ctx sdk.Context, msg *types.MsgBeginRedelegate, k } if msg.Amount.Denom != k.BondDenom(ctx) { - return nil, ErrBadDenom + return nil, types.ErrBadDenom } completionTime, err := k.BeginRedelegation( @@ -271,7 +271,7 @@ func handleMsgBeginRedelegate(ctx sdk.Context, msg *types.MsgBeginRedelegate, k ts, err := gogotypes.TimestampProto(completionTime) if err != nil { - return nil, ErrBadRedelegationAddr + return nil, types.ErrBadRedelegationAddr } completionTimeBz := types.ModuleCdc.MustMarshalBinaryLengthPrefixed(ts) diff --git a/x/staking/handler_test.go b/x/staking/handler_test.go index 99fa87a3df45..7358c8e46f73 100644 --- a/x/staking/handler_test.go +++ b/x/staking/handler_test.go @@ -68,7 +68,7 @@ func TestValidatorByPowerIndex(t *testing.T) { // verify that the by power index exists validator, found := app.StakingKeeper.GetValidator(ctx, validatorAddr) require.True(t, found) - power := staking.GetValidatorsByPowerIndexKey(validator) + power := types.GetValidatorsByPowerIndexKey(validator) require.True(t, keeper.ValidatorByPowerIndexExists(ctx, app.StakingKeeper, power)) // create a second validator keep it bonded @@ -99,17 +99,17 @@ func TestValidatorByPowerIndex(t *testing.T) { // but the new power record should have been created validator, found = app.StakingKeeper.GetValidator(ctx, validatorAddr) require.True(t, found) - power2 := staking.GetValidatorsByPowerIndexKey(validator) + power2 := types.GetValidatorsByPowerIndexKey(validator) require.True(t, keeper.ValidatorByPowerIndexExists(ctx, app.StakingKeeper, power2)) // now the new record power index should be the same as the original record - power3 := staking.GetValidatorsByPowerIndexKey(validator) + power3 := types.GetValidatorsByPowerIndexKey(validator) require.Equal(t, power2, power3) // unbond self-delegation totalBond := validator.TokensFromShares(bond.GetShares()).TruncateInt() unbondAmt := sdk.NewCoin(sdk.DefaultBondDenom, totalBond) - msgUndelegate := staking.NewMsgUndelegate(sdk.AccAddress(validatorAddr), validatorAddr, unbondAmt) + msgUndelegate := types.NewMsgUndelegate(sdk.AccAddress(validatorAddr), validatorAddr, unbondAmt) res, err = handler(ctx, msgUndelegate) require.NoError(t, err) @@ -1228,7 +1228,7 @@ func TestMultipleUnbondingDelegationAtUniqueTimes(t *testing.T) { // begin an unbonding delegation selfDelAddr := sdk.AccAddress(valAddr) // (the validator is it's own delegator) unbondAmt := sdk.NewCoin(sdk.DefaultBondDenom, valTokens.QuoRaw(2)) - msgUndelegate := staking.NewMsgUndelegate(selfDelAddr, valAddr, unbondAmt) + msgUndelegate := types.NewMsgUndelegate(selfDelAddr, valAddr, unbondAmt) res, err = handler(ctx, msgUndelegate) require.NoError(t, err) require.NotNil(t, res) @@ -1436,7 +1436,7 @@ func TestBondUnbondRedelegateSlashTwice(t *testing.T) { } func TestInvalidMsg(t *testing.T) { - k := staking.Keeper{} + k := keeper.Keeper{} h := staking.NewHandler(k) res, err := h(sdk.NewContext(nil, abci.Header{}, false, nil), sdk.NewTestMsg()) diff --git a/x/staking/keeper/common_test.go b/x/staking/keeper/common_test.go index 6be734af0e3d..b4c98a011c46 100644 --- a/x/staking/keeper/common_test.go +++ b/x/staking/keeper/common_test.go @@ -8,7 +8,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/staking" "github.com/cosmos/cosmos-sdk/x/staking/keeper" "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -27,10 +26,10 @@ func createTestInput() (*codec.Codec, *simapp.SimApp, sdk.Context) { app.StakingKeeper = keeper.NewKeeper( appCodec, - app.GetKey(staking.StoreKey), + app.GetKey(types.StoreKey), app.AccountKeeper, app.BankKeeper, - app.GetSubspace(staking.ModuleName), + app.GetSubspace(types.ModuleName), ) return codec.New(), app, ctx diff --git a/x/staking/keeper/querier_test.go b/x/staking/keeper/querier_test.go index 3c3d820c17ba..acd76d8874f8 100644 --- a/x/staking/keeper/querier_test.go +++ b/x/staking/keeper/querier_test.go @@ -10,7 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/staking" + "github.com/cosmos/cosmos-sdk/x/staking/keeper" "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -43,7 +43,7 @@ func TestNewQuerier(t *testing.T) { Data: []byte{}, } - querier := staking.NewQuerier(app.StakingKeeper) + querier := keeper.NewQuerier(app.StakingKeeper) bz, err := querier(ctx, []string{"other"}, query) require.Error(t, err) @@ -107,11 +107,11 @@ func TestNewQuerier(t *testing.T) { func TestQueryParametersPool(t *testing.T) { cdc, app, ctx := createTestInput() - querier := staking.NewQuerier(app.StakingKeeper) + querier := keeper.NewQuerier(app.StakingKeeper) bondDenom := sdk.DefaultBondDenom - res, err := querier(ctx, []string{staking.QueryParameters}, abci.RequestQuery{}) + res, err := querier(ctx, []string{types.QueryParameters}, abci.RequestQuery{}) require.NoError(t, err) var params types.Params @@ -119,7 +119,7 @@ func TestQueryParametersPool(t *testing.T) { require.NoError(t, errRes) require.Equal(t, app.StakingKeeper.GetParams(ctx), params) - res, err = querier(ctx, []string{staking.QueryPool}, abci.RequestQuery{}) + res, err = querier(ctx, []string{types.QueryPool}, abci.RequestQuery{}) require.NoError(t, err) var pool types.Pool @@ -133,7 +133,7 @@ func TestQueryParametersPool(t *testing.T) { func TestQueryValidators(t *testing.T) { cdc, app, ctx := createTestInput() params := app.StakingKeeper.GetParams(ctx) - querier := staking.NewQuerier(app.StakingKeeper) + querier := keeper.NewQuerier(app.StakingKeeper) addrs := simapp.AddTestAddrs(app, ctx, 500, sdk.TokensFromConsensusPower(10000)) @@ -200,7 +200,7 @@ func TestQueryValidators(t *testing.T) { func TestQueryDelegation(t *testing.T) { cdc, app, ctx := createTestInput() params := app.StakingKeeper.GetParams(ctx) - querier := staking.NewQuerier(app.StakingKeeper) + querier := keeper.NewQuerier(app.StakingKeeper) addrs := simapp.AddTestAddrs(app, ctx, 2, sdk.TokensFromConsensusPower(10000)) addrAcc1, addrAcc2 := addrs[0], addrs[1] @@ -448,7 +448,7 @@ func TestQueryValidatorDelegations_Pagination(t *testing.T) { } cdc, app, ctx := createTestInput() - querier := staking.NewQuerier(app.StakingKeeper) + querier := keeper.NewQuerier(app.StakingKeeper) addrs := simapp.AddTestAddrs(app, ctx, 100, sdk.TokensFromConsensusPower(10000)) pubKeys := simapp.CreateTestPubKeys(1) @@ -532,7 +532,7 @@ func TestQueryValidatorDelegations_Pagination(t *testing.T) { func TestQueryRedelegations(t *testing.T) { cdc, app, ctx := createTestInput() - querier := staking.NewQuerier(app.StakingKeeper) + querier := keeper.NewQuerier(app.StakingKeeper) addrs := simapp.AddTestAddrs(app, ctx, 2, sdk.TokensFromConsensusPower(10000)) addrAcc1, addrAcc2 := addrs[0], addrs[1] @@ -603,7 +603,7 @@ func TestQueryRedelegations(t *testing.T) { func TestQueryUnbondingDelegation(t *testing.T) { cdc, app, ctx := createTestInput() - querier := staking.NewQuerier(app.StakingKeeper) + querier := keeper.NewQuerier(app.StakingKeeper) addrs := simapp.AddTestAddrs(app, ctx, 2, sdk.TokensFromConsensusPower(10000)) addrAcc1, addrAcc2 := addrs[0], addrs[1] @@ -698,7 +698,7 @@ func TestQueryUnbondingDelegation(t *testing.T) { func TestQueryHistoricalInfo(t *testing.T) { cdc, app, ctx := createTestInput() - querier := staking.NewQuerier(app.StakingKeeper) + querier := keeper.NewQuerier(app.StakingKeeper) addrs := simapp.AddTestAddrs(app, ctx, 2, sdk.TokensFromConsensusPower(10000)) addrAcc1, addrAcc2 := addrs[0], addrs[1] diff --git a/x/staking/module.go b/x/staking/module.go index 1b999444d078..3597009db724 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -23,6 +23,7 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/staking/client/cli" "github.com/cosmos/cosmos-sdk/x/staking/client/rest" + "github.com/cosmos/cosmos-sdk/x/staking/keeper" "github.com/cosmos/cosmos-sdk/x/staking/simulation" "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -42,25 +43,25 @@ var _ module.AppModuleBasic = AppModuleBasic{} // Name returns the staking module's name. func (AppModuleBasic) Name() string { - return ModuleName + return types.ModuleName } // RegisterCodec registers the staking 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 staking // 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 staking 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) @@ -78,7 +79,7 @@ func (AppModuleBasic) GetTxCmd(clientCtx client.Context) *cobra.Command { // GetQueryCmd returns no root query command for the staking module. func (AppModuleBasic) GetQueryCmd(clientCtx client.Context) *cobra.Command { - return cli.GetQueryCmd(StoreKey, clientCtx.Codec) + return cli.GetQueryCmd(types.StoreKey, clientCtx.Codec) } //_____________________________________ @@ -108,13 +109,13 @@ func (AppModuleBasic) BuildCreateValidatorMsg(clientCtx client.Context, type AppModule struct { AppModuleBasic - keeper Keeper + keeper keeper.Keeper accountKeeper types.AccountKeeper bankKeeper types.BankKeeper } // NewAppModule creates a new AppModule object -func NewAppModule(cdc codec.Marshaler, keeper Keeper, ak types.AccountKeeper, bk types.BankKeeper) AppModule { +func NewAppModule(cdc codec.Marshaler, keeper keeper.Keeper, ak types.AccountKeeper, bk types.BankKeeper) AppModule { return AppModule{ AppModuleBasic: AppModuleBasic{cdc: cdc}, keeper: keeper, @@ -125,27 +126,27 @@ func NewAppModule(cdc codec.Marshaler, keeper Keeper, ak types.AccountKeeper, bk // Name returns the staking module's name. func (AppModule) Name() string { - return ModuleName + return types.ModuleName } // RegisterInvariants registers the staking module invariants. func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { - RegisterInvariants(ir, am.keeper) + keeper.RegisterInvariants(ir, am.keeper) } // Route returns the message routing key for the staking module. func (am AppModule) Route() sdk.Route { - return sdk.NewRoute(RouterKey, NewHandler(am.keeper)) + return sdk.NewRoute(types.RouterKey, NewHandler(am.keeper)) } // QuerierRoute returns the staking module's querier route name. func (AppModule) QuerierRoute() string { - return QuerierRoute + return types.QuerierRoute } // NewQuerierHandler returns the staking module sdk.Querier. func (am AppModule) NewQuerierHandler() sdk.Querier { - return NewQuerier(am.keeper) + return keeper.NewQuerier(am.keeper) } func (am AppModule) RegisterQueryService(grpc.Server) {} @@ -153,7 +154,7 @@ func (am AppModule) RegisterQueryService(grpc.Server) {} // InitGenesis performs genesis initialization for the staking 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) @@ -199,7 +200,7 @@ func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange { // RegisterStoreDecoder registers a decoder for staking module's types func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { - sdr[StoreKey] = simulation.NewDecodeStore(am.cdc) + sdr[types.StoreKey] = simulation.NewDecodeStore(am.cdc) } // WeightedOperations returns the all the staking module operations with their respective weights. diff --git a/x/staking/module_test.go b/x/staking/module_test.go index de77f4c97f8f..ed90d8458560 100644 --- a/x/staking/module_test.go +++ b/x/staking/module_test.go @@ -4,27 +4,27 @@ 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/staking" + "github.com/cosmos/cosmos-sdk/x/staking/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(staking.BondedPoolName)) + acc := app.AccountKeeper.GetAccount(ctx, auth.NewModuleAddress(types.BondedPoolName)) require.NotNil(t, acc) - acc = app.AccountKeeper.GetAccount(ctx, auth.NewModuleAddress(staking.NotBondedPoolName)) + acc = app.AccountKeeper.GetAccount(ctx, auth.NewModuleAddress(types.NotBondedPoolName)) require.NotNil(t, acc) }