forked from besu-eth/besu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
500 lines (454 loc) · 19.7 KB
/
build.gradle
File metadata and controls
500 lines (454 loc) · 19.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
/*
* 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
*/
apply plugin: 'java-library'
jar {
archiveBaseName = calculateArtifactId(project)
manifest {
attributes(
'Specification-Title': archiveBaseName,
'Specification-Version': project.version,
'Implementation-Title': archiveBaseName,
'Implementation-Version': calculateVersion(),
'Commit-Hash': getGitCommitDetails(40).hash
)
}
}
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",
"org.hyperledger.besu.ethereum.vm.blockchain",
("BlockchainTests/InvalidBlocks/bcExpectSection") // exclude test for test filling tool
)
}
def eipBlockchainReferenceTests = tasks.register("eipBlockchainReferenceTests") {
final referenceTestsPath = 'src/reference-test/external-resources/EIPTests/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"),
"EIPTests${File.separatorChar}BlockchainTests",
"$generatedTestsPath/org/hyperledger/besu/ethereum/vm/eip",
"EIPBlockchainReferenceTest",
"org.hyperledger.besu.ethereum.vm.eip",
"EIPTests${File.separatorChar}BlockchainTests${File.separatorChar}StateTests${File.separatorChar}stEOF" // exclude EOF tests
)
}
def eipStateReferenceTests = tasks.register("eipStateReferenceTests") {
final referenceTestsPath = 'src/reference-test/external-resources/EIPTests/StateTests'
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"),
"EIPTests${File.separatorChar}StateTests",
"$generatedTestsPath/org/hyperledger/besu/ethereum/vm/eip",
"EIPStateReferenceTest",
"org.hyperledger.besu.ethereum.vm.eip",
"EIPTests${File.separatorChar}StateTests${File.separatorChar}stEOF" // exclude EOF tests
)
}
def extractStableFixtures = tasks.register("extractStableFixtures", Copy) {
from {
tarTree(configurations.tarConfig.files.find { it.name.startsWith('execution-spec-tests') })
}
into layout.buildDirectory.dir("execution-spec-tests")
}
def executionSpecTests = tasks.register("executionSpecTests") {
dependsOn extractStableFixtures
final referenceTestsDir = layout.buildDirectory.dir("execution-spec-tests")
final generatedTestsDir = layout.buildDirectory.dir("generated/sources/reference-test/$name/java")
inputs.dir referenceTestsDir
inputs.files fileTree("src/reference-test/templates")
outputs.dir generatedTestsDir
doLast {
// generate blockchain_tests grouped by hardfork/EIP:
generateTestFilesGroupedByDirectory(
fileTree(referenceTestsDir.get().dir("fixtures/blockchain_tests")),
file("src/reference-test/templates/BlockchainReferenceTest.java.template"),
"fixtures",
"blockchain_tests",
generatedTestsDir.get().dir("org/hyperledger/besu/ethereum/vm/executionspec").asFile.path,
"ExecutionSpecBlockchainTest",
"org.hyperledger.besu.ethereum.vm.executionspec",
)
// generate state_tests grouped by hardfork/EIP:
generateTestFilesGroupedByDirectory(
fileTree(referenceTestsDir.get().dir("fixtures/state_tests")),
file("src/reference-test/templates/GeneralStateReferenceTest.java.template"),
"fixtures",
"state_tests",
generatedTestsDir.get().dir("org/hyperledger/besu/ethereum/vm/executionspec").asFile.path,
"ExecutionSpecStateTest",
"org.hyperledger.besu.ethereum.vm.executionspec",
)
}
}
def extractDevnetFixtures = tasks.register("extractDevnetFixtures", Copy) {
from {
tarTree(configurations.devnetTarConfig.files.find { it.name.startsWith('execution-spec-tests') })
}
into layout.buildDirectory.dir("execution-spec-devnet-tests")
}
def executionSpecDevnetTests = tasks.register("executionSpecDevnetTests") {
dependsOn extractDevnetFixtures
final referenceTestsDir = layout.buildDirectory.dir("execution-spec-devnet-tests")
final generatedTestsDir = layout.buildDirectory.dir("generated/sources/reference-test/$name/java")
inputs.dir referenceTestsDir
inputs.files fileTree("src/reference-test/templates")
outputs.dir generatedTestsDir
doLast {
generateTestFilesGroupedByDirectory(
fileTree(referenceTestsDir.get().dir("fixtures/blockchain_tests")),
file("src/reference-test/templates/BlockchainReferenceTest.java.template"),
"fixtures",
"blockchain_tests",
generatedTestsDir.get().dir("org/hyperledger/besu/ethereum/vm/executionspecdevnet").asFile.path,
"ExecutionSpecDevnetBlockchainTest",
"org.hyperledger.besu.ethereum.vm.executionspecdevnet",
)
generateTestFilesGroupedByDirectory(
fileTree(referenceTestsDir.get().dir("fixtures/state_tests")),
file("src/reference-test/templates/GeneralStateReferenceTest.java.template"),
"fixtures",
"state_tests",
generatedTestsDir.get().dir("org/hyperledger/besu/ethereum/vm/executionspecdevnet").asFile.path,
"ExecutionSpecDevnetStateTest",
"org.hyperledger.besu.ethereum.vm.executionspecdevnet",
)
}
}
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",
"org.hyperledger.besu.ethereum.vm.generalstate",
)
}
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",
"org.hyperledger.besu.ethereum.vm.generalstate"
)
}
def customBlockchainReferenceTests = tasks.register("customBlockchainReferenceTests") {
final referenceTestsPath = "src/reference-test/resources/custom"
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"),
"custom",
"$generatedTestsPath/org/hyperledger/besu/ethereum/vm/custom",
"CustomBlockchainReferenceTest",
"org.hyperledger.besu.ethereum.vm.custom"
)
}
sourceSets {
referenceTest {
java {
compileClasspath += main.output
runtimeClasspath += main.output
srcDirs "src/reference-test/java",
blockchainReferenceTests,
eipBlockchainReferenceTests,
eipStateReferenceTests,
executionSpecTests,
generalstateReferenceTests,
generalstateRegressionReferenceTests,
customBlockchainReferenceTests
}
resources {
srcDirs 'src/reference-test/resources',
'src/reference-test/external-resources',
'src/reference-test/templates',
'build/execution-spec-tests/',
'src/reference-test/resources/custom'
}
}
referenceTestDevnet {
java {
compileClasspath += main.output + referenceTest.output
runtimeClasspath += main.output + referenceTest.output
srcDirs executionSpecDevnetTests
}
resources {
srcDirs 'build/execution-spec-devnet-tests/'
}
}
}
// stable execution-spec-tests tarball contains fixtures/.meta/index.json
tasks.named('processReferenceTestResources') {
dependsOn extractStableFixtures
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
tasks.named('processReferenceTestDevnetResources') {
dependsOn extractDevnetFixtures
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
configurations {
referenceTestAnnotationProcessor.extendsFrom testAnnotationProcessor
referenceTestDevnetAnnotationProcessor.extendsFrom testAnnotationProcessor
referenceTestDevnetImplementation.extendsFrom referenceTestImplementation
referenceTestDevnetRuntimeOnly.extendsFrom referenceTestRuntimeOnly
// we need this because referenceTestImplementation defaults to 'canBeResolved=false'.
tarConfig.extendsFrom referenceTestImplementation
tarConfig {
canBeResolved = true
canBeConsumed = false
}
devnetTarConfig {
canBeResolved = true
canBeConsumed = false
}
}
dependencies {
compileOnly 'org.jspecify:jspecify'
implementation project(':config')
implementation project(':crypto:algorithms')
implementation project(':datatypes')
implementation project(':ethereum:core')
implementation project(':ethereum:eth')
implementation project(':ethereum:blockcreation')
implementation project(':consensus:merge')
implementation project(':metrics:core')
implementation project(':util')
implementation project(path: ':ethereum:core', configuration: 'testSupportArtifacts')
implementation project(':ethereum:rlp')
implementation project(':evm')
implementation project(':services:kvstore')
implementation 'io.consensys.tuweni:tuweni-rlp'
implementation 'com.fasterxml.jackson.core:jackson-databind'
implementation 'com.google.guava:guava'
implementation 'com.google.dagger:dagger'
annotationProcessor 'com.google.dagger:dagger-compiler'
referenceTestImplementation project(path: ':config')
referenceTestImplementation project(path: ':datatypes')
referenceTestImplementation project(path: ':ethereum:core')
referenceTestImplementation project(path: ':ethereum:eth')
referenceTestImplementation project(path: ':ethereum:blockcreation')
referenceTestImplementation project(path: ':consensus:merge')
referenceTestImplementation project(path: ':metrics: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: ':plugin-api')
referenceTestImplementation project(path: ':testutil')
referenceTestImplementation project(path: ':util')
// the following will be resolved via custom ivy repository declared in root build.gradle
referenceTestImplementation(
group: 'ethereum', name: 'execution-spec-tests',
version: 'v5.3.0', classifier: 'fixtures_develop', ext: 'tar.gz'
)
devnetTarConfig(
group: 'ethereum', name: 'execution-spec-tests',
version: 'bal@v5.6.1', classifier: 'fixtures_bal', ext: 'tar.gz'
)
referenceTestImplementation 'com.fasterxml.jackson.core:jackson-databind'
referenceTestImplementation 'com.google.guava:guava'
referenceTestImplementation 'io.consensys.tuweni:tuweni-bytes'
referenceTestImplementation 'io.consensys.tuweni:tuweni-units'
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'
referenceTestRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
tasks.register('referenceTests', 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
}
tasks.register('referenceTestsDevnet', Test) {
useJUnitPlatform()
description = 'Runs execution-spec-tests pre-release (devnet) reference tests.'
testClassesDirs = sourceSets.referenceTestDevnet.output.classesDirs
classpath = sourceSets.referenceTestDevnet.runtimeClasspath
}
tasks.register('validateReferenceTestSubmodule') {
description = "Checks that the reference tests submodule is not accidentally changed"
doLast {
def result = new ByteArrayOutputStream()
def expectedHash = '9201075490807f58811078e9bb5ec895b4ac01a5'
def submodulePath = java.nio.file.Path.of("${rootProject.projectDir}", "ethereum/referencetests/src/reference-test/external-resources").toAbsolutePath()
try {
exec {
commandLine 'git', 'submodule', 'status', submodulePath
standardOutput = result
errorOutput = result
}
} catch (Exception ignore) {
// Ignore it. We want to fail in a friendly fashion if they don't have git installed.
// The CI servers have git and that is the only critical place for this failure
expectedHash = ''
}
if (!result.toString().contains(expectedHash)) {
throw new GradleException("""For the Ethereum Reference Tests the git commit did not match what was expected.
If this is a deliberate change where you are updating the reference tests
then update "expectedHash" in `ethereum/referencetests/build.gradle` as the
commit hash for this task.
Expected hash : ${expectedHash}
Full git output : ${result}
If this is accidental you can correct the reference test versions with the
following commands:
pushd ${submodulePath}
git fetch
git checkout ${expectedHash}
cd ..
git add ${submodulePath}
popd""")
}
}
}
processResources.dependsOn('validateReferenceTestSubmodule')
def generateTestFiles(
FileTree jsonPath,
File templateFile,
String pathstrip,
String destination,
String namePrefix,
String packageString,
String ... excludedPath) {
mkdir(destination)
def referenceTestTemplate = templateFile.text
def paths = []
jsonPath.getFiles().forEach { testJsonFile ->
def parentFile = testJsonFile.getParentFile()
def parentPathFile = parentFile.getPath().substring(parentFile.getPath().indexOf(pathstrip))
def isExcluded = excludedPath.any { excluded -> parentPathFile.startsWith(excluded) }
if (!testJsonFile.getName().toString().startsWith(".") && !isExcluded) {
def pathFile = testJsonFile.getPath()
paths << pathFile.substring(pathFile.indexOf(pathstrip))
}
}
paths.collate(5).eachWithIndex { tests, idx ->
def testFile = file(destination + "/" + namePrefix + "_" + idx + ".java")
def allPaths = '"' + tests.join('",\n "') + '"'
def testFileContents = referenceTestTemplate
.replaceAll("%%TESTS_FILE%%", allPaths)
.replaceAll("%%TESTS_NAME%%", namePrefix + "_" + idx)
.replaceAll("%%PACKAGE_NAME%%", packageString)
testFile.newWriter().withWriter { w -> w << testFileContents }
}
}
def generateTestFilesGroupedByDirectory(
FileTree jsonPath,
File templateFile,
String pathstrip,
String groupBaseDir,
String destination,
String namePrefix,
String packageString,
String ... excludedPath) {
mkdir(destination)
def referenceTestTemplate = templateFile.text
// Collect paths and group by hardfork/EIP directory
def groups = [:] as TreeMap // sorted for deterministic output
jsonPath.getFiles().forEach { testJsonFile ->
def parentFile = testJsonFile.getParentFile()
def parentPathFile = parentFile.getPath().substring(parentFile.getPath().indexOf(pathstrip))
def isExcluded = excludedPath.any { excluded -> parentPathFile.startsWith(excluded) }
if (!testJsonFile.getName().toString().startsWith(".") && !isExcluded) {
def pathFile = testJsonFile.getPath()
def relativePath = pathFile.substring(pathFile.indexOf(pathstrip))
// Extract the part after groupBaseDir to get hardfork/eip/file structure
def groupBaseDirIndex = relativePath.indexOf(groupBaseDir)
def afterGroupBase = relativePath.substring(groupBaseDirIndex + groupBaseDir.length() + 1)
def parts = afterGroupBase.split("[/\\\\]")
// Extract group key from directory structure (e.g. "prague_eip7702_set_code_tx")
def groupKey = extractGroupKey(parts)
if (!groups.containsKey(groupKey)) {
groups[groupKey] = []
}
groups[groupKey] << relativePath
}
}
// Generate test files for each group, batched in groups of 5
groups.each { groupKey, paths ->
paths.collate(5).eachWithIndex { tests, idx ->
def className = namePrefix + "_" + groupKey + "_" + idx
def testFile = file(destination + "/" + className + ".java")
def allPaths = '"' + tests.join('",\n "') + '"'
def testFileContents = referenceTestTemplate
.replaceAll("%%TESTS_FILE%%", allPaths)
.replaceAll("%%TESTS_NAME%%", className)
.replaceAll("%%PACKAGE_NAME%%", packageString)
testFile.newWriter().withWriter { w -> w << testFileContents }
}
}
}
// Extract a group key from path segments for hardfork/EIP-based test grouping.
// Supports both old layout (hardfork/eip/file.json) and new per-fork layout (for_fork/hardfork/eip/file.json).
def extractGroupKey(String[] parts) {
def groupKey
// Strip leading for_{fork}/ directory if present (new per-fork fixture layout)
def effectiveParts = parts
if (parts.length >= 2 && parts[0].startsWith("for_")) {
effectiveParts = parts[1..parts.length - 1] as String[]
}
if (effectiveParts.length >= 3 && effectiveParts[0] == "static") {
// static dirs have deeper nesting: static/state_tests/stCreate2/file.json → static_stCreate2
groupKey = "static_" + effectiveParts[effectiveParts.length - 2]
} else if (effectiveParts.length >= 3) {
// Normal: hardfork/eip/file.json → hardfork_eip
groupKey = effectiveParts[0] + "_" + effectiveParts[1]
} else if (effectiveParts.length == 2) {
// File directly under hardfork dir: hardfork/file.json → hardfork
groupKey = effectiveParts[0]
} else {
groupKey = "unknown"
}
return groupKey.replaceAll("[^a-zA-Z0-9_]", "_")
}