Skip to content

Commit 846980a

Browse files
authored
Merge pull request #386 from embark-framework/bug_fix/test-rpc-not-installed
check if testrpc is installed and warn if not
2 parents 7ebaa7a + 4a9ff1f commit 846980a

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/cmds/simulator.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,20 @@ let shelljs = require('shelljs');
33
class Simulator {
44
constructor(options) {
55
this.blockchainConfig = options.blockchainConfig;
6+
this.logger = options.logger;
67
}
78

89
run(options) {
910
let cmds = [];
1011

12+
const testrpc = shelljs.which('testrpc');
13+
const ganache = shelljs.which('ganache-cli');
14+
if (!testrpc && !ganache) {
15+
this.logger.warn('Ganache CLI (TestRPC) is not installed on your machine');
16+
this.logger.info('You can install it by running: npm -g install ganache-cli');
17+
process.exit();
18+
}
19+
1120
cmds.push("-p " + (this.blockchainConfig.rpcPort || options.port || 8545));
1221
cmds.push("-h " + (this.blockchainConfig.rpcHost || options.host || 'localhost'));
1322
cmds.push("-a " + (options.numAccounts || 10));
@@ -26,7 +35,8 @@ class Simulator {
2635
cmds.push("-b \"" + (simulatorBlocktime) +"\"");
2736
}
2837

29-
shelljs.exec('testrpc ' + cmds.join(' '), {async : true});
38+
const program = ganache ? 'ganache-cli' : 'testrpc';
39+
shelljs.exec(`${program} ${cmds.join(' ')}`, {async : true});
3040
}
3141
}
3242

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class Embark {
5757
simulator(options) {
5858
this.context = options.context || [constants.contexts.simulator, constants.contexts.blockchain];
5959
let Simulator = require('./cmds/simulator.js');
60-
let simulator = new Simulator({blockchainConfig: this.config.blockchainConfig});
60+
let simulator = new Simulator({blockchainConfig: this.config.blockchainConfig, logger: this.logger});
6161
simulator.run(options);
6262
}
6363

0 commit comments

Comments
 (0)