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

Run Consensus Tests on MuirGlacier #648

Merged
merged 6 commits into from
Jan 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/vm-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions tests/BlockchainTestsRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
18 changes: 8 additions & 10 deletions tests/GeneralStateTestsRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
Expand Down
12 changes: 8 additions & 4 deletions tests/tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DRY-ing. 👍

testGetterArgs.file = argv.file
testGetterArgs.test = argv.test
testGetterArgs.dir = argv.dir
Expand All @@ -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

Expand Down Expand Up @@ -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') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should safeguard this conditional with lteHardfork() instead, so Berlin HF tests aren't searched for in LegacyTests?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I thought about that as well, just left it out for timing reasons.

name = 'LegacyTests/Constantinople/'.concat(name)
}
testing
Expand Down
5 changes: 5 additions & 0 deletions tests/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the core of the PR. LGTM 👍

}
// Petersburg is named ConstantinopleFix in the client-independent consensus test suite
if (String(forkConfig).match(/^petersburg$/i)) {
return 'ConstantinopleFix'
}
Expand Down