diff --git a/src/Nethermind/Nethermind.Optimism.Test/OptimismProtocolVersionTest.cs b/src/Nethermind/Nethermind.Optimism.Test/OptimismProtocolVersionTest.cs index 264f015b03f..66454cff342 100644 --- a/src/Nethermind/Nethermind.Optimism.Test/OptimismProtocolVersionTest.cs +++ b/src/Nethermind/Nethermind.Optimism.Test/OptimismProtocolVersionTest.cs @@ -129,6 +129,21 @@ public void OptimismProtocolVersion_Throws_Unknown_Version(byte version) read.Should().Throw(); } + + private static IEnumerable<(string, OptimismProtocolVersion.V0)> V0FromStringCases() + { + yield return ("3.1.0", new(new byte[8], 3, 1, 0, 0)); + yield return ("1.1.1", new(new byte[8], 1, 1, 1, 0)); + yield return ("1.1.1.16", new(new byte[8], 1, 1, 1, 16)); + yield return ("1.26.0.4", new(new byte[8], 1, 26, 0, 4)); + } + [TestCaseSource(nameof(V0FromStringCases))] + public void OptimismProtocolVersionV0_FromStringVersion((string Version, OptimismProtocolVersion.V0 Expected) testCase) + { + var actual = new OptimismProtocolVersion.V0(testCase.Version); + actual.Should().Be(testCase.Expected); + } + [Test] public void OptimismProtocolVersionV0_FromProductInfoVersion() { diff --git a/src/Nethermind/Nethermind.Optimism/ProtocolVersion/OptimismProtocolVersion.cs b/src/Nethermind/Nethermind.Optimism/ProtocolVersion/OptimismProtocolVersion.cs index 6716fe7693e..cd55ff0a851 100644 --- a/src/Nethermind/Nethermind.Optimism/ProtocolVersion/OptimismProtocolVersion.cs +++ b/src/Nethermind/Nethermind.Optimism/ProtocolVersion/OptimismProtocolVersion.cs @@ -71,13 +71,13 @@ public V0(ReadOnlySpan build, string version) if (build.Length != 8) throw new ArgumentException($"Expected build identifier to be 8 bytes long, got {build.Length}", nameof(build)); var parts = version.Split('.').Select(uint.Parse).ToList(); - if (parts.Count != 4) throw new ArgumentException($"Invalid version format '{version}'", nameof(version)); + if (parts.Count is < 3 or > 4) throw new ArgumentException($"Invalid version format '{version}'", nameof(version)); Build = build.ToArray(); Major = parts[0]; Minor = parts[1]; Patch = parts[2]; - PreRelease = parts[3]; + PreRelease = parts.Count == 4 ? parts[3] : 0; } public V0(string version) : this(new byte[8], version) { }