-
Notifications
You must be signed in to change notification settings - Fork 24
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
Fix test entropy #523
Fix test entropy #523
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we do the tests itself it is arguably fine to copy paste
but we shouldn't do it for writing utils code
maybe create a function called SortedMapKeys that uses generics, and put it in a utils file:
// SortMapByKey sorts a map by its keys and returns a sorted slice of key-value pairs.
func SortedMapKeys[K constraints.Ordered, V any](m map[K]V) []struct {
Key K
Value V
} {
// Extract and sort keys
keys := make([]K, 0, len(m))
for k := range m {
keys = append(keys, k)
}
sort.Slice(keys, func(i, j int) bool { return keys[i] < keys[j] })
// Create sorted key-value pairs
pairs := make([]struct {
Key K
Value V
}, len(keys))
for i, k := range keys {
pairs[i] = struct {
Key K
Value V
}{k, m[k]}
}
return pairs
}
@GalRogozinski added the generic function. Pls let me know if it's ok |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Overview
This PR fixes the test entropy, created in the Electra change, that uses randomly sorted validator indexes in messages.