diff --git a/lib/cmd.js b/lib/cmd.js index 05bcd33a..b7dbf71d 100644 --- a/lib/cmd.js +++ b/lib/cmd.js @@ -103,13 +103,18 @@ Cmd.prototype.blockchain = function() { }; Cmd.prototype.simulator = function() { + var self = this; program - .command('simulator') + .command('simulator [environment]') .description('run a fast ethereum rpc simulator') .option('--testrpc', 'use testrpc as the rpc simulator [default]') - .action(function(options) { - //console.log('TestRPC not found; Please install it with "npm install -g ethereumjs-testrpc'); - exec('testrpc'); + .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) { + self.Embark.initConfig(env || 'development', { + embarkConfig: 'embark.json' + }); + self.Embark.simulator({port: options.port, host: options.host}); }); }; diff --git a/lib/index.js b/lib/index.js index 8cc7063b..86229ca7 100644 --- a/lib/index.js +++ b/lib/index.js @@ -25,6 +25,7 @@ var ServicesMonitor = require('./services.js'); var Console = require('./console.js'); var IPFS = require('./ipfs.js'); var Swarm = require('./swarm.js'); +var Simulator = require('./simulator.js'); var Embark = { @@ -337,6 +338,11 @@ var Embark = { } }, + simulator: function(options) { + var simulator = new Simulator({blockchainConfig: this.config.blockchainConfig}); + simulator.run(options); + } + }; module.exports = Embark; diff --git a/lib/simulator.js b/lib/simulator.js new file mode 100644 index 00000000..daf10bfc --- /dev/null +++ b/lib/simulator.js @@ -0,0 +1,17 @@ + +var Simulator = function(options) { + this.blockchainConfig = options.blockchainConfig; +}; + +Simulator.prototype.run = function(options) { + var cmds = []; + + cmds.push("-p " + (this.blockchainConfig.rpcPort || options.port || 8545)); + cmds.push("-h " + (this.blockchainConfig.rpcHost || options.host || 'localhost')); + cmds.push("-a " + (options.num || 10)); + + exec('testrpc ' + cmds.join(' ')); +}; + +module.exports = Simulator; +