diff --git a/.gitmodules b/.gitmodules index 1b67e0567a..513862bb17 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,5 +1,5 @@ [submodule "eth-ref-tests"] - path = ethereum/referencetests/src/test/resources + path = ethereum/referencetests/src/reference-test/external-resources url = https://github.com/ethereum/tests.git ignore = all [submodule "qbft-ref-tests"] diff --git a/ethereum/core/build.gradle b/ethereum/core/build.gradle index ba2e3202bd..0963156ee5 100644 --- a/ethereum/core/build.gradle +++ b/ethereum/core/build.gradle @@ -27,16 +27,6 @@ jar { } } -sourceSets { - test { - java { - compileClasspath += main.output - runtimeClasspath += main.output - srcDirs += file('./build/generated/sources/referencetests/java/test') - } - } -} - dependencies { api 'org.slf4j:slf4j-api' @@ -72,7 +62,6 @@ dependencies { testImplementation project(path: ':config', configuration: 'testSupportArtifacts') testImplementation project(path: ':ethereum:api') testImplementation project(path: ':ethereum:referencetests') - testImplementation project(path: ':ethereum:referencetests', configuration: 'testOutput') testImplementation project(':testutil') testImplementation 'junit:junit' @@ -125,119 +114,6 @@ task testJar(type: Jar) { from sourceSets.test.output } -test { - exclude 'org/hyperledger/besu/ethereum/mainnet/DifficultyCalculatorTests.class' - exclude 'org/hyperledger/besu/ethereum/core/TransactionTest.class' - exclude 'org/hyperledger/besu/ethereum/vm/**ReferenceTest.class' - exclude 'org/hyperledger/besu/ethereum/vm/blockchain/**.class' - exclude 'org/hyperledger/besu/ethereum/vm/generalstate/**.class' -} - -def generateTestFiles(FileTree jsonPath, File templateFile, String pathstrip, String destination, String namePrefix, String ... excludedPath) { - mkdir(destination) - def referenceTestTemplate = templateFile.text - - // This is how many json files to include in each test file - def fileSets = jsonPath.getFiles().collate(5) - - fileSets.eachWithIndex { fileSet, idx -> - def paths = [] - fileSet.each { testJsonFile -> - def parentFile = testJsonFile.getParentFile() - def parentPathFile = parentFile.getPath().substring(parentFile.getPath().indexOf(pathstrip)) - if (!testJsonFile.getName().toString().startsWith(".") && !excludedPath.contains(parentPathFile)) { - def pathFile = testJsonFile.getPath() - paths << pathFile.substring(pathFile.indexOf(pathstrip)) - } - } - - def testFile = file(destination + "/" + namePrefix + "_" + idx + ".java") - - def allPaths = '"' + paths.join('", "') + '"' - - def testFileContents = referenceTestTemplate - .replaceAll("%%TESTS_FILE%%", allPaths) - .replaceAll("%%TESTS_NAME%%", namePrefix + "_" + idx) - testFile.newWriter().withWriter { w -> w << testFileContents } - } -} - -task blockchainReferenceTestsSetup { - inputs.files fileTree('../referencetests/src/test/resources/BlockchainTests') - outputs.files "./build/generated/sources/referencetests/java/test/org/hyperledger/besu/ethereum/vm/blockchain" - generateTestFiles( - fileTree('../referencetests/src/test/resources/BlockchainTests'), - file("./src/test/resources/org/hyperledger/besu/ethereum/vm/BlockchainReferenceTest.java.template"), - "BlockchainTests", - "./build/generated/sources/referencetests/java/test/org/hyperledger/besu/ethereum/vm/blockchain", - "BlockchainReferenceTest", - ("BlockchainTests/InvalidBlocks/bcExpectSection") // exclude test for test filling tool - ) -} - -task generalstateReferenceTestsSetup { - inputs.files fileTree("../referencetests/src/test/resources/GeneralStateTests") - outputs.files "./build/generated/sources/referencetests/java/test/org/hyperledger/besu/ethereum/vm/generalstate" - generateTestFiles( - fileTree("../referencetests/src/test/resources/GeneralStateTests"), - file("./src/test/resources/org/hyperledger/besu/ethereum/vm/GeneralStateReferenceTest.java.template"), - "GeneralStateTests", - "./build/generated/sources/referencetests/java/test/org/hyperledger/besu/ethereum/vm/generalstate", - "GeneralStateReferenceTest" - ) -} - -task generalstateRegressionReferenceTestsSetup { - inputs.files fileTree("./src/test/resources/regressions/generalstate") - outputs.files "./build/generated/sources/referencetests/java/test/org/hyperledger/besu/ethereum/vm/generalstate" - generateTestFiles( - fileTree("./src/test/resources/regressions/generalstate"), - file("./src/test/resources/org/hyperledger/besu/ethereum/vm/GeneralStateReferenceTest.java.template"), - "regressions", - "./build/generated/sources/referencetests/java/test/org/hyperledger/besu/ethereum/vm/generalstate", - "GeneralStateRegressionReferenceTest" - ) -} - -//TODO delete in Jan 2022. This is left as a migration aid for reference tests moving to the build directory -task cleanupReferenceTests(type: Delete) { - delete fileTree("./src/test/java/org/hyperledger/besu/ethereum/vm/generalstate/") { - include("**/GeneralStateReferenceTest*.java") - include("**/GeneralStateRegressionReferenceTest*.java") - include("**/LegacyGeneralStateReferenceTest*.java") - include("**/LegacyGeneralStateRegressionReferenceTest*.java") - } - delete fileTree("./src/test/java/org/hyperledger/besu/ethereum/vm/blockchain/") { - include("**/BlockchainReferenceTest*.java") - include("**/LegacyBlockchainReferenceTest*.java") - } -} - -clean.dependsOn(cleanupReferenceTests) - -task referenceTests(type: Test, dependsOn: [ - "blockchainReferenceTestsSetup", - "generalstateReferenceTestsSetup", - "generalstateRegressionReferenceTestsSetup", - "compileTestJava" -]) { - compileTestJava.mustRunAfter blockchainReferenceTestsSetup - compileTestJava.mustRunAfter generalstateReferenceTestsSetup - compileTestJava.mustRunAfter generalstateRegressionReferenceTestsSetup - doFirst { - if (!file("../referencetests/src/test/resources/README.md").exists()) { - throw new GradleException("ethereum/referencetests/src/test/resources/README.md missing: please clone submodules (git submodule update --init --recursive)") - } - } - scanForTestClasses = false - enableAssertions = true - include 'org/hyperledger/besu/ethereum/core/TransactionTest.class' - include 'org/hyperledger/besu/ethereum/mainnet/DifficultyCalculatorTests.class' - include 'org/hyperledger/besu/ethereum/vm/**ReferenceTest.class' - include 'org/hyperledger/besu/ethereum/vm/blockchain/**.class' - include 'org/hyperledger/besu/ethereum/vm/generalstate/**.class' -} - artifacts { testArtifacts testJar testSupportArtifacts testSupportJar diff --git a/ethereum/referencetests/build.gradle b/ethereum/referencetests/build.gradle index 17b7dd4acd..03e1b4cf7a 100644 --- a/ethereum/referencetests/build.gradle +++ b/ethereum/referencetests/build.gradle @@ -13,16 +13,70 @@ * SPDX-License-Identifier: Apache-2.0 */ +def blockchainReferenceTests = tasks.register("blockchainReferenceTests") { + final referenceTestsPath = 'src/reference-test/external-resources/BlockchainTests' + final generatedTestsPath = "$buildDir/generated/sources/reference-test/$name/java" + inputs.files fileTree(referenceTestsPath), + fileTree(generatedTestsPath) + outputs.files generatedTestsPath + generateTestFiles( + fileTree(referenceTestsPath), + file("src/reference-test/templates/BlockchainReferenceTest.java.template"), + "BlockchainTests", + "$generatedTestsPath/org/hyperledger/besu/ethereum/vm/blockchain", + "BlockchainReferenceTest", + ("BlockchainTests/InvalidBlocks/bcExpectSection") // exclude test for test filling tool + ) +} + +def generalstateReferenceTests = tasks.register("generalstateReferenceTests") { + final referenceTestsPath = "src/reference-test/external-resources/GeneralStateTests" + final generatedTestsPath = "$buildDir/generated/sources/reference-test/$name/java" + inputs.files fileTree(referenceTestsPath), + fileTree(generatedTestsPath) + outputs.files generatedTestsPath + generateTestFiles( + fileTree(referenceTestsPath), + file("src/reference-test/templates/GeneralStateReferenceTest.java.template"), + "GeneralStateTests", + "$generatedTestsPath/org/hyperledger/besu/ethereum/vm/generalstate", + "GeneralStateReferenceTest" + ) +} + +def generalstateRegressionReferenceTests = tasks.register("generalstateRegressionReferenceTests") { + final referenceTestsPath = "src/reference-test/resources/regressions/generalstate" + final generatedTestsPath = "$buildDir/generated/sources/reference-test/$name/java" + inputs.files fileTree(referenceTestsPath), + fileTree(generatedTestsPath) + outputs.files generatedTestsPath + generateTestFiles( + fileTree(referenceTestsPath), + file("src/reference-test/templates/GeneralStateReferenceTest.java.template"), + "regressions", + "$generatedTestsPath/org/hyperledger/besu/ethereum/vm/generalstate", + "GeneralStateRegressionReferenceTest" + ) +} + sourceSets { - test { + referenceTest { + java { + compileClasspath += main.output + runtimeClasspath += main.output + srcDirs "src/reference-test/java", + blockchainReferenceTests, + generalstateReferenceTests, + generalstateRegressionReferenceTests + } resources { - include '*Tests/**/*.json' + srcDirs 'src/reference-test/resources', + 'src/reference-test/external-resources', + 'src/reference-test/templates' } } } -configurations { testOutput } - dependencies { implementation project(':config') implementation project(':crypto') @@ -36,7 +90,36 @@ dependencies { implementation 'com.fasterxml.jackson.core:jackson-databind' implementation 'com.google.guava:guava' - testOutput sourceSets.test.output + referenceTestImplementation project(path: ':config') + referenceTestImplementation project(path: ':datatypes') + referenceTestImplementation project(path: ':ethereum:core') + referenceTestImplementation project(path: ':ethereum:core', configuration: 'testSupportArtifacts') + referenceTestImplementation project(path: ':ethereum:rlp') + referenceTestImplementation project(path: ':ethereum:rlp', configuration: 'testSupportArtifacts') + referenceTestImplementation project(path: ':ethereum:trie') + referenceTestImplementation project(path: ':evm') + referenceTestImplementation project(path: ':testutil') + referenceTestImplementation project(path: ':util') + referenceTestImplementation 'com.fasterxml.jackson.core:jackson-databind' + referenceTestImplementation 'com.google.guava:guava' + referenceTestImplementation 'org.apache.tuweni:tuweni-bytes' + referenceTestImplementation 'org.assertj:assertj-core' + referenceTestImplementation 'org.junit.jupiter:junit-jupiter-api' + referenceTestImplementation 'org.junit.jupiter:junit-jupiter-params' + + referenceTestRuntimeOnly 'org.junit.jupiter:junit-jupiter' +} + +task referenceTests(type: Test) { + useJUnitPlatform() + doFirst { + if (!file("src/reference-test/external-resources/README.md").exists()) { + throw new GradleException("ethereum/referencetest/src/reference-test/external-resources/README.md missing: please clone submodules (git submodule update --init --recursive)") + } + } + description = 'Runs ETH reference tests.' + testClassesDirs = sourceSets.referenceTest.output.classesDirs + classpath = sourceSets.referenceTest.runtimeClasspath } task ('validateReferenceTestSubmodule') { @@ -77,3 +160,33 @@ following commands: } } processResources.dependsOn('validateReferenceTestSubmodule') + +def generateTestFiles(FileTree jsonPath, File templateFile, String pathstrip, String destination, String namePrefix, String ... excludedPath) { + def pep = mkdir(destination) + def referenceTestTemplate = templateFile.text + + // This is how many json files to include in each test file + def fileSets = jsonPath.getFiles().collate(5) + + fileSets.eachWithIndex { fileSet, idx -> + def paths = [] + fileSet.each { testJsonFile -> + def parentFile = testJsonFile.getParentFile() + def parentPathFile = parentFile.getPath().substring(parentFile.getPath().indexOf(pathstrip)) + if (!testJsonFile.getName().toString().startsWith(".") && !excludedPath.contains(parentPathFile)) { + def pathFile = testJsonFile.getPath() + paths << pathFile.substring(pathFile.indexOf(pathstrip)) + } + } + + def testFile = file(destination + "/" + namePrefix + "_" + idx + ".java") + + + def allPaths = '"' + paths.join('", "') + '"' + + def testFileContents = referenceTestTemplate + .replaceAll("%%TESTS_FILE%%", allPaths) + .replaceAll("%%TESTS_NAME%%", namePrefix + "_" + idx) + testFile.newWriter().withWriter { w -> w << testFileContents } + } +} diff --git a/ethereum/referencetests/src/test/resources b/ethereum/referencetests/src/reference-test/external-resources similarity index 100% rename from ethereum/referencetests/src/test/resources rename to ethereum/referencetests/src/reference-test/external-resources diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/TransactionTest.java b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/core/TransactionTest.java similarity index 60% rename from ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/TransactionTest.java rename to ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/core/TransactionTest.java index ba3abebae9..9ee175c160 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/TransactionTest.java +++ b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/core/TransactionTest.java @@ -15,7 +15,6 @@ package org.hyperledger.besu.ethereum.core; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assume.assumeTrue; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.mainnet.MainnetTransactionValidator; @@ -38,16 +37,14 @@ import org.hyperledger.besu.evm.gascalculator.SpuriousDragonGasCalculator; import org.hyperledger.besu.evm.gascalculator.TangerineWhistleGasCalculator; import org.hyperledger.besu.testutil.JsonTestParameters; -import java.util.Collection; import java.util.Optional; +import java.util.stream.Stream; import org.apache.tuweni.bytes.Bytes; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; -@RunWith(Parameterized.class) public class TransactionTest { private static final ReferenceTestProtocolSchedules REFERENCE_TEST_PROTOCOL_SCHEDULES = @@ -60,77 +57,76 @@ public class TransactionTest { .getTransactionValidator(); } - private final String name; - private final TransactionTestCaseSpec spec; - private static final String TEST_CONFIG_FILE_DIR_PATH = "TransactionTests/"; - @Parameters(name = "Name: {0}") - public static Collection getTestParametersForConfig() { + public static Stream getTestParametersForConfig() { return JsonTestParameters.create(TransactionTestCaseSpec.class) .generator((name, spec, collector) -> collector.add(name, spec, true)) - .generate(TEST_CONFIG_FILE_DIR_PATH); - } - - public TransactionTest( - final String name, final TransactionTestCaseSpec spec, final boolean runTest) { - this.name = name; - this.spec = spec; - assumeTrue("Test " + name + " was ignored", runTest); + .generate(TEST_CONFIG_FILE_DIR_PATH).stream().map(params -> Arguments.of(params[0], params[1])); } - @Test - public void frontier() { - milestone("Frontier", new FrontierGasCalculator(), Optional.empty()); + @ParameterizedTest(name = "Name: {0}") + @MethodSource("getTestParametersForConfig") + public void frontier(final String name, final TransactionTestCaseSpec spec) { + milestone(spec, name, "Frontier", new FrontierGasCalculator(), Optional.empty()); } - @Test - public void homestead() { - milestone("Homestead", new HomesteadGasCalculator(), Optional.empty()); + @ParameterizedTest(name = "Name: {0}") + @MethodSource("getTestParametersForConfig") + public void homestead(final String name, final TransactionTestCaseSpec spec) { + milestone(spec, name, "Homestead", new HomesteadGasCalculator(), Optional.empty()); } - @Test - public void eIP150() { - milestone("EIP150", new TangerineWhistleGasCalculator(), Optional.empty()); + @ParameterizedTest(name = "Name: {0}") + @MethodSource("getTestParametersForConfig") + public void eIP150(final String name, final TransactionTestCaseSpec spec) { + milestone(spec, name, "EIP150", new TangerineWhistleGasCalculator(), Optional.empty()); } - @Test - public void eIP158() { - milestone("EIP158", new SpuriousDragonGasCalculator(), Optional.empty()); + @ParameterizedTest(name = "Name: {0}") + @MethodSource("getTestParametersForConfig") + public void eIP158(final String name, final TransactionTestCaseSpec spec) { + milestone(spec, name, "EIP158", new SpuriousDragonGasCalculator(), Optional.empty()); } - @Test - public void byzantium() { - milestone("Byzantium", new ByzantiumGasCalculator(), Optional.empty()); + @ParameterizedTest(name = "Name: {0}") + @MethodSource("getTestParametersForConfig") + public void byzantium(final String name, final TransactionTestCaseSpec spec) { + milestone(spec, name, "Byzantium", new ByzantiumGasCalculator(), Optional.empty()); } - @Test - public void constantinople() { - milestone("Constantinople", new ConstantinopleGasCalculator(), Optional.empty()); + @ParameterizedTest(name = "Name: {0}") + @MethodSource("getTestParametersForConfig") + public void constantinople(final String name, final TransactionTestCaseSpec spec) { + milestone(spec, name, "Constantinople", new ConstantinopleGasCalculator(), Optional.empty()); } - @Test - public void petersburg() { - milestone("ConstantinopleFix", new PetersburgGasCalculator(), Optional.empty()); + @ParameterizedTest(name = "Name: {0}") + @MethodSource("getTestParametersForConfig") + public void petersburg(final String name, final TransactionTestCaseSpec spec) { + milestone(spec, name, "ConstantinopleFix", new PetersburgGasCalculator(), Optional.empty()); } - @Test - public void istanbul() { - milestone("Istanbul", new IstanbulGasCalculator(), Optional.empty()); + @ParameterizedTest(name = "Name: {0}") + @MethodSource("getTestParametersForConfig") + public void istanbul(final String name, final TransactionTestCaseSpec spec) { + milestone(spec, name, "Istanbul", new IstanbulGasCalculator(), Optional.empty()); } - @Test - public void berlin() { - milestone("Berlin", new BerlinGasCalculator(), Optional.empty()); + @ParameterizedTest(name = "Name: {0}") + @MethodSource("getTestParametersForConfig") + public void berlin(final String name, final TransactionTestCaseSpec spec) { + milestone(spec, name, "Berlin", new BerlinGasCalculator(), Optional.empty()); } - @Test - public void london() { - milestone("London", new LondonGasCalculator(), Optional.of(Wei.of(0))); + @ParameterizedTest(name = "Name: {0}") + @MethodSource("getTestParametersForConfig") + public void london(final String name, final TransactionTestCaseSpec spec) { + milestone(spec, name, "London", new LondonGasCalculator(), Optional.of(Wei.of(0))); } public void milestone( - final String milestone, final GasCalculator gasCalculator, final Optional baseFee) { + final TransactionTestCaseSpec spec, final String name, final String milestone, final GasCalculator gasCalculator, final Optional baseFee) { final TransactionTestCaseSpec.Expectation expected = spec.expectation(milestone); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/TransactionTestCaseSpec.java b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/core/TransactionTestCaseSpec.java similarity index 100% rename from ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/TransactionTestCaseSpec.java rename to ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/core/TransactionTestCaseSpec.java diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/DifficultyCalculatorTests.java b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/mainnet/DifficultyCalculatorTests.java similarity index 83% rename from ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/DifficultyCalculatorTests.java rename to ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/mainnet/DifficultyCalculatorTests.java index 1d430946d9..ab69151b05 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/DifficultyCalculatorTests.java +++ b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/mainnet/DifficultyCalculatorTests.java @@ -31,40 +31,28 @@ import org.hyperledger.besu.evm.log.LogsBloomFilter; import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.util.Collection; -import java.util.List; import java.util.Map; +import java.util.stream.Stream; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.common.io.Resources; import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.units.bigints.UInt256; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; -@RunWith(Parameterized.class) public class DifficultyCalculatorTests { - private final String testFile; - private final ProtocolSchedule protocolSchedule; - - public DifficultyCalculatorTests(final String testFile, final ProtocolSchedule protocolSchedule) { - this.testFile = testFile; - this.protocolSchedule = protocolSchedule; - } - - @Parameters(name = "TestFile: {0}") - public static Collection getTestParametersForConfig() throws IOException { - return List.of( - new Object[] { + public static Stream getTestParametersForConfig() throws IOException { + return Stream.of( + Arguments.of( "/BasicTests/difficultyMainNetwork.json", MainnetProtocolSchedule.fromConfig( GenesisConfigFile.mainnet().getConfigOptions(), EvmConfiguration.DEFAULT) - }, - new Object[] { + ), + Arguments.of( "/BasicTests/difficultyRopsten.json", MainnetProtocolSchedule.fromConfig( GenesisConfigFile.fromConfig( @@ -73,54 +61,55 @@ public class DifficultyCalculatorTests { StandardCharsets.UTF_8)) .getConfigOptions(), EvmConfiguration.DEFAULT) - }, - new Object[] { + ), + Arguments.of( "/DifficultyTests/dfArrowGlacier/difficultyArrowGlacierForkBlock.json", MainnetProtocolSchedule.fromConfig( new StubGenesisConfigOptions().arrowGlacierBlock(13773000)) - }, - new Object[] { + ), + Arguments.of( "/DifficultyTests/dfArrowGlacier/difficultyArrowGlacierTimeDiff1.json", MainnetProtocolSchedule.fromConfig( new StubGenesisConfigOptions().arrowGlacierBlock(13773000)) - }, - new Object[] { + ), + Arguments.of( "/DifficultyTests/dfArrowGlacier/difficultyArrowGlacierTimeDiff2.json", MainnetProtocolSchedule.fromConfig( new StubGenesisConfigOptions().arrowGlacierBlock(13773000)) - }, - new Object[] { + ), + Arguments.of( "/DifficultyTests/dfByzantium/difficultyByzantium.json", MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().byzantiumBlock(0)) - }, - new Object[] { + ), + Arguments.of( "/DifficultyTests/dfConstantinople/difficultyConstantinople.json", MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().constantinopleBlock(0)) - }, - new Object[] { + ), + Arguments.of( "/DifficultyTests/dfEIP2384/difficultyEIP2384.json", MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().muirGlacierBlock(0)) - }, - new Object[] { + ), + Arguments.of( "/DifficultyTests/dfEIP2384/difficultyEIP2384_random.json", MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().muirGlacierBlock(0)) - }, - new Object[] { + ), + Arguments.of( "/DifficultyTests/dfEIP2384/difficultyEIP2384_random_to20M.json", MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().muirGlacierBlock(0)) - }, - new Object[] { + ), + Arguments.of( "/DifficultyTests/dfFrontier/difficultyFrontier.json", MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions()) - }, - new Object[] { + ), + Arguments.of( "/DifficultyTests/dfHomestead/difficultyHomestead.json", MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().homesteadBlock(0)) - }); + )); } - @Test - public void testDifficultyCalculation() throws IOException { + @ParameterizedTest(name = "TestFile: {0}") + @MethodSource("getTestParametersForConfig") + public void testDifficultyCalculation(final String testFile, final ProtocolSchedule protocolSchedule) throws IOException { final MainnetBlockHeaderFunctions blockHeaderFunctions = new MainnetBlockHeaderFunctions(); final ObjectNode testObject = JsonUtil.objectNodeFromString( @@ -135,17 +124,17 @@ public class DifficultyCalculatorTests { while (testHolderIter.hasNext()) { final var testList = testHolderIter.next(); if (!testList.getKey().equals("_info")) { - testDifficulty(blockHeaderFunctions, (ObjectNode) testList.getValue()); + testDifficulty(testFile, protocolSchedule, blockHeaderFunctions, (ObjectNode) testList.getValue()); } } } } else { - testDifficulty(blockHeaderFunctions, testObject); + testDifficulty(testFile, protocolSchedule, blockHeaderFunctions, testObject); } } private void testDifficulty( - final MainnetBlockHeaderFunctions blockHeaderFunctions, final ObjectNode testObject) { + final String testFile, final ProtocolSchedule protocolSchedule, final MainnetBlockHeaderFunctions blockHeaderFunctions, final ObjectNode testObject) { final var fields = testObject.fields(); while (fields.hasNext()) { final var entry = fields.next(); diff --git a/ethereum/rlp/src/test/java/org/hyperledger/besu/ethereum/rlp/InvalidRLPRefTest.java b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/rlp/InvalidRLPRefTest.java similarity index 67% rename from ethereum/rlp/src/test/java/org/hyperledger/besu/ethereum/rlp/InvalidRLPRefTest.java rename to ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/rlp/InvalidRLPRefTest.java index bb55cd0b93..718e5d19bd 100644 --- a/ethereum/rlp/src/test/java/org/hyperledger/besu/ethereum/rlp/InvalidRLPRefTest.java +++ b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/rlp/InvalidRLPRefTest.java @@ -15,21 +15,19 @@ package org.hyperledger.besu.ethereum.rlp; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assume.assumeTrue; +import static org.junit.jupiter.api.Assumptions.assumeTrue; import org.hyperledger.besu.ethereum.rlp.util.RLPTestUtil; import org.hyperledger.besu.testutil.JsonTestParameters; -import java.util.Collection; +import java.util.stream.Stream; import org.apache.tuweni.bytes.Bytes; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; /** The Ethereum reference RLP tests. */ -@RunWith(Parameterized.class) public class InvalidRLPRefTest { private static final String[] TEST_CONFIG_FILES = { @@ -37,22 +35,15 @@ public class InvalidRLPRefTest { "org/hyperledger/besu/ethereum/rlp/invalidRLPTest.json", "RLPTests/invalidRLPTest.json" }; - private final InvalidRLPRefTestCaseSpec spec; - - public InvalidRLPRefTest( - final String name, final InvalidRLPRefTestCaseSpec spec, final boolean runTest) { - this.spec = spec; - assumeTrue("Test was blacklisted", runTest); - } - - @Parameters(name = "Name: {0}") - public static Collection getTestParametersForConfig() { - return JsonTestParameters.create(InvalidRLPRefTestCaseSpec.class).generate(TEST_CONFIG_FILES); + public static Stream getTestParametersForConfig() { + return JsonTestParameters.create(InvalidRLPRefTestCaseSpec.class).generate(TEST_CONFIG_FILES).stream().map(params -> Arguments.of(params[0], params[1], params[2])); } /** Test RLP decoding. */ - @Test - public void decode() throws Exception { + @ParameterizedTest(name = "Name: {0}") + @MethodSource("getTestParametersForConfig") + public void decode(final String name, final InvalidRLPRefTestCaseSpec spec, final boolean runTest) { + assumeTrue(runTest, "Test was blacklisted"); final Bytes rlp = spec.getRLP(); assertThatThrownBy(() -> RLPTestUtil.decode(rlp)).isInstanceOf(RLPException.class); } diff --git a/ethereum/rlp/src/test/java/org/hyperledger/besu/ethereum/rlp/InvalidRLPRefTestCaseSpec.java b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/rlp/InvalidRLPRefTestCaseSpec.java similarity index 100% rename from ethereum/rlp/src/test/java/org/hyperledger/besu/ethereum/rlp/InvalidRLPRefTestCaseSpec.java rename to ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/rlp/InvalidRLPRefTestCaseSpec.java diff --git a/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/rlp/RLPRefTest.java b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/rlp/RLPRefTest.java new file mode 100644 index 0000000000..a4eff43c98 --- /dev/null +++ b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/rlp/RLPRefTest.java @@ -0,0 +1,51 @@ +/* + * Copyright ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.ethereum.rlp; + +import static org.junit.jupiter.api.Assumptions.assumeTrue; + +import org.assertj.core.api.Assertions; +import org.hyperledger.besu.ethereum.rlp.util.RLPTestUtil; +import org.hyperledger.besu.testutil.JsonTestParameters; + +import java.util.stream.Stream; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +/** The Ethereum reference RLP tests. */ +public class RLPRefTest { + + private static final String TEST_CONFIG_FILES = "RLPTests/rlptest.json"; + + public static Stream getTestParametersForConfig() { + return JsonTestParameters.create(RLPRefTestCaseSpec.class).generate(TEST_CONFIG_FILES).stream().map(params -> Arguments.of(params[0], params[1], params[2])); + } + + @ParameterizedTest(name = "Name: {0}") + @MethodSource("getTestParametersForConfig") + public void encode(final String name, final RLPRefTestCaseSpec spec, final boolean runTest) { + assumeTrue(runTest, "Test was blacklisted"); + Assertions.assertThat(RLPTestUtil.encode(spec.getIn())).isEqualTo(spec.getOut()); + } + + @ParameterizedTest(name = "Name: {0}") + @MethodSource("getTestParametersForConfig") + public void decode(final String name, final RLPRefTestCaseSpec spec, final boolean runTest) { + assumeTrue(runTest, "Test was blacklisted"); + Assertions.assertThat(RLPTestUtil.decode(spec.getOut())).isEqualTo(spec.getIn()); + } +} diff --git a/ethereum/rlp/src/test/java/org/hyperledger/besu/ethereum/rlp/RLPRefTestCaseSpec.java b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/rlp/RLPRefTestCaseSpec.java similarity index 100% rename from ethereum/rlp/src/test/java/org/hyperledger/besu/ethereum/rlp/RLPRefTestCaseSpec.java rename to ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/rlp/RLPRefTestCaseSpec.java diff --git a/ethereum/trie/src/test/java/org/hyperledger/besu/ethereum/trie/TrieRefTest.java b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/trie/TrieRefTest.java similarity index 67% rename from ethereum/trie/src/test/java/org/hyperledger/besu/ethereum/trie/TrieRefTest.java rename to ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/trie/TrieRefTest.java index 3dc3c13d79..cc9eea6cf7 100644 --- a/ethereum/trie/src/test/java/org/hyperledger/besu/ethereum/trie/TrieRefTest.java +++ b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/trie/TrieRefTest.java @@ -15,38 +15,30 @@ package org.hyperledger.besu.ethereum.trie; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assume.assumeTrue; +import static org.junit.jupiter.api.Assumptions.assumeTrue; import org.hyperledger.besu.testutil.JsonTestParameters; -import java.util.Collection; import java.util.function.Function; +import java.util.stream.Stream; import org.apache.tuweni.bytes.Bytes; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; -@RunWith(Parameterized.class) public class TrieRefTest { private static final String[] TEST_CONFIG_FILES = {"TrieTests/trietest.json"}; - private final TrieRefTestCaseSpec spec; - - public TrieRefTest(final String name, final TrieRefTestCaseSpec spec, final boolean runTest) { - this.spec = spec; - assumeTrue("Test was blacklisted", runTest); - } - - @Parameters(name = "Name: {0}") - public static Collection getTestParametersForConfig() { - return JsonTestParameters.create(TrieRefTestCaseSpec.class).generate(TEST_CONFIG_FILES); + public static Stream getTestParametersForConfig() { + return JsonTestParameters.create(TrieRefTestCaseSpec.class).generate(TEST_CONFIG_FILES).stream().map(params -> Arguments.of(params[0], params[1], params[2])); } - @Test - public void rootHashAfterInsertionsAndRemovals() { + @ParameterizedTest(name = "Name: {0}") + @MethodSource("getTestParametersForConfig") + public void rootHashAfterInsertionsAndRemovals(final String name, final TrieRefTestCaseSpec spec, final boolean runTest) { + assumeTrue(runTest, "Test was blacklisted"); final SimpleMerklePatriciaTrie trie = new SimpleMerklePatriciaTrie<>(Function.identity()); for (final Bytes[] pair : spec.getIn()) { diff --git a/ethereum/trie/src/test/java/org/hyperledger/besu/ethereum/trie/TrieRefTestCaseSpec.java b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/trie/TrieRefTestCaseSpec.java similarity index 100% rename from ethereum/trie/src/test/java/org/hyperledger/besu/ethereum/trie/TrieRefTestCaseSpec.java rename to ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/trie/TrieRefTestCaseSpec.java diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/vm/BlockchainReferenceTestTools.java b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/vm/BlockchainReferenceTestTools.java similarity index 100% rename from ethereum/core/src/test/java/org/hyperledger/besu/ethereum/vm/BlockchainReferenceTestTools.java rename to ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/vm/BlockchainReferenceTestTools.java diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/vm/GeneralStateReferenceTestTools.java b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/vm/GeneralStateReferenceTestTools.java similarity index 100% rename from ethereum/core/src/test/java/org/hyperledger/besu/ethereum/vm/GeneralStateReferenceTestTools.java rename to ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/vm/GeneralStateReferenceTestTools.java diff --git a/ethereum/rlp/src/test/resources/org/hyperledger/besu/ethereum/rlp/invalidRLPTest.json b/ethereum/referencetests/src/reference-test/resources/org/hyperledger/besu/ethereum/rlp/invalidRLPTest.json similarity index 100% rename from ethereum/rlp/src/test/resources/org/hyperledger/besu/ethereum/rlp/invalidRLPTest.json rename to ethereum/referencetests/src/reference-test/resources/org/hyperledger/besu/ethereum/rlp/invalidRLPTest.json diff --git a/ethereum/core/src/test/resources/regressions/generalstate/ripeMdAccountShouldBeDeletedWhenEmptyAndTouchedTransactionSucceedsPostEIP158.json b/ethereum/referencetests/src/reference-test/resources/regressions/generalstate/ripeMdAccountShouldBeDeletedWhenEmptyAndTouchedTransactionSucceedsPostEIP158.json similarity index 100% rename from ethereum/core/src/test/resources/regressions/generalstate/ripeMdAccountShouldBeDeletedWhenEmptyAndTouchedTransactionSucceedsPostEIP158.json rename to ethereum/referencetests/src/reference-test/resources/regressions/generalstate/ripeMdAccountShouldBeDeletedWhenEmptyAndTouchedTransactionSucceedsPostEIP158.json diff --git a/ethereum/core/src/test/resources/regressions/generalstate/ripeMdAccountShouldNotBeDeletedWhenEmptyAndTouchedTransactionFails.json b/ethereum/referencetests/src/reference-test/resources/regressions/generalstate/ripeMdAccountShouldNotBeDeletedWhenEmptyAndTouchedTransactionFails.json similarity index 100% rename from ethereum/core/src/test/resources/regressions/generalstate/ripeMdAccountShouldNotBeDeletedWhenEmptyAndTouchedTransactionFails.json rename to ethereum/referencetests/src/reference-test/resources/regressions/generalstate/ripeMdAccountShouldNotBeDeletedWhenEmptyAndTouchedTransactionFails.json diff --git a/ethereum/core/src/test/resources/regressions/generalstate/ripeMdAccountShouldNotBeDeletedWhenNonEmptyAndTouchedTransactionFails.json b/ethereum/referencetests/src/reference-test/resources/regressions/generalstate/ripeMdAccountShouldNotBeDeletedWhenNonEmptyAndTouchedTransactionFails.json similarity index 100% rename from ethereum/core/src/test/resources/regressions/generalstate/ripeMdAccountShouldNotBeDeletedWhenNonEmptyAndTouchedTransactionFails.json rename to ethereum/referencetests/src/reference-test/resources/regressions/generalstate/ripeMdAccountShouldNotBeDeletedWhenNonEmptyAndTouchedTransactionFails.json diff --git a/ethereum/core/src/test/resources/regressions/generalstate/ripeMdAccountShouldNotBeDeletedWhenNonEmptyAndTouchedTransactionSucceeds.json b/ethereum/referencetests/src/reference-test/resources/regressions/generalstate/ripeMdAccountShouldNotBeDeletedWhenNonEmptyAndTouchedTransactionSucceeds.json similarity index 100% rename from ethereum/core/src/test/resources/regressions/generalstate/ripeMdAccountShouldNotBeDeletedWhenNonEmptyAndTouchedTransactionSucceeds.json rename to ethereum/referencetests/src/reference-test/resources/regressions/generalstate/ripeMdAccountShouldNotBeDeletedWhenNonEmptyAndTouchedTransactionSucceeds.json diff --git a/ethereum/core/src/test/resources/org/hyperledger/besu/ethereum/vm/BlockchainReferenceTest.java.template b/ethereum/referencetests/src/reference-test/templates/BlockchainReferenceTest.java.template similarity index 56% rename from ethereum/core/src/test/resources/org/hyperledger/besu/ethereum/vm/BlockchainReferenceTest.java.template rename to ethereum/referencetests/src/reference-test/templates/BlockchainReferenceTest.java.template index 3ea7337574..f8b99e8a73 100644 --- a/ethereum/core/src/test/resources/org/hyperledger/besu/ethereum/vm/BlockchainReferenceTest.java.template +++ b/ethereum/referencetests/src/reference-test/templates/BlockchainReferenceTest.java.template @@ -5,38 +5,32 @@ import static org.hyperledger.besu.ethereum.vm.BlockchainReferenceTestTools.gene import org.hyperledger.besu.ethereum.referencetests.BlockchainReferenceTestCaseSpec; -import java.util.Collection; +import java.util.stream.Stream; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; -import static org.junit.Assume.assumeTrue; +import static org.junit.jupiter.api.Assumptions.assumeTrue; /** The blockchain test operation testing framework entry point. */ -@RunWith(Parameterized.class) public class %%TESTS_NAME%% { private static final String[] TEST_CONFIG_FILE_DIR_PATH = new String[] {%%TESTS_FILE%%}; - @Parameters(name = "Name: {0}") - public static Collection getTestParametersForConfig() { - return generateTestParametersForConfig(TEST_CONFIG_FILE_DIR_PATH); + public static Stream getTestParametersForConfig() { + return generateTestParametersForConfig(TEST_CONFIG_FILE_DIR_PATH).stream().map(params -> + Arguments.of(params[0], params[1], params[2]) + ); } - private final BlockchainReferenceTestCaseSpec spec; - - public %%TESTS_NAME%%( + @ParameterizedTest(name = "Name: {0}") + @MethodSource("getTestParametersForConfig") + public void execution( final String name, final BlockchainReferenceTestCaseSpec spec, final boolean runTest) { - this.spec = spec; - assumeTrue("Test " + name + " was ignored", runTest); - } - - @Test - public void execution() { + assumeTrue(runTest, "Test " + name + " was ignored"); executeTest(spec); } } diff --git a/ethereum/core/src/test/resources/org/hyperledger/besu/ethereum/vm/GeneralStateReferenceTest.java.template b/ethereum/referencetests/src/reference-test/templates/GeneralStateReferenceTest.java.template similarity index 53% rename from ethereum/core/src/test/resources/org/hyperledger/besu/ethereum/vm/GeneralStateReferenceTest.java.template rename to ethereum/referencetests/src/reference-test/templates/GeneralStateReferenceTest.java.template index 1401783207..4b93b87733 100644 --- a/ethereum/core/src/test/resources/org/hyperledger/besu/ethereum/vm/GeneralStateReferenceTest.java.template +++ b/ethereum/referencetests/src/reference-test/templates/GeneralStateReferenceTest.java.template @@ -2,41 +2,36 @@ package org.hyperledger.besu.ethereum.vm.generalstate; import static org.hyperledger.besu.ethereum.vm.GeneralStateReferenceTestTools.executeTest; import static org.hyperledger.besu.ethereum.vm.GeneralStateReferenceTestTools.generateTestParametersForConfig; +import static org.junit.jupiter.api.Assumptions.assumeTrue; import org.hyperledger.besu.ethereum.referencetests.GeneralStateTestCaseEipSpec; -import java.util.Collection; +import java.util.stream.Stream; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; -import static org.junit.Assume.assumeTrue; +import static org.junit.jupiter.api.Assumptions.assumeTrue; /** The general state test operation testing framework entry point. */ -@RunWith(Parameterized.class) public class %%TESTS_NAME%% { private static final String[] TEST_CONFIG_FILE_DIR_PATH = new String[] {%%TESTS_FILE%%}; - @Parameters(name = "Name: {0}") - public static Collection getTestParametersForConfig() { - return generateTestParametersForConfig(TEST_CONFIG_FILE_DIR_PATH); + public static Stream getTestParametersForConfig() { + return generateTestParametersForConfig(TEST_CONFIG_FILE_DIR_PATH).stream().map(params -> + Arguments.of(params[0], params[1], params[2]) + ); } - private final GeneralStateTestCaseEipSpec spec; - - public %%TESTS_NAME%%( + @ParameterizedTest(name = "Name: {0}") + @MethodSource("getTestParametersForConfig") + public void execution( final String name, final GeneralStateTestCaseEipSpec spec, final boolean runTest) { - this.spec = spec; - assumeTrue("Test " + name + " was ignored", runTest); - } - - @Test - public void execution() { + assumeTrue(runTest, "Test " + name + " was ignored"); executeTest(spec); } } diff --git a/ethereum/rlp/build.gradle b/ethereum/rlp/build.gradle index 802a11b66f..2eda1e1102 100644 --- a/ethereum/rlp/build.gradle +++ b/ethereum/rlp/build.gradle @@ -35,7 +35,6 @@ dependencies { jmh project(':util') - testImplementation project(path: ':ethereum:referencetests', configuration: 'testOutput') testImplementation project(':testutil') testImplementation 'com.fasterxml.jackson.core:jackson-databind' @@ -46,17 +45,6 @@ dependencies { testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } -test { - exclude 'org/hyperledger/besu/ethereum/rlp/InvalidRLPRefTest.class' - exclude 'org/hyperledger/besu/ethereum/rlp/RLPRefTest.class' -} - -task referenceTests(type: Test, dependsOn: ['compileTestJava']) { - doFirst { - if (!file("../referencetests/src/test/resources/README.md").exists()) { - throw new GradleException("ethereum/referencetests/src/test/resources/README.md missing: please clone submodules (git submodule update --init --recursive)") - } - } - include 'org/hyperledger/besu/ethereum/rlp/InvalidRLPRefTest.class' - include 'org/hyperledger/besu/ethereum/rlp/RLPRefTest.class' +artifacts { + testSupportArtifacts testSupportJar } diff --git a/ethereum/rlp/src/test/java/org/hyperledger/besu/ethereum/rlp/util/RLPTestUtil.java b/ethereum/rlp/src/test-support/java/org/hyperledger/besu/ethereum/rlp/util/RLPTestUtil.java similarity index 100% rename from ethereum/rlp/src/test/java/org/hyperledger/besu/ethereum/rlp/util/RLPTestUtil.java rename to ethereum/rlp/src/test-support/java/org/hyperledger/besu/ethereum/rlp/util/RLPTestUtil.java diff --git a/ethereum/rlp/src/test/java/org/hyperledger/besu/ethereum/rlp/RLPRefTest.java b/ethereum/rlp/src/test/java/org/hyperledger/besu/ethereum/rlp/RLPRefTest.java deleted file mode 100644 index f958fab282..0000000000 --- a/ethereum/rlp/src/test/java/org/hyperledger/besu/ethereum/rlp/RLPRefTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.ethereum.rlp; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assume.assumeTrue; - -import org.hyperledger.besu.ethereum.rlp.util.RLPTestUtil; -import org.hyperledger.besu.testutil.JsonTestParameters; - -import java.util.Collection; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; - -/** The Ethereum reference RLP tests. */ -@RunWith(Parameterized.class) -public class RLPRefTest { - - private static final String TEST_CONFIG_FILES = "RLPTests/rlptest.json"; - - private final RLPRefTestCaseSpec spec; - - public RLPRefTest(final String name, final RLPRefTestCaseSpec spec, final boolean runTest) { - this.spec = spec; - assumeTrue("Test was blacklisted", runTest); - } - - @Parameters(name = "Name: {0}") - public static Collection getTestParametersForConfig() { - return JsonTestParameters.create(RLPRefTestCaseSpec.class).generate(TEST_CONFIG_FILES); - } - - @Test - public void encode() { - assertThat(RLPTestUtil.encode(spec.getIn())).isEqualTo(spec.getOut()); - } - - @Test - public void decode() { - assertThat(RLPTestUtil.decode(spec.getOut())).isEqualTo(spec.getIn()); - } -} diff --git a/ethereum/trie/build.gradle b/ethereum/trie/build.gradle index 0e87bafaf9..5bf23f0e42 100644 --- a/ethereum/trie/build.gradle +++ b/ethereum/trie/build.gradle @@ -41,7 +41,6 @@ dependencies { implementation "org.immutables:value-annotations" testImplementation project(':testutil') - testImplementation project(path: ':ethereum:referencetests', configuration: 'testOutput') testImplementation 'com.fasterxml.jackson.core:jackson-databind' testImplementation 'junit:junit' @@ -52,14 +51,3 @@ dependencies { testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } - -test { exclude 'org/hyperledger/besu/ethereum/trie/TrieRefTest.class' } - -task referenceTests(type: Test, dependsOn: ['compileTestJava']) { - doFirst { - if (!file("../referencetests/src/test/resources/README.md").exists()) { - throw new GradleException("ethereum/referencetests/src/test/resources/README.md missing: please clone submodules (git submodule update --init --recursive)") - } - } - include 'org/hyperledger/besu/ethereum/trie/TrieRefTest.class' -}