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

Fix test entropy #523

Merged
merged 3 commits into from
Feb 20, 2025
Merged

Fix test entropy #523

merged 3 commits into from
Feb 20, 2025

Conversation

MatheusFranco99
Copy link
Contributor

Overview

This PR fixes the test entropy, created in the Electra change, that uses randomly sorted validator indexes in messages.

Copy link
Contributor

@GalRogozinski GalRogozinski left a 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
}

@MatheusFranco99
Copy link
Contributor Author

@GalRogozinski added the generic function. Pls let me know if it's ok

Copy link
Contributor

@GalRogozinski GalRogozinski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome

Copy link
Contributor

@alan-ssvlabs alan-ssvlabs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@GalRogozinski GalRogozinski merged commit 3d6c3ac into ssvlabs:main Feb 20, 2025
2 checks passed
@GalRogozinski GalRogozinski deleted the fix-test-entropy branch February 20, 2025 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants