refactor TestEditValidatorIncreaseMinSelfDelegationBeyondCurrentBond

This commit is contained in:
Jonathan Gimeno 2020-02-26 15:08:43 +01:00
parent 8ecd5b8954
commit a07ed83dd2
1 changed files with 35 additions and 34 deletions

View File

@ -421,40 +421,41 @@ func TestEditValidatorDecreaseMinSelfDelegation(t *testing.T) {
require.Nil(t, res)
}
//func TestEditValidatorIncreaseMinSelfDelegationBeyondCurrentBond(t *testing.T) {
// validatorAddr := sdk.ValAddress(Addrs[0])
//
// initPower := int64(100)
// initBond := sdk.TokensFromConsensusPower(100)
// ctx, _, _, keeper, _ := CreateTestInput(t, false, initPower)
// handler := NewHandler(keeper)
//
// // create validator
// msgCreateValidator := NewTestMsgCreateValidator(validatorAddr, PKs[0], initBond)
// msgCreateValidator.MinSelfDelegation = sdk.NewInt(2)
// res, err := handler(ctx, msgCreateValidator)
// require.NoError(t, err)
// require.NotNil(t, res)
//
// // must end-block
// updates := keeper.ApplyAndReturnValidatorSetUpdates(ctx)
// require.Equal(t, 1, len(updates))
//
// // verify the self-delegation exists
// bond, found := keeper.GetDelegation(ctx, sdk.AccAddress(validatorAddr), validatorAddr)
// require.True(t, found)
// gotBond := bond.Shares.RoundInt()
// require.Equal(t, initBond, gotBond,
// "initBond: %v\ngotBond: %v\nbond: %v\n",
// initBond, gotBond, bond)
//
// newMinSelfDelegation := initBond.Add(sdk.OneInt())
// msgEditValidator := NewMsgEditValidator(validatorAddr, Description{}, nil, &newMinSelfDelegation)
// res, err = handler(ctx, msgEditValidator)
// require.Error(t, err)
// require.Nil(t, res)
//}
//
func TestEditValidatorIncreaseMinSelfDelegationBeyondCurrentBond(t *testing.T) {
initPower := int64(100)
initBond := sdk.TokensFromConsensusPower(100)
app, ctx, _, valAddrs := bootstrapHandlerGenesisTest(t, initPower, 2, 1000000000)
validatorAddr := valAddrs[0]
handler := staking.NewHandler(app.StakingKeeper)
// create validator
msgCreateValidator := NewTestMsgCreateValidator(validatorAddr, PKs[0], initBond)
msgCreateValidator.MinSelfDelegation = sdk.NewInt(2)
res, err := handler(ctx, msgCreateValidator)
require.NoError(t, err)
require.NotNil(t, res)
// must end-block
updates := app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
require.Equal(t, 1, len(updates))
// verify the self-delegation exists
bond, found := app.StakingKeeper.GetDelegation(ctx, sdk.AccAddress(validatorAddr), validatorAddr)
require.True(t, found)
gotBond := bond.Shares.RoundInt()
require.Equal(t, initBond, gotBond,
"initBond: %v\ngotBond: %v\nbond: %v\n",
initBond, gotBond, bond)
newMinSelfDelegation := initBond.Add(sdk.OneInt())
msgEditValidator := types.NewMsgEditValidator(validatorAddr, types.Description{}, nil, &newMinSelfDelegation)
res, err = handler(ctx, msgEditValidator)
require.Error(t, err)
require.Nil(t, res)
}
//func TestIncrementsMsgUnbond(t *testing.T) {
// initPower := int64(1000)
// initBond := sdk.TokensFromConsensusPower(initPower)