Merge pull request #264 from toadkicker/eventing

integration testing fixes
This commit is contained in:
Iuri Matias 2017-03-30 20:01:55 -04:00 committed by GitHub
commit f5cfcae3dd
6 changed files with 218 additions and 210 deletions

View File

@ -3,11 +3,12 @@ let colors = require('colors');
let shelljs = require('shelljs');
let promptly = require('promptly');
let path = require('path');
let Embark = require('../lib/index');
const Embark = require('../lib/index');
let embark = new Embark;
class Cmd {
constructor() {
program.version(Embark.version);
program.version(embark.version);
}
process(args) {
@ -56,11 +57,11 @@ class Cmd {
err.retry();
} else {
//slightly different assignment of name since it comes from child prompt
Embark.generateTemplate('boilerplate', './', inputvalue);
embark.generateTemplate('boilerplate', './', inputvalue);
}
});
} else {
Embark.generateTemplate('boilerplate', './', name);
embark.generateTemplate('boilerplate', './', name);
}
});
@ -71,7 +72,7 @@ class Cmd {
.command('demo')
.description('create a working dapp with a SimpleStorage contract')
.action(function () {
Embark.generateTemplate('demo', './', 'embark_demo');
embark.generateTemplate('demo', './', 'embark_demo');
});
}
@ -80,7 +81,7 @@ class Cmd {
.command('build [environment]')
.description('deploy and build dapp at dist/ (default: development)')
.action(function (env, options) {
Embark.build({env: env || 'development'});
embark.build({env: env || 'development'});
});
}
@ -94,7 +95,7 @@ class Cmd {
.option('--no-color', 'no colors in case it\'s needed for compatbility purposes')
.description('run dapp (default: development)')
.action(function (env, options) {
Embark.run({
embark.run({
env: env || 'development',
serverPort: options.port,
serverHost: options.host,
@ -110,11 +111,11 @@ class Cmd {
.option('-c, --client [client]', 'Use a specific ethereum client or simulator (supported: geth, parity, ethersim, testrpc')
.description('run blockchain server (default: development)')
.action(function (env, options) {
Embark.initConfig(env || 'development', {
embark.initConfig(env || 'development', {
embarkConfig: 'embark.json',
interceptLogs: false
});
Embark.blockchain(env || 'development', options.client || 'geth');
embark.blockchain(env || 'development', options.client || 'geth');
});
}
@ -126,11 +127,11 @@ class Cmd {
.option('-p, --port [port]', 'port to run the rpc simulator (default: 8000)')
.option('-h, --host [host]', 'host to run the rpc simulator (default: localhost)')
.action(function (env, options) {
Embark.initConfig(env || 'development', {
embark.initConfig(env || 'development', {
embarkConfig: 'embark.json',
interceptLogs: false
});
Embark.simulator({port: options.port, host: options.host});
embark.simulator({port: options.port, host: options.host});
});
}
@ -149,10 +150,10 @@ class Cmd {
.description('upload your dapp to a decentralized storage. possible options: ipfs, swarm (e.g embark upload swarm)')
.action(function (platform, env, options) {
// TODO: get env in cmd line as well
Embark.initConfig(env || 'development', {
embark.initConfig(env || 'development', {
embarkConfig: 'embark.json', interceptLogs: false
});
Embark.upload(platform);
embark.upload(platform);
});
}

View File

@ -7,7 +7,7 @@ let GethCommands = require('./geth_commands.js');
let BlockchainClient = function(blockchainConfig, client, env) {
if (client === 'geth') {
return new Blockchain({blockchainConfig: blockchainConfig, client: GethCommands, env: env});
return new Blockchain({blockchainConfig: blockchainConfig, client: new GethCommands(), env: env});
} else {
throw new Error('unknown client');
}
@ -42,7 +42,7 @@ class Blockchain {
};
}
static runCommand(cmd) {
runCommand(cmd) {
console.log(("running: " + cmd.underline).green);
return shelljs.exec(cmd);
}

View File

@ -3,8 +3,8 @@ let async = require('async');
// TODO: make all of this async
class GethCommands {
constructor(options) {
this.config = options.config;
this.env = options.env || 'development';
this.config = options && options.hasOwnProperty('config') ? options.config : {};
this.env = options && options.hasOwnProperty('env') ? options.env : 'development';
this.name = "Go-Ethereum (https://github.com/ethereum/go-ethereum)";
this.geth_bin = this.config.geth_bin || "geth";
}
@ -141,7 +141,12 @@ class GethCommands {
callback(null, '--rpcapi "' + rpc_api.join(',') + '"');
},
function accountToUnlock(callback) {
let accountAddress = config.account.address || address;
let accountAddress = "";
if(config.hasOwnProperty('address') && config.account.hasOwnProperty('address')) {
accountAddress = config.account.address;
} else {
accountAddress = address;
}
if (accountAddress) {
return callback(null, "--unlock=" + accountAddress);
}

View File

@ -11,7 +11,6 @@ class Plugins extends EventEmitter {
//TODO: put an observer on this.plugins and call loadPlugin when a new item is added
this.config = {};
const loadPlugins = this.load;
for (let opt in options) {
if (options.hasOwnProperty(opt)) {
this.config[opt] = options[opt];
@ -44,10 +43,18 @@ class Plugins extends EventEmitter {
}
}
loadPlugins () {
return this.load();
}
listPlugins() {
return this.config.plugins.join(', ');
}
getPluginsFor(pluginType, plugins) {
return getPluginsFor(pluginType, plugins);
}
}
module.exports = Plugins;

View File

@ -4,52 +4,61 @@ let async = require('async');
let colors = require('colors');
let Engine = require('./core/engine.js');
let IPFS = require('./upload/ipfs.js');
let Swarm = require('./upload/swarm.js');
let EventEmitter = require('events').EventEmitter;
let Config = require('./core/config');
/**
* Initialize a new `Embark` instance.
*
* @return {Embark}
* @api public
*/
let version = require('../package.json').version;
const EventEmitter = require('events').EventEmitter;
class Embark extends EventEmitter {
class Embark {
constructor (options) {
this.version = require('../package.json').version;
super();
this.version = version;
this.options = options || {};
}
this.env = options.environment || options.env || "development";
initConfig(env, options) {
let Events = require('./core/events.js');
let Logger = require('./core/logger.js');
let Config = require('./core/config.js');
this.config = new Config({env: this.env, logger: this.logger, events: this.events});
this.events = new Events();
this.logger = new Logger({logLevel: 'debug'});
this.config = new Config({env: env, logger: this.logger, events: this.events});
this.config.loadConfigFiles(options);
this.plugins = this.config.plugins;
}
this.blockchain = function (env, client) {
return require('./cmds/blockchain/blockchain.js')(Embark.prototype.config.blockchainConfig, client, env).run();
};
blockchain(env, client) {
return require('./cmds/blockchain/blockchain.js')(this.config.blockchainConfig, client, env).run();
}
this.simulator = function (options) {
simulator(options) {
let Simulator = require('./cmds/simulator.js');
let simulator = new Simulator({blockchainConfig: Embark.prototype.config.blockchainConfig});
let simulator = new Simulator({blockchainConfig: this.config.blockchainConfig});
simulator.run(options);
};
}
this.generateTemplate = function (templateName, destinationFolder, name) {
generateTemplate(templateName, destinationFolder, name) {
let TemplateGenerator = require('./cmds/template_generator.js');
let templateGenerator = new TemplateGenerator(templateName);
templateGenerator.generate(destinationFolder, name);
};
}
this.run = function (options) {
run(options) {
let Dashboard = require('./dashboard/dashboard.js');
let Engine = require('./core/engine');
let env = options.env;
let engine = new Engine({
env: options.env,
embarkConfig: options.embarkConfig || 'embark.json'
});
engine.init();
if (!options.useDashboard) {
@ -71,12 +80,12 @@ class Embark {
env: engine.env
});
dashboard.start(function () {
Embark.on('abi-vanila', function (abi) {
engine.events.on('abi-vanila', function (abi) {
dashboard.console.runCode(abi);
});
engine.logger.info('dashboard start');
Embark.on('servicesState', function (servicesState) {
engine.events.on('servicesState', function (servicesState) {
dashboard.monitor.availableServices(servicesState);
});
@ -96,7 +105,7 @@ class Embark {
engine.startService("deployment");
engine.startService("ipfs");
Embark.on('check:backOnline:Ethereum', function () {
engine.events.on('check:backOnline:Ethereum', function () {
engine.logger.info('Ethereum node detected..');
engine.config.reloadConfig();
engine.deployManager.deployContracts(function () {
@ -126,10 +135,9 @@ class Embark {
engine.events.emit('firstDeploymentDone');
}
});
};
}
this.build = function (options) {
let Engine = require('./core/engine');
build(options) {
let engine = new Engine({
env: options.env,
@ -166,42 +174,27 @@ class Embark {
// needed due to child processes
process.exit();
});
};
}
this.initTests = function () {
initTests(options) {
let Test = require('./core/test.js');
return new Test(options);
};
}
// TODO: should deploy if it hasn't already
this.upload = function (platform) {
upload(platform) {
if (platform === 'ipfs') {
let ipfs = new IPFS({
buildDir: 'dist/',
plugins: Embark.prototype.plugins,
storageConfig: Embark.prototype.config.storageConfig
});
let ipfs = new IPFS({buildDir: 'dist/', plugins: this.plugins, storageConfig: this.config.storageConfig});
ipfs.deploy();
} else if (platform === 'swarm') {
let swarm = new Swarm({
buildDir: 'dist/',
plugins: Embark.prototype.plugins,
storageConfig: Embark.prototype.config.storageConfig
});
let swarm = new Swarm({buildDir: 'dist/', plugins: this.plugins, storageConfig: this.config.storageConfig});
swarm.deploy();
} else {
console.log(("unknown platform: " + platform).red);
console.log('try "embark upload ipfs" or "embark upload swarm"'.green);
}
};
if (!(this instanceof Embark)) {
return new Embark();
}
return this;
}
}
Embark.prototype = Object.create(EventEmitter.prototype);
}
module.exports = Embark;

View File

@ -11,7 +11,7 @@ describe('embark.Blockchain', function () {
//let client = new Client();
describe('with empty config', function () {
it('should have a default config', function () {
it('should have a default config', function (done) {
let config = {
networkType: 'custom',
genesisBlock: false,
@ -35,11 +35,12 @@ describe('embark.Blockchain', function () {
let blockchain = new Blockchain(config, 'geth');
assert.deepEqual(blockchain.config, config);
done();
});
});
describe('with config', function () {
it('should take config params', function () {
it('should take config params', function (done) {
let config = {
networkType: 'livenet',
genesisBlock: 'foo/bar/genesis.json',
@ -63,6 +64,7 @@ describe('embark.Blockchain', function () {
let blockchain = new Blockchain(config, 'geth');
assert.deepEqual(blockchain.config, config);
done();
});
});