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.
- 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 +8 -13
- package/package.json +48 -44
- 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 +159 -156
- package/tests/contracts/entrants.json +728 -728
- package/tests/contracts/lotto.contract.spec.ts +323 -372
- package/tests/setup.ts +18 -20
- package/tests/streamer.spec.ts +151 -151
- package/tests/utils.spec.ts +94 -99
- package/tsconfig.build.json +22 -20
- package/tslint.json +20 -20
- package/wallaby.js +26 -0
- package/.env +0 -1
- 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/dist/tests/contracts/dice.contract.spec.d.ts +0 -1
- package/dist/tests/contracts/dice.contract.spec.js +0 -130
- package/dist/tests/contracts/dice.contract.spec.js.map +0 -1
- package/dist/tests/contracts/entrants.json +0 -729
- package/dist/tests/contracts/lotto.contract.spec.d.ts +0 -1
- package/dist/tests/contracts/lotto.contract.spec.js +0 -300
- package/dist/tests/contracts/lotto.contract.spec.js.map +0 -1
- package/dist/tests/setup.d.ts +0 -1
- package/dist/tests/setup.js +0 -19
- package/dist/tests/setup.js.map +0 -1
- package/dist/tests/streamer.spec.d.ts +0 -1
- package/dist/tests/streamer.spec.js +0 -123
- package/dist/tests/streamer.spec.js.map +0 -1
- package/dist/tests/utils.spec.d.ts +0 -1
- package/dist/tests/utils.spec.js +0 -87
- package/dist/tests/utils.spec.js.map +0 -1
- package/hive-stream.json +0 -1
|
@@ -1,157 +1,160 @@
|
|
|
1
|
-
import { sleep } from '@
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
jest.spyOn(
|
|
39
|
-
jest.spyOn(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
jest.spyOn(
|
|
71
|
-
jest.spyOn(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
jest.spyOn(
|
|
103
|
-
jest.spyOn(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
jest.spyOn(
|
|
135
|
-
jest.spyOn(
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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
|
});
|