@ethersphere/bee-js 2.0.0 → 3.1.0

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 (159) hide show
  1. package/CHANGELOG.md +91 -0
  2. package/README.md +2 -2
  3. package/dist/index.browser.min.js +1 -1
  4. package/dist/index.browser.min.js.map +1 -1
  5. package/dist/index.min.js +1 -1
  6. package/dist/index.min.js.map +1 -1
  7. package/dist/src/bee-debug.d.ts +38 -6
  8. package/dist/src/bee.d.ts +34 -46
  9. package/dist/src/modules/chunk.d.ts +2 -10
  10. package/dist/src/modules/debug/stamps.d.ts +2 -0
  11. package/dist/src/modules/debug/status.d.ts +10 -4
  12. package/dist/src/modules/stewardship.d.ts +1 -0
  13. package/dist/src/types/debug.d.ts +11 -0
  14. package/dist/src/types/index.d.ts +6 -7
  15. package/dist/src/utils/bytes.d.ts +1 -1
  16. package/dist/src/utils/expose.d.ts +1 -0
  17. package/dist/src/utils/stamps.d.ts +12 -0
  18. package/package.json +10 -8
  19. package/.babelrc.js +0 -33
  20. package/.depcheckrc.json +0 -27
  21. package/.editorconfig +0 -6
  22. package/.eslintignore +0 -1
  23. package/.eslintrc.js +0 -109
  24. package/.gitattributes +0 -1
  25. package/.github/config.yaml +0 -23
  26. package/.github/workflows/check.yaml +0 -57
  27. package/.github/workflows/publish_npmjs.yaml +0 -20
  28. package/.github/workflows/release_github.yaml +0 -20
  29. package/.github/workflows/tests.yaml +0 -128
  30. package/.huskyrc +0 -5
  31. package/.prettierrc +0 -13
  32. package/.vscode/launch.json +0 -49
  33. package/.vscode/settings.json +0 -39
  34. package/CODEOWNERS +0 -1
  35. package/CODE_OF_CONDUCT.md +0 -76
  36. package/commitlint.config.js +0 -3
  37. package/dist/src/modules/stamps.d.ts +0 -4
  38. package/jest-puppeteer.config.js +0 -5
  39. package/jest.config.ts +0 -85
  40. package/src/bee-debug.ts +0 -559
  41. package/src/bee.ts +0 -1070
  42. package/src/chunk/bmt.ts +0 -55
  43. package/src/chunk/cac.ts +0 -79
  44. package/src/chunk/serialize.ts +0 -16
  45. package/src/chunk/signer.ts +0 -141
  46. package/src/chunk/soc.ts +0 -190
  47. package/src/chunk/span.ts +0 -33
  48. package/src/feed/index.ts +0 -217
  49. package/src/feed/json.ts +0 -33
  50. package/src/feed/topic.ts +0 -23
  51. package/src/feed/type.ts +0 -12
  52. package/src/index.ts +0 -24
  53. package/src/modules/bytes.ts +0 -70
  54. package/src/modules/bzz.ts +0 -179
  55. package/src/modules/chunk.ts +0 -69
  56. package/src/modules/debug/balance.ts +0 -63
  57. package/src/modules/debug/chequebook.ts +0 -175
  58. package/src/modules/debug/chunk.ts +0 -39
  59. package/src/modules/debug/connectivity.ts +0 -61
  60. package/src/modules/debug/settlements.ts +0 -33
  61. package/src/modules/debug/stamps.ts +0 -76
  62. package/src/modules/debug/states.ts +0 -35
  63. package/src/modules/debug/status.ts +0 -35
  64. package/src/modules/debug/tag.ts +0 -19
  65. package/src/modules/debug/transactions.ts +0 -79
  66. package/src/modules/feed.ts +0 -105
  67. package/src/modules/pinning.ts +0 -74
  68. package/src/modules/pss.ts +0 -49
  69. package/src/modules/soc.ts +0 -40
  70. package/src/modules/stamps.ts +0 -59
  71. package/src/modules/status.ts +0 -13
  72. package/src/modules/stewardship.ts +0 -18
  73. package/src/modules/tag.ts +0 -83
  74. package/src/types/debug.ts +0 -204
  75. package/src/types/index.ts +0 -566
  76. package/src/types/ky-universal/common.d.ts +0 -17
  77. package/src/types/ky-universal/hooks.d.ts +0 -103
  78. package/src/types/ky-universal/index.d.ts +0 -125
  79. package/src/types/ky-universal/options.d.ts +0 -235
  80. package/src/types/ky-universal/response.d.ts +0 -38
  81. package/src/types/ky-universal/retry.d.ts +0 -39
  82. package/src/types/tar-js.d.ts +0 -1
  83. package/src/types/webpack-bundle-analyzer/index.d.ts +0 -13
  84. package/src/utils/bytes.ts +0 -144
  85. package/src/utils/collection.ts +0 -151
  86. package/src/utils/data.browser.ts +0 -68
  87. package/src/utils/data.ts +0 -48
  88. package/src/utils/error.ts +0 -23
  89. package/src/utils/eth.ts +0 -229
  90. package/src/utils/expose.ts +0 -48
  91. package/src/utils/file.ts +0 -40
  92. package/src/utils/hash.ts +0 -16
  93. package/src/utils/headers.ts +0 -63
  94. package/src/utils/hex.ts +0 -186
  95. package/src/utils/http.ts +0 -141
  96. package/src/utils/merge.ts +0 -34
  97. package/src/utils/pss.ts +0 -16
  98. package/src/utils/stream.ts +0 -146
  99. package/src/utils/tar.ts +0 -30
  100. package/src/utils/type.ts +0 -394
  101. package/src/utils/uint64.ts +0 -31
  102. package/src/utils/url.ts +0 -52
  103. package/test/bee.sh +0 -187
  104. package/test/data/1.txt +0 -1
  105. package/test/data/2.txt +0 -0
  106. package/test/data/empty +0 -0
  107. package/test/data/sub/3.txt +0 -1
  108. package/test/data/sub//303/251 +0 -0
  109. package/test/data/sub//360/237/230/216 +0 -0
  110. package/test/integration/bee-class.browser.spec.ts +0 -272
  111. package/test/integration/bee-class.spec.ts +0 -631
  112. package/test/integration/bee-debug-class.spec.ts +0 -85
  113. package/test/integration/chunk/bmt.spec.ts +0 -33
  114. package/test/integration/chunk/cac.spec.ts +0 -27
  115. package/test/integration/chunk/soc.spec.ts +0 -38
  116. package/test/integration/feed/index.spec.ts +0 -84
  117. package/test/integration/modules/bytes.spec.ts +0 -23
  118. package/test/integration/modules/bzz.spec.ts +0 -265
  119. package/test/integration/modules/chunk.spec.ts +0 -29
  120. package/test/integration/modules/debug/balance.spec.ts +0 -70
  121. package/test/integration/modules/debug/chequebook.spec.ts +0 -64
  122. package/test/integration/modules/debug/connectivity.spec.ts +0 -69
  123. package/test/integration/modules/debug/settlements.spec.ts +0 -34
  124. package/test/integration/modules/debug/states.spec.ts +0 -34
  125. package/test/integration/modules/debug/status.spec.ts +0 -65
  126. package/test/integration/modules/debug/tag.spec.ts +0 -27
  127. package/test/integration/modules/debug/transactions.spec.ts +0 -10
  128. package/test/integration/modules/feed.spec.ts +0 -61
  129. package/test/integration/modules/pinning.spec.ts +0 -155
  130. package/test/integration/modules/pss.spec.ts +0 -97
  131. package/test/integration/modules/status.spec.ts +0 -10
  132. package/test/integration/modules/stewardship.spec.ts +0 -32
  133. package/test/integration/modules/tag.spec.ts +0 -51
  134. package/test/test-type-sequencer.js +0 -36
  135. package/test/testpage/testpage.html +0 -20
  136. package/test/tests-setup.ts +0 -94
  137. package/test/unit/assertions.ts +0 -460
  138. package/test/unit/bee-class.spec.ts +0 -976
  139. package/test/unit/bee-debug-class.spec.ts +0 -435
  140. package/test/unit/chunk/bmt.spec.ts +0 -16
  141. package/test/unit/chunk/cac.spec.ts +0 -29
  142. package/test/unit/chunk/serialize.spec.ts +0 -24
  143. package/test/unit/chunk/signer.spec.ts +0 -140
  144. package/test/unit/chunk/soc.spec.ts +0 -25
  145. package/test/unit/chunk/span.spec.ts +0 -38
  146. package/test/unit/feed/json.spec.ts +0 -73
  147. package/test/unit/nock.ts +0 -151
  148. package/test/unit/utils/bytes.spec.ts +0 -32
  149. package/test/unit/utils/collection.spec.ts +0 -22
  150. package/test/unit/utils/eth.spec.ts +0 -224
  151. package/test/unit/utils/hex.spec.ts +0 -115
  152. package/test/unit/utils/stream.spec.ts +0 -30
  153. package/test/unit/utils/type.spec.ts +0 -32
  154. package/test/unit/utils/uint64.spec.ts +0 -102
  155. package/test/utils.ts +0 -328
  156. package/tsconfig.json +0 -18
  157. package/tsconfig.test.json +0 -11
  158. package/typedoc.json +0 -7
  159. package/webpack.config.ts +0 -141
