Skip to content

Commit

Permalink
Run blockchain browser API tests against Goerli for reasonable test e…
Browse files Browse the repository at this point in the history
…xecution time, activated tests
  • Loading branch information
holgerd77 committed Mar 14, 2019
1 parent 3e8ec79 commit 390d1f2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
1 change: 0 additions & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ module.exports = function (config) {
// list of files / patterns to exclude
exclude: [
'./tests/api/state/stateManager.js', // 4, "# should clear the cache when the state root is set"
'./tests/api/runBlockchain.js' // 2, "# should run with valid and invalid blocks"
],

// preprocess matching files before serving them to the browser
Expand Down
29 changes: 19 additions & 10 deletions tests/api/runBlockchain.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@ const level = require('level-mem')
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')
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))
Expand All @@ -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')
Expand All @@ -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

Expand All @@ -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'
Expand Down
5 changes: 3 additions & 2 deletions tests/api/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 390d1f2

Please sign in to comment.