resolve conflict in test.js
This commit is contained in:
parent
723a4ae805
commit
c234655acd
|
@ -0,0 +1,120 @@
|
||||||
|
var async = require('async');
|
||||||
|
//require("../utils/debug_util.js")(__filename, async);
|
||||||
|
var Web3 = require('web3');
|
||||||
|
var Engine = require('../core/engine.js');
|
||||||
|
var TestLogger = require('./test_logger.js');
|
||||||
|
|
||||||
|
var getSimulator = function() {
|
||||||
|
try {
|
||||||
|
var sim = require('ethereumjs-testrpc');
|
||||||
|
return sim;
|
||||||
|
} catch (e) {
|
||||||
|
if (e.code === 'MODULE_NOT_FOUND') {
|
||||||
|
console.log(__('Simulator not found; Please install it with "%s"', '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 "%s"', '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 "%s". Alternatively install node 6.9.1 and the testrpc 3.0', 'npm install ethereumjs-testrpc@2.0 --save'));
|
||||||
|
console.log("==============");
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var Test = function(options) {
|
||||||
|
this.options = options || {};
|
||||||
|
this.simOptions = this.options.simulatorOptions || {};
|
||||||
|
|
||||||
|
this.engine = new Engine({
|
||||||
|
env: this.options.env || 'test',
|
||||||
|
// TODO: confi will need to detect if this is a obj
|
||||||
|
embarkConfig: this.options.embarkConfig || 'embark.json',
|
||||||
|
interceptLogs: false
|
||||||
|
});
|
||||||
|
|
||||||
|
this.engine.init({
|
||||||
|
logger: new TestLogger({logLevel: 'debug'})
|
||||||
|
});
|
||||||
|
|
||||||
|
this.web3 = new Web3();
|
||||||
|
|
||||||
|
if (this.simOptions.node) {
|
||||||
|
this.web3.setProvider(new this.web3.providers.HttpProvider(this.simOptions.node));
|
||||||
|
} else {
|
||||||
|
this.sim = getSimulator();
|
||||||
|
this.web3.setProvider(this.sim.provider(this.simOptions));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Test.prototype.getAccounts = function(cb) {
|
||||||
|
this.web3.eth.getAccounts(function(err, accounts) {
|
||||||
|
cb(err, accounts);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
Test.prototype.deployAll = function(contractsConfig, cb) {
|
||||||
|
var self = this;
|
||||||
|
if (!this.alreadyWarned) {
|
||||||
|
this.alreadyWarned = true;
|
||||||
|
console.warn('This test API is deprecated, please use the new one INSERT LINK'); // TODO add link
|
||||||
|
}
|
||||||
|
|
||||||
|
async.waterfall([
|
||||||
|
function getConfig(callback) {
|
||||||
|
let _versions_default = self.engine.config.contractsConfig.versions;
|
||||||
|
self.engine.config.contractsConfig = {contracts: contractsConfig, versions: _versions_default};
|
||||||
|
callback();
|
||||||
|
},
|
||||||
|
function startServices(callback) {
|
||||||
|
//{abiType: 'contracts', embarkJS: false}
|
||||||
|
self.engine.startService("libraryManager");
|
||||||
|
self.engine.startService("codeRunner");
|
||||||
|
self.engine.startService("web3", {
|
||||||
|
web3: self.web3
|
||||||
|
});
|
||||||
|
self.engine.startService("deployment", {
|
||||||
|
trackContracts: false
|
||||||
|
});
|
||||||
|
self.engine.startService("codeGenerator");
|
||||||
|
callback();
|
||||||
|
},
|
||||||
|
function deploy(callback) {
|
||||||
|
self.engine.events.on('code-generator-ready', function () {
|
||||||
|
self.engine.events.request('code-contracts-vanila', function(vanillaABI) {
|
||||||
|
callback(null, vanillaABI);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
self.engine.deployManager.gasLimit = 6000000;
|
||||||
|
self.engine.contractsManager.gasLimit = 6000000;
|
||||||
|
self.engine.deployManager.fatalErrors = true;
|
||||||
|
self.engine.deployManager.deployOnlyOnConfig = true;
|
||||||
|
self.engine.deployManager.deployContracts(function(err, _result) {
|
||||||
|
if (err) {
|
||||||
|
callback(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
], function(err, result) {
|
||||||
|
if (err) {
|
||||||
|
console.log(__('terminating due to error'));
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
// 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];
|
||||||
|
self.engine.events.request('runcode:eval', result);
|
||||||
|
//cb();
|
||||||
|
cb(accounts);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = Test;
|
|
@ -2,8 +2,7 @@ const async = require('async');
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const Mocha = require('mocha');
|
const Mocha = require('mocha');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const Test = require('./test.js');
|
const Test = require('./test');
|
||||||
const utils = require('../utils/utils.js');
|
|
||||||
|
|
||||||
function getFilesFromDir(filePath, cb) {
|
function getFilesFromDir(filePath, cb) {
|
||||||
fs.readdir(filePath, (err, files) => {
|
fs.readdir(filePath, (err, files) => {
|
||||||
|
@ -49,24 +48,20 @@ module.exports = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function setupGlobalNamespace(next) {
|
function setupGlobalNamespace(next) {
|
||||||
// ---------------- Deprecated code ------------------------------------------------------------
|
|
||||||
global.assert = require('assert');
|
global.assert = require('assert');
|
||||||
|
|
||||||
global.config = function(config) {
|
// TODO put default config
|
||||||
configOptions = utils.recursiveMerge(configOptions, config);
|
const test = new Test();
|
||||||
};
|
global.embark = test;
|
||||||
// TODO: check how to pass the options
|
global.config = test.config.bind(test);
|
||||||
//global.EmbarkSpec = new Test(options);
|
|
||||||
|
|
||||||
// TODO: this global here might not be necessary at all
|
// TODO: this global here might not be necessary at all
|
||||||
global.EmbarkSpec = new Test({});
|
global.web3 = global.embark.web3;
|
||||||
global.web3 = global.EmbarkSpec.web3;
|
|
||||||
|
|
||||||
global.contract = function(describeName, callback) {
|
global.contract = function(describeName, callback) {
|
||||||
return Mocha.describe(describeName, callback);
|
return Mocha.describe(describeName, callback);
|
||||||
};
|
};
|
||||||
next();
|
next();
|
||||||
// ---------------- Deprecated code ------------------------------------------------------------
|
|
||||||
}
|
}
|
||||||
], (err) => {
|
], (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
|
@ -1,116 +1,61 @@
|
||||||
var async = require('async');
|
const Engine = require('../core/engine.js');
|
||||||
//require("../utils/debug_util.js")(__filename, async);
|
const TestLogger = require('./test_logger.js');
|
||||||
var Web3 = require('web3');
|
const Web3 = require('web3');
|
||||||
var Engine = require('../core/engine.js');
|
const utils = require('../utils/utils');
|
||||||
var TestLogger = require('./test_logger.js');
|
|
||||||
|
|
||||||
var getSimulator = function() {
|
function getSimulator() {
|
||||||
try {
|
try {
|
||||||
var sim = require('ethereumjs-testrpc');
|
return require('ganache-cli');
|
||||||
return sim;
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
const moreInfo = 'For more information see https://github.com/trufflesuite/ganache-cli';
|
||||||
if (e.code === 'MODULE_NOT_FOUND') {
|
if (e.code === 'MODULE_NOT_FOUND') {
|
||||||
console.log(__('Simulator not found; Please install it with "%s"', 'npm install ethereumjs-testrpc --save'));
|
console.error(__('Simulator not found; Please install it with "%s"', 'npm install ganache-cli --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 "%s"', 'npm install ethereumjs-testrpc@2.0 --save'));
|
console.error(moreInfo);
|
||||||
console.log('For more information see https://github.com/ethereumjs/testrpc');
|
throw e;
|
||||||
// TODO: should throw exception instead
|
|
||||||
return process.exit();
|
|
||||||
}
|
}
|
||||||
console.log("==============");
|
console.error("==============");
|
||||||
console.log(__("Tried to load testrpc but an error occurred. This is a problem with testrpc"));
|
console.error(__("Tried to load Ganache CLI (testrpc), but an error occurred. This is a problem with Ganache CLI"));
|
||||||
console.log(__('IMPORTANT: if you using a NodeJS version older than 6.9.1 then you need to install an older version of testrpc "%s". Alternatively install node 6.9.1 and the testrpc 3.0', 'npm install ethereumjs-testrpc@2.0 --save'));
|
console.error(moreInfo);
|
||||||
console.log("==============");
|
console.error("==============");
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
var Test = function(options) {
|
class Test {
|
||||||
this.options = options || {};
|
constructor(options) {
|
||||||
this.simOptions = this.options.simulatorOptions || {};
|
this.options = options || {};
|
||||||
|
this.simOptions = this.options.simulatorOptions || {};
|
||||||
this.engine = new Engine({
|
this.web3 = new Web3();
|
||||||
env: this.options.env || 'test',
|
if (this.simOptions.node) {
|
||||||
// TODO: confi will need to detect if this is a obj
|
this.web3.setProvider(new this.web3.providers.HttpProvider(this.simOptions.node));
|
||||||
embarkConfig: this.options.embarkConfig || 'embark.json',
|
} else {
|
||||||
interceptLogs: false
|
this.sim = getSimulator();
|
||||||
});
|
this.web3.setProvider(this.sim.provider(this.simOptions));
|
||||||
|
|
||||||
this.engine.init({
|
|
||||||
logger: new TestLogger({logLevel: 'debug'})
|
|
||||||
});
|
|
||||||
|
|
||||||
this.web3 = new Web3();
|
|
||||||
|
|
||||||
if (this.simOptions.node) {
|
|
||||||
this.web3.setProvider(new this.web3.providers.HttpProvider(this.simOptions.node));
|
|
||||||
} else {
|
|
||||||
this.sim = getSimulator();
|
|
||||||
this.web3.setProvider(this.sim.provider(this.simOptions));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Test.prototype.getAccounts = function(cb) {
|
|
||||||
this.web3.eth.getAccounts(function(err, accounts) {
|
|
||||||
cb(err, accounts);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
Test.prototype.deployAll = function(contractsConfig, cb) {
|
|
||||||
var self = this;
|
|
||||||
|
|
||||||
async.waterfall([
|
|
||||||
function getConfig(callback) {
|
|
||||||
let _versions_default = self.engine.config.contractsConfig.versions;
|
|
||||||
self.engine.config.contractsConfig = {contracts: contractsConfig, versions: _versions_default};
|
|
||||||
callback();
|
|
||||||
},
|
|
||||||
function startServices(callback) {
|
|
||||||
//{abiType: 'contracts', embarkJS: false}
|
|
||||||
self.engine.startService("libraryManager");
|
|
||||||
self.engine.startService("codeRunner");
|
|
||||||
self.engine.startService("web3", {
|
|
||||||
web3: self.web3
|
|
||||||
});
|
|
||||||
self.engine.startService("deployment", {
|
|
||||||
trackContracts: false
|
|
||||||
});
|
|
||||||
self.engine.startService("codeGenerator");
|
|
||||||
callback();
|
|
||||||
},
|
|
||||||
function deploy(callback) {
|
|
||||||
self.engine.events.on('code-generator-ready', function () {
|
|
||||||
self.engine.events.request('code-contracts-vanila', function(vanillaABI) {
|
|
||||||
callback(null, vanillaABI);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
self.engine.deployManager.gasLimit = 6000000;
|
|
||||||
self.engine.contractsManager.gasLimit = 6000000;
|
|
||||||
self.engine.deployManager.fatalErrors = true;
|
|
||||||
self.engine.deployManager.deployOnlyOnConfig = true;
|
|
||||||
self.engine.events.request('deploy:contracts', function(err) {
|
|
||||||
if (err) {
|
|
||||||
callback(err);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
], function(err, result) {
|
|
||||||
if (err) {
|
|
||||||
console.log(__('terminating due to error'));
|
|
||||||
process.exit(1);
|
|
||||||
}
|
}
|
||||||
// this should be part of the waterfall and not just something done at the
|
}
|
||||||
// end
|
|
||||||
self.web3.eth.getAccounts(function(err, accounts) {
|
config(options) {
|
||||||
if (err) {
|
this.options = utils.recursiveMerge(this.options, options);
|
||||||
throw new Error(err);
|
this.simOptions = this.options.simulatorOptions || {};
|
||||||
}
|
|
||||||
self.web3.eth.defaultAccount = accounts[0];
|
this.engine = new Engine({
|
||||||
self.engine.events.request('runcode:eval', result);
|
env: this.options.env || 'test',
|
||||||
//cb();
|
// TODO: confi will need to detect if this is a obj
|
||||||
cb(accounts);
|
embarkConfig: this.options.embarkConfig || 'embark.json',
|
||||||
|
interceptLogs: false
|
||||||
});
|
});
|
||||||
});
|
|
||||||
};
|
this.engine.init({
|
||||||
|
logger: new TestLogger({logLevel: 'debug'})
|
||||||
|
});
|
||||||
|
|
||||||
|
if (this.simOptions.node) {
|
||||||
|
this.web3.setProvider(new this.web3.providers.HttpProvider(this.simOptions.node));
|
||||||
|
} else {
|
||||||
|
this.sim = getSimulator();
|
||||||
|
this.web3.setProvider(this.sim.provider(this.simOptions));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = Test;
|
module.exports = Test;
|
||||||
|
|
|
@ -40,12 +40,12 @@
|
||||||
"ejs": "^2.5.8",
|
"ejs": "^2.5.8",
|
||||||
"eth-ens-namehash": "^2.0.8",
|
"eth-ens-namehash": "^2.0.8",
|
||||||
"eth-lib": "^0.2.8",
|
"eth-lib": "^0.2.8",
|
||||||
"ethereumjs-testrpc": "^6.0.3",
|
|
||||||
"ethereumjs-wallet": "^0.6.0",
|
"ethereumjs-wallet": "^0.6.0",
|
||||||
"file-loader": "^1.1.5",
|
"file-loader": "^1.1.5",
|
||||||
"finalhandler": "^1.1.1",
|
"finalhandler": "^1.1.1",
|
||||||
"follow-redirects": "^1.2.4",
|
"follow-redirects": "^1.2.4",
|
||||||
"fs-extra": "^2.0.0",
|
"fs-extra": "^2.0.0",
|
||||||
|
"ganache-cli": "^6.1.0",
|
||||||
"globule": "^1.1.0",
|
"globule": "^1.1.0",
|
||||||
"hard-source-webpack-plugin": "^0.6.6",
|
"hard-source-webpack-plugin": "^0.6.6",
|
||||||
"http-shutdown": "^1.2.0",
|
"http-shutdown": "^1.2.0",
|
||||||
|
|
Loading…
Reference in New Issue