aboutsummaryrefslogtreecommitdiffstats
path: root/RPCTests/modules
diff options
context:
space:
mode:
authorDimitry <winsvega@mail.ru>2017-01-28 00:31:19 +0800
committerDimitry <winsvega@mail.ru>2017-01-28 00:31:19 +0800
commitea7e06b2970a01cd11b3a062425f5c5cafc19ee7 (patch)
tree82f0dad0a0c0c37591e8c8d542710b8d909f086d /RPCTests/modules
parentbc8ad7422d32a940bab194173083a684adcc2706 (diff)
downloadtangerine-tests-ea7e06b2970a01cd11b3a062425f5c5cafc19ee7.tar
tangerine-tests-ea7e06b2970a01cd11b3a062425f5c5cafc19ee7.tar.gz
tangerine-tests-ea7e06b2970a01cd11b3a062425f5c5cafc19ee7.tar.bz2
tangerine-tests-ea7e06b2970a01cd11b3a062425f5c5cafc19ee7.tar.lz
tangerine-tests-ea7e06b2970a01cd11b3a062425f5c5cafc19ee7.tar.xz
tangerine-tests-ea7e06b2970a01cd11b3a062425f5c5cafc19ee7.tar.zst
tangerine-tests-ea7e06b2970a01cd11b3a062425f5c5cafc19ee7.zip
rpc tests on js
Diffstat (limited to 'RPCTests/modules')
-rw-r--r--RPCTests/modules/ethconsole.js97
m---------RPCTests/modules/ethereum-console0
-rw-r--r--RPCTests/modules/startnode.js27
-rw-r--r--RPCTests/modules/testutils.js69
-rw-r--r--RPCTests/modules/utils.js35
5 files changed, 193 insertions, 35 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
+
diff --git a/RPCTests/modules/ethereum-console b/RPCTests/modules/ethereum-console
new file mode 160000
+Subproject 4dbc626aab094b10d859c78059285138774da70
diff --git a/RPCTests/modules/startnode.js b/RPCTests/modules/startnode.js
deleted file mode 100644
index f0877b065..000000000
--- a/RPCTests/modules/startnode.js
+++ /dev/null
@@ -1,27 +0,0 @@
-function startNode (nodeExec, dataDir, genesisPath, listeningPort)
-{
- var spawn = require('child_process').spawn
- var options = [
- '--private', 'privatechain',
- '-d', dataDir,
- '--config', genesisPath,
- '--ipcpath', dataDir + '/geth.ipc',
- '--ipc',
- '--listen', listeningPort,
- '--test'
- ]
- console.log('starting node')
- console.log(nodeExec + ' ' + options.join(' '))
- var node = spawn(nodeExec, options)
- node.stdout.on('data', (data) => {
- console.log(`stdout: ${data}`)
- })
- node.stderr.on('data', (data) => {
- console.log(`stderr: ${data}`)
- })
- node.on('close', (code) => {
- console.log(`child process exited with code ${code}`)
- })
-}
-
-module.exports = startNode
diff --git a/RPCTests/modules/testutils.js b/RPCTests/modules/testutils.js
new file mode 100644
index 000000000..7128c6972
--- /dev/null
+++ b/RPCTests/modules/testutils.js
@@ -0,0 +1,69 @@
+const fs = require('fs');
+var utils = require('./utils.js');
+var tests = {};
+var testCount = 0;
+
+module.exports = {
+
+generateCustomGenesis: function generateCustomGenesis(path, originalPath, accountName, finished)
+{
+ var onFileRead = function (err, data) {};
+ fs.readFile(originalPath, 'utf8', (err, data) => { onFileRead (err,data) });
+
+ onFileRead = function (err, data)
+ {
+ if (err)
+ throw err;
+
+ data = data.replace("[ADDRESS]", accountName);
+ fs.writeFile(path, data, (err) => {
+ if (err)
+ throw err;
+ finished();
+ });
+ }
+},
+
+readTestsInFolder: function readTestsInFolder(path)
+{
+ var res = utils.listFiles(path);
+ res.forEach(function(file) {
+ var testn = file.indexOf("test");
+ var slashn = file.indexOf("_");
+ if (testn != -1 && slashn != -1)
+ {
+ testNumber = parseInt(file.substring(testn + 4, slashn));
+ var noden = file.indexOf("node");
+ var slashn = file.indexOf("_", slashn+1);
+ var tmpFile = file.indexOf("~");
+ if (noden != -1 && slashn != -1 && tmpFile == -1)
+ {
+ if (tests[testNumber])
+ console.log("Error: dublicate test found " + file);
+ else
+ {
+ var testObject = {};
+ testObject.file = file;
+ testObject.node = file.substring(noden + 4, slashn);
+ tests[testNumber] = testObject;
+ testCount++;
+ }
+ }
+ }
+ });
+},
+
+getTestCount: function getTestCount()
+{
+ return testCount;
+},
+
+getTestNumber: function getTestNumber(n)
+{
+ if(n < testCount);
+ return tests[n];
+}
+
+
+}//modules
+
diff --git a/RPCTests/modules/utils.js b/RPCTests/modules/utils.js
index 763c9894e..24e9bd811 100644
--- a/RPCTests/modules/utils.js
+++ b/RPCTests/modules/utils.js
@@ -1,7 +1,5 @@
const fs = require('fs');
-function sleep(ms) {
- return new Promise(resolve => setTimeout(resolve, ms));
- }
+var debug = true;
module.exports = {
@@ -9,14 +7,20 @@ module.exports = {
return new Promise(resolve => setTimeout(resolve, ms));
},
+ setDebug: function setDebug(value) { debug = value; },
+
+ getDebug: function getDebug() { return debug; },
- mkdir: function mkdir(path, callback, arg) {
+ cLog: function cLog(value) { if (debug) console.log(value); },
+
+ testLog: function testLog(value) { console.log(value); },
+
+ mkdir: function mkdir(path) {
try {
fs.mkdirSync(path);
} catch(e) {
if ( e.code != 'EEXIST' ) throw e;
}
- callback(arg);
},
rmdir: function rmdir(path) {
@@ -33,12 +37,27 @@ module.exports = {
}
},
- readFile: function readFile(path, callback) {
- fs.readFile(path, 'utf8', (err, data) => { callback (err, data) });
+ readFile: function readFile(path, callback, cb) {
+ fs.readFile(path, 'utf8', (err, data) => { callback (err, data, cb) });
},
writeFile: function writeFile(path, data) {
fs.writeFile(path, data, (err) => { if (err) throw err;});
+ },
+
+ listFiles: function listFiles(dir) {
+
+ var results = [];
+ fs.readdirSync(dir).forEach(function(file) {
+ file = dir+'/'+file;
+ var stat = fs.statSync(file);
+
+ if (stat && stat.isDirectory()) {
+ results = results.concat(listFiles(file))
+ } else results.push(file);
+ });
+
+ return results;
}
-}
+} //exports