diff --git a/.github/workflows/vm-test.yml b/.github/workflows/vm-test.yml index 48c790ce03..16d61c7892 100644 --- a/.github/workflows/vm-test.yml +++ b/.github/workflows/vm-test.yml @@ -54,7 +54,7 @@ jobs: - run: npm install if: steps.cache-node-modules.outputs.cache-hit != 'true' - - run: npm run test:state:allForks + - run: npm run test:state:selectedForks env: CI: true diff --git a/package.json b/package.json index afab33106e..807c3e5a74 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,8 @@ "docs:build": "typedoc lib", "test:vm": "node ./tests/tester --vm", "test:state": "npm run build:dist && node ./tests/tester --state --dist", - "test:state:allForks": "npm run test:state -- --fork=Byzantium && npm run test:state -- --fork=Constantinople && npm run test:state -- --fork=Petersburg && npm run test:state -- --fork=Istanbul", + "test:state:allForks": "npm run test:state -- --fork=Byzantium && npm run test:state -- --fork=Constantinople && npm run test:state -- --fork=Petersburg && npm run test:state -- --fork=Istanbul && npm run test:state -- --fork=MuirGlacier", + "test:state:selectedForks": "npm run test:state -- --fork=Petersburg && npm run test:state -- --fork=Istanbul && npm run test:state -- --fork=MuirGlacier", "test:state:slow": "npm run test:state -- --runSkipped=slow", "test:buildIntegrity": "npm run test:state -- --test='stackOverflow'", "test:blockchain": "npm run build:dist && node --stack-size=1500 ./tests/tester --blockchain --dist", diff --git a/tests/BlockchainTestsRunner.js b/tests/BlockchainTestsRunner.js index 7f388acd1a..5b6047aa7d 100644 --- a/tests/BlockchainTestsRunner.js +++ b/tests/BlockchainTestsRunner.js @@ -20,7 +20,7 @@ module.exports = function runBlockchainTest (options, testData, t, cb) { } var blockchain = new Blockchain({ db: blockchainDB, - hardfork: options.forkConfig.toLowerCase(), + hardfork: options.forkConfigVM, validate: validate }) if (validate) { @@ -35,9 +35,9 @@ module.exports = function runBlockchainTest (options, testData, t, cb) { var vm = new VM({ state: state, blockchain: blockchain, - hardfork: options.forkConfig.toLowerCase() + hardfork: options.forkConfigVM }) - var genesisBlock = new Block({ hardfork: options.forkConfig.toLowerCase() }) + var genesisBlock = new Block({ hardfork: options.forkConfigVM }) testData.homestead = true if (testData.homestead) { @@ -60,7 +60,7 @@ module.exports = function runBlockchainTest (options, testData, t, cb) { function (done) { // create and add genesis block genesisBlock.header = new BlockHeader(formatBlockHeader(testData.genesisBlockHeader), { - hardfork: options.forkConfig.toLowerCase() + hardfork: options.forkConfigVM }) t.equal(state.root.toString('hex'), genesisBlock.header.stateRoot.toString('hex'), 'correct pre stateRoot') if (testData.genesisRLP) { @@ -74,7 +74,7 @@ module.exports = function runBlockchainTest (options, testData, t, cb) { async.eachSeries(testData.blocks, function (raw, cb) { try { var block = new Block(Buffer.from(raw.rlp.slice(2), 'hex'), { - hardfork: options.forkConfig.toLowerCase() + hardfork: options.forkConfigVM }) // forces the block into thinking they are homestead if (testData.homestead) { diff --git a/tests/GeneralStateTestsRunner.js b/tests/GeneralStateTestsRunner.js index ff964327c8..e2a0f0d3e7 100644 --- a/tests/GeneralStateTestsRunner.js +++ b/tests/GeneralStateTestsRunner.js @@ -4,12 +4,11 @@ const Trie = require('merkle-patricia-tree/secure') const ethUtil = require('ethereumjs-util') const Account = require('ethereumjs-account').default const BN = ethUtil.BN -const { getRequiredForkConfigAlias } = require('./util') -function parseTestCases (forkConfig, testData, data, gasLimit, value) { +function parseTestCases (forkConfigTestSuite, testData, data, gasLimit, value) { let testCases = [] - if (testData['post'][forkConfig]) { - testCases = testData['post'][forkConfig].map(testCase => { + if (testData['post'][forkConfigTestSuite]) { + testCases = testData['post'][forkConfigTestSuite].map(testCase => { let testIndexes = testCase['indexes'] let tx = { ...testData.transaction } if (data !== undefined && testIndexes['data'] !== data) { @@ -57,12 +56,12 @@ function runTestCase (options, testData, t, cb) { } vm = new VM({ state: state, - hardfork: options.forkConfig.toLowerCase() + hardfork: options.forkConfigVM }) testUtil.setupPreConditions(state, testData, done) }, function (done) { - var tx = testUtil.makeTx(testData.transaction, options.forkConfig.toLowerCase()) + var tx = testUtil.makeTx(testData.transaction, options.forkConfigVM) block = testUtil.makeBlockFromEnv(testData.env) tx._homestead = true tx.enableHomestead = true @@ -146,19 +145,18 @@ function runTestCase (options, testData, t, cb) { } module.exports = function runStateTest (options, testData, t, cb) { - const forkConfig = getRequiredForkConfigAlias(options.forkConfig) try { - const testCases = parseTestCases(forkConfig, testData, options.data, options.gasLimit, options.value) + const testCases = parseTestCases(options.forkConfigTestSuite, testData, options.data, options.gasLimit, options.value) if (testCases.length > 0) { async.eachSeries(testCases, (testCase, done) => runTestCase(options, testCase, t, done), cb) } else { - t.comment(`No ${forkConfig} post state defined, skip test`) + t.comment(`No ${options.forkConfigTestSuite} post state defined, skip test`) cb() } } catch (e) { - t.fail('error running test case for fork: ' + forkConfig) + t.fail('error running test case for fork: ' + options.forkConfigTestSuite) console.log('error:', e) cb() } diff --git a/tests/tester.js b/tests/tester.js index 7e5910f617..13d277592f 100755 --- a/tests/tester.js +++ b/tests/tester.js @@ -3,8 +3,11 @@ const argv = require('minimist')(process.argv.slice(2)) const tape = require('tape') const testing = require('ethereumjs-testing') -const FORK_CONFIG = argv.fork || 'Istanbul' const { getRequiredForkConfigAlias } = require('./util') +const FORK_CONFIG = (argv.fork || 'Istanbul') +const FORK_CONFIG_TEST_SUITE = getRequiredForkConfigAlias(FORK_CONFIG) +// Istanbul -> istanbul, MuirGlacier -> muirGlacier +const FORK_CONFIG_VM = FORK_CONFIG.charAt(0).toLowerCase() + FORK_CONFIG.substring(1) // tests which should be fixed const skipBroken = [ 'dynamicAccountOverwriteEmpty', // temporary till fixed (2019-01-30), skipped along constantinopleFix work time constraints @@ -138,7 +141,7 @@ function runTests(name, runnerArgs, cb) { testGetterArgs.skipTests = getSkipTests(argv.skip, argv.runSkipped ? 'NONE' : 'ALL') testGetterArgs.runSkipped = getSkipTests(argv.runSkipped, 'NONE') testGetterArgs.skipVM = skipVM - testGetterArgs.forkConfig = getRequiredForkConfigAlias(FORK_CONFIG) + testGetterArgs.forkConfig = FORK_CONFIG_TEST_SUITE testGetterArgs.file = argv.file testGetterArgs.test = argv.test testGetterArgs.dir = argv.dir @@ -147,7 +150,8 @@ function runTests(name, runnerArgs, cb) { testGetterArgs.customStateTest = argv.customStateTest - runnerArgs.forkConfig = FORK_CONFIG + runnerArgs.forkConfigVM = FORK_CONFIG_VM + runnerArgs.forkConfigTestSuite = FORK_CONFIG_TEST_SUITE runnerArgs.jsontrace = argv.jsontrace runnerArgs.debug = argv.debug // for BlockchainTests @@ -178,7 +182,7 @@ function runTests(name, runnerArgs, cb) { const runner = require(`./${name}Runner.js`) // Tests for HFs before Istanbul have been moved under `LegacyTests/Constantinople`: // https://github.com/ethereum/tests/releases/tag/v7.0.0-beta.1 - if (runnerArgs.forkConfig !== 'Istanbul') { + if (testGetterArgs.forkConfig !== 'Istanbul') { name = 'LegacyTests/Constantinople/'.concat(name) } testing diff --git a/tests/util.js b/tests/util.js index 09ca228a37..b059681ffc 100644 --- a/tests/util.js +++ b/tests/util.js @@ -403,6 +403,11 @@ exports.setupPreConditions = function (state, testData, done) { * @returns {String} Either an alias of the forkConfig param, or the forkConfig param itself */ exports.getRequiredForkConfigAlias = function (forkConfig) { + // Run the Istanbul tests for MuirGlacier since there are no dedicated tests + if (String(forkConfig).match(/^muirGlacier/i)) { + return 'Istanbul' + } + // Petersburg is named ConstantinopleFix in the client-independent consensus test suite if (String(forkConfig).match(/^petersburg$/i)) { return 'ConstantinopleFix' }