Skip to content

Commit 64b48b0

Browse files
jochem-brouweracolytec3holgerd77
authored
vm/tests: add support for test networks with activated EIPs (#1617)
* vm/tests: add support for test networks with activated EIPs * vm/tests: remove console.log * Change deprecated forCustomChain to custom * vm/tests: add extra information about activating EIPs * vm/tests: remove console.log Co-authored-by: acolytec3 <[email protected]> Co-authored-by: Holger Drewes <[email protected]>
1 parent b224247 commit 64b48b0

File tree

3 files changed

+48
-9
lines changed

3 files changed

+48
-9
lines changed

packages/vm/DEVELOPER.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ or
3737

3838
By default it is set to use the latest hardfork (`FORK_CONFIG` in `tests/tester.js`).
3939

40+
The `--fork` parameter can also be used to activate EIPs. This is done by first entering the hardfork, and then add the EIPs seperated with the `+` sign. For instance:
41+
42+
`npm run test:state -- --fork='London+3855'`
43+
44+
Will run the state tests with the London hardfork and with EIP-3855 activated. To activate multiple EIPs:
45+
46+
`npm run test:blockchain -- --fork='London+3855+3860'`
47+
48+
This runs the blockchain tests on the London hardfork with the EIP-3855 and EIP-3860 activated. Note, that only tests which have testdata on this specific configuration will run: most combinations will run 0 tests.
49+
4050
State tests run significantly faster than Blockchain tests, so it is often a good choice to start fixing State tests.
4151

4252
#### Running Specific Tests

packages/vm/tests/tester/config.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,19 @@ export function getTestDirs(network: string, testType: string) {
255255

256256
/**
257257
* Returns a Common for the given network (a test parameter)
258-
* @param {String} network - the network field of a test
258+
* @param {String} network - the network field of a test.
259+
* If this network has a `+` sign, it will also include these EIPs.
260+
* For instance, London+3855 will activate the network on the London hardfork, but will also activate EIP 3855.
261+
* Multiple EIPs can also be activated by seperating them with a `+` sign.
262+
* For instance, "London+3855+3860" will also activate EIP-3855 and EIP-3860.
259263
* @returns {Common} the Common which should be used
260264
*/
261-
export function getCommon(network: string) {
265+
export function getCommon(targetNetwork: string) {
266+
let network = targetNetwork
267+
if (network.includes('+')) {
268+
const index = network.indexOf('+')
269+
network = network.slice(0, index)
270+
}
262271
const networkLowercase = network.toLowerCase()
263272
if (normalHardforks.map((str) => str.toLowerCase()).includes(networkLowercase)) {
264273
// normal hard fork, return the common with this hard fork
@@ -289,13 +298,15 @@ export function getCommon(network: string) {
289298
})
290299
}
291300
}
292-
return Common.forCustomChain(
293-
'mainnet',
294-
{
295-
hardforks: testHardforks,
296-
},
297-
hfName
298-
)
301+
const common = Common.custom({
302+
hardforks: testHardforks,
303+
defaultHardfork: hfName,
304+
})
305+
const eips = targetNetwork.match(/(?<=\+)(.\d+)/g)
306+
if (eips) {
307+
common.setEIPs(eips.map((e: string) => parseInt(e)))
308+
}
309+
return common
299310
} else {
300311
// this is not a "default fork" network, but it is a "transition" network. we will test the VM if it transitions the right way
301312
const transitionForks =

packages/vm/tests/tester/index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,24 @@ async function runTests() {
9393
runnerArgs.debug = argv.debug // BlockchainTests
9494
runnerArgs.reps = argv.reps // test repetitions
9595

96+
/**
97+
* Modify the forkConfig string to ensure it works with RegEx (escape `+` characters)
98+
*/
99+
if (testGetterArgs.forkConfig.includes('+')) {
100+
let str = testGetterArgs.forkConfig
101+
const indicies = []
102+
for (let i = 0; i < str.length; i++) {
103+
if (str[i] == '+') {
104+
indicies.push(i)
105+
}
106+
}
107+
// traverse array in reverse order to ensure indicies match when we replace the '+' with '/+'
108+
for (let i = indicies.length - 1; i >= 0; i--) {
109+
str = `${str.substr(0, indicies[i])}\\${str.substr(indicies[i])}`
110+
}
111+
testGetterArgs.forkConfig = str
112+
}
113+
96114
let expectedTests: number | undefined
97115
if (argv['verify-test-amount-alltests']) {
98116
expectedTests = getExpectedTests(FORK_CONFIG_VM, name)

0 commit comments

Comments
 (0)