Skip to content

Commit

Permalink
chore(schema/testing): upgrade to go 1.23 iterators (#21282)
Browse files Browse the repository at this point in the history
Co-authored-by: Julien Robert <julien@rbrt.fr>
  • Loading branch information
aaronc and julienrbrt authored Aug 15, 2024
1 parent 858ec2f commit 0f39b4e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 23 deletions.
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

0 comments on commit 0f39b4e

Please sign in to comment.