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

chore(schema/testing): upgrade to go 1.23 iterators #21282

Merged
merged 8 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- uses: DeterminateSystems/magic-nix-cache-action@main
- uses: actions/setup-go@v5
with:
go-version: "1.22.2"
go-version: "1.23"
check-latest: true
- uses: technote-space/get-diff-action@v6.1.2
id: git_diff
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.22"
go-version: "1.23"
cache: true
cache-dependency-path: schema/testing/go.sum
- uses: technote-space/get-diff-action@v6.1.2
Expand Down
2 changes: 1 addition & 1 deletion schema/testing/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ require (

replace cosmossdk.io/schema => ./..

go 1.22
go 1.23
12 changes: 5 additions & 7 deletions schema/testing/statesim/app_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,29 @@ func DiffAppStates(expected, actual view.AppState) string {
res += fmt.Sprintf("MODULE COUNT ERROR: expected %d, got %d\n", expectNumModules, actualNumModules)
}

expected.Modules(func(expectedMod view.ModuleState, err error) bool {
for expectedMod, err := range expected.Modules {
if err != nil {
res += fmt.Sprintf("ERROR getting expected module: %s\n", err)
return true
continue
}

moduleName := expectedMod.ModuleName()
actualMod, err := actual.GetModule(moduleName)
if err != nil {
res += fmt.Sprintf("ERROR getting actual module: %s\n", err)
return true
continue
}
if actualMod == nil {
res += fmt.Sprintf("Module %s: actual module NOT FOUND\n", moduleName)
return true
continue
}

diff := DiffModuleStates(expectedMod, actualMod)
if diff != "" {
res += "Module " + moduleName + "\n"
res += indentAllLines(diff)
}

return true
})
}

return res
}
12 changes: 5 additions & 7 deletions schema/testing/statesim/module_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,29 @@ func DiffModuleStates(expected, actual view.ModuleState) string {
res += fmt.Sprintf("OBJECT COLLECTION COUNT ERROR: expected %d, got %d\n", expectedNumObjectCollections, actualNumObjectCollections)
}

expected.ObjectCollections(func(expectedColl view.ObjectCollection, err error) bool {
for expectedColl, err := range expected.ObjectCollections {
if err != nil {
res += fmt.Sprintf("ERROR getting expected object collection: %s\n", err)
return true
continue
}

objTypeName := expectedColl.ObjectType().Name
actualColl, err := actual.GetObjectCollection(objTypeName)
if err != nil {
res += fmt.Sprintf("ERROR getting actual object collection: %s\n", err)
return true
continue
}
if actualColl == nil {
res += fmt.Sprintf("Object Collection %s: actuall collection NOT FOUND\n", objTypeName)
return true
continue
}

diff := DiffObjectCollections(expectedColl, actualColl)
if diff != "" {
res += "Object Collection " + objTypeName + "\n"
res += indentAllLines(diff)
}

return true
})
}

return res
}
15 changes: 6 additions & 9 deletions schema/testing/statesim/object_coll_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"strings"

"cosmossdk.io/schema"
schematesting "cosmossdk.io/schema/testing"
"cosmossdk.io/schema/view"
)
Expand All @@ -30,29 +29,29 @@ func DiffObjectCollections(expected, actual view.ObjectCollection) string {
res += fmt.Sprintf("OBJECT COUNT ERROR: expected %d, got %d\n", expectedNumObjects, actualNumObjects)
}

expected.AllState(func(expectedUpdate schema.ObjectUpdate, err error) bool {
for expectedUpdate, err := range expected.AllState {
if err != nil {
res += fmt.Sprintf("ERROR getting expected object: %s\n", err)
return true
continue
}

keyStr := fmtObjectKey(expected.ObjectType(), expectedUpdate.Key)
actualUpdate, found, err := actual.GetObject(expectedUpdate.Key)
if err != nil {
res += fmt.Sprintf("Object %s: ERROR: %v\n", keyStr, err)
return true
continue
}
if !found {
res += fmt.Sprintf("Object %s: NOT FOUND\n", keyStr)
return true
continue
}

if expectedUpdate.Delete != actualUpdate.Delete {
res += fmt.Sprintf("Object %s: Deleted mismatch, expected %v, got %v\n", keyStr, expectedUpdate.Delete, actualUpdate.Delete)
}

if expectedUpdate.Delete {
return true
continue
}

valueDiff := schematesting.DiffObjectValues(expected.ObjectType().ValueFields, expectedUpdate.Value, actualUpdate.Value)
Expand All @@ -62,9 +61,7 @@ func DiffObjectCollections(expected, actual view.ObjectCollection) string {
res += "\n"
res += indentAllLines(valueDiff)
}

return true
})
}

return res
}
Expand Down
Loading