embark-area-51/lib/core/test.js

42 lines
1.6 KiB
JavaScript
Raw Normal View History

2017-03-30 11:12:39 +00:00
let getSimulator = function () {
2017-03-04 02:06:44 +00:00
try {
2017-03-12 03:23:30 +00:00
return require('ethereumjs-testrpc');
2017-03-04 02:06:44 +00:00
} catch (e) {
if (e.code === 'MODULE_NOT_FOUND') {
console.log('Simulator not found; Please install it with "npm install ethereumjs-testrpc --save"');
console.log('IMPORTANT: if you using a NodeJS version older than 6.9.1 then you need to install an older version of testrpc "npm install ethereumjs-testrpc@2.0 --save"');
console.log('For more information see https://github.com/ethereumjs/testrpc');
// TODO: should throw exception instead
return process.exit();
}
console.log("==============");
console.log("Tried to load testrpc but an error occurred. This is a problem with testrpc");
console.log('IMPORTANT: if you using a NodeJS version older than 6.9.1 then you need to install an older version of testrpc "npm install ethereumjs-testrpc@2.0 --save". Alternatively install node 6.9.1 and the testrpc 3.0');
console.log("==============");
throw e;
}
};
2017-03-30 11:12:39 +00:00
class Test {
constructor(options) {
2017-03-30 11:38:14 +00:00
this.opts = options === undefined ? {} : options;
this.opts.logLevel = this.opts.hasOwnProperty('logLevel') ? this.opts.logLevel : 'debug';
this.opts.simulatorOptions = this.opts.hasOwnProperty('simulatorOptions') ? this.opts.simulatorOptions : {};
this.sim = getSimulator();
2017-03-30 11:12:39 +00:00
}
newWebThree() {
2017-03-12 03:23:30 +00:00
try {
2017-03-29 17:50:05 +00:00
let Web3 = require('web3');
let web3 = new Web3();
2017-03-30 11:38:14 +00:00
web3.setProvider(this.sim.provider(this.opts.simulatorOptions));
2017-03-12 15:21:19 +00:00
return web3;
2017-03-12 03:23:30 +00:00
} catch (e) {
throw new Error(e);
}
}
2017-03-30 11:12:39 +00:00
}
2016-08-21 22:05:35 +00:00
module.exports = Test;