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() {
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;

View File

@ -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');

View File

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

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {