diff --git a/docs/developer.md b/docs/developer.md index 61ba6c10e8..b59ec9f9a1 100644 --- a/docs/developer.md +++ b/docs/developer.md @@ -11,10 +11,6 @@ or the associated YouTube video introduction to [core development with Ethereumj #### Running different Test Types -Running all the tests: - -`npm test` - Running the State tests: `node ./tests/tester -s` diff --git a/package.json b/package.json index 91022662c7..cd8f48c4e5 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "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'", "testAPI": "tape ./tests/api/*.js", - "test": "node ./tests/tester -a", + "test": "echo \"[INFO] Generic test cmd not used. See package.json for more specific test run cmds.\"", "lint": "standard", "prepublishOnly": "npm run lint && npm run build:dist && npm run testBuildIntegrity", "build:dist": "babel lib/ -d dist/", diff --git a/tests/hooked.js b/tests/api/hooked.js similarity index 98% rename from tests/hooked.js rename to tests/api/hooked.js index 689e61edcc..8f71062186 100644 --- a/tests/hooked.js +++ b/tests/api/hooked.js @@ -1,5 +1,5 @@ const tape = require('tape') -const createHookedVm = require('../lib/hooked') +const createHookedVm = require('../../lib/hooked') tape('hooked-vm', function (test) { var contractAddressHex = '0x1234000000000000000000000000000000001234' diff --git a/tests/api/stateManager.js b/tests/api/stateManager.js index 9ab7425f67..94fd1c6cce 100644 --- a/tests/api/stateManager.js +++ b/tests/api/stateManager.js @@ -105,4 +105,19 @@ tape('StateManager', (t) => { st.end() }) + + t.test('should generate the genesis state correctly', async (st) => { + const genesisData = require('ethereumjs-testing').getSingleFile('BasicTests/genesishashestest.json') + const stateManager = new StateManager() + + const generateCanonicalGenesis = promisify((...args) => stateManager.generateCanonicalGenesis(...args)) + const getStateRoot = promisify((...args) => stateManager.getStateRoot(...args)) + + await generateCanonicalGenesis() + let stateRoot = await getStateRoot() + + st.equal(stateRoot.toString('hex'), genesisData.genesis_state_root) + + st.end() + }) }) diff --git a/tests/constantinopleSstoreTest.js b/tests/constantinopleSstoreTest.js deleted file mode 100644 index f4e57f6676..0000000000 --- a/tests/constantinopleSstoreTest.js +++ /dev/null @@ -1,113 +0,0 @@ -const tape = require('tape') -const async = require('async') -const VM = require('../') -const Account = require('ethereumjs-account') -const testUtil = require('./util') -const Trie = require('merkle-patricia-tree/secure') -const ethUtil = require('ethereumjs-util') -const BN = ethUtil.BN - -var testCases = [ - { code: '0x60006000556000600055', usedGas: 412, refund: 0, original: '0x' }, - { code: '0x60006000556001600055', usedGas: 20212, refund: 0, original: '0x' }, - { code: '0x60016000556000600055', usedGas: 20212, refund: 19800, original: '0x' }, - { code: '0x60016000556002600055', usedGas: 20212, refund: 0, original: '0x' }, - { code: '0x60016000556001600055', usedGas: 20212, refund: 0, original: '0x' }, - { code: '0x60006000556000600055', usedGas: 5212, refund: 15000, original: '0x01' }, - { code: '0x60006000556001600055', usedGas: 5212, refund: 4800, original: '0x01' }, - { code: '0x60006000556002600055', usedGas: 5212, refund: 0, original: '0x01' }, - { code: '0x60026000556000600055', usedGas: 5212, refund: 15000, original: '0x01' }, - { code: '0x60026000556003600055', usedGas: 5212, refund: 0, original: '0x01' }, - { code: '0x60026000556001600055', usedGas: 5212, refund: 4800, original: '0x01' }, - { code: '0x60026000556002600055', usedGas: 5212, refund: 0, original: '0x01' }, - { code: '0x60016000556000600055', usedGas: 5212, refund: 15000, original: '0x01' }, - { code: '0x60016000556002600055', usedGas: 5212, refund: 0, original: '0x01' }, - { code: '0x60016000556001600055', usedGas: 412, refund: 0, original: '0x01' }, - { code: '0x600160005560006000556001600055', usedGas: 40218, refund: 19800, original: '0x' }, - { code: '0x600060005560016000556000600055', usedGas: 10218, refund: 19800, original: '0x01' } -] - -var testData = { - 'env': { - 'currentCoinbase': '0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba', - 'currentDifficulty': '0x0100', - 'currentGasLimit': '0x0f4240', - 'currentNumber': '0x00', - 'currentTimestamp': '0x01' - }, - 'exec': { - 'address': '0x01', - 'caller': '0xcd1722f3947def4cf144679da39c4c32bdc35681', - 'code': '0x60006000556000600055', - 'data': '0x', - 'gas': '0', - 'gasPrice': '0x5af3107a4000', - 'origin': '0xcd1722f3947def4cf144679da39c4c32bdc35681', - 'value': '0x0de0b6b3a7640000' - }, - 'gas': '0', - 'pre': { - '0x01': { - 'balance': '0x152d02c7e14af6800000', - 'code': '0x', - 'nonce': '0x00', - 'storage': { - '0x': '0' - } - } - } -} - -tape('test constantinople SSTORE (eip-1283)', function (t) { - testCases.forEach(function (params, i) { - t.test('should correctly run eip-1283 test #' + i, function (st) { - let state = new Trie() - let results - let account - - testData.exec.code = params.code - testData.exec.gas = params.usedGas - testData.pre['0x01'].storage['0x'] = params.original - - async.series([ - function (done) { - let acctData = testData.pre[testData.exec.address] - account = new Account() - account.nonce = testUtil.format(acctData.nonce) - account.balance = testUtil.format(acctData.balance) - testUtil.setupPreConditions(state, testData, done) - }, - function (done) { - state.get(Buffer.from(testData.exec.address, 'hex'), function (err, data) { - let a = new Account(data) - account.stateRoot = a.stateRoot - done(err) - }) - }, - function (done) { - let block = testUtil.makeBlockFromEnv(testData.env) - let vm = new VM({state: state, hardfork: 'constantinople'}) - let runCodeData = testUtil.makeRunCodeData(testData.exec, account, block) - vm.runCode(runCodeData, function (err, r) { - if (r) { - results = r - } - done(err) - }) - }, - function (done) { - if (testData.gas) { - let actualGas = results.gas.toString() - let expectedGas = new BN(testUtil.format(testData.gas)).toString() - t.equal(actualGas, expectedGas, 'valid gas usage') - t.equals(results.gasRefund.toNumber(), params.refund, 'valid gas refund') - } - done() - } - ], function (err) { - t.assert(!err) - st.end() - }) - }) - }) -}) diff --git a/tests/genesishashes.js b/tests/genesishashes.js deleted file mode 100644 index 02f3fd9c74..0000000000 --- a/tests/genesishashes.js +++ /dev/null @@ -1,19 +0,0 @@ -const genesisData = require('ethereumjs-testing').getSingleFile('BasicTests/genesishashestest.json') -const tape = require('tape') -const VM = require('../') - -var vm = new VM() - -tape('[Common]: genesis hashes tests', function (t) { - t.test('should generate the genesis state correctly', function (st) { - vm.stateManager.generateCanonicalGenesis(function () { - vm.stateManager.getStateRoot(function (err, stateRoot) { - if (err) st.fail(err) - else { - st.equal(stateRoot.toString('hex'), genesisData.genesis_state_root) - st.end() - } - }) - }) - }) -}) diff --git a/tests/tester.js b/tests/tester.js index 474be46cfd..2368b153b5 100755 --- a/tests/tester.js +++ b/tests/tester.js @@ -1,7 +1,6 @@ #!/usr/bin/env node const argv = require('minimist')(process.argv.slice(2)) -const async = require('async') const tape = require('tape') const testing = require('ethereumjs-testing') const FORK_CONFIG = argv.fork || 'Byzantium' @@ -115,8 +114,6 @@ if (argv.r) { runTests('VMTests', argv) } else if (argv.b) { runTests('BlockchainTests', argv) -} else if (argv.a) { - runAll() } // randomized tests @@ -244,14 +241,3 @@ function runTests (name, runnerArgs, cb) { }) } } - -function runAll () { - require('./tester.js') - require('./genesishashes.js') - require('./constantinopleSstoreTest.js') - async.series([ - // runTests.bind(this, 'VMTests', {}), // VM tests disabled since we don't support Frontier gas costs - runTests.bind(this, 'GeneralStateTests', {}), - runTests.bind(this, 'BlockchainTests', {}) - ]) -}