Skip to content

Commit

Permalink
Removed Epoch Unbonding Record's with Zero Amount (#612)
Browse files Browse the repository at this point in the history
  • Loading branch information
sampocs committed Feb 16, 2023
1 parent dfc5fb0 commit 470268d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion x/stakeibc/keeper/unbonding_records.go
Expand Up @@ -284,7 +284,7 @@ func (k Keeper) CleanupEpochUnbondingRecords(ctx sdk.Context, epochNumber uint64
for _, hostZoneUnbonding := range hostZoneUnbondings {
// if an EpochUnbondingRecord has any HostZoneUnbonding with non-zero balances, we don't delete the EpochUnbondingRecord
// because it has outstanding tokens that need to be claimed
if hostZoneUnbonding.NativeTokenAmount != sdkmath.ZeroInt() {
if !hostZoneUnbonding.NativeTokenAmount.Equal(sdkmath.ZeroInt()) {
shouldDeleteEpochUnbondingRecord = false
break
}
Expand Down
27 changes: 17 additions & 10 deletions x/stakeibc/keeper/unbonding_records_cleanup_test.go
Expand Up @@ -89,14 +89,21 @@ func (s *KeeperTestSuite) SetupCleanupEpochUnbondingRecords() CleanupEpochUnbond
}
}

func (s *KeeperTestSuite) CleanupEpochUnbondingRecords_Successful() {
// successfully clean up epoch unbonding records
tc := s.SetupGetHostZoneUnbondingMsgs()
// clean up epoch unbonding record 0
success := s.App.StakeibcKeeper.CleanupEpochUnbondingRecords(s.Ctx, 0)
s.Require().True(success, "cleanup unbonding records returns true")
epochUnbondings := tc.epochUnbondingRecords
s.Require().Len(epochUnbondings, 1, "only one epoch unbonding record should be left")
epochUnbonding := epochUnbondings[0]
s.Require().Equal(1, epochUnbonding.EpochNumber, "correct unbonding record remains unprocessed")
func (s *KeeperTestSuite) TestCleanupEpochUnbondingRecords_Successful() {
tc := s.SetupCleanupEpochUnbondingRecords()

// Call cleanup on each unbonding record
for i := range tc.epochUnbondingRecords {
success := s.App.StakeibcKeeper.CleanupEpochUnbondingRecords(s.Ctx, uint64(i))
s.Require().True(success, "cleanup unbonding record for epoch %d should succeed", i)
}

// Check one record was removed
finalUnbondingRecords := s.App.RecordsKeeper.GetAllEpochUnbondingRecord(s.Ctx)
expectedNumUnbondingRecords := len(tc.epochUnbondingRecords) - 1
s.Require().Len(finalUnbondingRecords, expectedNumUnbondingRecords, "two epoch unbonding records should remain")

// Confirm it was the last record that was removed
_, found := s.App.RecordsKeeper.GetEpochUnbondingRecord(s.Ctx, uint64(2))
s.Require().False(found, "removed record should not be found")
}

0 comments on commit 470268d

Please sign in to comment.