@@ -1,435 +0,0 @@
1
- import {
2
- assertAllIsDone,
3
- cashoutLastChequeMock,
4
- createPostageBatchMock,
5
- depositTokensMock,
6
- MOCK_SERVER_URL,
7
- withdrawTokensMock,
8
- } from './nock'
9
- import { BatchId, BeeArgumentError, BeeDebug, CashoutOptions, PostageBatchOptions, RequestOptions } from '../../src'
10
- import { testAddress, testBatchId } from '../utils'
11
- import {
12
- testAddressAssertions,
13
- testBatchIdAssertion,
14
- testCashoutOptionsAssertions,
15
- testPostageBatchOptionsAssertions,
16
- testRequestOptionsAssertions,
17
- } from './assertions'
18
-
19
- const TRANSACTION_HASH = '36b7efd913ca4cf880b8eeac5093fa27b0825906c600685b6abdd6566e6cfe8f'
20
- const CASHOUT_RESPONSE = {
21
- transactionHash: TRANSACTION_HASH,
22
- }
23
-
24
- describe('BeeDebug class', () => {
25
- function testUrl(url: unknown): void {
26
- it(`should not accept invalid url '${url}'`, () => {
27
- try {
28
- new BeeDebug(url as string)
29
- fail('BeeDebug constructor should have thrown error.')
30
- } catch (e) {
31
- if (e instanceof BeeArgumentError) {
32
- expect(e.value).toEqual(url)
33
-
34
- return
35
- }
36
-
37
- throw e
38
- }
39
- })
40
- }
41
-
42
- testUrl('')
43
- testUrl(null)
44
- testUrl(undefined)
45
- testUrl(1)
46
- testUrl('some-invalid-url')
47
- testUrl('invalid:protocol')
48
- // eslint-disable-next-line no-script-url
49
- testUrl('javascript:console.log()')
50
- testUrl('ws://localhost:1633')
51
-
52
- it('should set default headers and use them if specified', async () => {
53
- depositTokensMock('10', undefined, { 'X-Awesome-Header': '123' }).reply(201, CASHOUT_RESPONSE)
54
-
55
- const bee = new BeeDebug(MOCK_SERVER_URL, { defaultHeaders: { 'X-Awesome-Header': '123' } })
56
- await expect(bee.depositTokens('10')).resolves.toEqual(TRANSACTION_HASH)
57
-
58
- assertAllIsDone()
59
- })
60
-
61
- describe('removePeer', () => {
62
- testRequestOptionsAssertions(async (input: unknown, beeOptions) => {
63
- const bee = new BeeDebug(MOCK_SERVER_URL, beeOptions)
64
-
65
- return bee.removePeer(testAddress, input as RequestOptions)
66
- })
67
-
68
- testAddressAssertions(async (input: unknown) => {
69
- const bee = new BeeDebug(MOCK_SERVER_URL)
70
-
71
- return bee.removePeer(input as string)
72
- })
73
- })
74
-
75
- describe('pingPeer', () => {
76
- testRequestOptionsAssertions(async (input: unknown, beeOptions) => {
77
- const bee = new BeeDebug(MOCK_SERVER_URL, beeOptions)
78
-
79
- return bee.pingPeer(testAddress, input as RequestOptions)
80
- })
81
-
82
- testAddressAssertions(async (input: unknown) => {
83
- const bee = new BeeDebug(MOCK_SERVER_URL)
84
-
85
- return bee.pingPeer(input as string)
86
- })
87
- })
88
-
89
- describe('getPeerBalance', () => {
90
- testRequestOptionsAssertions(async (input: unknown, beeOptions) => {
91
- const bee = new BeeDebug(MOCK_SERVER_URL, beeOptions)
92
-
93
- return bee.getPeerBalance(testAddress, input as RequestOptions)
94
- })
95
-
96
- testAddressAssertions(async (input: unknown) => {
97
- const bee = new BeeDebug(MOCK_SERVER_URL)
98
-
99
- return bee.getPeerBalance(input as string)
100
- })
101
- })
102
-
103
- describe('getPastDueConsumptionPeerBalance', () => {
104
- testRequestOptionsAssertions(async (input: unknown, beeOptions) => {
105
- const bee = new BeeDebug(MOCK_SERVER_URL, beeOptions)
106
-
107
- return bee.getPastDueConsumptionPeerBalance(testAddress, input as RequestOptions)
108
- })
109
-
110
- testAddressAssertions(async (input: unknown) => {
111
- const bee = new BeeDebug(MOCK_SERVER_URL)
112
-
113
- return bee.getPastDueConsumptionPeerBalance(input as string)
114
- })
115
- })
116
-
117
- describe('getLastChequesForPeer', () => {
118
- testRequestOptionsAssertions(async (input: unknown, beeOptions) => {
119
- const bee = new BeeDebug(MOCK_SERVER_URL, beeOptions)
120
-
121
- return bee.getLastChequesForPeer(testAddress, input as RequestOptions)
122
- })
123
-
124
- testAddressAssertions(async (input: unknown) => {
125
- const bee = new BeeDebug(MOCK_SERVER_URL)
126
-
127
- return bee.getLastChequesForPeer(input as string)
128
- })
129
- })
130
-
131
- describe('getLastCashoutAction', () => {
132
- testRequestOptionsAssertions(async (input: unknown, beeOptions) => {
133
- const bee = new BeeDebug(MOCK_SERVER_URL, beeOptions)
134
-
135
- return bee.getLastCashoutAction(testAddress, input as RequestOptions)
136
- })
137
-
138
- testAddressAssertions(async (input: unknown) => {
139
- const bee = new BeeDebug(MOCK_SERVER_URL)
140
-
141
- return bee.getLastCashoutAction(input as string)
142
- })
143
- })
144
-
145
- describe('getSettlements', () => {
146
- testRequestOptionsAssertions(async (input: unknown, beeOptions) => {
147
- const bee = new BeeDebug(MOCK_SERVER_URL, beeOptions)
148
-
149
- return bee.getSettlements(testAddress, input as RequestOptions)
150
- })
151
-
152
- testAddressAssertions(async (input: unknown) => {
153
- const bee = new BeeDebug(MOCK_SERVER_URL)
154
-
155
- return bee.getSettlements(input as string)
156
- })
157
- })
158
-
159
- describe('cashoutLastCheque', () => {
160
- testRequestOptionsAssertions(async (input: unknown, beeOptions) => {
161
- const bee = new BeeDebug(MOCK_SERVER_URL, beeOptions)
162
-
163
- return bee.cashoutLastCheque(testAddress, input as RequestOptions)
164
- })
165
-
166
- testCashoutOptionsAssertions(async (input: unknown) => {
167
- const bee = new BeeDebug(MOCK_SERVER_URL)
168
-
169
- return bee.cashoutLastCheque('', input as CashoutOptions)
170
- })
171
-
172
- it('should not pass headers if no gas price is specified', async () => {
173
- cashoutLastChequeMock(testAddress).reply(201, CASHOUT_RESPONSE)
174
-
175
- const bee = new BeeDebug(MOCK_SERVER_URL)
176
- await expect(bee.cashoutLastCheque(testAddress)).resolves.toEqual(TRANSACTION_HASH)
177
- assertAllIsDone()
178
- })
179
-
180
- it('should pass headers if gas price is specified', async () => {
181
- cashoutLastChequeMock(testAddress, '100000000000').reply(201, CASHOUT_RESPONSE)
182
-
183
- const bee = new BeeDebug(MOCK_SERVER_URL)
184
- await expect(bee.cashoutLastCheque(testAddress, { gasPrice: '100000000000' })).resolves.toEqual(TRANSACTION_HASH)
185
- assertAllIsDone()
186
- })
187
-
188
- it('should pass headers if gas limit is specified', async () => {
189
- cashoutLastChequeMock(testAddress, undefined, '100000000000').reply(201, CASHOUT_RESPONSE)
190
-
191
- const bee = new BeeDebug(MOCK_SERVER_URL)
192
- await expect(bee.cashoutLastCheque(testAddress, { gasLimit: '100000000000' })).resolves.toEqual(TRANSACTION_HASH)
193
- assertAllIsDone()
194
- })
195
-
196
- testAddressAssertions(async (input: unknown) => {
197
- const bee = new BeeDebug(MOCK_SERVER_URL)
198
-
199
- return bee.cashoutLastCheque(input as string)
200
- })
201
- })
202
-
203
- describe('withdrawTokens', () => {
204
- const TRANSACTION_HASH = '36b7efd913ca4cf880b8eeac5093fa27b0825906c600685b6abdd6566e6cfe8f'
205
- const CASHOUT_RESPONSE = {
206
- transactionHash: TRANSACTION_HASH,
207
- }
208
-
209
- testRequestOptionsAssertions(async (input: unknown, beeOptions) => {
210
- const bee = new BeeDebug(MOCK_SERVER_URL, beeOptions)
211
-
212
- return bee.withdrawTokens('1', '0', input as RequestOptions)
213
- })
214
-
215
- it('should not pass headers if no gas price is specified', async () => {
216
- withdrawTokensMock('10').reply(201, CASHOUT_RESPONSE)
217
-
218
- const bee = new BeeDebug(MOCK_SERVER_URL)
219
- await expect(bee.withdrawTokens('10')).resolves.toEqual(TRANSACTION_HASH)
220
- assertAllIsDone()
221
- })
222
-
223
- it('should pass headers if gas price is specified', async () => {
224
- withdrawTokensMock('10', '100000000000').reply(201, CASHOUT_RESPONSE)
225
-
226
- const bee = new BeeDebug(MOCK_SERVER_URL)
227
- await expect(bee.withdrawTokens('10', '100000000000')).resolves.toEqual(TRANSACTION_HASH)
228
- assertAllIsDone()
229
- })
230
-
231
- it('should throw error if passed wrong amount', async () => {
232
- const bee = new BeeDebug(MOCK_SERVER_URL)
233
-
234
- // @ts-ignore: Input testing
235
- await expect(bee.withdrawTokens(true)).rejects.toThrow(TypeError)
236
-
237
- // @ts-ignore: Input testing
238
- await expect(bee.withdrawTokens('asd')).rejects.toThrow(TypeError)
239
- // @ts-ignore: Input testing
240
- await expect(bee.withdrawTokens(null)).rejects.toThrow(TypeError)
241
- // @ts-ignore: Input testing
242
- await expect(bee.withdrawTokens()).rejects.toThrow(TypeError)
243
-
244
- await expect(bee.withdrawTokens('-1')).rejects.toThrow(BeeArgumentError)
245
- })
246
-
247
- it('should throw error if passed wrong gas price input', async () => {
248
- const bee = new BeeDebug(MOCK_SERVER_URL)
249
-
250
- // @ts-ignore: Input testing
251
- await expect(bee.withdrawTokens('1', true)).rejects.toThrow(TypeError)
252
- // @ts-ignore: Input testing
253
- await expect(bee.withdrawTokens('1', 'asd')).rejects.toThrow(TypeError)
254
- await expect(bee.withdrawTokens('1', '-1')).rejects.toThrow(BeeArgumentError)
255
- })
256
- })
257
-
258
- describe('depositTokens', () => {
259
- const TRANSACTION_HASH = '36b7efd913ca4cf880b8eeac5093fa27b0825906c600685b6abdd6566e6cfe8f'
260
- const CASHOUT_RESPONSE = {
261
- transactionHash: TRANSACTION_HASH,
262
- }
263
-
264
- testRequestOptionsAssertions(async (input: unknown, beeOptions) => {
265
- const bee = new BeeDebug(MOCK_SERVER_URL, beeOptions)
266
-
267
- return bee.depositTokens('1', '0', input as RequestOptions)
268
- })
269
-
270
- it('should not pass headers if no gas price is specified', async () => {
271
- depositTokensMock('10').reply(201, CASHOUT_RESPONSE)
272
-
273
- const bee = new BeeDebug(MOCK_SERVER_URL)
274
- await expect(bee.depositTokens('10')).resolves.toEqual(TRANSACTION_HASH)
275
- assertAllIsDone()
276
- })
277
-
278
- it('should pass headers if gas price is specified', async () => {
279
- depositTokensMock('10', '100000000000').reply(201, CASHOUT_RESPONSE)
280
-
281
- const bee = new BeeDebug(MOCK_SERVER_URL)
282
- await expect(bee.depositTokens('10', '100000000000')).resolves.toEqual(TRANSACTION_HASH)
283
- assertAllIsDone()
284
- })
285
-
286
- it('should throw error if passed wrong amount', async () => {
287
- const bee = new BeeDebug(MOCK_SERVER_URL)
288
-
289
- // @ts-ignore: Input testing
290
- await expect(bee.depositTokens(true)).rejects.toThrow(TypeError)
291
-
292
- // @ts-ignore: Input testing
293
- await expect(bee.depositTokens('asd')).rejects.toThrow(TypeError)
294
- // @ts-ignore: Input testing
295
- await expect(bee.depositTokens(null)).rejects.toThrow(TypeError)
296
- // @ts-ignore: Input testing
297
- await expect(bee.depositTokens()).rejects.toThrow(TypeError)
298
-
299
- await expect(bee.depositTokens('-1')).rejects.toThrow(BeeArgumentError)
300
- })
301
-
302
- it('should throw error if passed wrong gas price input', async () => {
303
- const bee = new BeeDebug(MOCK_SERVER_URL)
304
-
305
- // @ts-ignore: Input testing
306
- await expect(bee.depositTokens('1', true)).rejects.toThrow(TypeError)
307
- // @ts-ignore: Input testing
308
- await expect(bee.depositTokens('1', 'asd')).rejects.toThrow(TypeError)
309
- await expect(bee.depositTokens('1', '-1')).rejects.toThrow(BeeArgumentError)
310
- })
311
- })
312
-
313
- describe('retrieveExtendedTag', () => {
314
- testRequestOptionsAssertions(async (input: unknown, beeOptions) => {
315
- const bee = new BeeDebug(MOCK_SERVER_URL, beeOptions)
316
-
317
- return bee.retrieveExtendedTag(0, input as RequestOptions)
318
- })
319
-
320
- it('should throw exception for bad Tag', async () => {
321
- const bee = new BeeDebug(MOCK_SERVER_URL)
322
-
323
- // @ts-ignore: Type testing
324
- await expect(bee.retrieveExtendedTag('')).rejects.toThrow(TypeError)
325
- // @ts-ignore: Type testing
326
- await expect(bee.retrieveExtendedTag(true)).rejects.toThrow(TypeError)
327
- // @ts-ignore: Type testing
328
- await expect(bee.retrieveExtendedTag([])).rejects.toThrow(TypeError)
329
- // @ts-ignore: Type testing
330
- await expect(bee.retrieveExtendedTag({})).rejects.toThrow(TypeError)
331
- // @ts-ignore: Type testing
332
- await expect(bee.retrieveExtendedTag(null)).rejects.toThrow(TypeError)
333
- // @ts-ignore: Type testing
334
- await expect(bee.retrieveExtendedTag(undefined)).rejects.toThrow(TypeError)
335
-
336
- // @ts-ignore: Type testing
337
- await expect(bee.retrieveExtendedTag({ total: true })).rejects.toThrow(TypeError)
338
- // @ts-ignore: Type testing
339
- await expect(bee.retrieveExtendedTag({ total: 'asdf' })).rejects.toThrow(TypeError)
340
- // @ts-ignore: Type testing
341
- await expect(bee.retrieveExtendedTag({ total: null })).rejects.toThrow(TypeError)
342
-
343
- await expect(bee.retrieveExtendedTag(-1)).rejects.toThrow(BeeArgumentError)
344
- })
345
- })
346
-
347
- describe('createPostageBatch', () => {
348
- const BATCH_ID = '36b7efd913ca4cf880b8eeac5093fa27b0825906c600685b6abdd6566e6cfe8f'
349
- const BATCH_RESPONSE = {
350
- batchID: BATCH_ID,
351
- }
352
-
353
- testPostageBatchOptionsAssertions(async (input: unknown) => {
354
- const bee = new BeeDebug(MOCK_SERVER_URL)
355
-
356
- return bee.createPostageBatch('10', 17, input as PostageBatchOptions)
357
- })
358
-
359
- testRequestOptionsAssertions(async (input: unknown, beeOptions) => {
360
- const bee = new BeeDebug(MOCK_SERVER_URL, beeOptions)
361
-
362
- return bee.createPostageBatch('10', 17, input as RequestOptions)
363
- })
364
-
365
- it('should not pass headers if no gas price is specified', async () => {
366
- createPostageBatchMock('10', '17').reply(201, BATCH_RESPONSE)
367
-
368
- const bee = new BeeDebug(MOCK_SERVER_URL)
369
- await expect(bee.createPostageBatch('10', 17)).resolves.toEqual(BATCH_ID)
370
- assertAllIsDone()
371
- })
372
-
373
- it('should pass headers if gas price is specified', async () => {
374
- createPostageBatchMock('10', '17', '100').reply(201, BATCH_RESPONSE)
375
-
376
- const bee = new BeeDebug(MOCK_SERVER_URL)
377
- await expect(bee.createPostageBatch('10', 17, { gasPrice: '100' })).resolves.toEqual(BATCH_ID)
378
- assertAllIsDone()
379
- })
380
-
381
- it('should throw error if passed wrong immutable input', async () => {
382
- const bee = new BeeDebug(MOCK_SERVER_URL)
383
-
384
- // @ts-ignore: Input testing
385
- await expect(bee.createPostageBatch('10', 17, { immutableFlag: 'asd' })).rejects.toThrow(TypeError)
386
-
387
- // @ts-ignore: Input testing
388
- await expect(bee.createPostageBatch('10', 17, { immutableFlag: -1 })).rejects.toThrow(TypeError)
389
-
390
- // @ts-ignore: Input testing
391
- await expect(bee.createPostageBatch('10', 17, { immutableFlag: 'true' })).rejects.toThrow(TypeError)
392
- })
393
-
394
- it('should throw error if too small depth', async () => {
395
- const bee = new BeeDebug(MOCK_SERVER_URL)
396
-
397
- await expect(bee.createPostageBatch('10', -1)).rejects.toThrow(BeeArgumentError)
398
- await expect(bee.createPostageBatch('10', 15)).rejects.toThrow(BeeArgumentError)
399
- })
400
-
401
- it('should throw error if too big depth', async () => {
402
- const bee = new BeeDebug(MOCK_SERVER_URL)
403
-
404
- await expect(bee.createPostageBatch('10', 256)).rejects.toThrow(BeeArgumentError)
405
- })
406
- })
407
-
408
- describe('getPostageBatch', () => {
409
- testRequestOptionsAssertions(async (input: unknown, beeOptions) => {
410
- const bee = new BeeDebug(MOCK_SERVER_URL, beeOptions)
411
-
412
- return bee.getPostageBatch(testBatchId, input as RequestOptions)
413
- })
414
-
415
- testBatchIdAssertion(async (input: unknown) => {
416
- const bee = new BeeDebug(MOCK_SERVER_URL)
417
-
418
- return bee.getPostageBatch(input as BatchId)
419
- })
420
- })
421
-
422
- describe('getPostageBatchBuckets', () => {
423
- testRequestOptionsAssertions(async (input: unknown, beeOptions) => {
424
- const bee = new BeeDebug(MOCK_SERVER_URL, beeOptions)
425
-
426
- return bee.getPostageBatchBuckets(testBatchId, input as RequestOptions)
427
- })
428
-
429
- testBatchIdAssertion(async (input: unknown) => {
430
- const bee = new BeeDebug(MOCK_SERVER_URL)
431
-
432
- return bee.getPostageBatchBuckets(input as BatchId)
433
- })
434
- })
435
- })
@@ -1,16 +0,0 @@
1
- import { bmtHash } from '../../../src/chunk/bmt'
2
- import { makeSpan } from '../../../src/chunk/span'
3
- import { bytesToHex } from '../../../src/utils/hex'
4
-
5
- describe('bmt', () => {
6
- it('should produce correct BMT hash', () => {
7
- const payload = new Uint8Array([1, 2, 3])
8
- const span = makeSpan(payload.length)
9
- const data = new Uint8Array([...span, ...payload])
10
- const hash = 'ca6357a08e317d15ec560fef34e4c45f8f19f01c372aa70f1da72bfa7f1a4338'
11
-
12
- const result = bmtHash(data)
13
-
14
- expect(bytesToHex(result)).toEqual(hash)
15
- })
16
- })
@@ -1,29 +0,0 @@
1
- import { assertBytes } from '../../../src/utils/bytes'
2
- import { makeContentAddressedChunk, assertValidChunkData } from '../../../src/chunk/cac'
3
- import { serializeBytes } from '../../../src/chunk/serialize'
4
- import { makeSpan } from '../../../src/chunk/span'
5
- import { hexToBytes, bytesToHex } from '../../../src/utils/hex'
6
-
7
- describe('cac', () => {
8
- const payload = new Uint8Array([1, 2, 3])
9
- const contentHash = 'ca6357a08e317d15ec560fef34e4c45f8f19f01c372aa70f1da72bfa7f1a4338'
10
-
11
- test('content address chunk creation', () => {
12
- const cac = makeContentAddressedChunk(payload)
13
- const address = cac.address()
14
-
15
- expect(bytesToHex(address)).toEqual(contentHash)
16
- })
17
-
18
- test('content address chunk verification', () => {
19
- const validAddress = hexToBytes(contentHash)
20
- assertBytes(validAddress, 32)
21
- const invalidAddress = hexToBytes('ca6357a08e317d15ec560fef34e4c45f8f19f01c372aa70f1da72bfa7f1a4335')
22
- assertBytes(invalidAddress, 32)
23
-
24
- const data = serializeBytes(makeSpan(payload.length), payload)
25
-
26
- expect(() => assertValidChunkData(data, validAddress)).not.toThrow()
27
- expect(() => assertValidChunkData(data, invalidAddress)).toThrow()
28
- })
29
- })
@@ -1,24 +0,0 @@
1
- import { serializeBytes } from '../../../src/chunk/serialize'
2
-
3
- describe('serializeBytes', () => {
4
- it('serializes', () => {
5
- const a1 = new Uint8Array([1])
6
- const a2 = new Uint8Array([2])
7
- const a3 = new Uint8Array([3])
8
- const expectedResult = new Uint8Array([1, 2, 3])
9
-
10
- const result = serializeBytes(a1, a2, a3)
11
-
12
- expect(result).toEqual(expectedResult)
13
- })
14
-
15
- it('serializes chunk data with span', () => {
16
- const span = new Uint8Array(8)
17
- const payload = new Uint8Array(4096)
18
- const expectedResult = new Uint8Array(span.length + payload.length)
19
-
20
- const result = serializeBytes(span, payload)
21
-
22
- expect(result).toEqual(expectedResult)
23
- })
24
- })
@@ -1,140 +0,0 @@
1
- import { sign, makePrivateKeySigner, makeSigner, recoverAddress } from '../../../src/chunk/signer'
2
- import { makeBytes, assertBytes, wrapBytesWithHelpers } from '../../../src/utils/bytes'
3
- import { HexString, hexToBytes, bytesToHex } from '../../../src/utils/hex'
4
- import { shorten, testIdentity } from '../../utils'
5
- import type { Signature, Signer } from '../../../src/types'
6
-
7
- describe('signer', () => {
8
- const dataToSignBytes = hexToBytes('2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae' as HexString)
9
- const dataToSignWithHelpers = wrapBytesWithHelpers(dataToSignBytes)
10
-
11
- const expectedSignatureHex =
12
- '336d24afef78c5883b96ad9a62552a8db3d236105cb059ddd04dc49680869dc16234f6852c277087f025d4114c4fac6b40295ecffd1194a84cdb91bd571769491b' as HexString
13
- const expectedSignatureBytes = hexToBytes(expectedSignatureHex)
14
-
15
- test('default signer (same data as Bee Go client)', async () => {
16
- const privateKey = hexToBytes(testIdentity.privateKey)
17
- assertBytes(privateKey, 32)
18
-
19
- const signer = makePrivateKeySigner(privateKey)
20
- const signature = await signer.sign(dataToSignWithHelpers)
21
-
22
- expect(signature).toEqual(expectedSignatureBytes)
23
- })
24
-
25
- test('recover address from signature', () => {
26
- const recoveredAddress = recoverAddress(expectedSignatureBytes as Signature, dataToSignWithHelpers)
27
-
28
- expect(bytesToHex(recoveredAddress)).toEqual(testIdentity.address)
29
- })
30
-
31
- describe('makeSigner', () => {
32
- test('converts string', async () => {
33
- const signer = makeSigner(testIdentity.privateKey)
34
- const signature = await signer.sign(dataToSignWithHelpers)
35
-
36
- expect(bytesToHex(signer.address)).toEqual(testIdentity.address)
37
- expect(signature).toEqual(expectedSignatureBytes)
38
- })
39
-
40
- test('converts uintarray', async () => {
41
- const signer = makeSigner(hexToBytes(testIdentity.privateKey))
42
- const signature = await signer.sign(dataToSignWithHelpers)
43
-
44
- expect(bytesToHex(signer.address)).toEqual(testIdentity.address)
45
- expect(signature).toEqual(expectedSignatureBytes)
46
- })
47
-
48
- test('returns already signer object', () => {
49
- const zeroAddress = makeBytes(20)
50
- const signerLikeObject = {
51
- address: zeroAddress,
52
- sign: () => {
53
- // noop
54
- },
55
- }
56
-
57
- const signer = makeSigner(signerLikeObject)
58
-
59
- expect(signer.address).toEqual(zeroAddress)
60
- })
61
-
62
- test('throws for invalid data', () => {
63
- const data = [
64
- null,
65
- 123,
66
- { some: 'property' },
67
- undefined,
68
- Symbol.for('symbol'),
69
- { address: makeBytes(20), sign: 'not a function' },
70
- {
71
- address: makeBytes(10),
72
- sign: () => {
73
- // noop
74
- },
75
- },
76
- ]
77
-
78
- for (const el of data) {
79
- expect(() => {
80
- makeSigner(el)
81
- }).toThrow(TypeError)
82
- }
83
- })
84
- })
85
-
86
- describe('sign', () => {
87
- it('should wrap the digest with helpers', async () => {
88
- const signer = {
89
- sign: digest => {
90
- expect(digest).toHaveProperty('hex')
91
- expect(digest).toHaveProperty('text')
92
- expect(digest).toHaveProperty('json')
93
-
94
- return expectedSignatureHex
95
- },
96
- address: makeBytes(20),
97
- } as Signer
98
-
99
- const result = await sign(signer, dataToSignBytes)
100
- expect(result).toEqual(expectedSignatureBytes)
101
- })
102
-
103
- function testSignerConversion(input: HexString, output: Uint8Array): void {
104
- it(`should convert sign result ${shorten(input)}`, async () => {
105
- const signer = {
106
- sign: () => {
107
- return input
108
- },
109
- address: makeBytes(20),
110
- } as Signer
111
-
112
- const result = await sign(signer, dataToSignBytes)
113
- expect(result).toEqual(output)
114
- })
115
- }
116
-
117
- testSignerConversion(expectedSignatureHex, expectedSignatureBytes)
118
- testSignerConversion(`0x${expectedSignatureHex}`, expectedSignatureBytes)
119
-
120
- function testSignerThrowing(input: unknown): void {
121
- it(`should throw for invalid result ${shorten(input)}`, async () => {
122
- const signer = {
123
- sign: () => {
124
- return input
125
- },
126
- address: makeBytes(20),
127
- } as Signer
128
-
129
- await expect(sign(signer, dataToSignBytes)).rejects.toThrow(TypeError)
130
- })
131
- }
132
-
133
- testSignerThrowing('0x1234')
134
- testSignerThrowing('1234')
135
- testSignerThrowing('asd')
136
- testSignerThrowing(1)
137
- testSignerThrowing([])
138
- testSignerThrowing({})
139
- })
140
- })
@@ -1,25 +0,0 @@
1
- import { Bytes, assertBytes } from '../../../src/utils/bytes'
2
- import { makeSingleOwnerChunk } from '../../../src/chunk/soc'
3
- import { makeContentAddressedChunk } from '../../../src/chunk/cac'
4
- import { testIdentity } from '../../utils'
5
- import { makePrivateKeySigner } from '../../../src/chunk/signer'
6
- import { HexString, hexToBytes, bytesToHex } from '../../../src/utils/hex'
7
-
8
- describe('soc', () => {
9
- const privateKey = hexToBytes(testIdentity.privateKey)
10
- assertBytes(privateKey, 32)
11
- const signer = makePrivateKeySigner(privateKey)
12
- const payload = new Uint8Array([1, 2, 3])
13
- const socHash = '9d453ebb73b2fedaaf44ceddcf7a0aa37f3e3d6453fea5841c31f0ea6d61dc85' as HexString
14
- const identifier = new Uint8Array(32) as Bytes<32>
15
-
16
- test('single owner chunk creation', async () => {
17
- const cac = makeContentAddressedChunk(payload)
18
- const soc = await makeSingleOwnerChunk(cac, identifier, signer)
19
- const socAddress = bytesToHex(soc.address())
20
- const owner = soc.owner()
21
-
22
- expect(socAddress).toEqual(socHash)
23
- expect(owner).toEqual(signer.address)
24
- })
25
- })