2020-03-02 06:52:43 -08:00
|
|
|
package keeper_test
|
|
|
|
|
2020-03-02 07:04:49 -08:00
|
|
|
import (
|
2020-10-23 05:07:52 -07:00
|
|
|
"testing"
|
|
|
|
|
2020-03-02 07:38:24 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/simapp"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2020-03-02 07:04:49 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
2020-03-02 12:07:51 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/staking"
|
2020-06-12 07:54:37 -07:00
|
|
|
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
|
|
|
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
2020-10-23 05:07:52 -07:00
|
|
|
"github.com/stretchr/testify/require"
|
2020-03-02 07:04:49 -08:00
|
|
|
)
|
2020-03-02 06:52:43 -08:00
|
|
|
|
|
|
|
var (
|
|
|
|
TestProposal = types.NewTextProposal("Test", "description")
|
|
|
|
)
|
2020-03-02 07:04:49 -08:00
|
|
|
|
2020-10-23 05:07:52 -07:00
|
|
|
func createValidators(t *testing.T, ctx sdk.Context, app *simapp.SimApp, powers []int64) ([]sdk.AccAddress, []sdk.ValAddress) {
|
2020-03-02 09:08:40 -08:00
|
|
|
addrs := simapp.AddTestAddrsIncremental(app, ctx, 5, sdk.NewInt(30000000))
|
2020-03-02 07:38:24 -08:00
|
|
|
valAddrs := simapp.ConvertAddrsToValAddrs(addrs)
|
2020-03-02 09:08:40 -08:00
|
|
|
pks := simapp.CreateTestPubKeys(5)
|
2020-03-02 07:38:24 -08:00
|
|
|
|
2020-05-05 07:28:20 -07:00
|
|
|
appCodec, _ := simapp.MakeCodecs()
|
2020-06-12 07:54:37 -07:00
|
|
|
app.StakingKeeper = stakingkeeper.NewKeeper(
|
2020-03-02 07:38:24 -08:00
|
|
|
appCodec,
|
2020-06-12 07:54:37 -07:00
|
|
|
app.GetKey(stakingtypes.StoreKey),
|
2020-04-20 12:32:10 -07:00
|
|
|
app.AccountKeeper,
|
2020-03-02 07:38:24 -08:00
|
|
|
app.BankKeeper,
|
2020-06-12 07:54:37 -07:00
|
|
|
app.GetSubspace(stakingtypes.ModuleName),
|
2020-03-02 07:38:24 -08:00
|
|
|
)
|
|
|
|
|
2020-10-23 05:07:52 -07:00
|
|
|
val1, err := stakingtypes.NewValidator(valAddrs[0], pks[0], stakingtypes.Description{})
|
|
|
|
require.NoError(t, err)
|
|
|
|
val2, err := stakingtypes.NewValidator(valAddrs[1], pks[1], stakingtypes.Description{})
|
|
|
|
require.NoError(t, err)
|
|
|
|
val3, err := stakingtypes.NewValidator(valAddrs[2], pks[2], stakingtypes.Description{})
|
|
|
|
require.NoError(t, err)
|
2020-03-02 07:38:24 -08:00
|
|
|
|
|
|
|
app.StakingKeeper.SetValidator(ctx, val1)
|
|
|
|
app.StakingKeeper.SetValidator(ctx, val2)
|
|
|
|
app.StakingKeeper.SetValidator(ctx, val3)
|
|
|
|
app.StakingKeeper.SetValidatorByConsAddr(ctx, val1)
|
|
|
|
app.StakingKeeper.SetValidatorByConsAddr(ctx, val2)
|
|
|
|
app.StakingKeeper.SetValidatorByConsAddr(ctx, val3)
|
|
|
|
app.StakingKeeper.SetNewValidatorByPowerIndex(ctx, val1)
|
|
|
|
app.StakingKeeper.SetNewValidatorByPowerIndex(ctx, val2)
|
|
|
|
app.StakingKeeper.SetNewValidatorByPowerIndex(ctx, val3)
|
|
|
|
|
2020-10-12 06:56:02 -07:00
|
|
|
_, _ = app.StakingKeeper.Delegate(ctx, addrs[0], sdk.TokensFromConsensusPower(powers[0]), stakingtypes.Unbonded, val1, true)
|
|
|
|
_, _ = app.StakingKeeper.Delegate(ctx, addrs[1], sdk.TokensFromConsensusPower(powers[1]), stakingtypes.Unbonded, val2, true)
|
|
|
|
_, _ = app.StakingKeeper.Delegate(ctx, addrs[2], sdk.TokensFromConsensusPower(powers[2]), stakingtypes.Unbonded, val3, true)
|
2020-03-02 07:38:24 -08:00
|
|
|
|
|
|
|
_ = staking.EndBlocker(ctx, app.StakingKeeper)
|
2020-03-02 07:47:06 -08:00
|
|
|
|
|
|
|
return addrs, valAddrs
|
2020-03-02 07:38:24 -08:00
|
|
|
}
|