78 lines
2.9 KiB
Go
78 lines
2.9 KiB
Go
package keeper_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/cosmos/cosmos-sdk/simapp"
|
|
"github.com/cosmos/cosmos-sdk/testutil/testdata"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2"
|
|
"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 (
|
|
_, _, addr = testdata.KeyTestPubAddr()
|
|
govAcct = authtypes.NewModuleAddress(types.ModuleName)
|
|
TestProposal = getTestProposal()
|
|
)
|
|
|
|
func getTestProposal() []sdk.Msg {
|
|
legacyProposalMsg, err := v1beta2.NewLegacyContent(v1beta1.NewTextProposal("Title", "description"), authtypes.NewModuleAddress(types.ModuleName).String())
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
return []sdk.Msg{
|
|
banktypes.NewMsgSend(govAcct, addr, sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(1000)))),
|
|
legacyProposalMsg,
|
|
}
|
|
}
|
|
|
|
func createValidators(t *testing.T, ctx sdk.Context, app *simapp.SimApp, powers []int64) ([]sdk.AccAddress, []sdk.ValAddress) {
|
|
addrs := simapp.AddTestAddrsIncremental(app, ctx, 5, sdk.NewInt(30000000))
|
|
valAddrs := simapp.ConvertAddrsToValAddrs(addrs)
|
|
pks := simapp.CreateTestPubKeys(5)
|
|
cdc := simapp.MakeTestEncodingConfig().Codec
|
|
|
|
app.StakingKeeper = stakingkeeper.NewKeeper(
|
|
cdc,
|
|
app.GetKey(stakingtypes.StoreKey),
|
|
app.AccountKeeper,
|
|
app.BankKeeper,
|
|
app.GetSubspace(stakingtypes.ModuleName),
|
|
)
|
|
|
|
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)
|
|
|
|
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)
|
|
|
|
_, _ = app.StakingKeeper.Delegate(ctx, addrs[0], app.StakingKeeper.TokensFromConsensusPower(ctx, powers[0]), stakingtypes.Unbonded, val1, true)
|
|
_, _ = app.StakingKeeper.Delegate(ctx, addrs[1], app.StakingKeeper.TokensFromConsensusPower(ctx, powers[1]), stakingtypes.Unbonded, val2, true)
|
|
_, _ = app.StakingKeeper.Delegate(ctx, addrs[2], app.StakingKeeper.TokensFromConsensusPower(ctx, powers[2]), stakingtypes.Unbonded, val3, true)
|
|
|
|
_ = staking.EndBlocker(ctx, app.StakingKeeper)
|
|
|
|
return addrs, valAddrs
|
|
}
|