diff --git a/karma.conf.js b/karma.conf.js index 16447fe3c6..e167b01d32 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -17,13 +17,8 @@ module.exports = function (config) { ], // list of files / patterns to exclude - // currently failing tests, open separate PRs to fix exclude: [ - './tests/api/state/stateManager.js', // 4, "# should clear the cache when the state root is set" - './tests/api/state/storageReader.js', // 1, "# should get value from stateManager" - './tests/api/index.js', // 11, "# should run blockchain with mocked runBlock" not working" - './tests/api/runBlock.js', // 3, "# should fail when runTx fails" - './tests/api/runBlockchain.js' // 2, "# should run with valid and invalid blocks" + './tests/api/state/stateManager.js' // 4, "# should clear the cache when the state root is set" ], // preprocess matching files before serving them to the browser @@ -69,6 +64,10 @@ module.exports = function (config) { // Concurrency level // how many browser should be started simultaneous - concurrency: Infinity + concurrency: Infinity, + + // Fail after timeout + browserDisconnectTimeout: 100000, + browserNoActivityTimeout: 100000 }) } diff --git a/tests/api/index.js b/tests/api/index.js index 5613a279d3..47946cda45 100644 --- a/tests/api/index.js +++ b/tests/api/index.js @@ -69,7 +69,7 @@ tape('VM with blockchain', (t) => { }) t.test('should run blockchain with mocked runBlock', async (st) => { - const vm = setupVM() + const vm = setupVM({ chain: 'goerli' }) const genesis = new Block(Buffer.from(testData.genesisRLP.slice(2), 'hex')) const block = new Block(Buffer.from(testData.blocks[0].rlp.slice(2), 'hex')) @@ -96,7 +96,7 @@ tape('VM with blockchain', (t) => { }) t.test('should run blockchain with blocks', async (st) => { - const vm = setupVM() + const vm = setupVM({ chain: 'goerli' }) const genesis = new Block(Buffer.from(testData.genesisRLP.slice(2), 'hex')) const block = new Block(Buffer.from(testData.blocks[0].rlp.slice(2), 'hex')) diff --git a/tests/api/runBlock.js b/tests/api/runBlock.js index 76d938d47b..97f188d4bf 100644 --- a/tests/api/runBlock.js +++ b/tests/api/runBlock.js @@ -31,8 +31,7 @@ function setup (vm = null) { data: testData, p: { runBlock: promisify(runBlock.bind(vm)), - putAccount: promisify(vm.stateManager.putAccount.bind(vm.stateManager)), - generateCanonicalGenesis: promisify(vm.stateManager.generateCanonicalGenesis.bind(vm.stateManager)) + putAccount: promisify(vm.stateManager.putAccount.bind(vm.stateManager)) } } } @@ -59,8 +58,6 @@ tape('runBlock', async (t) => { t.test('should fail when runTx fails', async (st) => { const block = new Block(util.rlp.decode(suite.data.blocks[0].rlp)) - await suite.p.generateCanonicalGenesis() - // The mocked VM uses a mocked runTx // which always returns an error. await suite.p.runBlock({ block, skipBlockValidation: true }) @@ -108,8 +105,6 @@ tape('should fail when tx gas limit higher than block gas limit', async (t) => { const block = new Block(util.rlp.decode(suite.data.blocks[0].rlp)) block.transactions[0].gasLimit = Buffer.from('3fefba', 'hex') - await suite.p.generateCanonicalGenesis() - await suite.p.runBlock({ block, skipBlockValidation: true }) .then(() => t.fail('should have returned error')) .catch((e) => t.ok(e.message.includes('higher gas limit'))) @@ -128,8 +123,6 @@ tape('should fail when runCall fails', async (t) => { await suite.p.putAccount(tx.from.toString('hex'), acc) } - await suite.p.generateCanonicalGenesis() - // The mocked VM uses a mocked runCall // which always returns an error. // runTx is a full implementation that works. diff --git a/tests/api/runBlockchain.js b/tests/api/runBlockchain.js index a48321d306..56f3f3c7ce 100644 --- a/tests/api/runBlockchain.js +++ b/tests/api/runBlockchain.js @@ -1,8 +1,9 @@ const tape = require('tape') const level = require('level-mem') -const { promisify } = require('util') +const promisify = require('util.promisify') const Blockchain = require('ethereumjs-blockchain') const Block = require('ethereumjs-block') +const Common = require('ethereumjs-common').default const util = require('ethereumjs-util') const runBlockchain = require('../../lib/runBlockchain') const { StateManager } = require('../../lib/state') @@ -10,8 +11,15 @@ const { createGenesis } = require('./utils') tape('runBlockchain', (t) => { const blockchainDB = level() - const blockchain = new Blockchain({ db: blockchainDB }) - const vm = { stateManager: new StateManager(), blockchain } + const blockchain = new Blockchain({ + db: blockchainDB, + chain: 'goerli', + validate: false + }) + const vm = { + stateManager: new StateManager({ common: new Common('goerli') }), + blockchain: blockchain + } const putGenesisP = promisify(blockchain.putGenesis.bind(blockchain)) const putBlockP = promisify(blockchain.putBlock.bind(blockchain)) @@ -29,7 +37,7 @@ tape('runBlockchain', (t) => { }) t.test('should run with genesis block', async (st) => { - const genesis = createGenesis() + const genesis = createGenesis({ chain: 'goerli' }) await putGenesisP(genesis) st.ok(blockchain.meta.genesis, 'genesis should be set for blockchain') @@ -49,12 +57,12 @@ tape('runBlockchain', (t) => { cb(null, {}) } - const genesis = createGenesis() + const genesis = createGenesis({ chain: 'goerli' }) await putGenesisP(genesis) - const b1 = createBlock(genesis, 1) - const b2 = createBlock(b1, 2) - const b3 = createBlock(b2, 3) + const b1 = createBlock(genesis, 1, { chain: 'goerli' }) + const b2 = createBlock(b1, 2, { chain: 'goerli' }) + const b3 = createBlock(b2, 3, { chain: 'goerli' }) blockchain.validate = false @@ -79,12 +87,13 @@ tape('runBlockchain', (t) => { }) }) -function createBlock (parent = null, n = 0) { +function createBlock (parent = null, n = 0, opts = {}) { + opts.chain = opts.chain ? opts.chain : 'mainnet' if (parent === null) { - return createGenesis() + return createGenesis(opts) } - const b = new Block() + const b = new Block(null, opts) b.header.number = util.toBuffer(n) b.header.parentHash = parent.hash() b.header.difficulty = '0xfffffff' diff --git a/tests/api/state/stateManager.js b/tests/api/state/stateManager.js index 15722bb25a..2c8bbb9d55 100644 --- a/tests/api/state/stateManager.js +++ b/tests/api/state/stateManager.js @@ -1,4 +1,4 @@ -const { promisify } = require('util') +const promisify = require('util.promisify') const tape = require('tape') const util = require('ethereumjs-util') const StateManager = require('../../../lib/state/stateManager') @@ -9,13 +9,12 @@ tape('StateManager', (t) => { const stateManager = new StateManager() st.deepEqual(stateManager._trie.root, util.KECCAK256_RLP, 'it has default root') + st.equal(stateManager._common.hardfork(), 'byzantium', 'it has default hardfork') stateManager.getStateRoot((err, res) => { st.error(err, 'getStateRoot returns no error') st.deepEqual(res, util.KECCAK256_RLP, 'it has default root') + st.end() }) - - st.equal(stateManager._common.hardfork(), 'byzantium', 'it has default hardfork') - st.end() }) t.test('should clear the cache when the state root is set', async (st) => { diff --git a/tests/api/state/storageReader.js b/tests/api/state/storageReader.js index aece74d7aa..ed3f564a23 100644 --- a/tests/api/state/storageReader.js +++ b/tests/api/state/storageReader.js @@ -1,4 +1,4 @@ -const { promisify } = require('util') +const promisify = require('util.promisify') const tape = require('tape') const { StorageReader } = require('../../../lib/state') diff --git a/tests/api/utils.js b/tests/api/utils.js index e29555acfe..0decdcd1da 100644 --- a/tests/api/utils.js +++ b/tests/api/utils.js @@ -4,8 +4,9 @@ const level = require('level-mem') const Blockchain = require('ethereumjs-blockchain') const VM = require('../../lib/index') -function createGenesis () { - const genesis = new Block() +function createGenesis (opts = {}) { + opts.chain = opts.chain ? opts.chain : 'mainnet' + const genesis = new Block(null, opts) genesis.setGenesisParams() return genesis @@ -20,10 +21,10 @@ function createAccount (nonce, balance) { return acc } -function setupVM () { +function setupVM (opts = {}) { const db = level() - const blockchain = new Blockchain(db) - const vm = new VM({ blockchain }) + opts.blockchain = opts.blockchain ? opts.blockchain : new Blockchain({ db, validate: false }) + const vm = new VM(opts) return vm }