hive-stream 2.0.2 → 2.0.5
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/.env +3 -1
- package/.env.example +3 -2
- package/.travis.yml +11 -11
- package/LICENSE +21 -21
- package/README.md +238 -236
- package/dist/actions.d.ts +10 -9
- package/dist/actions.js +23 -15
- package/dist/actions.js.map +1 -1
- package/dist/adapters/base.adapter.d.ts +25 -21
- package/dist/adapters/base.adapter.js +49 -63
- package/dist/adapters/base.adapter.js.map +1 -1
- package/dist/adapters/mongodb.adapter.d.ts +37 -29
- package/dist/adapters/mongodb.adapter.js +158 -113
- package/dist/adapters/mongodb.adapter.js.map +1 -1
- package/dist/adapters/sqlite.adapter.d.ts +41 -23
- package/dist/adapters/sqlite.adapter.js +397 -121
- package/dist/adapters/sqlite.adapter.js.map +1 -1
- package/dist/api.d.ts +6 -0
- package/dist/api.js +56 -0
- package/dist/api.js.map +1 -0
- package/dist/config.d.ts +16 -14
- package/dist/config.js +18 -15
- package/dist/config.js.map +1 -1
- package/dist/contracts/coinflip.contract.d.ts +14 -0
- package/dist/contracts/coinflip.contract.js +95 -0
- package/dist/contracts/coinflip.contract.js.map +1 -0
- package/dist/contracts/dice.contract.d.ts +29 -29
- package/dist/contracts/dice.contract.js +155 -157
- package/dist/contracts/dice.contract.js.map +1 -1
- package/dist/contracts/lotto.contract.d.ts +20 -16
- package/dist/contracts/lotto.contract.js +246 -107
- package/dist/contracts/lotto.contract.js.map +1 -1
- package/dist/exchanges/bittrex.d.ts +6 -0
- package/dist/exchanges/bittrex.js +35 -0
- package/dist/exchanges/bittrex.js.map +1 -0
- package/dist/exchanges/exchange.d.ts +9 -0
- package/dist/exchanges/exchange.js +27 -0
- package/dist/exchanges/exchange.js.map +1 -0
- package/dist/hive-rates.d.ts +9 -0
- package/dist/hive-rates.js +76 -0
- package/dist/hive-rates.js.map +1 -0
- package/dist/index.d.ts +11 -10
- package/dist/index.js +32 -15
- package/dist/index.js.map +1 -1
- package/dist/streamer.d.ts +93 -70
- package/dist/streamer.js +545 -439
- package/dist/streamer.js.map +1 -1
- package/dist/test.d.ts +1 -1
- package/dist/test.js +25 -27
- package/dist/test.js.map +1 -1
- package/dist/types/hive-stream.d.ts +6 -6
- package/dist/types/hive-stream.js +2 -2
- package/dist/utils.d.ts +27 -14
- package/dist/utils.js +261 -85
- package/dist/utils.js.map +1 -1
- package/ecosystem.config.js +17 -17
- package/jest.config.js +9 -14
- package/package.json +48 -40
- package/test-contract-block.md +18 -18
- package/tests/adapters/sqlite.adapter.spec.ts +43 -0
- package/tests/contracts/coinflip.contract.spec.ts +132 -0
- package/tests/contracts/dice.contract.spec.ts +160 -0
- package/tests/contracts/entrants.json +729 -0
- package/tests/contracts/lotto.contract.spec.ts +324 -0
- package/tests/setup.ts +19 -0
- package/tests/streamer.spec.ts +152 -0
- package/tests/utils.spec.ts +95 -0
- package/tsconfig.build.json +22 -19
- package/tslint.json +20 -20
- package/wallaby.js +26 -0
- package/dist/adapters/file.adapter.d.ts +0 -8
- package/dist/adapters/file.adapter.js +0 -70
- package/dist/adapters/file.adapter.js.map +0 -1
- package/dist/test/setup.d.ts +0 -0
- package/dist/test/setup.js +0 -9
- package/dist/test/setup.js.map +0 -1
- package/dist/test/streamer.spec.d.ts +0 -1
- package/dist/test/streamer.spec.js +0 -145
- package/dist/test/streamer.spec.js.map +0 -1
- package/dist/test/utils.spec.d.ts +0 -1
- package/dist/test/utils.spec.js +0 -11
- package/dist/test/utils.spec.js.map +0 -1
- package/hive-stream.json +0 -1
- package/test/contracts/dice.contract.spec.ts +0 -253
- package/test/contracts/lotto.contract.spec.ts +0 -61
- package/test/setup.ts +0 -9
- package/test/streamer.spec.ts +0 -348
- package/test/utils.spec.ts +0 -12
package/test/streamer.spec.ts
DELETED
|
@@ -1,348 +0,0 @@
|
|
|
1
|
-
import { Client } from '@hivechain/dhive';
|
|
2
|
-
import { Streamer } from './../src/streamer';
|
|
3
|
-
|
|
4
|
-
import fs from 'fs';
|
|
5
|
-
import { sleep } from '@hivechain/dhive/lib/utils';
|
|
6
|
-
|
|
7
|
-
jest.mock('fs');
|
|
8
|
-
|
|
9
|
-
describe('Streamer', () => {
|
|
10
|
-
|
|
11
|
-
let sut: Streamer;
|
|
12
|
-
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
sut = new Streamer({
|
|
15
|
-
JSON_ID: 'test',
|
|
16
|
-
PAYLOAD_IDENTIFIER: 'hiveContract'
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
afterEach(() => {
|
|
21
|
-
sut.stop();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test('Constructor should instantiate client instance', () => {
|
|
25
|
-
expect(sut['client']).toBeInstanceOf(Client);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test('setConfig properly assigns multiple values', () => {
|
|
29
|
-
sut.setConfig({
|
|
30
|
-
LAST_BLOCK_NUMBER: 1234
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
expect(sut['config'].LAST_BLOCK_NUMBER).toStrictEqual(1234);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test('should get last block number from load state call', async () => {
|
|
37
|
-
sut['adapter'] = {
|
|
38
|
-
create: jest.fn(),
|
|
39
|
-
destroy: jest.fn(),
|
|
40
|
-
loadState: jest.fn().mockResolvedValue({lastBlockNumber: 27777})
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
await sut.start();
|
|
44
|
-
|
|
45
|
-
expect(sut['lastBlockNumber']).toStrictEqual(27777);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test('load state method is not implemented in adapter', async () => {
|
|
49
|
-
sut['adapter'] = {
|
|
50
|
-
create: jest.fn(),
|
|
51
|
-
destroy: jest.fn(),
|
|
52
|
-
loadState: jest.fn()
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
sut['lastBlockNumber'] = 0;
|
|
56
|
-
|
|
57
|
-
await sut.start();
|
|
58
|
-
|
|
59
|
-
expect(sut['lastBlockNumber']).toStrictEqual(0);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test('getBlock gets a block', async () => {
|
|
63
|
-
sut['adapter'] = {
|
|
64
|
-
create: jest.fn(),
|
|
65
|
-
destroy: jest.fn()
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
jest.spyOn(sut['client'].database, 'getDynamicGlobalProperties').mockResolvedValue({head_block_number: 8882} as any);
|
|
69
|
-
|
|
70
|
-
jest.spyOn(sut['client'].database, 'getBlock').mockResolvedValue({
|
|
71
|
-
block_id: 1234,
|
|
72
|
-
previous: 1233,
|
|
73
|
-
transaction_ids: ['sdasd', 'dasdad'],
|
|
74
|
-
timestamp: new Date().toDateString(),
|
|
75
|
-
transactions: {
|
|
76
|
-
0: {
|
|
77
|
-
operations: {
|
|
78
|
-
0: {}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
} as any);
|
|
83
|
-
|
|
84
|
-
jest.spyOn(sut as any, 'getBlock');
|
|
85
|
-
jest.spyOn(sut as any, 'loadBlock');
|
|
86
|
-
|
|
87
|
-
sut['lastBlockNumber'] = 0;
|
|
88
|
-
|
|
89
|
-
await sut['getBlock']();
|
|
90
|
-
|
|
91
|
-
expect(sut['lastBlockNumber']).toStrictEqual(8881);
|
|
92
|
-
|
|
93
|
-
// Wait for 3 block cycles to be called
|
|
94
|
-
await sleep(3000);
|
|
95
|
-
|
|
96
|
-
sut['disableAllProcessing'] = true;
|
|
97
|
-
|
|
98
|
-
expect(sut['loadBlock']).toBeCalledWith(8882);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
test('getBlock global properties returns null', async () => {
|
|
102
|
-
jest.spyOn(sut['client'].database, 'getDynamicGlobalProperties').mockResolvedValue(null);
|
|
103
|
-
|
|
104
|
-
jest.spyOn(sut as any, 'getBlock');
|
|
105
|
-
jest.spyOn(sut as any, 'loadBlock');
|
|
106
|
-
|
|
107
|
-
await sut['getBlock']();
|
|
108
|
-
|
|
109
|
-
await sleep(1000);
|
|
110
|
-
|
|
111
|
-
sut['disableAllProcessing'] = true;
|
|
112
|
-
|
|
113
|
-
expect(sut['getBlock']).toBeCalled();
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
test('processOperation calls post subscriber', () => {
|
|
117
|
-
const callback = jest.fn();
|
|
118
|
-
|
|
119
|
-
sut.onPost(callback);
|
|
120
|
-
|
|
121
|
-
const operation = [
|
|
122
|
-
'comment',
|
|
123
|
-
{ parent_author: '' }
|
|
124
|
-
];
|
|
125
|
-
|
|
126
|
-
sut.processOperation(operation, 1234, 'ffsdfsd', '34fdfsd', '4234ff', '2020-03-22T10:19:24.228Z' as any);
|
|
127
|
-
|
|
128
|
-
expect(callback).toBeCalledWith({'parent_author': ''}, 1234, 'ffsdfsd', '34fdfsd', '4234ff', '2020-03-22T10:19:24.228Z');
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
test('processOperation calls comment subscriber', () => {
|
|
132
|
-
const callback = jest.fn();
|
|
133
|
-
|
|
134
|
-
sut.onComment(callback);
|
|
135
|
-
|
|
136
|
-
const operation = [
|
|
137
|
-
'comment',
|
|
138
|
-
{ parent_author: 'beggars' }
|
|
139
|
-
];
|
|
140
|
-
|
|
141
|
-
sut.processOperation(operation, 1234, 'ffsdfsd', '34fdfsd', '4234ff', '2020-03-22T10:19:24.228Z' as any);
|
|
142
|
-
|
|
143
|
-
expect(callback).toBeCalledWith({'parent_author': 'beggars'}, 1234, 'ffsdfsd', '34fdfsd', '4234ff', '2020-03-22T10:19:24.228Z');
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
test('processOperation calls transfer subscriber', () => {
|
|
147
|
-
const callback = jest.fn();
|
|
148
|
-
|
|
149
|
-
sut.onTransfer('beggars', callback);
|
|
150
|
-
|
|
151
|
-
const operation = [
|
|
152
|
-
'transfer',
|
|
153
|
-
{ to: 'beggars' }
|
|
154
|
-
];
|
|
155
|
-
|
|
156
|
-
sut.processOperation(operation, 1234, 'ffsdfsd', '34fdfsd', '4234ff', '2020-03-22T10:19:24.228Z' as any);
|
|
157
|
-
|
|
158
|
-
expect(callback).toBeCalledWith({'to': 'beggars'}, 1234, 'ffsdfsd', '34fdfsd', '4234ff', '2020-03-22T10:19:24.228Z');
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
test('processOperation calls custom json subscriber signed with active key', () => {
|
|
162
|
-
const callback = jest.fn();
|
|
163
|
-
|
|
164
|
-
sut.onCustomJson(callback);
|
|
165
|
-
|
|
166
|
-
const operation = [
|
|
167
|
-
'custom_json',
|
|
168
|
-
{ id: 'test', required_auths: ['beggars'] }
|
|
169
|
-
];
|
|
170
|
-
|
|
171
|
-
sut.processOperation(operation, 1234, 'ffsdfsd', '34fdfsd', '4234ff', '2020-03-22T10:19:24.228Z' as any);
|
|
172
|
-
|
|
173
|
-
expect(callback).toBeCalledWith({'id': 'test', 'required_auths': ['beggars']}, {'isSignedWithActiveKey': true, 'sender': 'beggars'}, 1234, 'ffsdfsd', '34fdfsd', '4234ff', '2020-03-22T10:19:24.228Z');
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
test('processOperation calls custom json subscriber signed without active key', () => {
|
|
177
|
-
const callback = jest.fn();
|
|
178
|
-
|
|
179
|
-
sut.onCustomJson(callback);
|
|
180
|
-
|
|
181
|
-
const operation = [
|
|
182
|
-
'custom_json',
|
|
183
|
-
{ id: 'test', required_posting_auths: ['beggars'] }
|
|
184
|
-
];
|
|
185
|
-
|
|
186
|
-
sut.processOperation(operation, 1234, 'ffsdfsd', '34fdfsd', '4234ff', '2020-03-22T10:19:24.228Z' as any);
|
|
187
|
-
|
|
188
|
-
expect(callback).toBeCalledWith({'id': 'test', 'required_posting_auths': ['beggars']}, {'isSignedWithActiveKey': false, 'sender': 'beggars'}, 1234, 'ffsdfsd', '34fdfsd', '4234ff', '2020-03-22T10:19:24.228Z');
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
test('processOperation calls custom json ID subscriber signed with active key', () => {
|
|
192
|
-
const callback = jest.fn();
|
|
193
|
-
|
|
194
|
-
sut.onCustomJsonId(callback, 'test');
|
|
195
|
-
|
|
196
|
-
const operation = [
|
|
197
|
-
'custom_json',
|
|
198
|
-
{ id: 'test', required_auths: ['beggars'] }
|
|
199
|
-
];
|
|
200
|
-
|
|
201
|
-
sut.processOperation(operation, 1234, 'ffsdfsd', '34fdfsd', '4234ff', '2020-03-22T10:19:24.228Z' as any);
|
|
202
|
-
|
|
203
|
-
expect(callback).toBeCalledWith({'id': 'test', 'required_auths': ['beggars']}, {'isSignedWithActiveKey': true, 'sender': 'beggars'}, 1234, 'ffsdfsd', '34fdfsd', '4234ff', '2020-03-22T10:19:24.228Z');
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
test('processOperation calls custom json ID subscriber signed without active key', () => {
|
|
207
|
-
const callback = jest.fn();
|
|
208
|
-
|
|
209
|
-
sut.onCustomJsonId(callback, 'test');
|
|
210
|
-
|
|
211
|
-
const operation = [
|
|
212
|
-
'custom_json',
|
|
213
|
-
{ id: 'test', required_posting_auths: ['beggars'] }
|
|
214
|
-
];
|
|
215
|
-
|
|
216
|
-
sut.processOperation(operation, 1234, 'ffsdfsd', '34fdfsd', '4234ff', '2020-03-22T10:19:24.228Z' as any);
|
|
217
|
-
|
|
218
|
-
expect(callback).toBeCalledWith({'id': 'test', 'required_posting_auths': ['beggars']}, {'isSignedWithActiveKey': false, 'sender': 'beggars'}, 1234, 'ffsdfsd', '34fdfsd', '4234ff', '2020-03-22T10:19:24.228Z');
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
describe('Contracts', () => {
|
|
222
|
-
|
|
223
|
-
test('contract create lifecycle function should be called', () => {
|
|
224
|
-
const contract = {
|
|
225
|
-
create: jest.fn()
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
// Register our contract
|
|
229
|
-
sut.registerContract('dice', contract);
|
|
230
|
-
|
|
231
|
-
const findContract = sut['contracts'].find(c => c.name === 'dice');
|
|
232
|
-
|
|
233
|
-
expect(contract.create).toBeCalled();
|
|
234
|
-
expect(findContract).not.toBeUndefined();
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
test('contract destroy lifecycle function should be called and unregistered', () => {
|
|
238
|
-
const contract = {
|
|
239
|
-
create: jest.fn(),
|
|
240
|
-
destroy: jest.fn()
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
// Register our contract
|
|
244
|
-
sut.registerContract('dice', contract);
|
|
245
|
-
|
|
246
|
-
sut.unregisterContract('dice');
|
|
247
|
-
|
|
248
|
-
expect(contract.destroy).toBeCalled();
|
|
249
|
-
|
|
250
|
-
const findContract = sut['contracts'].find(c => c.name === 'dice');
|
|
251
|
-
|
|
252
|
-
expect(findContract).toBeUndefined();
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
test('contract action should be called from payload', () => {
|
|
256
|
-
const contract = {
|
|
257
|
-
roll: jest.fn()
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
// Register our contract
|
|
261
|
-
sut.registerContract('dice', contract);
|
|
262
|
-
|
|
263
|
-
const operation = [
|
|
264
|
-
'custom_json',
|
|
265
|
-
{
|
|
266
|
-
id: 'test',
|
|
267
|
-
required_auths: ['beggars'],
|
|
268
|
-
json: JSON.stringify({
|
|
269
|
-
hiveContract: {
|
|
270
|
-
name: 'dice',
|
|
271
|
-
action: 'roll',
|
|
272
|
-
payload: {
|
|
273
|
-
roll: 12
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
})
|
|
277
|
-
}
|
|
278
|
-
];
|
|
279
|
-
|
|
280
|
-
sut.processOperation(operation, 1234, 'ffsdfsd', '34fdfsd', '4234ff', '2020-03-22T10:19:24.228Z' as any);
|
|
281
|
-
|
|
282
|
-
expect(contract.roll).toBeCalledWith({roll: 12}, { isSignedWithActiveKey: true, sender: 'beggars' }, 'test');
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
test('contract action should be called from transfer memo', () => {
|
|
286
|
-
const contract = {
|
|
287
|
-
roll: jest.fn()
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
// Register our contract
|
|
291
|
-
sut.registerContract('dice', contract);
|
|
292
|
-
|
|
293
|
-
const operation = [
|
|
294
|
-
'transfer',
|
|
295
|
-
{
|
|
296
|
-
from: 'beggars',
|
|
297
|
-
amount: '3.000 HIVE',
|
|
298
|
-
memo: JSON.stringify({
|
|
299
|
-
hiveContract: {
|
|
300
|
-
id: 'test',
|
|
301
|
-
name: 'dice',
|
|
302
|
-
action: 'roll',
|
|
303
|
-
payload: {
|
|
304
|
-
roll: 12
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
})
|
|
308
|
-
}
|
|
309
|
-
];
|
|
310
|
-
|
|
311
|
-
sut.processOperation(operation, 1234, 'ffsdfsd', '34fdfsd', '4234ff', '2020-03-22T10:19:24.228Z' as any);
|
|
312
|
-
|
|
313
|
-
expect(contract.roll).toBeCalledWith({roll: 12}, { amount: '3.000 HIVE', sender: 'beggars' });
|
|
314
|
-
});
|
|
315
|
-
|
|
316
|
-
test('contract should be updated with block info', () => {
|
|
317
|
-
const contract = {
|
|
318
|
-
updateBlockInfo: jest.fn()
|
|
319
|
-
};
|
|
320
|
-
|
|
321
|
-
// Register our contract
|
|
322
|
-
sut.registerContract('dice', contract);
|
|
323
|
-
|
|
324
|
-
const operation = [
|
|
325
|
-
'custom_json',
|
|
326
|
-
{
|
|
327
|
-
id: 'test',
|
|
328
|
-
required_auths: ['beggars'],
|
|
329
|
-
json: JSON.stringify({
|
|
330
|
-
hiveContract: {
|
|
331
|
-
name: 'dice',
|
|
332
|
-
action: 'roll',
|
|
333
|
-
payload: {
|
|
334
|
-
roll: 12
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
})
|
|
338
|
-
}
|
|
339
|
-
];
|
|
340
|
-
|
|
341
|
-
sut.processOperation(operation, 1234, 'ffsdfsd', '34fdfsd', '4234ff', '2020-03-22T10:19:24.228Z' as any);
|
|
342
|
-
|
|
343
|
-
expect(contract.updateBlockInfo).toBeCalledWith(1234, 'ffsdfsd', '34fdfsd', '4234ff');
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
});
|
package/test/utils.spec.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Utils } from './../src/utils';
|
|
2
|
-
|
|
3
|
-
describe('Utils', () => {
|
|
4
|
-
|
|
5
|
-
test('Should generate two deterministic numbers', () => {
|
|
6
|
-
// Should generate a deterministic random number
|
|
7
|
-
expect(Utils.randomNumber('dasdasdas', '2312fsdfsdfsdf', 'kfjlksdjflksdjf999')).toStrictEqual(26);
|
|
8
|
-
|
|
9
|
-
expect(Utils.randomNumber('fdfsdfsdfsdfsf', '2312fsdfsdfsdf', 'kfjlksdjflksdjf999')).toStrictEqual(43);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
});
|