fix tests

This commit is contained in:
Iuri Matias 2017-02-06 06:42:58 -05:00
parent 4e026fb6e7
commit e8db6dc8a0
11 changed files with 44 additions and 39 deletions

0
demo/app/images/.gitkeep Normal file
View File

View File

@ -2,15 +2,12 @@
"contracts": ["app/contracts/**"], "contracts": ["app/contracts/**"],
"app": { "app": {
"css/app.css": ["app/css/**"], "css/app.css": ["app/css/**"],
"images/": ["app/images/**"],
"js/app.js": ["embark.js", "app/js/_vendor/jquery.min.js", "app/js/_vendor/bootstrap.min.js", "app/js/**"], "js/app.js": ["embark.js", "app/js/_vendor/jquery.min.js", "app/js/_vendor/bootstrap.min.js", "app/js/**"],
"index.html": "app/index.html" "index.html": "app/index.html"
}, },
"buildDir": "dist/", "buildDir": "dist/",
"config": "config/", "config": "config/",
"plugins": { "plugins": {
"embark-pipelinefiles": {},
"embark-pipelinefiles2": {},
"embark-babel": {},
"embark-contracts": {}
} }
} }

View File

@ -11,6 +11,6 @@
"homepage": "", "homepage": "",
"devDependencies": { "devDependencies": {
"embark": "^2.2.1", "embark": "^2.2.1",
"mocha": "^3.2.0" "mocha": "^2.2.5"
} }
} }

View File

@ -3,8 +3,8 @@ var Plugins = require('./plugins.js');
var ABIGenerator = function(options) { var ABIGenerator = function(options) {
this.blockchainConfig = options.blockchainConfig || {}; this.blockchainConfig = options.blockchainConfig || {};
this.contractsManager = options.contractsManager; this.contractsManager = options.contractsManager;
this.rpcHost = options.blockchainConfig.rpcHost; this.rpcHost = options.blockchainConfig && options.blockchainConfig.rpcHost;
this.rpcPort = options.blockchainConfig.rpcPort; this.rpcPort = options.blockchainConfig && options.blockchainConfig.rpcPort;
this.plugins = options.plugins || new Plugins({}); this.plugins = options.plugins || new Plugins({});
}; };

View File

