diff options
author | Dimitry <winsvega@mail.ru> | 2017-01-28 00:31:19 +0800 |
---|---|---|
committer | Dimitry <winsvega@mail.ru> | 2017-01-28 00:31:19 +0800 |
commit | ea7e06b2970a01cd11b3a062425f5c5cafc19ee7 (patch) | |
tree | 82f0dad0a0c0c37591e8c8d542710b8d909f086d /RPCTests/scripts | |
parent | bc8ad7422d32a940bab194173083a684adcc2706 (diff) | |
download | dexon-tests-ea7e06b2970a01cd11b3a062425f5c5cafc19ee7.tar dexon-tests-ea7e06b2970a01cd11b3a062425f5c5cafc19ee7.tar.gz dexon-tests-ea7e06b2970a01cd11b3a062425f5c5cafc19ee7.tar.bz2 dexon-tests-ea7e06b2970a01cd11b3a062425f5c5cafc19ee7.tar.lz dexon-tests-ea7e06b2970a01cd11b3a062425f5c5cafc19ee7.tar.xz dexon-tests-ea7e06b2970a01cd11b3a062425f5c5cafc19ee7.tar.zst dexon-tests-ea7e06b2970a01cd11b3a062425f5c5cafc19ee7.zip |
rpc tests on js
Diffstat (limited to 'RPCTests/scripts')
-rw-r--r-- | RPCTests/scripts/addPeer.js | 1 | ||||
-rw-r--r-- | RPCTests/scripts/getLastBlock.js | 1 | ||||
-rw-r--r-- | RPCTests/scripts/getNewAccount.js | 3 | ||||
-rw-r--r-- | RPCTests/scripts/getNodeInfo.js | 1 | ||||
-rw-r--r-- | RPCTests/scripts/sleep.js | 4 | ||||
-rw-r--r-- | RPCTests/scripts/test00_node02_AddPeer.js | 26 | ||||
-rw-r--r-- | RPCTests/scripts/test01_node01_getPeerCount.js | 11 | ||||
-rw-r--r-- | RPCTests/scripts/test02_node01_mineBlocks.js | 31 | ||||
-rw-r--r-- | RPCTests/scripts/test03_node02_getBlockHash.js | 13 | ||||
-rw-r--r-- | RPCTests/scripts/test04_node02_mineBlocks.js | 31 | ||||
-rw-r--r-- | RPCTests/scripts/test05_node01_getBlockHash.js | 13 | ||||
-rw-r--r-- | RPCTests/scripts/testNewAccount.js | 12 |
12 files changed, 140 insertions, 7 deletions
diff --git a/RPCTests/scripts/addPeer.js b/RPCTests/scripts/addPeer.js new file mode 100644 index 000000000..3da731748 --- /dev/null +++ b/RPCTests/scripts/addPeer.js @@ -0,0 +1 @@ +web3.admin.addPeer("enode://" + args[0], function(err, res){ callback(err, res); }) 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/getNewAccount.js b/RPCTests/scripts/getNewAccount.js deleted file mode 100644 index eceacc23f..000000000 --- a/RPCTests/scripts/getNewAccount.js +++ /dev/null @@ -1,3 +0,0 @@ -sleep = require('./modules/sleep.js'); -var result; -web3.personal.newAccount("123", function(err,res){result = res; console.log(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/sleep.js b/RPCTests/scripts/sleep.js deleted file mode 100644 index 8308c93d3..000000000 --- a/RPCTests/scripts/sleep.js +++ /dev/null @@ -1,4 +0,0 @@ -function sleep(ms) { - return new Promise(resolve => setTimeout(resolve, ms)); -} -module.exports = sleep diff --git a/RPCTests/scripts/test00_node02_AddPeer.js b/RPCTests/scripts/test00_node02_AddPeer.js new file mode 100644 index 000000000..233648dc3 --- /dev/null +++ b/RPCTests/scripts/test00_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/test01_node01_getPeerCount.js b/RPCTests/scripts/test01_node01_getPeerCount.js new file mode 100644 index 000000000..155846dbf --- /dev/null +++ b/RPCTests/scripts/test01_node01_getPeerCount.js @@ -0,0 +1,11 @@ +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/test02_node01_mineBlocks.js b/RPCTests/scripts/test02_node01_mineBlocks.js new file mode 100644 index 000000000..14bc0bb63 --- /dev/null +++ b/RPCTests/scripts/test02_node01_mineBlocks.js @@ -0,0 +1,31 @@ +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/test03_node02_getBlockHash.js b/RPCTests/scripts/test03_node02_getBlockHash.js new file mode 100644 index 000000000..fc09f8423 --- /dev/null +++ b/RPCTests/scripts/test03_node02_getBlockHash.js @@ -0,0 +1,13 @@ +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/test04_node02_mineBlocks.js b/RPCTests/scripts/test04_node02_mineBlocks.js new file mode 100644 index 000000000..70936cc41 --- /dev/null +++ b/RPCTests/scripts/test04_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/test05_node01_getBlockHash.js b/RPCTests/scripts/test05_node01_getBlockHash.js new file mode 100644 index 000000000..d3a3b0bbf --- /dev/null +++ b/RPCTests/scripts/test05_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); +} 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); +} |