refactor TestMultipleUnbondingDelegationAtUniqueTimes and TestUnbondingWhenExcessValidators

This commit is contained in:
Jonathan Gimeno 2020-02-26 15:44:15 +01:00
parent 9381500fbc
commit 015fd43f51
1 changed files with 122 additions and 122 deletions

View File

@ -1205,128 +1205,128 @@ func TestMultipleUnbondingDelegationAtSameTime(t *testing.T) {
require.False(t, found) require.False(t, found)
} }
//func TestMultipleUnbondingDelegationAtUniqueTimes(t *testing.T) { func TestMultipleUnbondingDelegationAtUniqueTimes(t *testing.T) {
// ctx, _, _, keeper, _ := CreateTestInput(t, false, 1000) app, ctx, _, valAddrs := bootstrapHandlerGenesisTest(t, 1000, 1, 1000000000)
// handler := NewHandler(keeper) handler := staking.NewHandler(app.StakingKeeper)
// valAddr := sdk.ValAddress(Addrs[0]) valAddr := valAddrs[0]
//
// // set the unbonding time // set the unbonding time
// params := keeper.GetParams(ctx) params := app.StakingKeeper.GetParams(ctx)
// params.UnbondingTime = 10 * time.Second params.UnbondingTime = 10 * time.Second
// keeper.SetParams(ctx, params) app.StakingKeeper.SetParams(ctx, params)
//
// // create the validator // create the validator
// valTokens := sdk.TokensFromConsensusPower(10) valTokens := sdk.TokensFromConsensusPower(10)
// msgCreateValidator := NewTestMsgCreateValidator(valAddr, PKs[0], valTokens) msgCreateValidator := NewTestMsgCreateValidator(valAddr, PKs[0], valTokens)
// res, err := handler(ctx, msgCreateValidator) res, err := handler(ctx, msgCreateValidator)
// require.NoError(t, err) require.NoError(t, err)
// require.NotNil(t, res) require.NotNil(t, res)
//
// // end block to bond // end block to bond
// EndBlocker(ctx, keeper) staking.EndBlocker(ctx, app.StakingKeeper)
//
// // begin an unbonding delegation // begin an unbonding delegation
// selfDelAddr := sdk.AccAddress(valAddr) // (the validator is it's own delegator) selfDelAddr := sdk.AccAddress(valAddr) // (the validator is it's own delegator)
// unbondAmt := sdk.NewCoin(sdk.DefaultBondDenom, valTokens.QuoRaw(2)) unbondAmt := sdk.NewCoin(sdk.DefaultBondDenom, valTokens.QuoRaw(2))
// msgUndelegate := NewMsgUndelegate(selfDelAddr, valAddr, unbondAmt) msgUndelegate := staking.NewMsgUndelegate(selfDelAddr, valAddr, unbondAmt)
// res, err = handler(ctx, msgUndelegate) res, err = handler(ctx, msgUndelegate)
// require.NoError(t, err) require.NoError(t, err)
// require.NotNil(t, res) require.NotNil(t, res)
//
// // there should only be one entry in the ubd object // there should only be one entry in the ubd object
// ubd, found := keeper.GetUnbondingDelegation(ctx, selfDelAddr, valAddr) ubd, found := app.StakingKeeper.GetUnbondingDelegation(ctx, selfDelAddr, valAddr)
// require.True(t, found) require.True(t, found)
// require.Len(t, ubd.Entries, 1) require.Len(t, ubd.Entries, 1)
//
// // move forwaubd in time and start a second redelegation // move forwaubd in time and start a second redelegation
// ctx = ctx.WithBlockTime(ctx.BlockHeader().Time.Add(5 * time.Second)) ctx = ctx.WithBlockTime(ctx.BlockHeader().Time.Add(5 * time.Second))
// res, err = handler(ctx, msgUndelegate) res, err = handler(ctx, msgUndelegate)
// require.NoError(t, err) require.NoError(t, err)
// require.NotNil(t, res) require.NotNil(t, res)
//
// // now there should be two entries // now there should be two entries
// ubd, found = keeper.GetUnbondingDelegation(ctx, selfDelAddr, valAddr) ubd, found = app.StakingKeeper.GetUnbondingDelegation(ctx, selfDelAddr, valAddr)
// require.True(t, found) require.True(t, found)
// require.Len(t, ubd.Entries, 2) require.Len(t, ubd.Entries, 2)
//
// // move forwaubd in time, should complete the first redelegation, but not the second // move forwaubd in time, should complete the first redelegation, but not the second
// ctx = ctx.WithBlockTime(ctx.BlockHeader().Time.Add(5 * time.Second)) ctx = ctx.WithBlockTime(ctx.BlockHeader().Time.Add(5 * time.Second))
// EndBlocker(ctx, keeper) staking.EndBlocker(ctx, app.StakingKeeper)
// ubd, found = keeper.GetUnbondingDelegation(ctx, selfDelAddr, valAddr) ubd, found = app.StakingKeeper.GetUnbondingDelegation(ctx, selfDelAddr, valAddr)
// require.True(t, found) require.True(t, found)
// require.Len(t, ubd.Entries, 1) require.Len(t, ubd.Entries, 1)
//
// // move forwaubd in time, should complete the second redelegation // move forwaubd in time, should complete the second redelegation
// ctx = ctx.WithBlockTime(ctx.BlockHeader().Time.Add(5 * time.Second)) ctx = ctx.WithBlockTime(ctx.BlockHeader().Time.Add(5 * time.Second))
// EndBlocker(ctx, keeper) staking.EndBlocker(ctx, app.StakingKeeper)
// ubd, found = keeper.GetUnbondingDelegation(ctx, selfDelAddr, valAddr) ubd, found = app.StakingKeeper.GetUnbondingDelegation(ctx, selfDelAddr, valAddr)
// require.False(t, found) require.False(t, found)
//} }
//
//func TestUnbondingWhenExcessValidators(t *testing.T) { func TestUnbondingWhenExcessValidators(t *testing.T) {
// ctx, _, _, keeper, _ := CreateTestInput(t, false, 1000) app, ctx, _, valAddrs := bootstrapHandlerGenesisTest(t, 1000, 3, 1000000000)
// handler := NewHandler(keeper) handler := staking.NewHandler(app.StakingKeeper)
//
// validatorAddr1 := sdk.ValAddress(Addrs[0]) validatorAddr1 := valAddrs[0]
// validatorAddr2 := sdk.ValAddress(Addrs[1]) validatorAddr2 := valAddrs[1]
// validatorAddr3 := sdk.ValAddress(Addrs[2]) validatorAddr3 := valAddrs[2]
//
// // set the unbonding time // set the unbonding time
// params := keeper.GetParams(ctx) params := app.StakingKeeper.GetParams(ctx)
// params.MaxValidators = 2 params.MaxValidators = 2
// keeper.SetParams(ctx, params) app.StakingKeeper.SetParams(ctx, params)
//
// // add three validators // add three validators
// valTokens1 := sdk.TokensFromConsensusPower(50) valTokens1 := sdk.TokensFromConsensusPower(50)
// msgCreateValidator := NewTestMsgCreateValidator(validatorAddr1, PKs[0], valTokens1) msgCreateValidator := NewTestMsgCreateValidator(validatorAddr1, PKs[0], valTokens1)
// res, err := handler(ctx, msgCreateValidator) res, err := handler(ctx, msgCreateValidator)
// require.NoError(t, err) require.NoError(t, err)
// require.NotNil(t, res) require.NotNil(t, res)
//
// // apply TM updates // apply TM updates
// keeper.ApplyAndReturnValidatorSetUpdates(ctx) app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
// require.Equal(t, 1, len(keeper.GetLastValidators(ctx))) require.Equal(t, 1, len(app.StakingKeeper.GetLastValidators(ctx)))
//
// valTokens2 := sdk.TokensFromConsensusPower(30) valTokens2 := sdk.TokensFromConsensusPower(30)
// msgCreateValidator = NewTestMsgCreateValidator(validatorAddr2, PKs[1], valTokens2) msgCreateValidator = NewTestMsgCreateValidator(validatorAddr2, PKs[1], valTokens2)
// res, err = handler(ctx, msgCreateValidator) res, err = handler(ctx, msgCreateValidator)
// require.NoError(t, err) require.NoError(t, err)
// require.NotNil(t, res) require.NotNil(t, res)
//
// // apply TM updates // apply TM updates
// keeper.ApplyAndReturnValidatorSetUpdates(ctx) app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
// require.Equal(t, 2, len(keeper.GetLastValidators(ctx))) require.Equal(t, 2, len(app.StakingKeeper.GetLastValidators(ctx)))
//
// valTokens3 := sdk.TokensFromConsensusPower(10) valTokens3 := sdk.TokensFromConsensusPower(10)
// msgCreateValidator = NewTestMsgCreateValidator(validatorAddr3, PKs[2], valTokens3) msgCreateValidator = NewTestMsgCreateValidator(validatorAddr3, PKs[2], valTokens3)
// res, err = handler(ctx, msgCreateValidator) res, err = handler(ctx, msgCreateValidator)
// require.NoError(t, err) require.NoError(t, err)
// require.NotNil(t, res) require.NotNil(t, res)
//
// // apply TM updates // apply TM updates
// keeper.ApplyAndReturnValidatorSetUpdates(ctx) app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
// require.Equal(t, 2, len(keeper.GetLastValidators(ctx))) require.Equal(t, 2, len(app.StakingKeeper.GetLastValidators(ctx)))
//
// // unbond the validator-2 // unbond the validator-2
// unbondAmt := sdk.NewCoin(sdk.DefaultBondDenom, valTokens2) unbondAmt := sdk.NewCoin(sdk.DefaultBondDenom, valTokens2)
// msgUndelegate := NewMsgUndelegate(sdk.AccAddress(validatorAddr2), validatorAddr2, unbondAmt) msgUndelegate := types.NewMsgUndelegate(sdk.AccAddress(validatorAddr2), validatorAddr2, unbondAmt)
// res, err = handler(ctx, msgUndelegate) res, err = handler(ctx, msgUndelegate)
// require.NoError(t, err) require.NoError(t, err)
// require.NotNil(t, res) require.NotNil(t, res)
//
// // apply TM updates // apply TM updates
// keeper.ApplyAndReturnValidatorSetUpdates(ctx) app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
//
// // because there are extra validators waiting to get in, the queued // because there are extra validators waiting to get in, the queued
// // validator (aka. validator-1) should make it into the bonded group, thus // validator (aka. validator-1) should make it into the bonded group, thus
// // the total number of validators should stay the same // the total number of validators should stay the same
// vals := keeper.GetLastValidators(ctx) vals := app.StakingKeeper.GetLastValidators(ctx)
// require.Equal(t, 2, len(vals), "vals %v", vals) require.Equal(t, 2, len(vals), "vals %v", vals)
// val1, found := keeper.GetValidator(ctx, validatorAddr1) val1, found := app.StakingKeeper.GetValidator(ctx, validatorAddr1)
// require.True(t, found) require.True(t, found)
// require.Equal(t, sdk.Bonded, val1.Status, "%v", val1) require.Equal(t, sdk.Bonded, val1.Status, "%v", val1)
//} }
//
//func TestBondUnbondRedelegateSlashTwice(t *testing.T) { //func TestBondUnbondRedelegateSlashTwice(t *testing.T) {
// ctx, _, _, keeper, _ := CreateTestInput(t, false, 1000) // ctx, _, _, keeper, _ := CreateTestInput(t, false, 1000)
// handler := NewHandler(keeper) // handler := NewHandler(keeper)