-
Notifications
You must be signed in to change notification settings - Fork 852
Expand file tree
/
Copy pathconfig.ts
More file actions
474 lines (455 loc) · 15.7 KB
/
Copy pathconfig.ts
File metadata and controls
474 lines (455 loc) · 15.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
/**
* This file is deprecated (helper for old test runner).
*
* The new runners in executionSpec*.test.ts will become the main
* entry point for test running.
*
* If you discover functionality here which is still missing in the new runner,
* please open a PR against executionSpecState.test.ts.
*
* PLEASE DO NOT COPY LARGER PARTS OF THE CODE TO THE NEW RUNNER BUT RE-IMPLEMENT
* (USE COMMON SENSE).
*/
import * as path from 'path'
import { Common, Hardfork, Mainnet, createCustomCommon } from '@ethereumjs/common'
import type { HardforkTransitionConfig } from '@ethereumjs/common'
import type { KZG } from '@ethereumjs/util'
/**
* Default tests path (git submodule: ethereum-tests)
*/
export const DEFAULT_TESTS_PATH = path.resolve('../ethereum-tests')
/**
* Default hardfork rules to run tests against
*/
export const DEFAULT_FORK_CONFIG = 'Paris'
/**
* Tests which should be fixed
*/
export const SKIP_BROKEN = [
'ForkStressTest', // Only BlockchainTest, temporary till fixed (2020-05-23)
'ChainAtoChainB', // Only BlockchainTest, temporary, along expectException fixes (2020-05-23)
// In these tests, we have access to two forked chains. Their total difficulty is equal. There are errors in the second chain, but we have no reason to execute this chain if the TD remains equal.
'blockChainFrontierWithLargerTDvsHomesteadBlockchain2_FrontierToHomesteadAt5',
'blockChainFrontierWithLargerTDvsHomesteadBlockchain_FrontierToHomesteadAt5',
'HomesteadOverrideFrontier_FrontierToHomesteadAt5',
// Test skipped in ethereum-tests v14, this is an internal test for retesteth to throw an error if the test self is wrong
// This test is thus not supposed to pass
// TODO: remove me once this test is removed from the releases
'filling_unexpectedException',
]
/**
* Tests skipped due to system specifics / design considerations
*/
export const SKIP_PERMANENT = [
'SuicidesMixingCoinbase', // suicides to the coinbase, since we run a blockLevel we create coinbase account.
'static_SuicidesMixingCoinbase', // suicides to the coinbase, since we run a blockLevel we create coinbase account.
'ForkUncle', // Only BlockchainTest, correct behavior unspecified (?)
'UncleFromSideChain', // Only BlockchainTest, same as ForkUncle, the TD is the same for two different branches so its not clear which one should be the finally chain
]
/**
* tests running slow (run from time to time)
*/
export const SKIP_SLOW = [
'Call50000_sha256', // Last check: 2023-08-24, Constantinople HF, still slow (1-2 minutes per block execution)
'CALLBlake2f_MaxRounds', // Last check: 2023-08-24, Berlin HF, still very slow (several minutes per block execution)
'Return50000', // Last check: 2023-08-24, Constantinople HF, still slow (1-2 minutes per block execution)
'Return50000_2', // Last check: 2023-08-24, Constantinople HF, still slow (1-2 minutes per block execution)
'static_Call50000_sha256', // Last check: 2023-08-24, Berlin HF, still slow (30-60 secs per block execution)
// vmPerformance tests
'loopMul', // Last check: 2023-08-24, Berlin HF, still very slow (up to minutes per block execution)
'loopExp', // Last check: 2023-08-24, Berlin HF, somewhat slow (5-10 secs per block execution)
]
/**
* Returns an alias for specified hardforks to meet test dependencies requirements/assumptions.
* @param {String} forkConfig - the name of the hardfork for which an alias should be returned
* @returns {String} Either an alias of the forkConfig param, or the forkConfig param itself
*/
export function getRequiredForkConfigAlias(forkConfig: string) {
const indexOfPlus = forkConfig.indexOf('+')
const remainder = indexOfPlus !== -1 ? forkConfig.substring(indexOfPlus) : ''
// Chainstart is also called Frontier and is called as such in the tests
if (String(forkConfig).match(/^chainstart$/i)) {
return 'Frontier' + remainder
}
// TangerineWhistle is named EIP150 (attention: misleading name)
// in the client-independent consensus test suite
if (String(forkConfig).match(/^tangerineWhistle$/i)) {
return 'EIP150' + remainder
}
// SpuriousDragon is named EIP158 (attention: misleading name)
// in the client-independent consensus test suite
if (String(forkConfig).match(/^spuriousDragon$/i)) {
return 'EIP158' + remainder
}
// Run the Istanbul tests for MuirGlacier since there are no dedicated tests
if (String(forkConfig).match(/^muirGlacier/i)) {
return 'Istanbul' + remainder
}
// Petersburg is named ConstantinopleFix
// in the client-independent consensus test suite
if (String(forkConfig).match(/^petersburg$/i)) {
return 'ConstantinopleFix' + remainder
}
return forkConfig
}
const normalHardforks = [
'chainstart',
'homestead',
'dao',
'tangerineWhistle',
'spuriousDragon',
'byzantium',
'constantinople',
'petersburg',
'istanbul',
'muirGlacier',
'berlin',
'london',
'paris',
'shanghai',
'arrowGlacier', // This network has no tests, but need to add it due to common generation logic
'cancun',
'prague',
'osaka',
]
const transitionNetworks = {
ByzantiumToConstantinopleFixAt5: {
byzantium: 0,
constantinople: 5,
petersburg: 5,
dao: null,
finalSupportedFork: 'petersburg',
startFork: 'byzantium',
},
EIP158ToByzantiumAt5: {
spuriousDragon: 0,
byzantium: 5,
dao: null,
finalSupportedFork: 'byzantium',
startFork: 'spuriousDragon',
},
FrontierToHomesteadAt5: {
chainstart: 0,
homestead: 5,
dao: null,
finalSupportedFork: 'homestead',
startFork: 'chainstart',
},
HomesteadToDaoAt5: {
homestead: 0,
dao: 5,
finalSupportedFork: 'dao',
startFork: 'homestead',
},
HomesteadToEIP150At5: {
homestead: 0,
tangerineWhistle: 5,
dao: null,
finalSupportedFork: 'tangerineWhistle',
startFork: 'homestead',
},
BerlinToLondonAt5: {
berlin: 0,
london: 5,
dao: null,
finalSupportedFork: 'london',
startFork: 'berlin',
},
}
const retestethAlias = {
Frontier: 'chainstart',
EIP150: 'tangerineWhistle',
EIP158: 'spuriousDragon',
ConstantinopleFix: 'petersburg',
Merge: 'paris',
}
const testLegacy = {
chainstart: true,
homestead: true,
tangerineWhistle: true,
spuriousDragon: true,
byzantium: true,
constantinople: true,
petersburg: true,
istanbul: true,
muirGlacier: true,
berlin: true,
london: true,
paris: true,
shanghai: true,
ByzantiumToConstantinopleFixAt5: true,
EIP158ToByzantiumAt5: true,
FrontierToHomesteadAt5: true,
HomesteadToDaoAt5: true,
HomesteadToEIP150At5: true,
BerlinToLondonAt5: true,
}
/**
* Returns an array of dirs to run tests on
* @param network (fork identifier)
* @param testType (BlockchainTests/StateTests)
*/
export function getTestDirs(network: string, testType: string) {
const testDirs = [testType]
for (const key in testLegacy) {
if (
key.toLowerCase() === network.toLowerCase() &&
testLegacy[key as keyof typeof testLegacy] === true
) {
// Tests snapshots have moved in `LegacyTests/Constantinople`:
// https://github.com/ethereum/tests/releases/tag/v7.0.0-beta.1
// Also tests have moved in `LegacyTests/Cancun`:
// https://github.com/ethereum/tests/releases/tag/v14.0
testDirs.push('LegacyTests/Constantinople/' + testType)
testDirs.push('LegacyTests/Cancun/' + testType)
break
}
}
return testDirs
}
/**
* Setups the common with networks
* @param network Network target (this can include EIPs, such as Byzantium+2537+2929)
* @param ttd If set: total terminal difficulty to switch to merge
* @returns
*/
function setupCommonWithNetworks(network: string, ttd?: number, timestamp?: number, kzg?: KZG) {
let networkLowercase: string // This only consists of the target hardfork, so without the EIPs
if (network.includes('+')) {
const index = network.indexOf('+')
networkLowercase = network.slice(0, index).toLowerCase()
} else {
networkLowercase = network.toLowerCase()
}
// normal hard fork, return the common with this hard fork
// find the right upper/lowercased version
const hfName = normalHardforks.reduce((previousValue, currentValue) =>
currentValue.toLowerCase() === networkLowercase ? currentValue : previousValue,
)
const mainnetCommon = new Common({ chain: Mainnet, hardfork: hfName })
const hardforks = mainnetCommon.hardforks()
const testHardforks: HardforkTransitionConfig[] = []
for (const hf of hardforks) {
// check if we enable this hf
// disable dao hf by default (if enabled at block 0 forces the first 10 blocks to have dao-hard-fork in extraData of block header)
if (mainnetCommon.gteHardfork(hf.name) && hf.name !== Hardfork.Dao) {
// this hardfork should be activated at block 0
testHardforks.push({
name: hf.name,
// Current type definition Partial<Chain> in Common is currently not allowing to pass in forkHash
// forkHash: hf.forkHash,
block: 0,
})
} else {
// disable hardforks newer than the test hardfork (but do add "support" for it, it just never gets activated)
if (
(ttd === undefined && timestamp === undefined) ||
(hf.name === 'paris' && ttd !== undefined)
) {
testHardforks.push({
name: hf.name,
block: null,
})
}
if (timestamp !== undefined && hf.name !== Hardfork.Dao) {
testHardforks.push({
name: hf.name,
block: null,
timestamp,
})
}
}
}
const common = createCustomCommon(
{
hardforks: testHardforks,
defaultHardfork: hfName,
},
Mainnet,
{ eips: [3607], customCrypto: { kzg } },
)
// Activate EIPs
const eips = network.match(/(?<=\+)(.\d+)/g)
if (eips) {
common.setEIPs(eips.map((e: string) => parseInt(e)))
}
return common
}
/**
* Returns a Common for the given network (a test parameter)
* @param network - the network field of a test.
* If this network has a `+` sign, it will also include these EIPs.
* For instance, London+3855 will activate the network on the London hardfork, but will also activate EIP 3855.
* Multiple EIPs can also be activated by separating them with a `+` sign.
* For instance, "London+3855+3860" will also activate EIP-3855 and EIP-3860.
* @returns the Common which should be used
*/
export function getCommon(network: string, kzg?: KZG): Common {
if (retestethAlias[network as keyof typeof retestethAlias] !== undefined) {
network = retestethAlias[network as keyof typeof retestethAlias]
}
let networkLowercase = network.toLowerCase()
if (network.includes('+')) {
const index = network.indexOf('+')
networkLowercase = network.slice(0, index).toLowerCase()
}
if (normalHardforks.map((str) => str.toLowerCase()).includes(networkLowercase)) {
// Case 1: normal network, such as "London" or "Byzantium" (without any EIPs enabled, and it is not a transition network)
return setupCommonWithNetworks(network, undefined, undefined, kzg)
} else if (networkLowercase.match('tomergeatdiff')) {
// Case 2: special case of a transition network, this setups the right common with the right Merge properties (TTD)
// This is a HF -> Merge transition
const start = networkLowercase.match('tomergeatdiff')!.index!
const end = start + 'tomergeatdiff'.length
const startNetwork = network.substring(0, start) // HF before the merge
const TTD = Number('0x' + network.substring(end)) // Total difficulty to transition to PoS
return setupCommonWithNetworks(startNetwork, TTD, undefined, kzg)
} else if (networkLowercase === 'shanghaitocancunattime15k') {
return setupCommonWithNetworks('Shanghai', undefined, 15000, kzg)
} else if (networkLowercase === 'cancuntopragueattime15k') {
return setupCommonWithNetworks('Cancun', undefined, 15000, kzg)
} else {
// Case 3: this is not a "default fork" network, but it is a "transition" network. Test the VM if it transitions the right way
const transitionForks =
network in transitionNetworks
? transitionNetworks[network as keyof typeof transitionNetworks]
: transitionNetworks[
(network.charAt(0).toUpperCase() + network.slice(1)) as keyof typeof transitionNetworks
]
if (transitionForks === undefined) {
throw new Error('network not supported: ' + network)
}
const mainnetCommon = new Common({
chain: Mainnet,
hardfork: transitionForks.finalSupportedFork,
})
const hardforks = mainnetCommon.hardforks()
const testHardforks = []
for (const hf of hardforks) {
if (mainnetCommon.gteHardfork(hf.name)) {
// this hardfork should be activated at block 0
const forkBlockNumber = transitionForks[hf.name as keyof typeof transitionForks] as
| number
| null
| undefined
testHardforks.push({
name: hf.name,
block: forkBlockNumber ?? 0, // If hardfork isn't in transitionForks, activate at 0
})
} else {
// disable the hardfork
testHardforks.push({
name: hf.name,
block: null,
})
}
}
const common = createCustomCommon(
{
hardforks: testHardforks,
},
Mainnet,
{
hardfork: transitionForks.startFork,
eips: [3607],
customCrypto: { kzg },
},
)
return common
}
}
const expectedTestsFull: {
BlockchainTests: Record<string, number | undefined>
GeneralStateTests: Record<string, number | undefined>
} = {
BlockchainTests: {
Chainstart: 4496,
Homestead: 7321,
Dao: 0,
TangerineWhistle: 4609,
SpuriousDragon: 4632,
Byzantium: 15703,
Constantinople: 33146,
Petersburg: 33128,
Istanbul: 38340,
MuirGlacier: 38340,
Berlin: 41365,
London: 61197,
ArrowGlacier: 0,
Paris: 60373,
Shanghai: 61563,
ByzantiumToConstantinopleFixAt5: 3,
EIP158ToByzantiumAt5: 3,
FrontierToHomesteadAt5: 13,
HomesteadToDaoAt5: 32,
HomesteadToEIP150At5: 3,
BerlinToLondonAt5: 24,
Cancun: 61633,
},
GeneralStateTests: {
Chainstart: 1045,
Homestead: 2078,
Dao: 0,
TangerineWhistle: 1200,
SpuriousDragon: 1325,
Byzantium: 4857,
Constantinople: 10648,
Petersburg: 10642,
Istanbul: 12271,
MuirGlacier: 12271,
Berlin: 13214,
London: 19449,
Paris: 19727,
Shanghai: 19564,
ByzantiumToConstantinopleFixAt5: 0,
EIP158ToByzantiumAt5: 0,
FrontierToHomesteadAt5: 0,
HomesteadToDaoAt5: 0,
HomesteadToEIP150At5: 0,
BerlinToLondonAt5: 0,
Cancun: 19048,
},
}
/**
* Returns the amount of expected tests for a given fork, assuming all tests are ran
*/
export function getExpectedTests(
fork: string,
name: 'BlockchainTests' | 'GeneralStateTests',
): number | undefined {
if (expectedTestsFull[name] === undefined) {
return
}
for (const key in expectedTestsFull[name]) {
if (fork.toLowerCase() === key.toLowerCase()) {
return expectedTestsFull[name][key]
}
}
}
/**
* Returns an aggregated array with the tests to skip
* @param choices comma-separated list with skip options, e.g. BROKEN,PERMANENT
* @param defaultChoice if to use `NONE` or `ALL` as default choice
* @returns array with test names
*/
export function getSkipTests(choices: string | undefined, defaultChoice: string): string[] {
let skipTests: string[] = []
if (choices === undefined) {
choices = defaultChoice
}
choices = choices.toLowerCase()
if (choices !== 'none') {
const choicesList = choices.split(',')
const all = choicesList.includes('all')
if (all || choicesList.includes('broken')) {
skipTests = skipTests.concat(SKIP_BROKEN)
}
if (all || choicesList.includes('permanent')) {
skipTests = skipTests.concat(SKIP_PERMANENT)
}
if (all || choicesList.includes('slow')) {
skipTests = skipTests.concat(SKIP_SLOW)
}
}
return skipTests
}