Use Ganache programmatically in e2e tests (#7664)
The `ganache.js` helper module uses `ganache-core` to start `ganache` instead of `ganache-cli`, and allows all of the same customization. Using `ganache` programmatically from our e2e tests is much faster, as we don't have to wait that arbitrary 5 seconds before each test as we wait for `ganache-cli` to start up.feature/default_network_editable
parent
49a525b9f8
commit
476e422714
@ -0,0 +1,37 @@ |
||||
const ganache = require('ganache-core') |
||||
const { promisify } = require('util') |
||||
|
||||
const defaultOptions = { |
||||
blockTime: 2, |
||||
network_id: 5777, |
||||
mnemonic: 'phrase upgrade clock rough situate wedding elder clever doctor stamp excess tent', |
||||
port: 8545, |
||||
vmErrorsOnRPCResponse: false, |
||||
} |
||||
|
||||
class Ganache { |
||||
async start (options) { |
||||
options = Object.assign({}, defaultOptions, options) |
||||
|
||||
const port = options.port |
||||
this._server = ganache.server(options) |
||||
|
||||
const listen = promisify(this._server.listen).bind(this._server) |
||||
const blockchain = await listen(port) |
||||
|
||||
return { |
||||
...blockchain, |
||||
port, |
||||
} |
||||
} |
||||
|
||||
async quit () { |
||||
if (!this._server) { |
||||
throw new Error('Server not running yet') |
||||
} |
||||
const close = promisify(this._server.close).bind(this._server) |
||||
await close() |
||||
} |
||||
} |
||||
|
||||
module.exports = Ganache |
Loading…
Reference in new issue