Migrate referenceTests to Junit5 (#3850)

* Remove deprecated cleanup task
* Move util class into test-support
This is because this class can be used outside the scope of the junit tests but it'll not be part of main
* Move referenceTests into its own scope
* Migrate referenceTests to Junit5

I inlined `o.h.b.e.vm.AbstractRetryingTest` into `o.h.b.e.vm.VMReferenceTest` because there was a single usage of the abstraction and also because it wasn't portable to how Junit5 parameters work

Signed-off-by: Diego López León <dieguitoll@gmail.com>

Co-authored-by: Danno Ferrin <danno.ferrin@gmail.com>
Co-authored-by: Sally MacFarlane <sally.macfarlane@consensys.net>
pull/3934/head
Diego López León 3 years ago committed by GitHub
parent 5b55c0a34e
commit 02d389a19e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      .gitmodules
  2. 124
      ethereum/core/build.gradle
  3. 123
      ethereum/referencetests/build.gradle
  4. 0
      ethereum/referencetests/src/reference-test/external-resources
  5. 98
      ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/core/TransactionTest.java
  6. 0
      ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/core/TransactionTestCaseSpec.java
  7. 83
      ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/mainnet/DifficultyCalculatorTests.java
  8. 31
      ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/rlp/InvalidRLPRefTest.java
  9. 0
      ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/rlp/InvalidRLPRefTestCaseSpec.java
  10. 51
      ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/rlp/RLPRefTest.java
  11. 0
      ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/rlp/RLPRefTestCaseSpec.java
  12. 30
      ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/trie/TrieRefTest.java
  13. 0
      ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/trie/TrieRefTestCaseSpec.java
  14. 0
      ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/vm/BlockchainReferenceTestTools.java
  15. 0
      ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/vm/GeneralStateReferenceTestTools.java
  16. 0
      ethereum/referencetests/src/reference-test/resources/org/hyperledger/besu/ethereum/rlp/invalidRLPTest.json
  17. 0
      ethereum/referencetests/src/reference-test/resources/regressions/generalstate/ripeMdAccountShouldBeDeletedWhenEmptyAndTouchedTransactionSucceedsPostEIP158.json
  18. 0
      ethereum/referencetests/src/reference-test/resources/regressions/generalstate/ripeMdAccountShouldNotBeDeletedWhenEmptyAndTouchedTransactionFails.json
  19. 0
      ethereum/referencetests/src/reference-test/resources/regressions/generalstate/ripeMdAccountShouldNotBeDeletedWhenNonEmptyAndTouchedTransactionFails.json
  20. 0
      ethereum/referencetests/src/reference-test/resources/regressions/generalstate/ripeMdAccountShouldNotBeDeletedWhenNonEmptyAndTouchedTransactionSucceeds.json
  21. 32
      ethereum/referencetests/src/reference-test/templates/BlockchainReferenceTest.java.template
  22. 33
      ethereum/referencetests/src/reference-test/templates/GeneralStateReferenceTest.java.template
  23. 16
      ethereum/rlp/build.gradle
  24. 0
      ethereum/rlp/src/test-support/java/org/hyperledger/besu/ethereum/rlp/util/RLPTestUtil.java
  25. 57
      ethereum/rlp/src/test/java/org/hyperledger/besu/ethereum/rlp/RLPRefTest.java
  26. 12
      ethereum/trie/build.gradle

2
.gitmodules vendored

@ -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"]

@ -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

@ -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 }
}
}

@ -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<Object[]> getTestParametersForConfig() {
public static Stream<Arguments> 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<Wei> baseFee) {
final TransactionTestCaseSpec spec, final String name, final String milestone, final GasCalculator gasCalculator, final Optional<Wei> baseFee) {
final TransactionTestCaseSpec.Expectation expected = spec.expectation(milestone);

@ -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<Object[]> getTestParametersForConfig() throws IOException {
return List.of(
new Object[] {
public static Stream<Arguments> 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();

@ -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<Object[]> getTestParametersForConfig() {
return JsonTestParameters.create(InvalidRLPRefTestCaseSpec.class).generate(TEST_CONFIG_FILES);
public static Stream<Arguments> 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);
}

@ -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<Arguments> 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());
}
}

@ -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<Object[]> getTestParametersForConfig() {
return JsonTestParameters.create(TrieRefTestCaseSpec.class).generate(TEST_CONFIG_FILES);
public static Stream<Arguments> 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<Bytes, Bytes> trie =
new SimpleMerklePatriciaTrie<>(Function.identity());
for (final Bytes[] pair : spec.getIn()) {

@ -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<Object[]> getTestParametersForConfig() {
return generateTestParametersForConfig(TEST_CONFIG_FILE_DIR_PATH);
public static Stream<Arguments> 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);
}
}

@ -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<Object[]> getTestParametersForConfig() {
return generateTestParametersForConfig(TEST_CONFIG_FILE_DIR_PATH);
public static Stream<Arguments> 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);
}
}

@ -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
}

@ -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<Object[]> 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());
}
}

@ -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'
}

Loading…
Cancel
Save