|
| 1 | +// Copyright 2024 the libevm authors. |
| 2 | +// |
| 3 | +// The libevm additions to go-ethereum are free software: you can redistribute |
| 4 | +// them and/or modify them under the terms of the GNU Lesser General Public License |
| 5 | +// as published by the Free Software Foundation, either version 3 of the License, |
| 6 | +// or (at your option) any later version. |
| 7 | +// |
| 8 | +// The libevm additions are distributed in the hope that they will be useful, |
| 9 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser |
| 11 | +// General Public License for more details. |
| 12 | +// |
| 13 | +// You should have received a copy of the GNU Lesser General Public License |
| 14 | +// along with the go-ethereum library. If not, see |
| 15 | +// <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +package params |
| 18 | + |
| 19 | +import ( |
| 20 | + "testing" |
| 21 | + |
| 22 | + "golang.org/x/mod/semver" |
| 23 | +) |
| 24 | + |
| 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. |
| 29 | + |
| 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 | + } |
| 36 | + |
| 37 | + ordered := []libEVMSemver{ |
| 38 | + { |
| 39 | + semverTriplet{1, 13, 14}, |
| 40 | + semverTriplet{0, 1, 0}, |
| 41 | + betaRelease, |
| 42 | + 0, // ignored |
| 43 | + }, |
| 44 | + { |
| 45 | + semverTriplet{1, 13, 14}, |
| 46 | + semverTriplet{0, 1, 0}, |
| 47 | + releaseCandidate, 1, |
| 48 | + }, |
| 49 | + { |
| 50 | + semverTriplet{1, 13, 14}, |
| 51 | + semverTriplet{0, 1, 0}, |
| 52 | + releaseCandidate, 2, |
| 53 | + }, |
| 54 | + { |
| 55 | + semverTriplet{1, 13, 14}, |
| 56 | + semverTriplet{0, 1, 0}, |
| 57 | + productionRelease, |
| 58 | + 0, // ignored, |
| 59 | + }, |
| 60 | + { |
| 61 | + semverTriplet{1, 13, 14}, |
| 62 | + semverTriplet{0, 1, 1}, // bump takes precedence |
| 63 | + betaRelease, 0, |
| 64 | + }, |
| 65 | + { |
| 66 | + semverTriplet{1, 13, 14}, |
| 67 | + semverTriplet{0, 1, 1}, |
| 68 | + productionRelease, 0, |
| 69 | + }, |
| 70 | + { |
| 71 | + semverTriplet{1, 13, 15}, // bump takes precedence |
| 72 | + semverTriplet{0, 1, 1}, |
| 73 | + betaRelease, 0, |
| 74 | + }, |
| 75 | + } |
| 76 | + |
| 77 | + for i, low := range ordered[:len(ordered)-1] { |
| 78 | + // The `go mod` semver package requires the "v" prefix, which |
| 79 | + // technically isn't valid semver. |
| 80 | + lo := "v" + low.String() |
| 81 | + hi := "v" + ordered[i+1].String() |
| 82 | + if got := semver.Compare(lo, hi); got != -1 { |
| 83 | + t.Errorf("Version pattern is not strictly ordered; semver.Compare(%q, %q) = %d", lo, hi, got) |
| 84 | + } |
| 85 | + } |
| 86 | +} |
0 commit comments