From 94cca83670f87444f07959d968777d606dd03e13 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 3 Mar 2017 21:06:44 -0500 Subject: [PATCH] simplify test constructor --- lib/core/test.js | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/lib/core/test.js b/lib/core/test.js index 5173a86c..71855931 100644 --- a/lib/core/test.js +++ b/lib/core/test.js @@ -13,8 +13,30 @@ var Config = require('./config.js'); var RunCode = require('./runCode.js'); var TestLogger = require('./test_logger.js'); +var getSimulator = function() { + try { + var sim = require('ethereumjs-testrpc'); + return sim; + } 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; + } +}; + var Test = function(options) { this.options = options || {}; + var simOptions = this.options.simulatorOptions || {}; + this.engine = new Engine({ env: this.options.env || 'test', // TODO: confi will need to detect if this is a obj @@ -26,26 +48,7 @@ var Test = function(options) { logger: new TestLogger({logLevel: this.options.logLevel || 'debug'}) }); - var simOptions = this.options.simulatorOptions || {}; - - try { - this.sim = require('ethereumjs-testrpc'); - } 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 - process.exit(); - } else { - 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; - } - } - + this.sim = getSimulator(); this.web3 = new Web3(); this.web3.setProvider(this.sim.provider(simOptions)); };