aboutsummaryrefslogtreecommitdiffstats
path: root/jsonrpc.isValidResponse.js
diff options
context:
space:
mode:
authorMarek Kotewicz <marek.kotewicz@gmail.com>2015-02-04 06:14:19 +0800
committerMarek Kotewicz <marek.kotewicz@gmail.com>2015-02-04 06:14:19 +0800
commitd9b422cfbc5959c1f476e32633a1aec432610b94 (patch)
treecfccda92c2335d95363419dd835ad29e31c48fb1 /jsonrpc.isValidResponse.js
parent46f47eaf3824b9eb9d6f0756d9023e1ac12ecf02 (diff)
downloaddexon-solidity-d9b422cfbc5959c1f476e32633a1aec432610b94.tar
dexon-solidity-d9b422cfbc5959c1f476e32633a1aec432610b94.tar.gz
dexon-solidity-d9b422cfbc5959c1f476e32633a1aec432610b94.tar.bz2
dexon-solidity-d9b422cfbc5959c1f476e32633a1aec432610b94.tar.lz
dexon-solidity-d9b422cfbc5959c1f476e32633a1aec432610b94.tar.xz
dexon-solidity-d9b422cfbc5959c1f476e32633a1aec432610b94.tar.zst
dexon-solidity-d9b422cfbc5959c1f476e32633a1aec432610b94.zip
Squashed 'libjsqrc/ethereumjs/' changes from f1a5cf9..a0cfa3c
a0cfa3c version upgrade e58e2f5 jsonrpc.js tests && jsonrpc response validation is more strict 45134de jsonrpc.js file && batch polling f3ce1f0 simplified polling && jsonrpc payload creation ddc1719 tests && fixes for utils methods fdcc1af clearing tests 4a54b8c version upgrade 0.0.12 git-subtree-dir: libjsqrc/ethereumjs git-subtree-split: a0cfa3ca21163f26f3f71a0e2ce0a1e617554c72
Diffstat (limited to 'jsonrpc.isValidResponse.js')
-rw-r--r--jsonrpc.isValidResponse.js128
1 files changed, 128 insertions, 0 deletions
diff --git a/jsonrpc.isValidResponse.js b/jsonrpc.isValidResponse.js
new file mode 100644
index 00000000..2fe20049
--- /dev/null
+++ b/jsonrpc.isValidResponse.js
@@ -0,0 +1,128 @@
+var assert = require('assert');
+var jsonrpc = require('../lib/jsonrpc');
+
+describe('jsonrpc', function () {
+ describe('isValidResponse', function () {
+ it('should validate basic jsonrpc response', function () {
+
+ // given
+ var response = {
+ jsonrpc: '2.0',
+ id: 1,
+ result: []
+ };
+
+ // when
+ var valid = jsonrpc.isValidResponse(response);
+
+ // then
+ assert.equal(valid, true);
+ });
+
+ it('should validate basic undefined response', function () {
+
+ // given
+ var response = undefined;
+
+ // when
+ var valid = jsonrpc.isValidResponse(response);
+
+ // then
+ assert.equal(valid, false);
+ });
+
+ it('should validate jsonrpc response without jsonrpc field', function () {
+
+ // given
+ var response = {
+ id: 1,
+ result: []
+ };
+
+ // when
+ var valid = jsonrpc.isValidResponse(response);
+
+ // then
+ assert.equal(valid, false);
+ });
+
+ it('should validate jsonrpc response with wrong jsonrpc version', function () {
+
+ // given
+ var response = {
+ jsonrpc: '1.0',
+ id: 1,
+ result: []
+ };
+
+ // when
+ var valid = jsonrpc.isValidResponse(response);
+
+ // then
+ assert.equal(valid, false);
+ });
+
+ it('should validate jsonrpc response without id number', function () {
+
+ // given
+ var response = {
+ jsonrpc: '2.0',
+ result: []
+ };
+
+ // when
+ var valid = jsonrpc.isValidResponse(response);
+
+ // then
+ assert.equal(valid, false);
+ });
+
+ it('should validate jsonrpc response with wrong id field', function () {
+
+ // given
+ var response = {
+ jsonrpc: '2.0',
+ id: 'x',
+ result: []
+ };
+
+ // when
+ var valid = jsonrpc.isValidResponse(response);
+
+ // then
+ assert.equal(valid, false);
+ });
+
+ it('should validate jsonrpc response without result field', function () {
+
+ // given
+ var response = {
+ jsonrpc: '2.0',
+ id: 1
+ };
+
+ // when
+ var valid = jsonrpc.isValidResponse(response);
+
+ // then
+ assert.equal(valid, false);
+ });
+
+ it('should validate jsonrpc response with result field === false', function () {
+
+ // given
+ var response = {
+ jsonrpc: '2.0',
+ id: 1,
+ result: false
+ };
+
+ // when
+ var valid = jsonrpc.isValidResponse(response);
+
+ // then
+ assert.equal(valid, true);
+ });
+
+ });
+});