From 124177c8fc4a8288f923508ea1a0774e0d4ffc7c Mon Sep 17 00:00:00 2001 From: Todd Baur Date: Mon, 13 Mar 2017 00:21:19 +0900 Subject: [PATCH] speed up testing --- lib/core/test.js | 56 ++++++++++----------------- lib/index.js | 2 +- test_app/package.json | 2 +- test_app/test/another_storage_spec.js | 5 +-- test_app/test/simple_storage_spec.js | 4 +- test_app/test/token_spec.js | 6 +-- 6 files changed, 26 insertions(+), 49 deletions(-) diff --git a/lib/core/test.js b/lib/core/test.js index 3c0a186c3..d4b216e45 100644 --- a/lib/core/test.js +++ b/lib/core/test.js @@ -1,6 +1,3 @@ -var async = require('async'); -var Web3 = require('web3'); - var getSimulator = function() { try { return require('ethereumjs-testrpc'); @@ -20,34 +17,26 @@ var getSimulator = function() { } }; - -var Test = function(options) { +var Test; +Test = (function (options) { + var async = require('async'); var opts = options === undefined ? {} : options; opts.logLevel = opts.hasOwnProperty('logLevel') ? opts.logLevel : 'debug'; opts.simulatorOptions = opts.hasOwnProperty('simulatorOptions') ? opts.simulatorOptions : {}; + var sim = getSimulator(); - function newWebThree () { + function newWebThree() { try { var Web3 = require('web3'); var web3 = new Web3(); - web3.setProvider(getSimulator()); + web3.setProvider(sim.provider(opts.simulatorOptions)); + return web3; } 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 new Error(e); } } - function deployAll (contractsConfig, cb) { + function deployAll(contractsConfig, cb) { var RunCode = require('./runCode.js'); var self = this; @@ -58,20 +47,16 @@ var Test = function(options) { // TODO: confi will need to detect if this is a obj embarkConfig: opts.embarkConfig || 'embark.json', interceptLogs: false - }).init(); + }); } - function newLogger() { - var TestLogger = require('./test_logger.js'); - new TestLogger({logLevel: opts.logLevel}) - } - - this.engine = newEngine(); - this.web3 = newWebThree(); + self.web3 = newWebThree(); + self.engine = newEngine(); + self.engine.init(); async.waterfall([ function getConfig(callback) { - contractsConfig = { contracts: contractsConfig }; + self.engine.config.contractsConfig = {contracts: contractsConfig}; callback(); }, function startServices(callback) { @@ -84,24 +69,24 @@ var Test = function(options) { callback(); }, function deploy(callback) { - self.engine.events.on('abi-contracts-vanila', function(vanillaABI) { + self.engine.events.on('abi-contracts-vanila', function (vanillaABI) { callback(null, vanillaABI); }); - self.engine.deployManager.deployContracts(function(err, result) { + self.engine.deployManager.deployContracts(function (err, result) { if (err) { console.log(err); callback(err); } }); } - ], function(err, result) { + ], function (err, result) { if (err) { console.log("got error"); process.exit(); } // this should be part of the waterfall and not just something done at the // end - self.web3.eth.getAccounts(function(err, accounts) { + self.web3.eth.getAccounts(function (err, accounts) { if (err) { throw new Error(err); } @@ -114,8 +99,9 @@ var Test = function(options) { return { - deployAll: deployAll - } -}(); + deployAll: deployAll, + sim: sim + }; +}()); module.exports = Test; diff --git a/lib/index.js b/lib/index.js index 468a4987c..7037f2246 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,6 +1,6 @@ /*jshint esversion: 6 */ var async = require('async'); -//require("./core/debug_util.js")(__filename, async); +// require("./utils/debug_util.js")(__filename, async); var colors = require('colors'); diff --git a/test_app/package.json b/test_app/package.json index 29cd34ffa..042f454f1 100644 --- a/test_app/package.json +++ b/test_app/package.json @@ -10,7 +10,7 @@ "license": "ISC", "homepage": "", "devDependencies": { - "embark": "../", + "embark": "file:../", "mocha": "^2.2.5" }, "dependencies": { diff --git a/test_app/test/another_storage_spec.js b/test_app/test/another_storage_spec.js index bb5f8c911..b60297b57 100644 --- a/test_app/test/another_storage_spec.js +++ b/test_app/test/another_storage_spec.js @@ -1,8 +1,5 @@ var assert = require('assert'); -var Embark = require('embark'); -//TODO: this path is temporary to handle the scope of Embark within an app -var EmbarkSpec = require('../node_modules/embark/lib/core/test.js'); -var web3 = EmbarkSpec.web3; +var EmbarkSpec = require('embark/lib/core/test.js'); describe("AnotherStorage", function() { before(function(done) { diff --git a/test_app/test/simple_storage_spec.js b/test_app/test/simple_storage_spec.js index 9a24bc69f..b330ced62 100644 --- a/test_app/test/simple_storage_spec.js +++ b/test_app/test/simple_storage_spec.js @@ -1,7 +1,5 @@ var assert = require('assert'); -var Embark = require('embark'); -var EmbarkSpec = require('../node_modules/embark/lib/core/test.js'); -var web3 = EmbarkSpec.web3; +var EmbarkSpec = require('embark/lib/core/test.js'); describe("SimpleStorage", function() { before(function(done) { diff --git a/test_app/test/token_spec.js b/test_app/test/token_spec.js index a043f84ab..93eb28b5f 100644 --- a/test_app/test/token_spec.js +++ b/test_app/test/token_spec.js @@ -1,9 +1,5 @@ var assert = require('assert'); -var Embark = require('embark'); -var EmbarkSpec = require('../node_modules/embark/lib/core/test.js'); -var Embark = require('embark'); -var EmbarkSpec = Embark.initTests(); -var web3 = EmbarkSpec.web3; +var EmbarkSpec = require('embark/lib/core/test.js'); describe("Token", function() { before(function(done) {