mirror of https://github.com/embarklabs/embark.git
fix testing functionality in develop
This commit is contained in:
parent
ad9b18133a
commit
2a2a5820fc
|
@ -1,6 +1,7 @@
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var EmbarkSpec = require('embark/lib/core/test.js');
|
var Embark = require('embark');
|
||||||
|
var EmbarkSpec = Embark.initTests();
|
||||||
|
var web3 = EmbarkSpec.web3;
|
||||||
|
|
||||||
// describe("SimpleStorage", function() {
|
// describe("SimpleStorage", function() {
|
||||||
// before(function(done) {
|
// before(function(done) {
|
||||||
|
|
|
@ -22,7 +22,7 @@ class Engine {
|
||||||
let self = this;
|
let self = this;
|
||||||
let options = _options || {};
|
let options = _options || {};
|
||||||
this.events = new Events();
|
this.events = new Events();
|
||||||
this.logger = options.logger || new Logger({logLevel: 'debug'});
|
this.logger = options.logger || new Logger({logLevel: options.logLevel || 'debug'});
|
||||||
this.config = new Config({env: this.env, logger: this.logger, events: this.events});
|
this.config = new Config({env: this.env, logger: this.logger, events: this.events});
|
||||||
this.config.loadConfigFiles({embarkConfig: this.embarkConfig, interceptLogs: this.interceptLogs});
|
this.config.loadConfigFiles({embarkConfig: this.embarkConfig, interceptLogs: this.interceptLogs});
|
||||||
this.plugins = this.config.plugins;
|
this.plugins = this.config.plugins;
|
||||||
|
|
|
@ -8,7 +8,7 @@ let web3;
|
||||||
// ======================
|
// ======================
|
||||||
function doEval(code, _web3) {
|
function doEval(code, _web3) {
|
||||||
if (_web3) {
|
if (_web3) {
|
||||||
let web3 = _web3;
|
web3 = _web3;
|
||||||
}
|
}
|
||||||
return eval(code); // jshint ignore:line
|
return eval(code); // jshint ignore:line
|
||||||
}
|
}
|
||||||
|
|
100
lib/core/test.js
100
lib/core/test.js
|
@ -1,6 +1,23 @@
|
||||||
let getSimulator = function () {
|
var async = require('async');
|
||||||
|
var Web3 = require('web3');
|
||||||
|
|
||||||
|
var Embark = require('../index.js');
|
||||||
|
|
||||||
|
var Engine = require('./engine.js');
|
||||||
|
|
||||||
|
var ABIGenerator = require('../contracts/abi.js');
|
||||||
|
var ContractsManager = require('../contracts/contracts.js');
|
||||||
|
var Deploy = require('../contracts/deploy.js');
|
||||||
|
|
||||||
|
var Config = require('./config.js');
|
||||||
|
var RunCode = require('./runCode.js');
|
||||||
|
var TestLogger = require('./test_logger.js');
|
||||||
|
var web3;
|
||||||
|
|
||||||
|
var getSimulator = function() {
|
||||||
try {
|
try {
|
||||||
return require('ethereumjs-testrpc');
|
var sim = require('ethereumjs-testrpc');
|
||||||
|
return sim;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e.code === 'MODULE_NOT_FOUND') {
|
if (e.code === 'MODULE_NOT_FOUND') {
|
||||||
console.log('Simulator not found; Please install it with "npm install ethereumjs-testrpc --save"');
|
console.log('Simulator not found; Please install it with "npm install ethereumjs-testrpc --save"');
|
||||||
|
@ -17,25 +34,70 @@ let getSimulator = function () {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var Test = function(options) {
|
||||||
|
this.options = options || {};
|
||||||
|
var simOptions = this.options.simulatorOptions || {};
|
||||||
|
|
||||||
class Test {
|
this.engine = new Engine({
|
||||||
constructor(options) {
|
env: this.options.env || 'test',
|
||||||
this.opts = options === undefined ? {} : options;
|
// TODO: confi will need to detect if this is a obj
|
||||||
this.opts.logLevel = this.opts.hasOwnProperty('logLevel') ? this.opts.logLevel : 'debug';
|
embarkConfig: this.options.embarkConfig || 'embark.json',
|
||||||
this.opts.simulatorOptions = this.opts.hasOwnProperty('simulatorOptions') ? this.opts.simulatorOptions : {};
|
interceptLogs: false
|
||||||
this.sim = getSimulator();
|
});
|
||||||
}
|
|
||||||
|
|
||||||
newWebThree() {
|
this.engine.init({
|
||||||
try {
|
logger: new TestLogger({logLevel: 'debug'})
|
||||||
let Web3 = require('web3');
|
});
|
||||||
let web3 = new Web3();
|
|
||||||
web3.setProvider(this.sim.provider(this.opts.simulatorOptions));
|
this.sim = getSimulator();
|
||||||
return web3;
|
this.web3 = new Web3();
|
||||||
} catch (e) {
|
this.web3.setProvider(this.sim.provider(simOptions));
|
||||||
throw new Error(e);
|
};
|
||||||
|
|
||||||
|
Test.prototype.deployAll = function(contractsConfig, cb) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
async.waterfall([
|
||||||
|
function getConfig(callback) {
|
||||||
|
self.engine.config.contractsConfig = {contracts: contractsConfig};
|
||||||
|
callback();
|
||||||
|
},
|
||||||
|
function startServices(callback) {
|
||||||
|
//{abiType: 'contracts', embarkJS: false}
|
||||||
|
self.engine.startService("abi");
|
||||||
|
self.engine.startService("deployment", {
|
||||||
|
web3: self.web3,
|
||||||
|
trackContracts: false
|
||||||
|
});
|
||||||
|
callback();
|
||||||
|
},
|
||||||
|
function deploy(callback) {
|
||||||
|
self.engine.events.on('abi-contracts-vanila', function(vanillaABI) {
|
||||||
|
callback(null, vanillaABI);
|
||||||
|
});
|
||||||
|
self.engine.deployManager.deployContracts(function(err, result) {
|
||||||
|
if (err) {
|
||||||
|
console.log(err);
|
||||||
|
callback(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
], 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) {
|
||||||
|
if (err) {
|
||||||
|
throw new Error(err);
|
||||||
|
}
|
||||||
|
self.web3.eth.defaultAccount = accounts[0];
|
||||||
|
RunCode.doEval(result, self.web3); // jshint ignore:line
|
||||||
|
cb();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = Test;
|
module.exports = Test;
|
||||||
|
|
|
@ -197,4 +197,10 @@ class Embark {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// temporary until next refactor
|
||||||
|
Embark.initTests = function(options) {
|
||||||
|
let Test = require('./core/test.js');
|
||||||
|
return new Test(options);
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = Embark;
|
module.exports = Embark;
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var EmbarkSpec = require('embark/lib/core/test.js');
|
var Embark = require('embark');
|
||||||
|
var EmbarkSpec = Embark.initTests();
|
||||||
|
var web3 = EmbarkSpec.web3;
|
||||||
|
|
||||||
describe("AnotherStorage", function() {
|
describe("AnotherStorage", function() {
|
||||||
before(function(done) {
|
before(function(done) {
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var EmbarkSpec = require('embark/lib/core/test.js');
|
var Embark = require('embark');
|
||||||
|
var EmbarkSpec = Embark.initTests();
|
||||||
|
var web3 = EmbarkSpec.web3;
|
||||||
|
|
||||||
describe("SimpleStorage", function() {
|
describe("SimpleStorage", function() {
|
||||||
before(function(done) {
|
before(function(done) {
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var EmbarkSpec = require('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) {
|
||||||
|
|
Loading…
Reference in New Issue