2022-01-19 00:08:41 +01:00
|
|
|
const ganache = require('ganache');
|
2019-12-09 15:40:43 +01:00
|
|
|
|
|
|
|
const defaultOptions = {
|
|
|
|
blockTime: 2,
|
2020-10-12 21:05:40 +02:00
|
|
|
network_id: 1337,
|
2020-11-03 00:41:28 +01:00
|
|
|
mnemonic:
|
|
|
|
'phrase upgrade clock rough situate wedding elder clever doctor stamp excess tent',
|
2019-12-09 15:40:43 +01:00
|
|
|
port: 8545,
|
|
|
|
vmErrorsOnRPCResponse: false,
|
2022-01-19 00:08:41 +01:00
|
|
|
hardfork: 'muirGlacier',
|
2022-02-16 15:21:41 +01:00
|
|
|
quiet: true,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-12-09 15:40:43 +01:00
|
|
|
|
|
|
|
class Ganache {
|
2020-11-03 00:41:28 +01:00
|
|
|
async start(opts) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const options = { ...defaultOptions, ...opts };
|
|
|
|
const { port } = options;
|
|
|
|
this._server = ganache.server(options);
|
2022-01-19 00:08:41 +01:00
|
|
|
await this._server.listen(port);
|
2019-12-09 15:40:43 +01:00
|
|
|
}
|
|
|
|
|
2022-08-09 15:59:20 +02:00
|
|
|
getProvider() {
|
|
|
|
return this._server.provider;
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
async quit() {
|
2019-12-09 15:40:43 +01:00
|
|
|
if (!this._server) {
|
2021-02-04 19:15:23 +01:00
|
|
|
throw new Error('Server not running yet');
|
2019-12-09 15:40:43 +01:00
|
|
|
}
|
2022-01-19 00:08:41 +01:00
|
|
|
await this._server.close();
|
2019-12-09 15:40:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
module.exports = Ganache;
|