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,17 +1,17 @@
1
- // PM2 configuration
2
-
3
- module.exports = {
4
- apps: [
5
- {
6
- name: 'steem-stream',
7
- script: 'index.js',
8
- ignore_watch: ['node_modules'],
9
- env: {
10
- NODE_ENV: 'development'
11
- },
12
- env_production: {
13
- NODE_ENV: 'production'
14
- }
15
- }
16
- ]
17
- };
1
+ // PM2 configuration
2
+
3
+ module.exports = {
4
+ apps: [
5
+ {
6
+ name: 'steem-stream',
7
+ script: 'index.js',
8
+ ignore_watch: ['node_modules'],
9
+ env: {
10
+ NODE_ENV: 'development'
11
+ },
12
+ env_production: {
13
+ NODE_ENV: 'production'
14
+ }
15
+ }
16
+ ]
17
+ };
package/jest.config.js CHANGED
@@ -1,14 +1,9 @@
1
- module.exports = {
2
- globals: {
3
- 'ts-jest': {
4
- tsConfig: 'tsconfig.json'
5
- }
6
- },
7
- setupFilesAfterEnv: ["<rootDir>/tests/setup.ts"],
8
- moduleFileExtensions: ['ts', 'js'],
9
- transform: {
10
- '^.+\\.(ts|tsx)$': 'ts-jest'
11
- },
12
- testMatch: ['**/tests/**/*.spec.(ts)'],
13
- testEnvironment: 'node'
1
+ module.exports = {
2
+ setupFilesAfterEnv: ["<rootDir>/tests/setup.ts"],
3
+ moduleFileExtensions: ['ts', 'js'],
4
+ transform: {
5
+ '^.+\\.(ts|tsx)$': 'ts-jest'
6
+ },
7
+ testMatch: ['**/tests/**/*.spec.(ts)'],
8
+ testEnvironment: 'node'
14
9
  };
package/package.json CHANGED
@@ -1,44 +1,48 @@
1
- {
2
- "name": "hive-stream",
3
- "version": "2.0.3",
4
- "description": "A layer for streaming actions on the Hive blockchain and reacting to them.",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "repository": "git@github.com:Vheissu/hive-stream.git",
8
- "author": "Dwayne Charrington <dwaynecharrington@gmail.com>",
9
- "license": "MIT",
10
- "private": false,
11
- "scripts": {
12
- "build": "tsc --project tsconfig.build.json",
13
- "start": "npx ts-node src/test.ts",
14
- "watch": "tsc -w",
15
- "test": "jest --verbose",
16
- "clean-tests": "jest --clearCache"
17
- },
18
- "dependencies": {
19
- "@hivechain/dhive": "^0.13.3",
20
- "bignumber.js": "^9.0.0",
21
- "dotenv": "^8.2.0",
22
- "moment": "^2.24.0",
23
- "mongodb": "^3.5.6",
24
- "node-fetch": "^2.6.0",
25
- "seedrandom": "^3.0.5",
26
- "sqlite3": "^4.1.1",
27
- "sscjs": "^0.0.8"
28
- },
29
- "devDependencies": {
30
- "@types/bytebuffer": "^5.0.40",
31
- "@types/dotenv": "^8.2.0",
32
- "@types/jest": "^25.2.1",
33
- "@types/mongodb": "^3.5.8",
34
- "@types/node": "^13.11.1",
35
- "@types/node-cron": "^2.0.3",
36
- "@types/seedrandom": "^2.4.28",
37
- "@types/sqlite3": "^3.1.6",
38
- "jest": "^25.3.0",
39
- "jest-fetch-mock": "^3.0.3",
40
- "ts-jest": "^25.4.0",
41
- "ts-node": "^8.8.2",
42
- "typescript": "^3.8.3"
43
- }
44
- }
1
+ {
2
+ "name": "hive-stream",
3
+ "version": "2.0.6",
4
+ "description": "A layer for streaming actions on the Hive blockchain and reacting to them.",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "repository": "git@github.com:Vheissu/hive-stream.git",
8
+ "author": "Dwayne Charrington <dwaynecharrington@gmail.com>",
9
+ "license": "MIT",
10
+ "private": false,
11
+ "scripts": {
12
+ "build": "tsc --project tsconfig.build.json",
13
+ "start": "npx ts-node src/test.ts",
14
+ "watch": "tsc -w",
15
+ "test": "jest --verbose",
16
+ "clean-tests": "jest --clearCache"
17
+ },
18
+ "dependencies": {
19
+ "@hiveio/dhive": "^1.2.4",
20
+ "bignumber.js": "^9.1.0",
21
+ "cors": "^2.8.5",
22
+ "dotenv": "^16.0.3",
23
+ "express": "^4.18.2",
24
+ "moment": "^2.29.4",
25
+ "mongodb": "^4.11.0",
26
+ "node-fetch": "^3.2.10",
27
+ "seedrandom": "^3.0.5",
28
+ "sqlite3": "^5.1.2",
29
+ "sscjs": "^0.0.9",
30
+ "uuid": "^9.0.0"
31
+ },
32
+ "devDependencies": {
33
+ "@types/bytebuffer": "^5.0.44",
34
+ "@types/dotenv": "^8.2.0",
35
+ "@types/jest": "^29.2.3",
36
+ "@types/mongodb": "^4.0.7",
37
+ "@types/node": "^18.11.9",
38
+ "@types/node-cron": "^3.0.5",
39
+ "@types/seedrandom": "^3.0.2",
40
+ "jest": "^29.3.1",
41
+ "jest-cli": "^29.3.1",
42
+ "jest-fetch-mock": "^3.0.3",
43
+ "mongodb-memory-server": "^8.9.5",
44
+ "ts-jest": "^29.0.3",
45
+ "ts-node": "^10.9.1",
46
+ "typescript": "^4.9.3"
47
+ }
48
+ }
@@ -1,19 +1,19 @@
1
- 42189228
2
-
3
- hive_keychain.requestCustomJson('beggars', 'hivedice', 'active', JSON.stringify({ hiveContract: { name: 'hivedice', action: 'roll', payload: { roll: 22, direction: 'lesserThan'} } }), 'Test', function(response) {
4
- console.log(response);
5
- });
6
-
7
- 42203941
8
- Transfer memo payload
9
-
10
- {"hiveContract":{"id":"testdice", "name":"hivedice","action":"roll","payload":{"roll":95,"direction":"greaterThan"}}}
11
-
12
- 42208330
13
- Transfer memo, amount higher than max
14
-
15
- 42209768
16
- Transfer memo, valid bet
17
-
18
- 42210252
1
+ 42189228
2
+
3
+ hive_keychain.requestCustomJson('beggars', 'hivedice', 'active', JSON.stringify({ hiveContract: { name: 'hivedice', action: 'roll', payload: { roll: 22, direction: 'lesserThan'} } }), 'Test', function(response) {
4
+ console.log(response);
5
+ });
6
+
7
+ 42203941
8
+ Transfer memo payload
9
+
10
+ {"hiveContract":{"id":"testdice", "name":"hivedice","action":"roll","payload":{"roll":95,"direction":"greaterThan"}}}
11
+
12
+ 42208330
13
+ Transfer memo, amount higher than max
14
+
15
+ 42209768
16
+ Transfer memo, valid bet
17
+
18
+ 42210252
19
19
  Transfer memo, valid bet and greater than
@@ -0,0 +1,43 @@
1
+ import { SqliteAdapter } from "../../src/adapters/sqlite.adapter";
2
+
3
+
4
+ describe('SQLite Adapter', () => {
5
+ let sut: SqliteAdapter;
6
+
7
+ beforeEach(() => {
8
+ sut = new SqliteAdapter();
9
+ });
10
+
11
+ test('find method returns values', async () => {
12
+ jest.spyOn(sut.db, 'all').mockImplementation((query: any, callback: any) => {
13
+ return callback(null, [{ id: 1, name: 'John' }]);
14
+ });
15
+
16
+ const result = await sut.find('USERS', { id: 1, name: 'John' });
17
+
18
+ expect(result).toEqual([{ id: 1, name: 'John' }]);
19
+ expect(sut.db.all).toHaveBeenCalledWith('SELECT * FROM USERS WHERE id = 1 AND name = John', expect.any(Function));
20
+ });
21
+
22
+ test('findOne method returns value', async () => {
23
+ jest.spyOn(sut.db, 'get').mockImplementation((query: any, callback: any) => {
24
+ return callback(null, { id: 1, name: 'John' });
25
+ });
26
+
27
+ const result = await sut.findOne('USERS', { id: 1, name: 'John', email: 'john@hotmail.com' });
28
+
29
+ expect(result).toEqual({ id: 1, name: 'John' });
30
+ expect(sut.db.get).toHaveBeenCalledWith('SELECT * FROM USERS WHERE id = 1 AND name = John AND email = john@hotmail.com', expect.any(Function));
31
+ });
32
+
33
+ test('replace method replaces value', async () => {
34
+ jest.spyOn(sut.db, 'run').mockImplementation((query: any, callback: any) => {
35
+ return callback(null, { id: 1, name: 'John' });
36
+ });
37
+
38
+ const result = await sut.replace('USERS', { id: 1, name: 'John' }, { id: 2, name: 'Johnny' });
39
+
40
+ expect(result).toEqual({ id: 2, name: 'Johnny' });
41
+ expect(sut.db.run).toHaveBeenCalledWith(`REPLACE INTO USERS id = 1 AND name = John VALUES ([object Object])`, expect.any(Function));
42
+ });
43
+ });
@@ -0,0 +1,132 @@
1
+ import * as uuid from 'uuid';
2
+ import { CoinflipContract } from '../../src/contracts/coinflip.contract';
3
+ import { sleep } from '@hiveio/dhive/lib/utils';
4
+ import { Streamer } from '../../src/streamer';
5
+
6
+ describe('Coinflip Contract', () => {
7
+ let sut: Streamer;
8
+ let contract: CoinflipContract;
9
+
10
+ beforeEach(() => {
11
+ sut = new Streamer();
12
+ contract = new CoinflipContract();
13
+
14
+ // @ts-ignore
15
+ sut.api = jest.fn();
16
+ });
17
+
18
+ afterEach(() => {
19
+ sut.stop();
20
+ });
21
+
22
+ afterAll(() => {
23
+ jest.restoreAllMocks();
24
+ });
25
+
26
+ test('Registers the contract', () => {
27
+ sut.registerContract('coinflip', contract);
28
+
29
+ const findContract = sut['contracts'].find(c => c.name === 'coinflip');
30
+
31
+ expect(findContract).not.toBeUndefined();
32
+ });
33
+
34
+ test('User wins a flip', async () => {
35
+ sut.registerContract('coinflip', contract);
36
+
37
+ contract['_instance'] = sut;
38
+
39
+ jest.spyOn(contract as any, 'flip');
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: 'coinflip',
49
+ action: 'flip',
50
+ payload: {
51
+ guess: 'heads',
52
+ seed: 'hj879879g7686876'
53
+ }
54
+ }
55
+ });
56
+
57
+ jest.spyOn(uuid, 'v4').mockReturnValue('j93jgsjghjdhgjfhgkfdhgkj34872394723');
58
+
59
+ sut.processOperation(['transfer', { from: 'testuser', amount: '9.000 HIVE', memo }], 778782, 'dfjfsdfsdfs4hfkj88787', 'fkjs7878dkfj', 'fhkjsdhfkjsdf', '2019-06-23' as any);
60
+
61
+ await sleep(100);
62
+
63
+ expect(contract['flip']).toBeCalled();
64
+ expect(contract['_instance'].getTransaction).toBeCalledWith(778782, 'fhkjsdhfkjsdf');
65
+ expect(contract['_instance'].transferHiveTokens).toBeCalledWith('beggars', 'testuser', '18.000', 'HIVE', '[Winner] | Guess: heads | Server Roll: heads | Previous block id: fkjs7878dkfj | BlockID: dfjfsdfsdfs4hfkj88787 | Trx ID: fhkjsdhfkjsdf | Server Seed: j93jgsjghjdhgjfhgkfdhgkj34872394723');
66
+ });
67
+
68
+ test('User loses a flip', async () => {
69
+ sut.registerContract('coinflip', contract);
70
+
71
+ contract['_instance'] = sut;
72
+
73
+ jest.spyOn(contract as any, 'flip');
74
+
75
+ jest.spyOn(sut, 'getTransaction').mockResolvedValue({test: 123} as any);
76
+ jest.spyOn(sut, 'verifyTransfer').mockResolvedValue(true as any);
77
+ jest.spyOn(sut, 'transferHiveTokens').mockResolvedValue(true as any);
78
+
79
+ const memo = JSON.stringify({
80
+ hivePayload: {
81
+ id: 'hivestream',
82
+ name: 'coinflip',
83
+ action: 'flip',
84
+ payload: {
85
+ guess: 'heads',
86
+ seed: 'tulips'
87
+ }
88
+ }
89
+ });
90
+
91
+ jest.spyOn(uuid, 'v4').mockReturnValue('j93jgsjghjdhgjfhgkfdhgkj34872394723');
92
+
93
+ sut.processOperation(['transfer', { from: 'testuser', amount: '9.000 HIVE', memo }], 778782, 'dfjfsdfsdfs4hfkj88787', 'fkjs7878dkfj', 'fhkjsdhfkjsdf', '2019-06-23' as any);
94
+
95
+ await sleep(100);
96
+
97
+ expect(contract['flip']).toBeCalled();
98
+ expect(contract['_instance'].getTransaction).toBeCalledWith(778782, 'fhkjsdhfkjsdf');
99
+ expect(contract['_instance'].transferHiveTokens).toBeCalledWith('beggars', 'testuser', '0.001', 'HIVE', '[Lost] | Guess: heads | Server Roll: tails | Previous block id: fkjs7878dkfj | BlockID: dfjfsdfsdfs4hfkj88787 | Trx ID: fhkjsdhfkjsdf | Server Seed: j93jgsjghjdhgjfhgkfdhgkj34872394723');
100
+ });
101
+
102
+ test('User sent an unsupported currency, refund them', async () => {
103
+ sut.registerContract('coinflip', contract);
104
+
105
+ contract['_instance'] = sut;
106
+
107
+ jest.spyOn(contract as any, 'flip');
108
+
109
+ jest.spyOn(sut, 'getTransaction').mockResolvedValue({test: 123} as any);
110
+ jest.spyOn(sut, 'verifyTransfer').mockResolvedValue(true as any);
111
+ jest.spyOn(sut, 'transferHiveTokens').mockResolvedValue(true as any);
112
+
113
+ const memo = JSON.stringify({
114
+ hivePayload: {
115
+ id: 'hivestream',
116
+ name: 'coinflip',
117
+ action: 'flip',
118
+ payload: {
119
+ guess: 'heads'
120
+ }
121
+ }
122
+ });
123
+
124
+ sut.processOperation(['transfer', { from: 'testuser', amount: '10.000 HBD', memo }], 778782, 'dfjfsdfsdfs4hfkj88787', 'fkjsdkfj', 'fhkjsdhfkjsdf', '2019-06-23' as any);
125
+
126
+ await sleep(100);
127
+
128
+ expect(contract['flip']).toBeCalled();
129
+ expect(sut.getTransaction).toBeCalledWith(778782, 'fhkjsdhfkjsdf');
130
+ expect(sut.transferHiveTokens).toBeCalledWith('beggars', 'testuser', '10.000', 'HBD', '[Refund] You sent an invalid currency.');
131
+ });
132
+ });