Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vm/tests: add support for test networks with activated EIPs #1617

Merged
merged 9 commits into from
Feb 1, 2022
10 changes: 10 additions & 0 deletions packages/vm/DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ or

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

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:

`npm run test:state -- --fork='London+3855'`

Will run the state tests with the London hardfork and with EIP-3855 activated. To activate multiple EIPs:

`npm run test:blockchain -- --fork='London+3855+3860'`

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.

State tests run significantly faster than Blockchain tests, so it is often a good choice to start fixing State tests.

#### Running Specific Tests
Expand Down
29 changes: 20 additions & 9 deletions packages/vm/tests/tester/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,19 @@ export function getTestDirs(network: string, testType: string) {

/**
* Returns a Common for the given network (a test parameter)
* @param {String} network - the network field of a test
* @param {String} 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 seperating them with a `+` sign.
* For instance, "London+3855+3860" will also activate EIP-3855 and EIP-3860.
* @returns {Common} the Common which should be used
*/
export function getCommon(network: string) {
export function getCommon(targetNetwork: string) {
let network = targetNetwork
if (network.includes('+')) {
jochem-brouwer marked this conversation as resolved.
Show resolved Hide resolved
const index = network.indexOf('+')
network = network.slice(0, index)
}
const networkLowercase = network.toLowerCase()
if (normalHardforks.map((str) => str.toLowerCase()).includes(networkLowercase)) {
// normal hard fork, return the common with this hard fork
Expand Down Expand Up @@ -289,13 +298,15 @@ export function getCommon(network: string) {
})
}
}
return Common.forCustomChain(
'mainnet',
{
hardforks: testHardforks,
},
hfName
)
const common = Common.custom({
hardforks: testHardforks,
defaultHardfork: hfName,
})
const eips = targetNetwork.match(/(?<=\+)(.\d+)/g)
if (eips) {
common.setEIPs(eips.map((e: string) => parseInt(e)))
}
return common
} else {
// this is not a "default fork" network, but it is a "transition" network. we will test the VM if it transitions the right way
const transitionForks =
Expand Down
18 changes: 18 additions & 0 deletions packages/vm/tests/tester/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,24 @@ async function runTests() {
runnerArgs.debug = argv.debug // BlockchainTests
runnerArgs.reps = argv.reps // test repetitions

/**
* Modify the forkConfig string to ensure it works with RegEx (escape `+` characters)
*/
if (testGetterArgs.forkConfig.includes('+')) {
let str = testGetterArgs.forkConfig
const indicies = []
for (let i = 0; i < str.length; i++) {
if (str[i] == '+') {
indicies.push(i)
}
}
// traverse array in reverse order to ensure indicies match when we replace the '+' with '/+'
for (let i = indicies.length - 1; i >= 0; i--) {
str = `${str.substr(0, indicies[i])}\\${str.substr(indicies[i])}`
}
testGetterArgs.forkConfig = str
}

let expectedTests: number | undefined
if (argv['verify-test-amount-alltests']) {
expectedTests = getExpectedTests(FORK_CONFIG_VM, name)
Expand Down