viz-js-lib 0.12.6 → 0.12.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api-frontend/app.js +890 -0
- package/api-frontend/index.html +41 -0
- package/api-frontend/jsonrpc-api-spec.json +1353 -0
- package/api-frontend/style.css +600 -0
- package/config.json +1 -1
- package/dist/statistics.html +1 -1
- package/dist/viz-tests.min.js +6 -272
- package/dist/viz-tests.min.js.gz +0 -0
- package/dist/viz.min.js +6 -6
- package/dist/viz.min.js.gz +0 -0
- package/lib/api/methods.js +23 -153
- package/package.json +6 -3
- package/test/api.test.js +11 -164
- package/test/api.ws.test.js +162 -0
- package/test/methods_by_version.js +27 -35
- package/test/types_test.js +2 -2
package/dist/viz.min.js.gz
CHANGED
|
Binary file
|
package/lib/api/methods.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
module.exports = [{
|
|
4
|
-
"api": "validator_api",
|
|
5
|
-
"method": "get_miner_queue"
|
|
6
|
-
}, {
|
|
7
4
|
"api": "validator_api",
|
|
8
5
|
"method": "get_validator_schedule"
|
|
9
6
|
}, {
|
|
@@ -73,89 +70,6 @@ module.exports = [{
|
|
|
73
70
|
"api": "operation_history",
|
|
74
71
|
"method": "get_transaction",
|
|
75
72
|
"params": ["trxId"]
|
|
76
|
-
}, {
|
|
77
|
-
"api": "tags",
|
|
78
|
-
"method": "get_trending_tags",
|
|
79
|
-
"params": ["afterTag", "limit"]
|
|
80
|
-
}, {
|
|
81
|
-
"api": "tags",
|
|
82
|
-
"method": "get_tags_used_by_author",
|
|
83
|
-
"params": ["author"]
|
|
84
|
-
}, {
|
|
85
|
-
"api": "tags",
|
|
86
|
-
"method": "get_discussions_by_payout",
|
|
87
|
-
"params": ["query"]
|
|
88
|
-
}, {
|
|
89
|
-
"api": "tags",
|
|
90
|
-
"method": "get_discussions_by_trending",
|
|
91
|
-
"params": ["query"]
|
|
92
|
-
}, {
|
|
93
|
-
"api": "tags",
|
|
94
|
-
"method": "get_discussions_by_created",
|
|
95
|
-
"params": ["query"]
|
|
96
|
-
}, {
|
|
97
|
-
"api": "tags",
|
|
98
|
-
"method": "get_discussions_by_active",
|
|
99
|
-
"params": ["query"]
|
|
100
|
-
}, {
|
|
101
|
-
"api": "tags",
|
|
102
|
-
"method": "get_discussions_by_cashout",
|
|
103
|
-
"params": ["query"]
|
|
104
|
-
}, {
|
|
105
|
-
"api": "tags",
|
|
106
|
-
"method": "get_discussions_by_votes",
|
|
107
|
-
"params": ["query"]
|
|
108
|
-
}, {
|
|
109
|
-
"api": "tags",
|
|
110
|
-
"method": "get_discussions_by_children",
|
|
111
|
-
"params": ["query"]
|
|
112
|
-
}, {
|
|
113
|
-
"api": "tags",
|
|
114
|
-
"method": "get_discussions_by_hot",
|
|
115
|
-
"params": ["query"]
|
|
116
|
-
}, {
|
|
117
|
-
"api": "tags",
|
|
118
|
-
"method": "get_discussions_by_feed",
|
|
119
|
-
"params": ["query"]
|
|
120
|
-
}, {
|
|
121
|
-
"api": "tags",
|
|
122
|
-
"method": "get_discussions_by_blog",
|
|
123
|
-
"params": ["query"]
|
|
124
|
-
}, {
|
|
125
|
-
"api": "tags",
|
|
126
|
-
"method": "get_discussions_by_contents",
|
|
127
|
-
"params": ["query"]
|
|
128
|
-
}, {
|
|
129
|
-
"api": "tags",
|
|
130
|
-
"method": "get_discussions_by_author_before_date",
|
|
131
|
-
"params": ["author", "startPermlink", "beforeDate", "limit"]
|
|
132
|
-
}, {
|
|
133
|
-
"api": "tags",
|
|
134
|
-
"method": "get_languages"
|
|
135
|
-
}, {
|
|
136
|
-
"api": "social_network",
|
|
137
|
-
"method": "get_replies_by_last_update",
|
|
138
|
-
"params": ["startAuthor", "startPermlink", "limit", "voteLimit"]
|
|
139
|
-
}, {
|
|
140
|
-
"api": "social_network",
|
|
141
|
-
"method": "get_content",
|
|
142
|
-
"params": ["author", "permlink", "voteLimit"]
|
|
143
|
-
}, {
|
|
144
|
-
"api": "social_network",
|
|
145
|
-
"method": "get_content_replies",
|
|
146
|
-
"params": ["parent", "parentPermlink", "voteLimit"]
|
|
147
|
-
}, {
|
|
148
|
-
"api": "social_network",
|
|
149
|
-
"method": "get_all_content_replies",
|
|
150
|
-
"params": ["parent", "parentPermlink", "voteLimit"]
|
|
151
|
-
}, {
|
|
152
|
-
"api": "social_network",
|
|
153
|
-
"method": "get_active_votes",
|
|
154
|
-
"params": ["author", "permlink", "voteLimit"]
|
|
155
|
-
}, {
|
|
156
|
-
"api": "social_network",
|
|
157
|
-
"method": "get_account_votes",
|
|
158
|
-
"params": ["voter", "from", "voteLimit"]
|
|
159
73
|
}, {
|
|
160
74
|
"api": "database_api",
|
|
161
75
|
"method": "get_block_header",
|
|
@@ -172,6 +86,10 @@ module.exports = [{
|
|
|
172
86
|
"api": "database_api",
|
|
173
87
|
"method": "get_irreversible_block",
|
|
174
88
|
"params": ["blockNum"]
|
|
89
|
+
}, {
|
|
90
|
+
"api": "database_api",
|
|
91
|
+
"method": "set_block_applied_callback",
|
|
92
|
+
"params": ["callback"]
|
|
175
93
|
}, {
|
|
176
94
|
"api": "database_api",
|
|
177
95
|
"method": "get_config"
|
|
@@ -189,19 +107,23 @@ module.exports = [{
|
|
|
189
107
|
"method": "get_next_scheduled_hardfork"
|
|
190
108
|
}, {
|
|
191
109
|
"api": "database_api",
|
|
192
|
-
"method": "
|
|
110
|
+
"method": "get_accounts",
|
|
111
|
+
"params": ["accountNames"]
|
|
193
112
|
}, {
|
|
194
113
|
"api": "database_api",
|
|
195
|
-
"method": "
|
|
196
|
-
"params": ["
|
|
114
|
+
"method": "lookup_account_names",
|
|
115
|
+
"params": ["accountNames"]
|
|
197
116
|
}, {
|
|
198
117
|
"api": "database_api",
|
|
199
|
-
"method": "
|
|
200
|
-
"params": ["
|
|
118
|
+
"method": "lookup_accounts",
|
|
119
|
+
"params": ["lowerBoundName", "limit"]
|
|
201
120
|
}, {
|
|
202
121
|
"api": "database_api",
|
|
203
|
-
"method": "
|
|
204
|
-
|
|
122
|
+
"method": "get_account_count"
|
|
123
|
+
}, {
|
|
124
|
+
"api": "database_api",
|
|
125
|
+
"method": "get_master_history",
|
|
126
|
+
"params": ["account"]
|
|
205
127
|
}, {
|
|
206
128
|
"api": "database_api",
|
|
207
129
|
"method": "get_recovery_request",
|
|
@@ -214,6 +136,14 @@ module.exports = [{
|
|
|
214
136
|
"api": "database_api",
|
|
215
137
|
"method": "get_withdraw_routes",
|
|
216
138
|
"params": ["account", "withdrawRouteType"]
|
|
139
|
+
}, {
|
|
140
|
+
"api": "database_api",
|
|
141
|
+
"method": "get_vesting_delegations",
|
|
142
|
+
"params": ["account", "from", "limit", "type"]
|
|
143
|
+
}, {
|
|
144
|
+
"api": "database_api",
|
|
145
|
+
"method": "get_expiring_vesting_delegations",
|
|
146
|
+
"params": ["account", "from", "limit"]
|
|
217
147
|
}, {
|
|
218
148
|
"api": "database_api",
|
|
219
149
|
"method": "get_transaction_hex",
|
|
@@ -234,33 +164,9 @@ module.exports = [{
|
|
|
234
164
|
"api": "database_api",
|
|
235
165
|
"method": "verify_account_authority",
|
|
236
166
|
"params": ["name", "signers"]
|
|
237
|
-
}, {
|
|
238
|
-
"api": "database_api",
|
|
239
|
-
"method": "get_accounts",
|
|
240
|
-
"params": ["accountNames"]
|
|
241
|
-
}, {
|
|
242
|
-
"api": "database_api",
|
|
243
|
-
"method": "lookup_account_names",
|
|
244
|
-
"params": ["accountNames"]
|
|
245
|
-
}, {
|
|
246
|
-
"api": "database_api",
|
|
247
|
-
"method": "lookup_accounts",
|
|
248
|
-
"params": ["lowerBoundName", "limit"]
|
|
249
|
-
}, {
|
|
250
|
-
"api": "database_api",
|
|
251
|
-
"method": "get_proposed_transaction",
|
|
252
|
-
"params": ["account"]
|
|
253
167
|
}, {
|
|
254
168
|
"api": "database_api",
|
|
255
169
|
"method": "get_database_info"
|
|
256
|
-
}, {
|
|
257
|
-
"api": "database_api",
|
|
258
|
-
"method": "get_vesting_delegations",
|
|
259
|
-
"params": ["account", "from", "limit", "type"]
|
|
260
|
-
}, {
|
|
261
|
-
"api": "database_api",
|
|
262
|
-
"method": "get_expiring_vesting_delegations",
|
|
263
|
-
"params": ["account", "from", "limit"]
|
|
264
170
|
}, {
|
|
265
171
|
"api": "database_api",
|
|
266
172
|
"method": "get_proposed_transactions",
|
|
@@ -277,42 +183,6 @@ module.exports = [{
|
|
|
277
183
|
"api": "database_api",
|
|
278
184
|
"method": "get_subaccounts_on_sale",
|
|
279
185
|
"params": ["from", "limit"]
|
|
280
|
-
}, {
|
|
281
|
-
"api": "follow",
|
|
282
|
-
"method": "get_followers",
|
|
283
|
-
"params": ["following", "startFollower", "followType", "limit"]
|
|
284
|
-
}, {
|
|
285
|
-
"api": "follow",
|
|
286
|
-
"method": "get_following",
|
|
287
|
-
"params": ["follower", "startFollowing", "followType", "limit"]
|
|
288
|
-
}, {
|
|
289
|
-
"api": "follow",
|
|
290
|
-
"method": "get_follow_count",
|
|
291
|
-
"params": ["account"]
|
|
292
|
-
}, {
|
|
293
|
-
"api": "follow",
|
|
294
|
-
"method": "get_feed_entries",
|
|
295
|
-
"params": ["account", "entryId", "limit"]
|
|
296
|
-
}, {
|
|
297
|
-
"api": "follow",
|
|
298
|
-
"method": "get_feed",
|
|
299
|
-
"params": ["account", "entryId", "limit"]
|
|
300
|
-
}, {
|
|
301
|
-
"api": "follow",
|
|
302
|
-
"method": "get_blog_entries",
|
|
303
|
-
"params": ["account", "entryId", "limit"]
|
|
304
|
-
}, {
|
|
305
|
-
"api": "follow",
|
|
306
|
-
"method": "get_blog",
|
|
307
|
-
"params": ["account", "entryId", "limit"]
|
|
308
|
-
}, {
|
|
309
|
-
"api": "follow",
|
|
310
|
-
"method": "get_reblogged_by",
|
|
311
|
-
"params": ["author", "permlink"]
|
|
312
|
-
}, {
|
|
313
|
-
"api": "follow",
|
|
314
|
-
"method": "get_blog_authors",
|
|
315
|
-
"params": ["blogAccount"]
|
|
316
186
|
}, {
|
|
317
187
|
"api": "account_by_key",
|
|
318
188
|
"method": "get_key_references",
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "viz-js-lib",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.7",
|
|
4
4
|
"description": "viz.js the JavaScript Library with API support for VIZ blockchain",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "mocha -t 20000 --require babel-polyfill --require babel-register",
|
|
8
|
+
"test-ci": "npm test -- --exclude test/broadcast.test.js --exclude test/comment.test.js --exclude test/api.ws.test.js",
|
|
9
|
+
"test-broadcast": "mocha -t 20000 --require babel-polyfill --require babel-register test/broadcast.test.js test/comment.test.js",
|
|
10
|
+
"test-ws": "mocha -t 30000 --require babel-polyfill --require babel-register test/api.ws.test.js",
|
|
8
11
|
"test-auth": "npm test -- --grep 'viz.auth'",
|
|
9
12
|
"build": "npm run build-browser && npm run build-node",
|
|
10
13
|
"build-browser": "rm -rf dist && NODE_ENV=production webpack && gzip -k -f ./dist/*.js && du -h ./dist/*",
|
|
@@ -36,7 +39,6 @@
|
|
|
36
39
|
},
|
|
37
40
|
"homepage": "https://github.com/VIZ-Blockchain/viz-js-lib#readme",
|
|
38
41
|
"dependencies": {
|
|
39
|
-
"babel-preset-env": "^1.7.0",
|
|
40
42
|
"bigi": "^1.4.2",
|
|
41
43
|
"bluebird": "^3.5.5",
|
|
42
44
|
"browserify-aes": "^1.0.6",
|
|
@@ -45,7 +47,6 @@
|
|
|
45
47
|
"bytebuffer": "^5.0.1",
|
|
46
48
|
"create-hash": "^1.1.2",
|
|
47
49
|
"create-hmac": "^1.1.4",
|
|
48
|
-
"cross-env": "^5.0.0",
|
|
49
50
|
"cross-fetch": "^3.0.0",
|
|
50
51
|
"debug": "^2.6.8",
|
|
51
52
|
"detect-node": "^2.0.3",
|
|
@@ -59,9 +60,11 @@
|
|
|
59
60
|
"babel-eslint": "^7.1.1",
|
|
60
61
|
"babel-loader": "^6.2.5",
|
|
61
62
|
"babel-polyfill": "^6.23.0",
|
|
63
|
+
"babel-preset-env": "^1.7.0",
|
|
62
64
|
"babel-preset-es2015": "^6.16.0",
|
|
63
65
|
"babel-preset-es2017": "^6.16.0",
|
|
64
66
|
"babel-register": "^6.14.0",
|
|
67
|
+
"cross-env": "^5.0.0",
|
|
65
68
|
"eslint": "^3.5.0",
|
|
66
69
|
"eslint-plugin-import": "^1.15.0",
|
|
67
70
|
"eslint-plugin-jsx-a11y": "^2.2.2",
|
package/test/api.test.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
require('babel-polyfill');
|
|
2
|
-
import Promise from 'bluebird';
|
|
3
2
|
import assert from 'assert';
|
|
4
|
-
import makeStub from 'mocha-make-stub'
|
|
5
3
|
import should from 'should';
|
|
6
4
|
|
|
7
5
|
import viz, { VIZ } from '../src/api/index';
|
|
8
6
|
import config from '../src/config';
|
|
9
|
-
import testPost from './test-post.json';
|
|
10
7
|
|
|
11
8
|
describe('viz.api:', function () {
|
|
12
9
|
this.timeout(30 * 1000);
|
|
@@ -16,19 +13,14 @@ describe('viz.api:', function () {
|
|
|
16
13
|
assert(!viz.ws, 'There was a connection on the singleton?');
|
|
17
14
|
assert(!new VIZ().ws, 'There was a connection on a new instance?');
|
|
18
15
|
});
|
|
19
|
-
|
|
20
|
-
it('opens a connection on demand', (done) => {
|
|
21
|
-
const s = new VIZ();
|
|
22
|
-
assert(!new VIZ().ws, 'There was a connection on a new instance?');
|
|
23
|
-
s.start();
|
|
24
|
-
process.nextTick(() => {
|
|
25
|
-
assert(s.ws, 'There was no connection?');
|
|
26
|
-
done();
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
16
|
});
|
|
30
17
|
|
|
31
18
|
describe('setWebSocket', () => {
|
|
19
|
+
const originalNode = config.get('websocket');
|
|
20
|
+
after(() => {
|
|
21
|
+
viz.setWebSocket(originalNode);
|
|
22
|
+
});
|
|
23
|
+
|
|
32
24
|
it('works', () => {
|
|
33
25
|
viz.setWebSocket('ws://localhost');
|
|
34
26
|
config.get('websocket').should.be.eql('ws://localhost');
|
|
@@ -39,36 +31,13 @@ describe('viz.api:', function () {
|
|
|
39
31
|
await viz.apiIdsP;
|
|
40
32
|
});
|
|
41
33
|
|
|
42
|
-
describe('
|
|
43
|
-
describe('getting viz\'s
|
|
44
|
-
it('works', async () => {
|
|
45
|
-
const followersCount = 1;
|
|
46
|
-
const result = await viz.getFollowersAsync('viz', 0, 'blog', followersCount);
|
|
47
|
-
assert(result, 'getFollowersAsync resoved to null?');
|
|
48
|
-
result.should.have.lengthOf(followersCount);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('the startFollower parameter has an impact on the result', async () => {
|
|
52
|
-
const followersCount = 1;
|
|
53
|
-
// Get the first followersCount
|
|
54
|
-
const result1 = await viz.getFollowersAsync('viz', 0, 'blog', followersCount)
|
|
55
|
-
result1.should.have.lengthOf(followersCount);
|
|
56
|
-
const result2 = await viz.getFollowersAsync('viz', result1[result1.length - 1].follower, 'blog', followersCount)
|
|
57
|
-
result2.should.have.lengthOf(followersCount);
|
|
58
|
-
result1.should.not.be.eql(result2);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('clears listeners', async () => {
|
|
62
|
-
viz.listeners('message').should.have.lengthOf(0);
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
describe('getContent', () => {
|
|
68
|
-
describe('getting a random post', () => {
|
|
34
|
+
describe('getAccounts', () => {
|
|
35
|
+
describe('getting viz\'s account', () => {
|
|
69
36
|
it('works', async () => {
|
|
70
|
-
const result = await viz.
|
|
71
|
-
result
|
|
37
|
+
const result = await viz.getAccountsAsync(['viz']);
|
|
38
|
+
assert(result, 'getAccountsAsync resolved to null?');
|
|
39
|
+
result.should.have.lengthOf(1);
|
|
40
|
+
result[0].should.have.property('name', 'viz');
|
|
72
41
|
});
|
|
73
42
|
|
|
74
43
|
it('clears listeners', async () => {
|
|
@@ -76,126 +45,4 @@ describe('viz.api:', function () {
|
|
|
76
45
|
});
|
|
77
46
|
});
|
|
78
47
|
});
|
|
79
|
-
|
|
80
|
-
describe('streamBlockNumber', () => {
|
|
81
|
-
it('streams viz transactions', (done) => {
|
|
82
|
-
let i = 0;
|
|
83
|
-
const release = viz.streamBlockNumber((err, block) => {
|
|
84
|
-
should.exist(block);
|
|
85
|
-
block.should.be.instanceOf(Number);
|
|
86
|
-
i++;
|
|
87
|
-
if (i === 2) {
|
|
88
|
-
release();
|
|
89
|
-
done();
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
describe('streamBlock', () => {
|
|
96
|
-
it('streams viz blocks', (done) => {
|
|
97
|
-
let i = 0;
|
|
98
|
-
const release = viz.streamBlock((err, block) => {
|
|
99
|
-
try {
|
|
100
|
-
should.exist(block);
|
|
101
|
-
block.should.have.properties([
|
|
102
|
-
'previous',
|
|
103
|
-
'transactions',
|
|
104
|
-
'timestamp',
|
|
105
|
-
]);
|
|
106
|
-
} catch (err) {
|
|
107
|
-
release();
|
|
108
|
-
done(err);
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
i++;
|
|
113
|
-
if (i === 2) {
|
|
114
|
-
release();
|
|
115
|
-
done();
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
describe('streamTransactions', () => {
|
|
122
|
-
it('streams viz transactions', (done) => {
|
|
123
|
-
let i = 0;
|
|
124
|
-
const release = viz.streamTransactions((err, transaction) => {
|
|
125
|
-
try {
|
|
126
|
-
should.exist(transaction);
|
|
127
|
-
transaction.should.have.properties([
|
|
128
|
-
'ref_block_num',
|
|
129
|
-
'operations',
|
|
130
|
-
'extensions',
|
|
131
|
-
]);
|
|
132
|
-
} catch (err) {
|
|
133
|
-
release();
|
|
134
|
-
done(err);
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
i++;
|
|
139
|
-
if (i === 2) {
|
|
140
|
-
release();
|
|
141
|
-
done();
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
describe('streamOperations', () => {
|
|
148
|
-
it('streams viz operations', (done) => {
|
|
149
|
-
let i = 0;
|
|
150
|
-
const release = viz.streamOperations((err, operation) => {
|
|
151
|
-
try {
|
|
152
|
-
should.exist(operation);
|
|
153
|
-
} catch (err) {
|
|
154
|
-
release();
|
|
155
|
-
done(err);
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
i++;
|
|
160
|
-
if (i === 2) {
|
|
161
|
-
release();
|
|
162
|
-
done();
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
describe('when there are network failures (the ws closes)', () => {
|
|
169
|
-
const originalStart = VIZ.prototype.start;
|
|
170
|
-
makeStub(VIZ.prototype, 'start', function () {
|
|
171
|
-
return originalStart.apply(this, arguments);
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
const originalStop = VIZ.prototype.stop;
|
|
175
|
-
makeStub(VIZ.prototype, 'stop', function () {
|
|
176
|
-
return originalStop.apply(this, arguments);
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
it('tries to reconnect automatically', async () => {
|
|
180
|
-
const viz = new VIZ();
|
|
181
|
-
// console.log('RECONNECT TEST start');
|
|
182
|
-
assert(!viz.ws, 'There was a websocket connection before a call?');
|
|
183
|
-
// console.log('RECONNECT TEST make followers call');
|
|
184
|
-
const followersCount = 1;
|
|
185
|
-
await viz.getFollowersAsync('viz', 0, 'blog', followersCount);
|
|
186
|
-
assert(viz.ws, 'There was no websocket connection after a call?');
|
|
187
|
-
// console.log('RECONNECT TEST wait 1s');
|
|
188
|
-
await Promise.delay(1000);
|
|
189
|
-
// console.log('RECONNECT TEST simulate close event');
|
|
190
|
-
assert(!viz.stop.calledOnce, 'VIZ::stop was already called before disconnect?');
|
|
191
|
-
viz.ws.emit('close');
|
|
192
|
-
assert(!viz.ws);
|
|
193
|
-
assert(!viz.startP);
|
|
194
|
-
assert(viz.stop.calledOnce, 'VIZ::stop wasn\'t called when the connection closed?');
|
|
195
|
-
// console.log('RECONNECT TEST make followers call');
|
|
196
|
-
await viz.getFollowersAsync('viz', 0, 'blog', followersCount);
|
|
197
|
-
assert(viz.ws, 'There was no websocket connection after a call?');
|
|
198
|
-
assert(viz.isOpen, 'There was no websocket connection after a call?');
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
48
|
});
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
// Websocket-transport / streaming tests.
|
|
2
|
+
//
|
|
3
|
+
// These require a websocket (ws:// or wss://) node and a persistent
|
|
4
|
+
// connection, so they are excluded from `npm run test-ci` and meant to be
|
|
5
|
+
// run manually via `npm run test-ws` against a ws endpoint, e.g.:
|
|
6
|
+
// VIZ_WS_NODE=wss://node.example/ws npm run test-ws
|
|
7
|
+
require('babel-polyfill');
|
|
8
|
+
import Promise from 'bluebird';
|
|
9
|
+
import assert from 'assert';
|
|
10
|
+
import makeStub from 'mocha-make-stub'
|
|
11
|
+
import should from 'should';
|
|
12
|
+
|
|
13
|
+
import viz, { VIZ } from '../src/api/index';
|
|
14
|
+
import config from '../src/config';
|
|
15
|
+
|
|
16
|
+
describe('viz.api (websocket):', function () {
|
|
17
|
+
this.timeout(30 * 1000);
|
|
18
|
+
|
|
19
|
+
const wsNode = process.env.VIZ_WS_NODE;
|
|
20
|
+
before(() => {
|
|
21
|
+
if (wsNode) {
|
|
22
|
+
config.set('websocket', wsNode);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
beforeEach(async () => {
|
|
27
|
+
await viz.apiIdsP;
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe('new VIZ', () => {
|
|
31
|
+
it('opens a connection on demand', (done) => {
|
|
32
|
+
const s = new VIZ();
|
|
33
|
+
assert(!new VIZ().ws, 'There was a connection on a new instance?');
|
|
34
|
+
s.start();
|
|
35
|
+
process.nextTick(() => {
|
|
36
|
+
assert(s.ws, 'There was no connection?');
|
|
37
|
+
done();
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe('streamBlockNumber', () => {
|
|
43
|
+
it('streams viz transactions', (done) => {
|
|
44
|
+
let i = 0;
|
|
45
|
+
const release = viz.streamBlockNumber((err, block) => {
|
|
46
|
+
should.exist(block);
|
|
47
|
+
block.should.be.instanceOf(Number);
|
|
48
|
+
i++;
|
|
49
|
+
if (i === 2) {
|
|
50
|
+
release();
|
|
51
|
+
done();
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('streamBlock', () => {
|
|
58
|
+
it('streams viz blocks', (done) => {
|
|
59
|
+
let i = 0;
|
|
60
|
+
const release = viz.streamBlock((err, block) => {
|
|
61
|
+
try {
|
|
62
|
+
should.exist(block);
|
|
63
|
+
block.should.have.properties([
|
|
64
|
+
'previous',
|
|
65
|
+
'transactions',
|
|
66
|
+
'timestamp',
|
|
67
|
+
]);
|
|
68
|
+
} catch (err) {
|
|
69
|
+
release();
|
|
70
|
+
done(err);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
i++;
|
|
75
|
+
if (i === 2) {
|
|
76
|
+
release();
|
|
77
|
+
done();
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe('streamTransactions', () => {
|
|
84
|
+
it('streams viz transactions', (done) => {
|
|
85
|
+
let i = 0;
|
|
86
|
+
const release = viz.streamTransactions((err, transaction) => {
|
|
87
|
+
try {
|
|
88
|
+
should.exist(transaction);
|
|
89
|
+
transaction.should.have.properties([
|
|
90
|
+
'ref_block_num',
|
|
91
|
+
'operations',
|
|
92
|
+
'extensions',
|
|
93
|
+
]);
|
|
94
|
+
} catch (err) {
|
|
95
|
+
release();
|
|
96
|
+
done(err);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
i++;
|
|
101
|
+
if (i === 2) {
|
|
102
|
+
release();
|
|
103
|
+
done();
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
describe('streamOperations', () => {
|
|
110
|
+
it('streams viz operations', (done) => {
|
|
111
|
+
let i = 0;
|
|
112
|
+
const release = viz.streamOperations((err, operation) => {
|
|
113
|
+
try {
|
|
114
|
+
should.exist(operation);
|
|
115
|
+
} catch (err) {
|
|
116
|
+
release();
|
|
117
|
+
done(err);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
i++;
|
|
122
|
+
if (i === 2) {
|
|
123
|
+
release();
|
|
124
|
+
done();
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
describe('when there are network failures (the ws closes)', () => {
|
|
131
|
+
const originalStart = VIZ.prototype.start;
|
|
132
|
+
makeStub(VIZ.prototype, 'start', function () {
|
|
133
|
+
return originalStart.apply(this, arguments);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const originalStop = VIZ.prototype.stop;
|
|
137
|
+
makeStub(VIZ.prototype, 'stop', function () {
|
|
138
|
+
return originalStop.apply(this, arguments);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('tries to reconnect automatically', async () => {
|
|
142
|
+
const viz = new VIZ();
|
|
143
|
+
// console.log('RECONNECT TEST start');
|
|
144
|
+
assert(!viz.ws, 'There was a websocket connection before a call?');
|
|
145
|
+
// console.log('RECONNECT TEST make accounts call');
|
|
146
|
+
await viz.getAccountsAsync(['viz']);
|
|
147
|
+
assert(viz.ws, 'There was no websocket connection after a call?');
|
|
148
|
+
// console.log('RECONNECT TEST wait 1s');
|
|
149
|
+
await Promise.delay(1000);
|
|
150
|
+
// console.log('RECONNECT TEST simulate close event');
|
|
151
|
+
assert(!viz.stop.calledOnce, 'VIZ::stop was already called before disconnect?');
|
|
152
|
+
viz.ws.emit('close');
|
|
153
|
+
assert(!viz.ws);
|
|
154
|
+
assert(!viz.startP);
|
|
155
|
+
assert(viz.stop.calledOnce, 'VIZ::stop wasn\'t called when the connection closed?');
|
|
156
|
+
// console.log('RECONNECT TEST make accounts call');
|
|
157
|
+
await viz.getAccountsAsync(['viz']);
|
|
158
|
+
assert(viz.ws, 'There was no websocket connection after a call?');
|
|
159
|
+
assert(viz.isOpen, 'There was no websocket connection after a call?');
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
});
|