hive-stream 3.0.1 → 3.0.3

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 (195) hide show
  1. package/DOCUMENTATION.md +66 -2
  2. package/README.md +95 -24
  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/config.d.ts +29 -0
  19. package/dist/config.js +77 -2
  20. package/dist/config.js.map +1 -1
  21. package/dist/contracts/auctionhouse.contract.d.ts +4 -0
  22. package/dist/contracts/auctionhouse.contract.js +234 -0
  23. package/dist/contracts/auctionhouse.contract.js.map +1 -0
  24. package/dist/contracts/booking.contract.d.ts +4 -0
  25. package/dist/contracts/booking.contract.js +225 -0
  26. package/dist/contracts/booking.contract.js.map +1 -0
  27. package/dist/contracts/bountyboard.contract.d.ts +4 -0
  28. package/dist/contracts/bountyboard.contract.js +233 -0
  29. package/dist/contracts/bountyboard.contract.js.map +1 -0
  30. package/dist/contracts/bundlemarketplace.contract.d.ts +4 -0
  31. package/dist/contracts/bundlemarketplace.contract.js +195 -0
  32. package/dist/contracts/bundlemarketplace.contract.js.map +1 -0
  33. package/dist/contracts/charitymatch.contract.d.ts +4 -0
  34. package/dist/contracts/charitymatch.contract.js +172 -0
  35. package/dist/contracts/charitymatch.contract.js.map +1 -0
  36. package/dist/contracts/coinflip.contract.js +7 -1
  37. package/dist/contracts/coinflip.contract.js.map +1 -1
  38. package/dist/contracts/crowdfund.contract.d.ts +4 -0
  39. package/dist/contracts/crowdfund.contract.js +290 -0
  40. package/dist/contracts/crowdfund.contract.js.map +1 -0
  41. package/dist/contracts/dcabot.contract.d.ts +4 -0
  42. package/dist/contracts/dcabot.contract.js +217 -0
  43. package/dist/contracts/dcabot.contract.js.map +1 -0
  44. package/dist/contracts/dice.contract.js +7 -1
  45. package/dist/contracts/dice.contract.js.map +1 -1
  46. package/dist/contracts/domainregistry.contract.d.ts +4 -0
  47. package/dist/contracts/domainregistry.contract.js +232 -0
  48. package/dist/contracts/domainregistry.contract.js.map +1 -0
  49. package/dist/contracts/exchange.contract.js +209 -168
  50. package/dist/contracts/exchange.contract.js.map +1 -1
  51. package/dist/contracts/fanclub.contract.d.ts +4 -0
  52. package/dist/contracts/fanclub.contract.js +193 -0
  53. package/dist/contracts/fanclub.contract.js.map +1 -0
  54. package/dist/contracts/giftcard.contract.d.ts +4 -0
  55. package/dist/contracts/giftcard.contract.js +158 -0
  56. package/dist/contracts/giftcard.contract.js.map +1 -0
  57. package/dist/contracts/grantrounds.contract.d.ts +4 -0
  58. package/dist/contracts/grantrounds.contract.js +265 -0
  59. package/dist/contracts/grantrounds.contract.js.map +1 -0
  60. package/dist/contracts/groupbuy.contract.d.ts +4 -0
  61. package/dist/contracts/groupbuy.contract.js +198 -0
  62. package/dist/contracts/groupbuy.contract.js.map +1 -0
  63. package/dist/contracts/helpers.d.ts +64 -0
  64. package/dist/contracts/helpers.js +159 -0
  65. package/dist/contracts/helpers.js.map +1 -0
  66. package/dist/contracts/insurancepool.contract.d.ts +4 -0
  67. package/dist/contracts/insurancepool.contract.js +281 -0
  68. package/dist/contracts/insurancepool.contract.js.map +1 -0
  69. package/dist/contracts/invoice.contract.d.ts +4 -0
  70. package/dist/contracts/invoice.contract.js +193 -0
  71. package/dist/contracts/invoice.contract.js.map +1 -0
  72. package/dist/contracts/launchpad.contract.d.ts +4 -0
  73. package/dist/contracts/launchpad.contract.js +225 -0
  74. package/dist/contracts/launchpad.contract.js.map +1 -0
  75. package/dist/contracts/lotto.contract.js +53 -37
  76. package/dist/contracts/lotto.contract.js.map +1 -1
  77. package/dist/contracts/multisigtreasury.contract.d.ts +4 -0
  78. package/dist/contracts/multisigtreasury.contract.js +245 -0
  79. package/dist/contracts/multisigtreasury.contract.js.map +1 -0
  80. package/dist/contracts/nft.contract.d.ts +1 -0
  81. package/dist/contracts/nft.contract.js +236 -192
  82. package/dist/contracts/nft.contract.js.map +1 -1
  83. package/dist/contracts/oraclebounty.contract.d.ts +4 -0
  84. package/dist/contracts/oraclebounty.contract.js +250 -0
  85. package/dist/contracts/oraclebounty.contract.js.map +1 -0
  86. package/dist/contracts/payroll.contract.d.ts +4 -0
  87. package/dist/contracts/payroll.contract.js +232 -0
  88. package/dist/contracts/payroll.contract.js.map +1 -0
  89. package/dist/contracts/paywall.contract.d.ts +4 -0
  90. package/dist/contracts/paywall.contract.js +185 -0
  91. package/dist/contracts/paywall.contract.js.map +1 -0
  92. package/dist/contracts/poll.contract.js +2 -0
  93. package/dist/contracts/poll.contract.js.map +1 -1
  94. package/dist/contracts/predictionmarket.contract.d.ts +4 -0
  95. package/dist/contracts/predictionmarket.contract.js +213 -0
  96. package/dist/contracts/predictionmarket.contract.js.map +1 -0
  97. package/dist/contracts/proposaltimelock.contract.d.ts +4 -0
  98. package/dist/contracts/proposaltimelock.contract.js +250 -0
  99. package/dist/contracts/proposaltimelock.contract.js.map +1 -0
  100. package/dist/contracts/questpass.contract.d.ts +4 -0
  101. package/dist/contracts/questpass.contract.js +214 -0
  102. package/dist/contracts/questpass.contract.js.map +1 -0
  103. package/dist/contracts/referral.contract.d.ts +4 -0
  104. package/dist/contracts/referral.contract.js +238 -0
  105. package/dist/contracts/referral.contract.js.map +1 -0
  106. package/dist/contracts/rental.contract.d.ts +4 -0
  107. package/dist/contracts/rental.contract.js +221 -0
  108. package/dist/contracts/rental.contract.js.map +1 -0
  109. package/dist/contracts/revenuesplit.contract.d.ts +4 -0
  110. package/dist/contracts/revenuesplit.contract.js +211 -0
  111. package/dist/contracts/revenuesplit.contract.js.map +1 -0
  112. package/dist/contracts/rps.contract.js +17 -1
  113. package/dist/contracts/rps.contract.js.map +1 -1
  114. package/dist/contracts/savings.contract.d.ts +4 -0
  115. package/dist/contracts/savings.contract.js +208 -0
  116. package/dist/contracts/savings.contract.js.map +1 -0
  117. package/dist/contracts/subscription.contract.d.ts +4 -0
  118. package/dist/contracts/subscription.contract.js +241 -0
  119. package/dist/contracts/subscription.contract.js.map +1 -0
  120. package/dist/contracts/sweepstakes.contract.d.ts +4 -0
  121. package/dist/contracts/sweepstakes.contract.js +209 -0
  122. package/dist/contracts/sweepstakes.contract.js.map +1 -0
  123. package/dist/contracts/ticketing.contract.d.ts +4 -0
  124. package/dist/contracts/ticketing.contract.js +185 -0
  125. package/dist/contracts/ticketing.contract.js.map +1 -0
  126. package/dist/contracts/tipjar.contract.js +2 -0
  127. package/dist/contracts/tipjar.contract.js.map +1 -1
  128. package/dist/contracts/token.contract.js +135 -125
  129. package/dist/contracts/token.contract.js.map +1 -1
  130. package/dist/index.d.ts +40 -0
  131. package/dist/index.js +72 -1
  132. package/dist/index.js.map +1 -1
  133. package/dist/metadata.d.ts +70 -0
  134. package/dist/metadata.js +470 -0
  135. package/dist/metadata.js.map +1 -0
  136. package/dist/providers/block-provider.d.ts +22 -0
  137. package/dist/providers/block-provider.js +3 -0
  138. package/dist/providers/block-provider.js.map +1 -0
  139. package/dist/providers/haf-client.d.ts +30 -0
  140. package/dist/providers/haf-client.js +119 -0
  141. package/dist/providers/haf-client.js.map +1 -0
  142. package/dist/providers/haf-provider.d.ts +49 -0
  143. package/dist/providers/haf-provider.js +256 -0
  144. package/dist/providers/haf-provider.js.map +1 -0
  145. package/dist/providers/hive-provider.d.ts +13 -0
  146. package/dist/providers/hive-provider.js +25 -0
  147. package/dist/providers/hive-provider.js.map +1 -0
  148. package/dist/providers/index.d.ts +4 -0
  149. package/dist/providers/index.js +21 -0
  150. package/dist/providers/index.js.map +1 -0
  151. package/dist/streamer.d.ts +24 -4
  152. package/dist/streamer.js +196 -69
  153. package/dist/streamer.js.map +1 -1
  154. package/dist/utils.js +11 -2
  155. package/dist/utils.js.map +1 -1
  156. package/package.json +16 -1
  157. package/.claude/settings.local.json +0 -12
  158. package/.env.example +0 -3
  159. package/.travis.yml +0 -11
  160. package/AGENTS.md +0 -35
  161. package/CLAUDE.md +0 -75
  162. package/ecosystem.config.js +0 -17
  163. package/examples/contracts/README.md +0 -8
  164. package/examples/contracts/exchange.ts +0 -38
  165. package/examples/contracts/poll.ts +0 -21
  166. package/examples/contracts/rps.ts +0 -19
  167. package/examples/contracts/tipjar.ts +0 -19
  168. package/jest.config.js +0 -9
  169. package/test-contract-block.md +0 -19
  170. package/tests/actions.spec.ts +0 -252
  171. package/tests/adapters/actions-persistence.spec.ts +0 -144
  172. package/tests/adapters/postgresql.adapter.spec.ts +0 -127
  173. package/tests/adapters/sqlite.adapter.spec.ts +0 -181
  174. package/tests/contracts/coinflip.contract.spec.ts +0 -94
  175. package/tests/contracts/dice.contract.spec.ts +0 -87
  176. package/tests/contracts/entrants.json +0 -729
  177. package/tests/contracts/exchange.contract.spec.ts +0 -84
  178. package/tests/contracts/lotto.contract.spec.ts +0 -59
  179. package/tests/contracts/nft.contract.spec.ts +0 -948
  180. package/tests/contracts/token.contract.spec.ts +0 -90
  181. package/tests/exchanges/coingecko.exchange.spec.ts +0 -169
  182. package/tests/exchanges/exchange.base.spec.ts +0 -246
  183. package/tests/helpers/mock-adapter.ts +0 -214
  184. package/tests/helpers/mock-fetch.ts +0 -165
  185. package/tests/hive-chain-features.spec.ts +0 -238
  186. package/tests/hive-rates.spec.ts +0 -443
  187. package/tests/integration/hive-rates.integration.spec.ts +0 -35
  188. package/tests/setup.ts +0 -30
  189. package/tests/streamer-actions.spec.ts +0 -274
  190. package/tests/streamer.spec.ts +0 -342
  191. package/tests/types/rates.spec.ts +0 -216
  192. package/tests/utils.spec.ts +0 -113
  193. package/tsconfig.build.json +0 -4
  194. package/tslint.json +0 -21
  195. 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,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
- });