diff --git a/lib/console.js b/lib/console.js index 973950a3..d0c7bc07 100644 --- a/lib/console.js +++ b/lib/console.js @@ -1,5 +1,5 @@ -var Web3 = require('web3'); var utils = require('./utils.js'); +var RunCode = require('./runCode.js'); var Console = function(options) { this.plugins = options.plugins; @@ -7,7 +7,7 @@ var Console = function(options) { }; Console.prototype.runCode = function(code) { - eval(code); // jshint ignore:line + RunCode.doEval(code); // jshint ignore:line }; Console.prototype.executeCmd = function(cmd, callback) { @@ -37,7 +37,7 @@ Console.prototype.executeCmd = function(cmd, callback) { } try { - var result = eval(cmd); // jshint ignore:line + var result = RunCode.doEval(cmd); return callback(result); } catch(e) { diff --git a/lib/deploy.js b/lib/deploy.js index 089d1c41..66de8604 100644 --- a/lib/deploy.js +++ b/lib/deploy.js @@ -1,7 +1,7 @@ var async = require('async'); var DeployTracker = require('./deploy_tracker.js'); var ABIGenerator = require('./abi.js'); -var web3; +var RunCode = require('./runCode.js'); var Deploy = function(options) { this.web3 = options.web3; @@ -76,17 +76,13 @@ Deploy.prototype.checkAndDeployContract = function(contract, params, callback) { self.deployTracker.save(); self.logger.contractsState(self.contractsManager.contractsState()); - // TODO: replace evals with separate process so it's isolated and with - // a callback if (contract.onDeploy !== undefined) { self.logger.info('executing onDeploy commands'); var abiGenerator = new ABIGenerator({contractsManager: self.contractsManager}); - web3 = self.web3; var abi = abiGenerator.generateContracts(false); - eval(abi); // jshint ignore:line - var cmds = contract.onDeploy.join(';\n'); - eval(cmds); // jshint ignore:line + + RunCode.doEval(abi + "\n" + cmds, self.web3); } callback(); diff --git a/lib/runCode.js b/lib/runCode.js new file mode 100644 index 00000000..7134b94a --- /dev/null +++ b/lib/runCode.js @@ -0,0 +1,18 @@ +var Web3 = require('web3'); +var web3; + +// ====================== +// the eval is used for evaluating some of the contact calls for different purposes +// this should be at least moved to a different process and scope +// for now it is defined here +// ====================== +function doEval(code, _web3) { + if (_web3) { + web3 = _web3; + } + return eval(code); // jshint ignore:line +} + +module.exports = { + doEval: doEval +}; diff --git a/lib/test.js b/lib/test.js index 9728b7b1..dac0bc1c 100644 --- a/lib/test.js +++ b/lib/test.js @@ -6,6 +6,7 @@ var Deploy = require('./deploy.js'); var TestLogger = require('./test_logger.js'); var Config = require('./config.js'); var ABIGenerator = require('./abi.js'); +var RunCode = require('./runCode.js'); var Test = function(_options) { var options = _options || {}; @@ -80,11 +81,8 @@ Test.prototype.deployAll = function(contractsConfig, cb) { if (err) { throw new Error(err); } - var web3 = self.web3; - web3.eth.defaultAccount = accounts[0]; - // TODO: replace evals with separate process so it's isolated and with - // a callback - eval(result); // jshint ignore:line + self.web3.eth.defaultAccount = accounts[0]; + RunCode.doEval(result, self.web3); // jshint ignore:line cb(); }); });