Skip to content

Commit

Permalink
Pyspec new dir and state test support (#6977)
Browse files Browse the repository at this point in the history
  • Loading branch information
smartprogrammer93 authored May 4, 2024
1 parent f469f94 commit 981fbb1
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@
// SPDX-License-Identifier: LGPL-3.0-only

using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Ethereum.Test.Base;
using FluentAssertions;
using NUnit.Framework;

namespace Ethereum.Blockchain.Pyspec.Test;

[TestFixture]
[Parallelizable(ParallelScope.All)]
public class CancunTests : BlockchainTestBase
public class CancunBlockchainTests : BlockchainTestBase
{
[TestCaseSource(nameof(LoadTests))]
public async Task Test(BlockchainTest test) => await RunTest(test);
public async Task Test(BlockchainTest test) => (await RunTest(test)).Pass.Should().BeTrue();

private static IEnumerable<BlockchainTest> LoadTests()
{
TestsSourceLoader loader = new(new LoadPyspecTestsStrategy(), $"fixtures/cancun");
return (IEnumerable<BlockchainTest>)loader.LoadTests();
TestsSourceLoader loader = new(new LoadPyspecTestsStrategy(), $"fixtures/blockchain_tests/cancun");
return loader.LoadTests().Cast<BlockchainTest>();
}

}
26 changes: 26 additions & 0 deletions src/Nethermind/Ethereum.Blockchain.Pyspec.Test/CancunStateTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System.Collections.Generic;
using System.Linq;
using Ethereum.Test.Base;
using FluentAssertions;
using NUnit.Framework;

namespace Ethereum.Blockchain.Pyspec.Test;

[TestFixture]
[Parallelizable(ParallelScope.All)]
public class CancunStateTests : GeneralStateTestBase
{

[Explicit("We are failing some of those tests")]
[TestCaseSource(nameof(LoadTests))]
public void Test(GeneralStateTest test) => RunTest(test).Pass.Should().BeTrue();

private static IEnumerable<GeneralStateTest> LoadTests()
{
TestsSourceLoader loader = new(new LoadPyspecTestsStrategy(), $"fixtures/state_tests/cancun");
return loader.LoadTests().Cast<GeneralStateTest>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace Ethereum.Blockchain.Pyspec.Test;
public class Constants
{
public const string ARCHIVE_URL_TEMPLATE = "https://github.com/ethereum/execution-spec-tests/releases/download/{0}/{1}";
public const string DEFAULT_ARCHIVE_VERSION = "v1.0.6";
public const string DEFAULT_ARCHIVE_VERSION = "v2.1.1";
public const string DEFAULT_ARCHIVE_NAME = "fixtures_develop.tar.gz";
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ public IEnumerable<IEthereumTest> 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
DownloadAndExtract(ArchiveVersion, ArchiveName, testsDirectoryName);
bool isStateTest = testsDir.Contains("state_tests", StringComparison.InvariantCultureIgnoreCase);
IEnumerable<string> testDirs = !string.IsNullOrEmpty(testsDir)
? Directory.EnumerateDirectories(Path.Combine(testsDirectoryName, testsDir), "*", new EnumerationOptions { RecurseSubdirectories = true })
: Directory.EnumerateDirectories(testsDirectoryName, "*", new EnumerationOptions { RecurseSubdirectories = true });
return testDirs.SelectMany(td => LoadTestsFromDirectory(td, wildcard));
return testDirs.SelectMany(td => LoadTestsFromDirectory(td, wildcard, isStateTest));
}

private void DownloadAndExtract(string archiveVersion, string archiveName, string testsDirectoryName)
Expand All @@ -43,27 +44,33 @@ private void DownloadAndExtract(string archiveVersion, string archiveName, strin
TarFile.ExtractToDirectory(gzStream, testsDirectoryName, true);
}

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

foreach (string testFile in testFiles)
{
FileTestsSource fileTestsSource = new(testFile, wildcard);
try
{
IEnumerable<BlockchainTest> tests = fileTestsSource.LoadBlockchainTests();
foreach (BlockchainTest blockchainTest in tests)
IEnumerable<IEthereumTest> tests = isStateTest
? fileTestsSource.LoadGeneralStateTests()
: fileTestsSource.LoadBlockchainTests();
foreach (IEthereumTest test in tests)
{
blockchainTest.Category = testDir;
test.Category = testDir;
}

testsByName.AddRange(tests);
}
catch (Exception e)
{
testsByName.Add(new BlockchainTest { Name = testFile, LoadFailure = $"Failed to load: {e}" });
IEthereumTest failedTest = isStateTest
? new GeneralStateTest()
: new BlockchainTest();
failedTest.Name = testDir;
failedTest.LoadFailure = $"Failed to load: {e}";
testsByName.Add(failedTest);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: LGPL-3.0-only

using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Ethereum.Test.Base;
using NUnit.Framework;
Expand All @@ -17,7 +18,7 @@ public class ShanghaiTests : BlockchainTestBase

private static IEnumerable<BlockchainTest> LoadTests()
{
TestsSourceLoader loader = new(new LoadPyspecTestsStrategy(), "fixtures/shanghai");
return (IEnumerable<BlockchainTest>)loader.LoadTests();
TestsSourceLoader loader = new(new LoadPyspecTestsStrategy(), "fixtures/blockchain_tests/shanghai");
return loader.LoadTests().Cast<BlockchainTest>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ namespace Ethereum.Test.Base.Interfaces
{
public interface IEthereumTest
{

string? Category { get; set; }
string? Name { get; set; }
string? LoadFailure { get; set; }
}
}

0 comments on commit 981fbb1

Please sign in to comment.