mirror of https://github.com/embarklabs/embark.git
build only once
This commit is contained in:
parent
41aaa5c20d
commit
093bd13c6a
|
@ -19,7 +19,11 @@ class DeployManager {
|
||||||
this.onlyCompile = options.onlyCompile !== undefined ? options.onlyCompile : false;
|
this.onlyCompile = options.onlyCompile !== undefined ? options.onlyCompile : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
deployContracts(done) {
|
deployContracts(compileOnlyIfNeeded, done) {
|
||||||
|
if (typeof compileOnlyIfNeeded === 'function') {
|
||||||
|
done = compileOnlyIfNeeded;
|
||||||
|
compileOnlyIfNeeded = false;
|
||||||
|
}
|
||||||
let self = this;
|
let self = this;
|
||||||
|
|
||||||
if (self.blockchainConfig === {} || self.blockchainConfig.enabled === false) {
|
if (self.blockchainConfig === {} || self.blockchainConfig.enabled === false) {
|
||||||
|
@ -30,6 +34,13 @@ class DeployManager {
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function buildContracts(callback) {
|
function buildContracts(callback) {
|
||||||
|
if (compileOnlyIfNeeded) {
|
||||||
|
if (self.contractsManager.compiledContracts && Object.keys(self.contractsManager.compiledContracts).length) {
|
||||||
|
// Contracts have already been compiled
|
||||||
|
return callback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log('compiling');
|
||||||
self.contractsManager.deployOnlyOnConfig = self.deployOnlyOnConfig; // temporary, should refactor
|
self.contractsManager.deployOnlyOnConfig = self.deployOnlyOnConfig; // temporary, should refactor
|
||||||
self.contractsManager.build(() => {
|
self.contractsManager.build(() => {
|
||||||
callback();
|
callback();
|
||||||
|
|
|
@ -26,9 +26,6 @@ module.exports = {
|
||||||
if (!filePath) {
|
if (!filePath) {
|
||||||
filePath = 'test/';
|
filePath = 'test/';
|
||||||
}
|
}
|
||||||
let configOptions = {
|
|
||||||
gasPrice: 1
|
|
||||||
};
|
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function getFiles(next) {
|
function getFiles(next) {
|
||||||
|
@ -48,8 +45,6 @@ module.exports = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function setupGlobalNamespace(next) {
|
function setupGlobalNamespace(next) {
|
||||||
global.assert = require('assert');
|
|
||||||
|
|
||||||
// TODO put default config
|
// TODO put default config
|
||||||
const test = new Test();
|
const test = new Test();
|
||||||
global.embark = test;
|
global.embark = test;
|
||||||
|
@ -69,7 +64,7 @@ module.exports = {
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
// Run the tests.
|
// Run the tests.
|
||||||
let runner = mocha.run(function(failures) {
|
mocha.run(function(failures) {
|
||||||
// Clean contracts folder for next test run
|
// Clean contracts folder for next test run
|
||||||
fs.remove('.embark/contracts', (_err) => {
|
fs.remove('.embark/contracts', (_err) => {
|
||||||
process.on('exit', function () {
|
process.on('exit', function () {
|
||||||
|
@ -78,12 +73,6 @@ module.exports = {
|
||||||
process.exit();
|
process.exit();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
runner.on('suite', function() {
|
|
||||||
global.assert = require('assert');
|
|
||||||
global.EmbarkSpec = new Test({simulatorOptions: configOptions});
|
|
||||||
global.web3 = global.EmbarkSpec.web3;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
|
const async = require('async');
|
||||||
const Engine = require('../core/engine.js');
|
const Engine = require('../core/engine.js');
|
||||||
const TestLogger = require('./test_logger.js');
|
const TestLogger = require('./test_logger.js');
|
||||||
const Web3 = require('web3');
|
const Web3 = require('web3');
|
||||||
const utils = require('../utils/utils');
|
const utils = require('../utils/utils');
|
||||||
|
const constants = require('../constants');
|
||||||
|
|
||||||
function getSimulator() {
|
function getSimulator() {
|
||||||
try {
|
try {
|
||||||
|
@ -32,15 +34,10 @@ class Test {
|
||||||
this.sim = getSimulator();
|
this.sim = getSimulator();
|
||||||
this.web3.setProvider(this.sim.provider(this.simOptions));
|
this.web3.setProvider(this.sim.provider(this.simOptions));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
config(options) {
|
|
||||||
this.options = utils.recursiveMerge(this.options, options);
|
|
||||||
this.simOptions = this.options.simulatorOptions || {};
|
|
||||||
|
|
||||||
this.engine = new Engine({
|
this.engine = new Engine({
|
||||||
env: this.options.env || 'test',
|
env: this.options.env || 'test',
|
||||||
// TODO: confi will need to detect if this is a obj
|
// TODO: config will need to detect if this is a obj
|
||||||
embarkConfig: this.options.embarkConfig || 'embark.json',
|
embarkConfig: this.options.embarkConfig || 'embark.json',
|
||||||
interceptLogs: false
|
interceptLogs: false
|
||||||
});
|
});
|
||||||
|
@ -49,12 +46,69 @@ class Test {
|
||||||
logger: new TestLogger({logLevel: 'debug'})
|
logger: new TestLogger({logLevel: 'debug'})
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.simOptions.node) {
|
this.engine.startService("libraryManager");
|
||||||
this.web3.setProvider(new this.web3.providers.HttpProvider(this.simOptions.node));
|
this.engine.startService("codeRunner");
|
||||||
} else {
|
this.engine.startService("web3", {
|
||||||
this.sim = getSimulator();
|
web3: this.web3
|
||||||
this.web3.setProvider(this.sim.provider(this.simOptions));
|
});
|
||||||
}
|
this.engine.startService("deployment", {
|
||||||
|
trackContracts: false
|
||||||
|
});
|
||||||
|
this.engine.startService("codeGenerator");
|
||||||
|
}
|
||||||
|
|
||||||
|
config(options, callback) {
|
||||||
|
this.options = utils.recursiveMerge(this.options, options);
|
||||||
|
this.simOptions = this.options.simulatorOptions || {};
|
||||||
|
|
||||||
|
this._deploy(options, (err, accounts) => {
|
||||||
|
if (err) {
|
||||||
|
console.error(err);
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
callback(null, accounts);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
_deploy(config, cb) {
|
||||||
|
const self = this;
|
||||||
|
async.waterfall([
|
||||||
|
function getConfig(callback) {
|
||||||
|
let _versions_default = self.engine.config.contractsConfig.versions;
|
||||||
|
self.engine.config.contractsConfig = {contracts: config.contracts, versions: _versions_default};
|
||||||
|
callback();
|
||||||
|
},
|
||||||
|
function reloadConfig(callback) {
|
||||||
|
self.engine.events.emit(constants.events.contractConfigChanged, self.engine.config.contractsConfig);
|
||||||
|
callback();
|
||||||
|
},
|
||||||
|
function deploy(callback) {
|
||||||
|
self.engine.deployManager.gasLimit = 6000000;
|
||||||
|
self.engine.contractsManager.gasLimit = 6000000;
|
||||||
|
self.engine.deployManager.fatalErrors = true;
|
||||||
|
self.engine.deployManager.deployOnlyOnConfig = true;
|
||||||
|
self.engine.deployManager.deployContracts(true, function(err, _result) {
|
||||||
|
if (err) {
|
||||||
|
callback(err);
|
||||||
|
}
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
], function(err) {
|
||||||
|
if (err) {
|
||||||
|
console.log(__('terminating due to error'));
|
||||||
|
cb(err);
|
||||||
|
}
|
||||||
|
// 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];
|
||||||
|
cb(null, accounts);
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ class TestLogger {
|
||||||
|
|
||||||
logFunction() {
|
logFunction() {
|
||||||
this.logs.push(arguments);
|
this.logs.push(arguments);
|
||||||
//console.dir(arguments[0]);
|
console.log(...arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
contractsState() {
|
contractsState() {
|
||||||
|
|
Loading…
Reference in New Issue