Skip to content

Commit

Permalink
Unbonding ops are put on hold even w/o consumer chains (#118)
Browse files Browse the repository at this point in the history
* conditional PutUnbondingOnHold and test

* change if condition
  • Loading branch information
mpoke authored Jun 3, 2022
1 parent 5acf1ee commit f0de0c5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions x/ccv/provider/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
30 changes: 30 additions & 0 deletions x/ccv/provider/unbonding_hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit f0de0c5

Please sign in to comment.