Problem: nondeterministic default fork value when generate genesis (#15151)

* Problem: nondeterministic default fork value when generate genesis

add sort versions

* add doc

* Apply suggestions from code review

* lint

---------

Co-authored-by: Bastin <43618253+Inspector-Butters@users.noreply.github.com>
This commit is contained in:
mmsqe
2025-04-17 00:33:48 +08:00
committed by GitHub
parent 8418157f8a
commit d4469d17b7
4 changed files with 35 additions and 1 deletions

View File

@@ -0,0 +1,3 @@
### Fixed
- avoid nondeterministic default fork value when generate genesis. [[PR]](https://github.com/prysmaticlabs/prysm/pull/15151)

View File

@@ -26,4 +26,5 @@ go_test(
name = "go_default_test",
srcs = ["fork_test.go"],
embed = [":go_default_library"],
deps = ["@com_github_stretchr_testify//assert:go_default_library"],
)

View File

@@ -1,6 +1,8 @@
package version
import (
"sort"
"github.com/pkg/errors"
)
@@ -63,4 +65,5 @@ func init() {
stringToVersion[s] = v
i++
}
sort.Ints(allVersions)
}

View File

@@ -1,6 +1,12 @@
package version
import "testing"
import (
"slices"
"sort"
"testing"
"github.com/stretchr/testify/assert"
)
func TestVersionString(t *testing.T) {
tests := []struct {
@@ -27,3 +33,24 @@ func TestVersionString(t *testing.T) {
})
}
}
func TestVersionSorting(t *testing.T) {
versions := All()
expected := slices.Clone(versions)
sort.Ints(expected)
tests := []struct {
name string
expected []int
}{
{
name: "allVersions sorted in ascending order",
expected: expected,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.expected, versions, "allVersions should match expected order")
})
}
}