Skip to content

Commit

Permalink
fix: update pending undelegations when nil after unmarshaling
Browse files Browse the repository at this point in the history
  • Loading branch information
red-0ne committed May 9, 2024
1 parent cb5c706 commit af411fc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions x/application/keeper/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ func (k Keeper) GetAllApplications(ctx context.Context) (apps []types.Applicatio
for ; iterator.Valid(); iterator.Next() {
var app types.Application
k.cdc.MustUnmarshal(iterator.Value(), &app)

// Ensure that the PendingUndelegations is an empty map and not nil when
// unmarshalling an app that has no pending undelegations.
if app.PendingUndelegations == nil {
app.PendingUndelegations = make(map[uint64]types.UndelegatingGatewayList)
}

apps = append(apps, app)
}

Expand Down
2 changes: 2 additions & 0 deletions x/application/keeper/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ func createNApplications(keeper keeper.Keeper, ctx context.Context, n int) []typ
apps := make([]types.Application, n)
for i := range apps {
apps[i].Address = strconv.Itoa(i)
// Setting pending undelegations since nullify.Fill does not seem to do it.
apps[i].PendingUndelegations = make(map[uint64]types.UndelegatingGatewayList)

keeper.SetApplication(ctx, apps[i])
}
Expand Down
6 changes: 6 additions & 0 deletions x/application/keeper/query_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ func (k Keeper) AllApplications(ctx context.Context, req *types.QueryAllApplicat
return err
}

// Ensure that the PendingUndelegations is an empty map and not nil when
// unmarshalling an app that has no pending undelegations.
if application.PendingUndelegations == nil {
application.PendingUndelegations = make(map[uint64]types.UndelegatingGatewayList)
}

apps = append(apps, application)
return nil
})
Expand Down

0 comments on commit af411fc

Please sign in to comment.