@ -49,7 +49,6 @@ Compiler.prototype.compile_solidity = function(contractFiles) {
for (var i = 0; i < contractFiles.length; i++){ for (var i = 0; i < contractFiles.length; i++){
// TODO: this depends on the config // TODO: this depends on the config
var filename = contractFiles[i].filename.replace('app/contracts/',''); var filename = contractFiles[i].filename.replace('app/contracts/','');
console.log("normal compile " + filename);
input[filename] = contractFiles[i].content.toString(); input[filename] = contractFiles[i].content.toString();
} }

View File

@ -21,10 +21,14 @@ var Config = function(options) {
}; };
Config.prototype.loadConfigFiles = function(options) { Config.prototype.loadConfigFiles = function(options) {
var interceptLogs = options.interceptLogs;
if (options.interceptLogs === undefined) {
interceptLogs = true;
}
this.embarkConfig = JSON.parse(fs.readFileSync(options.embarkConfig)); this.embarkConfig = JSON.parse(fs.readFileSync(options.embarkConfig));
this.embarkConfig.plugins = this.embarkConfig.plugins || {}; this.embarkConfig.plugins = this.embarkConfig.plugins || {};
this.plugins = new Plugins({plugins: this.embarkConfig.plugins, logger: this.logger}); this.plugins = new Plugins({plugins: this.embarkConfig.plugins, logger: this.logger, interceptLogs: interceptLogs});
this.plugins.loadPlugins(); this.plugins.loadPlugins();
this.loadPipelineConfigFile(); this.loadPipelineConfigFile();
@ -66,7 +70,6 @@ Config.prototype.loadContractsConfigFile = function() {
var envContractsConfig = configObject[this.env]; var envContractsConfig = configObject[this.env];
var mergedConfig = merge.recursive(defaultContractsConfig, envContractsConfig); var mergedConfig = merge.recursive(defaultContractsConfig, envContractsConfig);
console.log(JSON.stringify(mergedConfig));
this.contractsConfig = mergedConfig; this.contractsConfig = mergedConfig;
}; };

View File

@ -78,7 +78,7 @@ ContractsManager.prototype.build = function(done) {
contract.functionHashes = compiledContract.functionHashes; contract.functionHashes = compiledContract.functionHashes;
contract.abiDefinition = compiledContract.abiDefinition; contract.abiDefinition = compiledContract.abiDefinition;
contract.gas = (contractConfig && contractConfig.gas) || self.contractsConfig.gas; contract.gas = (contractConfig && contractConfig.gas) || self.contractsConfig.gas || 'auto';
adjustGas(contract); adjustGas(contract);
contract.gasPrice = contract.gasPrice || self.contractsConfig.gasPrice; contract.gasPrice = contract.gasPrice || self.contractsConfig.gasPrice;

View File

@ -33,7 +33,6 @@ Pipeline.prototype.build = function(abi) {
pipelinePlugins.forEach(function(plugin) { pipelinePlugins.forEach(function(plugin) {
try { try {
if (file.options && file.options.skipPipeline) { if (file.options && file.options.skipPipeline) {
console.log("skipping");
return; return;
} }
file.content = plugin.runPipeline({targetFile: file.filename, source: file.content}); file.content = plugin.runPipeline({targetFile: file.filename, source: file.content});

View File

@ -9,6 +9,7 @@ var Plugin = function(options) {
this.pluginModule = options.pluginModule; this.pluginModule = options.pluginModule;
this.pluginPath = options.pluginPath; this.pluginPath = options.pluginPath;
this.pluginConfig = options.pluginConfig; this.pluginConfig = options.pluginConfig;
this.shouldInterceptLogs = options.interceptLogs;
this.clientWeb3Providers = []; this.clientWeb3Providers = [];
this.contractsGenerators = []; this.contractsGenerators = [];
this.pipeline = []; this.pipeline = [];
@ -22,8 +23,10 @@ var Plugin = function(options) {
}; };
Plugin.prototype.loadPlugin = function() { Plugin.prototype.loadPlugin = function() {
this.interceptLogs(this.pluginModule); if (this.shouldInterceptLogs) {
(this.pluginModule.call(this, this)); this.interceptLogs(this.pluginModule);
}
(this.pluginModule.call(this, this));
}; };
Plugin.prototype.loadPluginFile = function(filename) { Plugin.prototype.loadPluginFile = function(filename) {
@ -36,7 +39,8 @@ Plugin.prototype.pathToFile = function(filename) {
Plugin.prototype.interceptLogs = function(context) { Plugin.prototype.interceptLogs = function(context) {
var self = this; var self = this;
context.console = console; // TODO: this is a bit nasty, figure out a better way
context.console = context.console || console;
context.console.error = function(txt) { context.console.error = function(txt) {
// TODO: logger should support an array instead of a single argument // TODO: logger should support an array instead of a single argument
//self.logger.error.apply(self.logger, arguments); //self.logger.error.apply(self.logger, arguments);

View File

@ -3,6 +3,7 @@ var path = require('path');
var Plugins = function(options) { var Plugins = function(options) {
this.pluginList = options.plugins || []; this.pluginList = options.plugins || [];
this.interceptLogs = options.interceptLogs;
this.plugins = []; this.plugins = [];
// TODO: need backup 'NullLogger' // TODO: need backup 'NullLogger'
this.logger = options.logger; this.logger = options.logger;
@ -28,7 +29,7 @@ Plugins.prototype.loadPlugin = function(pluginName, pluginConfig) {
var pluginPath = path.join(process.env.PWD, 'node_modules', pluginName); var pluginPath = path.join(process.env.PWD, 'node_modules', pluginName);
var plugin = require(pluginPath); var plugin = require(pluginPath);
var pluginWrapper = new Plugin({name: pluginName, pluginModule: plugin, pluginConfig: pluginConfig, logger: this.logger, pluginPath: pluginPath}); var pluginWrapper = new Plugin({name: pluginName, pluginModule: plugin, pluginConfig: pluginConfig, logger: this.logger, pluginPath: pluginPath, interceptLogs: this.interceptLogs});
pluginWrapper.loadPlugin(); pluginWrapper.loadPlugin();
this.plugins.push(pluginWrapper); this.plugins.push(pluginWrapper);
}; };

View File

@ -7,23 +7,27 @@ var TestLogger = require('./test_logger.js');
var Config = require('./config.js'); var Config = require('./config.js');
var ABIGenerator = require('./abi.js'); var ABIGenerator = require('./abi.js');
// TODO: load config file
// TODO: include plugins
var Test = function(options) { var Test = function(options) {
//try {
this.sim = require('ethereumjs-testrpc');
//} catch(e) {
// this.sim = false;
//}
//if (this.sim === false) { try {
// console.log('Simulator not found; Please install it with "npm install -g ethereumjs-testrpc'); this.sim = require('ethereumjs-testrpc');
// console.log('For more information see https://github.com/ethereumjs/testrpc'); } catch (e) {
// exit(); 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');
exit();
} else {
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 e;
}
}
this.web3 = new Web3(); this.web3 = new Web3();
this.web3.setProvider(this.sim.provider(options)); this.web3.setProvider(this.sim.provider());
}; };
Test.prototype.deployAll = function(contractsConfig, cb) { Test.prototype.deployAll = function(contractsConfig, cb) {
@ -33,21 +37,20 @@ Test.prototype.deployAll = function(contractsConfig, cb) {
async.waterfall([ async.waterfall([
function getConfig(callback) { function getConfig(callback) {
var config = new Config({env: 'test', logger: logger}); var config = new Config({env: 'test', logger: logger});
config.loadConfigFiles({embarkConfig: 'embark.json'}); config.loadConfigFiles({embarkConfig: 'embark.json', interceptLogs: false});
config.contractsConfig = {contracts: contractsConfig};
callback(null, config); callback(null, config);
}, },
function buildContracts(callback) { function buildContracts(config, callback) {
//var config = new Config({env: 'test'});
//config.contractsFiles = config.loadFiles(["app/contracts/**"]);
config.contractsConfig = {contracts: contractsConfig} ;
var contractsManager = new ContractsManager({ var contractsManager = new ContractsManager({
contractFiles: config.contractsFiles, contractFiles: config.contractsFiles,
contractsConfig: config.contractsConfig, contractsConfig: config.contractsConfig,
logger: logger, logger: logger,
plugins: config.plugins plugins: config.plugins
}); });
contractsManager.build(callback); contractsManager.build(function() {
callback(null, contractsManager);
});
}, },
function deployContracts(contractsManager, callback) { function deployContracts(contractsManager, callback) {
var deploy = new Deploy({ var deploy = new Deploy({
@ -76,10 +79,9 @@ Test.prototype.deployAll = function(contractsConfig, cb) {
} }
var web3 = self.web3; var web3 = self.web3;
web3.eth.defaultAccount = accounts[0]; web3.eth.defaultAccount = accounts[0];
console.log("hello!");
// TODO: replace evals with separate process so it's isolated and with // TODO: replace evals with separate process so it's isolated and with
// a callback // a callback
//eval(result); // jshint ignore:line eval(result); // jshint ignore:line
cb(); cb();
}); });
}); });