Skip to content

Fix test entropy#523

Merged
GalRogozinski merged 3 commits intossvlabs:mainfrom
MFrancoLink:fix-test-entropy
Feb 20, 2025
Merged

Fix test entropy#523
GalRogozinski merged 3 commits intossvlabs:mainfrom
MFrancoLink:fix-test-entropy

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