diff options
-rw-r--r-- | RPCTests/main.js | 127 | ||||
-rw-r--r-- | RPCTests/modules/ethconsole.js | 97 | ||||
-rw-r--r-- | RPCTests/modules/testutils.js | 78 | ||||
-rw-r--r-- | RPCTests/modules/utils.js | 85 | ||||
-rw-r--r-- | RPCTests/modules/web3Admin.js | 320 | ||||
-rw-r--r-- | RPCTests/package.json | 29 | ||||
-rw-r--r-- | RPCTests/scripts/genesis.json | 34 | ||||
-rw-r--r-- | RPCTests/scripts/getLastBlock.js | 1 | ||||
-rw-r--r-- | RPCTests/scripts/getNodeInfo.js | 1 | ||||
-rw-r--r-- | RPCTests/scripts/testNewAccount.js | 12 | ||||
-rw-r--r-- | RPCTests/scripts/tests/AddPeer/step00_node02_AddPeer.js | 26 | ||||
-rw-r--r-- | RPCTests/scripts/tests/AddPeer/step01_node01_getPeerCount.js.js | 12 | ||||
-rw-r--r-- | RPCTests/scripts/tests/MineBlocks/step00_node01_mineBlocks.js | 32 | ||||
-rw-r--r-- | RPCTests/scripts/tests/MineBlocks/step01_node02_getBlockHash.js | 14 | ||||
-rw-r--r-- | RPCTests/scripts/tests/MineBlocks2/step00_node02_mineBlocks.js | 31 | ||||
-rw-r--r-- | RPCTests/scripts/tests/MineBlocks2/step01_node01_getBlockHash.js | 13 |
16 files changed, 912 insertions, 0 deletions
diff --git a/RPCTests/main.js b/RPCTests/main.js new file mode 100644 index 000000000..fce4327d2 --- /dev/null +++ b/RPCTests/main.js @@ -0,0 +1,127 @@ +//requires npm +//requires installed node v6 +//requires ethereum eth path on input + +var async = require("async"); +var utils = require('./modules/utils.js'); +var testutils = require('./modules/testutils.js'); +var ethconsole = require('./modules/ethconsole.js'); + +var ethpath = process.argv[2]; +var testdir = __dirname + "/dynamic"; +var workdir = __dirname; + +var dynamic = {}; + +function cb(){} +function main() +{ +if (!ethpath || !utils.fileExists(ethpath)) +{ + utils.cLog("Executable '" + ethpath + "' not found!"); + utils.cLog("Please, set eth path. Usage: node main.js <ethpath>"); + return; +} + +testutils.readTestsInFolder(workdir + "/scripts/tests"); +async.series([ +function(cb) { + utils.setDebug(false); + ethconsole.startNode(ethpath, testdir + "/ethnode1", testdir + "/genesis.json", 30305, cb); +}, +function(cb) { + prepareDynamicVars(cb); +}, +function(cb) { + ethconsole.stopNode(testdir + "/ethnode1", cb); +}, +function(cb) { + ethconsole.startNode(ethpath, testdir + "/ethnode1", testdir + "/genesis.json", 30305, cb); + dynamic["node1_port"] = "30305"; +}, +function(cb) { + ethconsole.startNode(ethpath, testdir + "/ethnode2", testdir + "/genesis.json", 30306, cb); + dynamic["node2_port"] = "30306"; +}, +function(cb) { + runAllTests(cb); +}, +function(cb) { + ethconsole.stopNode(testdir + "/ethnode1", cb); + ethconsole.stopNode(testdir + "/ethnode2", cb); +} +], function() { + utils.rmdir(testdir); } +) +}//main + + + +function prepareDynamicVars(finished) +{ + async.series([ + function(cb) { + ethconsole.runScriptOnNode(testdir + "/ethnode1", workdir + "/scripts/testNewAccount.js", {}, cb); + }, + function(cb) { + dynamic["account"] = ethconsole.getLastResponse(); + utils.mkdir(testdir); + testutils.generateCustomGenesis(testdir + '/genesis.json', workdir + "/scripts/genesis.json", dynamic["account"], cb); + }, + function(cb) { + ethconsole.runScriptOnNode(testdir + "/ethnode1", workdir + "/scripts/getNodeInfo.js", {}, cb); + }, + function(cb) { + dynamic["node1_ID"] = ethconsole.getLastResponse().id; + cb(); + } + ], function() { finished(); }) +} + +function runAllTests(finished) +{ + var currentTest = -1; + var updateDynamic = function(){}; + + function nextTest() + { + currentTest++; + if (currentTest == testutils.getTestCount()) + finished(); + else + { + var testObject = testutils.getTestNumber(currentTest); + var nodepath; + if (testObject.node == '01') + nodepath = testdir + "/ethnode1"; + if (testObject.node == '02') + nodepath = testdir + "/ethnode2"; + + ethconsole.runScriptOnNode(nodepath, testObject.file, dynamic, updateDynamic); + } + } + + updateDynamic = function updateDynamic() + { + async.series([ + function(cb) { + ethconsole.runScriptOnNode(testdir + "/ethnode1", workdir + "/scripts/getLastBlock.js", {}, cb); + }, + function(cb) { + dynamic["node1_lastblock"] = ethconsole.getLastResponse(); + cb(); + }, + function(cb) { + ethconsole.runScriptOnNode(testdir + "/ethnode2", workdir + "/scripts/getLastBlock.js", {}, cb); + }, + function(cb) { + dynamic["node2_lastblock"] = ethconsole.getLastResponse(); + cb(); + } + ], function() { nextTest(); }); + } + nextTest(); +} + +main(); + diff --git a/RPCTests/modules/ethconsole.js b/RPCTests/modules/ethconsole.js new file mode 100644 index 000000000..de6cae5af --- /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('web3'); + var web3admin = require('./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/testutils.js b/RPCTests/modules/testutils.js new file mode 100644 index 000000000..54cd64525 --- /dev/null +++ b/RPCTests/modules/testutils.js @@ -0,0 +1,78 @@ +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 testNumber = 0; + var folders = utils.listFolders(path); + folders.forEach(function(folder) { + + var res = utils.listFiles(folder); + res.forEach(function(file) { + + var testn = file.indexOf("step"); + 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++; + testNumber++; + } + } + } + }); + }); + + //console.log(tests); +}, + +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 new file mode 100644 index 000000000..0d0f2b02f --- /dev/null +++ b/RPCTests/modules/utils.js @@ -0,0 +1,85 @@ +const fs = require('fs'); +var debug = true; + +module.exports = { + + sleep: function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + }, + + setDebug: function setDebug(value) { debug = value; }, + + getDebug: function getDebug() { return debug; }, + + 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; + } + }, + + rmdir: function rmdir(path) { + if( fs.existsSync(path) ) { + fs.readdirSync(path).forEach(function(file,index){ + var curPath = path + "/" + file; + if(fs.lstatSync(curPath).isDirectory()) { // recurse + rmdir(curPath); + } else { // delete file + fs.unlinkSync(curPath); + } + }); + fs.rmdirSync(path); + } + }, + + fileExists: function fileExists(path) + { + if(fs.existsSync(path)) + return true; + return false; + }, + + 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, recursive = false) { + + var results = []; + fs.readdirSync(dir).forEach(function(file) { + file = dir+'/'+file; + var stat = fs.statSync(file); + + if (stat && stat.isDirectory() && recursive) { + results = results.concat(listFiles(file, recursive)) + } else results.push(file); + }); + + return results; + }, + + listFolders: function listFolders(dir) { + + var results = []; + fs.readdirSync(dir).forEach(function(file) { + file = dir+'/'+file; + var stat = fs.statSync(file); + + if (stat && stat.isDirectory()) { + results.push(file); + } + }); + + return results; + } + +} //exports diff --git a/RPCTests/modules/web3Admin.js b/RPCTests/modules/web3Admin.js new file mode 100644 index 000000000..819a87f30 --- /dev/null +++ b/RPCTests/modules/web3Admin.js @@ -0,0 +1,320 @@ +module.exports = { + extend: function(web3) { + + // ADMIN + web3._extend({ + property: 'admin', + methods: + [ + new web3._extend.Method({ + name: 'addPeer', + call: 'admin_addPeer', + params: 1, + inputFormatter: [web3._extend.utils.formatInputString], + outputFormatter: web3._extend.formatters.formatOutputBool + }), + new web3._extend.Method({ + name: 'exportChain', + call: 'admin_exportChain', + params: 1, + inputFormatter: [null], + outputFormatter: function(obj) { return obj; } + }), + new web3._extend.Method({ + name: 'importChain', + call: 'admin_importChain', + params: 1, + inputFormatter: [null], + outputFormatter: function(obj) { return obj; } + }), + new web3._extend.Method({ + name: 'verbosity', + call: 'admin_verbosity', + params: 1, + inputFormatter: [web3._extend.utils.formatInputInt], + outputFormatter: web3._extend.formatters.formatOutputBool + }), + new web3._extend.Method({ + name: 'setSolc', + call: 'admin_setSolc', + params: 1, + inputFormatter: [null], + outputFormatter: web3._extend.formatters.formatOutputString + }), + new web3._extend.Method({ + name: 'startRPC', + call: 'admin_startRPC', + params: 4, + inputFormatter: [null,web3._extend.utils.formatInputInteger,null,null], + outputFormatter: web3._extend.formatters.formatOutputBool + }), + new web3._extend.Method({ + name: 'stopRPC', + call: 'admin_stopRPC', + params: 0, + inputFormatter: [], + outputFormatter: web3._extend.formatters.formatOutputBool + }) + ], + properties: + [ + new web3._extend.Property({ + name: 'nodeInfo', + getter: 'admin_nodeInfo', + outputFormatter: web3._extend.formatters.formatOutputString + }), + new web3._extend.Property({ + name: 'peers', + getter: 'admin_peers', + outputFormatter: function(obj) { return obj; } + }), + new web3._extend.Property({ + name: 'datadir', + getter: 'admin_datadir', + outputFormatter: web3._extend.formatters.formatOutputString + }), + new web3._extend.Property({ + name: 'chainSyncStatus', + getter: 'admin_chainSyncStatus', + outputFormatter: function(obj) { return obj; } + }) + ] + }); + + // DEBUG + web3._extend({ + property: 'debug', + methods: + [ + new web3._extend.Method({ + name: 'printBlock', + call: 'debug_printBlock', + params: 1, + inputFormatter: [web3._extend.formatters.formatInputInt], + outputFormatter: web3._extend.formatters.formatOutputString + }), + new web3._extend.Method({ + name: 'getBlockRlp', + call: 'debug_getBlockRlp', + params: 1, + inputFormatter: [web3._extend.formatters.formatInputInt], + outputFormatter: web3._extend.formatters.formatOutputString + }), + new web3._extend.Method({ + name: 'setHead', + call: 'debug_setHead', + params: 1, + inputFormatter: [web3._extend.formatters.formatInputInt], + outputFormatter: web3._extend.formatters.formatOutputBool + }), + new web3._extend.Method({ + name: 'processBlock', + call: 'debug_processBlock', + params: 1, + inputFormatter: [web3._extend.formatters.formatInputInt], + outputFormatter: function(obj) { return obj; } + }), + new web3._extend.Method({ + name: 'seedHash', + call: 'debug_seedHash', + params: 1, + inputFormatter: [web3._extend.formatters.formatInputInt], + outputFormatter: web3._extend.formatters.formatOutputString + }), + new web3._extend.Method({ + name: 'dumpBlock', + call: 'debug_dumpBlock', + params: 1, + inputFormatter: [web3._extend.formatters.formatInputInt], + outputFormatter: function(obj) { return obj; } + }), + new web3._extend.Method({ + name: 'traceTransaction', + call: 'debug_traceTransaction', + inputFormatter: [null, null], + params: 2 + }), + new web3._extend.Method({ + name: 'storageRangeAt', + call: 'debug_storageRangeAt', + inputFormatter: [null, null, null, null, null], + params: 5 + }) + ], + properties: + [ + ] + }); + + // MINER + web3._extend({ + property: 'miner', + methods: + [ + new web3._extend.Method({ + name: 'start', + call: 'miner_start', + params: 1, + inputFormatter: [web3._extend.formatters.formatInputInt], + outputFormatter: web3._extend.formatters.formatOutputBool + }), + new web3._extend.Method({ + name: 'stop', + call: 'miner_stop', + params: 1, + inputFormatter: [web3._extend.formatters.formatInputInt], + outputFormatter: web3._extend.formatters.formatOutputBool + }), + new web3._extend.Method({ + name: 'setExtra', + call: 'miner_setExtra', + params: 1, + inputFormatter: [web3._extend.utils.formatInputString], + outputFormatter: web3._extend.formatters.formatOutputBool + }), + new web3._extend.Method({ + name: 'setGasPrice', + call: 'miner_setGasPrice', + params: 1, + inputFormatter: [web3._extend.utils.formatInputString], + outputFormatter: web3._extend.formatters.formatOutputBool + }), + new web3._extend.Method({ + name: 'startAutoDAG', + call: 'miner_startAutoDAG', + params: 0, + inputFormatter: [], + outputFormatter: web3._extend.formatters.formatOutputBool + }), + new web3._extend.Method({ + name: 'stopAutoDAG', + call: 'miner_stopAutoDAG', + params: 0, + inputFormatter: [], + outputFormatter: web3._extend.formatters.formatOutputBool + }), + new web3._extend.Method({ + name: 'makeDAG', + call: 'miner_makeDAG', + params: 1, + inputFormatter: [web3._extend.formatters.inputDefaultBlockNumberFormatter], + outputFormatter: web3._extend.formatters.formatOutputBool + }) + ], + properties: + [ + new web3._extend.Property({ + name: 'hashrate', + getter: 'miner_hashrate', + outputFormatter: web3._extend.utils.toDecimal + }) + ] + }); + + // NETWORK + web3._extend({ + property: 'network', + methods: + [ + new web3._extend.Method({ + name: 'addPeer', + call: 'net_addPeer', + params: 1, + inputFormatter: [web3._extend.utils.formatInputString], + outputFormatter: web3._extend.formatters.formatOutputBool + }), + new web3._extend.Method({ + name: 'getPeerCount', + call: 'net_peerCount', + params: 0, + inputFormatter: [], + outputFormatter: web3._extend.formatters.formatOutputString + }) + ], + properties: + [ + new web3._extend.Property({ + name: 'listening', + getter: 'net_listening', + outputFormatter: web3._extend.formatters.formatOutputBool + }), + new web3._extend.Property({ + name: 'peerCount', + getter: 'net_peerCount', + outputFormatter: web3._extend.utils.toDecimal + }), + new web3._extend.Property({ + name: 'peers', + getter: 'net_peers', + outputFormatter: function(obj) { return obj; } + }), + new web3._extend.Property({ + name: 'version', + getter: 'net_version', + outputFormatter: web3._extend.formatters.formatOutputString + }) + ] + }); + + // TX POOL + web3._extend({ + property: 'txpool', + methods: + [ + ], + properties: + [ + new web3._extend.Property({ + name: 'status', + getter: 'txpool_status', + outputFormatter: function(obj) { return obj; } + }) + ] + }); + + // TEST + web3._extend({ + property: 'test', + methods: + [ + new web3._extend.Method({ + name: 'setChainParams', + call: 'test_setChainParams', + params: 1, + outputFormatter: web3._extend.formatters.formatOutputBool + }), + new web3._extend.Method({ + name: 'mineBlocks', + call: 'test_mineBlocks', + params: 1, + inputFormatter: [web3._extend.utils.formatInputInt], + outputFormatter: web3._extend.formatters.formatOutputBool + }), + new web3._extend.Method({ + name: 'modifyTimestamp', + call: 'test_modifyTimestamp', + params: 1, + inputFormatter: [web3._extend.utils.formatInputInt], + outputFormatter: web3._extend.formatters.formatOutputBool + }), + new web3._extend.Method({ + name: 'addBlock', + call: 'test_addBlock', + params: 1, + inputFormatter: [web3._extend.utils.formatInputString], + outputFormatter: web3._extend.formatters.formatOutputBool + }), + new web3._extend.Method({ + name: 'rewindToBlock', + call: 'test_rewindToBlock', + params: 1, + inputFormatter: [web3._extend.utils.formatInputInt], + outputFormatter: web3._extend.formatters.formatOutputBool + }) + ], + properties: + [ + ] + }); + } +}; diff --git a/RPCTests/package.json b/RPCTests/package.json new file mode 100644 index 000000000..2e3283a2b --- /dev/null +++ b/RPCTests/package.json @@ -0,0 +1,29 @@ +{ + "name": "rpctests", + "version": "0.0.1", + "description": "Ethereum cpp client RPC tests", + "main": "./main.js", + "devDependencies": { + "web3": "^0.15.3", + "async": "^1.5" + }, + "scripts": { + + }, + "repository": { + + }, + "author": "cpp-ethereum team", + "license": "MIT", + "bugs": { + + }, + "homepage": "", + "standard": { + "ignore": [ + "node_modules/*", + "build/*", + "test/resources/*" + ] + } +} diff --git a/RPCTests/scripts/genesis.json b/RPCTests/scripts/genesis.json new file mode 100644 index 000000000..e4545e6d2 --- /dev/null +++ b/RPCTests/scripts/genesis.json @@ -0,0 +1,34 @@ +{ + "sealEngine": "NoProof", + "params": { + "accountStartNonce": "0x00", + "frontierCompatibilityModeLimit": "0xffffffff", + "maximumExtraDataSize": "0x0400", + "tieBreakingGas": false, + "minGasLimit": "125000", + "gasLimitBoundDivisor": "0x0400", + "minimumDifficulty": "0x020000", + "difficultyBoundDivisor": "0x0800", + "durationLimit": "0x08", + "blockReward": "0x14D1120D7B160000", + "registrar": "5e70c0bbcd5636e0f9f9316e9f8633feb64d4050", + "networkID" : "0x25" + }, + "genesis": { + "nonce": "0x000000000000002a", + "difficulty": "0x2000", + "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "author": "0x0000000000000000000000000000000000000000", + "timestamp": "0x00", + "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "extraData": "0x", + "gasLimit": "0x2fefd8" + }, + "accounts": { + "0000000000000000000000000000000000000001": { "wei": "1", "precompiled": { "name": "ecrecover", "linear": { "base": 3000, "word": 0 } } }, + "0000000000000000000000000000000000000002": { "wei": "1", "precompiled": { "name": "sha256", "linear": { "base": 60, "word": 12 } } }, + "0000000000000000000000000000000000000003": { "wei": "1", "precompiled": { "name": "ripemd160", "linear": { "base": 600, "word": 120 } } }, + "0000000000000000000000000000000000000004": { "wei": "1", "precompiled": { "name": "identity", "linear": { "base": 15, "word": 3 } } }, + "[ADDRESS]": { "wei": "100000000000000000000" } + } +} diff --git a/RPCTests/scripts/getLastBlock.js b/RPCTests/scripts/getLastBlock.js new file mode 100644 index 000000000..5ea2efafa --- /dev/null +++ b/RPCTests/scripts/getLastBlock.js @@ -0,0 +1 @@ +web3.eth.getBlock("latest", function(err, res){ callback(err, res); }) diff --git a/RPCTests/scripts/getNodeInfo.js b/RPCTests/scripts/getNodeInfo.js new file mode 100644 index 000000000..7452d9ca3 --- /dev/null +++ b/RPCTests/scripts/getNodeInfo.js @@ -0,0 +1 @@ +web3.admin.getNodeInfo(function(err,res){ callback(err, res); }) diff --git a/RPCTests/scripts/testNewAccount.js b/RPCTests/scripts/testNewAccount.js new file mode 100644 index 000000000..ae3224384 --- /dev/null +++ b/RPCTests/scripts/testNewAccount.js @@ -0,0 +1,12 @@ +process.stdout.write("TEST_newAccount "); +var onResult = {}; +web3.personal.newAccount("123", function(err,res){ onResult(err,res); }) + +onResult = function (err,res) +{ + if (res.length == 42) + console.log("OK"); + else + console.log("FAILED"); + callback(err, res); +} diff --git a/RPCTests/scripts/tests/AddPeer/step00_node02_AddPeer.js b/RPCTests/scripts/tests/AddPeer/step00_node02_AddPeer.js new file mode 100644 index 000000000..233648dc3 --- /dev/null +++ b/RPCTests/scripts/tests/AddPeer/step00_node02_AddPeer.js @@ -0,0 +1,26 @@ +process.stdout.write("TEST_addPeerOnNode2 "); +var onResult = {}; +web3.admin.addPeer("enode://" + args["node1_ID"] + "@127.0.0.1:" + args["node1_port"], function(err, res){ onResult(err, res); }) + +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); +} + +var onGetPeerCount = {}; +onResult = function (err,res) +{ + //wait for peer being added + sleep(1000).then(() => { + web3.net.getPeerCount(function(err, res){ onGetPeerCount(err, res); }) + }); +} + +onGetPeerCount = function (err, res) +{ + if (res == 1) + console.log("OK"); + else + console.log("FAILED"); + callback(err, res); +} + diff --git a/RPCTests/scripts/tests/AddPeer/step01_node01_getPeerCount.js.js b/RPCTests/scripts/tests/AddPeer/step01_node01_getPeerCount.js.js new file mode 100644 index 000000000..1f53480ff --- /dev/null +++ b/RPCTests/scripts/tests/AddPeer/step01_node01_getPeerCount.js.js @@ -0,0 +1,12 @@ +process.stdout.write("TEST_getPeerCountOnNode1 "); +var onResult = {}; +web3.net.getPeerCount(function(err, res){ onResult(err, res); }) +onResult = function (err,res) +{ + if (res == 1) + console.log("OK"); + else + console.log("FAILED"); + callback(err, res); +} + diff --git a/RPCTests/scripts/tests/MineBlocks/step00_node01_mineBlocks.js b/RPCTests/scripts/tests/MineBlocks/step00_node01_mineBlocks.js new file mode 100644 index 000000000..4abcdbd40 --- /dev/null +++ b/RPCTests/scripts/tests/MineBlocks/step00_node01_mineBlocks.js @@ -0,0 +1,32 @@ +process.stdout.write("TEST_mineBlockOnNode1 "); + +var latestBlock; +web3.eth.getBlockNumber(function(err, res){ onGetBlockNumber1(err, res); }) +onGetBlockNumber1 = function (err, res) +{ + latestBlock = res; + web3.test.mineBlocks(1, function(err, res){ onResult(err, res); }) +} + + +onResult = function (err,res) +{ + function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + } + + //wait for block being mined + sleep(1000).then(() => { + web3.eth.getBlockNumber(function(err, res){ onGetBlockNumber(err, res); }) + }); +} + +onGetBlockNumber = function (err, res) +{ + if (res == latestBlock + 1) + console.log("OK"); + else + console.log("FAILED"); + callback(err, res); +} + diff --git a/RPCTests/scripts/tests/MineBlocks/step01_node02_getBlockHash.js b/RPCTests/scripts/tests/MineBlocks/step01_node02_getBlockHash.js new file mode 100644 index 000000000..92be98acf --- /dev/null +++ b/RPCTests/scripts/tests/MineBlocks/step01_node02_getBlockHash.js @@ -0,0 +1,14 @@ +process.stdout.write("TEST_getBlockHashOnNode2 "); + +var onResult = {}; +web3.eth.getBlock("latest", function(err, res){ onResult(err, res); }) + +onResult = function (err,res) +{ + if (res.hash == args["node1_lastblock"].hash) + console.log("OK"); + else + console.log("FAILED"); + callback(err, res); +} + diff --git a/RPCTests/scripts/tests/MineBlocks2/step00_node02_mineBlocks.js b/RPCTests/scripts/tests/MineBlocks2/step00_node02_mineBlocks.js new file mode 100644 index 000000000..70936cc41 --- /dev/null +++ b/RPCTests/scripts/tests/MineBlocks2/step00_node02_mineBlocks.js @@ -0,0 +1,31 @@ +process.stdout.write("TEST_mineBlockOnNode2 "); + +var latestBlock; +web3.eth.getBlockNumber(function(err, res){ onGetBlockNumber1(err, res); }) +onGetBlockNumber1 = function (err, res) +{ + latestBlock = res; + web3.test.mineBlocks(1, function(err, res){ onResult(err, res); }) +} + + +onResult = function (err,res) +{ + function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + } + + //wait for block being mined and propagated + sleep(1000).then(() => { + web3.eth.getBlockNumber(function(err, res){ onGetBlockNumber(err, res); }) + }); +} + +onGetBlockNumber = function (err, res) +{ + if (res == latestBlock + 1) + console.log("OK"); + else + console.log("FAILED"); + callback(err, res); +} diff --git a/RPCTests/scripts/tests/MineBlocks2/step01_node01_getBlockHash.js b/RPCTests/scripts/tests/MineBlocks2/step01_node01_getBlockHash.js new file mode 100644 index 000000000..d3a3b0bbf --- /dev/null +++ b/RPCTests/scripts/tests/MineBlocks2/step01_node01_getBlockHash.js @@ -0,0 +1,13 @@ +process.stdout.write("TEST_getBlockHashOnNode1 "); + +var onResult = {}; +web3.eth.getBlock("latest", function(err, res){ onResult(err, res); }) + +onResult = function (err,res) +{ + if (res.hash == args["node2_lastblock"].hash) + console.log("OK"); + else + console.log("FAILED "); + callback(err, res); +} |