From f0de0c5c5033f44d2a86df520907de313bd51557 Mon Sep 17 00:00:00 2001 From: Marius Poke Date: Fri, 3 Jun 2022 15:00:10 +0200 Subject: [PATCH] Unbonding ops are put on hold even w/o consumer chains (#118) * conditional PutUnbondingOnHold and test * change if condition --- x/ccv/provider/keeper/keeper.go | 4 ++++ x/ccv/provider/unbonding_hook_test.go | 30 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/x/ccv/provider/keeper/keeper.go b/x/ccv/provider/keeper/keeper.go index 4119a54a62..7509d9d622 100644 --- a/x/ccv/provider/keeper/keeper.go +++ b/x/ccv/provider/keeper/keeper.go @@ -433,6 +433,10 @@ func (h StakingHooks) AfterUnbondingInitiated(ctx sdk.Context, ID uint64) { consumerChainIDS = append(consumerChainIDS, chainID) return false }) + if len(consumerChainIDS) == 0 { + // Do not put the unbonding op on hold if there are no consumer chains + return + } valsetUpdateID := h.k.GetValidatorSetUpdateId(ctx) unbondingOp := ccv.UnbondingOp{ Id: ID, diff --git a/x/ccv/provider/unbonding_hook_test.go b/x/ccv/provider/unbonding_hook_test.go index 6c688b7429..8b377a2d6c 100644 --- a/x/ccv/provider/unbonding_hook_test.go +++ b/x/ccv/provider/unbonding_hook_test.go @@ -243,6 +243,36 @@ func (s *ProviderTestSuite) TestUnbondingEdgeCase() { s.Require().True(getBalance(s, newProviderCtx, delAddr).Equal(initBalance)) } +// Bond some tokens on provider +// Unbond them to create unbonding op +// Check unbonding ops on both sides +// Advance time so that provider's unbonding op completes +// Check that unbonding has completed in provider staking +func (s *ProviderTestSuite) TestUnbondingNoConsumer() { + origTime := s.ctx.BlockTime() + + bondAmt := sdk.NewInt(10000000) + delAddr := s.providerChain.SenderAccount.GetAddress() + // delegate bondAmt and undelegate 1/2 of it + initBalance, valsetUpdateID := bondAndUnbond(s, delAddr, bondAmt, 2) + + // check that staking unbonding op was created and onHold is false + checkStakingUnbondingOps(s, 1, true, false) + + // check that CCV unbonding op was not created + checkCCVUnbondingOp(s, s.providerCtx(), s.consumerChain.ChainID, valsetUpdateID, false) + + // END PROVIDER UNBONDING + newProviderCtx := endProviderUnbondingPeriod(s, origTime) + + // CHECK THAT UNBONDING IS COMPLETE + // Check that staking unbonding op has been deleted + checkStakingUnbondingOps(s, valsetUpdateID, false, false) + + // Check that half the coins have been returned + s.Require().True(getBalance(s, newProviderCtx, delAddr).Equal(initBalance.Sub(bondAmt.Quo(sdk.NewInt(2))))) +} + func getBalance(s *ProviderTestSuite, providerCtx sdk.Context, delAddr sdk.AccAddress) sdk.Int { return s.providerChain.App.(*appProvider.App).BankKeeper.GetBalance(providerCtx, delAddr, s.providerBondDenom()).Amount }