Skip to content

Commit

Permalink
Merge pull request #433 from ethereumjs/add-petersburg-aka-constantin…
Browse files Browse the repository at this point in the history
…ople-fix-support

Add petersburg aka constantinopleFix support
  • Loading branch information
holgerd77 authored Feb 7, 2019
2 parents b1e318f + 3d8f14f commit 44fa613
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 15 deletions.
12 changes: 12 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ jobs:
- run:
name: testStateConstantinople
command: npm run testStateConstantinople
test_state_petersburg:
<<: *defaults
steps:
- attach_workspace:
at: ~/project
- *restore_node_modules
- run:
name: testStatePetersburg
command: npm run testStatePetersburg
test_blockchain:
<<: *defaults
steps:
Expand Down Expand Up @@ -99,6 +108,9 @@ workflows:
- test_state_constantinople:
requires:
- install
- test_state_petersburg:
requires:
- install
- test_blockchain:
requires:
- install
Expand Down
5 changes: 3 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const Buffer = require('safe-buffer').Buffer
const util = require('util')
const ethUtil = require('ethereumjs-util')
const StateManager = require('./stateManager.js')
const Common = require('ethereumjs-common')
const Common = require('ethereumjs-common').default
const Account = require('ethereumjs-account')
const AsyncEventEmitter = require('async-eventemitter')
const Trie = require('merkle-patricia-tree/secure.js')
Expand Down Expand Up @@ -48,7 +48,8 @@ function VM (opts = {}) {
let hardfork = opts.hardfork ? opts.hardfork : 'byzantium'
let supportedHardforks = [
'byzantium',
'constantinople'
'constantinople',
'petersburg'
]
this._common = new Common(chain, hardfork, supportedHardforks)

Expand Down
6 changes: 3 additions & 3 deletions lib/stateManager.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const Buffer = require('safe-buffer').Buffer
const Trie = require('merkle-patricia-tree/secure.js')
const Common = require('ethereumjs-common')
const genesisStates = require('ethereumjs-common/genesisStates')
const Common = require('ethereumjs-common').default
const { genesisStateByName } = require('ethereumjs-common/dist/genesisStates')
const async = require('async')
const Account = require('ethereumjs-account')
const Cache = require('./cache.js')
Expand Down Expand Up @@ -481,7 +481,7 @@ proto.generateCanonicalGenesis = function (cb) {

this.hasGenesisState(function (err, genesis) {
if (!genesis && !err) {
self.generateGenesis(genesisStates[self._common.chainName()], cb)
self.generateGenesis(genesisStateByName(self._common.chainName()), cb)
} else {
cb(err)
}
Expand Down
4 changes: 2 additions & 2 deletions lib/vm/opFns.js
Original file line number Diff line number Diff line change
Expand Up @@ -1082,15 +1082,15 @@ function isCreateOpCode (opName) {
}

function getContractStorage (runState, address, key, cb) {
if (runState._common.gteHardfork('constantinople')) {
if (runState._common.hardfork() === 'constantinople') {
runState.storageReader.getContractStorage(address, key, cb)
} else {
runState.stateManager.getContractStorage(address, key, cb)
}
}

function updateSstoreGas (runState, found, value) {
if (runState._common.gteHardfork('constantinople')) {
if (runState._common.hardfork() === 'constantinople') {
var original = found.original
var current = found.current
if (current.equals(value)) {
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"testVM": "node ./tests/tester -v",
"testStateByzantium": "npm run build:dist && node ./tests/tester -s --fork='Byzantium' --dist",
"testStateConstantinople": "npm run build:dist && node ./tests/tester -s --fork='Constantinople' --dist",
"testStatePetersburg": "npm run build:dist && node ./tests/tester -s --fork='Petersburg' --dist",
"testBuildIntegrity": "npm run build:dist && node ./tests/tester -s --dist --test='stackOverflow'",
"testBlockchain": "npm run build:dist && node --stack-size=1500 ./tests/tester -b --fork='Constantinople' --dist --excludeDir='GeneralStateTests'",
"testBlockchainGeneralStateTests": "npm run build:dist && node --stack-size=1500 ./tests/tester -b --dist --dir='GeneralStateTests'",
Expand All @@ -36,8 +37,8 @@
"async": "^2.1.2",
"async-eventemitter": "^0.2.2",
"ethereumjs-account": "^2.0.3",
"ethereumjs-block": "~2.1.0",
"ethereumjs-common": "^0.6.0",
"ethereumjs-block": "~2.2.0",
"ethereumjs-common": "^1.1.0",
"ethereumjs-util": "^6.0.0",
"fake-merkle-patricia-tree": "^1.0.1",
"functional-red-black-tree": "^1.0.1",
Expand All @@ -50,7 +51,7 @@
"babel-preset-env": "^1.6.1",
"coveralls": "^3.0.0",
"documentation": "^8.1.2",
"ethereumjs-blockchain": "^3.3.3",
"ethereumjs-blockchain": "^3.4.0",
"ethereumjs-testing": "git+https://github.com/ethereumjs/ethereumjs-testing.git#v1.2.7",
"ethereumjs-tx": "1.3.7",
"level": "^4.0.0",
Expand Down
8 changes: 5 additions & 3 deletions tests/GeneralStateTestsRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const testUtil = require('./util')
const Trie = require('merkle-patricia-tree/secure')
const ethUtil = require('ethereumjs-util')
const BN = ethUtil.BN
const { getRequiredForkConfigAlias } = require('./util')

function parseTestCases (forkConfig, testData, data, gasLimit, value) {
let testCases = []
Expand Down Expand Up @@ -125,18 +126,19 @@ function runTestCase (options, testData, t, cb) {
}

module.exports = function runStateTest (options, testData, t, cb) {
const forkConfig = getRequiredForkConfigAlias(options.forkConfig)
try {
const testCases = parseTestCases(options.forkConfig, testData, options.data, options.gasLimit, options.value)
const testCases = parseTestCases(forkConfig, 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 ${options.forkConfig} post state defined, skip test`)
t.comment(`No ${forkConfig} post state defined, skip test`)
cb()
}
} catch (e) {
t.fail('error running test case for fork: ' + options.forkConfig)
t.fail('error running test case for fork: ' + forkConfig)
console.log('error:', e)
cb()
}
Expand Down
2 changes: 1 addition & 1 deletion tests/api/runBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { promisify } = require('util')
const tape = require('tape')
const Block = require('ethereumjs-block')
const Transaction = require('ethereumjs-tx')
const Common = require('ethereumjs-common')
const Common = require('ethereumjs-common').default
const util = require('ethereumjs-util')
const runBlock = require('../../lib/runBlock')
const StateManager = require('../../lib/stateManager')
Expand Down
5 changes: 4 additions & 1 deletion tests/tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ const async = require('async')
const tape = require('tape')
const testing = require('ethereumjs-testing')
const FORK_CONFIG = argv.fork || 'Byzantium'
const {
getRequiredForkConfigAlias
} = require('./util')
// tests which should be fixed
const skipBroken = [
'ExtCodeCopyTargetRangeLongerThanCodeTests', // temporary till fixed (2018-11-14)
Expand Down Expand Up @@ -178,7 +181,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 = FORK_CONFIG
testGetterArgs.forkConfig = getRequiredForkConfigAlias(FORK_CONFIG)
testGetterArgs.file = argv.file
testGetterArgs.test = argv.test
testGetterArgs.dir = argv.dir
Expand Down
12 changes: 12 additions & 0 deletions tests/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,3 +393,15 @@ exports.setupPreConditions = function (state, testData, done) {
], callback)
}, done)
}

/**
* Returns an alias for specified hardforks to meet test dependencies requirements/assumptions.
* @param {String} forkConfig - the name of the hardfork for which an alias should be returned
* @returns {String} Either an alias of the forkConfig param, or the forkConfig param itself
*/
exports.getRequiredForkConfigAlias = function (forkConfig) {
if (String(forkConfig).match(/^petersburg$/i)) {
return 'ConstantinopleFix'
}
return forkConfig
}

0 comments on commit 44fa613

Please sign in to comment.