refactor(x/staking)!: KVStoreService, return errors and use context.Context (#16324)
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
This commit is contained in:
co-authored by
Aleksandr Bezobchuk
parent
c44957890a
commit
1be7d9805e
@@ -95,12 +95,14 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
"delayed vesting has vested, multiple delegations less than the total account balance",
|
||||
func(ctx sdk.Context, validator stakingtypes.Validator, delegatorAddr sdk.AccAddress) {
|
||||
baseAccount := createBaseAccount(delegatorAddr)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(stakingKeeper.BondDenom(ctx), sdkmath.NewInt(200)))
|
||||
bondDenom, err := stakingKeeper.BondDenom(ctx)
|
||||
require.NoError(t, err)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, sdkmath.NewInt(200)))
|
||||
delayedAccount := types.NewDelayedVestingAccount(baseAccount, vestedCoins, ctx.BlockTime().Unix())
|
||||
|
||||
ctx = ctx.WithBlockTime(ctx.BlockTime().AddDate(1, 0, 0))
|
||||
|
||||
err := accountKeeper.Params.Set(ctx, authtypes.DefaultParams())
|
||||
err = accountKeeper.Params.Set(ctx, authtypes.DefaultParams())
|
||||
require.NoError(t, err)
|
||||
|
||||
accountKeeper.SetAccount(ctx, delayedAccount)
|
||||
@@ -121,9 +123,10 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
{
|
||||
"delayed vesting has vested, single delegations which exceed the vested amount",
|
||||
func(ctx sdk.Context, validator stakingtypes.Validator, delegatorAddr sdk.AccAddress) {
|
||||
bondDenom, err := stakingKeeper.BondDenom(ctx)
|
||||
require.NoError(t, err)
|
||||
baseAccount := createBaseAccount(delegatorAddr)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(stakingKeeper.BondDenom(ctx), sdkmath.NewInt(200)))
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, sdkmath.NewInt(200)))
|
||||
delayedAccount := types.NewDelayedVestingAccount(baseAccount, vestedCoins, ctx.BlockTime().Unix())
|
||||
|
||||
ctx = ctx.WithBlockTime(ctx.BlockTime().AddDate(1, 0, 0))
|
||||
@@ -143,7 +146,9 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
"delayed vesting has vested, multiple delegations which exceed the vested amount",
|
||||
func(ctx sdk.Context, validator stakingtypes.Validator, delegatorAddr sdk.AccAddress) {
|
||||
baseAccount := createBaseAccount(delegatorAddr)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(stakingKeeper.BondDenom(ctx), sdkmath.NewInt(200)))
|
||||
bondDenom, err := stakingKeeper.BondDenom(ctx)
|
||||
require.NoError(t, err)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, sdkmath.NewInt(200)))
|
||||
delayedAccount := types.NewDelayedVestingAccount(baseAccount, vestedCoins, ctx.BlockTime().Unix())
|
||||
|
||||
ctx = ctx.WithBlockTime(ctx.BlockTime().AddDate(1, 0, 0))
|
||||
@@ -167,7 +172,9 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
"delayed vesting has not vested, single delegations which exceed the vested amount",
|
||||
func(ctx sdk.Context, validator stakingtypes.Validator, delegatorAddr sdk.AccAddress) {
|
||||
baseAccount := createBaseAccount(delegatorAddr)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(stakingKeeper.BondDenom(ctx), sdkmath.NewInt(200)))
|
||||
bondDenom, err := stakingKeeper.BondDenom(ctx)
|
||||
require.NoError(t, err)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, sdkmath.NewInt(200)))
|
||||
delayedAccount := types.NewDelayedVestingAccount(baseAccount, vestedCoins, ctx.BlockTime().AddDate(1, 0, 0).Unix())
|
||||
|
||||
accountKeeper.SetAccount(ctx, delayedAccount)
|
||||
@@ -185,7 +192,9 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
"delayed vesting has not vested, multiple delegations which exceed the vested amount",
|
||||
func(ctx sdk.Context, validator stakingtypes.Validator, delegatorAddr sdk.AccAddress) {
|
||||
baseAccount := createBaseAccount(delegatorAddr)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(stakingKeeper.BondDenom(ctx), sdkmath.NewInt(200)))
|
||||
bondDenom, err := stakingKeeper.BondDenom(ctx)
|
||||
require.NoError(t, err)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, sdkmath.NewInt(200)))
|
||||
delayedAccount := types.NewDelayedVestingAccount(baseAccount, vestedCoins, ctx.BlockTime().AddDate(1, 0, 0).Unix())
|
||||
|
||||
accountKeeper.SetAccount(ctx, delayedAccount)
|
||||
@@ -207,7 +216,9 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
"not end time",
|
||||
func(ctx sdk.Context, validator stakingtypes.Validator, delegatorAddr sdk.AccAddress) {
|
||||
baseAccount := createBaseAccount(delegatorAddr)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(stakingKeeper.BondDenom(ctx), sdkmath.NewInt(300)))
|
||||
bondDenom, err := stakingKeeper.BondDenom(ctx)
|
||||
require.NoError(t, err)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, sdkmath.NewInt(300)))
|
||||
delayedAccount := types.NewDelayedVestingAccount(baseAccount, vestedCoins, ctx.BlockTime().AddDate(1, 0, 0).Unix())
|
||||
|
||||
accountKeeper.SetAccount(ctx, delayedAccount)
|
||||
@@ -229,7 +240,9 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
"delayed vesting has not vested, single delegation greater than the total account balance",
|
||||
func(ctx sdk.Context, validator stakingtypes.Validator, delegatorAddr sdk.AccAddress) {
|
||||
baseAccount := createBaseAccount(delegatorAddr)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(stakingKeeper.BondDenom(ctx), sdkmath.NewInt(300)))
|
||||
bondDenom, err := stakingKeeper.BondDenom(ctx)
|
||||
require.NoError(t, err)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, sdkmath.NewInt(300)))
|
||||
delayedAccount := types.NewDelayedVestingAccount(baseAccount, vestedCoins, ctx.BlockTime().AddDate(1, 0, 0).Unix())
|
||||
|
||||
accountKeeper.SetAccount(ctx, delayedAccount)
|
||||
@@ -247,7 +260,9 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
"delayed vesting has vested, single delegation greater than the total account balance",
|
||||
func(ctx sdk.Context, validator stakingtypes.Validator, delegatorAddr sdk.AccAddress) {
|
||||
baseAccount := createBaseAccount(delegatorAddr)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(stakingKeeper.BondDenom(ctx), sdkmath.NewInt(300)))
|
||||
bondDenom, err := stakingKeeper.BondDenom(ctx)
|
||||
require.NoError(t, err)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, sdkmath.NewInt(300)))
|
||||
delayedAccount := types.NewDelayedVestingAccount(baseAccount, vestedCoins, ctx.BlockTime().Unix())
|
||||
|
||||
ctx = ctx.WithBlockTime(ctx.BlockTime().AddDate(1, 0, 0))
|
||||
@@ -269,7 +284,9 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
startTime := ctx.BlockTime().AddDate(1, 0, 0).Unix()
|
||||
endTime := ctx.BlockTime().AddDate(2, 0, 0).Unix()
|
||||
baseAccount := createBaseAccount(delegatorAddr)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(stakingKeeper.BondDenom(ctx), sdkmath.NewInt(300)))
|
||||
bondDenom, err := stakingKeeper.BondDenom(ctx)
|
||||
require.NoError(t, err)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, sdkmath.NewInt(300)))
|
||||
delayedAccount := types.NewContinuousVestingAccount(baseAccount, vestedCoins, startTime, endTime)
|
||||
|
||||
ctx = ctx.WithBlockTime(ctx.BlockTime().AddDate(1, 0, 0))
|
||||
@@ -291,7 +308,9 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
startTime := ctx.BlockTime().AddDate(-1, 0, 0).Unix()
|
||||
endTime := ctx.BlockTime().AddDate(2, 0, 0).Unix()
|
||||
baseAccount := createBaseAccount(delegatorAddr)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(stakingKeeper.BondDenom(ctx), sdkmath.NewInt(300)))
|
||||
bondDenom, err := stakingKeeper.BondDenom(ctx)
|
||||
require.NoError(t, err)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, sdkmath.NewInt(300)))
|
||||
delayedAccount := types.NewContinuousVestingAccount(baseAccount, vestedCoins, startTime, endTime)
|
||||
|
||||
ctx = ctx.WithBlockTime(ctx.BlockTime().AddDate(1, 0, 0))
|
||||
@@ -313,7 +332,9 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
startTime := ctx.BlockTime().AddDate(-2, 0, 0).Unix()
|
||||
endTime := ctx.BlockTime().AddDate(-1, 0, 0).Unix()
|
||||
baseAccount := createBaseAccount(delegatorAddr)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(stakingKeeper.BondDenom(ctx), sdkmath.NewInt(300)))
|
||||
bondDenom, err := stakingKeeper.BondDenom(ctx)
|
||||
require.NoError(t, err)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, sdkmath.NewInt(300)))
|
||||
delayedAccount := types.NewContinuousVestingAccount(baseAccount, vestedCoins, startTime, endTime)
|
||||
|
||||
ctx = ctx.WithBlockTime(ctx.BlockTime().AddDate(1, 0, 0))
|
||||
@@ -333,7 +354,9 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
"periodic vesting account, yet to be vested, some rewards delegated",
|
||||
func(ctx sdk.Context, validator stakingtypes.Validator, delegatorAddr sdk.AccAddress) {
|
||||
baseAccount := createBaseAccount(delegatorAddr)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(stakingKeeper.BondDenom(ctx), sdkmath.NewInt(100)))
|
||||
bondDenom, err := stakingKeeper.BondDenom(ctx)
|
||||
require.NoError(t, err)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, sdkmath.NewInt(100)))
|
||||
|
||||
start := ctx.BlockTime().Unix() + int64(time.Hour/time.Second)
|
||||
|
||||
@@ -371,19 +394,21 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
*/
|
||||
startTime := int64(1601042400)
|
||||
baseAccount := createBaseAccount(delegatorAddr)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(stakingKeeper.BondDenom(ctx), sdk.NewInt(3666666670000)))
|
||||
bondDenom, err := stakingKeeper.BondDenom(ctx)
|
||||
require.NoError(t, err)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, sdkmath.NewInt(3666666670000)))
|
||||
periods := []types.Period{
|
||||
{
|
||||
Length: 31536000,
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(stakingKeeper.BondDenom(ctx), sdk.NewInt(1833333335000))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(bondDenom, sdk.NewInt(1833333335000))),
|
||||
},
|
||||
{
|
||||
Length: 15638400,
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(stakingKeeper.BondDenom(ctx), sdk.NewInt(916666667500))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(bondDenom, sdk.NewInt(916666667500))),
|
||||
},
|
||||
{
|
||||
Length: 15897600,
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(stakingKeeper.BondDenom(ctx), sdk.NewInt(916666667500))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(bondDenom, sdk.NewInt(916666667500))),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -415,19 +440,21 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
*/
|
||||
startTime := int64(1601042400)
|
||||
baseAccount := createBaseAccount(delegatorAddr)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(stakingKeeper.BondDenom(ctx), sdk.NewInt(3666666670000)))
|
||||
bondDenom, err := stakingKeeper.BondDenom(ctx)
|
||||
require.NoError(t, err)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, sdk.NewInt(3666666670000)))
|
||||
periods := []types.Period{
|
||||
{
|
||||
Length: 31536000,
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(stakingKeeper.BondDenom(ctx), sdk.NewInt(1833333335000))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(bondDenom, sdk.NewInt(1833333335000))),
|
||||
},
|
||||
{
|
||||
Length: 15638400,
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(stakingKeeper.BondDenom(ctx), sdk.NewInt(916666667500))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(bondDenom, sdk.NewInt(916666667500))),
|
||||
},
|
||||
{
|
||||
Length: 15897600,
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(stakingKeeper.BondDenom(ctx), sdk.NewInt(916666667500))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(bondDenom, sdk.NewInt(916666667500))),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -461,19 +488,21 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
*/
|
||||
startTime := int64(1601042400)
|
||||
baseAccount := createBaseAccount(delegatorAddr)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(stakingKeeper.BondDenom(ctx), sdk.NewInt(3666666670000)))
|
||||
bondDenom, err := stakingKeeper.BondDenom(ctx)
|
||||
require.NoError(t, err)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, sdk.NewInt(3666666670000)))
|
||||
periods := []types.Period{
|
||||
{
|
||||
Length: 31536000,
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(stakingKeeper.BondDenom(ctx), sdk.NewInt(1833333335000))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(bondDenom, sdk.NewInt(1833333335000))),
|
||||
},
|
||||
{
|
||||
Length: 15638400,
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(stakingKeeper.BondDenom(ctx), sdk.NewInt(916666667500))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(bondDenom, sdk.NewInt(916666667500))),
|
||||
},
|
||||
{
|
||||
Length: 15897600,
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(stakingKeeper.BondDenom(ctx), sdk.NewInt(916666667500))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(bondDenom, sdk.NewInt(916666667500))),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -507,19 +536,21 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
*/
|
||||
startTime := int64(1601042400)
|
||||
baseAccount := createBaseAccount(delegatorAddr)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(stakingKeeper.BondDenom(ctx), sdk.NewInt(3666666670000)))
|
||||
bondDenom, err := stakingKeeper.BondDenom(ctx)
|
||||
require.NoError(t, err)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, sdk.NewInt(3666666670000)))
|
||||
periods := []types.Period{
|
||||
{
|
||||
Length: 31536000,
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(stakingKeeper.BondDenom(ctx), sdk.NewInt(1833333335000))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(bondDenom, sdk.NewInt(1833333335000))),
|
||||
},
|
||||
{
|
||||
Length: 15638400,
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(stakingKeeper.BondDenom(ctx), sdk.NewInt(916666667500))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(bondDenom, sdk.NewInt(916666667500))),
|
||||
},
|
||||
{
|
||||
Length: 15897600,
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(stakingKeeper.BondDenom(ctx), sdk.NewInt(916666667500))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(bondDenom, sdk.NewInt(916666667500))),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -543,7 +574,9 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
"vesting account has unbonding delegations in place",
|
||||
func(ctx sdk.Context, validator stakingtypes.Validator, delegatorAddr sdk.AccAddress) {
|
||||
baseAccount := createBaseAccount(delegatorAddr)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(stakingKeeper.BondDenom(ctx), sdk.NewInt(300)))
|
||||
bondDenom, err := stakingKeeper.BondDenom(ctx)
|
||||
require.NoError(t, err)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, sdk.NewInt(300)))
|
||||
|
||||
delayedAccount := types.NewDelayedVestingAccount(baseAccount, vestedCoins, ctx.BlockTime().AddDate(10, 0, 0).Unix())
|
||||
|
||||
@@ -572,7 +605,9 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
"vesting account has never delegated anything",
|
||||
func(ctx sdk.Context, validator stakingtypes.Validator, delegatorAddr sdk.AccAddress) {
|
||||
baseAccount := createBaseAccount(delegatorAddr)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(stakingKeeper.BondDenom(ctx), sdk.NewInt(300)))
|
||||
bondDenom, err := stakingKeeper.BondDenom(ctx)
|
||||
require.NoError(t, err)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, sdk.NewInt(300)))
|
||||
|
||||
delayedAccount := types.NewDelayedVestingAccount(baseAccount, vestedCoins, ctx.BlockTime().AddDate(10, 0, 0).Unix())
|
||||
|
||||
@@ -588,7 +623,9 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
"vesting account has no delegation but dirty DelegatedFree and DelegatedVesting fields",
|
||||
func(ctx sdk.Context, validator stakingtypes.Validator, delegatorAddr sdk.AccAddress) {
|
||||
baseAccount := createBaseAccount(delegatorAddr)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(stakingKeeper.BondDenom(ctx), sdk.NewInt(300)))
|
||||
bondDenom, err := stakingKeeper.BondDenom(ctx)
|
||||
require.NoError(t, err)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, sdk.NewInt(300)))
|
||||
|
||||
delayedAccount := types.NewDelayedVestingAccount(baseAccount, vestedCoins, ctx.BlockTime().AddDate(10, 0, 0).Unix())
|
||||
|
||||
@@ -612,8 +649,8 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
delegatorAddr := addrs[0]
|
||||
|
||||
_, valAddr := createValidator(t, ctx, bankKeeper, stakingKeeper, tc.tokenAmount*2)
|
||||
validator, found := stakingKeeper.GetValidator(ctx, valAddr)
|
||||
require.True(t, found)
|
||||
validator, err := stakingKeeper.GetValidator(ctx, valAddr)
|
||||
require.NoError(t, err)
|
||||
|
||||
tc.prepareFunc(ctx, validator, delegatorAddr)
|
||||
|
||||
@@ -633,12 +670,15 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
var expVested sdk.Coins
|
||||
var expFree sdk.Coins
|
||||
|
||||
bondDenom, err := stakingKeeper.BondDenom(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
if tc.expVested != 0 {
|
||||
expVested = sdk.NewCoins(sdk.NewCoin(stakingKeeper.BondDenom(ctx), sdk.NewInt(tc.expVested)))
|
||||
expVested = sdk.NewCoins(sdk.NewCoin(bondDenom, sdk.NewInt(tc.expVested)))
|
||||
}
|
||||
|
||||
if tc.expFree != 0 {
|
||||
expFree = sdk.NewCoins(sdk.NewCoin(stakingKeeper.BondDenom(ctx), sdk.NewInt(tc.expFree)))
|
||||
expFree = sdk.NewCoins(sdk.NewCoin(bondDenom, sdk.NewInt(tc.expFree)))
|
||||
}
|
||||
|
||||
trackingCorrected(
|
||||
|
||||
@@ -96,7 +96,7 @@ func initFixture(t testing.TB) *fixture {
|
||||
log.NewNopLogger(),
|
||||
)
|
||||
|
||||
stakingKeeper := stakingkeeper.NewKeeper(cdc, keys[stakingtypes.StoreKey], accountKeeper, bankKeeper, authority.String())
|
||||
stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), accountKeeper, bankKeeper, authority.String())
|
||||
|
||||
distrKeeper := distrkeeper.NewKeeper(
|
||||
cdc, runtime.NewKVStoreService(keys[distrtypes.StoreKey]), accountKeeper, bankKeeper, stakingKeeper, distrtypes.ModuleName, authority.String(),
|
||||
@@ -245,7 +245,7 @@ func TestMsgWithdrawDelegatorReward(t *testing.T) {
|
||||
ValidatorAddress: f.valAddr.String(),
|
||||
},
|
||||
expErr: true,
|
||||
expErrMsg: "no delegation distribution info",
|
||||
expErrMsg: "no delegation for (address, validator) tuple",
|
||||
},
|
||||
{
|
||||
name: "validator with no delegations",
|
||||
@@ -254,7 +254,7 @@ func TestMsgWithdrawDelegatorReward(t *testing.T) {
|
||||
ValidatorAddress: sdk.ValAddress(sdk.AccAddress(PKS[2].Address())).String(),
|
||||
},
|
||||
expErr: true,
|
||||
expErrMsg: "no validator distribution info",
|
||||
expErrMsg: "validator does not exist",
|
||||
},
|
||||
{
|
||||
name: "valid msg",
|
||||
@@ -891,6 +891,9 @@ func TestMsgDepositValidatorRewardsPool(t *testing.T) {
|
||||
f.bankKeeper.MintCoins(f.sdkCtx, distrtypes.ModuleName, amt)
|
||||
f.bankKeeper.SendCoinsFromModuleToAccount(f.sdkCtx, distrtypes.ModuleName, addr, amt)
|
||||
|
||||
bondDenom, err := f.stakingKeeper.BondDenom(f.sdkCtx)
|
||||
require.NoError(t, err)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
msg *distrtypes.MsgDepositValidatorRewardsPool
|
||||
@@ -902,7 +905,7 @@ func TestMsgDepositValidatorRewardsPool(t *testing.T) {
|
||||
msg: &distrtypes.MsgDepositValidatorRewardsPool{
|
||||
Depositor: addr.String(),
|
||||
ValidatorAddress: valAddr1.String(),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(f.stakingKeeper.BondDenom(f.sdkCtx), sdk.NewInt(100))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(bondDenom, sdk.NewInt(100))),
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -918,7 +921,7 @@ func TestMsgDepositValidatorRewardsPool(t *testing.T) {
|
||||
msg: &distrtypes.MsgDepositValidatorRewardsPool{
|
||||
Depositor: addr.String(),
|
||||
ValidatorAddress: sdk.ValAddress([]byte("addr1_______________")).String(),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(f.stakingKeeper.BondDenom(f.sdkCtx), sdk.NewInt(100))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(bondDenom, sdk.NewInt(100))),
|
||||
},
|
||||
expErr: true,
|
||||
expErrMsg: "validator does not exist",
|
||||
|
||||
@@ -117,7 +117,7 @@ func initFixture(t testing.TB) *fixture {
|
||||
log.NewNopLogger(),
|
||||
)
|
||||
|
||||
stakingKeeper := stakingkeeper.NewKeeper(cdc, keys[stakingtypes.StoreKey], accountKeeper, bankKeeper, authority.String())
|
||||
stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), accountKeeper, bankKeeper, authority.String())
|
||||
|
||||
slashingKeeper := slashingkeeper.NewKeeper(cdc, codec.NewLegacyAmino(), runtime.NewKVStoreService(keys[slashingtypes.StoreKey]), stakingKeeper, authority.String())
|
||||
|
||||
@@ -164,35 +164,40 @@ func TestHandleDoubleSign(t *testing.T) {
|
||||
populateValidators(t, f)
|
||||
|
||||
power := int64(100)
|
||||
stakingParams := f.stakingKeeper.GetParams(ctx)
|
||||
operatorAddr, val := valAddresses[0], pubkeys[0]
|
||||
stakingParams, err := f.stakingKeeper.GetParams(ctx)
|
||||
assert.NilError(t, err)
|
||||
operatorAddr, valpubkey := valAddresses[0], pubkeys[0]
|
||||
tstaking := stakingtestutil.NewHelper(t, ctx, f.stakingKeeper)
|
||||
|
||||
selfDelegation := tstaking.CreateValidatorWithValPower(operatorAddr, val, power, true)
|
||||
selfDelegation := tstaking.CreateValidatorWithValPower(operatorAddr, valpubkey, power, true)
|
||||
|
||||
// execute end-blocker and verify validator attributes
|
||||
_, err := f.stakingKeeper.EndBlocker(f.sdkCtx)
|
||||
_, err = f.stakingKeeper.EndBlocker(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
assert.DeepEqual(t,
|
||||
f.bankKeeper.GetAllBalances(ctx, sdk.AccAddress(operatorAddr)).String(),
|
||||
sdk.NewCoins(sdk.NewCoin(stakingParams.BondDenom, initAmt.Sub(selfDelegation))).String(),
|
||||
)
|
||||
assert.DeepEqual(t, selfDelegation, f.stakingKeeper.Validator(ctx, operatorAddr).GetBondedTokens())
|
||||
val, err := f.stakingKeeper.Validator(ctx, operatorAddr)
|
||||
assert.NilError(t, err)
|
||||
assert.DeepEqual(t, selfDelegation, val.GetBondedTokens())
|
||||
|
||||
assert.NilError(t, f.slashingKeeper.AddPubkey(f.sdkCtx, val))
|
||||
assert.NilError(t, f.slashingKeeper.AddPubkey(f.sdkCtx, valpubkey))
|
||||
|
||||
info := slashingtypes.NewValidatorSigningInfo(sdk.ConsAddress(val.Address()), f.sdkCtx.BlockHeight(), int64(0), time.Unix(0, 0), false, int64(0))
|
||||
f.slashingKeeper.SetValidatorSigningInfo(f.sdkCtx, sdk.ConsAddress(val.Address()), info)
|
||||
info := slashingtypes.NewValidatorSigningInfo(sdk.ConsAddress(valpubkey.Address()), f.sdkCtx.BlockHeight(), int64(0), time.Unix(0, 0), false, int64(0))
|
||||
f.slashingKeeper.SetValidatorSigningInfo(f.sdkCtx, sdk.ConsAddress(valpubkey.Address()), info)
|
||||
|
||||
// handle a signature to set signing info
|
||||
f.slashingKeeper.HandleValidatorSignature(ctx, val.Address(), selfDelegation.Int64(), comet.BlockIDFlagCommit)
|
||||
f.slashingKeeper.HandleValidatorSignature(ctx, valpubkey.Address(), selfDelegation.Int64(), comet.BlockIDFlagCommit)
|
||||
|
||||
// double sign less than max age
|
||||
oldTokens := f.stakingKeeper.Validator(ctx, operatorAddr).GetTokens()
|
||||
val, err = f.stakingKeeper.Validator(ctx, operatorAddr)
|
||||
assert.NilError(t, err)
|
||||
oldTokens := val.GetTokens()
|
||||
|
||||
nci := NewCometInfo(abci.RequestFinalizeBlock{
|
||||
Misbehavior: []abci.Misbehavior{{
|
||||
Validator: abci.Validator{Address: val.Address(), Power: power},
|
||||
Validator: abci.Validator{Address: valpubkey.Address(), Power: power},
|
||||
Type: abci.MisbehaviorType_DUPLICATE_VOTE,
|
||||
Time: time.Now().UTC(),
|
||||
Height: 1,
|
||||
@@ -203,18 +208,22 @@ func TestHandleDoubleSign(t *testing.T) {
|
||||
assert.NilError(t, f.evidenceKeeper.BeginBlocker(ctx.WithCometInfo(nci)))
|
||||
|
||||
// should be jailed and tombstoned
|
||||
assert.Assert(t, f.stakingKeeper.Validator(ctx, operatorAddr).IsJailed())
|
||||
assert.Assert(t, f.slashingKeeper.IsTombstoned(ctx, sdk.ConsAddress(val.Address())))
|
||||
val, err = f.stakingKeeper.Validator(ctx, operatorAddr)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, val.IsJailed())
|
||||
assert.Assert(t, f.slashingKeeper.IsTombstoned(ctx, sdk.ConsAddress(valpubkey.Address())))
|
||||
|
||||
// tokens should be decreased
|
||||
newTokens := f.stakingKeeper.Validator(ctx, operatorAddr).GetTokens()
|
||||
newTokens := val.GetTokens()
|
||||
assert.Assert(t, newTokens.LT(oldTokens))
|
||||
|
||||
// submit duplicate evidence
|
||||
assert.NilError(t, f.evidenceKeeper.BeginBlocker(ctx))
|
||||
|
||||
// tokens should be the same (capped slash)
|
||||
assert.Assert(t, f.stakingKeeper.Validator(ctx, operatorAddr).GetTokens().Equal(newTokens))
|
||||
val, err = f.stakingKeeper.Validator(ctx, operatorAddr)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, val.GetTokens().Equal(newTokens))
|
||||
|
||||
// jump to past the unbonding period
|
||||
ctx = ctx.WithBlockTime(time.Unix(1, 0).Add(stakingParams.UnbondingTime))
|
||||
@@ -247,25 +256,28 @@ func TestHandleDoubleSign_TooOld(t *testing.T) {
|
||||
populateValidators(t, f)
|
||||
|
||||
power := int64(100)
|
||||
stakingParams := f.stakingKeeper.GetParams(ctx)
|
||||
operatorAddr, val := valAddresses[0], pubkeys[0]
|
||||
stakingParams, err := f.stakingKeeper.GetParams(ctx)
|
||||
assert.NilError(t, err)
|
||||
operatorAddr, valpubkey := valAddresses[0], pubkeys[0]
|
||||
|
||||
tstaking := stakingtestutil.NewHelper(t, ctx, f.stakingKeeper)
|
||||
|
||||
amt := tstaking.CreateValidatorWithValPower(operatorAddr, val, power, true)
|
||||
amt := tstaking.CreateValidatorWithValPower(operatorAddr, valpubkey, power, true)
|
||||
|
||||
// execute end-blocker and verify validator attributes
|
||||
_, err := f.stakingKeeper.EndBlocker(f.sdkCtx)
|
||||
_, err = f.stakingKeeper.EndBlocker(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
assert.DeepEqual(t,
|
||||
f.bankKeeper.GetAllBalances(ctx, sdk.AccAddress(operatorAddr)),
|
||||
sdk.NewCoins(sdk.NewCoin(stakingParams.BondDenom, initAmt.Sub(amt))),
|
||||
)
|
||||
assert.DeepEqual(t, amt, f.stakingKeeper.Validator(ctx, operatorAddr).GetBondedTokens())
|
||||
val, err := f.stakingKeeper.Validator(ctx, operatorAddr)
|
||||
assert.NilError(t, err)
|
||||
assert.DeepEqual(t, amt, val.GetBondedTokens())
|
||||
|
||||
nci := NewCometInfo(abci.RequestFinalizeBlock{
|
||||
Misbehavior: []abci.Misbehavior{{
|
||||
Validator: abci.Validator{Address: val.Address(), Power: power},
|
||||
Validator: abci.Validator{Address: valpubkey.Address(), Power: power},
|
||||
Type: abci.MisbehaviorType_DUPLICATE_VOTE,
|
||||
Time: ctx.BlockTime(),
|
||||
Height: 0,
|
||||
@@ -282,8 +294,10 @@ func TestHandleDoubleSign_TooOld(t *testing.T) {
|
||||
|
||||
assert.NilError(t, f.evidenceKeeper.BeginBlocker(ctx))
|
||||
|
||||
assert.Assert(t, f.stakingKeeper.Validator(ctx, operatorAddr).IsJailed() == false)
|
||||
assert.Assert(t, f.slashingKeeper.IsTombstoned(ctx, sdk.ConsAddress(val.Address())) == false)
|
||||
val, err = f.stakingKeeper.Validator(ctx, operatorAddr)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, val.IsJailed() == false)
|
||||
assert.Assert(t, f.slashingKeeper.IsTombstoned(ctx, sdk.ConsAddress(valpubkey.Address())) == false)
|
||||
}
|
||||
|
||||
func populateValidators(t assert.TestingT, f *fixture) {
|
||||
|
||||
@@ -87,7 +87,7 @@ func initFixture(t testing.TB) *fixture {
|
||||
log.NewNopLogger(),
|
||||
)
|
||||
|
||||
stakingKeeper := stakingkeeper.NewKeeper(cdc, keys[stakingtypes.StoreKey], accountKeeper, bankKeeper, authority.String())
|
||||
stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), accountKeeper, bankKeeper, authority.String())
|
||||
|
||||
// set default staking params
|
||||
stakingKeeper.SetParams(newCtx, stakingtypes.DefaultParams())
|
||||
|
||||
@@ -88,7 +88,7 @@ func initFixture(t testing.TB) *fixture {
|
||||
log.NewNopLogger(),
|
||||
)
|
||||
|
||||
stakingKeeper := stakingkeeper.NewKeeper(cdc, keys[stakingtypes.StoreKey], accountKeeper, bankKeeper, authority.String())
|
||||
stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), accountKeeper, bankKeeper, authority.String())
|
||||
|
||||
slashingKeeper := slashingkeeper.NewKeeper(cdc, &codec.LegacyAmino{}, runtime.NewKVStoreService(keys[slashingtypes.StoreKey]), stakingKeeper, authority.String())
|
||||
|
||||
@@ -133,7 +133,8 @@ func TestUnJailNotBonded(t *testing.T) {
|
||||
t.Parallel()
|
||||
f := initFixture(t)
|
||||
|
||||
p := f.stakingKeeper.GetParams(f.ctx)
|
||||
p, err := f.stakingKeeper.GetParams(f.ctx)
|
||||
assert.NilError(t, err)
|
||||
p.MaxValidators = 5
|
||||
f.stakingKeeper.SetParams(f.ctx, p)
|
||||
|
||||
@@ -212,7 +213,7 @@ func TestHandleNewValidator(t *testing.T) {
|
||||
f := initFixture(t)
|
||||
|
||||
pks := simtestutil.CreateTestPubKeys(1)
|
||||
addr, val := f.valAddrs[0], pks[0]
|
||||
addr, valpubkey := f.valAddrs[0], pks[0]
|
||||
tstaking := stakingtestutil.NewHelper(t, f.ctx, f.stakingKeeper)
|
||||
signedBlocksWindow, err := f.slashingKeeper.SignedBlocksWindow(f.ctx)
|
||||
assert.NilError(t, err)
|
||||
@@ -220,27 +221,33 @@ func TestHandleNewValidator(t *testing.T) {
|
||||
|
||||
assert.NilError(t, f.slashingKeeper.AddPubkey(f.ctx, pks[0]))
|
||||
|
||||
info := slashingtypes.NewValidatorSigningInfo(sdk.ConsAddress(val.Address()), f.ctx.BlockHeight(), int64(0), time.Unix(0, 0), false, int64(0))
|
||||
err = f.slashingKeeper.SetValidatorSigningInfo(f.ctx, sdk.ConsAddress(val.Address()), info)
|
||||
assert.NilError(t, err)
|
||||
info := slashingtypes.NewValidatorSigningInfo(sdk.ConsAddress(valpubkey.Address()), f.ctx.BlockHeight(), int64(0), time.Unix(0, 0), false, int64(0))
|
||||
assert.NilError(t, f.slashingKeeper.SetValidatorSigningInfo(f.ctx, sdk.ConsAddress(valpubkey.Address()), info))
|
||||
|
||||
// Validator created
|
||||
amt := tstaking.CreateValidatorWithValPower(addr, val, 100, true)
|
||||
amt := tstaking.CreateValidatorWithValPower(addr, valpubkey, 100, true)
|
||||
|
||||
_, err = f.stakingKeeper.EndBlocker(f.ctx)
|
||||
assert.NilError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
bondDenom, err := f.stakingKeeper.BondDenom(f.ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.DeepEqual(
|
||||
t, f.bankKeeper.GetAllBalances(f.ctx, sdk.AccAddress(addr)),
|
||||
sdk.NewCoins(sdk.NewCoin(f.stakingKeeper.GetParams(f.ctx).BondDenom, testutil.InitTokens.Sub(amt))),
|
||||
sdk.NewCoins(sdk.NewCoin(bondDenom, testutil.InitTokens.Sub(amt))),
|
||||
)
|
||||
assert.DeepEqual(t, amt, f.stakingKeeper.Validator(f.ctx, addr).GetBondedTokens())
|
||||
|
||||
val, err := f.stakingKeeper.Validator(f.ctx, addr)
|
||||
require.NoError(t, err)
|
||||
assert.DeepEqual(t, amt, val.GetBondedTokens())
|
||||
|
||||
// Now a validator, for two blocks
|
||||
assert.NilError(t, f.slashingKeeper.HandleValidatorSignature(f.ctx, val.Address(), 100, comet.BlockIDFlagCommit))
|
||||
assert.NilError(t, f.slashingKeeper.HandleValidatorSignature(f.ctx, valpubkey.Address(), 100, comet.BlockIDFlagCommit))
|
||||
f.ctx = f.ctx.WithBlockHeight(signedBlocksWindow + 2)
|
||||
assert.NilError(t, f.slashingKeeper.HandleValidatorSignature(f.ctx, val.Address(), 100, comet.BlockIDFlagAbsent))
|
||||
assert.NilError(t, f.slashingKeeper.HandleValidatorSignature(f.ctx, valpubkey.Address(), 100, comet.BlockIDFlagAbsent))
|
||||
|
||||
info, found := f.slashingKeeper.GetValidatorSigningInfo(f.ctx, sdk.ConsAddress(val.Address()))
|
||||
info, found := f.slashingKeeper.GetValidatorSigningInfo(f.ctx, sdk.ConsAddress(valpubkey.Address()))
|
||||
assert.Assert(t, found)
|
||||
assert.Equal(t, signedBlocksWindow+1, info.StartHeight)
|
||||
assert.Equal(t, int64(2), info.IndexOffset)
|
||||
@@ -248,11 +255,11 @@ func TestHandleNewValidator(t *testing.T) {
|
||||
assert.Equal(t, time.Unix(0, 0).UTC(), info.JailedUntil)
|
||||
|
||||
// validator should be bonded still, should not have been jailed or slashed
|
||||
validator, _ := f.stakingKeeper.GetValidatorByConsAddr(f.ctx, sdk.GetConsAddress(val))
|
||||
validator, _ := f.stakingKeeper.GetValidatorByConsAddr(f.ctx, sdk.GetConsAddress(valpubkey))
|
||||
assert.Equal(t, stakingtypes.Bonded, validator.GetStatus())
|
||||
bondPool := f.stakingKeeper.GetBondedPool(f.ctx)
|
||||
expTokens := f.stakingKeeper.TokensFromConsensusPower(f.ctx, 100)
|
||||
assert.Assert(t, expTokens.Equal(f.bankKeeper.GetBalance(f.ctx, bondPool.GetAddress(), f.stakingKeeper.BondDenom(f.ctx)).Amount))
|
||||
assert.Assert(t, expTokens.Equal(f.bankKeeper.GetBalance(f.ctx, bondPool.GetAddress(), bondDenom).Amount))
|
||||
}
|
||||
|
||||
// Test a jailed validator being "down" twice
|
||||
@@ -326,7 +333,8 @@ func TestValidatorDippingInAndOut(t *testing.T) {
|
||||
t.Parallel()
|
||||
f := initFixture(t)
|
||||
|
||||
params := f.stakingKeeper.GetParams(f.ctx)
|
||||
params, err := f.stakingKeeper.GetParams(f.ctx)
|
||||
require.NoError(t, err)
|
||||
params.MaxValidators = 1
|
||||
f.stakingKeeper.SetParams(f.ctx, params)
|
||||
power := int64(100)
|
||||
|
||||
@@ -71,12 +71,12 @@ func createValidators(t *testing.T, f *fixture, powers []int64) ([]sdk.AccAddres
|
||||
val2 := testutil.NewValidator(t, valAddrs[1], pks[1])
|
||||
vals := []types.Validator{val1, val2}
|
||||
|
||||
f.stakingKeeper.SetValidator(f.sdkCtx, val1)
|
||||
f.stakingKeeper.SetValidator(f.sdkCtx, val2)
|
||||
f.stakingKeeper.SetValidatorByConsAddr(f.sdkCtx, val1)
|
||||
f.stakingKeeper.SetValidatorByConsAddr(f.sdkCtx, val2)
|
||||
f.stakingKeeper.SetNewValidatorByPowerIndex(f.sdkCtx, val1)
|
||||
f.stakingKeeper.SetNewValidatorByPowerIndex(f.sdkCtx, val2)
|
||||
assert.NilError(t, f.stakingKeeper.SetValidator(f.sdkCtx, val1))
|
||||
assert.NilError(t, f.stakingKeeper.SetValidator(f.sdkCtx, val2))
|
||||
assert.NilError(t, f.stakingKeeper.SetValidatorByConsAddr(f.sdkCtx, val1))
|
||||
assert.NilError(t, f.stakingKeeper.SetValidatorByConsAddr(f.sdkCtx, val2))
|
||||
assert.NilError(t, f.stakingKeeper.SetNewValidatorByPowerIndex(f.sdkCtx, val1))
|
||||
assert.NilError(t, f.stakingKeeper.SetNewValidatorByPowerIndex(f.sdkCtx, val2))
|
||||
|
||||
_, err := f.stakingKeeper.Delegate(f.sdkCtx, addrs[0], f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, powers[0]), types.Unbonded, val1, true)
|
||||
assert.NilError(t, err)
|
||||
@@ -130,7 +130,7 @@ func initFixture(t testing.TB) *fixture {
|
||||
log.NewNopLogger(),
|
||||
)
|
||||
|
||||
stakingKeeper := stakingkeeper.NewKeeper(cdc, keys[types.StoreKey], accountKeeper, bankKeeper, authority.String())
|
||||
stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[types.StoreKey]), accountKeeper, bankKeeper, authority.String())
|
||||
|
||||
authModule := auth.NewAppModule(cdc, accountKeeper, authsims.RandomGenesisAccounts, nil)
|
||||
bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper, nil)
|
||||
@@ -145,7 +145,7 @@ func initFixture(t testing.TB) *fixture {
|
||||
types.RegisterQueryServer(integrationApp.QueryHelper(), stakingkeeper.NewQuerier(stakingKeeper))
|
||||
|
||||
// set default staking params
|
||||
stakingKeeper.SetParams(sdkCtx, types.DefaultParams())
|
||||
assert.NilError(t, stakingKeeper.SetParams(sdkCtx, types.DefaultParams()))
|
||||
|
||||
f := fixture{
|
||||
app: integrationApp,
|
||||
|
||||
@@ -21,23 +21,20 @@ func TestUnbondingDelegationsMaxEntries(t *testing.T) {
|
||||
ctx := f.sdkCtx
|
||||
|
||||
initTokens := f.stakingKeeper.TokensFromConsensusPower(ctx, int64(1000))
|
||||
f.bankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initTokens)))
|
||||
assert.NilError(t, f.bankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initTokens))))
|
||||
|
||||
addrDel := sdk.AccAddress([]byte("addr"))
|
||||
accAmt := sdk.NewInt(10000)
|
||||
initCoins := sdk.NewCoins(sdk.NewCoin(f.stakingKeeper.BondDenom(ctx), accAmt))
|
||||
if err := f.bankKeeper.MintCoins(ctx, types.ModuleName, initCoins); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
bondDenom, err := f.stakingKeeper.BondDenom(ctx)
|
||||
assert.NilError(t, err)
|
||||
|
||||
if err := f.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, addrDel, initCoins); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
initCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, accAmt))
|
||||
assert.NilError(t, f.bankKeeper.MintCoins(ctx, types.ModuleName, initCoins))
|
||||
assert.NilError(t, f.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, addrDel, initCoins))
|
||||
addrVal := sdk.ValAddress(addrDel)
|
||||
|
||||
startTokens := f.stakingKeeper.TokensFromConsensusPower(ctx, 10)
|
||||
|
||||
bondDenom := f.stakingKeeper.BondDenom(ctx)
|
||||
notBondedPool := f.stakingKeeper.GetNotBondedPool(ctx)
|
||||
|
||||
assert.NilError(t, banktestutil.FundModuleAccount(ctx, f.bankKeeper, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(bondDenom, startTokens))))
|
||||
@@ -54,9 +51,10 @@ func TestUnbondingDelegationsMaxEntries(t *testing.T) {
|
||||
assert.Assert(t, validator.IsBonded())
|
||||
|
||||
delegation := types.NewDelegation(addrDel, addrVal, issuedShares)
|
||||
f.stakingKeeper.SetDelegation(ctx, delegation)
|
||||
assert.NilError(t, f.stakingKeeper.SetDelegation(ctx, delegation))
|
||||
|
||||
maxEntries := f.stakingKeeper.MaxEntries(ctx)
|
||||
maxEntries, err := f.stakingKeeper.MaxEntries(ctx)
|
||||
assert.NilError(t, err)
|
||||
|
||||
oldBonded := f.bankKeeper.GetBalance(ctx, f.stakingKeeper.GetBondedPool(ctx).GetAddress(), bondDenom).Amount
|
||||
oldNotBonded := f.bankKeeper.GetBalance(ctx, f.stakingKeeper.GetNotBondedPool(ctx).GetAddress(), bondDenom).Amount
|
||||
@@ -69,8 +67,8 @@ func TestUnbondingDelegationsMaxEntries(t *testing.T) {
|
||||
ctx = ctx.WithBlockHeight(i)
|
||||
var amount math.Int
|
||||
completionTime, amount, err = f.stakingKeeper.Undelegate(ctx, addrDel, addrVal, math.LegacyNewDec(1))
|
||||
totalUnbonded = totalUnbonded.Add(amount)
|
||||
assert.NilError(t, err)
|
||||
totalUnbonded = totalUnbonded.Add(amount)
|
||||
}
|
||||
|
||||
newBonded := f.bankKeeper.GetBalance(ctx, f.stakingKeeper.GetBondedPool(ctx).GetAddress(), bondDenom).Amount
|
||||
@@ -84,7 +82,7 @@ func TestUnbondingDelegationsMaxEntries(t *testing.T) {
|
||||
oldNotBonded = f.bankKeeper.GetBalance(ctx, f.stakingKeeper.GetNotBondedPool(ctx).GetAddress(), bondDenom).Amount
|
||||
|
||||
// an additional unbond should fail due to max entries
|
||||
_, _, err := f.stakingKeeper.Undelegate(ctx, addrDel, addrVal, math.LegacyNewDec(1))
|
||||
_, _, err = f.stakingKeeper.Undelegate(ctx, addrDel, addrVal, math.LegacyNewDec(1))
|
||||
assert.Error(t, err, "too many unbonding delegation entries for (delegator, validator) tuple")
|
||||
|
||||
newBonded = f.bankKeeper.GetBalance(ctx, f.stakingKeeper.GetBondedPool(ctx).GetAddress(), bondDenom).Amount
|
||||
|
||||
@@ -102,7 +102,7 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture {
|
||||
log.NewNopLogger(),
|
||||
)
|
||||
|
||||
stakingKeeper := stakingkeeper.NewKeeper(cdc, keys[stakingtypes.StoreKey], accountKeeper, bankKeeper, authority.String())
|
||||
stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), accountKeeper, bankKeeper, authority.String())
|
||||
|
||||
authModule := auth.NewAppModule(cdc, accountKeeper, authsims.RandomGenesisAccounts, nil)
|
||||
bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper, nil)
|
||||
@@ -110,34 +110,35 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture {
|
||||
|
||||
integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc, authModule, bankModule, stakingModule)
|
||||
|
||||
sdkCtx := sdk.UnwrapSDKContext(integrationApp.Context())
|
||||
ctx := integrationApp.Context()
|
||||
|
||||
// Register MsgServer and QueryServer
|
||||
stakingtypes.RegisterMsgServer(integrationApp.MsgServiceRouter(), stakingkeeper.NewMsgServerImpl(stakingKeeper))
|
||||
stakingtypes.RegisterQueryServer(integrationApp.QueryHelper(), stakingkeeper.NewQuerier(stakingKeeper))
|
||||
|
||||
// set default staking params
|
||||
stakingKeeper.SetParams(sdkCtx, stakingtypes.DefaultParams())
|
||||
assert.NilError(t, stakingKeeper.SetParams(ctx, stakingtypes.DefaultParams()))
|
||||
|
||||
// set pools
|
||||
startTokens := stakingKeeper.TokensFromConsensusPower(sdkCtx, 10)
|
||||
bondDenom := stakingKeeper.BondDenom(sdkCtx)
|
||||
notBondedPool := stakingKeeper.GetNotBondedPool(sdkCtx)
|
||||
assert.NilError(t, banktestutil.FundModuleAccount(sdkCtx, bankKeeper, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(bondDenom, startTokens))))
|
||||
accountKeeper.SetModuleAccount(sdkCtx, notBondedPool)
|
||||
bondedPool := stakingKeeper.GetBondedPool(sdkCtx)
|
||||
assert.NilError(t, banktestutil.FundModuleAccount(sdkCtx, bankKeeper, bondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(bondDenom, startTokens))))
|
||||
accountKeeper.SetModuleAccount(sdkCtx, bondedPool)
|
||||
startTokens := stakingKeeper.TokensFromConsensusPower(ctx, 10)
|
||||
bondDenom, err := stakingKeeper.BondDenom(ctx)
|
||||
assert.NilError(t, err)
|
||||
notBondedPool := stakingKeeper.GetNotBondedPool(ctx)
|
||||
assert.NilError(t, banktestutil.FundModuleAccount(ctx, bankKeeper, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(bondDenom, startTokens))))
|
||||
accountKeeper.SetModuleAccount(ctx, notBondedPool)
|
||||
bondedPool := stakingKeeper.GetBondedPool(ctx)
|
||||
assert.NilError(t, banktestutil.FundModuleAccount(ctx, bankKeeper, bondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(bondDenom, startTokens))))
|
||||
accountKeeper.SetModuleAccount(ctx, bondedPool)
|
||||
|
||||
qr := integrationApp.QueryHelper()
|
||||
queryClient := stakingtypes.NewQueryClient(qr)
|
||||
|
||||
amt1 := stakingKeeper.TokensFromConsensusPower(sdkCtx, 101)
|
||||
amt2 := stakingKeeper.TokensFromConsensusPower(sdkCtx, 102)
|
||||
amt1 := stakingKeeper.TokensFromConsensusPower(ctx, 101)
|
||||
amt2 := stakingKeeper.TokensFromConsensusPower(ctx, 102)
|
||||
|
||||
f := deterministicFixture{
|
||||
app: integrationApp,
|
||||
ctx: sdkCtx,
|
||||
ctx: sdk.UnwrapSDKContext(ctx),
|
||||
cdc: cdc,
|
||||
keys: keys,
|
||||
accountKeeper: accountKeeper,
|
||||
@@ -220,14 +221,14 @@ func createAndSetValidator(rt *rapid.T, f *deterministicFixture, t *testing.T) s
|
||||
}
|
||||
|
||||
func setValidator(f *deterministicFixture, t *testing.T, validator stakingtypes.Validator) {
|
||||
f.stakingKeeper.SetValidator(f.ctx, validator)
|
||||
f.stakingKeeper.SetValidatorByPowerIndex(f.ctx, validator)
|
||||
f.stakingKeeper.SetValidatorByConsAddr(f.ctx, validator)
|
||||
assert.NilError(t, f.stakingKeeper.SetValidator(f.ctx, validator))
|
||||
assert.NilError(t, f.stakingKeeper.SetValidatorByPowerIndex(f.ctx, validator))
|
||||
assert.NilError(t, f.stakingKeeper.SetValidatorByConsAddr(f.ctx, validator))
|
||||
assert.NilError(t, f.stakingKeeper.Hooks().AfterValidatorCreated(f.ctx, validator.GetOperator()))
|
||||
|
||||
delegatorAddress := sdk.AccAddress(validator.GetOperator())
|
||||
coins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, validator.BondedTokens()))
|
||||
banktestutil.FundAccount(f.ctx, f.bankKeeper, delegatorAddress, coins)
|
||||
assert.NilError(t, banktestutil.FundAccount(f.ctx, f.bankKeeper, delegatorAddress, coins))
|
||||
|
||||
_, err := f.stakingKeeper.Delegate(f.ctx, delegatorAddress, validator.BondedTokens(), stakingtypes.Unbonded, validator, true)
|
||||
assert.NilError(t, err)
|
||||
@@ -312,7 +313,7 @@ func fundAccountAndDelegate(f *deterministicFixture, t *testing.T, delegator sdk
|
||||
coins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, amt))
|
||||
|
||||
assert.NilError(t, f.bankKeeper.MintCoins(f.ctx, minttypes.ModuleName, coins))
|
||||
banktestutil.FundAccount(f.ctx, f.bankKeeper, delegator, coins)
|
||||
assert.NilError(t, banktestutil.FundAccount(f.ctx, f.bankKeeper, delegator, coins))
|
||||
|
||||
shares, err := f.stakingKeeper.Delegate(f.ctx, delegator, amt, stakingtypes.Unbonded, validator, true)
|
||||
return shares, err
|
||||
@@ -651,11 +652,11 @@ func TestGRPCHistoricalInfo(t *testing.T) {
|
||||
|
||||
height := rapid.Int64Min(0).Draw(rt, "height")
|
||||
|
||||
f.stakingKeeper.SetHistoricalInfo(
|
||||
assert.NilError(t, f.stakingKeeper.SetHistoricalInfo(
|
||||
f.ctx,
|
||||
height,
|
||||
&historicalInfo,
|
||||
)
|
||||
))
|
||||
|
||||
req := &stakingtypes.QueryHistoricalInfoRequest{
|
||||
Height: height,
|
||||
@@ -675,11 +676,11 @@ func TestGRPCHistoricalInfo(t *testing.T) {
|
||||
|
||||
height := int64(127)
|
||||
|
||||
f.stakingKeeper.SetHistoricalInfo(
|
||||
assert.NilError(t, f.stakingKeeper.SetHistoricalInfo(
|
||||
f.ctx,
|
||||
height,
|
||||
&historicalInfo,
|
||||
)
|
||||
))
|
||||
|
||||
req := &stakingtypes.QueryHistoricalInfoRequest{
|
||||
Height: height,
|
||||
|
||||
@@ -40,10 +40,14 @@ func TestInitGenesis(t *testing.T) {
|
||||
DelegatorShares: sdk.NewDecFromInt(valTokens),
|
||||
Description: types.NewDescription("hoop", "", "", "", ""),
|
||||
}
|
||||
f.stakingKeeper.SetValidator(f.sdkCtx, bondedVal)
|
||||
assert.NilError(t, f.stakingKeeper.SetValidator(f.sdkCtx, bondedVal))
|
||||
|
||||
params, err := f.stakingKeeper.GetParams(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
|
||||
validators, err := f.stakingKeeper.GetAllValidators(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
|
||||
params := (f.stakingKeeper.GetParams(f.sdkCtx))
|
||||
validators := (f.stakingKeeper.GetAllValidators(f.sdkCtx))
|
||||
assert.Assert(t, len(validators) == 1)
|
||||
var delegations []types.Delegation
|
||||
|
||||
@@ -87,7 +91,8 @@ func TestInitGenesis(t *testing.T) {
|
||||
),
|
||||
)
|
||||
|
||||
genesisDelegations := (f.stakingKeeper.GetAllDelegations(f.sdkCtx))
|
||||
genesisDelegations, err := f.stakingKeeper.GetAllDelegations(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
delegations = append(delegations, genesisDelegations...)
|
||||
|
||||
genesisState := types.NewGenesisState(params, validators, delegations)
|
||||
@@ -96,7 +101,10 @@ func TestInitGenesis(t *testing.T) {
|
||||
actualGenesis := (f.stakingKeeper.ExportGenesis(f.sdkCtx))
|
||||
assert.DeepEqual(t, genesisState.Params, actualGenesis.Params)
|
||||
assert.DeepEqual(t, genesisState.Delegations, actualGenesis.Delegations)
|
||||
assert.DeepEqual(t, (f.stakingKeeper.GetAllValidators(f.sdkCtx)), actualGenesis.Validators)
|
||||
|
||||
allvals, err := f.stakingKeeper.GetAllValidators(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
assert.DeepEqual(t, allvals, actualGenesis.Validators)
|
||||
|
||||
// Ensure validators have addresses.
|
||||
vals2, err := staking.WriteValidators(f.sdkCtx, (f.stakingKeeper))
|
||||
@@ -175,14 +183,14 @@ func TestInitGenesisLargeValidatorSet(t *testing.T) {
|
||||
assert.Assert(t, size > 100)
|
||||
|
||||
f, addrs := bootstrapGenesisTest(t, 200)
|
||||
genesisValidators := f.stakingKeeper.GetAllValidators(f.sdkCtx)
|
||||
genesisValidators, err := f.stakingKeeper.GetAllValidators(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
|
||||
params := f.stakingKeeper.GetParams(f.sdkCtx)
|
||||
params, err := f.stakingKeeper.GetParams(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
delegations := []types.Delegation{}
|
||||
validators := make([]types.Validator, size)
|
||||
|
||||
var err error
|
||||
|
||||
bondedPoolAmt := math.ZeroInt()
|
||||
for i := range validators {
|
||||
validators[i], err = types.NewValidator(
|
||||
|
||||
@@ -27,7 +27,7 @@ func createValidatorAccs(t *testing.T, f *fixture) ([]sdk.AccAddress, []types.Va
|
||||
sortedVals := make([]types.Validator, len(validators))
|
||||
copy(sortedVals, validators)
|
||||
hi := types.NewHistoricalInfo(header, sortedVals, f.stakingKeeper.PowerReduction(f.sdkCtx))
|
||||
f.stakingKeeper.SetHistoricalInfo(f.sdkCtx, 5, &hi)
|
||||
assert.NilError(t, f.stakingKeeper.SetHistoricalInfo(f.sdkCtx, 5, &hi))
|
||||
|
||||
return addrs, validators
|
||||
}
|
||||
@@ -126,8 +126,10 @@ func TestGRPCQueryDelegatorValidators(t *testing.T) {
|
||||
qr := f.app.QueryHelper()
|
||||
queryClient := types.NewQueryClient(qr)
|
||||
|
||||
params := f.stakingKeeper.GetParams(ctx)
|
||||
delValidators := f.stakingKeeper.GetDelegatorValidators(ctx, addrs[0], params.MaxValidators)
|
||||
params, err := f.stakingKeeper.GetParams(ctx)
|
||||
assert.NilError(t, err)
|
||||
delValidators, err := f.stakingKeeper.GetDelegatorValidators(ctx, addrs[0], params.MaxValidators)
|
||||
assert.NilError(t, err)
|
||||
var req *types.QueryDelegatorValidatorsRequest
|
||||
testCases := []struct {
|
||||
msg string
|
||||
@@ -712,7 +714,9 @@ func TestGRPCQueryPoolParameters(t *testing.T) {
|
||||
// Query Params
|
||||
resp, err := queryClient.Params(gocontext.Background(), &types.QueryParamsRequest{})
|
||||
assert.NilError(t, err)
|
||||
assert.DeepEqual(t, f.stakingKeeper.GetParams(ctx), resp.Params)
|
||||
params, err := f.stakingKeeper.GetParams(ctx)
|
||||
assert.NilError(t, err)
|
||||
assert.DeepEqual(t, params, resp.Params)
|
||||
}
|
||||
|
||||
func TestGRPCQueryHistoricalInfo(t *testing.T) {
|
||||
|
||||
@@ -19,16 +19,17 @@ func TestCancelUnbondingDelegation(t *testing.T) {
|
||||
|
||||
ctx := f.sdkCtx
|
||||
msgServer := keeper.NewMsgServerImpl(f.stakingKeeper)
|
||||
bondDenom := f.stakingKeeper.BondDenom(ctx)
|
||||
bondDenom, err := f.stakingKeeper.BondDenom(ctx)
|
||||
assert.NilError(t, err)
|
||||
|
||||
// set the not bonded pool module account
|
||||
notBondedPool := f.stakingKeeper.GetNotBondedPool(ctx)
|
||||
startTokens := f.stakingKeeper.TokensFromConsensusPower(ctx, 5)
|
||||
|
||||
assert.NilError(t, testutil.FundModuleAccount(ctx, f.bankKeeper, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(f.stakingKeeper.BondDenom(ctx), startTokens))))
|
||||
assert.NilError(t, testutil.FundModuleAccount(ctx, f.bankKeeper, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(bondDenom, startTokens))))
|
||||
f.accountKeeper.SetModuleAccount(ctx, notBondedPool)
|
||||
|
||||
moduleBalance := f.bankKeeper.GetBalance(ctx, notBondedPool.GetAddress(), f.stakingKeeper.BondDenom(ctx))
|
||||
moduleBalance := f.bankKeeper.GetBalance(ctx, notBondedPool.GetAddress(), bondDenom)
|
||||
assert.DeepEqual(t, sdk.NewInt64Coin(bondDenom, startTokens.Int64()), moduleBalance)
|
||||
|
||||
// accounts
|
||||
@@ -40,13 +41,13 @@ func TestCancelUnbondingDelegation(t *testing.T) {
|
||||
validator, err := types.NewValidator(valAddr, PKs[0], types.NewDescription("Validator", "", "", "", ""))
|
||||
validator.Status = types.Bonded
|
||||
assert.NilError(t, err)
|
||||
f.stakingKeeper.SetValidator(ctx, validator)
|
||||
assert.NilError(t, f.stakingKeeper.SetValidator(ctx, validator))
|
||||
|
||||
validatorAddr, err := sdk.ValAddressFromBech32(validator.OperatorAddress)
|
||||
assert.NilError(t, err)
|
||||
|
||||
// setting the ubd entry
|
||||
unbondingAmount := sdk.NewInt64Coin(f.stakingKeeper.BondDenom(ctx), 5)
|
||||
unbondingAmount := sdk.NewInt64Coin(bondDenom, 5)
|
||||
ubd := types.NewUnbondingDelegation(
|
||||
delegatorAddr, validatorAddr, 10,
|
||||
ctx.BlockTime().Add(time.Minute*10),
|
||||
@@ -55,7 +56,7 @@ func TestCancelUnbondingDelegation(t *testing.T) {
|
||||
)
|
||||
|
||||
// set and retrieve a record
|
||||
f.stakingKeeper.SetUnbondingDelegation(ctx, ubd)
|
||||
assert.NilError(t, f.stakingKeeper.SetUnbondingDelegation(ctx, ubd))
|
||||
resUnbond, found := f.stakingKeeper.GetUnbondingDelegation(ctx, delegatorAddr, validatorAddr)
|
||||
assert.Assert(t, found)
|
||||
assert.DeepEqual(t, ubd, resUnbond)
|
||||
@@ -72,7 +73,7 @@ func TestCancelUnbondingDelegation(t *testing.T) {
|
||||
req: types.MsgCancelUnbondingDelegation{
|
||||
DelegatorAddress: resUnbond.DelegatorAddress,
|
||||
ValidatorAddress: resUnbond.ValidatorAddress,
|
||||
Amount: sdk.NewCoin(f.stakingKeeper.BondDenom(ctx), sdk.NewInt(4)),
|
||||
Amount: sdk.NewCoin(bondDenom, sdk.NewInt(4)),
|
||||
CreationHeight: 11,
|
||||
},
|
||||
expErrMsg: "unbonding delegation entry is not found at block height",
|
||||
@@ -83,7 +84,7 @@ func TestCancelUnbondingDelegation(t *testing.T) {
|
||||
req: types.MsgCancelUnbondingDelegation{
|
||||
DelegatorAddress: resUnbond.DelegatorAddress,
|
||||
ValidatorAddress: resUnbond.ValidatorAddress,
|
||||
Amount: sdk.NewCoin(f.stakingKeeper.BondDenom(ctx), sdk.NewInt(4)),
|
||||
Amount: sdk.NewCoin(bondDenom, sdk.NewInt(4)),
|
||||
CreationHeight: 0,
|
||||
},
|
||||
expErrMsg: "invalid height",
|
||||
|
||||
@@ -24,7 +24,9 @@ func bootstrapSlashTest(t *testing.T, power int64) (*fixture, []sdk.AccAddress,
|
||||
addrDels, addrVals := generateAddresses(f, 100)
|
||||
|
||||
amt := f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, power)
|
||||
totalSupply := sdk.NewCoins(sdk.NewCoin(f.stakingKeeper.BondDenom(f.sdkCtx), amt.MulRaw(int64(len(addrDels)))))
|
||||
bondDenom, err := f.stakingKeeper.BondDenom(f.sdkCtx)
|
||||
require.NoError(t, err)
|
||||
totalSupply := sdk.NewCoins(sdk.NewCoin(bondDenom, amt.MulRaw(int64(len(addrDels)))))
|
||||
|
||||
notBondedPool := f.stakingKeeper.GetNotBondedPool(f.sdkCtx)
|
||||
assert.NilError(t, banktestutil.FundModuleAccount(f.sdkCtx, f.bankKeeper, notBondedPool.GetName(), totalSupply))
|
||||
@@ -32,7 +34,7 @@ func bootstrapSlashTest(t *testing.T, power int64) (*fixture, []sdk.AccAddress,
|
||||
f.accountKeeper.SetModuleAccount(f.sdkCtx, notBondedPool)
|
||||
|
||||
numVals := int64(3)
|
||||
bondedCoins := sdk.NewCoins(sdk.NewCoin(f.stakingKeeper.BondDenom(f.sdkCtx), amt.MulRaw(numVals)))
|
||||
bondedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, amt.MulRaw(numVals)))
|
||||
bondedPool := f.stakingKeeper.GetBondedPool(f.sdkCtx)
|
||||
|
||||
// set bonded pool balance
|
||||
@@ -43,7 +45,7 @@ func bootstrapSlashTest(t *testing.T, power int64) (*fixture, []sdk.AccAddress,
|
||||
validator := testutil.NewValidator(t, addrVals[i], PKs[i])
|
||||
validator, _ = validator.AddTokensFromDel(amt)
|
||||
validator = keeper.TestingUpdateValidator(f.stakingKeeper, f.sdkCtx, validator, true)
|
||||
f.stakingKeeper.SetValidatorByConsAddr(f.sdkCtx, validator)
|
||||
assert.NilError(t, f.stakingKeeper.SetValidatorByConsAddr(f.sdkCtx, validator))
|
||||
}
|
||||
|
||||
return f, addrDels, addrVals
|
||||
@@ -60,24 +62,27 @@ func TestSlashUnbondingDelegation(t *testing.T) {
|
||||
ubd := types.NewUnbondingDelegation(addrDels[0], addrVals[0], 0,
|
||||
time.Unix(5, 0), sdk.NewInt(10), 0)
|
||||
|
||||
f.stakingKeeper.SetUnbondingDelegation(f.sdkCtx, ubd)
|
||||
assert.NilError(t, f.stakingKeeper.SetUnbondingDelegation(f.sdkCtx, ubd))
|
||||
|
||||
// unbonding started prior to the infraction height, stakw didn't contribute
|
||||
slashAmount := f.stakingKeeper.SlashUnbondingDelegation(f.sdkCtx, ubd, 1, fraction)
|
||||
slashAmount, err := f.stakingKeeper.SlashUnbondingDelegation(f.sdkCtx, ubd, 1, fraction)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, slashAmount.Equal(sdk.NewInt(0)))
|
||||
|
||||
// after the expiration time, no longer eligible for slashing
|
||||
f.sdkCtx = f.sdkCtx.WithBlockHeader(cmtproto.Header{Time: time.Unix(10, 0)})
|
||||
f.stakingKeeper.SetUnbondingDelegation(f.sdkCtx, ubd)
|
||||
slashAmount = f.stakingKeeper.SlashUnbondingDelegation(f.sdkCtx, ubd, 0, fraction)
|
||||
assert.NilError(t, f.stakingKeeper.SetUnbondingDelegation(f.sdkCtx, ubd))
|
||||
slashAmount, err = f.stakingKeeper.SlashUnbondingDelegation(f.sdkCtx, ubd, 0, fraction)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, slashAmount.Equal(sdk.NewInt(0)))
|
||||
|
||||
// test valid slash, before expiration timestamp and to which stake contributed
|
||||
notBondedPool := f.stakingKeeper.GetNotBondedPool(f.sdkCtx)
|
||||
oldUnbondedPoolBalances := f.bankKeeper.GetAllBalances(f.sdkCtx, notBondedPool.GetAddress())
|
||||
f.sdkCtx = f.sdkCtx.WithBlockHeader(cmtproto.Header{Time: time.Unix(0, 0)})
|
||||
f.stakingKeeper.SetUnbondingDelegation(f.sdkCtx, ubd)
|
||||
slashAmount = f.stakingKeeper.SlashUnbondingDelegation(f.sdkCtx, ubd, 0, fraction)
|
||||
assert.NilError(t, f.stakingKeeper.SetUnbondingDelegation(f.sdkCtx, ubd))
|
||||
slashAmount, err = f.stakingKeeper.SlashUnbondingDelegation(f.sdkCtx, ubd, 0, fraction)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, slashAmount.Equal(sdk.NewInt(5)))
|
||||
ubd, found := f.stakingKeeper.GetUnbondingDelegation(f.sdkCtx, addrDels[0], addrVals[0])
|
||||
assert.Assert(t, found)
|
||||
@@ -90,7 +95,9 @@ func TestSlashUnbondingDelegation(t *testing.T) {
|
||||
assert.DeepEqual(t, sdk.NewInt(5), ubd.Entries[0].Balance)
|
||||
newUnbondedPoolBalances := f.bankKeeper.GetAllBalances(f.sdkCtx, notBondedPool.GetAddress())
|
||||
diffTokens := oldUnbondedPoolBalances.Sub(newUnbondedPoolBalances...)
|
||||
assert.Assert(t, diffTokens.AmountOf(f.stakingKeeper.BondDenom(f.sdkCtx)).Equal(sdk.NewInt(5)))
|
||||
bondDenom, err := f.stakingKeeper.BondDenom(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, diffTokens.AmountOf(bondDenom).Equal(sdk.NewInt(5)))
|
||||
}
|
||||
|
||||
// tests slashRedelegation
|
||||
@@ -98,8 +105,11 @@ func TestSlashRedelegation(t *testing.T) {
|
||||
f, addrDels, addrVals := bootstrapSlashTest(t, 10)
|
||||
fraction := sdk.NewDecWithPrec(5, 1)
|
||||
|
||||
bondDenom, err := f.stakingKeeper.BondDenom(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
|
||||
// add bonded tokens to pool for (re)delegations
|
||||
startCoins := sdk.NewCoins(sdk.NewInt64Coin(f.stakingKeeper.BondDenom(f.sdkCtx), 15))
|
||||
startCoins := sdk.NewCoins(sdk.NewInt64Coin(bondDenom, 15))
|
||||
bondedPool := f.stakingKeeper.GetBondedPool(f.sdkCtx)
|
||||
_ = f.bankKeeper.GetAllBalances(f.sdkCtx, bondedPool.GetAddress())
|
||||
|
||||
@@ -111,34 +121,37 @@ func TestSlashRedelegation(t *testing.T) {
|
||||
rd := types.NewRedelegation(addrDels[0], addrVals[0], addrVals[1], 0,
|
||||
time.Unix(5, 0), sdk.NewInt(10), math.LegacyNewDec(10), 0)
|
||||
|
||||
f.stakingKeeper.SetRedelegation(f.sdkCtx, rd)
|
||||
assert.NilError(t, f.stakingKeeper.SetRedelegation(f.sdkCtx, rd))
|
||||
|
||||
// set the associated delegation
|
||||
del := types.NewDelegation(addrDels[0], addrVals[1], math.LegacyNewDec(10))
|
||||
f.stakingKeeper.SetDelegation(f.sdkCtx, del)
|
||||
assert.NilError(t, f.stakingKeeper.SetDelegation(f.sdkCtx, del))
|
||||
|
||||
// started redelegating prior to the current height, stake didn't contribute to infraction
|
||||
validator, found := f.stakingKeeper.GetValidator(f.sdkCtx, addrVals[1])
|
||||
assert.Assert(t, found)
|
||||
slashAmount := f.stakingKeeper.SlashRedelegation(f.sdkCtx, validator, rd, 1, fraction)
|
||||
slashAmount, err := f.stakingKeeper.SlashRedelegation(f.sdkCtx, validator, rd, 1, fraction)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, slashAmount.Equal(sdk.NewInt(0)))
|
||||
|
||||
// after the expiration time, no longer eligible for slashing
|
||||
f.sdkCtx = f.sdkCtx.WithBlockHeader(cmtproto.Header{Time: time.Unix(10, 0)})
|
||||
f.stakingKeeper.SetRedelegation(f.sdkCtx, rd)
|
||||
assert.NilError(t, f.stakingKeeper.SetRedelegation(f.sdkCtx, rd))
|
||||
validator, found = f.stakingKeeper.GetValidator(f.sdkCtx, addrVals[1])
|
||||
assert.Assert(t, found)
|
||||
slashAmount = f.stakingKeeper.SlashRedelegation(f.sdkCtx, validator, rd, 0, fraction)
|
||||
slashAmount, err = f.stakingKeeper.SlashRedelegation(f.sdkCtx, validator, rd, 0, fraction)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, slashAmount.Equal(sdk.NewInt(0)))
|
||||
|
||||
balances := f.bankKeeper.GetAllBalances(f.sdkCtx, bondedPool.GetAddress())
|
||||
|
||||
// test valid slash, before expiration timestamp and to which stake contributed
|
||||
f.sdkCtx = f.sdkCtx.WithBlockHeader(cmtproto.Header{Time: time.Unix(0, 0)})
|
||||
f.stakingKeeper.SetRedelegation(f.sdkCtx, rd)
|
||||
assert.NilError(t, f.stakingKeeper.SetRedelegation(f.sdkCtx, rd))
|
||||
validator, found = f.stakingKeeper.GetValidator(f.sdkCtx, addrVals[1])
|
||||
assert.Assert(t, found)
|
||||
slashAmount = f.stakingKeeper.SlashRedelegation(f.sdkCtx, validator, rd, 0, fraction)
|
||||
slashAmount, err = f.stakingKeeper.SlashRedelegation(f.sdkCtx, validator, rd, 0, fraction)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, slashAmount.Equal(sdk.NewInt(5)))
|
||||
rd, found = f.stakingKeeper.GetRedelegation(f.sdkCtx, addrDels[0], addrVals[0], addrVals[1])
|
||||
assert.Assert(t, found)
|
||||
@@ -156,7 +169,7 @@ func TestSlashRedelegation(t *testing.T) {
|
||||
assert.Equal(t, int64(5), del.Shares.RoundInt64())
|
||||
|
||||
// pool bonded tokens should decrease
|
||||
burnedCoins := sdk.NewCoins(sdk.NewCoin(f.stakingKeeper.BondDenom(f.sdkCtx), slashAmount))
|
||||
burnedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, slashAmount))
|
||||
assert.DeepEqual(t, balances.Sub(burnedCoins...), f.bankKeeper.GetAllBalances(f.sdkCtx, bondedPool.GetAddress()))
|
||||
}
|
||||
|
||||
@@ -172,7 +185,8 @@ func TestSlashAtNegativeHeight(t *testing.T) {
|
||||
|
||||
_, found := f.stakingKeeper.GetValidatorByConsAddr(f.sdkCtx, consAddr)
|
||||
assert.Assert(t, found)
|
||||
f.stakingKeeper.Slash(f.sdkCtx, consAddr, -2, 10, fraction)
|
||||
_, err := f.stakingKeeper.Slash(f.sdkCtx, consAddr, -2, 10, fraction)
|
||||
assert.NilError(t, err)
|
||||
|
||||
// read updated state
|
||||
validator, found := f.stakingKeeper.GetValidatorByConsAddr(f.sdkCtx, consAddr)
|
||||
@@ -186,9 +200,12 @@ func TestSlashAtNegativeHeight(t *testing.T) {
|
||||
// power decreased
|
||||
assert.Equal(t, int64(5), validator.GetConsensusPower(f.stakingKeeper.PowerReduction(f.sdkCtx)))
|
||||
|
||||
bondDenom, err := f.stakingKeeper.BondDenom(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
|
||||
// pool bonded shares decreased
|
||||
newBondedPoolBalances := f.bankKeeper.GetAllBalances(f.sdkCtx, bondedPool.GetAddress())
|
||||
diffTokens := oldBondedPoolBalances.Sub(newBondedPoolBalances...).AmountOf(f.stakingKeeper.BondDenom(f.sdkCtx))
|
||||
diffTokens := oldBondedPoolBalances.Sub(newBondedPoolBalances...).AmountOf(bondDenom)
|
||||
assert.DeepEqual(t, f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, 5).String(), diffTokens.String())
|
||||
}
|
||||
|
||||
@@ -198,12 +215,16 @@ func TestSlashValidatorAtCurrentHeight(t *testing.T) {
|
||||
consAddr := sdk.ConsAddress(PKs[0].Address())
|
||||
fraction := sdk.NewDecWithPrec(5, 1)
|
||||
|
||||
bondDenom, err := f.stakingKeeper.BondDenom(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
|
||||
bondedPool := f.stakingKeeper.GetBondedPool(f.sdkCtx)
|
||||
oldBondedPoolBalances := f.bankKeeper.GetAllBalances(f.sdkCtx, bondedPool.GetAddress())
|
||||
|
||||
_, found := f.stakingKeeper.GetValidatorByConsAddr(f.sdkCtx, consAddr)
|
||||
assert.Assert(t, found)
|
||||
f.stakingKeeper.Slash(f.sdkCtx, consAddr, f.sdkCtx.BlockHeight(), 10, fraction)
|
||||
_, err = f.stakingKeeper.Slash(f.sdkCtx, consAddr, f.sdkCtx.BlockHeight(), 10, fraction)
|
||||
assert.NilError(t, err)
|
||||
|
||||
// read updated state
|
||||
validator, found := f.stakingKeeper.GetValidatorByConsAddr(f.sdkCtx, consAddr)
|
||||
@@ -219,7 +240,7 @@ func TestSlashValidatorAtCurrentHeight(t *testing.T) {
|
||||
|
||||
// pool bonded shares decreased
|
||||
newBondedPoolBalances := f.bankKeeper.GetAllBalances(f.sdkCtx, bondedPool.GetAddress())
|
||||
diffTokens := oldBondedPoolBalances.Sub(newBondedPoolBalances...).AmountOf(f.stakingKeeper.BondDenom(f.sdkCtx))
|
||||
diffTokens := oldBondedPoolBalances.Sub(newBondedPoolBalances...).AmountOf(bondDenom)
|
||||
assert.DeepEqual(t, f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, 5).String(), diffTokens.String())
|
||||
}
|
||||
|
||||
@@ -230,11 +251,14 @@ func TestSlashWithUnbondingDelegation(t *testing.T) {
|
||||
consAddr := sdk.ConsAddress(PKs[0].Address())
|
||||
fraction := sdk.NewDecWithPrec(5, 1)
|
||||
|
||||
bondDenom, err := f.stakingKeeper.BondDenom(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
|
||||
// set an unbonding delegation with expiration timestamp beyond which the
|
||||
// unbonding delegation shouldn't be slashed
|
||||
ubdTokens := f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, 4)
|
||||
ubd := types.NewUnbondingDelegation(addrDels[0], addrVals[0], 11, time.Unix(0, 0), ubdTokens, 0)
|
||||
f.stakingKeeper.SetUnbondingDelegation(f.sdkCtx, ubd)
|
||||
assert.NilError(t, f.stakingKeeper.SetUnbondingDelegation(f.sdkCtx, ubd))
|
||||
|
||||
// slash validator for the first time
|
||||
f.sdkCtx = f.sdkCtx.WithBlockHeight(12)
|
||||
@@ -243,7 +267,8 @@ func TestSlashWithUnbondingDelegation(t *testing.T) {
|
||||
|
||||
_, found := f.stakingKeeper.GetValidatorByConsAddr(f.sdkCtx, consAddr)
|
||||
assert.Assert(t, found)
|
||||
f.stakingKeeper.Slash(f.sdkCtx, consAddr, 10, 10, fraction)
|
||||
_, err = f.stakingKeeper.Slash(f.sdkCtx, consAddr, 10, 10, fraction)
|
||||
assert.NilError(t, err)
|
||||
|
||||
// end block
|
||||
applyValidatorSetUpdates(t, f.sdkCtx, f.stakingKeeper, 1)
|
||||
@@ -258,7 +283,7 @@ func TestSlashWithUnbondingDelegation(t *testing.T) {
|
||||
|
||||
// bonded tokens burned
|
||||
newBondedPoolBalances := f.bankKeeper.GetAllBalances(f.sdkCtx, bondedPool.GetAddress())
|
||||
diffTokens := oldBondedPoolBalances.Sub(newBondedPoolBalances...).AmountOf(f.stakingKeeper.BondDenom(f.sdkCtx))
|
||||
diffTokens := oldBondedPoolBalances.Sub(newBondedPoolBalances...).AmountOf(bondDenom)
|
||||
assert.DeepEqual(t, f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, 3), diffTokens)
|
||||
|
||||
// read updated validator
|
||||
@@ -273,7 +298,8 @@ func TestSlashWithUnbondingDelegation(t *testing.T) {
|
||||
|
||||
// slash validator again
|
||||
f.sdkCtx = f.sdkCtx.WithBlockHeight(13)
|
||||
f.stakingKeeper.Slash(f.sdkCtx, consAddr, 9, 10, fraction)
|
||||
_, err = f.stakingKeeper.Slash(f.sdkCtx, consAddr, 9, 10, fraction)
|
||||
assert.NilError(t, err)
|
||||
|
||||
ubd, found = f.stakingKeeper.GetUnbondingDelegation(f.sdkCtx, addrDels[0], addrVals[0])
|
||||
assert.Assert(t, found)
|
||||
@@ -284,7 +310,7 @@ func TestSlashWithUnbondingDelegation(t *testing.T) {
|
||||
|
||||
// bonded tokens burned again
|
||||
newBondedPoolBalances = f.bankKeeper.GetAllBalances(f.sdkCtx, bondedPool.GetAddress())
|
||||
diffTokens = oldBondedPoolBalances.Sub(newBondedPoolBalances...).AmountOf(f.stakingKeeper.BondDenom(f.sdkCtx))
|
||||
diffTokens = oldBondedPoolBalances.Sub(newBondedPoolBalances...).AmountOf(bondDenom)
|
||||
assert.DeepEqual(t, f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, 6), diffTokens)
|
||||
|
||||
// read updated validator
|
||||
@@ -299,7 +325,8 @@ func TestSlashWithUnbondingDelegation(t *testing.T) {
|
||||
// on the unbonding delegation, but it will slash stake bonded since the infraction
|
||||
// this may not be the desirable behavior, ref https://github.com/cosmos/cosmos-sdk/issues/1440
|
||||
f.sdkCtx = f.sdkCtx.WithBlockHeight(13)
|
||||
f.stakingKeeper.Slash(f.sdkCtx, consAddr, 9, 10, fraction)
|
||||
_, err = f.stakingKeeper.Slash(f.sdkCtx, consAddr, 9, 10, fraction)
|
||||
assert.NilError(t, err)
|
||||
|
||||
ubd, found = f.stakingKeeper.GetUnbondingDelegation(f.sdkCtx, addrDels[0], addrVals[0])
|
||||
assert.Assert(t, found)
|
||||
@@ -310,7 +337,7 @@ func TestSlashWithUnbondingDelegation(t *testing.T) {
|
||||
|
||||
// bonded tokens burned again
|
||||
newBondedPoolBalances = f.bankKeeper.GetAllBalances(f.sdkCtx, bondedPool.GetAddress())
|
||||
diffTokens = oldBondedPoolBalances.Sub(newBondedPoolBalances...).AmountOf(f.stakingKeeper.BondDenom(f.sdkCtx))
|
||||
diffTokens = oldBondedPoolBalances.Sub(newBondedPoolBalances...).AmountOf(bondDenom)
|
||||
assert.DeepEqual(t, f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, 9), diffTokens)
|
||||
|
||||
// read updated validator
|
||||
@@ -325,7 +352,8 @@ func TestSlashWithUnbondingDelegation(t *testing.T) {
|
||||
// on the unbonding delegation, but it will slash stake bonded since the infraction
|
||||
// this may not be the desirable behavior, ref https://github.com/cosmos/cosmos-sdk/issues/1440
|
||||
f.sdkCtx = f.sdkCtx.WithBlockHeight(13)
|
||||
f.stakingKeeper.Slash(f.sdkCtx, consAddr, 9, 10, fraction)
|
||||
_, err = f.stakingKeeper.Slash(f.sdkCtx, consAddr, 9, 10, fraction)
|
||||
assert.NilError(t, err)
|
||||
|
||||
ubd, found = f.stakingKeeper.GetUnbondingDelegation(f.sdkCtx, addrDels[0], addrVals[0])
|
||||
assert.Assert(t, found)
|
||||
@@ -336,7 +364,7 @@ func TestSlashWithUnbondingDelegation(t *testing.T) {
|
||||
|
||||
// just 1 bonded token burned again since that's all the validator now has
|
||||
newBondedPoolBalances = f.bankKeeper.GetAllBalances(f.sdkCtx, bondedPool.GetAddress())
|
||||
diffTokens = oldBondedPoolBalances.Sub(newBondedPoolBalances...).AmountOf(f.stakingKeeper.BondDenom(f.sdkCtx))
|
||||
diffTokens = oldBondedPoolBalances.Sub(newBondedPoolBalances...).AmountOf(bondDenom)
|
||||
assert.DeepEqual(t, f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, 10), diffTokens)
|
||||
|
||||
// apply TM updates
|
||||
@@ -354,16 +382,17 @@ func TestSlashWithRedelegation(t *testing.T) {
|
||||
f, addrDels, addrVals := bootstrapSlashTest(t, 10)
|
||||
consAddr := sdk.ConsAddress(PKs[0].Address())
|
||||
fraction := sdk.NewDecWithPrec(5, 1)
|
||||
bondDenom := f.stakingKeeper.BondDenom(f.sdkCtx)
|
||||
bondDenom, err := f.stakingKeeper.BondDenom(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
|
||||
// set a redelegation
|
||||
rdTokens := f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, 6)
|
||||
rd := types.NewRedelegation(addrDels[0], addrVals[0], addrVals[1], 11, time.Unix(0, 0), rdTokens, sdk.NewDecFromInt(rdTokens), 0)
|
||||
f.stakingKeeper.SetRedelegation(f.sdkCtx, rd)
|
||||
assert.NilError(t, f.stakingKeeper.SetRedelegation(f.sdkCtx, rd))
|
||||
|
||||
// set the associated delegation
|
||||
del := types.NewDelegation(addrDels[0], addrVals[1], sdk.NewDecFromInt(rdTokens))
|
||||
f.stakingKeeper.SetDelegation(f.sdkCtx, del)
|
||||
assert.NilError(t, f.stakingKeeper.SetDelegation(f.sdkCtx, del))
|
||||
|
||||
// update bonded tokens
|
||||
bondedPool := f.stakingKeeper.GetBondedPool(f.sdkCtx)
|
||||
@@ -382,9 +411,9 @@ func TestSlashWithRedelegation(t *testing.T) {
|
||||
_, found := f.stakingKeeper.GetValidatorByConsAddr(f.sdkCtx, consAddr)
|
||||
assert.Assert(t, found)
|
||||
|
||||
require.NotPanics(t, func() {
|
||||
f.stakingKeeper.Slash(f.sdkCtx, consAddr, 10, 10, fraction)
|
||||
})
|
||||
_, err = f.stakingKeeper.Slash(f.sdkCtx, consAddr, 10, 10, fraction)
|
||||
assert.NilError(t, err)
|
||||
|
||||
burnAmount := sdk.NewDecFromInt(f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, 10)).Mul(fraction).TruncateInt()
|
||||
|
||||
bondedPool = f.stakingKeeper.GetBondedPool(f.sdkCtx)
|
||||
@@ -415,9 +444,8 @@ func TestSlashWithRedelegation(t *testing.T) {
|
||||
_, found = f.stakingKeeper.GetValidatorByConsAddr(f.sdkCtx, consAddr)
|
||||
assert.Assert(t, found)
|
||||
|
||||
require.NotPanics(t, func() {
|
||||
f.stakingKeeper.Slash(f.sdkCtx, consAddr, 10, 10, math.LegacyOneDec())
|
||||
})
|
||||
_, err = f.stakingKeeper.Slash(f.sdkCtx, consAddr, 10, 10, math.LegacyOneDec())
|
||||
assert.NilError(t, err)
|
||||
burnAmount = f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, 7)
|
||||
|
||||
// read updated pool
|
||||
@@ -451,9 +479,8 @@ func TestSlashWithRedelegation(t *testing.T) {
|
||||
_, found = f.stakingKeeper.GetValidatorByConsAddr(f.sdkCtx, consAddr)
|
||||
assert.Assert(t, found)
|
||||
|
||||
require.NotPanics(t, func() {
|
||||
f.stakingKeeper.Slash(f.sdkCtx, consAddr, 10, 10, math.LegacyOneDec())
|
||||
})
|
||||
_, err = f.stakingKeeper.Slash(f.sdkCtx, consAddr, 10, 10, math.LegacyOneDec())
|
||||
assert.NilError(t, err)
|
||||
|
||||
burnAmount = sdk.NewDecFromInt(f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, 10)).Mul(math.LegacyOneDec()).TruncateInt()
|
||||
burnAmount = burnAmount.Sub(math.LegacyOneDec().MulInt(rdTokens).TruncateInt())
|
||||
@@ -486,9 +513,8 @@ func TestSlashWithRedelegation(t *testing.T) {
|
||||
validator, _ = f.stakingKeeper.GetValidatorByConsAddr(f.sdkCtx, consAddr)
|
||||
assert.Equal(t, validator.GetStatus(), types.Unbonding)
|
||||
|
||||
require.NotPanics(t, func() {
|
||||
f.stakingKeeper.Slash(f.sdkCtx, consAddr, 10, 10, math.LegacyOneDec())
|
||||
})
|
||||
_, err = f.stakingKeeper.Slash(f.sdkCtx, consAddr, 10, 10, math.LegacyOneDec())
|
||||
assert.NilError(t, err)
|
||||
|
||||
// read updated pool
|
||||
bondedPool = f.stakingKeeper.GetBondedPool(f.sdkCtx)
|
||||
@@ -513,24 +539,25 @@ func TestSlashWithRedelegation(t *testing.T) {
|
||||
func TestSlashBoth(t *testing.T) {
|
||||
f, addrDels, addrVals := bootstrapSlashTest(t, 10)
|
||||
fraction := sdk.NewDecWithPrec(5, 1)
|
||||
bondDenom := f.stakingKeeper.BondDenom(f.sdkCtx)
|
||||
bondDenom, err := f.stakingKeeper.BondDenom(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
|
||||
// set a redelegation with expiration timestamp beyond which the
|
||||
// redelegation shouldn't be slashed
|
||||
rdATokens := f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, 6)
|
||||
rdA := types.NewRedelegation(addrDels[0], addrVals[0], addrVals[1], 11, time.Unix(0, 0), rdATokens, sdk.NewDecFromInt(rdATokens), 0)
|
||||
f.stakingKeeper.SetRedelegation(f.sdkCtx, rdA)
|
||||
assert.NilError(t, f.stakingKeeper.SetRedelegation(f.sdkCtx, rdA))
|
||||
|
||||
// set the associated delegation
|
||||
delA := types.NewDelegation(addrDels[0], addrVals[1], sdk.NewDecFromInt(rdATokens))
|
||||
f.stakingKeeper.SetDelegation(f.sdkCtx, delA)
|
||||
assert.NilError(t, f.stakingKeeper.SetDelegation(f.sdkCtx, delA))
|
||||
|
||||
// set an unbonding delegation with expiration timestamp (beyond which the
|
||||
// unbonding delegation shouldn't be slashed)
|
||||
ubdATokens := f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, 4)
|
||||
ubdA := types.NewUnbondingDelegation(addrDels[0], addrVals[0], 11,
|
||||
time.Unix(0, 0), ubdATokens, 0)
|
||||
f.stakingKeeper.SetUnbondingDelegation(f.sdkCtx, ubdA)
|
||||
assert.NilError(t, f.stakingKeeper.SetUnbondingDelegation(f.sdkCtx, ubdA))
|
||||
|
||||
bondedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, rdATokens.MulRaw(2)))
|
||||
notBondedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, ubdATokens))
|
||||
@@ -552,7 +579,8 @@ func TestSlashBoth(t *testing.T) {
|
||||
_, found := f.stakingKeeper.GetValidatorByConsAddr(f.sdkCtx, sdk.GetConsAddress(PKs[0]))
|
||||
assert.Assert(t, found)
|
||||
consAddr0 := sdk.ConsAddress(PKs[0].Address())
|
||||
f.stakingKeeper.Slash(f.sdkCtx, consAddr0, 10, 10, fraction)
|
||||
_, err = f.stakingKeeper.Slash(f.sdkCtx, consAddr0, 10, 10, fraction)
|
||||
assert.NilError(t, err)
|
||||
|
||||
burnedNotBondedAmount := fraction.MulInt(ubdATokens).TruncateInt()
|
||||
burnedBondAmount := sdk.NewDecFromInt(f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, 10)).Mul(fraction).TruncateInt()
|
||||
@@ -583,11 +611,13 @@ func TestSlashAmount(t *testing.T) {
|
||||
f, _, _ := bootstrapSlashTest(t, 10)
|
||||
consAddr := sdk.ConsAddress(PKs[0].Address())
|
||||
fraction := sdk.NewDecWithPrec(5, 1)
|
||||
burnedCoins := f.stakingKeeper.Slash(f.sdkCtx, consAddr, f.sdkCtx.BlockHeight(), 10, fraction)
|
||||
burnedCoins, err := f.stakingKeeper.Slash(f.sdkCtx, consAddr, f.sdkCtx.BlockHeight(), 10, fraction)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, burnedCoins.GT(math.ZeroInt()))
|
||||
|
||||
// test the case where the validator was not found, which should return no coins
|
||||
_, addrVals := generateAddresses(f, 100)
|
||||
noBurned := f.stakingKeeper.Slash(f.sdkCtx, sdk.ConsAddress(addrVals[0]), f.sdkCtx.BlockHeight(), 10, fraction)
|
||||
noBurned, err := f.stakingKeeper.Slash(f.sdkCtx, sdk.ConsAddress(addrVals[0]), f.sdkCtx.BlockHeight(), 10, fraction)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, sdk.NewInt(0).Equal(noBurned))
|
||||
}
|
||||
|
||||
@@ -49,11 +49,11 @@ func SetupUnbondingTests(t *testing.T, f *fixture, hookCalled *bool, ubdeID *uin
|
||||
valTokens := f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, 10)
|
||||
startTokens := f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, 20)
|
||||
|
||||
bondDenom = f.stakingKeeper.BondDenom(f.sdkCtx)
|
||||
bondDenom, err := f.stakingKeeper.BondDenom(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
notBondedPool := f.stakingKeeper.GetNotBondedPool(f.sdkCtx)
|
||||
|
||||
assert.NilError(t, banktestutil.FundModuleAccount(f.sdkCtx, f.bankKeeper, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(bondDenom, startTokens))))
|
||||
f.bankKeeper.SendCoinsFromModuleToModule(f.sdkCtx, types.BondedPoolName, types.NotBondedPoolName, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, startTokens)))
|
||||
f.accountKeeper.SetModuleAccount(f.sdkCtx, notBondedPool)
|
||||
|
||||
// Create a validator
|
||||
@@ -67,7 +67,7 @@ func SetupUnbondingTests(t *testing.T, f *fixture, hookCalled *bool, ubdeID *uin
|
||||
|
||||
// Create a delegator
|
||||
delegation := types.NewDelegation(addrDels[0], addrVals[0], issuedShares1)
|
||||
f.stakingKeeper.SetDelegation(f.sdkCtx, delegation)
|
||||
assert.NilError(t, f.stakingKeeper.SetDelegation(f.sdkCtx, delegation))
|
||||
|
||||
// Create a validator to redelegate to
|
||||
validator2 := testutil.NewValidator(t, addrVals[1], PKs[1])
|
||||
@@ -110,7 +110,8 @@ func doUnbondingDelegation(
|
||||
assert.Assert(math.IntEq(t, notBondedAmt1.AddRaw(1), notBondedAmt2))
|
||||
|
||||
// Check that the unbonding happened- we look up the entry and see that it has the correct number of shares
|
||||
unbondingDelegations := stakingKeeper.GetUnbondingDelegationsFromValidator(ctx, addrVals[0])
|
||||
unbondingDelegations, err := stakingKeeper.GetUnbondingDelegationsFromValidator(ctx, addrVals[0])
|
||||
assert.NilError(t, err)
|
||||
assert.DeepEqual(t, math.NewInt(1), unbondingDelegations[0].Entries[0].Balance)
|
||||
|
||||
// check that our hook was called
|
||||
@@ -132,7 +133,8 @@ func doRedelegation(
|
||||
assert.NilError(t, err)
|
||||
|
||||
// Check that the redelegation happened- we look up the entry and see that it has the correct number of shares
|
||||
redelegations := stakingKeeper.GetRedelegationsFromSrcValidator(ctx, addrVals[0])
|
||||
redelegations, err := stakingKeeper.GetRedelegationsFromSrcValidator(ctx, addrVals[0])
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, 1, len(redelegations))
|
||||
assert.DeepEqual(t, math.LegacyNewDec(1), redelegations[0].Entries[0].SharesDst)
|
||||
|
||||
@@ -188,26 +190,28 @@ func TestValidatorUnbondingOnHold1(t *testing.T) {
|
||||
assert.NilError(t, err)
|
||||
|
||||
// Try to unbond validator
|
||||
f.stakingKeeper.UnbondAllMatureValidators(f.sdkCtx)
|
||||
assert.NilError(t, f.stakingKeeper.UnbondAllMatureValidators(f.sdkCtx))
|
||||
|
||||
// Check that validator unbonding is not complete (is not mature yet)
|
||||
validator, found := f.stakingKeeper.GetValidator(f.sdkCtx, addrVals[0])
|
||||
assert.Assert(t, found)
|
||||
assert.Equal(t, types.Unbonding, validator.Status)
|
||||
unbondingVals := f.stakingKeeper.GetUnbondingValidators(f.sdkCtx, completionTime, completionHeight)
|
||||
unbondingVals, err := f.stakingKeeper.GetUnbondingValidators(f.sdkCtx, completionTime, completionHeight)
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, 1, len(unbondingVals))
|
||||
assert.Equal(t, validator.OperatorAddress, unbondingVals[0])
|
||||
|
||||
// PROVIDER CHAIN'S UNBONDING PERIOD ENDS - BUT UNBONDING CANNOT COMPLETE
|
||||
f.sdkCtx = f.sdkCtx.WithBlockTime(completionTime.Add(time.Duration(1)))
|
||||
f.sdkCtx = f.sdkCtx.WithBlockHeight(completionHeight + 1)
|
||||
f.stakingKeeper.UnbondAllMatureValidators(f.sdkCtx)
|
||||
assert.NilError(t, f.stakingKeeper.UnbondAllMatureValidators(f.sdkCtx))
|
||||
|
||||
// Check that validator unbonding is complete
|
||||
validator, found = f.stakingKeeper.GetValidator(f.sdkCtx, addrVals[0])
|
||||
assert.Assert(t, found)
|
||||
assert.Equal(t, types.Unbonded, validator.Status)
|
||||
unbondingVals = f.stakingKeeper.GetUnbondingValidators(f.sdkCtx, completionTime, completionHeight)
|
||||
unbondingVals, err = f.stakingKeeper.GetUnbondingValidators(f.sdkCtx, completionTime, completionHeight)
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, 0, len(unbondingVals))
|
||||
}
|
||||
|
||||
@@ -246,7 +250,7 @@ func TestValidatorUnbondingOnHold2(t *testing.T) {
|
||||
// PROVIDER CHAIN'S UNBONDING PERIOD ENDS - BUT UNBONDING CANNOT COMPLETE
|
||||
f.sdkCtx = f.sdkCtx.WithBlockTime(completionTime.Add(time.Duration(1)))
|
||||
f.sdkCtx = f.sdkCtx.WithBlockHeight(completionHeight + 1)
|
||||
f.stakingKeeper.UnbondAllMatureValidators(f.sdkCtx)
|
||||
assert.NilError(t, f.stakingKeeper.UnbondAllMatureValidators(f.sdkCtx))
|
||||
|
||||
// Check that unbonding is not complete for both validators
|
||||
validator1, found := f.stakingKeeper.GetValidator(f.sdkCtx, addrVals[0])
|
||||
@@ -255,17 +259,18 @@ func TestValidatorUnbondingOnHold2(t *testing.T) {
|
||||
validator2, found = f.stakingKeeper.GetValidator(f.sdkCtx, addrVals[1])
|
||||
assert.Assert(t, found)
|
||||
assert.Equal(t, types.Unbonding, validator2.Status)
|
||||
unbondingVals := f.stakingKeeper.GetUnbondingValidators(f.sdkCtx, completionTime, completionHeight)
|
||||
unbondingVals, err := f.stakingKeeper.GetUnbondingValidators(f.sdkCtx, completionTime, completionHeight)
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, 2, len(unbondingVals))
|
||||
assert.Equal(t, validator1.OperatorAddress, unbondingVals[0])
|
||||
assert.Equal(t, validator2.OperatorAddress, unbondingVals[1])
|
||||
|
||||
// CONSUMER CHAIN'S UNBONDING PERIOD ENDS - STOPPED UNBONDING CAN NOW COMPLETE
|
||||
err := f.stakingKeeper.UnbondingCanComplete(f.sdkCtx, ubdeIDs[0])
|
||||
err = f.stakingKeeper.UnbondingCanComplete(f.sdkCtx, ubdeIDs[0])
|
||||
assert.NilError(t, err)
|
||||
|
||||
// Try again to unbond validators
|
||||
f.stakingKeeper.UnbondAllMatureValidators(f.sdkCtx)
|
||||
assert.NilError(t, f.stakingKeeper.UnbondAllMatureValidators(f.sdkCtx))
|
||||
|
||||
// Check that unbonding is complete for validator1, but not for validator2
|
||||
validator1, found = f.stakingKeeper.GetValidator(f.sdkCtx, addrVals[0])
|
||||
@@ -274,7 +279,8 @@ func TestValidatorUnbondingOnHold2(t *testing.T) {
|
||||
validator2, found = f.stakingKeeper.GetValidator(f.sdkCtx, addrVals[1])
|
||||
assert.Assert(t, found)
|
||||
assert.Equal(t, types.Unbonding, validator2.Status)
|
||||
unbondingVals = f.stakingKeeper.GetUnbondingValidators(f.sdkCtx, completionTime, completionHeight)
|
||||
unbondingVals, err = f.stakingKeeper.GetUnbondingValidators(f.sdkCtx, completionTime, completionHeight)
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, 1, len(unbondingVals))
|
||||
assert.Equal(t, validator2.OperatorAddress, unbondingVals[0])
|
||||
|
||||
@@ -283,13 +289,14 @@ func TestValidatorUnbondingOnHold2(t *testing.T) {
|
||||
assert.NilError(t, err)
|
||||
|
||||
// Try again to unbond validators
|
||||
f.stakingKeeper.UnbondAllMatureValidators(f.sdkCtx)
|
||||
assert.NilError(t, f.stakingKeeper.UnbondAllMatureValidators(f.sdkCtx))
|
||||
|
||||
// Check that unbonding is complete for validator2
|
||||
validator2, found = f.stakingKeeper.GetValidator(f.sdkCtx, addrVals[1])
|
||||
assert.Assert(t, found)
|
||||
assert.Equal(t, types.Unbonded, validator2.Status)
|
||||
unbondingVals = f.stakingKeeper.GetUnbondingValidators(f.sdkCtx, completionTime, completionHeight)
|
||||
unbondingVals, err = f.stakingKeeper.GetUnbondingValidators(f.sdkCtx, completionTime, completionHeight)
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, 0, len(unbondingVals))
|
||||
}
|
||||
|
||||
@@ -311,7 +318,8 @@ func TestRedelegationOnHold1(t *testing.T) {
|
||||
assert.NilError(t, err)
|
||||
|
||||
// Redelegation is not complete - still exists
|
||||
redelegations := f.stakingKeeper.GetRedelegationsFromSrcValidator(f.sdkCtx, addrVals[0])
|
||||
redelegations, err := f.stakingKeeper.GetRedelegationsFromSrcValidator(f.sdkCtx, addrVals[0])
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, 1, len(redelegations))
|
||||
|
||||
// PROVIDER CHAIN'S UNBONDING PERIOD ENDS - STOPPED UNBONDING CAN NOW COMPLETE
|
||||
@@ -320,7 +328,8 @@ func TestRedelegationOnHold1(t *testing.T) {
|
||||
assert.NilError(t, err)
|
||||
|
||||
// Redelegation is complete and record is gone
|
||||
redelegations = f.stakingKeeper.GetRedelegationsFromSrcValidator(f.sdkCtx, addrVals[0])
|
||||
redelegations, err = f.stakingKeeper.GetRedelegationsFromSrcValidator(f.sdkCtx, addrVals[0])
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, 0, len(redelegations))
|
||||
}
|
||||
|
||||
@@ -343,7 +352,8 @@ func TestRedelegationOnHold2(t *testing.T) {
|
||||
assert.NilError(t, err)
|
||||
|
||||
// Redelegation is not complete - still exists
|
||||
redelegations := f.stakingKeeper.GetRedelegationsFromSrcValidator(f.sdkCtx, addrVals[0])
|
||||
redelegations, err := f.stakingKeeper.GetRedelegationsFromSrcValidator(f.sdkCtx, addrVals[0])
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, 1, len(redelegations))
|
||||
|
||||
// CONSUMER CHAIN'S UNBONDING PERIOD ENDS - STOPPED UNBONDING CAN NOW COMPLETE
|
||||
@@ -351,7 +361,8 @@ func TestRedelegationOnHold2(t *testing.T) {
|
||||
assert.NilError(t, err)
|
||||
|
||||
// Redelegation is complete and record is gone
|
||||
redelegations = f.stakingKeeper.GetRedelegationsFromSrcValidator(f.sdkCtx, addrVals[0])
|
||||
redelegations, err = f.stakingKeeper.GetRedelegationsFromSrcValidator(f.sdkCtx, addrVals[0])
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, 0, len(redelegations))
|
||||
}
|
||||
|
||||
|
||||
@@ -28,8 +28,11 @@ func bootstrapValidatorTest(t testing.TB, power int64, numAddrs int) (*fixture,
|
||||
|
||||
addrDels, addrVals := generateAddresses(f, numAddrs)
|
||||
|
||||
bondDenom, err := f.stakingKeeper.BondDenom(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
|
||||
amt := f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, power)
|
||||
totalSupply := sdk.NewCoins(sdk.NewCoin(f.stakingKeeper.BondDenom(f.sdkCtx), amt.MulRaw(int64(len(addrDels)))))
|
||||
totalSupply := sdk.NewCoins(sdk.NewCoin(bondDenom, amt.MulRaw(int64(len(addrDels)))))
|
||||
|
||||
notBondedPool := f.stakingKeeper.GetNotBondedPool(f.sdkCtx)
|
||||
|
||||
@@ -65,13 +68,17 @@ func TestUpdateBondedValidatorsDecreaseCliff(t *testing.T) {
|
||||
notBondedPool := f.stakingKeeper.GetNotBondedPool(f.sdkCtx)
|
||||
|
||||
// create keeper parameters
|
||||
params := f.stakingKeeper.GetParams(f.sdkCtx)
|
||||
params, err := f.stakingKeeper.GetParams(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
params.MaxValidators = uint32(maxVals)
|
||||
f.stakingKeeper.SetParams(f.sdkCtx, params)
|
||||
assert.NilError(t, f.stakingKeeper.SetParams(f.sdkCtx, params))
|
||||
|
||||
bondDenom, err := f.stakingKeeper.BondDenom(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
|
||||
// create a random pool
|
||||
assert.NilError(t, banktestutil.FundModuleAccount(f.sdkCtx, f.bankKeeper, bondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(f.stakingKeeper.BondDenom(f.sdkCtx), f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, 1234)))))
|
||||
assert.NilError(t, banktestutil.FundModuleAccount(f.sdkCtx, f.bankKeeper, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(f.stakingKeeper.BondDenom(f.sdkCtx), f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, 10000)))))
|
||||
assert.NilError(t, banktestutil.FundModuleAccount(f.sdkCtx, f.bankKeeper, bondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(bondDenom, f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, 1234)))))
|
||||
assert.NilError(t, banktestutil.FundModuleAccount(f.sdkCtx, f.bankKeeper, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(bondDenom, f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, 10000)))))
|
||||
|
||||
f.accountKeeper.SetModuleAccount(f.sdkCtx, bondedPool)
|
||||
f.accountKeeper.SetModuleAccount(f.sdkCtx, notBondedPool)
|
||||
@@ -124,8 +131,9 @@ func TestSlashToZeroPowerRemoved(t *testing.T) {
|
||||
valTokens := f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, 100)
|
||||
|
||||
bondedPool := f.stakingKeeper.GetBondedPool(f.sdkCtx)
|
||||
|
||||
assert.NilError(t, banktestutil.FundModuleAccount(f.sdkCtx, f.bankKeeper, bondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(f.stakingKeeper.BondDenom(f.sdkCtx), valTokens))))
|
||||
bondDenom, err := f.stakingKeeper.BondDenom(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
assert.NilError(t, banktestutil.FundModuleAccount(f.sdkCtx, f.bankKeeper, bondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(bondDenom, valTokens))))
|
||||
|
||||
f.accountKeeper.SetModuleAccount(f.sdkCtx, bondedPool)
|
||||
|
||||
@@ -168,7 +176,8 @@ func TestGetValidatorSortingUnmixed(t *testing.T) {
|
||||
}
|
||||
|
||||
// first make sure everything made it in to the gotValidator group
|
||||
resValidators := f.stakingKeeper.GetBondedValidatorsByPower(f.sdkCtx)
|
||||
resValidators, err := f.stakingKeeper.GetBondedValidatorsByPower(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, n, len(resValidators))
|
||||
assert.DeepEqual(t, sdk.NewInt(400).Mul(f.stakingKeeper.PowerReduction(f.sdkCtx)), resValidators[0].BondedTokens())
|
||||
assert.DeepEqual(t, sdk.NewInt(200).Mul(f.stakingKeeper.PowerReduction(f.sdkCtx)), resValidators[1].BondedTokens())
|
||||
@@ -184,14 +193,16 @@ func TestGetValidatorSortingUnmixed(t *testing.T) {
|
||||
// test a basic increase in voting power
|
||||
validators[3].Tokens = sdk.NewInt(500).Mul(f.stakingKeeper.PowerReduction(f.sdkCtx))
|
||||
keeper.TestingUpdateValidator(f.stakingKeeper, f.sdkCtx, validators[3], true)
|
||||
resValidators = f.stakingKeeper.GetBondedValidatorsByPower(f.sdkCtx)
|
||||
resValidators, err = f.stakingKeeper.GetBondedValidatorsByPower(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, len(resValidators), n)
|
||||
assert.Assert(ValEq(t, validators[3], resValidators[0]))
|
||||
|
||||
// test a decrease in voting power
|
||||
validators[3].Tokens = sdk.NewInt(300).Mul(f.stakingKeeper.PowerReduction(f.sdkCtx))
|
||||
keeper.TestingUpdateValidator(f.stakingKeeper, f.sdkCtx, validators[3], true)
|
||||
resValidators = f.stakingKeeper.GetBondedValidatorsByPower(f.sdkCtx)
|
||||
resValidators, err = f.stakingKeeper.GetBondedValidatorsByPower(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, len(resValidators), n)
|
||||
assert.Assert(ValEq(t, validators[3], resValidators[0]))
|
||||
assert.Assert(ValEq(t, validators[4], resValidators[1]))
|
||||
@@ -200,7 +211,8 @@ func TestGetValidatorSortingUnmixed(t *testing.T) {
|
||||
validators[3].Tokens = sdk.NewInt(200).Mul(f.stakingKeeper.PowerReduction(f.sdkCtx))
|
||||
f.sdkCtx = f.sdkCtx.WithBlockHeight(10)
|
||||
keeper.TestingUpdateValidator(f.stakingKeeper, f.sdkCtx, validators[3], true)
|
||||
resValidators = f.stakingKeeper.GetBondedValidatorsByPower(f.sdkCtx)
|
||||
resValidators, err = f.stakingKeeper.GetBondedValidatorsByPower(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, len(resValidators), n)
|
||||
assert.Assert(ValEq(t, validators[3], resValidators[0]))
|
||||
assert.Assert(ValEq(t, validators[4], resValidators[1]))
|
||||
@@ -208,7 +220,8 @@ func TestGetValidatorSortingUnmixed(t *testing.T) {
|
||||
// no change in voting power - no change in sort
|
||||
f.sdkCtx = f.sdkCtx.WithBlockHeight(20)
|
||||
keeper.TestingUpdateValidator(f.stakingKeeper, f.sdkCtx, validators[4], true)
|
||||
resValidators = f.stakingKeeper.GetBondedValidatorsByPower(f.sdkCtx)
|
||||
resValidators, err = f.stakingKeeper.GetBondedValidatorsByPower(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, len(resValidators), n)
|
||||
assert.Assert(ValEq(t, validators[3], resValidators[0]))
|
||||
assert.Assert(ValEq(t, validators[4], resValidators[1]))
|
||||
@@ -217,11 +230,13 @@ func TestGetValidatorSortingUnmixed(t *testing.T) {
|
||||
validators[3].Tokens = sdk.NewInt(300).Mul(f.stakingKeeper.PowerReduction(f.sdkCtx))
|
||||
validators[4].Tokens = sdk.NewInt(300).Mul(f.stakingKeeper.PowerReduction(f.sdkCtx))
|
||||
keeper.TestingUpdateValidator(f.stakingKeeper, f.sdkCtx, validators[3], true)
|
||||
resValidators = f.stakingKeeper.GetBondedValidatorsByPower(f.sdkCtx)
|
||||
resValidators, err = f.stakingKeeper.GetBondedValidatorsByPower(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, len(resValidators), n)
|
||||
f.sdkCtx = f.sdkCtx.WithBlockHeight(30)
|
||||
keeper.TestingUpdateValidator(f.stakingKeeper, f.sdkCtx, validators[4], true)
|
||||
resValidators = f.stakingKeeper.GetBondedValidatorsByPower(f.sdkCtx)
|
||||
resValidators, err = f.stakingKeeper.GetBondedValidatorsByPower(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, len(resValidators), n, "%v", resValidators)
|
||||
assert.Assert(ValEq(t, validators[3], resValidators[0]))
|
||||
assert.Assert(ValEq(t, validators[4], resValidators[1]))
|
||||
@@ -232,16 +247,20 @@ func TestGetValidatorSortingMixed(t *testing.T) {
|
||||
bondedPool := f.stakingKeeper.GetBondedPool(f.sdkCtx)
|
||||
notBondedPool := f.stakingKeeper.GetNotBondedPool(f.sdkCtx)
|
||||
|
||||
assert.NilError(t, banktestutil.FundModuleAccount(f.sdkCtx, f.bankKeeper, bondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(f.stakingKeeper.BondDenom(f.sdkCtx), f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, 501)))))
|
||||
assert.NilError(t, banktestutil.FundModuleAccount(f.sdkCtx, f.bankKeeper, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(f.stakingKeeper.BondDenom(f.sdkCtx), f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, 0)))))
|
||||
bondDenom, err := f.stakingKeeper.BondDenom(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
|
||||
assert.NilError(t, banktestutil.FundModuleAccount(f.sdkCtx, f.bankKeeper, bondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(bondDenom, f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, 501)))))
|
||||
assert.NilError(t, banktestutil.FundModuleAccount(f.sdkCtx, f.bankKeeper, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(bondDenom, f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, 0)))))
|
||||
|
||||
f.accountKeeper.SetModuleAccount(f.sdkCtx, notBondedPool)
|
||||
f.accountKeeper.SetModuleAccount(f.sdkCtx, bondedPool)
|
||||
|
||||
// now 2 max resValidators
|
||||
params := f.stakingKeeper.GetParams(f.sdkCtx)
|
||||
params, err := f.stakingKeeper.GetParams(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
params.MaxValidators = 2
|
||||
f.stakingKeeper.SetParams(f.sdkCtx, params)
|
||||
assert.NilError(t, f.stakingKeeper.SetParams(f.sdkCtx, params))
|
||||
|
||||
// initialize some validators into the state
|
||||
amts := []math.Int{
|
||||
@@ -278,7 +297,8 @@ func TestGetValidatorSortingMixed(t *testing.T) {
|
||||
assert.Equal(t, types.Bonded, val4.Status)
|
||||
|
||||
// first make sure everything made it in to the gotValidator group
|
||||
resValidators := f.stakingKeeper.GetBondedValidatorsByPower(f.sdkCtx)
|
||||
resValidators, err := f.stakingKeeper.GetBondedValidatorsByPower(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
// The validators returned should match the max validators
|
||||
assert.Equal(t, 2, len(resValidators))
|
||||
assert.DeepEqual(t, sdk.NewInt(400).Mul(f.stakingKeeper.PowerReduction(f.sdkCtx)), resValidators[0].BondedTokens())
|
||||
@@ -292,7 +312,8 @@ func TestGetValidatorsEdgeCases(t *testing.T) {
|
||||
f, addrs, _ := bootstrapValidatorTest(t, 1000, 20)
|
||||
|
||||
// set max validators to 2
|
||||
params := f.stakingKeeper.GetParams(f.sdkCtx)
|
||||
params, err := f.stakingKeeper.GetParams(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
nMax := uint32(2)
|
||||
params.MaxValidators = nMax
|
||||
f.stakingKeeper.SetParams(f.sdkCtx, params)
|
||||
@@ -314,7 +335,8 @@ func TestGetValidatorsEdgeCases(t *testing.T) {
|
||||
}
|
||||
|
||||
// ensure that the first two bonded validators are the largest validators
|
||||
resValidators := f.stakingKeeper.GetBondedValidatorsByPower(f.sdkCtx)
|
||||
resValidators, err := f.stakingKeeper.GetBondedValidatorsByPower(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, nMax, uint32(len(resValidators)))
|
||||
assert.Assert(ValEq(t, validators[2], resValidators[0]))
|
||||
assert.Assert(ValEq(t, validators[3], resValidators[1]))
|
||||
@@ -334,7 +356,8 @@ func TestGetValidatorsEdgeCases(t *testing.T) {
|
||||
// a) validator 0 with 500 tokens
|
||||
// b) validator 2 with 400 tokens (delegated before validator 3)
|
||||
validators[0] = keeper.TestingUpdateValidator(f.stakingKeeper, f.sdkCtx, validators[0], true)
|
||||
resValidators = f.stakingKeeper.GetBondedValidatorsByPower(f.sdkCtx)
|
||||
resValidators, err = f.stakingKeeper.GetBondedValidatorsByPower(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, nMax, uint32(len(resValidators)))
|
||||
assert.Assert(ValEq(t, validators[0], resValidators[0]))
|
||||
assert.Assert(ValEq(t, validators[2], resValidators[1]))
|
||||
@@ -351,9 +374,8 @@ func TestGetValidatorsEdgeCases(t *testing.T) {
|
||||
// validator 3 enters bonded validator set
|
||||
f.sdkCtx = f.sdkCtx.WithBlockHeight(40)
|
||||
|
||||
var found bool
|
||||
validators[3], found = f.stakingKeeper.GetValidator(f.sdkCtx, validators[3].GetOperator())
|
||||
assert.Assert(t, found)
|
||||
validators[3], err = f.stakingKeeper.GetValidator(f.sdkCtx, validators[3].GetOperator())
|
||||
assert.NilError(t, err)
|
||||
f.stakingKeeper.DeleteValidatorByPowerIndex(f.sdkCtx, validators[3])
|
||||
validators[3], _ = validators[3].AddTokensFromDel(f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, 1))
|
||||
|
||||
@@ -363,7 +385,8 @@ func TestGetValidatorsEdgeCases(t *testing.T) {
|
||||
f.accountKeeper.SetModuleAccount(f.sdkCtx, notBondedPool)
|
||||
|
||||
validators[3] = keeper.TestingUpdateValidator(f.stakingKeeper, f.sdkCtx, validators[3], true)
|
||||
resValidators = f.stakingKeeper.GetBondedValidatorsByPower(f.sdkCtx)
|
||||
resValidators, err = f.stakingKeeper.GetBondedValidatorsByPower(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, nMax, uint32(len(resValidators)))
|
||||
assert.Assert(ValEq(t, validators[0], resValidators[0]))
|
||||
assert.Assert(ValEq(t, validators[3], resValidators[1]))
|
||||
@@ -378,7 +401,8 @@ func TestGetValidatorsEdgeCases(t *testing.T) {
|
||||
f.accountKeeper.SetModuleAccount(f.sdkCtx, bondedPool)
|
||||
|
||||
validators[3] = keeper.TestingUpdateValidator(f.stakingKeeper, f.sdkCtx, validators[3], true)
|
||||
resValidators = f.stakingKeeper.GetBondedValidatorsByPower(f.sdkCtx)
|
||||
resValidators, err = f.stakingKeeper.GetBondedValidatorsByPower(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, nMax, uint32(len(resValidators)))
|
||||
assert.Assert(ValEq(t, validators[0], resValidators[0]))
|
||||
assert.Assert(ValEq(t, validators[2], resValidators[1]))
|
||||
@@ -392,7 +416,8 @@ func TestGetValidatorsEdgeCases(t *testing.T) {
|
||||
f.accountKeeper.SetModuleAccount(f.sdkCtx, notBondedPool)
|
||||
|
||||
validators[3] = keeper.TestingUpdateValidator(f.stakingKeeper, f.sdkCtx, validators[3], true)
|
||||
resValidators = f.stakingKeeper.GetBondedValidatorsByPower(f.sdkCtx)
|
||||
resValidators, err = f.stakingKeeper.GetBondedValidatorsByPower(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, nMax, uint32(len(resValidators)))
|
||||
assert.Assert(ValEq(t, validators[0], resValidators[0]))
|
||||
assert.Assert(ValEq(t, validators[2], resValidators[1]))
|
||||
@@ -404,7 +429,8 @@ func TestValidatorBondHeight(t *testing.T) {
|
||||
f, addrs, _ := bootstrapValidatorTest(t, 1000, 20)
|
||||
|
||||
// now 2 max resValidators
|
||||
params := f.stakingKeeper.GetParams(f.sdkCtx)
|
||||
params, err := f.stakingKeeper.GetParams(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
params.MaxValidators = 2
|
||||
f.stakingKeeper.SetParams(f.sdkCtx, params)
|
||||
|
||||
@@ -429,7 +455,8 @@ func TestValidatorBondHeight(t *testing.T) {
|
||||
validators[1] = keeper.TestingUpdateValidator(f.stakingKeeper, f.sdkCtx, validators[1], true)
|
||||
validators[2] = keeper.TestingUpdateValidator(f.stakingKeeper, f.sdkCtx, validators[2], true)
|
||||
|
||||
resValidators := f.stakingKeeper.GetBondedValidatorsByPower(f.sdkCtx)
|
||||
resValidators, err := f.stakingKeeper.GetBondedValidatorsByPower(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, uint32(len(resValidators)), params.MaxValidators)
|
||||
|
||||
assert.Assert(ValEq(t, validators[0], resValidators[0]))
|
||||
@@ -440,7 +467,8 @@ func TestValidatorBondHeight(t *testing.T) {
|
||||
validators[1], _ = validators[1].AddTokensFromDel(delTokens)
|
||||
validators[2], _ = validators[2].AddTokensFromDel(delTokens)
|
||||
validators[2] = keeper.TestingUpdateValidator(f.stakingKeeper, f.sdkCtx, validators[2], true)
|
||||
resValidators = f.stakingKeeper.GetBondedValidatorsByPower(f.sdkCtx)
|
||||
resValidators, err = f.stakingKeeper.GetBondedValidatorsByPower(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, params.MaxValidators, uint32(len(resValidators)))
|
||||
validators[1] = keeper.TestingUpdateValidator(f.stakingKeeper, f.sdkCtx, validators[1], true)
|
||||
assert.Assert(ValEq(t, validators[0], resValidators[0]))
|
||||
@@ -449,10 +477,11 @@ func TestValidatorBondHeight(t *testing.T) {
|
||||
|
||||
func TestFullValidatorSetPowerChange(t *testing.T) {
|
||||
f, addrs, _ := bootstrapValidatorTest(t, 1000, 20)
|
||||
params := f.stakingKeeper.GetParams(f.sdkCtx)
|
||||
params, err := f.stakingKeeper.GetParams(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
max := 2
|
||||
params.MaxValidators = uint32(2)
|
||||
f.stakingKeeper.SetParams(f.sdkCtx, params)
|
||||
assert.NilError(t, f.stakingKeeper.SetParams(f.sdkCtx, params))
|
||||
|
||||
// initialize some validators into the state
|
||||
powers := []int64{0, 100, 400, 400, 200}
|
||||
@@ -464,16 +493,16 @@ func TestFullValidatorSetPowerChange(t *testing.T) {
|
||||
keeper.TestingUpdateValidator(f.stakingKeeper, f.sdkCtx, validators[i], true)
|
||||
}
|
||||
for i := range powers {
|
||||
var found bool
|
||||
validators[i], found = f.stakingKeeper.GetValidator(f.sdkCtx, validators[i].GetOperator())
|
||||
assert.Assert(t, found)
|
||||
validators[i], err = f.stakingKeeper.GetValidator(f.sdkCtx, validators[i].GetOperator())
|
||||
assert.NilError(t, err)
|
||||
}
|
||||
assert.Equal(t, types.Unbonded, validators[0].Status)
|
||||
assert.Equal(t, types.Unbonding, validators[1].Status)
|
||||
assert.Equal(t, types.Bonded, validators[2].Status)
|
||||
assert.Equal(t, types.Bonded, validators[3].Status)
|
||||
assert.Equal(t, types.Unbonded, validators[4].Status)
|
||||
resValidators := f.stakingKeeper.GetBondedValidatorsByPower(f.sdkCtx)
|
||||
resValidators, err := f.stakingKeeper.GetBondedValidatorsByPower(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, max, len(resValidators))
|
||||
assert.Assert(ValEq(t, validators[2], resValidators[0])) // in the order of txs
|
||||
assert.Assert(ValEq(t, validators[3], resValidators[1]))
|
||||
@@ -483,7 +512,8 @@ func TestFullValidatorSetPowerChange(t *testing.T) {
|
||||
tokens := f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, 600)
|
||||
validators[0], _ = validators[0].AddTokensFromDel(tokens)
|
||||
validators[0] = keeper.TestingUpdateValidator(f.stakingKeeper, f.sdkCtx, validators[0], true)
|
||||
resValidators = f.stakingKeeper.GetBondedValidatorsByPower(f.sdkCtx)
|
||||
resValidators, err = f.stakingKeeper.GetBondedValidatorsByPower(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, max, len(resValidators))
|
||||
assert.Assert(ValEq(t, validators[0], resValidators[0]))
|
||||
assert.Assert(ValEq(t, validators[2], resValidators[1]))
|
||||
@@ -661,10 +691,11 @@ func TestApplyAndReturnValidatorSetUpdatesWithCliffValidator(t *testing.T) {
|
||||
|
||||
func TestApplyAndReturnValidatorSetUpdatesNewValidator(t *testing.T) {
|
||||
f, _, _ := bootstrapValidatorTest(t, 1000, 20)
|
||||
params := f.stakingKeeper.GetParams(f.sdkCtx)
|
||||
params, err := f.stakingKeeper.GetParams(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
params.MaxValidators = uint32(3)
|
||||
|
||||
f.stakingKeeper.SetParams(f.sdkCtx, params)
|
||||
assert.NilError(t, f.stakingKeeper.SetParams(f.sdkCtx, params))
|
||||
|
||||
powers := []int64{100, 100}
|
||||
var validators [2]types.Validator
|
||||
@@ -739,10 +770,11 @@ func TestApplyAndReturnValidatorSetUpdatesNewValidator(t *testing.T) {
|
||||
|
||||
func TestApplyAndReturnValidatorSetUpdatesBondTransition(t *testing.T) {
|
||||
f, _, _ := bootstrapValidatorTest(t, 1000, 20)
|
||||
params := f.stakingKeeper.GetParams(f.sdkCtx)
|
||||
params, err := f.stakingKeeper.GetParams(f.sdkCtx)
|
||||
assert.NilError(t, err)
|
||||
params.MaxValidators = uint32(2)
|
||||
|
||||
f.stakingKeeper.SetParams(f.sdkCtx, params)
|
||||
assert.NilError(t, f.stakingKeeper.SetParams(f.sdkCtx, params))
|
||||
|
||||
powers := []int64{100, 200, 300}
|
||||
var validators [3]types.Validator
|
||||
@@ -772,9 +804,8 @@ func TestApplyAndReturnValidatorSetUpdatesBondTransition(t *testing.T) {
|
||||
// delegate to validator with lowest power but not enough to bond
|
||||
f.sdkCtx = f.sdkCtx.WithBlockHeight(1)
|
||||
|
||||
var found bool
|
||||
validators[0], found = f.stakingKeeper.GetValidator(f.sdkCtx, validators[0].GetOperator())
|
||||
assert.Assert(t, found)
|
||||
validators[0], err = f.stakingKeeper.GetValidator(f.sdkCtx, validators[0].GetOperator())
|
||||
assert.NilError(t, err)
|
||||
|
||||
f.stakingKeeper.DeleteValidatorByPowerIndex(f.sdkCtx, validators[0])
|
||||
tokens := f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, 1)
|
||||
@@ -789,8 +820,8 @@ func TestApplyAndReturnValidatorSetUpdatesBondTransition(t *testing.T) {
|
||||
// lowest power in a single block context (height)
|
||||
f.sdkCtx = f.sdkCtx.WithBlockHeight(2)
|
||||
|
||||
validators[1], found = f.stakingKeeper.GetValidator(f.sdkCtx, validators[1].GetOperator())
|
||||
assert.Assert(t, found)
|
||||
validators[1], err = f.stakingKeeper.GetValidator(f.sdkCtx, validators[1].GetOperator())
|
||||
assert.NilError(t, err)
|
||||
|
||||
f.stakingKeeper.DeleteValidatorByPowerIndex(f.sdkCtx, validators[0])
|
||||
validators[0], _ = validators[0].RemoveDelShares(validators[0].DelegatorShares)
|
||||
|
||||
@@ -167,7 +167,8 @@ func (s *SimTestSuite) TestWeightedOperations() {
|
||||
// Abonormal scenarios, where the message are created by an errors are not tested here.
|
||||
func (s *SimTestSuite) TestSimulateMsgCreateValidator() {
|
||||
require := s.Require()
|
||||
s.app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: s.app.LastBlockHeight() + 1, Hash: s.app.LastCommitID().Hash})
|
||||
_, err := s.app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: s.app.LastBlockHeight() + 1, Hash: s.app.LastCommitID().Hash})
|
||||
require.NoError(err)
|
||||
|
||||
// execute operation
|
||||
op := simulation.SimulateMsgCreateValidator(s.txConfig, s.accountKeeper, s.bankKeeper, s.stakingKeeper)
|
||||
@@ -201,17 +202,18 @@ func (s *SimTestSuite) TestSimulateMsgCancelUnbondingDelegation() {
|
||||
validator0, issuedShares := validator0.AddTokensFromDel(delTokens)
|
||||
delegator := s.accounts[2]
|
||||
delegation := types.NewDelegation(delegator.Address, validator0.GetOperator(), issuedShares)
|
||||
s.stakingKeeper.SetDelegation(ctx, delegation)
|
||||
require.NoError(s.stakingKeeper.SetDelegation(ctx, delegation))
|
||||
s.Require().NoError(s.distrKeeper.DelegatorStartingInfo.Set(ctx, collections.Join(validator0.GetOperator(), delegator.Address), distrtypes.NewDelegatorStartingInfo(2, math.LegacyOneDec(), 200)))
|
||||
|
||||
s.setupValidatorRewards(ctx, validator0.GetOperator())
|
||||
|
||||
// unbonding delegation
|
||||
udb := types.NewUnbondingDelegation(delegator.Address, validator0.GetOperator(), s.app.LastBlockHeight()+1, blockTime.Add(2*time.Minute), delTokens, 0)
|
||||
s.stakingKeeper.SetUnbondingDelegation(ctx, udb)
|
||||
require.NoError(s.stakingKeeper.SetUnbondingDelegation(ctx, udb))
|
||||
s.setupValidatorRewards(ctx, validator0.GetOperator())
|
||||
|
||||
s.app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: s.app.LastBlockHeight() + 1, Hash: s.app.LastCommitID().Hash, Time: blockTime})
|
||||
_, err := s.app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: s.app.LastBlockHeight() + 1, Hash: s.app.LastCommitID().Hash, Time: blockTime})
|
||||
require.NoError(err)
|
||||
|
||||
// execute operation
|
||||
op := simulation.SimulateMsgCancelUnbondingDelegate(s.txConfig, s.accountKeeper, s.bankKeeper, s.stakingKeeper)
|
||||
@@ -239,7 +241,8 @@ func (s *SimTestSuite) TestSimulateMsgEditValidator() {
|
||||
// setup accounts[0] as validator
|
||||
_ = s.getTestingValidator0(ctx)
|
||||
|
||||
s.app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: s.app.LastBlockHeight() + 1, Hash: s.app.LastCommitID().Hash, Time: blockTime})
|
||||
_, err := s.app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: s.app.LastBlockHeight() + 1, Hash: s.app.LastCommitID().Hash, Time: blockTime})
|
||||
require.NoError(err)
|
||||
|
||||
// execute operation
|
||||
op := simulation.SimulateMsgEditValidator(s.txConfig, s.accountKeeper, s.bankKeeper, s.stakingKeeper)
|
||||
@@ -293,12 +296,13 @@ func (s *SimTestSuite) TestSimulateMsgUndelegate() {
|
||||
validator0, issuedShares := validator0.AddTokensFromDel(delTokens)
|
||||
delegator := s.accounts[2]
|
||||
delegation := types.NewDelegation(delegator.Address, validator0.GetOperator(), issuedShares)
|
||||
s.stakingKeeper.SetDelegation(ctx, delegation)
|
||||
require.NoError(s.stakingKeeper.SetDelegation(ctx, delegation))
|
||||
s.Require().NoError(s.distrKeeper.DelegatorStartingInfo.Set(ctx, collections.Join(validator0.GetOperator(), delegator.Address), distrtypes.NewDelegatorStartingInfo(2, math.LegacyOneDec(), 200)))
|
||||
|
||||
s.setupValidatorRewards(ctx, validator0.GetOperator())
|
||||
|
||||
s.app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: s.app.LastBlockHeight() + 1, Hash: s.app.LastCommitID().Hash, Time: blockTime})
|
||||
_, err := s.app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: s.app.LastBlockHeight() + 1, Hash: s.app.LastCommitID().Hash, Time: blockTime})
|
||||
require.NoError(err)
|
||||
|
||||
// execute operation
|
||||
op := simulation.SimulateMsgUndelegate(s.txConfig, s.accountKeeper, s.bankKeeper, s.stakingKeeper)
|
||||
@@ -334,14 +338,14 @@ func (s *SimTestSuite) TestSimulateMsgBeginRedelegate() {
|
||||
// setup accounts[3] as delegator
|
||||
delegator := s.accounts[3]
|
||||
delegation := types.NewDelegation(delegator.Address, validator0.GetOperator(), issuedShares)
|
||||
s.stakingKeeper.SetDelegation(ctx, delegation)
|
||||
require.NoError(s.stakingKeeper.SetDelegation(ctx, delegation))
|
||||
s.Require().NoError(s.distrKeeper.DelegatorStartingInfo.Set(ctx, collections.Join(validator0.GetOperator(), delegator.Address), distrtypes.NewDelegatorStartingInfo(2, math.LegacyOneDec(), 200)))
|
||||
|
||||
s.setupValidatorRewards(ctx, validator0.GetOperator())
|
||||
s.setupValidatorRewards(ctx, validator1.GetOperator())
|
||||
|
||||
_, err := s.app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: s.app.LastBlockHeight() + 1, Hash: s.app.LastCommitID().Hash, Time: blockTime})
|
||||
s.Require().NoError(err)
|
||||
require.NoError(err)
|
||||
|
||||
// execute operation
|
||||
op := simulation.SimulateMsgBeginRedelegate(s.txConfig, s.accountKeeper, s.bankKeeper, s.stakingKeeper)
|
||||
@@ -382,7 +386,7 @@ func (s *SimTestSuite) getTestingValidator(ctx sdk.Context, commission types.Com
|
||||
validator.DelegatorShares = math.LegacyNewDec(100)
|
||||
validator.Tokens = s.stakingKeeper.TokensFromConsensusPower(ctx, 100)
|
||||
|
||||
s.stakingKeeper.SetValidator(ctx, validator)
|
||||
s.Require().NoError(s.stakingKeeper.SetValidator(ctx, validator))
|
||||
|
||||
return validator
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user