Skip to content

Commit 0ed6135

Browse files
authored
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.
1 parent 08490a9 commit 0ed6135

File tree

6 files changed

+36
-55
lines changed

6 files changed

+36
-55
lines changed

.github/workflows/go.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ on:
55
branches: [main, "release/**"]
66
pull_request:
77
branches: [main, "release/**"]
8-
merge_group:
9-
types: [checks_requested]
108
workflow_dispatch:
119

1210
concurrency:

.github/workflows/libevm-delta.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ on:
55
branches: [main, "release/**"]
66
pull_request:
77
branches: [main, "release/**"]
8-
merge_group:
9-
types: [checks_requested]
108
workflow_dispatch:
119

1210
concurrency:

.github/workflows/lint.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ on:
55
branches: [main, "release/**"]
66
pull_request:
77
branches: [main, "release/**"]
8-
merge_group:
9-
types: [checks_requested]
108
workflow_dispatch:
119

1210
permissions:

core/types/rlp_payload.libevm.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"fmt"
2121
"io"
2222

23-
"github.com/ava-labs/libevm/common"
2423
"github.com/ava-labs/libevm/libevm/pseudo"
2524
"github.com/ava-labs/libevm/libevm/register"
2625
"github.com/ava-labs/libevm/libevm/testonly"
@@ -366,8 +365,3 @@ func (e *StateAccountExtra) Format(s fmt.State, verb rune) {
366365
}
367366
_, _ = s.Write([]byte(out))
368367
}
369-
370-
// RLPHash returns the hash of the RLP encoding of `x`.
371-
func RLPHash(x any) common.Hash {
372-
return rlpHash(x)
373-
}

params/version.libevm.go

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@
1616

1717
package params
1818

19-
import "fmt"
20-
2119
const (
2220
LibEVMVersionMajor = 0
23-
LibEVMVersionMinor = 1
21+
LibEVMVersionMinor = 2
2422
LibEVMVersionPatch = 0
2523

2624
LibEVMReleaseType ReleaseType = BetaRelease
@@ -50,23 +48,7 @@ const (
5048
// triplet.
5149
//
5250
// [semver v2]: https://semver.org/
53-
var LibEVMVersion = func() string {
54-
v := libEVMSemver{
55-
geth: semverTriplet{VersionMajor, VersionMinor, VersionPatch},
56-
libEVM: semverTriplet{LibEVMVersionMajor, LibEVMVersionMinor, LibEVMVersionPatch},
57-
typ: LibEVMReleaseType,
58-
rc: libEVMReleaseCandidate,
59-
}
60-
return v.String()
61-
}()
62-
63-
type semverTriplet struct {
64-
major, minor, patch uint
65-
}
66-
67-
func (t semverTriplet) String() string {
68-
return fmt.Sprintf("%d.%d.%d", t.major, t.minor, t.patch)
69-
}
51+
const LibEVMVersion = "1.13.14-0.2.0.beta"
7052

7153
// A ReleaseType is a suffix for [LibEVMVersion].
7254
type ReleaseType string
@@ -86,17 +68,3 @@ const (
8668
func (t ReleaseType) ForReleaseBranch() bool {
8769
return t == ReleaseCandidate || t == ProductionRelease
8870
}
89-
90-
type libEVMSemver struct {
91-
geth, libEVM semverTriplet
92-
typ ReleaseType
93-
rc uint
94-
}
95-
96-
func (v libEVMSemver) String() string {
97-
suffix := v.typ
98-
if suffix == ReleaseCandidate {
99-
suffix = ReleaseType(fmt.Sprintf("%s.%d", suffix, v.rc))
100-
}
101-
return fmt.Sprintf("%s-%s.%s", v.geth, v.libEVM, suffix)
102-
}

params/version.libevm_test.go

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,47 @@
1717
package params
1818

1919
import (
20+
"fmt"
2021
"testing"
2122

23+
"github.com/stretchr/testify/assert"
2224
"golang.org/x/mod/semver"
2325
)
2426

25-
func TestLibEVMVersioning(t *testing.T) {
26-
// We have an unusual version structure as defined by [LibEVMVersion] that
27-
// is easy to mess up, so it's easier to just automate it and test the
28-
// ordering assumptions.
27+
// libEVMServer automates the version rules described by the [LibEVMVersion]
28+
// documentation.
29+
type libEVMSemver struct {
30+
geth, libEVM semverTriplet
31+
typ ReleaseType
32+
rc uint
33+
}
2934

30-
// This is a deliberate change-detector test to provide us with a copyable
31-
// string of the current version, useful for git tagging.
32-
const curr = "1.13.14-0.1.0.beta"
33-
if got, want := LibEVMVersion, curr; got != want {
34-
t.Errorf("got LibEVMVersion %q; want %q", got, want)
35+
func (v libEVMSemver) String() string {
36+
suffix := v.typ
37+
if suffix == ReleaseCandidate {
38+
suffix = ReleaseType(fmt.Sprintf("%s.%d", suffix, v.rc))
3539
}
40+
return fmt.Sprintf("%s-%s.%s", v.geth, v.libEVM, suffix)
41+
}
42+
43+
type semverTriplet struct {
44+
major, minor, patch uint
45+
}
46+
47+
func (t semverTriplet) String() string {
48+
return fmt.Sprintf("%d.%d.%d", t.major, t.minor, t.patch)
49+
}
50+
51+
func TestLibEVMVersioning(t *testing.T) {
52+
t.Run("current", func(t *testing.T) {
53+
want := libEVMSemver{
54+
geth: semverTriplet{VersionMajor, VersionMinor, VersionPatch},
55+
libEVM: semverTriplet{LibEVMVersionMajor, LibEVMVersionMinor, LibEVMVersionPatch},
56+
typ: LibEVMReleaseType,
57+
rc: libEVMReleaseCandidate,
58+
}.String()
59+
assert.Equal(t, want, LibEVMVersion, "LibEVMVersion")
60+
})
3661

3762
ordered := []libEVMSemver{
3863
{

0 commit comments

Comments
 (0)