hive-stream 3.0.2 → 3.0.4

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 (202) hide show
  1. package/DOCUMENTATION.md +50 -2
  2. package/README.md +282 -4
  3. package/dist/adapters/base.adapter.d.ts +5 -0
  4. package/dist/adapters/base.adapter.js +9 -0
  5. package/dist/adapters/base.adapter.js.map +1 -1
  6. package/dist/adapters/mongodb.adapter.d.ts +6 -6
  7. package/dist/adapters/mongodb.adapter.js +36 -21
  8. package/dist/adapters/mongodb.adapter.js.map +1 -1
  9. package/dist/adapters/postgresql.adapter.d.ts +7 -0
  10. package/dist/adapters/postgresql.adapter.js +46 -19
  11. package/dist/adapters/postgresql.adapter.js.map +1 -1
  12. package/dist/adapters/sqlite.adapter.d.ts +4 -0
  13. package/dist/adapters/sqlite.adapter.js +10 -0
  14. package/dist/adapters/sqlite.adapter.js.map +1 -1
  15. package/dist/api.d.ts +13 -3
  16. package/dist/api.js +96 -62
  17. package/dist/api.js.map +1 -1
  18. package/dist/builders.d.ts +176 -0
  19. package/dist/builders.js +727 -0
  20. package/dist/builders.js.map +1 -0
  21. package/dist/config.d.ts +16 -1
  22. package/dist/config.js +95 -3
  23. package/dist/config.js.map +1 -1
  24. package/dist/contracts/auctionhouse.contract.d.ts +4 -0
  25. package/dist/contracts/auctionhouse.contract.js +234 -0
  26. package/dist/contracts/auctionhouse.contract.js.map +1 -0
  27. package/dist/contracts/booking.contract.d.ts +4 -0
  28. package/dist/contracts/booking.contract.js +225 -0
  29. package/dist/contracts/booking.contract.js.map +1 -0
  30. package/dist/contracts/bountyboard.contract.d.ts +4 -0
  31. package/dist/contracts/bountyboard.contract.js +233 -0
  32. package/dist/contracts/bountyboard.contract.js.map +1 -0
  33. package/dist/contracts/bundlemarketplace.contract.d.ts +4 -0
  34. package/dist/contracts/bundlemarketplace.contract.js +195 -0
  35. package/dist/contracts/bundlemarketplace.contract.js.map +1 -0
  36. package/dist/contracts/charitymatch.contract.d.ts +4 -0
  37. package/dist/contracts/charitymatch.contract.js +172 -0
  38. package/dist/contracts/charitymatch.contract.js.map +1 -0
  39. package/dist/contracts/coinflip.contract.js +25 -22
  40. package/dist/contracts/coinflip.contract.js.map +1 -1
  41. package/dist/contracts/crowdfund.contract.d.ts +4 -0
  42. package/dist/contracts/crowdfund.contract.js +290 -0
  43. package/dist/contracts/crowdfund.contract.js.map +1 -0
  44. package/dist/contracts/dcabot.contract.d.ts +4 -0
  45. package/dist/contracts/dcabot.contract.js +217 -0
  46. package/dist/contracts/dcabot.contract.js.map +1 -0
  47. package/dist/contracts/dice.contract.js +25 -22
  48. package/dist/contracts/dice.contract.js.map +1 -1
  49. package/dist/contracts/domainregistry.contract.d.ts +4 -0
  50. package/dist/contracts/domainregistry.contract.js +232 -0
  51. package/dist/contracts/domainregistry.contract.js.map +1 -0
  52. package/dist/contracts/exchange.contract.js +209 -168
  53. package/dist/contracts/exchange.contract.js.map +1 -1
  54. package/dist/contracts/fanclub.contract.d.ts +4 -0
  55. package/dist/contracts/fanclub.contract.js +193 -0
  56. package/dist/contracts/fanclub.contract.js.map +1 -0
  57. package/dist/contracts/giftcard.contract.d.ts +4 -0
  58. package/dist/contracts/giftcard.contract.js +158 -0
  59. package/dist/contracts/giftcard.contract.js.map +1 -0
  60. package/dist/contracts/grantrounds.contract.d.ts +4 -0
  61. package/dist/contracts/grantrounds.contract.js +265 -0
  62. package/dist/contracts/grantrounds.contract.js.map +1 -0
  63. package/dist/contracts/groupbuy.contract.d.ts +4 -0
  64. package/dist/contracts/groupbuy.contract.js +198 -0
  65. package/dist/contracts/groupbuy.contract.js.map +1 -0
  66. package/dist/contracts/helpers.d.ts +66 -0
  67. package/dist/contracts/helpers.js +166 -0
  68. package/dist/contracts/helpers.js.map +1 -0
  69. package/dist/contracts/insurancepool.contract.d.ts +4 -0
  70. package/dist/contracts/insurancepool.contract.js +281 -0
  71. package/dist/contracts/insurancepool.contract.js.map +1 -0
  72. package/dist/contracts/invoice.contract.d.ts +4 -0
  73. package/dist/contracts/invoice.contract.js +193 -0
  74. package/dist/contracts/invoice.contract.js.map +1 -0
  75. package/dist/contracts/launchpad.contract.d.ts +4 -0
  76. package/dist/contracts/launchpad.contract.js +225 -0
  77. package/dist/contracts/launchpad.contract.js.map +1 -0
  78. package/dist/contracts/lotto.contract.js +53 -37
  79. package/dist/contracts/lotto.contract.js.map +1 -1
  80. package/dist/contracts/multisigtreasury.contract.d.ts +4 -0
  81. package/dist/contracts/multisigtreasury.contract.js +245 -0
  82. package/dist/contracts/multisigtreasury.contract.js.map +1 -0
  83. package/dist/contracts/nft.contract.d.ts +1 -0
  84. package/dist/contracts/nft.contract.js +234 -195
  85. package/dist/contracts/nft.contract.js.map +1 -1
  86. package/dist/contracts/oraclebounty.contract.d.ts +4 -0
  87. package/dist/contracts/oraclebounty.contract.js +250 -0
  88. package/dist/contracts/oraclebounty.contract.js.map +1 -0
  89. package/dist/contracts/payroll.contract.d.ts +4 -0
  90. package/dist/contracts/payroll.contract.js +232 -0
  91. package/dist/contracts/payroll.contract.js.map +1 -0
  92. package/dist/contracts/paywall.contract.d.ts +4 -0
  93. package/dist/contracts/paywall.contract.js +185 -0
  94. package/dist/contracts/paywall.contract.js.map +1 -0
  95. package/dist/contracts/poll.contract.js +2 -0
  96. package/dist/contracts/poll.contract.js.map +1 -1
  97. package/dist/contracts/predictionmarket.contract.d.ts +4 -0
  98. package/dist/contracts/predictionmarket.contract.js +213 -0
  99. package/dist/contracts/predictionmarket.contract.js.map +1 -0
  100. package/dist/contracts/proposaltimelock.contract.d.ts +4 -0
  101. package/dist/contracts/proposaltimelock.contract.js +250 -0
  102. package/dist/contracts/proposaltimelock.contract.js.map +1 -0
  103. package/dist/contracts/questpass.contract.d.ts +4 -0
  104. package/dist/contracts/questpass.contract.js +214 -0
  105. package/dist/contracts/questpass.contract.js.map +1 -0
  106. package/dist/contracts/referral.contract.d.ts +4 -0
  107. package/dist/contracts/referral.contract.js +238 -0
  108. package/dist/contracts/referral.contract.js.map +1 -0
  109. package/dist/contracts/rental.contract.d.ts +4 -0
  110. package/dist/contracts/rental.contract.js +221 -0
  111. package/dist/contracts/rental.contract.js.map +1 -0
  112. package/dist/contracts/revenuesplit.contract.d.ts +4 -0
  113. package/dist/contracts/revenuesplit.contract.js +211 -0
  114. package/dist/contracts/revenuesplit.contract.js.map +1 -0
  115. package/dist/contracts/rps.contract.js +48 -20
  116. package/dist/contracts/rps.contract.js.map +1 -1
  117. package/dist/contracts/savings.contract.d.ts +4 -0
  118. package/dist/contracts/savings.contract.js +208 -0
  119. package/dist/contracts/savings.contract.js.map +1 -0
  120. package/dist/contracts/subscription.contract.d.ts +4 -0
  121. package/dist/contracts/subscription.contract.js +241 -0
  122. package/dist/contracts/subscription.contract.js.map +1 -0
  123. package/dist/contracts/sweepstakes.contract.d.ts +4 -0
  124. package/dist/contracts/sweepstakes.contract.js +209 -0
  125. package/dist/contracts/sweepstakes.contract.js.map +1 -0
  126. package/dist/contracts/ticketing.contract.d.ts +4 -0
  127. package/dist/contracts/ticketing.contract.js +185 -0
  128. package/dist/contracts/ticketing.contract.js.map +1 -0
  129. package/dist/contracts/tipjar.contract.js +2 -0
  130. package/dist/contracts/tipjar.contract.js.map +1 -1
  131. package/dist/contracts/token.contract.js +135 -125
  132. package/dist/contracts/token.contract.js.map +1 -1
  133. package/dist/index.d.ts +40 -0
  134. package/dist/index.js +72 -1
  135. package/dist/index.js.map +1 -1
  136. package/dist/metadata.d.ts +20 -0
  137. package/dist/metadata.js +320 -1
  138. package/dist/metadata.js.map +1 -1
  139. package/dist/providers/block-provider.d.ts +22 -0
  140. package/dist/providers/block-provider.js +3 -0
  141. package/dist/providers/block-provider.js.map +1 -0
  142. package/dist/providers/haf-client.d.ts +30 -0
  143. package/dist/providers/haf-client.js +119 -0
  144. package/dist/providers/haf-client.js.map +1 -0
  145. package/dist/providers/haf-provider.d.ts +49 -0
  146. package/dist/providers/haf-provider.js +256 -0
  147. package/dist/providers/haf-provider.js.map +1 -0
  148. package/dist/providers/hive-provider.d.ts +13 -0
  149. package/dist/providers/hive-provider.js +25 -0
  150. package/dist/providers/hive-provider.js.map +1 -0
  151. package/dist/providers/index.d.ts +4 -0
  152. package/dist/providers/index.js +21 -0
  153. package/dist/providers/index.js.map +1 -0
  154. package/dist/streamer.d.ts +65 -4
  155. package/dist/streamer.js +768 -72
  156. package/dist/streamer.js.map +1 -1
  157. package/dist/types/hive-stream.d.ts +317 -0
  158. package/dist/utils.d.ts +33 -0
  159. package/dist/utils.js +198 -2
  160. package/dist/utils.js.map +1 -1
  161. package/package.json +16 -1
  162. package/.claude/settings.local.json +0 -12
  163. package/.env.example +0 -3
  164. package/.travis.yml +0 -11
  165. package/AGENTS.md +0 -35
  166. package/CLAUDE.md +0 -75
  167. package/ecosystem.config.js +0 -17
  168. package/examples/contracts/README.md +0 -8
  169. package/examples/contracts/exchange.ts +0 -38
  170. package/examples/contracts/poll.ts +0 -21
  171. package/examples/contracts/rps.ts +0 -19
  172. package/examples/contracts/tipjar.ts +0 -19
  173. package/jest.config.js +0 -9
  174. package/test-contract-block.md +0 -19
  175. package/tests/actions.spec.ts +0 -252
  176. package/tests/adapters/actions-persistence.spec.ts +0 -144
  177. package/tests/adapters/postgresql.adapter.spec.ts +0 -127
  178. package/tests/adapters/sqlite.adapter.spec.ts +0 -181
  179. package/tests/config-input.spec.ts +0 -90
  180. package/tests/contracts/coinflip.contract.spec.ts +0 -94
  181. package/tests/contracts/dice.contract.spec.ts +0 -87
  182. package/tests/contracts/entrants.json +0 -729
  183. package/tests/contracts/exchange.contract.spec.ts +0 -84
  184. package/tests/contracts/lotto.contract.spec.ts +0 -59
  185. package/tests/contracts/nft.contract.spec.ts +0 -948
  186. package/tests/contracts/token.contract.spec.ts +0 -90
  187. package/tests/exchanges/coingecko.exchange.spec.ts +0 -169
  188. package/tests/exchanges/exchange.base.spec.ts +0 -246
  189. package/tests/helpers/mock-adapter.ts +0 -214
  190. package/tests/helpers/mock-fetch.ts +0 -165
  191. package/tests/hive-chain-features.spec.ts +0 -319
  192. package/tests/hive-rates.spec.ts +0 -443
  193. package/tests/integration/hive-rates.integration.spec.ts +0 -35
  194. package/tests/metadata.spec.ts +0 -63
  195. package/tests/setup.ts +0 -30
  196. package/tests/streamer-actions.spec.ts +0 -274
  197. package/tests/streamer.spec.ts +0 -342
  198. package/tests/types/rates.spec.ts +0 -216
  199. package/tests/utils.spec.ts +0 -113
  200. package/tsconfig.build.json +0 -4
  201. package/tslint.json +0 -21
  202. package/wallaby.js +0 -26
