speed up testing

This commit is contained in:
Todd Baur 2017-03-13 00:21:19 +09:00
parent 32953f7204
commit 124177c8fc
6 changed files with 26 additions and 49 deletions

View File

@ -1,6 +1,3 @@
var async = require('async');
var Web3 = require('web3');
var getSimulator = function() { var getSimulator = function() {
try { try {
return require('ethereumjs-testrpc'); return require('ethereumjs-testrpc');
@ -20,34 +17,26 @@ var getSimulator = function() {
} }
}; };
var Test;
var Test = function(options) { Test = (function (options) {
var async = require('async');
var opts = options === undefined ? {} : options; var opts = options === undefined ? {} : options;
opts.logLevel = opts.hasOwnProperty('logLevel') ? opts.logLevel : 'debug'; opts.logLevel = opts.hasOwnProperty('logLevel') ? opts.logLevel : 'debug';
opts.simulatorOptions = opts.hasOwnProperty('simulatorOptions') ? opts.simulatorOptions : {}; opts.simulatorOptions = opts.hasOwnProperty('simulatorOptions') ? opts.simulatorOptions : {};
var sim = getSimulator();
function newWebThree () { function newWebThree() {
try { try {
var Web3 = require('web3'); var Web3 = require('web3');
var web3 = new Web3(); var web3 = new Web3();
web3.setProvider(getSimulator()); web3.setProvider(sim.provider(opts.simulatorOptions));
return web3;
} catch (e) { } 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); throw new Error(e);
} }
} }
function deployAll (contractsConfig, cb) { function deployAll(contractsConfig, cb) {
var RunCode = require('./runCode.js'); var RunCode = require('./runCode.js');
var self = this; var self = this;
@ -58,20 +47,16 @@ var Test = function(options) {
// TODO: confi will need to detect if this is a obj // TODO: confi will need to detect if this is a obj
embarkConfig: opts.embarkConfig || 'embark.json', embarkConfig: opts.embarkConfig || 'embark.json',
interceptLogs: false interceptLogs: false
}).init(); });
} }
function newLogger() { self.web3 = newWebThree();
var TestLogger = require('./test_logger.js'); self.engine = newEngine();
new TestLogger({logLevel: opts.logLevel}) self.engine.init();
}
this.engine = newEngine();
this.web3 = newWebThree();
async.waterfall([ async.waterfall([
function getConfig(callback) { function getConfig(callback) {
contractsConfig = { contracts: contractsConfig }; self.engine.config.contractsConfig = {contracts: contractsConfig};
callback(); callback();
}, },
function startServices(callback) { function startServices(callback) {
@ -84,24 +69,24 @@ var Test = function(options) {
callback(); callback();
}, },
function deploy(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); callback(null, vanillaABI);
}); });
self.engine.deployManager.deployContracts(function(err, result) { self.engine.deployManager.deployContracts(function (err, result) {
if (err) { if (err) {
console.log(err); console.log(err);
callback(err); callback(err);
} }
}); });
} }
], function(err, result) { ], function (err, result) {
if (err) { if (err) {
console.log("got error"); console.log("got error");
process.exit(); process.exit();
} }
// this should be part of the waterfall and not just something done at the // this should be part of the waterfall and not just something done at the
// end // end
self.web3.eth.getAccounts(function(err, accounts) { self.web3.eth.getAccounts(function (err, accounts) {
if (err) { if (err) {
throw new Error(err); throw new Error(err);
} }
@ -114,8 +99,9 @@ var Test = function(options) {
return { return {
deployAll: deployAll deployAll: deployAll,
} sim: sim
}(); };
}());
module.exports = Test; module.exports = Test;

View File

@ -1,6 +1,6 @@
/*jshint esversion: 6 */ /*jshint esversion: 6 */
var async = require('async'); var async = require('async');
//require("./core/debug_util.js")(__filename, async); // require("./utils/debug_util.js")(__filename, async);
var colors = require('colors'); var colors = require('colors');

View File

@ -10,7 +10,7 @@
"license": "ISC", "license": "ISC",
"homepage": "", "homepage": "",
"devDependencies": { "devDependencies": {
"embark": "../", "embark": "file:../",
"mocha": "^2.2.5" "mocha": "^2.2.5"
}, },
"dependencies": { "dependencies": {

View File

@ -1,8 +1,5 @@
var assert = require('assert'); var assert = require('assert');
var Embark = require('embark'); var EmbarkSpec = require('embark/lib/core/test.js');
//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;
describe("AnotherStorage", function() { describe("AnotherStorage", function() {
before(function(done) { before(function(done) {

View File

@ -1,7 +1,5 @@
var assert = require('assert'); var assert = require('assert');
var Embark = require('embark'); var EmbarkSpec = require('embark/lib/core/test.js');
var EmbarkSpec = require('../node_modules/embark/lib/core/test.js');
var web3 = EmbarkSpec.web3;
describe("SimpleStorage", function() { describe("SimpleStorage", function() {
before(function(done) { before(function(done) {

View File

@ -1,9 +1,5 @@
var assert = require('assert'); var assert = require('assert');
var Embark = require('embark'); var EmbarkSpec = require('embark/lib/core/test.js');
var EmbarkSpec = require('../node_modules/embark/lib/core/test.js');
var Embark = require('embark');
var EmbarkSpec = Embark.initTests();
var web3 = EmbarkSpec.web3;
describe("Token", function() { describe("Token", function() {
before(function(done) { before(function(done) {