Skip to content

Commit 020bc03

Browse files
committed
Make handling of petersburg fork names case agnostic and abstract fork alias handling logic in tests.
1 parent b007c4d commit 020bc03

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

tests/GeneralStateTestsRunner.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const testUtil = require('./util')
33
const Trie = require('merkle-patricia-tree/secure')
44
const ethUtil = require('ethereumjs-util')
55
const BN = ethUtil.BN
6+
const { getRequiredForkConfigAlias } = require('./util')
67

78
function parseTestCases (forkConfig, testData, data, gasLimit, value) {
89
let testCases = []
@@ -125,22 +126,19 @@ function runTestCase (options, testData, t, cb) {
125126
}
126127

127128
module.exports = function runStateTest (options, testData, t, cb) {
129+
const forkConfig = getRequiredForkConfigAlias(options.forkConfig)
128130
try {
129-
let aliasForkConfig
130-
if (options.forkConfig === 'Petersburg') {
131-
aliasForkConfig = 'ConstantinopleFix'
132-
}
133-
const testCases = parseTestCases(aliasForkConfig || options.forkConfig, testData, options.data, options.gasLimit, options.value)
131+
const testCases = parseTestCases(forkConfig, testData, options.data, options.gasLimit, options.value)
134132
if (testCases.length > 0) {
135133
async.eachSeries(testCases,
136134
(testCase, done) => runTestCase(options, testCase, t, done),
137135
cb)
138136
} else {
139-
t.comment(`No ${options.forkConfig} post state defined, skip test`)
137+
t.comment(`No ${forkConfig} post state defined, skip test`)
140138
cb()
141139
}
142140
} catch (e) {
143-
t.fail('error running test case for fork: ' + options.forkConfig)
141+
t.fail('error running test case for fork: ' + forkConfig)
144142
console.log('error:', e)
145143
cb()
146144
}

tests/tester.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ const argv = require('minimist')(process.argv.slice(2))
44
const async = require('async')
55
const tape = require('tape')
66
const testing = require('ethereumjs-testing')
7-
const FORK_CONFIG = argv.fork || 'Byzantium'
7+
const {
8+
getRequiredForkConfigAlias
9+
} = require('./util')
810
// tests which should be fixed
911
const skipBroken = [
1012
'ExtCodeCopyTargetRangeLongerThanCodeTests', // temporary till fixed (2018-11-14)
@@ -178,7 +180,7 @@ function runTests (name, runnerArgs, cb) {
178180
testGetterArgs.skipTests = getSkipTests(argv.skip, argv.runSkipped ? 'NONE' : 'ALL')
179181
testGetterArgs.runSkipped = getSkipTests(argv.runSkipped, 'NONE')
180182
testGetterArgs.skipVM = skipVM
181-
testGetterArgs.forkConfig = FORK_CONFIG === 'Petersburg' ? 'ConstantinopleFix' : FORK_CONFIG
183+
testGetterArgs.forkConfig = getRequiredForkConfigAlias(FORK_CONFIG)
182184
testGetterArgs.file = argv.file
183185
testGetterArgs.test = argv.test
184186
testGetterArgs.dir = argv.dir

tests/util.js

+12
Original file line numberDiff line numberDiff line change
@@ -393,3 +393,15 @@ exports.setupPreConditions = function (state, testData, done) {
393393
], callback)
394394
}, done)
395395
}
396+
397+
/**
398+
* Returns an alias for specified hardforks to meet test dependencies requirements/assumptions.
399+
* @param {String} forkConfig - the name of the hardfork for which an alias should be returned
400+
* @returns {String} Either an alias of the forkConfig param, or the forkConfig param itself
401+
*/
402+
exports.getRequiredForkConfigAlias = function (forkConfig) {
403+
if (String(forkConfig).match(/^petersburg$/i)) {
404+
return 'ConstantinopleFix'
405+
}
406+
return forkConfig
407+
}

0 commit comments

Comments
 (0)