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
package/tests/setup.ts
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import { GlobalWithFetchMock } from 'jest-fetch-mock';
|
|
2
|
-
|
|
3
|
-
// (global as any).console = {
|
|
4
|
-
// log: jest.fn(), // console.log are ignored in tests
|
|
5
|
-
|
|
6
|
-
// // Keep native behaviour for other methods, use those to print out things in your own tests, not `console.log`
|
|
7
|
-
// error: console.error,
|
|
8
|
-
// warn: console.warn,
|
|
9
|
-
// info: console.info,
|
|
10
|
-
// debug: console.debug,
|
|
11
|
-
// };
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
process.on('unhandledRejection', (error) => {
|
|
20
|
-
throw error; // Or whatever you like...
|
|
1
|
+
import { GlobalWithFetchMock } from 'jest-fetch-mock';
|
|
2
|
+
|
|
3
|
+
// (global as any).console = {
|
|
4
|
+
// log: jest.fn(), // console.log are ignored in tests
|
|
5
|
+
|
|
6
|
+
// // Keep native behaviour for other methods, use those to print out things in your own tests, not `console.log`
|
|
7
|
+
// error: console.error,
|
|
8
|
+
// warn: console.warn,
|
|
9
|
+
// info: console.info,
|
|
10
|
+
// debug: console.debug,
|
|
11
|
+
// };
|
|
12
|
+
|
|
13
|
+
const customGlobal: GlobalWithFetchMock = global as unknown as GlobalWithFetchMock;
|
|
14
|
+
customGlobal.fetch = require('jest-fetch-mock');
|
|
15
|
+
customGlobal.fetchMock = customGlobal.fetch;
|
|
16
|
+
|
|
17
|
+
process.on('unhandledRejection', (error) => {
|
|
18
|
+
throw error; // Or whatever you like...
|
|
21
19
|
});
|
package/tests/streamer.spec.ts
CHANGED
|
@@ -1,152 +1,152 @@
|
|
|
1
|
-
import { TimeAction } from '../src/actions';
|
|
2
|
-
import { Streamer } from '../src/streamer';
|
|
3
|
-
|
|
4
|
-
describe('Streamer', () => {
|
|
5
|
-
let sut: Streamer;
|
|
6
|
-
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
sut = new Streamer({
|
|
9
|
-
JSON_ID: 'testing'
|
|
10
|
-
});
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
afterEach(() => {
|
|
14
|
-
sut.stop();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
describe('Adapters', () => {
|
|
18
|
-
test('Registers adapter and calls the create lifecycle method', () => {
|
|
19
|
-
const adapter = {
|
|
20
|
-
create: jest.fn().mockResolvedValue(true),
|
|
21
|
-
destroy: jest.fn()
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
sut.registerAdapter(adapter);
|
|
25
|
-
|
|
26
|
-
expect(adapter.create).toBeCalled();
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe('Actions', () => {
|
|
31
|
-
test('Registers a new action', async () => {
|
|
32
|
-
const adapter = {
|
|
33
|
-
create: jest.fn().mockResolvedValue(true),
|
|
34
|
-
destroy: jest.fn(),
|
|
35
|
-
loadActions: jest.fn().mockResolvedValue([])
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
sut.registerAdapter(adapter);
|
|
39
|
-
|
|
40
|
-
const action = new TimeAction('1m', 'testoneminute', 'testcontract', 'testmethod');
|
|
41
|
-
|
|
42
|
-
await sut.registerAction(action);
|
|
43
|
-
|
|
44
|
-
const foundAction = sut['actions'].find(a => a.id === 'testoneminute');
|
|
45
|
-
|
|
46
|
-
expect(foundAction).not.toBeUndefined();
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
test('Does not allow duplicate actions of the same id', async () => {
|
|
50
|
-
const adapter = {
|
|
51
|
-
create: jest.fn().mockResolvedValue(true),
|
|
52
|
-
destroy: jest.fn(),
|
|
53
|
-
loadActions: jest.fn().mockResolvedValue([])
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
sut.registerAdapter(adapter);
|
|
57
|
-
|
|
58
|
-
const action = new TimeAction('1m', 'testoneminute', 'testcontract', 'testmethod');
|
|
59
|
-
const action2 = new TimeAction('1m', 'testoneminute', 'testcontract', 'testmethod');
|
|
60
|
-
|
|
61
|
-
await sut.registerAction(action);
|
|
62
|
-
await sut.registerAction(action2);
|
|
63
|
-
|
|
64
|
-
expect(sut['actions'].length).toStrictEqual(1);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
test('Registers actions loaded from adapter loadActions call', async () => {
|
|
68
|
-
const adapter = {
|
|
69
|
-
create: jest.fn().mockResolvedValue(true),
|
|
70
|
-
destroy: jest.fn(),
|
|
71
|
-
loadActions: jest.fn().mockResolvedValue([new TimeAction('1m', 'testoneminute', 'testcontract', 'testmethod')])
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
sut.registerAdapter(adapter);
|
|
75
|
-
|
|
76
|
-
const action = new TimeAction('1h', 'testonehour', 'testcontract', 'testmethod');
|
|
77
|
-
|
|
78
|
-
await sut.registerAction(action);
|
|
79
|
-
|
|
80
|
-
const foundAction = sut['actions'].find(a => a.id === 'testoneminute');
|
|
81
|
-
|
|
82
|
-
expect(foundAction).not.toBeUndefined();
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
describe('Contracts', () => {
|
|
87
|
-
test('Should register a new contract', () => {
|
|
88
|
-
const contract = {
|
|
89
|
-
myMethod: jest.fn()
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
sut.registerContract('testcontract', contract);
|
|
93
|
-
|
|
94
|
-
expect(contract['_instance']).toBeInstanceOf(Streamer);
|
|
95
|
-
expect(sut['contracts'].length).toStrictEqual(1);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
test('Should register a new contract and call its create method', () => {
|
|
99
|
-
const contract = {
|
|
100
|
-
create: jest.fn(),
|
|
101
|
-
myMethod: jest.fn()
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
sut.registerContract('testcontract', contract);
|
|
105
|
-
|
|
106
|
-
expect(contract.create).toBeCalled();
|
|
107
|
-
expect(contract['_instance']).toBeInstanceOf(Streamer);
|
|
108
|
-
expect(sut['contracts'].length).toStrictEqual(1);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
test('Should unregister a registered contract', () => {
|
|
112
|
-
const contract = {
|
|
113
|
-
myMethod: jest.fn()
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
sut.registerContract('testcontract', contract);
|
|
117
|
-
sut.unregisterContract('testcontract');
|
|
118
|
-
|
|
119
|
-
expect(sut['contracts'].length).toStrictEqual(0);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
test('Should unregister a registered contract and call its destroy method', () => {
|
|
123
|
-
const contract = {
|
|
124
|
-
destroy: jest.fn(),
|
|
125
|
-
myMethod: jest.fn()
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
sut.registerContract('testcontract', contract);
|
|
129
|
-
sut.unregisterContract('testcontract');
|
|
130
|
-
|
|
131
|
-
expect(contract.destroy).toBeCalled();
|
|
132
|
-
expect(sut['contracts'].length).toStrictEqual(0);
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
test('Start method should resume from previous block number', async () => {
|
|
137
|
-
const adapter = {
|
|
138
|
-
loadState: jest.fn().mockResolvedValue({ lastBlockNumber: 509992 })
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
sut.registerAdapter(adapter);
|
|
142
|
-
|
|
143
|
-
jest.spyOn(sut as any, 'getBlock').mockImplementation(() => true);
|
|
144
|
-
jest.spyOn(sut as any, 'getLatestBlock').mockImplementation(() => true);
|
|
145
|
-
|
|
146
|
-
await sut.start();
|
|
147
|
-
|
|
148
|
-
expect(sut['lastBlockNumber']).toStrictEqual(509992);
|
|
149
|
-
|
|
150
|
-
sut.stop();
|
|
151
|
-
});
|
|
1
|
+
import { TimeAction } from '../src/actions';
|
|
2
|
+
import { Streamer } from '../src/streamer';
|
|
3
|
+
|
|
4
|
+
describe('Streamer', () => {
|
|
5
|
+
let sut: Streamer;
|
|
6
|
+
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
sut = new Streamer({
|
|
9
|
+
JSON_ID: 'testing'
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
sut.stop();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe('Adapters', () => {
|
|
18
|
+
test('Registers adapter and calls the create lifecycle method', () => {
|
|
19
|
+
const adapter = {
|
|
20
|
+
create: jest.fn().mockResolvedValue(true),
|
|
21
|
+
destroy: jest.fn()
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
sut.registerAdapter(adapter);
|
|
25
|
+
|
|
26
|
+
expect(adapter.create).toBeCalled();
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe('Actions', () => {
|
|
31
|
+
test('Registers a new action', async () => {
|
|
32
|
+
const adapter = {
|
|
33
|
+
create: jest.fn().mockResolvedValue(true),
|
|
34
|
+
destroy: jest.fn(),
|
|
35
|
+
loadActions: jest.fn().mockResolvedValue([])
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
sut.registerAdapter(adapter);
|
|
39
|
+
|
|
40
|
+
const action = new TimeAction('1m', 'testoneminute', 'testcontract', 'testmethod');
|
|
41
|
+
|
|
42
|
+
await sut.registerAction(action);
|
|
43
|
+
|
|
44
|
+
const foundAction = sut['actions'].find(a => a.id === 'testoneminute');
|
|
45
|
+
|
|
46
|
+
expect(foundAction).not.toBeUndefined();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('Does not allow duplicate actions of the same id', async () => {
|
|
50
|
+
const adapter = {
|
|
51
|
+
create: jest.fn().mockResolvedValue(true),
|
|
52
|
+
destroy: jest.fn(),
|
|
53
|
+
loadActions: jest.fn().mockResolvedValue([])
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
sut.registerAdapter(adapter);
|
|
57
|
+
|
|
58
|
+
const action = new TimeAction('1m', 'testoneminute', 'testcontract', 'testmethod');
|
|
59
|
+
const action2 = new TimeAction('1m', 'testoneminute', 'testcontract', 'testmethod');
|
|
60
|
+
|
|
61
|
+
await sut.registerAction(action);
|
|
62
|
+
await sut.registerAction(action2);
|
|
63
|
+
|
|
64
|
+
expect(sut['actions'].length).toStrictEqual(1);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('Registers actions loaded from adapter loadActions call', async () => {
|
|
68
|
+
const adapter = {
|
|
69
|
+
create: jest.fn().mockResolvedValue(true),
|
|
70
|
+
destroy: jest.fn(),
|
|
71
|
+
loadActions: jest.fn().mockResolvedValue([new TimeAction('1m', 'testoneminute', 'testcontract', 'testmethod')])
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
sut.registerAdapter(adapter);
|
|
75
|
+
|
|
76
|
+
const action = new TimeAction('1h', 'testonehour', 'testcontract', 'testmethod');
|
|
77
|
+
|
|
78
|
+
await sut.registerAction(action);
|
|
79
|
+
|
|
80
|
+
const foundAction = sut['actions'].find(a => a.id === 'testoneminute');
|
|
81
|
+
|
|
82
|
+
expect(foundAction).not.toBeUndefined();
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe('Contracts', () => {
|
|
87
|
+
test('Should register a new contract', () => {
|
|
88
|
+
const contract = {
|
|
89
|
+
myMethod: jest.fn()
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
sut.registerContract('testcontract', contract);
|
|
93
|
+
|
|
94
|
+
expect(contract['_instance']).toBeInstanceOf(Streamer);
|
|
95
|
+
expect(sut['contracts'].length).toStrictEqual(1);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test('Should register a new contract and call its create method', () => {
|
|
99
|
+
const contract = {
|
|
100
|
+
create: jest.fn(),
|
|
101
|
+
myMethod: jest.fn()
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
sut.registerContract('testcontract', contract);
|
|
105
|
+
|
|
106
|
+
expect(contract.create).toBeCalled();
|
|
107
|
+
expect(contract['_instance']).toBeInstanceOf(Streamer);
|
|
108
|
+
expect(sut['contracts'].length).toStrictEqual(1);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test('Should unregister a registered contract', () => {
|
|
112
|
+
const contract = {
|
|
113
|
+
myMethod: jest.fn()
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
sut.registerContract('testcontract', contract);
|
|
117
|
+
sut.unregisterContract('testcontract');
|
|
118
|
+
|
|
119
|
+
expect(sut['contracts'].length).toStrictEqual(0);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test('Should unregister a registered contract and call its destroy method', () => {
|
|
123
|
+
const contract = {
|
|
124
|
+
destroy: jest.fn(),
|
|
125
|
+
myMethod: jest.fn()
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
sut.registerContract('testcontract', contract);
|
|
129
|
+
sut.unregisterContract('testcontract');
|
|
130
|
+
|
|
131
|
+
expect(contract.destroy).toBeCalled();
|
|
132
|
+
expect(sut['contracts'].length).toStrictEqual(0);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test('Start method should resume from previous block number', async () => {
|
|
137
|
+
const adapter = {
|
|
138
|
+
loadState: jest.fn().mockResolvedValue({ lastBlockNumber: 509992 })
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
sut.registerAdapter(adapter);
|
|
142
|
+
|
|
143
|
+
jest.spyOn(sut as any, 'getBlock').mockImplementation(() => true);
|
|
144
|
+
jest.spyOn(sut as any, 'getLatestBlock').mockImplementation(() => true);
|
|
145
|
+
|
|
146
|
+
await sut.start();
|
|
147
|
+
|
|
148
|
+
expect(sut['lastBlockNumber']).toStrictEqual(509992);
|
|
149
|
+
|
|
150
|
+
sut.stop();
|
|
151
|
+
});
|
|
152
152
|
});
|
package/tests/utils.spec.ts
CHANGED
|
@@ -1,100 +1,95 @@
|
|
|
1
|
-
import { Utils } from './../src/utils';
|
|
2
|
-
|
|
3
|
-
describe('Utils', () => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
expect(Utils.roundPrecision(
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
test('Generates a memo
|
|
45
|
-
expect(Utils.randomString(
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
test('Should generate
|
|
55
|
-
expect(Utils.randomRange(
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
test('
|
|
59
|
-
expect(Utils.randomRange(
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test('
|
|
63
|
-
expect(Utils.randomRange(
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
expect(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
test('Gets a transfer URL string', () => {
|
|
96
|
-
expect(Utils.getTransferUrl('beggars', 'TEST123', '10.000 HIVE', 'http://localhost:5001')).toStrictEqual(`https://hivesigner.com/sign/transfer?to=beggars&memo=TEST123&amount=10.000 HIVE&redirect_uri=http://localhost:5001`);
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
|
|
1
|
+
import { Utils } from './../src/utils';
|
|
2
|
+
|
|
3
|
+
describe('Utils', () => {
|
|
4
|
+
|
|
5
|
+
describe('Round Precision', () => {
|
|
6
|
+
test('Properly rounds precision of number to 3 places', () => {
|
|
7
|
+
const value = 99.299223;
|
|
8
|
+
|
|
9
|
+
expect(Utils.roundPrecision(value, 3)).toStrictEqual(99.299);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test('Properly rounds precision of number up and to 3 places', () => {
|
|
13
|
+
const value = 99.2966;
|
|
14
|
+
|
|
15
|
+
expect(Utils.roundPrecision(value, 3)).toStrictEqual(99.297);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test('Invalid numeric values passed', () => {
|
|
19
|
+
expect(Utils.roundPrecision('dasd', 3)).toBeNaN();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('Should generate two deterministic numbers', () => {
|
|
24
|
+
// Should generate a deterministic random number
|
|
25
|
+
expect(Utils.randomNumber('dasdasdas', '2312fsdfsdfsdf', 'kfjlksdjflksdjf999')).toStrictEqual(26);
|
|
26
|
+
|
|
27
|
+
expect(Utils.randomNumber('fdfsdfsdfsdfsf', '2312fsdfsdfsdf', 'kfjlksdjflksdjf999')).toStrictEqual(43);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('Should shuffle array in a non-deterministic way', () => {
|
|
31
|
+
const array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];
|
|
32
|
+
const arrayCloned = [...array];
|
|
33
|
+
|
|
34
|
+
Utils.shuffle(array);
|
|
35
|
+
|
|
36
|
+
expect(array).not.toMatchObject(arrayCloned);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe('Generate String', () => {
|
|
40
|
+
test('Generates a memo 6 characters in length', () => {
|
|
41
|
+
expect(Utils.randomString(6)).toHaveLength(6);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('Generates a memo using default 12 character length', () => {
|
|
45
|
+
expect(Utils.randomString()).toHaveLength(12);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe('Random Range', () => {
|
|
50
|
+
test('Should generate a random number between 0 and 10', () => {
|
|
51
|
+
expect(Utils.randomRange(0, 10)).toBeLessThanOrEqual(10);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('Should generate the number 10', () => {
|
|
55
|
+
expect(Utils.randomRange(10, 10)).toStrictEqual(10);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('Only pass min and not max', () => {
|
|
59
|
+
expect(Utils.randomRange(0)).toBeLessThanOrEqual(2000);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('Pass non numeric values to random range', () => {
|
|
63
|
+
expect(Utils.randomRange('dd' as any, 'asjj' as any)).toBeNaN();
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('Convert Hive Amount', () => {
|
|
68
|
+
test('Converts amount', async () => {
|
|
69
|
+
const amount = 25;
|
|
70
|
+
const fiatSymbol = 'USD';
|
|
71
|
+
const hiveSymbol = 'HIVE';
|
|
72
|
+
|
|
73
|
+
(fetch as any)
|
|
74
|
+
.once(JSON.stringify({'success':true,'message':'','result':{'Bid':6905.98900000,'Ask':6925.65900000,'Last':6925.66500000}}))
|
|
75
|
+
.once(JSON.stringify({'success':true,'message':'','result':{'Bid':0.00003083,'Ask':0.00003169,'Last':0.00003192}}))
|
|
76
|
+
.once(JSON.stringify({'success':true,'message':'','result':{'Bid':0.00010800,'Ask':0.00010900,'Last':0.00010800}}))
|
|
77
|
+
.once(JSON.stringify({'rates':{'CAD':1.4383752203,'HKD':7.7558193453,'ISK':140.4989335064,'PHP':51.4003524066,'DKK':6.9281276083,'HUF':326.7458035797,'CZK':25.6283038116,'GBP':0.862190485,'RON':4.4960586108,'SEK':10.2675507744,'IDR':16574.9976815358,'INR':76.1620142817,'BRL':5.0683483261,'RUB':79.8293610313,'HRK':7.053695632,'JPY':110.4609106928,'THB':32.8646944264,'CHF':0.982101456,'EUR':0.9273856997,'MYR':4.4449596587,'BGN':1.8137809515,'TRY':6.5859222851,'CNY':7.0838356673,'NOK':11.3667810442,'NZD':1.7563757767,'ZAR':17.6333116943,'USD':1.0,'MXN':24.6805156264,'SGD':1.4601687842,'AUD':1.7236390615,'ILS':3.6698506909,'KRW':1256.7003616804,'PLN':4.2711675786},'base':'USD','date':'2020-03-23'}));
|
|
78
|
+
|
|
79
|
+
const value = await Utils.convertHiveAmount(amount, fiatSymbol, hiveSymbol);
|
|
80
|
+
|
|
81
|
+
expect(fetch).toBeCalledWith(`https://api.bittrex.com/v3/markets/USD-BTC/ticker`);
|
|
82
|
+
expect(fetch).toBeCalledWith(`https://api.bittrex.com/v3/markets/HIVE-BTC/ticker`);
|
|
83
|
+
expect(fetch).toBeCalledWith(`https://api.bittrex.com/v3/markets/HBD-BTC/ticker`);
|
|
84
|
+
|
|
85
|
+
expect(value).toStrictEqual(113.088);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe('Get transfer URL', () => {
|
|
90
|
+
test('Gets a transfer URL string', () => {
|
|
91
|
+
expect(Utils.getTransferUrl('beggars', 'TEST123', '10.000 HIVE', 'http://localhost:5001')).toStrictEqual(`https://hivesigner.com/sign/transfer?to=beggars&memo=TEST123&amount=10.000 HIVE&redirect_uri=http://localhost:5001`);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
100
95
|
});
|
package/tsconfig.build.json
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"module": "commonjs",
|
|
4
|
-
"esModuleInterop": true,
|
|
5
|
-
"target": "
|
|
6
|
-
"allowSyntheticDefaultImports": true,
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "commonjs",
|
|
4
|
+
"esModuleInterop": true,
|
|
5
|
+
"target": "esnext",
|
|
6
|
+
"allowSyntheticDefaultImports": true,
|
|
7
|
+
"emitDecoratorMetadata": true,
|
|
8
|
+
"experimentalDecorators": true,
|
|
9
|
+
"resolveJsonModule": true,
|
|
10
|
+
"moduleResolution": "node",
|
|
11
|
+
"declaration": true,
|
|
12
|
+
"sourceMap": true,
|
|
13
|
+
"outDir": "dist",
|
|
14
|
+
"baseUrl": ".",
|
|
15
|
+
"paths": {
|
|
16
|
+
"*": [
|
|
17
|
+
"node_modules/*",
|
|
18
|
+
"src/types/*"
|
|
19
|
+
]
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"exclude": ["node_modules", ".vscode", "dist", "tests"]
|
|
21
23
|
}
|
package/tslint.json
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": [
|
|
3
|
-
"tslint:recommended"
|
|
4
|
-
],
|
|
5
|
-
"jsRules": {},
|
|
6
|
-
"rules": {
|
|
7
|
-
"quotemark": [true, "single"],
|
|
8
|
-
"ordered-imports": false,
|
|
9
|
-
"interface-name": false,
|
|
10
|
-
"object-literal-sort-keys": false,
|
|
11
|
-
"eofline": false,
|
|
12
|
-
"no-console": false,
|
|
13
|
-
"member-ordering": false,
|
|
14
|
-
"max-line-length": false,
|
|
15
|
-
"trailing-comma": false,
|
|
16
|
-
"no-string-literal": false,
|
|
17
|
-
"arrow-parens": false,
|
|
18
|
-
"object-literal-key-quotes": false
|
|
19
|
-
},
|
|
20
|
-
"rulesDirectory": []
|
|
1
|
+
{
|
|
2
|
+
"extends": [
|
|
3
|
+
"tslint:recommended"
|
|
4
|
+
],
|
|
5
|
+
"jsRules": {},
|
|
6
|
+
"rules": {
|
|
7
|
+
"quotemark": [true, "single"],
|
|
8
|
+
"ordered-imports": false,
|
|
9
|
+
"interface-name": false,
|
|
10
|
+
"object-literal-sort-keys": false,
|
|
11
|
+
"eofline": false,
|
|
12
|
+
"no-console": false,
|
|
13
|
+
"member-ordering": false,
|
|
14
|
+
"max-line-length": false,
|
|
15
|
+
"trailing-comma": false,
|
|
16
|
+
"no-string-literal": false,
|
|
17
|
+
"arrow-parens": false,
|
|
18
|
+
"object-literal-key-quotes": false
|
|
19
|
+
},
|
|
20
|
+
"rulesDirectory": []
|
|
21
21
|
}
|