Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions src/Nethermind/Ethereum.Test.Base/JsonToEthereumTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,16 +417,50 @@ private static List<TransactionTest> ConvertTransactionTests(Dictionary<string,
return tests;
}

private const string NeitherShapeMessage = "Fixture matches neither the standard nor the trimmed blockchain test shape.";

/// <remarks>Only deserialization falls back between shapes, so a conversion failure surfaces as itself.</remarks>
public static IEnumerable<BlockchainTest> ConvertToBlockchainTests(string json)
{
try { return ConvertToBlockchainTests(_serializer.Deserialize<Dictionary<string, BlockchainTestJson>>(json)); }
catch (Exception) { return ConvertToBlockchainTests(CoerceFromHalf(_serializer.Deserialize<Dictionary<string, HalfBlockchainTestJson>>(json))); }
Dictionary<string, BlockchainTestJson> tests;
try
{
tests = _serializer.Deserialize<Dictionary<string, BlockchainTestJson>>(json);
}
catch (Exception standardShapeException)
{
try
{
tests = CoerceFromHalf(_serializer.Deserialize<Dictionary<string, HalfBlockchainTestJson>>(json));
}
catch (Exception trimmedShapeException)
{
throw new AggregateException(NeitherShapeMessage, standardShapeException, trimmedShapeException);
}
}
return ConvertToBlockchainTests(tests);
}

/// <remarks>Only deserialization falls back between shapes, so a conversion failure surfaces as itself.</remarks>
public static IEnumerable<BlockchainTest> ConvertToBlockchainTests(ReadOnlySpan<byte> json)
{
try { return ConvertToBlockchainTests(_serializer.Deserialize<Dictionary<string, BlockchainTestJson>>(json)); }
catch (Exception) { return ConvertToBlockchainTests(CoerceFromHalf(_serializer.Deserialize<Dictionary<string, HalfBlockchainTestJson>>(json))); }
Dictionary<string, BlockchainTestJson> tests;
try
{
tests = _serializer.Deserialize<Dictionary<string, BlockchainTestJson>>(json);
}
catch (Exception standardShapeException)
{
try
{
tests = CoerceFromHalf(_serializer.Deserialize<Dictionary<string, HalfBlockchainTestJson>>(json));
}
catch (Exception trimmedShapeException)
{
throw new AggregateException(NeitherShapeMessage, standardShapeException, trimmedShapeException);
}
}
return ConvertToBlockchainTests(tests);
}
Comment thread
Marchhill marked this conversation as resolved.

// Some BAL fixtures use the trimmed HalfBlockchainTestJson shape; coerce on demand.
Expand Down
30 changes: 30 additions & 0 deletions src/Nethermind/Nethermind.Specs.Test/SpecNameParserTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-FileCopyrightText: 2026 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using Nethermind.Core.Specs;
using Nethermind.Specs.Forks;
using NUnit.Framework;

namespace Nethermind.Specs.Test;

public class SpecNameParserTests
{
[Test]
public void Parse_maps_Bogota_to_the_frame_transactions_fork()
{
IReleaseSpec spec = SpecNameParser.Parse("Bogota");

Assert.That(spec, Is.SameAs(Bogota.Instance));
}

[TestCase("NotAFork", "NotAFork")]
[TestCase("Merge+9999", "Paris+9999")]
public void Parse_names_the_offending_fork_when_unmapped(string specName, string resolvedSpecName)
{
NotSupportedException e = Assert.Throws<NotSupportedException>(() => SpecNameParser.Parse(specName))!;

Assert.That(e.Message, Does.Contain(specName));
Assert.That(e.Message, Does.Contain(resolvedSpecName));
}
}
5 changes: 4 additions & 1 deletion src/Nethermind/Nethermind.Specs/SpecNameParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ private static IReleaseSpec ParseUncached(string specName)
"BPO4" => BPO4.Instance,
"BPO5" => BPO5.Instance,
"Amsterdam" => Amsterdam.Instance,
_ => throw new NotSupportedException()
"Bogota" => Bogota.Instance,
_ => throw new NotSupportedException(specName == unambiguousSpecName
? $"Unknown fork name '{specName}'"
: $"Unknown fork name '{specName}' (resolved to '{unambiguousSpecName}')")
};
}
}
Expand Down
Loading