Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sontrinh16 committed Dec 2, 2024
1 parent 1ed4b64 commit a7ee203
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
3 changes: 3 additions & 0 deletions x/accounts/defaults/lockup/continuous_locking_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ func TestContinousAccountUndelegate(t *testing.T) {
err = acc.CheckUbdEntriesMature(sdkCtx)
require.NoError(t, err)

_, err = acc.UnbondEntries.Get(sdkCtx, "val_address")
require.Error(t, err)

delLocking, err = acc.DelegatedLocking.Get(ctx, "test")
require.NoError(t, err)
require.True(t, delLocking.Equal(math.ZeroInt()))
Expand Down
3 changes: 3 additions & 0 deletions x/accounts/defaults/lockup/delayed_locking_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ func TestDelayedAccountUndelegate(t *testing.T) {
err = acc.CheckUbdEntriesMature(sdkCtx)
require.NoError(t, err)

_, err = acc.UnbondEntries.Get(sdkCtx, "val_address")
require.Error(t, err)

delLocking, err = acc.DelegatedLocking.Get(ctx, "test")
require.NoError(t, err)
require.True(t, delLocking.Equal(math.ZeroInt()))
Expand Down
13 changes: 9 additions & 4 deletions x/accounts/defaults/lockup/lockup.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ func (bva *BaseLockup) CheckUbdEntriesMature(ctx context.Context) error {

currentTime := bva.headerService.HeaderInfo(ctx).Time

removeKeys := []string{}
err = bva.UnbondEntries.Walk(ctx, nil, func(key string, value lockuptypes.UnbondingEntries) (stop bool, err error) {
for i := 0; i < len(value.Entries); i++ {
entry := value.Entries[i]
Expand Down Expand Up @@ -524,10 +525,7 @@ func (bva *BaseLockup) CheckUbdEntriesMature(ctx context.Context) error {
}

if len(value.Entries) == 0 {
err = bva.UnbondEntries.Remove(ctx, key)
if err != nil {
return true, err
}
removeKeys = append(removeKeys, key)
} else {
err = bva.UnbondEntries.Set(ctx, key, value)
if err != nil {
Expand All @@ -537,6 +535,13 @@ func (bva *BaseLockup) CheckUbdEntriesMature(ctx context.Context) error {

return false, nil
})

for _, key := range removeKeys {
err = bva.UnbondEntries.Remove(ctx, key)
if err != nil {
return err
}
}
return err
}

Expand Down
3 changes: 3 additions & 0 deletions x/accounts/defaults/lockup/periodic_locking_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ func TestPeriodicAccountUndelegate(t *testing.T) {
err = acc.CheckUbdEntriesMature(sdkCtx)
require.NoError(t, err)

_, err = acc.UnbondEntries.Get(sdkCtx, "val_address")
require.Error(t, err)

delLocking, err = acc.DelegatedLocking.Get(ctx, "test")
require.NoError(t, err)
require.True(t, delLocking.Equal(math.ZeroInt()))
Expand Down
3 changes: 3 additions & 0 deletions x/accounts/defaults/lockup/permanent_locking_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ func TestPermanentAccountUndelegate(t *testing.T) {
err = acc.CheckUbdEntriesMature(sdkCtx)
require.NoError(t, err)

_, err = acc.UnbondEntries.Get(sdkCtx, "val_address")
require.Error(t, err)

delLocking, err = acc.DelegatedLocking.Get(ctx, "test")
require.NoError(t, err)
require.True(t, delLocking.Equal(math.ZeroInt()))
Expand Down

0 comments on commit a7ee203

Please sign in to comment.