aboutsummaryrefslogtreecommitdiffstats
path: root/RPCTests/modules/ethconsole.js
diff options
context:
space:
mode:
Diffstat (limited to 'RPCTests/modules/ethconsole.js')
-rw-r--r--RPCTests/modules/ethconsole.js97
1 files changed, 97 insertions, 0 deletions
diff --git a/RPCTests/modules/ethconsole.js b/RPCTests/modules/ethconsole.js
new file mode 100644
index 000000000..d3ee707bb
--- /dev/null
+++ b/RPCTests/modules/ethconsole.js
@@ -0,0 +1,97 @@
+const fs = require('fs');
+var lastResponse;
+var nodes = {};
+
+module.exports = {
+
+startNode: function startNode (nodeExec, dataDir, genesisPath, listeningPort, finished)
+{
+ var utils = require('./utils.js');
+ var spawn = require('child_process').spawn
+ var options = [
+ '--private', 'privatechain',
+ '-d', dataDir,
+ '--config', genesisPath,
+ '--ipcpath', dataDir + '/geth.ipc',
+ '--ipc',
+ '--listen', listeningPort,
+ '--test'
+ ]
+ utils.cLog('starting node')
+ utils.cLog(nodeExec + ' ' + options.join(' '))
+ var node = spawn(nodeExec, options)
+ node.stdout.on('data', (data) => {
+ utils.cLog(`stdout: ${data}`)
+ })
+ node.stderr.on('data', (data) => {
+ utils.cLog(`stderr: ${data}`)
+ })
+ node.on('close', (code) => {
+ utils.cLog(`child process exited with code ${code}`)
+ })
+
+ nodes[dataDir] = node;
+ utils.sleep(6000).then(() => {
+ utils.cLog("Node Started");
+ finished();
+ });
+},
+
+stopNode: function stopNode(dataDir, finished)
+{
+ nodes[dataDir].kill();
+ var utils = require('./utils.js');
+ utils.sleep(1000).then(() => {
+ finished();
+ });
+},
+
+
+runScriptOnNode: function runScriptOnNode(dataDir, jsScript, args, finished)
+{
+ var utils = require('./utils.js');
+ var ipcPath = dataDir + '/geth.ipc';
+
+ var Web3 = require('./ethereum-console/node_modules/web3');
+ var web3admin = require('./ethereum-console/web3Admin.js');
+ var net = require('net');
+
+ utils.cLog("Connecting to node at " + ipcPath);
+ var web3 = new Web3(new Web3.providers.IpcProvider(ipcPath, net));
+ web3admin.extend(web3);
+ global.web3 = web3;
+
+ var onScriptCallback = function (err, data)
+ {
+ utils.cLog(data);
+ lastResponse = data;
+ finished();
+ }
+ global.callback = onScriptCallback;
+ global.args = args;
+
+ var vm = require('vm');
+ utils.cLog("Executing " + jsScript + " ...");
+ fs.readFile(jsScript, 'utf8', function (err, data)
+ {
+ if (err)
+ {
+ utils.cLog(err);
+ finished();
+ }
+ else
+ {
+ var script = new vm.Script(data);
+ - script.runInThisContext();
+ }
+ });
+},
+
+
+getLastResponse: function getLastResponse()
+{
+ return lastResponse;
+}
+
+}//exports
+