Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Gnosis test runner #8102

Merged
merged 3 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions src/Nethermind/Ethereum.Test.Base/BlockchainTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class BlockchainTest : IEthereumTest
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
21 changes: 9 additions & 12 deletions src/Nethermind/Ethereum.Test.Base/BlockchainTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
using Nethermind.Int256;
using Nethermind.Logging;
using Nethermind.Serialization.Rlp;
using Nethermind.Specs;
using Nethermind.Specs.Forks;
using Nethermind.Specs.Test;
using Nethermind.State;
Expand Down Expand Up @@ -77,22 +78,18 @@ 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");

ISpecProvider specProvider;
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
if (test.NetworkAfterTransition is not null)
{
specProvider = new CustomSpecProvider(
((ForkActivation)0, Frontier.Instance),
((ForkActivation)1, test.Network),
(test.TransitionForkActivation!.Value, test.NetworkAfterTransition));
}
else
{
specProvider = 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
((ForkActivation)1, test.Network));
transitions.Add((test.TransitionForkActivation!.Value, test.NetworkAfterTransition));
}

if (specProvider.GenesisSpec != Frontier.Instance)
ISpecProvider specProvider = test.ChainId == GnosisSpecProvider.Instance.ChainId
? GnosisSpecProvider.Instance
: new CustomSpecProvider(transitions.ToArray());

if (test.ChainId != GnosisSpecProvider.Instance.ChainId && specProvider.GenesisSpec != Frontier.Instance)
{
Assert.Fail("Expected genesis spec to be Frontier for blockchain tests");
}
Expand Down
1 change: 1 addition & 0 deletions src/Nethermind/Ethereum.Test.Base/GeneralStateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class GeneralStateTest : IEthereumTest
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
10 changes: 6 additions & 4 deletions src/Nethermind/Ethereum.Test.Base/GeneralTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,13 @@ 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 = 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
((ForkActivation)1, test.Fork));
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
((ForkActivation)1, test.Fork));

if (specProvider.GenesisSpec != Frontier.Instance)
if (test.ChainId != GnosisSpecProvider.Instance.ChainId && specProvider.GenesisSpec != Frontier.Instance)
{
Assert.Fail("Expected genesis spec to be Frontier for blockchain tests");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ public class BlockchainTestsRunner : BlockchainTestBase, IBlockchainTestRunner
private readonly ConsoleColor _defaultColour;
private readonly ITestSourceLoader _testsSource;
private readonly string? _filter;
private readonly ulong _chainId;

public BlockchainTestsRunner(ITestSourceLoader testsSource, string? filter)
public BlockchainTestsRunner(ITestSourceLoader testsSource, string? filter, ulong chainId)
{
_testsSource = testsSource ?? throw new ArgumentNullException(nameof(testsSource));
_defaultColour = Console.ForegroundColor;
_filter = filter;
_chainId = chainId;
}

public async Task<IEnumerable<EthereumTestResult>> RunTestsAsync()
Expand All @@ -42,6 +44,7 @@ public async Task<IEnumerable<EthereumTestResult>> RunTestsAsync()
}
else
{
test.ChainId = _chainId;
EthereumTestResult result = await RunTest(test);
testResults.Add(result);
if (result.Pass)
Expand Down
8 changes: 7 additions & 1 deletion src/Nethermind/Nethermind.Test.Runner/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public class Options

public static CliOption<bool> Stdin { get; } =
new("--stdin", "-x") { Description = "If stdin is used, the state runner will read inputs (filenames) from stdin, and continue executing until empty line is read." };

public static CliOption<bool> GnosisTest { get; } =
new("--gnosisTest", "-g") { Description = "Set test as gnosisTest. if not, it will be by default assumed a mainnet test." };
}

public static async Task<int> Main(params string[] args)
Expand Down Expand Up @@ -78,15 +81,18 @@ 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;


while (!string.IsNullOrWhiteSpace(input))
{
if (parseResult.GetValue(Options.BlockTest))
await RunBlockTest(input, source => new BlockchainTestsRunner(source, parseResult.GetValue(Options.Filter)));
await RunBlockTest(input, source => new BlockchainTestsRunner(source, parseResult.GetValue(Options.Filter), chainId));
else
RunStateTest(input, source => new StateTestsRunner(source, whenTrace,
!parseResult.GetValue(Options.ExcludeMemory),
!parseResult.GetValue(Options.ExcludeStack),
chainId,
parseResult.GetValue(Options.Filter)));

if (!parseResult.GetValue(Options.Stdin))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@
"commandName": "Project",
"commandLineArgs": "-i statetest1.json"
},
"Gnosis State Test": {
"commandName": "Project",
"commandLineArgs": "-g -i gnosisStateTest1.json"
},
"Blockchain Test": {
"commandName": "Project",
"commandLineArgs": "-b -i blockchainTest1.json"
},
"Gnosis Blockchain Test": {
"commandName": "Project",
"commandLineArgs": "-g -b -i gnosisBlockchainTest1.json"
},
"Regex State Test": {
"commandName": "Project",
"commandLineArgs": "-i statetest1.json -f \"randomStatetestmartin-Wed_10_02_29-14338-([0-9]+)\""
Expand Down
5 changes: 4 additions & 1 deletion src/Nethermind/Nethermind.Test.Runner/StateTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@ public class StateTestsRunner : GeneralStateTestBase, IStateTestRunner
private readonly bool _traceMemory;
private readonly bool _traceStack;
private readonly string? _filter;
private readonly ulong _chainId;
private static readonly IJsonSerializer _serializer = new EthereumJsonSerializer();

public StateTestsRunner(ITestSourceLoader testsSource, WhenTrace whenTrace, bool traceMemory, bool traceStack, string? filter = null)
public StateTestsRunner(ITestSourceLoader testsSource, WhenTrace whenTrace, bool traceMemory, bool traceStack, ulong chainId, string? filter = null)
{
_testsSource = testsSource ?? throw new ArgumentNullException(nameof(testsSource));
_whenTrace = whenTrace;
_traceMemory = traceMemory;
_traceStack = traceStack;
_filter = filter;
_chainId = chainId;
Setup(null);
}

Expand Down Expand Up @@ -65,6 +67,7 @@ public IEnumerable<EthereumTestResult> RunTests()
{
if (_filter is not null && !Regex.Match(test.Name, $"^({_filter})").Success)
continue;
test.ChainId = _chainId;

EthereumTestResult result = null;
if (_whenTrace != WhenTrace.Always)
Expand Down
Loading