Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unbonding ops are put on hold even w/o consumer chains #118

Merged
merged 2 commits into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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