diff --git a/src/Nethermind/Ethereum.Test.Base/BlockchainTestBase.cs b/src/Nethermind/Ethereum.Test.Base/BlockchainTestBase.cs index 98dd868d8ba..008e1a19a95 100644 --- a/src/Nethermind/Ethereum.Test.Base/BlockchainTestBase.cs +++ b/src/Nethermind/Ethereum.Test.Base/BlockchainTestBase.cs @@ -39,7 +39,7 @@ namespace Ethereum.Test.Base { - public abstract class BlockchainTestBase + public class BlockchainTestBase: IBlockchainTestBase { private static InterfaceLogger _logger = new NUnitLogger(LogLevel.Trace); // private static ILogManager _logManager = new OneLoggerLogManager(_logger); @@ -74,7 +74,7 @@ public UInt256 Calculate(BlockHeader header, BlockHeader parent) } } - protected async Task RunTest(BlockchainTest test, Stopwatch? stopwatch = null, bool failOnInvalidRlp = true) + public async Task RunTest(BlockchainTest test, Stopwatch? stopwatch = null, bool failOnInvalidRlp = true) { TestContext.WriteLine($"Running {test.Name}, Network: [{test.Network.Name}] at {DateTime.UtcNow:HH:mm:ss.ffffff}"); if (test.NetworkAfterTransition is not null) diff --git a/src/Nethermind/Ethereum.Test.Base/IBlockchainTestBase.cs b/src/Nethermind/Ethereum.Test.Base/IBlockchainTestBase.cs new file mode 100644 index 00000000000..70a5239b6b0 --- /dev/null +++ b/src/Nethermind/Ethereum.Test.Base/IBlockchainTestBase.cs @@ -0,0 +1,14 @@ +// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using System.Diagnostics; +using System.Threading.Tasks; + +namespace Ethereum.Test.Base; + +public interface IBlockchainTestBase +{ + public void Setup(); + + public Task RunTest(BlockchainTest test, Stopwatch? stopwatch = null, bool failOnInvalidRlp = true); +} diff --git a/src/Nethermind/Ethereum.Test.Base/TestSuffixDiffJson.cs b/src/Nethermind/Ethereum.Test.Base/TestSuffixDiffJson.cs deleted file mode 100644 index 6782bf5def7..00000000000 --- a/src/Nethermind/Ethereum.Test.Base/TestSuffixDiffJson.cs +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited -// SPDX-License-Identifier: LGPL-3.0-only - -namespace Ethereum.Test.Base; - -public class TestSuffixDiffJson -{ - public int Suffix { get; set; } - public string CurrentValue { get; set; } - public string NewValue { get; set; } -} diff --git a/src/Nethermind/Ethereum.Test.Base/VerkleBlockChainTestBase.cs b/src/Nethermind/Ethereum.Test.Base/VerkleBlockChainTestBase.cs index 91f808d3e27..33940df28fd 100644 --- a/src/Nethermind/Ethereum.Test.Base/VerkleBlockChainTestBase.cs +++ b/src/Nethermind/Ethereum.Test.Base/VerkleBlockChainTestBase.cs @@ -35,7 +35,7 @@ namespace Ethereum.Test.Base { - public abstract class VerkleBlockChainTestBase + public class VerkleBlockChainTestBase: IBlockchainTestBase { private static InterfaceLogger _logger = new NUnitLogger(LogLevel.Trace); // private static ILogManager _logManager = new OneLoggerLogManager(_logger); @@ -70,7 +70,7 @@ public UInt256 Calculate(BlockHeader header, BlockHeader parent) } } - protected async Task RunTest(BlockchainTest test, Stopwatch? stopwatch = null, bool failOnInvalidRlp = true) + public async Task RunTest(BlockchainTest test, Stopwatch? stopwatch = null, bool failOnInvalidRlp = true) { Assert.IsNull(test.LoadFailure, "test data loading failure"); diff --git a/src/Nethermind/Nethermind.Test.Runner/BlockchainTestsRunner.cs b/src/Nethermind/Nethermind.Test.Runner/BlockchainTestsRunner.cs index ee23932b43e..073c069a411 100644 --- a/src/Nethermind/Nethermind.Test.Runner/BlockchainTestsRunner.cs +++ b/src/Nethermind/Nethermind.Test.Runner/BlockchainTestsRunner.cs @@ -11,17 +11,19 @@ namespace Nethermind.Test.Runner; -public class BlockchainTestsRunner : BlockchainTestBase, IBlockchainTestRunner +public class BlockchainTestsRunner : IBlockchainTestRunner { private readonly ConsoleColor _defaultColour; private readonly ITestSourceLoader _testsSource; private readonly string? _filter; + private readonly IBlockchainTestBase _blockchainTestBase; - public BlockchainTestsRunner(ITestSourceLoader testsSource, string? filter) + public BlockchainTestsRunner(ITestSourceLoader testsSource, string? filter, IBlockchainTestBase blockchainTestBase) { _testsSource = testsSource ?? throw new ArgumentNullException(nameof(testsSource)); _defaultColour = Console.ForegroundColor; _filter = filter; + _blockchainTestBase = blockchainTestBase; } public async Task> RunTestsAsync() @@ -32,7 +34,7 @@ public async Task> RunTestsAsync() { if (_filter is not null && !Regex.Match(test.Name, $"^({_filter})").Success) continue; - Setup(); + _blockchainTestBase.Setup(); Console.Write($"{test,-120} "); if (test.LoadFailure != null) @@ -42,7 +44,7 @@ public async Task> RunTestsAsync() } else { - EthereumTestResult result = await RunTest(test); + EthereumTestResult result = await _blockchainTestBase.RunTest(test); testResults.Add(result); if (result.Pass) WriteGreen("PASS"); diff --git a/src/Nethermind/Nethermind.Test.Runner/Program.cs b/src/Nethermind/Nethermind.Test.Runner/Program.cs index 07f7158be63..8815b700156 100644 --- a/src/Nethermind/Nethermind.Test.Runner/Program.cs +++ b/src/Nethermind/Nethermind.Test.Runner/Program.cs @@ -68,9 +68,9 @@ private static async Task Run(Options options) while (!string.IsNullOrWhiteSpace(input)) { if (options.VerkleTest) - await RunBlockTest(input, source => new VerkleBlockchainTestsRunner(source, options.Filter)); + await RunBlockTest(input, source => new BlockchainTestsRunner(source, options.Filter, new VerkleBlockChainTestBase())); else if (options.BlockTest) - await RunBlockTest(input, source => new BlockchainTestsRunner(source, options.Filter)); + await RunBlockTest(input, source => new BlockchainTestsRunner(source, options.Filter, new BlockchainTestBase())); else RunStateTest(input, source => new StateTestsRunner(source, whenTrace, !options.ExcludeMemory, !options.ExcludeStack, options.Filter)); if (!options.Stdin) diff --git a/src/Nethermind/Nethermind.Test.Runner/VerkleBlockchainTestsRunner.cs b/src/Nethermind/Nethermind.Test.Runner/VerkleBlockchainTestsRunner.cs deleted file mode 100644 index 7c5d564e29a..00000000000 --- a/src/Nethermind/Nethermind.Test.Runner/VerkleBlockchainTestsRunner.cs +++ /dev/null @@ -1,69 +0,0 @@ -// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited -// SPDX-License-Identifier: LGPL-3.0-only - -using System; -using System.Collections.Generic; -using System.Text.RegularExpressions; -using System.Threading.Tasks; -using Ethereum.Test.Base; -using Ethereum.Test.Base.Interfaces; - -namespace Nethermind.Test.Runner; - -public class VerkleBlockchainTestsRunner : VerkleBlockChainTestBase, IBlockchainTestRunner -{ - private readonly ConsoleColor _defaultColour; - private readonly ITestSourceLoader _testsSource; - private readonly string? _filter; - - public VerkleBlockchainTestsRunner(ITestSourceLoader testsSource, string? filter) - { - _testsSource = testsSource ?? throw new ArgumentNullException(nameof(testsSource)); - _defaultColour = Console.ForegroundColor; - _filter = filter; - } - - public async Task> RunTestsAsync() - { - List testResults = new(); - IEnumerable tests = (IEnumerable)_testsSource.LoadTests(); - foreach (BlockchainTest test in tests) - { - if (_filter is not null && !Regex.Match(test.Name, $"^({_filter})").Success) - continue; - Setup(); - - Console.Write($"{test,-120} "); - if (test.LoadFailure != null) - { - WriteRed(test.LoadFailure); - testResults.Add(new EthereumTestResult(test.Name, test.LoadFailure)); - } - else - { - EthereumTestResult result = await RunTest(test); - testResults.Add(result); - if (result.Pass) - WriteGreen("PASS"); - else - WriteRed("FAIL"); - } - } - - return testResults; - } - - private void WriteRed(string text) - { - Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine(text); - Console.ForegroundColor = _defaultColour; - } - - private void WriteGreen(string text) - { - Console.ForegroundColor = ConsoleColor.Green; - Console.WriteLine(text); - Console.ForegroundColor = _defaultColour; - } -}