Skip to content

Commit

Permalink
fix gnosis state / blockchain tests runner (#8216)
Browse files Browse the repository at this point in the history
  • Loading branch information
yerke26 authored Feb 18, 2025
1 parent d09d600 commit 9eef599
Show file tree
Hide file tree
Showing 23 changed files with 467 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class LoadPyspecTestsStrategy : ITestLoadStrategy
public string ArchiveVersion { get; init; } = Constants.DEFAULT_ARCHIVE_VERSION;
public string ArchiveName { get; init; } = Constants.DEFAULT_ARCHIVE_NAME;

public IEnumerable<IEthereumTest> Load(string testsDir, string wildcard = null)
public IEnumerable<EthereumTest> Load(string testsDir, string wildcard = null)
{
string testsDirectoryName = Path.Combine(AppContext.BaseDirectory, "PyTests", ArchiveVersion, ArchiveName.Split('.')[0]);
if (!Directory.Exists(testsDirectoryName)) // Prevent redownloading the fixtures if they already exists with this version and archive name
Expand All @@ -44,28 +44,28 @@ private void DownloadAndExtract(string archiveVersion, string archiveName, strin
TarFile.ExtractToDirectory(gzStream, testsDirectoryName, true);
}

private IEnumerable<IEthereumTest> LoadTestsFromDirectory(string testDir, string wildcard, bool isStateTest)
private IEnumerable<EthereumTest> LoadTestsFromDirectory(string testDir, string wildcard, bool isStateTest)
{
List<IEthereumTest> testsByName = new();
List<EthereumTest> testsByName = new();
IEnumerable<string> testFiles = Directory.EnumerateFiles(testDir);

foreach (string testFile in testFiles)
{
FileTestsSource fileTestsSource = new(testFile, wildcard);
try
{
IEnumerable<IEthereumTest> tests = isStateTest
IEnumerable<EthereumTest> tests = isStateTest
? fileTestsSource.LoadGeneralStateTests()
: fileTestsSource.LoadBlockchainTests();
foreach (IEthereumTest test in tests)
foreach (EthereumTest test in tests)
{
test.Category = testDir;
}
testsByName.AddRange(tests);
}
catch (Exception e)
{
IEthereumTest failedTest = isStateTest
EthereumTest failedTest = isStateTest
? new GeneralStateTest()
: new BlockchainTest();
failedTest.Name = testDir;
Expand Down
6 changes: 1 addition & 5 deletions src/Nethermind/Ethereum.Test.Base/BlockchainTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@

namespace Ethereum.Test.Base
{
public class BlockchainTest : IEthereumTest
public class BlockchainTest : EthereumTest
{
public string? Category { get; set; }
public string? Name { get; set; }
public IReleaseSpec? Network { get; set; }
public IReleaseSpec? NetworkAfterTransition { get; set; }
public ForkActivation? TransitionForkActivation { get; set; }
Expand All @@ -27,8 +25,6 @@ public class BlockchainTest : IEthereumTest
public Dictionary<Address, AccountState>? PostState { get; set; }
public Hash256? PostStateRoot { get; set; }
public bool SealEngineUsed { get; set; }
public string? LoadFailure { get; set; }
public ulong ChainId { get; set; }

public override string? ToString()
{
Expand Down
10 changes: 6 additions & 4 deletions src/Nethermind/Ethereum.Test.Base/BlockchainTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
using Nethermind.Serialization.Rlp;
using Nethermind.Specs;
using Nethermind.Specs.Forks;
using Nethermind.Specs.GnosisForks;
using Nethermind.Specs.Test;
using Nethermind.State;
using Nethermind.TxPool;
Expand Down Expand Up @@ -78,16 +79,17 @@ protected async Task<EthereumTestResult> RunTest(BlockchainTest test, Stopwatch?
TestContext.Out.WriteLine($"Network after transition: [{test.NetworkAfterTransition.Name}] at {test.TransitionForkActivation}");
Assert.That(test.LoadFailure, Is.Null, "test data loading failure");

test.Network = ChainUtils.ResolveSpec(test.Network, test.ChainId);
test.NetworkAfterTransition = ChainUtils.ResolveSpec(test.NetworkAfterTransition, test.ChainId);

List<(ForkActivation Activation, IReleaseSpec Spec)> transitions =
[((ForkActivation)0, Frontier.Instance), ((ForkActivation)1, test.Network)]; // TODO: this thing took a lot of time to find after it was removed!, genesis block is always initialized with Frontier
[((ForkActivation)0, test.GenesisSpec), ((ForkActivation)1, test.Network)]; // TODO: this thing took a lot of time to find after it was removed!, genesis block is always initialized with Frontier
if (test.NetworkAfterTransition is not null)
{
transitions.Add((test.TransitionForkActivation!.Value, test.NetworkAfterTransition));
}

ISpecProvider specProvider = test.ChainId == GnosisSpecProvider.Instance.ChainId
? GnosisSpecProvider.Instance
: new CustomSpecProvider(transitions.ToArray());
ISpecProvider specProvider = new CustomSpecProvider(test.ChainId, test.ChainId, transitions.ToArray());

if (test.ChainId != GnosisSpecProvider.Instance.ChainId && specProvider.GenesisSpec != Frontier.Instance)
{
Expand Down
31 changes: 31 additions & 0 deletions src/Nethermind/Ethereum.Test.Base/ChainUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-FileCopyrightText: 2025 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using Nethermind.Core.Specs;
using Nethermind.Specs;
using Nethermind.Specs.Forks;
using Nethermind.Specs.GnosisForks;

namespace Ethereum.Test.Base;

public class ChainUtils
{
public static IReleaseSpec? ResolveSpec(IReleaseSpec? spec, ulong chainId)
{
if (chainId != GnosisSpecProvider.Instance.ChainId)
{
return spec;
}

if (spec == Cancun.Instance)
{
return CancunGnosis.Instance;
}
if (spec == Prague.Instance)
{
return PragueGnosis.Instance;
}

return spec;
}
}
6 changes: 1 addition & 5 deletions src/Nethermind/Ethereum.Test.Base/GeneralStateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@

namespace Ethereum.Test.Base
{
public class GeneralStateTest : IEthereumTest
public class GeneralStateTest : EthereumTest
{
public string? Category { get; set; }
public string? Name { get; set; }
public IReleaseSpec? Fork { get; set; }
public string? ForkName { get; set; }
public Address? CurrentCoinbase { get; set; }
Expand All @@ -28,15 +26,13 @@ public class GeneralStateTest : IEthereumTest
public Dictionary<Address, AccountState> Pre { get; set; }
public Hash256? PostHash { get; set; }
public Hash256? PostReceiptsRoot { get; set; }
public string? LoadFailure { get; set; }
public Transaction? Transaction { get; set; }
public Hash256? CurrentRandom { get; set; }
public Hash256? CurrentBeaconRoot { get; set; }
public Hash256? CurrentWithdrawalsRoot { get; set; }
public ulong? CurrentExcessBlobGas { get; set; }
public UInt256? ParentBlobGasUsed { get; set; }
public UInt256? ParentExcessBlobGas { get; set; }
public ulong ChainId { get; set; }

public Hash256? RequestsHash { get; set; }

Expand Down
13 changes: 8 additions & 5 deletions src/Nethermind/Ethereum.Test.Base/GeneralTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
using System.Threading.Tasks;
using Autofac;
using Nethermind.Config;
using Nethermind.Consensus.AuRa.InitializationSteps;
using Nethermind.Core.Test.Builders;
using Nethermind.Core.Test.Modules;
using Nethermind.Specs.GnosisForks;

namespace Ethereum.Test.Base
{
Expand Down Expand Up @@ -62,10 +64,11 @@ protected EthereumTestResult RunTest(GeneralStateTest test, ITxTracer txTracer)
TestContext.Out.Write($"Running {test.Name} at {DateTime.UtcNow:HH:mm:ss.ffffff}");
Assert.That(test.LoadFailure, Is.Null, "test data loading failure");

ISpecProvider specProvider = test.ChainId == GnosisSpecProvider.Instance.ChainId
? GnosisSpecProvider.Instance
: new CustomSpecProvider(
((ForkActivation)0, Frontier.Instance), // TODO: this thing took a lot of time to find after it was removed!, genesis block is always initialized with Frontier
test.Fork = ChainUtils.ResolveSpec(test.Fork, test.ChainId);

ISpecProvider specProvider =
new CustomSpecProvider(test.ChainId, test.ChainId,
((ForkActivation)0, test.GenesisSpec), // TODO: this thing took a lot of time to find after it was removed!, genesis block is always initialized with Frontier
((ForkActivation)1, test.Fork));

if (test.ChainId != GnosisSpecProvider.Instance.ChainId && specProvider.GenesisSpec != Frontier.Instance)
Expand Down Expand Up @@ -111,7 +114,7 @@ protected EthereumTestResult RunTest(GeneralStateTest test, ITxTracer txTracer)
IReleaseSpec? spec = specProvider.GetSpec((ForkActivation)test.CurrentNumber);

if (test.Transaction.ChainId is null)
test.Transaction.ChainId = MainnetSpecProvider.Instance.ChainId;
test.Transaction.ChainId = test.ChainId;
if (test.ParentBlobGasUsed is not null && test.ParentExcessBlobGas is not null)
{
BlockHeader parent = new(
Expand Down
16 changes: 16 additions & 0 deletions src/Nethermind/Ethereum.Test.Base/Interfaces/EthereumTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Nethermind.Core.Specs;
using Nethermind.Specs;

namespace Ethereum.Test.Base.Interfaces
{
public abstract class EthereumTest
{
public string? Category { get; set; }
public string? Name { get; set; }
public string? LoadFailure { get; set; }
public ulong ChainId { get; set; } = MainnetSpecProvider.Instance.ChainId;
public IReleaseSpec GenesisSpec => ChainId == MainnetSpecProvider.Instance.ChainId
? MainnetSpecProvider.Instance.GenesisSpec
: GnosisSpecProvider.Instance.GenesisSpec;
}
}
9 changes: 0 additions & 9 deletions src/Nethermind/Ethereum.Test.Base/Interfaces/IEthereumTest.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ namespace Ethereum.Test.Base.Interfaces
{
public interface ITestLoadStrategy
{
IEnumerable<IEthereumTest> Load(string testDirectoryName, string wildcard = null);
IEnumerable<EthereumTest> Load(string testDirectoryName, string wildcard = null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ namespace Ethereum.Test.Base.Interfaces
{
public interface ITestSourceLoader
{
IEnumerable<IEthereumTest> LoadTests();
IEnumerable<EthereumTest> LoadTests();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Ethereum.Test.Base
{
public class LoadBlockchainTestFileStrategy : ITestLoadStrategy
{
public IEnumerable<IEthereumTest> Load(string testName, string? wildcard = null)
public IEnumerable<EthereumTest> Load(string testName, string? wildcard = null)
{
FileTestsSource fileTestsSource = new(testName, wildcard);
IEnumerable<BlockchainTest> tests = fileTestsSource.LoadBlockchainTests();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Ethereum.Test.Base
{
public class LoadBlockchainTestsStrategy : ITestLoadStrategy
{
public IEnumerable<IEthereumTest> Load(string testsDirectoryName, string wildcard = null)
public IEnumerable<EthereumTest> Load(string testsDirectoryName, string wildcard = null)
{
IEnumerable<string> testDirs;
if (!Path.IsPathRooted(testsDirectoryName))
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Ethereum.Test.Base/LoadEipTestsStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Ethereum.Test.Base
{
public class LoadEipTestsStrategy : ITestLoadStrategy
{
public IEnumerable<IEthereumTest> Load(string testsDirectoryName, string wildcard = null)
public IEnumerable<EthereumTest> Load(string testsDirectoryName, string wildcard = null)
{
IEnumerable<string> testDirs;
if (!Path.IsPathRooted(testsDirectoryName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ namespace Ethereum.Test.Base
{
public class LoadGeneralStateTestFileStrategy : ITestLoadStrategy
{
public IEnumerable<IEthereumTest> Load(string testName, string? wildcard = null)
public IEnumerable<EthereumTest> Load(string testName, string? wildcard = null)
{
//in case user wants to give test file other than the ones in ethereum tests submodule
//in case user wants to give test file other than the ones in ethereum tests submodule
if (File.Exists(testName))
{
FileTestsSource fileTestsSource = new(testName, wildcard);
Expand All @@ -27,7 +27,7 @@ public IEnumerable<IEthereumTest> Load(string testName, string? wildcard = null)

List<GeneralStateTest> generalStateTests = new();

//load all tests from found test files in ethereum tests submodule
//load all tests from found test files in ethereum tests submodule
foreach (string testFile in testFiles)
{
FileTestsSource fileTestsSource = new(testFile, wildcard);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Ethereum.Test.Base
{
public class LoadGeneralStateTestsStrategy : ITestLoadStrategy
{
public IEnumerable<IEthereumTest> Load(string testsDirectoryName, string wildcard = null)
public IEnumerable<EthereumTest> Load(string testsDirectoryName, string wildcard = null)
{
IEnumerable<string> testDirs;
if (!Path.IsPathRooted(testsDirectoryName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Ethereum.Test.Base
{
public class LoadLegacyBlockchainTestsStrategy : ITestLoadStrategy
{
public IEnumerable<IEthereumTest> Load(string testsDirectoryName, string wildcard = null)
public IEnumerable<EthereumTest> Load(string testsDirectoryName, string wildcard = null)
{
IEnumerable<string> testDirs;
if (!Path.IsPathRooted(testsDirectoryName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Ethereum.Test.Base
{
public class LoadLegacyGeneralStateTestsStrategy : ITestLoadStrategy
{
public IEnumerable<IEthereumTest> Load(string testsDirectoryName, string wildcard = null)
public IEnumerable<EthereumTest> Load(string testsDirectoryName, string wildcard = null)
{
IEnumerable<string> testDirs;
if (!Path.IsPathRooted(testsDirectoryName))
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Ethereum.Test.Base/TestsSourceLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public TestsSourceLoader(ITestLoadStrategy testLoadStrategy, string path, string
_wildcard = wildcard;
}

public IEnumerable<IEthereumTest> LoadTests()
public IEnumerable<EthereumTest> LoadTests()
{
return _testLoadStrategy.Load(_path, _wildcard);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public AuthorizationTuple[] ToAuthorizationList() => _tuples
(ulong)tuple.ChainId,
tuple.Address,
tuple.Nonce,
new Signature(tuple.R, tuple.S, (ulong)tuple.YParity))
new Signature(tuple.R, tuple.S, (ulong)tuple.YParity + Signature.VOffset))
).ToArray();

public class JsonConverter : JsonConverter<AuthorizationListForRpc>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
<Content Include="storagefuzz0.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Update="gnosisBlockchainTest1.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="gnosisStateTest1.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
6 changes: 4 additions & 2 deletions src/Nethermind/Nethermind.Test.Runner/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading.Tasks;
using Ethereum.Test.Base;
using Ethereum.Test.Base.Interfaces;
using Nethermind.Specs;

namespace Nethermind.Test.Runner;

Expand Down Expand Up @@ -58,7 +59,8 @@ public static async Task<int> Main(params string[] args)
Options.ExcludeMemory,
Options.ExcludeStack,
Options.Wait,
Options.Stdin
Options.Stdin,
Options.GnosisTest,
];
rootCommand.SetAction(Run);

Expand All @@ -81,7 +83,7 @@ private static async Task<int> Run(ParseResult parseResult, CancellationToken ca

if (parseResult.GetValue(Options.Stdin))
input = Console.ReadLine();
ulong chainId = parseResult.GetValue(Options.GnosisTest) ? 100ul : 1ul;
ulong chainId = parseResult.GetValue(Options.GnosisTest) ? GnosisSpecProvider.Instance.ChainId : MainnetSpecProvider.Instance.ChainId;


while (!string.IsNullOrWhiteSpace(input))
Expand Down
Loading

0 comments on commit 9eef599

Please sign in to comment.