mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-20 05:41:35 +00:00
refactor(params): make LibEVMVersion a constant (#162)
> [!NOTE] > This will be merged into `main` once the current target branch has been merged. ## Why this should be merged My original implementation was back to front and it's been bugging me. ## How this works Originally `params.LibEVMVersion` was a `var` (because it needed to be computed) and the test used a `const`. This change simply inverts the two and moves some code around without any change in logic. I bumped the minor version to 2 (a no-op when not on a release branch) to bring it in line with the latest release candidate and to avoid forgetting to do so when performing an actual release. ## How this was tested Unit test of version-string constant.
This commit is contained in:
parent
08490a9b76
commit
0ed61356ed
6 changed files with 36 additions and 55 deletions
2
.github/workflows/go.yml
vendored
2
.github/workflows/go.yml
vendored
|
|
@ -5,8 +5,6 @@ on:
|
|||
branches: [main, "release/**"]
|
||||
pull_request:
|
||||
branches: [main, "release/**"]
|
||||
merge_group:
|
||||
types: [checks_requested]
|
||||
workflow_dispatch:
|
||||
|
||||
concurrency:
|
||||
|
|
|
|||
2
.github/workflows/libevm-delta.yml
vendored
2
.github/workflows/libevm-delta.yml
vendored
|
|
@ -5,8 +5,6 @@ on:
|
|||
branches: [main, "release/**"]
|
||||
pull_request:
|
||||
branches: [main, "release/**"]
|
||||
merge_group:
|
||||
types: [checks_requested]
|
||||
workflow_dispatch:
|
||||
|
||||
concurrency:
|
||||
|
|
|
|||
2
.github/workflows/lint.yml
vendored
2
.github/workflows/lint.yml
vendored
|
|
@ -5,8 +5,6 @@ on:
|
|||
branches: [main, "release/**"]
|
||||
pull_request:
|
||||
branches: [main, "release/**"]
|
||||
merge_group:
|
||||
types: [checks_requested]
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/ava-labs/libevm/common"
|
||||
"github.com/ava-labs/libevm/libevm/pseudo"
|
||||
"github.com/ava-labs/libevm/libevm/register"
|
||||
"github.com/ava-labs/libevm/libevm/testonly"
|
||||
|
|
@ -366,8 +365,3 @@ func (e *StateAccountExtra) Format(s fmt.State, verb rune) {
|
|||
}
|
||||
_, _ = s.Write([]byte(out))
|
||||
}
|
||||
|
||||
// RLPHash returns the hash of the RLP encoding of `x`.
|
||||
func RLPHash(x any) common.Hash {
|
||||
return rlpHash(x)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,11 +16,9 @@
|
|||
|
||||
package params
|
||||
|
||||
import "fmt"
|
||||
|
||||
const (
|
||||
LibEVMVersionMajor = 0
|
||||
LibEVMVersionMinor = 1
|
||||
LibEVMVersionMinor = 2
|
||||
LibEVMVersionPatch = 0
|
||||
|
||||
LibEVMReleaseType ReleaseType = BetaRelease
|
||||
|
|
@ -50,23 +48,7 @@ const (
|
|||
// triplet.
|
||||
//
|
||||
// [semver v2]: https://semver.org/
|
||||
var LibEVMVersion = func() string {
|
||||
v := libEVMSemver{
|
||||
geth: semverTriplet{VersionMajor, VersionMinor, VersionPatch},
|
||||
libEVM: semverTriplet{LibEVMVersionMajor, LibEVMVersionMinor, LibEVMVersionPatch},
|
||||
typ: LibEVMReleaseType,
|
||||
rc: libEVMReleaseCandidate,
|
||||
}
|
||||
return v.String()
|
||||
}()
|
||||
|
||||
type semverTriplet struct {
|
||||
major, minor, patch uint
|
||||
}
|
||||
|
||||
func (t semverTriplet) String() string {
|
||||
return fmt.Sprintf("%d.%d.%d", t.major, t.minor, t.patch)
|
||||
}
|
||||
const LibEVMVersion = "1.13.14-0.2.0.beta"
|
||||
|
||||
// A ReleaseType is a suffix for [LibEVMVersion].
|
||||
type ReleaseType string
|
||||
|
|
@ -86,17 +68,3 @@ const (
|
|||
func (t ReleaseType) ForReleaseBranch() bool {
|
||||
return t == ReleaseCandidate || t == ProductionRelease
|
||||
}
|
||||
|
||||
type libEVMSemver struct {
|
||||
geth, libEVM semverTriplet
|
||||
typ ReleaseType
|
||||
rc uint
|
||||
}
|
||||
|
||||
func (v libEVMSemver) String() string {
|
||||
suffix := v.typ
|
||||
if suffix == ReleaseCandidate {
|
||||
suffix = ReleaseType(fmt.Sprintf("%s.%d", suffix, v.rc))
|
||||
}
|
||||
return fmt.Sprintf("%s-%s.%s", v.geth, v.libEVM, suffix)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,22 +17,47 @@
|
|||
package params
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"golang.org/x/mod/semver"
|
||||
)
|
||||
|
||||
func TestLibEVMVersioning(t *testing.T) {
|
||||
// We have an unusual version structure as defined by [LibEVMVersion] that
|
||||
// is easy to mess up, so it's easier to just automate it and test the
|
||||
// ordering assumptions.
|
||||
// libEVMServer automates the version rules described by the [LibEVMVersion]
|
||||
// documentation.
|
||||
type libEVMSemver struct {
|
||||
geth, libEVM semverTriplet
|
||||
typ ReleaseType
|
||||
rc uint
|
||||
}
|
||||
|
||||
// This is a deliberate change-detector test to provide us with a copyable
|
||||
// string of the current version, useful for git tagging.
|
||||
const curr = "1.13.14-0.1.0.beta"
|
||||
if got, want := LibEVMVersion, curr; got != want {
|
||||
t.Errorf("got LibEVMVersion %q; want %q", got, want)
|
||||
func (v libEVMSemver) String() string {
|
||||
suffix := v.typ
|
||||
if suffix == ReleaseCandidate {
|
||||
suffix = ReleaseType(fmt.Sprintf("%s.%d", suffix, v.rc))
|
||||
}
|
||||
return fmt.Sprintf("%s-%s.%s", v.geth, v.libEVM, suffix)
|
||||
}
|
||||
|
||||
type semverTriplet struct {
|
||||
major, minor, patch uint
|
||||
}
|
||||
|
||||
func (t semverTriplet) String() string {
|
||||
return fmt.Sprintf("%d.%d.%d", t.major, t.minor, t.patch)
|
||||
}
|
||||
|
||||
func TestLibEVMVersioning(t *testing.T) {
|
||||
t.Run("current", func(t *testing.T) {
|
||||
want := libEVMSemver{
|
||||
geth: semverTriplet{VersionMajor, VersionMinor, VersionPatch},
|
||||
libEVM: semverTriplet{LibEVMVersionMajor, LibEVMVersionMinor, LibEVMVersionPatch},
|
||||
typ: LibEVMReleaseType,
|
||||
rc: libEVMReleaseCandidate,
|
||||
}.String()
|
||||
assert.Equal(t, want, LibEVMVersion, "LibEVMVersion")
|
||||
})
|
||||
|
||||
ordered := []libEVMSemver{
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue