hive-stream 2.0.3 → 2.0.6

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.
Files changed (99) hide show
  1. package/.env.example +3 -2
  2. package/.travis.yml +11 -11
  3. package/LICENSE +21 -21
  4. package/README.md +238 -236
  5. package/dist/actions.d.ts +10 -9
  6. package/dist/actions.js +23 -15
  7. package/dist/actions.js.map +1 -1
  8. package/dist/adapters/base.adapter.d.ts +25 -21
  9. package/dist/adapters/base.adapter.js +49 -63
  10. package/dist/adapters/base.adapter.js.map +1 -1
  11. package/dist/adapters/mongodb.adapter.d.ts +37 -29
  12. package/dist/adapters/mongodb.adapter.js +158 -113
  13. package/dist/adapters/mongodb.adapter.js.map +1 -1
  14. package/dist/adapters/sqlite.adapter.d.ts +41 -23
  15. package/dist/adapters/sqlite.adapter.js +397 -121
  16. package/dist/adapters/sqlite.adapter.js.map +1 -1
  17. package/dist/api.d.ts +6 -0
  18. package/dist/api.js +56 -0
  19. package/dist/api.js.map +1 -0
  20. package/dist/config.d.ts +16 -14
  21. package/dist/config.js +18 -15
  22. package/dist/config.js.map +1 -1
  23. package/dist/contracts/coinflip.contract.d.ts +14 -0
  24. package/dist/contracts/coinflip.contract.js +95 -0
  25. package/dist/contracts/coinflip.contract.js.map +1 -0
  26. package/dist/contracts/dice.contract.d.ts +29 -29
  27. package/dist/contracts/dice.contract.js +155 -157
  28. package/dist/contracts/dice.contract.js.map +1 -1
  29. package/dist/contracts/lotto.contract.d.ts +20 -16
  30. package/dist/contracts/lotto.contract.js +246 -107
  31. package/dist/contracts/lotto.contract.js.map +1 -1
  32. package/dist/exchanges/bittrex.d.ts +6 -0
  33. package/dist/exchanges/bittrex.js +35 -0
  34. package/dist/exchanges/bittrex.js.map +1 -0
  35. package/dist/exchanges/exchange.d.ts +9 -0
  36. package/dist/exchanges/exchange.js +27 -0
  37. package/dist/exchanges/exchange.js.map +1 -0
  38. package/dist/hive-rates.d.ts +9 -0
  39. package/dist/hive-rates.js +76 -0
  40. package/dist/hive-rates.js.map +1 -0
  41. package/dist/index.d.ts +11 -10
  42. package/dist/index.js +32 -15
  43. package/dist/index.js.map +1 -1
  44. package/dist/streamer.d.ts +93 -70
  45. package/dist/streamer.js +545 -439
  46. package/dist/streamer.js.map +1 -1
  47. package/dist/test.d.ts +1 -1
  48. package/dist/test.js +25 -27
  49. package/dist/test.js.map +1 -1
  50. package/dist/types/hive-stream.d.ts +6 -6
  51. package/dist/types/hive-stream.js +2 -2
  52. package/dist/utils.d.ts +27 -14
  53. package/dist/utils.js +261 -85
  54. package/dist/utils.js.map +1 -1
  55. package/ecosystem.config.js +17 -17
  56. package/jest.config.js +8 -13
  57. package/package.json +48 -44
  58. package/test-contract-block.md +18 -18
  59. package/tests/adapters/sqlite.adapter.spec.ts +43 -0
  60. package/tests/contracts/coinflip.contract.spec.ts +132 -0
  61. package/tests/contracts/dice.contract.spec.ts +159 -156
  62. package/tests/contracts/entrants.json +728 -728
  63. package/tests/contracts/lotto.contract.spec.ts +323 -372
  64. package/tests/setup.ts +18 -20
  65. package/tests/streamer.spec.ts +151 -151
  66. package/tests/utils.spec.ts +94 -99
  67. package/tsconfig.build.json +22 -20
  68. package/tslint.json +20 -20
  69. package/wallaby.js +26 -0
  70. package/.env +0 -1
  71. package/dist/adapters/file.adapter.d.ts +0 -8
  72. package/dist/adapters/file.adapter.js +0 -70
  73. package/dist/adapters/file.adapter.js.map +0 -1
  74. package/dist/test/setup.d.ts +0 -0
  75. package/dist/test/setup.js +0 -9
  76. package/dist/test/setup.js.map +0 -1
  77. package/dist/test/streamer.spec.d.ts +0 -1
  78. package/dist/test/streamer.spec.js +0 -145
  79. package/dist/test/streamer.spec.js.map +0 -1
  80. package/dist/test/utils.spec.d.ts +0 -1
  81. package/dist/test/utils.spec.js +0 -11
  82. package/dist/test/utils.spec.js.map +0 -1
  83. package/dist/tests/contracts/dice.contract.spec.d.ts +0 -1
  84. package/dist/tests/contracts/dice.contract.spec.js +0 -130
  85. package/dist/tests/contracts/dice.contract.spec.js.map +0 -1
  86. package/dist/tests/contracts/entrants.json +0 -729
  87. package/dist/tests/contracts/lotto.contract.spec.d.ts +0 -1
  88. package/dist/tests/contracts/lotto.contract.spec.js +0 -300
  89. package/dist/tests/contracts/lotto.contract.spec.js.map +0 -1
  90. package/dist/tests/setup.d.ts +0 -1
  91. package/dist/tests/setup.js +0 -19
  92. package/dist/tests/setup.js.map +0 -1
  93. package/dist/tests/streamer.spec.d.ts +0 -1
  94. package/dist/tests/streamer.spec.js +0 -123
  95. package/dist/tests/streamer.spec.js.map +0 -1
  96. package/dist/tests/utils.spec.d.ts +0 -1
  97. package/dist/tests/utils.spec.js +0 -87
  98. package/dist/tests/utils.spec.js.map +0 -1
  99. package/hive-stream.json +0 -1
@@ -1,157 +1,160 @@
1
- import { sleep } from '@hivechain/dhive/lib/utils';
2
- import { DiceContract } from './../../src/contracts/dice.contract';
3
- import { Streamer } from '../../src/streamer';
4
-
5
- describe('Dice Contract', () => {
6
- let sut: Streamer;
7
- let contract: DiceContract;
8
-
9
- beforeEach(() => {
10
- sut = new Streamer();
11
- contract = new DiceContract();
12
- });
13
-
14
- afterEach(() => {
15
- sut.stop();
16
- });
17
-
18
- afterAll(() => {
19
- jest.restoreAllMocks();
20
- });
21
-
22
- test('Registers the dice contract', () => {
23
- sut.registerContract('testdice', contract);
24
-
25
- const findContract = sut['contracts'].find(c => c.name === 'testdice');
26
-
27
- expect(findContract).not.toBeUndefined();
28
- });
29
-
30
- test('User wins a roll', async () => {
31
- sut.registerContract('testdice', contract);
32
-
33
- contract['_instance'] = sut;
34
-
35
- jest.spyOn(contract as any, 'roll');
36
- jest.spyOn(contract as any, 'getBalance').mockResolvedValue(2000);
37
-
38
- jest.spyOn(sut, 'getTransaction').mockResolvedValue({test: 123} as any);
39
- jest.spyOn(sut, 'verifyTransfer').mockResolvedValue(true as any);
40
- jest.spyOn(sut, 'transferHiveTokens').mockResolvedValue(true as any);
41
-
42
- const memo = JSON.stringify({
43
- hivePayload: {
44
- id: 'hivestream',
45
- name: 'testdice',
46
- action: 'roll',
47
- payload: {
48
- roll: 69
49
- }
50
- }
51
- });
52
-
53
- sut.processOperation(['transfer', { from: 'testuser', amount: '9.000 HIVE', memo }], 778782, 'dfjfsdfsdfsd34hfkj88787', 'fkjsdkfj', 'fhkjsdhfkjsdf', '2019-06-23' as any);
54
-
55
- await sleep(100);
56
-
57
- expect(contract['roll']).toBeCalled();
58
- expect(contract['_instance'].getTransaction).toBeCalledWith(778782, 'fhkjsdhfkjsdf');
59
- expect(contract['_instance'].transferHiveTokens).toBeCalledWith('beggars', 'testuser', '12.391', 'HIVE', 'You won 12.391 HIVE. Roll: 54, Your guess: 69');
60
- });
61
-
62
- test('User loses a roll', async () => {
63
- sut.registerContract('testdice', contract);
64
-
65
- contract['_instance'] = sut;
66
-
67
- jest.spyOn(contract as any, 'roll');
68
- jest.spyOn(contract as any, 'getBalance').mockResolvedValue(2000);
69
-
70
- jest.spyOn(sut, 'getTransaction').mockResolvedValue({test: 123} as any);
71
- jest.spyOn(sut, 'verifyTransfer').mockResolvedValue(true as any);
72
- jest.spyOn(sut, 'transferHiveTokens').mockResolvedValue(true as any);
73
-
74
- const memo = JSON.stringify({
75
- hivePayload: {
76
- id: 'hivestream',
77
- name: 'testdice',
78
- action: 'roll',
79
- payload: {
80
- roll: 69
81
- }
82
- }
83
- });
84
-
85
- sut.processOperation(['transfer', { from: 'testuser', amount: '9.000 HIVE', memo }], 778782, 'dfjfsdfsdfs4hfkj88787', 'fkjsdkfj', 'fhkjsdhfkjsdf', '2019-06-23' as any);
86
-
87
- await sleep(100);
88
-
89
- expect(contract['roll']).toBeCalled();
90
- expect(sut.getTransaction).toBeCalledWith(778782, 'fhkjsdhfkjsdf');
91
- expect(sut.transferHiveTokens).toBeCalledWith('beggars', 'testuser', '0.001', 'HIVE', 'You lost 9 HIVE. Roll: 81, Your guess: 69');
92
- });
93
-
94
- test('User sent an invalid amount, refund them', async () => {
95
- sut.registerContract('testdice', contract);
96
-
97
- contract['_instance'] = sut;
98
-
99
- jest.spyOn(contract as any, 'roll');
100
- jest.spyOn(contract as any, 'getBalance').mockResolvedValue(2000);
101
-
102
- jest.spyOn(sut, 'getTransaction').mockResolvedValue({test: 123} as any);
103
- jest.spyOn(sut, 'verifyTransfer').mockResolvedValue(true as any);
104
- jest.spyOn(sut, 'transferHiveTokens').mockResolvedValue(true as any);
105
-
106
- const memo = JSON.stringify({
107
- hivePayload: {
108
- id: 'hivestream',
109
- name: 'testdice',
110
- action: 'roll',
111
- payload: {
112
- roll: 69
113
- }
114
- }
115
- });
116
-
117
- sut.processOperation(['transfer', { from: 'testuser', amount: '100.000 HIVE', memo }], 778782, 'dfjfsdfsdfs4hfkj88787', 'fkjsdkfj', 'fhkjsdhfkjsdf', '2019-06-23' as any);
118
-
119
- await sleep(100);
120
-
121
- expect(contract['roll']).toBeCalled();
122
- expect(sut.getTransaction).toBeCalledWith(778782, 'fhkjsdhfkjsdf');
123
- expect(sut.transferHiveTokens).toBeCalledWith('beggars', 'testuser', '100.000', 'HIVE', '[Refund] You sent an invalid bet amount.');
124
- });
125
-
126
- test('User sent an unsupported currency, refund them', async () => {
127
- sut.registerContract('testdice', contract);
128
-
129
- contract['_instance'] = sut;
130
-
131
- jest.spyOn(contract as any, 'roll');
132
- jest.spyOn(contract as any, 'getBalance').mockResolvedValue(2000);
133
-
134
- jest.spyOn(sut, 'getTransaction').mockResolvedValue({test: 123} as any);
135
- jest.spyOn(sut, 'verifyTransfer').mockResolvedValue(true as any);
136
- jest.spyOn(sut, 'transferHiveTokens').mockResolvedValue(true as any);
137
-
138
- const memo = JSON.stringify({
139
- hivePayload: {
140
- id: 'hivestream',
141
- name: 'testdice',
142
- action: 'roll',
143
- payload: {
144
- roll: 69
145
- }
146
- }
147
- });
148
-
149
- sut.processOperation(['transfer', { from: 'testuser', amount: '10.000 HBD', memo }], 778782, 'dfjfsdfsdfs4hfkj88787', 'fkjsdkfj', 'fhkjsdhfkjsdf', '2019-06-23' as any);
150
-
151
- await sleep(100);
152
-
153
- expect(contract['roll']).toBeCalled();
154
- expect(sut.getTransaction).toBeCalledWith(778782, 'fhkjsdhfkjsdf');
155
- expect(sut.transferHiveTokens).toBeCalledWith('beggars', 'testuser', '10.000', 'HBD', '[Refund] Invalid bet params.');
156
- });
1
+ import { sleep } from '@hiveio/dhive/lib/utils';
2
+ import { DiceContract } from './../../src/contracts/dice.contract';
3
+ import { Streamer } from '../../src/streamer';
4
+
5
+ describe('Dice Contract', () => {
6
+ let sut: Streamer;
7
+ let contract: DiceContract;
8
+
9
+ beforeEach(() => {
10
+ sut = new Streamer();
11
+ contract = new DiceContract();
12
+
13
+ // @ts-ignore
14
+ sut.api = jest.fn();
15
+ });
16
+
17
+ afterEach(() => {
18
+ sut.stop();
19
+ });
20
+
21
+ afterAll(() => {
22
+ jest.restoreAllMocks();
23
+ });
24
+
25
+ test('Registers the dice contract', () => {
26
+ sut.registerContract('testdice', contract);
27
+
28
+ const findContract = sut['contracts'].find(c => c.name === 'testdice');
29
+
30
+ expect(findContract).not.toBeUndefined();
31
+ });
32
+
33
+ test('User wins a roll', async () => {
34
+ sut.registerContract('testdice', contract);
35
+
36
+ contract['_instance'] = sut;
37
+
38
+ jest.spyOn(contract as any, 'roll');
39
+ jest.spyOn(contract as any, 'getBalance').mockResolvedValue(2000);
40
+
41
+ jest.spyOn(sut, 'getTransaction').mockResolvedValue({test: 123} as any);
42
+ jest.spyOn(sut, 'verifyTransfer').mockResolvedValue(true as any);
43
+ jest.spyOn(sut, 'transferHiveTokens').mockResolvedValue(true as any);
44
+
45
+ const memo = JSON.stringify({
46
+ hivePayload: {
47
+ id: 'hivestream',
48
+ name: 'testdice',
49
+ action: 'roll',
50
+ payload: {
51
+ roll: 69
52
+ }
53
+ }
54
+ });
55
+
56
+ sut.processOperation(['transfer', { from: 'testuser', amount: '9.000 HIVE', memo }], 778782, 'dfjfsdfsdfsd34hfkj88787', 'fkjsdkfj', 'fhkjsdhfkjsdf', '2019-06-23' as any);
57
+
58
+ await sleep(100);
59
+
60
+ expect(contract['roll']).toBeCalled();
61
+ expect(contract['_instance'].getTransaction).toBeCalledWith(778782, 'fhkjsdhfkjsdf');
62
+ expect(contract['_instance'].transferHiveTokens).toBeCalledWith('beggars', 'testuser', '12.391', 'HIVE', 'You won 12.391 HIVE. Roll: 54, Your guess: 69');
63
+ });
64
+
65
+ test('User loses a roll', async () => {
66
+ sut.registerContract('testdice', contract);
67
+
68
+ contract['_instance'] = sut;
69
+
70
+ jest.spyOn(contract as any, 'roll');
71
+ jest.spyOn(contract as any, 'getBalance').mockResolvedValue(2000);
72
+
73
+ jest.spyOn(sut, 'getTransaction').mockResolvedValue({test: 123} as any);
74
+ jest.spyOn(sut, 'verifyTransfer').mockResolvedValue(true as any);
75
+ jest.spyOn(sut, 'transferHiveTokens').mockResolvedValue(true as any);
76
+
77
+ const memo = JSON.stringify({
78
+ hivePayload: {
79
+ id: 'hivestream',
80
+ name: 'testdice',
81
+ action: 'roll',
82
+ payload: {
83
+ roll: 69
84
+ }
85
+ }
86
+ });
87
+
88
+ sut.processOperation(['transfer', { from: 'testuser', amount: '9.000 HIVE', memo }], 778782, 'dfjfsdfsdfs4hfkj88787', 'fkjsdkfj', 'fhkjsdhfkjsdf', '2019-06-23' as any);
89
+
90
+ await sleep(100);
91
+
92
+ expect(contract['roll']).toBeCalled();
93
+ expect(sut.getTransaction).toBeCalledWith(778782, 'fhkjsdhfkjsdf');
94
+ expect(sut.transferHiveTokens).toBeCalledWith('beggars', 'testuser', '0.001', 'HIVE', 'You lost 9 HIVE. Roll: 81, Your guess: 69');
95
+ });
96
+
97
+ test('User sent an invalid amount, refund them', async () => {
98
+ sut.registerContract('testdice', contract);
99
+
100
+ contract['_instance'] = sut;
101
+
102
+ jest.spyOn(contract as any, 'roll');
103
+ jest.spyOn(contract as any, 'getBalance').mockResolvedValue(2000);
104
+
105
+ jest.spyOn(sut, 'getTransaction').mockResolvedValue({test: 123} as any);
106
+ jest.spyOn(sut, 'verifyTransfer').mockResolvedValue(true as any);
107
+ jest.spyOn(sut, 'transferHiveTokens').mockResolvedValue(true as any);
108
+
109
+ const memo = JSON.stringify({
110
+ hivePayload: {
111
+ id: 'hivestream',
112
+ name: 'testdice',
113
+ action: 'roll',
114
+ payload: {
115
+ roll: 69
116
+ }
117
+ }
118
+ });
119
+
120
+ sut.processOperation(['transfer', { from: 'testuser', amount: '100.000 HIVE', memo }], 778782, 'dfjfsdfsdfs4hfkj88787', 'fkjsdkfj', 'fhkjsdhfkjsdf', '2019-06-23' as any);
121
+
122
+ await sleep(100);
123
+
124
+ expect(contract['roll']).toBeCalled();
125
+ expect(sut.getTransaction).toBeCalledWith(778782, 'fhkjsdhfkjsdf');
126
+ expect(sut.transferHiveTokens).toBeCalledWith('beggars', 'testuser', '100.000', 'HIVE', '[Refund] You sent an invalid bet amount.');
127
+ });
128
+
129
+ test('User sent an unsupported currency, refund them', async () => {
130
+ sut.registerContract('testdice', contract);
131
+
132
+ contract['_instance'] = sut;
133
+
134
+ jest.spyOn(contract as any, 'roll');
135
+ jest.spyOn(contract as any, 'getBalance').mockResolvedValue(2000);
136
+
137
+ jest.spyOn(sut, 'getTransaction').mockResolvedValue({test: 123} as any);
138
+ jest.spyOn(sut, 'verifyTransfer').mockResolvedValue(true as any);
139
+ jest.spyOn(sut, 'transferHiveTokens').mockResolvedValue(true as any);
140
+
141
+ const memo = JSON.stringify({
142
+ hivePayload: {
143
+ id: 'hivestream',
144
+ name: 'testdice',
145
+ action: 'roll',
146
+ payload: {
147
+ roll: 69
148
+ }
149
+ }
150
+ });
151
+
152
+ sut.processOperation(['transfer', { from: 'testuser', amount: '10.000 HBD', memo }], 778782, 'dfjfsdfsdfs4hfkj88787', 'fkjsdkfj', 'fhkjsdhfkjsdf', '2019-06-23' as any);
153
+
154
+ await sleep(100);
155
+
156
+ expect(contract['roll']).toBeCalled();
157
+ expect(sut.getTransaction).toBeCalledWith(778782, 'fhkjsdhfkjsdf');
158
+ expect(sut.transferHiveTokens).toBeCalledWith('beggars', 'testuser', '10.000', 'HBD', '[Refund] Invalid bet params.');
159
+ });
157
160
  });