refactor: move x/{moduleName}/test{ModuleName} to x/{moduleName}/testutil (#13427)

* refactor: move `x/{moduleName}/test{ModuleName}` to `x/{moduleName}/testutil`

* updates

* updates
This commit is contained in:
Julien Robert
2022-10-02 10:42:52 -04:00
committed by GitHub
parent c221d7f1de
commit 80ce491734
33 changed files with 175 additions and 183 deletions
@@ -138,9 +138,6 @@ func (suite *IntegrationTestSuite) SetupTest() {
suite.ctx = app.BaseApp.NewContext(false, tmproto.Header{Time: time.Now()})
suite.fetchStoreKey = app.UnsafeFindStoreKey
// suite.Require().NoError(suite.accountKeeper.SetParams(suite.ctx, authtypes.DefaultParams()))
suite.Require().NoError(suite.bankKeeper.SetParams(suite.ctx, types.DefaultParams()))
queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, interfaceRegistry)
types.RegisterQueryServer(queryHelper, suite.bankKeeper)
queryClient := types.NewQueryClient(queryHelper)
@@ -18,7 +18,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/distribution/testutil"
disttypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
"github.com/cosmos/cosmos-sdk/x/staking/teststaking"
stakingtestutil "github.com/cosmos/cosmos-sdk/x/staking/testutil"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)
@@ -40,7 +40,7 @@ func TestAllocateTokensToValidatorWithCommission(t *testing.T) {
addrs := simtestutil.AddTestAddrs(bankKeeper, stakingKeeper, ctx, 3, sdk.NewInt(1234))
valAddrs := simtestutil.ConvertAddrsToValAddrs(addrs)
tstaking := teststaking.NewHelper(t, ctx, stakingKeeper)
tstaking := stakingtestutil.NewHelper(t, ctx, stakingKeeper)
// create validator with 50% commission
tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), math.LegacyNewDec(0))
@@ -86,7 +86,7 @@ func TestAllocateTokensToManyValidators(t *testing.T) {
addrs := simtestutil.AddTestAddrs(bankKeeper, stakingKeeper, ctx, 2, sdk.NewInt(1234))
valAddrs := simtestutil.ConvertAddrsToValAddrs(addrs)
tstaking := teststaking.NewHelper(t, ctx, stakingKeeper)
tstaking := stakingtestutil.NewHelper(t, ctx, stakingKeeper)
// create validator with 50% commission
tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), math.LegacyNewDec(0))
@@ -179,7 +179,7 @@ func TestAllocateTokensTruncation(t *testing.T) {
addrs := simtestutil.AddTestAddrs(bankKeeper, stakingKeeper, ctx, 3, sdk.NewInt(1234))
valAddrs := simtestutil.ConvertAddrsToValAddrs(addrs)
tstaking := teststaking.NewHelper(t, ctx, stakingKeeper)
tstaking := stakingtestutil.NewHelper(t, ctx, stakingKeeper)
// create validator with 10% commission
tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(1, 1), sdk.NewDecWithPrec(1, 1), math.LegacyNewDec(0))
@@ -16,7 +16,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/distribution/testutil"
"github.com/cosmos/cosmos-sdk/x/staking"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
"github.com/cosmos/cosmos-sdk/x/staking/teststaking"
stakingtestutil "github.com/cosmos/cosmos-sdk/x/staking/testutil"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)
@@ -38,7 +38,7 @@ func TestCalculateRewardsBasic(t *testing.T) {
distrKeeper.DeleteAllValidatorHistoricalRewards(ctx)
tstaking := teststaking.NewHelper(t, ctx, stakingKeeper)
tstaking := stakingtestutil.NewHelper(t, ctx, stakingKeeper)
addr := simtestutil.AddTestAddrs(bankKeeper, stakingKeeper, ctx, 2, sdk.NewInt(1000))
valAddrs := simtestutil.ConvertAddrsToValAddrs(addr)
@@ -107,7 +107,7 @@ func TestCalculateRewardsAfterSlash(t *testing.T) {
addr := simtestutil.AddTestAddrs(bankKeeper, stakingKeeper, ctx, 2, sdk.NewInt(100000000))
valAddrs := simtestutil.ConvertAddrsToValAddrs(addr)
tstaking := teststaking.NewHelper(t, ctx, stakingKeeper)
tstaking := stakingtestutil.NewHelper(t, ctx, stakingKeeper)
// create validator with 50% commission
tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), math.LegacyNewDec(0))
@@ -180,7 +180,7 @@ func TestCalculateRewardsAfterManySlashes(t *testing.T) {
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
tstaking := teststaking.NewHelper(t, ctx, stakingKeeper)
tstaking := stakingtestutil.NewHelper(t, ctx, stakingKeeper)
addr := simtestutil.AddTestAddrs(bankKeeper, stakingKeeper, ctx, 2, sdk.NewInt(100000000))
valAddrs := simtestutil.ConvertAddrsToValAddrs(addr)
@@ -267,7 +267,7 @@ func TestCalculateRewardsMultiDelegator(t *testing.T) {
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
tstaking := teststaking.NewHelper(t, ctx, stakingKeeper)
tstaking := stakingtestutil.NewHelper(t, ctx, stakingKeeper)
addr := simtestutil.AddTestAddrs(bankKeeper, stakingKeeper, ctx, 2, sdk.NewInt(100000000))
valAddrs := simtestutil.ConvertAddrsToValAddrs(addr)
@@ -350,7 +350,7 @@ func TestWithdrawDelegationRewardsBasic(t *testing.T) {
balanceTokens := stakingKeeper.TokensFromConsensusPower(ctx, balancePower)
addr := simtestutil.AddTestAddrs(bankKeeper, stakingKeeper, ctx, 1, sdk.NewInt(1000000000))
valAddrs := simtestutil.ConvertAddrsToValAddrs(addr)
tstaking := teststaking.NewHelper(t, ctx, stakingKeeper)
tstaking := stakingtestutil.NewHelper(t, ctx, stakingKeeper)
// set module account coins
distrAcc := distrKeeper.GetDistributionAccount(ctx)
@@ -431,7 +431,7 @@ func TestCalculateRewardsAfterManySlashesInSameBlock(t *testing.T) {
addr := simtestutil.AddTestAddrs(bankKeeper, stakingKeeper, ctx, 1, sdk.NewInt(1000000000))
valAddrs := simtestutil.ConvertAddrsToValAddrs(addr)
tstaking := teststaking.NewHelper(t, ctx, stakingKeeper)
tstaking := stakingtestutil.NewHelper(t, ctx, stakingKeeper)
// create validator with 50% commission
valPower := int64(100)
@@ -509,7 +509,7 @@ func TestCalculateRewardsMultiDelegatorMultiSlash(t *testing.T) {
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
tstaking := teststaking.NewHelper(t, ctx, stakingKeeper)
tstaking := stakingtestutil.NewHelper(t, ctx, stakingKeeper)
addr := simtestutil.AddTestAddrs(bankKeeper, stakingKeeper, ctx, 2, sdk.NewInt(1000000000))
valAddrs := simtestutil.ConvertAddrsToValAddrs(addr)
@@ -599,7 +599,7 @@ func TestCalculateRewardsMultiDelegatorMultWithdraw(t *testing.T) {
distrKeeper.DeleteAllValidatorHistoricalRewards(ctx)
tstaking := teststaking.NewHelper(t, ctx, stakingKeeper)
tstaking := stakingtestutil.NewHelper(t, ctx, stakingKeeper)
addr := simtestutil.AddTestAddrs(bankKeeper, stakingKeeper, ctx, 2, sdk.NewInt(1000000000))
valAddrs := simtestutil.ConvertAddrsToValAddrs(addr)
initial := int64(20)
@@ -758,7 +758,7 @@ func Test100PercentCommissionReward(t *testing.T) {
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
tstaking := teststaking.NewHelper(t, ctx, stakingKeeper)
tstaking := stakingtestutil.NewHelper(t, ctx, stakingKeeper)
addr := simtestutil.AddTestAddrs(bankKeeper, stakingKeeper, ctx, 2, sdk.NewInt(1000000000))
valAddrs := simtestutil.ConvertAddrsToValAddrs(addr)
initial := int64(20)
@@ -21,7 +21,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/cosmos/cosmos-sdk/x/staking"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
"github.com/cosmos/cosmos-sdk/x/staking/teststaking"
stakingtestutil "github.com/cosmos/cosmos-sdk/x/staking/testutil"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)
@@ -60,8 +60,6 @@ func (suite *KeeperTestSuite) SetupTest() {
suite.addrs = simtestutil.AddTestAddrs(suite.bankKeeper, suite.stakingKeeper, ctx, 2, sdk.NewInt(1000000000))
suite.valAddrs = simtestutil.ConvertAddrsToValAddrs(suite.addrs)
suite.NoError(suite.distrKeeper.SetParams(suite.ctx, types.DefaultParams()))
suite.msgServer = keeper.NewMsgServerImpl(suite.distrKeeper)
}
@@ -362,7 +360,7 @@ func (suite *KeeperTestSuite) TestGRPCValidatorSlashes() {
func (suite *KeeperTestSuite) TestGRPCDelegationRewards() {
ctx, addrs, valAddrs := suite.ctx, suite.addrs, suite.valAddrs
tstaking := teststaking.NewHelper(suite.T(), ctx, suite.stakingKeeper)
tstaking := stakingtestutil.NewHelper(suite.T(), ctx, suite.stakingKeeper)
tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), math.LegacyNewDec(0))
tstaking.CreateValidator(valAddrs[0], valConsPk0, sdk.NewInt(100), true)
@@ -10,19 +10,16 @@ import (
"github.com/cosmos/cosmos-sdk/baseapp"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/slashing/testslashing"
"github.com/cosmos/cosmos-sdk/x/slashing/testutil"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/cosmos/cosmos-sdk/x/staking/teststaking"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtestutil "github.com/cosmos/cosmos-sdk/x/staking/testutil"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)
@@ -57,10 +54,8 @@ func (s *KeeperTestSuite) SetupTest() {
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
s.accountKeeper.SetParams(ctx, authtypes.DefaultParams())
s.bankKeeper.SetParams(ctx, banktypes.DefaultParams())
s.slashingKeeper.SetParams(ctx, testslashing.TestParams())
// TestParams set the SignedBlocksWindow to 1000 and MaxMissedBlocksPerWindow to 500
s.slashingKeeper.SetParams(ctx, testutil.TestParams())
addrDels := simtestutil.AddTestAddrsIncremental(s.bankKeeper, s.stakingKeeper, ctx, 5, s.stakingKeeper.TokensFromConsensusPower(ctx, 200))
info1 := slashingtypes.NewValidatorSigningInfo(sdk.ConsAddress(addrDels[0]), int64(4), int64(3),
@@ -91,7 +86,7 @@ func (s *KeeperTestSuite) TestUnJailNotBonded() {
addrDels := simtestutil.AddTestAddrsIncremental(s.bankKeeper, s.stakingKeeper, ctx, 6, s.stakingKeeper.TokensFromConsensusPower(ctx, 200))
valAddrs := simtestutil.ConvertAddrsToValAddrs(addrDels)
pks := simtestutil.CreateTestPubKeys(6)
tstaking := teststaking.NewHelper(s.T(), ctx, s.stakingKeeper)
tstaking := stakingtestutil.NewHelper(s.T(), ctx, s.stakingKeeper)
// create max (5) validators all with the same power
for i := uint32(0); i < p.MaxValidators; i++ {
@@ -153,7 +148,7 @@ func (s *KeeperTestSuite) TestHandleNewValidator() {
valAddrs := simtestutil.ConvertAddrsToValAddrs(addrDels)
pks := simtestutil.CreateTestPubKeys(1)
addr, val := valAddrs[0], pks[0]
tstaking := teststaking.NewHelper(s.T(), ctx, s.stakingKeeper)
tstaking := stakingtestutil.NewHelper(s.T(), ctx, s.stakingKeeper)
ctx = ctx.WithBlockHeight(s.slashingKeeper.SignedBlocksWindow(ctx) + 1)
// Validator created
@@ -192,7 +187,6 @@ func (s *KeeperTestSuite) TestHandleNewValidator() {
// Ensure that they're only slashed once
func (s *KeeperTestSuite) TestHandleAlreadyJailed() {
// initial setup
ctx := s.ctx
addrDels := simtestutil.AddTestAddrsIncremental(s.bankKeeper, s.stakingKeeper, ctx, 1, s.stakingKeeper.TokensFromConsensusPower(ctx, 200))
@@ -200,7 +194,7 @@ func (s *KeeperTestSuite) TestHandleAlreadyJailed() {
pks := simtestutil.CreateTestPubKeys(1)
addr, val := valAddrs[0], pks[0]
power := int64(100)
tstaking := teststaking.NewHelper(s.T(), ctx, s.stakingKeeper)
tstaking := stakingtestutil.NewHelper(s.T(), ctx, s.stakingKeeper)
amt := tstaking.CreateValidatorWithValPower(addr, val, power, true)
@@ -244,11 +238,7 @@ func (s *KeeperTestSuite) TestHandleAlreadyJailed() {
// the start height of the signing info is reset correctly
func (s *KeeperTestSuite) TestValidatorDippingInAndOut() {
// initial setup
// TestParams set the SignedBlocksWindow to 1000 and MaxMissedBlocksPerWindow to 500
ctx := s.ctx
s.slashingKeeper.SetParams(ctx, testslashing.TestParams())
params := s.stakingKeeper.GetParams(ctx)
params.MaxValidators = 1
s.stakingKeeper.SetParams(ctx, params)
@@ -259,7 +249,7 @@ func (s *KeeperTestSuite) TestValidatorDippingInAndOut() {
addr, val := pks[0].Address(), pks[0]
consAddr := sdk.ConsAddress(addr)
tstaking := teststaking.NewHelper(s.T(), ctx, s.stakingKeeper)
tstaking := stakingtestutil.NewHelper(s.T(), ctx, s.stakingKeeper)
valAddr := sdk.ValAddress(addr)
tstaking.CreateValidatorWithValPower(valAddr, val, power, true)
@@ -15,7 +15,7 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/staking/keeper"
"github.com/cosmos/cosmos-sdk/x/staking/teststaking"
"github.com/cosmos/cosmos-sdk/x/staking/testutil"
"github.com/cosmos/cosmos-sdk/x/staking/types"
)
@@ -67,8 +67,8 @@ func createValidators(t *testing.T, ctx sdk.Context, app *simapp.SimApp, powers
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
val1 := teststaking.NewValidator(t, valAddrs[0], pks[0])
val2 := teststaking.NewValidator(t, valAddrs[1], pks[1])
val1 := testutil.NewValidator(t, valAddrs[0], pks[0])
val2 := testutil.NewValidator(t, valAddrs[1], pks[1])
vals := []types.Validator{val1, val2}
app.StakingKeeper.SetValidator(ctx, val1)
@@ -10,9 +10,9 @@ import (
"cosmossdk.io/simapp"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank/testutil"
banktestutil "github.com/cosmos/cosmos-sdk/x/bank/testutil"
"github.com/cosmos/cosmos-sdk/x/staking/keeper"
"github.com/cosmos/cosmos-sdk/x/staking/teststaking"
"github.com/cosmos/cosmos-sdk/x/staking/testutil"
"github.com/cosmos/cosmos-sdk/x/staking/types"
)
@@ -27,11 +27,11 @@ func TestUnbondingDelegationsMaxEntries(t *testing.T) {
bondDenom := app.StakingKeeper.BondDenom(ctx)
notBondedPool := app.StakingKeeper.GetNotBondedPool(ctx)
require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(bondDenom, startTokens))))
require.NoError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(bondDenom, startTokens))))
app.AccountKeeper.SetModuleAccount(ctx, notBondedPool)
// create a validator and a delegator to that validator
validator := teststaking.NewValidator(t, addrVals[0], PKs[0])
validator := testutil.NewValidator(t, addrVals[0], PKs[0])
validator, issuedShares := validator.AddTokensFromDel(startTokens)
require.Equal(t, startTokens, issuedShares.RoundInt())
@@ -3,7 +3,6 @@ package keeper_test
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
@@ -54,23 +53,6 @@ func (suite *IntegrationTestSuite) SetupTest() {
suite.app, suite.ctx, suite.queryClient, suite.addrs, suite.vals = app, ctx, queryClient, addrs, validators
}
func TestParams(t *testing.T) {
app := simapp.Setup(t, false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
expParams := types.DefaultParams()
// check that the empty keeper loads the default
resParams := app.StakingKeeper.GetParams(ctx)
require.True(t, expParams.Equal(resParams))
// modify a params, save, and retrieve
expParams.MaxValidators = 777
app.StakingKeeper.SetParams(ctx, expParams)
resParams = app.StakingKeeper.GetParams(ctx)
require.True(t, expParams.Equal(resParams))
}
func TestIntegrationTestSuite(t *testing.T) {
suite.Run(t, new(IntegrationTestSuite))
}
@@ -0,0 +1,27 @@
package keeper
import (
"testing"
"cosmossdk.io/simapp"
"github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/stretchr/testify/require"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)
func TestParams(t *testing.T) {
app := simapp.Setup(t, false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
expParams := types.DefaultParams()
// check that the empty keeper loads the default
resParams := app.StakingKeeper.GetParams(ctx)
require.True(t, expParams.Equal(resParams))
// modify a params, save, and retrieve
expParams.MaxValidators = 777
app.StakingKeeper.SetParams(ctx, expParams)
resParams = app.StakingKeeper.GetParams(ctx)
require.True(t, expParams.Equal(resParams))
}
@@ -11,9 +11,9 @@ import (
"cosmossdk.io/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank/testutil"
banktestutil "github.com/cosmos/cosmos-sdk/x/bank/testutil"
"github.com/cosmos/cosmos-sdk/x/staking/keeper"
"github.com/cosmos/cosmos-sdk/x/staking/teststaking"
"github.com/cosmos/cosmos-sdk/x/staking/testutil"
"github.com/cosmos/cosmos-sdk/x/staking/types"
)
@@ -27,7 +27,7 @@ func bootstrapSlashTest(t *testing.T, power int64) (*simapp.SimApp, sdk.Context,
totalSupply := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), amt.MulRaw(int64(len(addrDels)))))
notBondedPool := app.StakingKeeper.GetNotBondedPool(ctx)
require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), totalSupply))
require.NoError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), totalSupply))
app.AccountKeeper.SetModuleAccount(ctx, notBondedPool)
@@ -37,10 +37,10 @@ func bootstrapSlashTest(t *testing.T, power int64) (*simapp.SimApp, sdk.Context,
// set bonded pool balance
app.AccountKeeper.SetModuleAccount(ctx, bondedPool)
require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), bondedCoins))
require.NoError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), bondedCoins))
for i := int64(0); i < numVals; i++ {
validator := teststaking.NewValidator(t, addrVals[i], PKs[i])
validator := testutil.NewValidator(t, addrVals[i], PKs[i])
validator, _ = validator.AddTokensFromDel(amt)
validator = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validator, true)
app.StakingKeeper.SetValidatorByConsAddr(ctx, validator)
@@ -103,7 +103,7 @@ func TestSlashRedelegation(t *testing.T) {
bondedPool := app.StakingKeeper.GetBondedPool(ctx)
balances := app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress())
require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), startCoins))
require.NoError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), startCoins))
app.AccountKeeper.SetModuleAccount(ctx, bondedPool)
// set a redelegation with an expiration timestamp beyond which the
@@ -370,7 +370,7 @@ func TestSlashWithRedelegation(t *testing.T) {
notBondedPool := app.StakingKeeper.GetNotBondedPool(ctx)
rdCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, rdTokens.MulRaw(2)))
require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), rdCoins))
require.NoError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), rdCoins))
app.AccountKeeper.SetModuleAccount(ctx, bondedPool)
@@ -531,8 +531,8 @@ func TestSlashBoth(t *testing.T) {
bondedPool := app.StakingKeeper.GetBondedPool(ctx)
notBondedPool := app.StakingKeeper.GetNotBondedPool(ctx)
require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), bondedCoins))
require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), notBondedCoins))
require.NoError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), bondedCoins))
require.NoError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), notBondedCoins))
app.AccountKeeper.SetModuleAccount(ctx, bondedPool)
app.AccountKeeper.SetModuleAccount(ctx, notBondedPool)
@@ -13,10 +13,10 @@ import (
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank/testutil"
banktestutil "github.com/cosmos/cosmos-sdk/x/bank/testutil"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/cosmos/cosmos-sdk/x/staking/keeper"
"github.com/cosmos/cosmos-sdk/x/staking/teststaking"
"github.com/cosmos/cosmos-sdk/x/staking/testutil"
"github.com/cosmos/cosmos-sdk/x/staking/types"
)
@@ -38,7 +38,7 @@ func bootstrapValidatorTest(t testing.TB, power int64, numAddrs int) (*simapp.Si
// set bonded pool supply
app.AccountKeeper.SetModuleAccount(ctx, notBondedPool)
require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), totalSupply))
require.NoError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), totalSupply))
// unbond genesis validator delegations
delegations := app.StakingKeeper.GetAllDelegations(ctx)
@@ -60,7 +60,7 @@ func initValidators(t testing.TB, power int64, numAddrs int, powers []int64) (*s
vs := make([]types.Validator, len(powers))
for i, power := range powers {
vs[i] = teststaking.NewValidator(t, sdk.ValAddress(addrs[i]), pks[i])
vs[i] = testutil.NewValidator(t, sdk.ValAddress(addrs[i]), pks[i])
tokens := app.StakingKeeper.TokensFromConsensusPower(ctx, power)
vs[i], _ = vs[i].AddTokensFromDel(tokens)
}
@@ -83,8 +83,8 @@ func TestUpdateBondedValidatorsDecreaseCliff(t *testing.T) {
app.StakingKeeper.SetParams(ctx, params)
// create a random pool
require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), app.StakingKeeper.TokensFromConsensusPower(ctx, 1234)))))
require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), app.StakingKeeper.TokensFromConsensusPower(ctx, 10000)))))
require.NoError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), app.StakingKeeper.TokensFromConsensusPower(ctx, 1234)))))
require.NoError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), app.StakingKeeper.TokensFromConsensusPower(ctx, 10000)))))
app.AccountKeeper.SetModuleAccount(ctx, bondedPool)
app.AccountKeeper.SetModuleAccount(ctx, notBondedPool)
@@ -133,12 +133,12 @@ func TestSlashToZeroPowerRemoved(t *testing.T) {
app, ctx, _, addrVals := bootstrapValidatorTest(t, 100, 20)
// add a validator
validator := teststaking.NewValidator(t, addrVals[0], PKs[0])
validator := testutil.NewValidator(t, addrVals[0], PKs[0])
valTokens := app.StakingKeeper.TokensFromConsensusPower(ctx, 100)
bondedPool := app.StakingKeeper.GetBondedPool(ctx)
require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), valTokens))))
require.NoError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), valTokens))))
app.AccountKeeper.SetModuleAccount(ctx, bondedPool)
@@ -173,7 +173,7 @@ func TestGetValidatorSortingUnmixed(t *testing.T) {
n := len(amts)
var validators [5]types.Validator
for i, amt := range amts {
validators[i] = teststaking.NewValidator(t, sdk.ValAddress(addrs[i]), PKs[i])
validators[i] = testutil.NewValidator(t, sdk.ValAddress(addrs[i]), PKs[i])
validators[i].Status = types.Bonded
validators[i].Tokens = amt
validators[i].DelegatorShares = sdk.NewDecFromInt(amt)
@@ -245,8 +245,8 @@ func TestGetValidatorSortingMixed(t *testing.T) {
bondedPool := app.StakingKeeper.GetBondedPool(ctx)
notBondedPool := app.StakingKeeper.GetNotBondedPool(ctx)
require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), app.StakingKeeper.TokensFromConsensusPower(ctx, 501)))))
require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), app.StakingKeeper.TokensFromConsensusPower(ctx, 0)))))
require.NoError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), app.StakingKeeper.TokensFromConsensusPower(ctx, 501)))))
require.NoError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), app.StakingKeeper.TokensFromConsensusPower(ctx, 0)))))
app.AccountKeeper.SetModuleAccount(ctx, notBondedPool)
app.AccountKeeper.SetModuleAccount(ctx, bondedPool)
@@ -267,7 +267,7 @@ func TestGetValidatorSortingMixed(t *testing.T) {
var validators [5]types.Validator
for i, amt := range amts {
validators[i] = teststaking.NewValidator(t, sdk.ValAddress(addrs[i]), PKs[i])
validators[i] = testutil.NewValidator(t, sdk.ValAddress(addrs[i]), PKs[i])
validators[i].DelegatorShares = sdk.NewDecFromInt(amt)
validators[i].Status = types.Bonded
validators[i].Tokens = amt
@@ -321,7 +321,7 @@ func TestGetValidatorsEdgeCases(t *testing.T) {
validators[i], _ = validators[i].AddTokensFromDel(tokens)
notBondedPool := app.StakingKeeper.GetNotBondedPool(ctx)
require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(params.BondDenom, tokens))))
require.NoError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(params.BondDenom, tokens))))
app.AccountKeeper.SetModuleAccount(ctx, notBondedPool)
validators[i] = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validators[i], true)
}
@@ -340,7 +340,7 @@ func TestGetValidatorsEdgeCases(t *testing.T) {
newTokens := sdk.NewCoins()
require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), newTokens))
require.NoError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), newTokens))
app.AccountKeeper.SetModuleAccount(ctx, notBondedPool)
// test that the two largest validators are
@@ -372,7 +372,7 @@ func TestGetValidatorsEdgeCases(t *testing.T) {
notBondedPool = app.StakingKeeper.GetNotBondedPool(ctx)
newTokens = sdk.NewCoins(sdk.NewCoin(params.BondDenom, app.StakingKeeper.TokensFromConsensusPower(ctx, 1)))
require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), newTokens))
require.NoError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), newTokens))
app.AccountKeeper.SetModuleAccount(ctx, notBondedPool)
validators[3] = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validators[3], true)
@@ -387,7 +387,7 @@ func TestGetValidatorsEdgeCases(t *testing.T) {
validators[3], _ = validators[3].RemoveDelShares(math.LegacyNewDec(201))
bondedPool := app.StakingKeeper.GetBondedPool(ctx)
require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(params.BondDenom, rmTokens))))
require.NoError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(params.BondDenom, rmTokens))))
app.AccountKeeper.SetModuleAccount(ctx, bondedPool)
validators[3] = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validators[3], true)
@@ -401,7 +401,7 @@ func TestGetValidatorsEdgeCases(t *testing.T) {
validators[3], _ = validators[3].AddTokensFromDel(sdk.NewInt(200))
notBondedPool = app.StakingKeeper.GetNotBondedPool(ctx)
require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(params.BondDenom, sdk.NewInt(200)))))
require.NoError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(params.BondDenom, sdk.NewInt(200)))))
app.AccountKeeper.SetModuleAccount(ctx, notBondedPool)
validators[3] = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validators[3], true)
@@ -423,9 +423,9 @@ func TestValidatorBondHeight(t *testing.T) {
// initialize some validators into the state
var validators [3]types.Validator
validators[0] = teststaking.NewValidator(t, sdk.ValAddress(PKs[0].Address().Bytes()), PKs[0])
validators[1] = teststaking.NewValidator(t, sdk.ValAddress(addrs[1]), PKs[1])
validators[2] = teststaking.NewValidator(t, sdk.ValAddress(addrs[2]), PKs[2])
validators[0] = testutil.NewValidator(t, sdk.ValAddress(PKs[0].Address().Bytes()), PKs[0])
validators[1] = testutil.NewValidator(t, sdk.ValAddress(addrs[1]), PKs[1])
validators[2] = testutil.NewValidator(t, sdk.ValAddress(addrs[2]), PKs[2])
tokens0 := app.StakingKeeper.TokensFromConsensusPower(ctx, 200)
tokens1 := app.StakingKeeper.TokensFromConsensusPower(ctx, 100)
@@ -471,7 +471,7 @@ func TestFullValidatorSetPowerChange(t *testing.T) {
powers := []int64{0, 100, 400, 400, 200}
var validators [5]types.Validator
for i, power := range powers {
validators[i] = teststaking.NewValidator(t, sdk.ValAddress(addrs[i]), PKs[i])
validators[i] = testutil.NewValidator(t, sdk.ValAddress(addrs[i]), PKs[i])
tokens := app.StakingKeeper.TokensFromConsensusPower(ctx, power)
validators[i], _ = validators[i].AddTokensFromDel(tokens)
keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validators[i], true)
@@ -511,7 +511,7 @@ func TestApplyAndReturnValidatorSetUpdatesAllNone(t *testing.T) {
valPubKey := PKs[i+1]
valAddr := sdk.ValAddress(valPubKey.Address().Bytes())
validators[i] = teststaking.NewValidator(t, valAddr, valPubKey)
validators[i] = testutil.NewValidator(t, valAddr, valPubKey)
tokens := app.StakingKeeper.TokensFromConsensusPower(ctx, power)
validators[i], _ = validators[i].AddTokensFromDel(tokens)
}
@@ -537,7 +537,7 @@ func TestApplyAndReturnValidatorSetUpdatesIdentical(t *testing.T) {
powers := []int64{10, 20}
var validators [2]types.Validator
for i, power := range powers {
validators[i] = teststaking.NewValidator(t, sdk.ValAddress(addrs[i]), PKs[i])
validators[i] = testutil.NewValidator(t, sdk.ValAddress(addrs[i]), PKs[i])
tokens := app.StakingKeeper.TokensFromConsensusPower(ctx, power)
validators[i], _ = validators[i].AddTokensFromDel(tokens)
@@ -560,7 +560,7 @@ func TestApplyAndReturnValidatorSetUpdatesSingleValueChange(t *testing.T) {
powers := []int64{10, 20}
var validators [2]types.Validator
for i, power := range powers {
validators[i] = teststaking.NewValidator(t, sdk.ValAddress(addrs[i]), PKs[i])
validators[i] = testutil.NewValidator(t, sdk.ValAddress(addrs[i]), PKs[i])
tokens := app.StakingKeeper.TokensFromConsensusPower(ctx, power)
validators[i], _ = validators[i].AddTokensFromDel(tokens)
@@ -645,7 +645,7 @@ func TestApplyAndReturnValidatorSetUpdatesWithCliffValidator(t *testing.T) {
powers := []int64{10, 20, 5}
var validators [5]types.Validator
for i, power := range powers {
validators[i] = teststaking.NewValidator(t, sdk.ValAddress(addrs[i]), PKs[i])
validators[i] = testutil.NewValidator(t, sdk.ValAddress(addrs[i]), PKs[i])
tokens := app.StakingKeeper.TokensFromConsensusPower(ctx, power)
validators[i], _ = validators[i].AddTokensFromDel(tokens)
}
@@ -687,7 +687,7 @@ func TestApplyAndReturnValidatorSetUpdatesNewValidator(t *testing.T) {
valPubKey := PKs[i+1]
valAddr := sdk.ValAddress(valPubKey.Address().Bytes())
validators[i] = teststaking.NewValidator(t, valAddr, valPubKey)
validators[i] = testutil.NewValidator(t, valAddr, valPubKey)
tokens := app.StakingKeeper.TokensFromConsensusPower(ctx, power)
validators[i], _ = validators[i].AddTokensFromDel(tokens)
@@ -721,7 +721,7 @@ func TestApplyAndReturnValidatorSetUpdatesNewValidator(t *testing.T) {
valAddr := sdk.ValAddress(valPubKey.Address().Bytes())
amt := sdk.NewInt(100)
validator := teststaking.NewValidator(t, valAddr, valPubKey)
validator := testutil.NewValidator(t, valAddr, valPubKey)
validator, _ = validator.AddTokensFromDel(amt)
app.StakingKeeper.SetValidator(ctx, validator)
@@ -734,7 +734,7 @@ func TestApplyAndReturnValidatorSetUpdatesNewValidator(t *testing.T) {
valPubKey = PKs[len(validators)+2]
valAddr = sdk.ValAddress(valPubKey.Address().Bytes())
validator = teststaking.NewValidator(t, valAddr, valPubKey)
validator = testutil.NewValidator(t, valAddr, valPubKey)
tokens := app.StakingKeeper.TokensFromConsensusPower(ctx, 500)
validator, _ = validator.AddTokensFromDel(tokens)
app.StakingKeeper.SetValidator(ctx, validator)