@@ -1,181 +0,0 @@
1
- import { SqliteAdapter } from "../../src/adapters/sqlite.adapter";
2
- import fs from 'fs';
3
- import path from 'path';
4
-
5
- describe('SQLite Adapter', () => {
6
- let sut: SqliteAdapter;
7
- let testDbPath: string;
8
-
9
- beforeEach(async () => {
10
- testDbPath = path.resolve(__dirname, `../../src/adapters/hive-stream-test-basic-${Date.now()}-${Math.random()}.db`);
11
-
12
- if (fs.existsSync(testDbPath)) {
13
- fs.unlinkSync(testDbPath);
14
- }
15
-
16
- sut = new SqliteAdapter(testDbPath);
17
- await sut.create();
18
- });
19
-
20
- afterEach(async () => {
21
- if (sut && sut.getDb()) {
22
- await sut.destroy();
23
- }
24
-
25
- if (fs.existsSync(testDbPath)) {
26
- fs.unlinkSync(testDbPath);
27
- }
28
- });
29
-
30
- test('find method returns values', async () => {
31
- // Create a test table
32
- await sut.db.schema.createTableIfNotExists('USERS', table => {
33
- table.integer('id');
34
- table.string('name');
35
- });
36
-
37
- // Insert test data
38
- await sut.db('USERS').insert({ id: 1, name: 'John' });
39
-
40
- const result = await sut.find('USERS', { id: 1, name: 'John' });
41
-
42
- expect(result).toEqual([{ id: 1, name: 'John' }]);
43
- });
44
-
45
- test('findOne method returns value', async () => {
46
- // Create a test table
47
- await sut.db.schema.createTableIfNotExists('USERS', table => {
48
- table.integer('id');
49
- table.string('name');
50
- table.string('email');
51
- });
52
-
53
- // Insert test data
54
- await sut.db('USERS').insert({ id: 1, name: 'John', email: 'john@hotmail.com' });
55
-
56
- const result = await sut.findOne('USERS', { id: 1, name: 'John', email: 'john@hotmail.com' });
57
-
58
- expect(result).toEqual({ id: 1, name: 'John', email: 'john@hotmail.com' });
59
- });
60
-
61
- test('replace method replaces value', async () => {
62
- // Create a test table
63
- await sut.db.schema.createTableIfNotExists('USERS', table => {
64
- table.integer('id').primary();
65
- table.string('name');
66
- });
67
-
68
- // Insert initial data
69
- await sut.db('USERS').insert({ id: 1, name: 'John' });
70
-
71
- const result = await sut.replace('USERS', { id: 1 }, { id: 1, name: 'Johnny' });
72
-
73
- expect(result).toEqual({ id: 1, name: 'Johnny' });
74
-
75
- // Verify the data was actually replaced
76
- const updatedRecord = await sut.db('USERS').where({ id: 1 }).first();
77
- expect(updatedRecord).toEqual({ id: 1, name: 'Johnny' });
78
- });
79
-
80
- test('insert method inserts values', async () => {
81
- // Create a test table
82
- await sut.db.schema.createTableIfNotExists('USERS', table => {
83
- table.integer('id');
84
- table.string('name');
85
- });
86
-
87
- const result = await sut.insert('USERS', { id: 1, name: 'Alice' });
88
-
89
- expect(result).toBe(true);
90
-
91
- // Verify the data was actually inserted
92
- const insertedRecord = await sut.db('USERS').where({ id: 1 }).first();
93
- expect(insertedRecord).toEqual({ id: 1, name: 'Alice' });
94
- });
95
-
96
- test('loadState and saveState work correctly', async () => {
97
- const testData = {
98
- lastBlockNumber: 12345,
99
- actions: [{ id: 'test-action', type: 'test' }]
100
- };
101
-
102
- // Save state
103
- const saveResult = await sut.saveState(testData);
104
- expect(saveResult).toBe(true);
105
-
106
- // Load state
107
- const loadedState = await sut.loadState();
108
- expect(loadedState?.lastBlockNumber).toBe(12345);
109
- expect(loadedState?.actions).toEqual([{ id: 'test-action', type: 'test' }]);
110
- });
111
-
112
- test('processTransfer works correctly', async () => {
113
- const mockPayload = {
114
- contract: 'test-contract',
115
- action: 'transfer',
116
- payload: { amount: '100', recipient: 'bob' }
117
- };
118
-
119
- const mockMetadata = {
120
- sender: 'alice',
121
- amount: '100 HIVE'
122
- };
123
-
124
- // Set up transaction context
125
- await sut.processOperation({}, 12345, 'block123', 'prevblock', 'tx123', new Date());
126
-
127
- const result = await sut.processTransfer({}, mockPayload, mockMetadata);
128
- expect(result).toBe(true);
129
-
130
- // Verify the transfer was stored
131
- const transfers = await sut.getTransfers();
132
- expect(transfers).toHaveLength(1);
133
- expect(transfers[0].sender).toBe('alice');
134
- expect(transfers[0].contractName).toBe('test-contract');
135
- });
136
-
137
- test('processCustomJson works correctly', async () => {
138
- const mockPayload = {
139
- contract: 'test-contract',
140
- action: 'custom',
141
- payload: { data: 'test' }
142
- };
143
-
144
- const mockMetadata = {
145
- sender: 'alice',
146
- isSignedWithActiveKey: true
147
- };
148
-
149
- // Set up transaction context
150
- await sut.processOperation({}, 12345, 'block123', 'prevblock', 'tx123', new Date());
151
-
152
- const result = await sut.processCustomJson({}, mockPayload, mockMetadata);
153
- expect(result).toBe(true);
154
-
155
- // Verify the custom JSON was stored
156
- const customJson = await sut.getJson();
157
- expect(customJson).toHaveLength(1);
158
- expect(customJson[0].sender).toBe('alice');
159
- expect(customJson[0].contractName).toBe('test-contract');
160
- expect(customJson[0].isSignedWithActiveKey).toBe(1);
161
- });
162
-
163
- test('query method executes raw SQL', async () => {
164
- // Create a test table
165
- await sut.db.schema.createTableIfNotExists('USERS', table => {
166
- table.integer('id');
167
- table.string('name');
168
- });
169
-
170
- // Insert test data
171
- await sut.db('USERS').insert({ id: 1, name: 'Alice' });
172
- await sut.db('USERS').insert({ id: 2, name: 'Bob' });
173
-
174
- // Test raw SQL query
175
- const result = await sut.query('SELECT * FROM USERS WHERE name = ?', ['Alice']);
176
-
177
- expect(result).toHaveLength(1);
178
- expect(result[0].name).toBe('Alice');
179
- expect(result[0].id).toBe(1);
180
- });
181
- });
@@ -1,90 +0,0 @@
1
- import { createConfig, normalizeConfigInput } from '../src/config';
2
- import { Streamer } from '../src/streamer';
3
-
4
- describe('Config input aliases', () => {
5
- test('maps camelCase keys to canonical config keys', () => {
6
- const normalized = normalizeConfigInput({
7
- activeKey: 'active',
8
- postingKey: 'posting',
9
- username: 'alice',
10
- jsonId: 'builder',
11
- payloadIdentifier: 'payload',
12
- blockCheckInterval: 1500,
13
- blocksBehindWarning: 30,
14
- resumeFromState: false,
15
- catchUpBatchSize: 10,
16
- catchUpDelayMs: 25,
17
- apiNodes: ['https://api.hive.blog'],
18
- debugMode: false
19
- });
20
-
21
- expect(normalized.ACTIVE_KEY).toBe('active');
22
- expect(normalized.POSTING_KEY).toBe('posting');
23
- expect(normalized.USERNAME).toBe('alice');
24
- expect(normalized.JSON_ID).toBe('builder');
25
- expect(normalized.PAYLOAD_IDENTIFIER).toBe('payload');
26
- expect(normalized.BLOCK_CHECK_INTERVAL).toBe(1500);
27
- expect(normalized.BLOCKS_BEHIND_WARNING).toBe(30);
28
- expect(normalized.RESUME_FROM_STATE).toBe(false);
29
- expect(normalized.CATCH_UP_BATCH_SIZE).toBe(10);
30
- expect(normalized.CATCH_UP_DELAY_MS).toBe(25);
31
- expect(normalized.API_NODES).toEqual(['https://api.hive.blog']);
32
- expect(normalized.DEBUG_MODE).toBe(false);
33
- });
34
-
35
- test('canonical keys override camelCase aliases when both are supplied', () => {
36
- const normalized = normalizeConfigInput({
37
- JSON_ID: 'canonical-id',
38
- jsonId: 'alias-id'
39
- });
40
-
41
- expect(normalized.JSON_ID).toBe('canonical-id');
42
- });
43
-
44
- test('createConfig merges aliases with defaults', () => {
45
- const config = createConfig({
46
- jsonId: 'custom-json-id',
47
- debugMode: false
48
- });
49
-
50
- expect(config.JSON_ID).toBe('custom-json-id');
51
- expect(config.DEBUG_MODE).toBe(false);
52
- expect(Array.isArray(config.API_NODES)).toBe(true);
53
- });
54
-
55
- test('Streamer constructor accepts camelCase config keys', async () => {
56
- const sut = new Streamer({
57
- username: 'builder-user',
58
- postingKey: 'posting-key',
59
- activeKey: 'active-key',
60
- jsonId: 'custom-id'
61
- });
62
-
63
- expect(sut['config'].JSON_ID).toBe('custom-id');
64
- expect(sut['username']).toBe('builder-user');
65
- expect(sut['postingKey']).toBe('posting-key');
66
- expect(sut['activeKey']).toBe('active-key');
67
-
68
- await sut.stop();
69
- });
70
-
71
- test('Streamer.setConfig accepts camelCase config keys', async () => {
72
- const sut = new Streamer();
73
-
74
- sut.setConfig({
75
- username: 'updated-user',
76
- postingKey: 'updated-posting',
77
- activeKey: 'updated-active',
78
- blockCheckInterval: 333,
79
- debugMode: false
80
- });
81
-
82
- expect(sut['config'].BLOCK_CHECK_INTERVAL).toBe(333);
83
- expect(sut['config'].DEBUG_MODE).toBe(false);
84
- expect(sut['username']).toBe('updated-user');
85
- expect(sut['postingKey']).toBe('updated-posting');
86
- expect(sut['activeKey']).toBe('updated-active');
87
-
88
- await sut.stop();
89
- });
90
- });
@@ -1,94 +0,0 @@
1
- import { createCoinflipContract } from '../../src/contracts/coinflip.contract';
2
- import { sleep } from '@hiveio/dhive/lib/utils';
3
- import { Streamer } from '../../src/streamer';
4
- import { createMockAdapter } from '../helpers/mock-adapter';
5
-
6
- jest.mock('uuid', () => ({
7
- v4: jest.fn()
8
- }));
9
-
10
- import { v4 as uuidv4 } from 'uuid';
11
-
12
- describe('Coinflip Contract', () => {
13
- let sut: Streamer;
14
- let contract: ReturnType<typeof createCoinflipContract>;
15
-
16
- beforeEach(async () => {
17
- sut = new Streamer();
18
- await sut.registerAdapter(createMockAdapter());
19
- contract = createCoinflipContract();
20
-
21
- // @ts-ignore
22
- sut.api = jest.fn();
23
- });
24
-
25
- afterEach(async () => {
26
- await sut.stop();
27
- jest.restoreAllMocks();
28
- });
29
-
30
- test('Registers the contract', async () => {
31
- await sut.registerContract(contract);
32
-
33
- const findContract = sut['contracts'].find(c => c.name === 'coinflip');
34
- expect(findContract).not.toBeUndefined();
35
- });
36
-
37
- test('User wins a flip', async () => {
38
- await sut.registerContract(contract);
39
-
40
- jest.spyOn(sut, 'getTransaction').mockResolvedValue({ test: 123 } as any);
41
- jest.spyOn(sut, 'verifyTransfer').mockResolvedValue(true as any);
42
- jest.spyOn(sut, 'transferHiveTokens').mockResolvedValue(true as any);
43
- jest.spyOn(sut['client'].database, 'getAccounts').mockResolvedValue([{ balance: '2000.000 HIVE' }] as any);
44
-
45
- (uuidv4 as jest.Mock).mockReturnValue('j93jgsjghjdhgjfhgkfdhgkj34872394723');
46
-
47
- const memo = JSON.stringify({
48
- hive_stream: {
49
- contract: 'coinflip',
50
- action: 'flip',
51
- payload: {
52
- guess: 'heads',
53
- seed: 'hj879879g7686876'
54
- }
55
- }
56
- });
57
-
58
- await sut.processOperation(['transfer', { from: 'testuser', amount: '9.000 HIVE', memo }], 778782, 'dfjfsdfsdfs4hfkj88787', 'fkjs7878dkfj', 'fhkjsdhfkjsdf', '2019-06-23' as any);
59
-
60
- await sleep(100);
61
-
62
- expect(sut.getTransaction).toHaveBeenCalledWith(778782, 'fhkjsdhfkjsdf');
63
- expect(sut.transferHiveTokens).toHaveBeenCalledWith('beggars', 'testuser', '18.000', 'HIVE', '[Winner] | Guess: heads | Server Roll: heads | Previous block id: fkjs7878dkfj | BlockID: dfjfsdfsdfs4hfkj88787 | Trx ID: fhkjsdhfkjsdf | Server Seed: j93jgsjghjdhgjfhgkfdhgkj34872394723');
64
- });
65
-
66
- test('User loses a flip', async () => {
67
- await sut.registerContract(contract);
68
-
69
- jest.spyOn(sut, 'getTransaction').mockResolvedValue({ test: 123 } as any);
70
- jest.spyOn(sut, 'verifyTransfer').mockResolvedValue(true as any);
71
- jest.spyOn(sut, 'transferHiveTokens').mockResolvedValue(true as any);
72
- jest.spyOn(sut['client'].database, 'getAccounts').mockResolvedValue([{ balance: '2000.000 HIVE' }] as any);
73
-
74
- (uuidv4 as jest.Mock).mockReturnValue('j93jgsjghjdhgjfhgkfdhgkj34872394723');
75
-
76
- const memo = JSON.stringify({
77
- hive_stream: {
78
- contract: 'coinflip',
79
- action: 'flip',
80
- payload: {
81
- guess: 'heads',
82
- seed: 'tulips'
83
- }
84
- }
85
- });
86
-
87
- await sut.processOperation(['transfer', { from: 'testuser', amount: '9.000 HIVE', memo }], 778782, 'dfjfsdfsdfs4hfkj88787', 'fkjs7878dkfj', 'fhkjsdhfkjsdf', '2019-06-23' as any);
88
-
89
- await sleep(100);
90
-
91
- expect(sut.getTransaction).toHaveBeenCalledWith(778782, 'fhkjsdhfkjsdf');
92
- expect(sut.transferHiveTokens).toHaveBeenCalledWith('beggars', 'testuser', '0.001', 'HIVE', '[Lost] | Guess: heads | Server Roll: tails | Previous block id: fkjs7878dkfj | BlockID: dfjfsdfsdfs4hfkj88787 | Trx ID: fhkjsdhfkjsdf | Server Seed: j93jgsjghjdhgjfhgkfdhgkj34872394723');
93
- });
94
- });
@@ -1,87 +0,0 @@
1
- import { sleep } from '@hiveio/dhive/lib/utils';
2
- import { createDiceContract } from './../../src/contracts/dice.contract';
3
- import { Streamer } from '../../src/streamer';
4
- import { createMockAdapter } from '../helpers/mock-adapter';
5
-
6
- describe('Dice Contract', () => {
7
- let sut: Streamer;
8
- let contract: ReturnType<typeof createDiceContract>;
9
-
10
- beforeEach(async () => {
11
- sut = new Streamer();
12
- await sut.registerAdapter(createMockAdapter());
13
-
14
- contract = createDiceContract({ name: 'testdice' });
15
-
16
- // @ts-ignore
17
- sut.api = jest.fn();
18
- });
19
-
20
- afterEach(async () => {
21
- await sut.stop();
22
- });
23
-
24
- afterAll(() => {
25
- jest.restoreAllMocks();
26
- });
27
-
28
- test('Registers the dice contract', async () => {
29
- await sut.registerContract(contract);
30
-
31
- const findContract = sut['contracts'].find(c => c.name === 'testdice');
32
-
33
- expect(findContract).not.toBeUndefined();
34
- });
35
-
36
- test('User wins a roll', async () => {
37
- await sut.registerContract(contract);
38
-
39
- jest.spyOn(sut, 'getTransaction').mockResolvedValue({ test: 123 } as any);
40
- jest.spyOn(sut, 'verifyTransfer').mockResolvedValue(true as any);
41
- jest.spyOn(sut, 'transferHiveTokens').mockResolvedValue(true as any);
42
- jest.spyOn(sut['client'].database, 'getAccounts').mockResolvedValue([{ balance: '2000.000 HIVE' }] as any);
43
-
44
- const memo = JSON.stringify({
45
- hive_stream: {
46
- contract: 'testdice',
47
- action: 'roll',
48
- payload: {
49
- roll: 69
50
- }
51
- }
52
- });
53
-
54
- await sut.processOperation(['transfer', { from: 'testuser', amount: '9.000 HIVE', memo }], 778782, 'dfjfsdfsdfsd34hfkj88787', 'fkjsdkfj', 'fhkjsdhfkjsdf', '2019-06-23' as any);
55
-
56
- await sleep(100);
57
-
58
- expect(sut.getTransaction).toHaveBeenCalledWith(778782, 'fhkjsdhfkjsdf');
59
- expect(sut.transferHiveTokens).toHaveBeenCalledWith('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
- await sut.registerContract(contract);
64
-
65
- jest.spyOn(sut, 'getTransaction').mockResolvedValue({ test: 123 } as any);
66
- jest.spyOn(sut, 'verifyTransfer').mockResolvedValue(true as any);
67
- jest.spyOn(sut, 'transferHiveTokens').mockResolvedValue(true as any);
68
- jest.spyOn(sut['client'].database, 'getAccounts').mockResolvedValue([{ balance: '2000.000 HIVE' }] as any);
69
-
70
- const memo = JSON.stringify({
71
- hive_stream: {
72
- contract: 'testdice',
73
- action: 'roll',
74
- payload: {
75
- roll: 10
76
- }
77
- }
78
- });
79
-
80
- await sut.processOperation(['transfer', { from: 'testuser', amount: '9.000 HIVE', memo }], 778782, 'dfjfsdfsdfsd34hfkj88787', 'fkjsdkfj', 'fhkjsdhfkjsdf', '2019-06-23' as any);
81
-
82
- await sleep(100);
83
-
84
- expect(sut.getTransaction).toHaveBeenCalledWith(778782, 'fhkjsdhfkjsdf');
85
- expect(sut.transferHiveTokens).toHaveBeenCalledWith('beggars', 'testuser', '0.001', 'HIVE', 'You lost 9.000 HIVE. Roll: 54, Your guess: 10');
86
- });
87
- });