@ethersphere/bee-js 1.2.1 → 3.0.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 (181) hide show
  1. package/CHANGELOG.md +135 -2
  2. package/README.md +3 -1
  3. package/dist/index.browser.min.js +1 -1
  4. package/dist/index.browser.min.js.LICENSE.txt +51 -0
  5. package/dist/index.browser.min.js.map +1 -1
  6. package/dist/index.min.js +1 -1
  7. package/dist/index.min.js.LICENSE.txt +42 -0
  8. package/dist/index.min.js.map +1 -1
  9. package/dist/src/bee-debug.d.ts +75 -38
  10. package/dist/src/bee.d.ts +88 -82
  11. package/dist/src/chunk/soc.d.ts +6 -6
  12. package/dist/src/feed/index.d.ts +7 -7
  13. package/dist/src/feed/json.d.ts +2 -2
  14. package/dist/src/modules/bytes.d.ts +8 -11
  15. package/dist/src/modules/bzz.d.ts +9 -14
  16. package/dist/src/modules/chunk.d.ts +7 -11
  17. package/dist/src/modules/debug/balance.d.ts +9 -9
  18. package/dist/src/modules/debug/chequebook.d.ts +17 -18
  19. package/dist/src/modules/debug/chunk.d.ts +5 -5
  20. package/dist/src/modules/debug/connectivity.d.ts +7 -7
  21. package/dist/src/modules/debug/settlements.d.ts +5 -5
  22. package/dist/src/modules/debug/stamps.d.ts +7 -5
  23. package/dist/src/modules/debug/states.d.ts +5 -5
  24. package/dist/src/modules/debug/status.d.ts +5 -4
  25. package/dist/src/modules/debug/tag.d.ts +3 -3
  26. package/dist/src/modules/debug/transactions.d.ts +9 -9
  27. package/dist/src/modules/feed.d.ts +5 -5
  28. package/dist/src/modules/pinning.d.ts +9 -9
  29. package/dist/src/modules/pss.d.ts +4 -3
  30. package/dist/src/modules/soc.d.ts +3 -3
  31. package/dist/src/modules/status.d.ts +3 -2
  32. package/dist/src/modules/stewardship.d.ts +4 -4
  33. package/dist/src/modules/tag.d.ts +6 -6
  34. package/dist/src/types/debug.d.ts +4 -2
  35. package/dist/src/types/index.d.ts +71 -19
  36. package/dist/src/utils/bytes.d.ts +1 -1
  37. package/dist/src/utils/data.browser.d.ts +3 -1
  38. package/dist/src/utils/data.d.ts +7 -4
  39. package/dist/src/utils/expose.d.ts +6 -9
  40. package/dist/src/utils/headers.d.ts +3 -3
  41. package/dist/src/utils/http.d.ts +25 -0
  42. package/dist/src/utils/merge.d.ts +8 -0
  43. package/dist/src/utils/pss.d.ts +9 -0
  44. package/dist/src/utils/stream.d.ts +37 -0
  45. package/dist/src/utils/type.d.ts +19 -9
  46. package/package.json +15 -8
  47. package/.babelrc.js +0 -33
  48. package/.depcheckrc.json +0 -27
  49. package/.editorconfig +0 -6
  50. package/.eslintignore +0 -1
  51. package/.eslintrc.js +0 -108
  52. package/.gitattributes +0 -1
  53. package/.github/config.yaml +0 -23
  54. package/.github/workflows/check.yaml +0 -57
  55. package/.github/workflows/publish_npmjs.yaml +0 -20
  56. package/.github/workflows/release_github.yaml +0 -20
  57. package/.github/workflows/tests.yaml +0 -128
  58. package/.huskyrc +0 -5
  59. package/.prettierrc +0 -13
  60. package/.vscode/launch.json +0 -49
  61. package/.vscode/settings.json +0 -39
  62. package/CODEOWNERS +0 -1
  63. package/CODE_OF_CONDUCT.md +0 -76
  64. package/commitlint.config.js +0 -3
  65. package/dist/src/modules/stamps.d.ts +0 -4
  66. package/dist/src/utils/hooks.d.ts +0 -31
  67. package/dist/src/utils/safe-axios.d.ts +0 -8
  68. package/jest-puppeteer.config.js +0 -5
  69. package/jest.config.ts +0 -170
  70. package/src/bee-debug.ts +0 -440
  71. package/src/bee.ts +0 -941
  72. package/src/chunk/bmt.ts +0 -55
  73. package/src/chunk/cac.ts +0 -79
  74. package/src/chunk/serialize.ts +0 -16
  75. package/src/chunk/signer.ts +0 -141
  76. package/src/chunk/soc.ts +0 -190
  77. package/src/chunk/span.ts +0 -33
  78. package/src/feed/index.ts +0 -221
  79. package/src/feed/json.ts +0 -32
  80. package/src/feed/topic.ts +0 -23
  81. package/src/feed/type.ts +0 -12
  82. package/src/index.ts +0 -24
  83. package/src/modules/bytes.ts +0 -75
  84. package/src/modules/bzz.ts +0 -184
  85. package/src/modules/chunk.ts +0 -75
  86. package/src/modules/debug/balance.ts +0 -63
  87. package/src/modules/debug/chequebook.ts +0 -174
  88. package/src/modules/debug/chunk.ts +0 -39
  89. package/src/modules/debug/connectivity.ts +0 -61
  90. package/src/modules/debug/settlements.ts +0 -33
  91. package/src/modules/debug/stamps.ts +0 -69
  92. package/src/modules/debug/states.ts +0 -35
  93. package/src/modules/debug/status.ts +0 -34
  94. package/src/modules/debug/tag.ts +0 -19
  95. package/src/modules/debug/transactions.ts +0 -79
  96. package/src/modules/feed.ts +0 -92
  97. package/src/modules/pinning.ts +0 -74
  98. package/src/modules/pss.ts +0 -48
  99. package/src/modules/soc.ts +0 -41
  100. package/src/modules/stamps.ts +0 -59
  101. package/src/modules/status.ts +0 -13
  102. package/src/modules/stewardship.ts +0 -21
  103. package/src/modules/tag.ts +0 -83
  104. package/src/types/axios/index.d.ts +0 -18
  105. package/src/types/debug.ts +0 -204
  106. package/src/types/index.ts +0 -497
  107. package/src/types/tar-js.d.ts +0 -1
  108. package/src/types/webpack-bundle-analyzer/index.d.ts +0 -13
  109. package/src/utils/bytes.ts +0 -144
  110. package/src/utils/collection.ts +0 -151
  111. package/src/utils/data.browser.ts +0 -24
  112. package/src/utils/data.ts +0 -35
  113. package/src/utils/error.ts +0 -23
  114. package/src/utils/eth.ts +0 -229
  115. package/src/utils/expose.ts +0 -10
  116. package/src/utils/file.ts +0 -40
  117. package/src/utils/hash.ts +0 -16
  118. package/src/utils/headers.ts +0 -63
  119. package/src/utils/hex.ts +0 -186
  120. package/src/utils/hooks.ts +0 -89
  121. package/src/utils/safe-axios.ts +0 -98
  122. package/src/utils/tar.ts +0 -30
  123. package/src/utils/type.ts +0 -302
  124. package/src/utils/uint64.ts +0 -31
  125. package/src/utils/url.ts +0 -52
  126. package/test/bee.sh +0 -187
  127. package/test/data/1.txt +0 -1
  128. package/test/data/2.txt +0 -0
  129. package/test/data/empty +0 -0
  130. package/test/data/sub/3.txt +0 -1
  131. package/test/data/sub//303/251 +0 -0
  132. package/test/data/sub//360/237/230/216 +0 -0
  133. package/test/integration/bee-class.browser.spec.ts +0 -215
  134. package/test/integration/bee-class.spec.ts +0 -595
  135. package/test/integration/bee-debug-class.spec.ts +0 -85
  136. package/test/integration/chunk/bmt.spec.ts +0 -33
  137. package/test/integration/chunk/cac.spec.ts +0 -27
  138. package/test/integration/chunk/soc.spec.ts +0 -38
  139. package/test/integration/feed/index.spec.ts +0 -84
  140. package/test/integration/modules/bytes.spec.ts +0 -23
  141. package/test/integration/modules/bzz.spec.ts +0 -270
  142. package/test/integration/modules/chunk.spec.ts +0 -29
  143. package/test/integration/modules/debug/balance.spec.ts +0 -70
  144. package/test/integration/modules/debug/chequebook.spec.ts +0 -64
  145. package/test/integration/modules/debug/connectivity.spec.ts +0 -69
  146. package/test/integration/modules/debug/settlements.spec.ts +0 -34
  147. package/test/integration/modules/debug/states.spec.ts +0 -34
  148. package/test/integration/modules/debug/status.spec.ts +0 -65
  149. package/test/integration/modules/debug/tag.spec.ts +0 -27
  150. package/test/integration/modules/feed.spec.ts +0 -61
  151. package/test/integration/modules/pinning.spec.ts +0 -155
  152. package/test/integration/modules/pss.spec.ts +0 -92
  153. package/test/integration/modules/status.spec.ts +0 -10
  154. package/test/integration/modules/stewardship.spec.ts +0 -32
  155. package/test/integration/modules/tag.spec.ts +0 -51
  156. package/test/test-type-sequencer.js +0 -36
  157. package/test/testpage/testpage.html +0 -20
  158. package/test/unit/assertions.ts +0 -376
  159. package/test/unit/bee-class.spec.ts +0 -685
  160. package/test/unit/bee-debug-class.spec.ts +0 -365
  161. package/test/unit/chunk/bmt.spec.ts +0 -16
  162. package/test/unit/chunk/cac.spec.ts +0 -29
  163. package/test/unit/chunk/serialize.spec.ts +0 -24
  164. package/test/unit/chunk/signer.spec.ts +0 -140
  165. package/test/unit/chunk/soc.spec.ts +0 -25
  166. package/test/unit/chunk/span.spec.ts +0 -38
  167. package/test/unit/feed/json.spec.ts +0 -73
  168. package/test/unit/nock.ts +0 -134
  169. package/test/unit/utils/bytes.spec.ts +0 -32
  170. package/test/unit/utils/collection.spec.ts +0 -22
  171. package/test/unit/utils/eth.spec.ts +0 -224
  172. package/test/unit/utils/hex.spec.ts +0 -115
  173. package/test/unit/utils/hooks.spec.ts +0 -179
  174. package/test/unit/utils/safe-axios.spec.ts +0 -20
  175. package/test/unit/utils/type.spec.ts +0 -32
  176. package/test/unit/utils/uint64.spec.ts +0 -102
  177. package/test/utils.ts +0 -292
  178. package/tsconfig.json +0 -18
  179. package/tsconfig.test.json +0 -11
  180. package/typedoc.json +0 -7
  181. package/webpack.config.ts +0 -141
@@ -1,685 +0,0 @@
1
- import { assertAllIsDone, createPostageBatchMock, downloadDataMock, fetchFeedUpdateMock, MOCK_SERVER_URL } from './nock'
2
- import {
3
- BatchId,
4
- Bee,
5
- BeeArgumentError,
6
- CollectionUploadOptions,
7
- PssMessageHandler,
8
- ReferenceResponse,
9
- UploadOptions,
10
- } from '../../src'
11
- import { testBatchId, testIdentity, testJsonHash, testJsonPayload, testJsonStringPayload } from '../utils'
12
- import { makeTopicFromString } from '../../src/feed/topic'
13
- import {
14
- testAddressPrefixAssertions,
15
- testBatchIdAssertion,
16
- testCollectionUploadOptionsAssertions,
17
- testDataAssertions,
18
- testFileDataAssertions,
19
- testFileUploadOptionsAssertions,
20
- testPssMessageHandlerAssertions,
21
- testPublicKeyAssertions,
22
- testReferenceAssertions,
23
- testTopicAssertions,
24
- testUploadOptionsAssertions,
25
- testFeedTypeAssertions,
26
- testFeedTopicAssertions,
27
- testEthAddressAssertions,
28
- testMakeSignerAssertions,
29
- } from './assertions'
30
- import { FeedType } from '../../src/feed/type'
31
-
32
- const TOPIC = 'some=very%nice#topic'
33
- const HASHED_TOPIC = makeTopicFromString(TOPIC)
34
-
35
- describe('Bee class', () => {
36
- function testUrl(url: unknown): void {
37
- it(`should not accept invalid url '${url}'`, () => {
38
- try {
39
- new Bee(url as string)
40
- fail('Bee constructor should have thrown error.')
41
- } catch (e) {
42
- if (e instanceof BeeArgumentError) {
43
- expect(e.value).toEqual(url)
44
-
45
- return
46
- }
47
-
48
- throw e
49
- }
50
- })
51
- }
52
-
53
- testUrl('')
54
- testUrl(null)
55
- testUrl(undefined)
56
- testUrl(1)
57
- testUrl('some-invalid-url')
58
- testUrl('invalid:protocol')
59
- // eslint-disable-next-line no-script-url
60
- testUrl('javascript:console.log()')
61
- testUrl('ws://localhost:1633')
62
-
63
- describe('uploadData', () => {
64
- testBatchIdAssertion(async (input: unknown) => {
65
- const bee = new Bee(MOCK_SERVER_URL)
66
-
67
- return bee.uploadData(input as BatchId, '')
68
- })
69
-
70
- testDataAssertions(async (input: unknown) => {
71
- const bee = new Bee(MOCK_SERVER_URL)
72
-
73
- return bee.uploadData(testBatchId, input as string)
74
- })
75
-
76
- testUploadOptionsAssertions(async (input: unknown) => {
77
- const bee = new Bee(MOCK_SERVER_URL)
78
-
79
- return bee.uploadData(testBatchId, '', input as UploadOptions)
80
- })
81
- })
82
-
83
- describe('downloadData', () => {
84
- testReferenceAssertions(async (input: unknown) => {
85
- const bee = new Bee(MOCK_SERVER_URL)
86
-
87
- return bee.downloadData(input as string)
88
- })
89
- })
90
-
91
- describe('downloadReadableData', () => {
92
- testReferenceAssertions(async (input: unknown) => {
93
- const bee = new Bee(MOCK_SERVER_URL)
94
-
95
- return bee.downloadReadableData(input as string)
96
- })
97
- })
98
-
99
- describe('uploadFile', () => {
100
- testBatchIdAssertion(async (input: unknown) => {
101
- const bee = new Bee(MOCK_SERVER_URL)
102
-
103
- return bee.uploadFile(input as BatchId, '')
104
- })
105
-
106
- testFileDataAssertions(async (input: unknown) => {
107
- const bee = new Bee(MOCK_SERVER_URL)
108
-
109
- return bee.uploadFile(testBatchId, input as string)
110
- })
111
-
112
- testUploadOptionsAssertions(async (input: unknown) => {
113
- const bee = new Bee(MOCK_SERVER_URL)
114
-
115
- return bee.uploadFile(testBatchId, '', undefined, input as UploadOptions)
116
- })
117
-
118
- testFileUploadOptionsAssertions(async (input: unknown) => {
119
- const bee = new Bee(MOCK_SERVER_URL)
120
-
121
- return bee.uploadFile(testBatchId, '', undefined, input as UploadOptions)
122
- })
123
- })
124
-
125
- describe('downloadFile', () => {
126
- testReferenceAssertions(async (input: unknown) => {
127
- const bee = new Bee(MOCK_SERVER_URL)
128
-
129
- return bee.downloadFile(input as string)
130
- })
131
- })
132
-
133
- describe('downloadReadableFile', () => {
134
- testReferenceAssertions(async (input: unknown) => {
135
- const bee = new Bee(MOCK_SERVER_URL)
136
-
137
- return bee.downloadReadableFile(input as string)
138
- })
139
- })
140
-
141
- describe('uploadFiles', () => {
142
- // eslint-disable-next-line @typescript-eslint/no-empty-function
143
- const files = [{ name: 'some name', arrayBuffer() {} }] as File[]
144
-
145
- testBatchIdAssertion(async (input: unknown) => {
146
- const bee = new Bee(MOCK_SERVER_URL)
147
-
148
- return bee.uploadFiles(input as BatchId, files)
149
- })
150
-
151
- testUploadOptionsAssertions(async (input: unknown) => {
152
- const bee = new Bee(MOCK_SERVER_URL)
153
-
154
- return bee.uploadFiles(testBatchId, files, input as UploadOptions)
155
- })
156
-
157
- testCollectionUploadOptionsAssertions(async (input: unknown) => {
158
- const bee = new Bee(MOCK_SERVER_URL)
159
-
160
- return bee.uploadFiles(testBatchId, files, input as UploadOptions)
161
- })
162
- })
163
-
164
- describe('uploadFilesFromDirectory', () => {
165
- testBatchIdAssertion(async (input: unknown) => {
166
- const bee = new Bee(MOCK_SERVER_URL)
167
-
168
- return bee.uploadFilesFromDirectory(input as BatchId, 'some path')
169
- })
170
-
171
- testUploadOptionsAssertions(async (input: unknown) => {
172
- const bee = new Bee(MOCK_SERVER_URL)
173
-
174
- return bee.uploadFilesFromDirectory(testBatchId, 'some path', input as CollectionUploadOptions)
175
- })
176
-
177
- testCollectionUploadOptionsAssertions(async (input: unknown) => {
178
- const bee = new Bee(MOCK_SERVER_URL)
179
-
180
- return bee.uploadFilesFromDirectory(testBatchId, 'some path', input as CollectionUploadOptions)
181
- })
182
-
183
- it('should throw exception for bad Dir', async () => {
184
- const bee = new Bee(MOCK_SERVER_URL)
185
-
186
- await expect(bee.uploadFilesFromDirectory(testBatchId, '')).rejects.toThrow(TypeError)
187
- // @ts-ignore: Type testing
188
- await expect(bee.uploadFilesFromDirectory(testBatchId, true)).rejects.toThrow(TypeError)
189
- // @ts-ignore: Type testing
190
- await expect(bee.uploadFilesFromDirectory(testBatchId, 1)).rejects.toThrow(TypeError)
191
- // @ts-ignore: Type testing
192
- await expect(bee.uploadFilesFromDirectory(testBatchId, [])).rejects.toThrow(TypeError)
193
- // @ts-ignore: Type testing
194
- await expect(bee.uploadFilesFromDirectory(testBatchId, {})).rejects.toThrow(TypeError)
195
- // @ts-ignore: Type testing
196
- await expect(bee.uploadFilesFromDirectory(testBatchId, null)).rejects.toThrow(TypeError)
197
- // @ts-ignore: Type testing
198
- await expect(bee.uploadFilesFromDirectory(testBatchId, undefined)).rejects.toThrow(TypeError)
199
- })
200
- })
201
-
202
- describe('retrieveTag', () => {
203
- it('should throw exception for bad Tag', async () => {
204
- const bee = new Bee(MOCK_SERVER_URL)
205
-
206
- // @ts-ignore: Type testing
207
- await expect(bee.retrieveTag('')).rejects.toThrow(TypeError)
208
- // @ts-ignore: Type testing
209
- await expect(bee.retrieveTag(true)).rejects.toThrow(TypeError)
210
- // @ts-ignore: Type testing
211
- await expect(bee.retrieveTag([])).rejects.toThrow(TypeError)
212
- // @ts-ignore: Type testing
213
- await expect(bee.retrieveTag({})).rejects.toThrow(TypeError)
214
- // @ts-ignore: Type testing
215
- await expect(bee.retrieveTag(null)).rejects.toThrow(TypeError)
216
- // @ts-ignore: Type testing
217
- await expect(bee.retrieveTag(undefined)).rejects.toThrow(TypeError)
218
-
219
- // @ts-ignore: Type testing
220
- await expect(bee.retrieveTag({ total: true })).rejects.toThrow(TypeError)
221
- // @ts-ignore: Type testing
222
- await expect(bee.retrieveTag({ total: 'asdf' })).rejects.toThrow(TypeError)
223
- // @ts-ignore: Type testing
224
- await expect(bee.retrieveTag({ total: null })).rejects.toThrow(TypeError)
225
-
226
- await expect(bee.retrieveTag(-1)).rejects.toThrow(BeeArgumentError)
227
- })
228
- })
229
-
230
- describe('deleteTag', () => {
231
- it('should throw exception for bad Tag', async () => {
232
- const bee = new Bee(MOCK_SERVER_URL)
233
-
234
- // @ts-ignore: Type testing
235
- await expect(bee.deleteTag('')).rejects.toThrow(TypeError)
236
- // @ts-ignore: Type testing
237
- await expect(bee.deleteTag(true)).rejects.toThrow(TypeError)
238
- // @ts-ignore: Type testing
239
- await expect(bee.deleteTag([])).rejects.toThrow(TypeError)
240
- // @ts-ignore: Type testing
241
- await expect(bee.deleteTag({})).rejects.toThrow(TypeError)
242
- // @ts-ignore: Type testing
243
- await expect(bee.deleteTag(null)).rejects.toThrow(TypeError)
244
- // @ts-ignore: Type testing
245
- await expect(bee.deleteTag(undefined)).rejects.toThrow(TypeError)
246
-
247
- // @ts-ignore: Type testing
248
- await expect(bee.deleteTag({ total: true })).rejects.toThrow(TypeError)
249
- // @ts-ignore: Type testing
250
- await expect(bee.deleteTag({ total: 'asdf' })).rejects.toThrow(TypeError)
251
- // @ts-ignore: Type testing
252
- await expect(bee.deleteTag({ total: null })).rejects.toThrow(TypeError)
253
-
254
- await expect(bee.deleteTag(-1)).rejects.toThrow(BeeArgumentError)
255
- })
256
- })
257
-
258
- describe('getAllTags', () => {
259
- it('should throw exception for bad options', async () => {
260
- const bee = new Bee(MOCK_SERVER_URL)
261
-
262
- // @ts-ignore: Type testing
263
- await expect(bee.getAllTags('')).rejects.toThrow(TypeError)
264
- // @ts-ignore: Type testing
265
- await expect(bee.getAllTags(true)).rejects.toThrow(TypeError)
266
- // @ts-ignore: Type testing
267
- await expect(bee.getAllTags(-1)).rejects.toThrow(TypeError)
268
- // @ts-ignore: Type testing
269
- await expect(bee.getAllTags([])).rejects.toThrow(TypeError)
270
- // @ts-ignore: Type testing
271
- await expect(bee.getAllTags(null)).rejects.toThrow(TypeError)
272
- })
273
-
274
- it('should throw exception for bad limit', async () => {
275
- const bee = new Bee(MOCK_SERVER_URL)
276
-
277
- // @ts-ignore: Type testing
278
- await expect(bee.getAllTags({ limit: '' })).rejects.toThrow(TypeError)
279
- // @ts-ignore: Type testing
280
- await expect(bee.getAllTags({ limit: true })).rejects.toThrow(TypeError)
281
- // @ts-ignore: Type testing
282
- await expect(bee.getAllTags({ limit: [] })).rejects.toThrow(TypeError)
283
- // @ts-ignore: Type testing
284
- await expect(bee.getAllTags({ limit: {} })).rejects.toThrow(TypeError)
285
- // @ts-ignore: Type testing
286
- await expect(bee.getAllTags({ limit: null })).rejects.toThrow(TypeError)
287
-
288
- await expect(bee.getAllTags({ limit: -1 })).rejects.toThrow(BeeArgumentError)
289
- await expect(bee.getAllTags({ limit: Number.MAX_VALUE })).rejects.toThrow(BeeArgumentError)
290
- })
291
-
292
- it('should throw exception for bad offset', async () => {
293
- const bee = new Bee(MOCK_SERVER_URL)
294
-
295
- // @ts-ignore: Type testing
296
- await expect(bee.getAllTags({ offset: '' })).rejects.toThrow(TypeError)
297
- // @ts-ignore: Type testing
298
- await expect(bee.getAllTags({ offset: true })).rejects.toThrow(TypeError)
299
- // @ts-ignore: Type testing
300
- await expect(bee.getAllTags({ offset: [] })).rejects.toThrow(TypeError)
301
- // @ts-ignore: Type testing
302
- await expect(bee.getAllTags({ offset: {} })).rejects.toThrow(TypeError)
303
- // @ts-ignore: Type testing
304
- await expect(bee.getAllTags({ offset: null })).rejects.toThrow(TypeError)
305
-
306
- await expect(bee.getAllTags({ offset: -1 })).rejects.toThrow(BeeArgumentError)
307
- })
308
- })
309
-
310
- describe('pin', () => {
311
- testReferenceAssertions(async (input: unknown) => {
312
- const bee = new Bee(MOCK_SERVER_URL)
313
-
314
- return bee.pin(input as string)
315
- })
316
- })
317
-
318
- describe('unpin', () => {
319
- testReferenceAssertions(async (input: unknown) => {
320
- const bee = new Bee(MOCK_SERVER_URL)
321
-
322
- return bee.unpin(input as string)
323
- })
324
- })
325
-
326
- describe('getPin', () => {
327
- testReferenceAssertions(async (input: unknown) => {
328
- const bee = new Bee(MOCK_SERVER_URL)
329
-
330
- return bee.getPin(input as string)
331
- })
332
- })
333
-
334
- describe('reuploadPinnedData', () => {
335
- testReferenceAssertions(async (input: unknown) => {
336
- const bee = new Bee(MOCK_SERVER_URL)
337
-
338
- return bee.reuploadPinnedData(input as string)
339
- })
340
- })
341
-
342
- describe('pssSend', () => {
343
- testBatchIdAssertion(async (input: unknown) => {
344
- const bee = new Bee(MOCK_SERVER_URL)
345
-
346
- return bee.pssSend(input as BatchId, 'topic', '123', 'data')
347
- })
348
-
349
- testDataAssertions(async (input: unknown) => {
350
- const bee = new Bee(MOCK_SERVER_URL)
351
-
352
- return bee.pssSend(testBatchId, 'topic', '123', input as string)
353
- })
354
-
355
- testAddressPrefixAssertions(async (input: unknown) => {
356
- const bee = new Bee(MOCK_SERVER_URL)
357
-
358
- return bee.pssSend(testBatchId, 'topic', input as string, '123')
359
- })
360
-
361
- testPublicKeyAssertions(async (input: unknown) => {
362
- const bee = new Bee(MOCK_SERVER_URL)
363
-
364
- return bee.pssSend(testBatchId, 'topic', '123', 'data', input as string)
365
- })
366
-
367
- testTopicAssertions(async (input: unknown) => {
368
- const bee = new Bee(MOCK_SERVER_URL)
369
-
370
- return bee.pssSend(testBatchId, input as string, '123', 'data')
371
- })
372
- })
373
-
374
- describe('pssSubscribe', () => {
375
- testPssMessageHandlerAssertions(async (input: unknown) => {
376
- const bee = new Bee(MOCK_SERVER_URL)
377
-
378
- return bee.pssSubscribe('topic', input as PssMessageHandler)
379
- })
380
-
381
- testTopicAssertions(async (input: unknown) => {
382
- const bee = new Bee(MOCK_SERVER_URL)
383
- const handler = {
384
- // eslint-disable-next-line @typescript-eslint/no-empty-function
385
- onMessage() {},
386
- // eslint-disable-next-line @typescript-eslint/no-empty-function
387
- onError() {},
388
- }
389
-
390
- return bee.pssSubscribe(input as string, handler)
391
- })
392
- })
393
-
394
- describe('pssReceive', () => {
395
- testTopicAssertions(async (input: unknown) => {
396
- const bee = new Bee(MOCK_SERVER_URL)
397
-
398
- return bee.pssReceive(input as string)
399
- })
400
-
401
- it('should throw exception for bad Timeout', async () => {
402
- const bee = new Bee(MOCK_SERVER_URL)
403
-
404
- // @ts-ignore: Type testing
405
- await expect(bee.pssReceive('topic', true)).rejects.toThrow(TypeError)
406
- // @ts-ignore: Type testing
407
- await expect(bee.pssReceive('topic', 'asd')).rejects.toThrow(TypeError)
408
- // @ts-ignore: Type testing
409
- await expect(bee.pssReceive('topic', [])).rejects.toThrow(TypeError)
410
- // @ts-ignore: Type testing
411
- await expect(bee.pssReceive('topic', {})).rejects.toThrow(TypeError)
412
- })
413
- })
414
-
415
- describe('createFeedManifest', () => {
416
- testBatchIdAssertion(async (input: unknown) => {
417
- const bee = new Bee(MOCK_SERVER_URL)
418
-
419
- return bee.createFeedManifest(input as BatchId, 'epoch', '123', testIdentity.address)
420
- })
421
-
422
- testFeedTypeAssertions(async (input: unknown) => {
423
- const bee = new Bee(MOCK_SERVER_URL)
424
-
425
- return bee.createFeedManifest(testBatchId, input as FeedType, '123', testIdentity.address)
426
- })
427
-
428
- testFeedTopicAssertions(async (input: unknown) => {
429
- const bee = new Bee(MOCK_SERVER_URL)
430
-
431
- return bee.createFeedManifest(testBatchId, 'epoch', input as string, testIdentity.address)
432
- })
433
-
434
- testEthAddressAssertions(async (input: unknown) => {
435
- const bee = new Bee(MOCK_SERVER_URL)
436
-
437
- return bee.createFeedManifest(testBatchId, 'epoch', '123', input as string)
438
- })
439
- })
440
-
441
- describe('makeFeedReader', () => {
442
- testFeedTypeAssertions(async (input: unknown) => {
443
- const bee = new Bee(MOCK_SERVER_URL)
444
-
445
- return bee.makeFeedReader(input as FeedType, '123', testIdentity.address)
446
- })
447
-
448
- testFeedTopicAssertions(async (input: unknown) => {
449
- const bee = new Bee(MOCK_SERVER_URL)
450
-
451
- return bee.makeFeedReader('epoch', input as string, testIdentity.address)
452
- })
453
-
454
- testEthAddressAssertions(async (input: unknown) => {
455
- const bee = new Bee(MOCK_SERVER_URL)
456
-
457
- return bee.makeFeedReader('epoch', '123', input as string)
458
- })
459
- })
460
-
461
- describe('makeFeedWriter', () => {
462
- testFeedTypeAssertions(async (input: unknown) => {
463
- const bee = new Bee(MOCK_SERVER_URL)
464
-
465
- return bee.makeFeedWriter(input as FeedType, '123', testIdentity.privateKey)
466
- })
467
-
468
- testFeedTopicAssertions(async (input: unknown) => {
469
- const bee = new Bee(MOCK_SERVER_URL)
470
-
471
- return bee.makeFeedWriter('epoch', input as string, testIdentity.privateKey)
472
- })
473
-
474
- testMakeSignerAssertions(async (input: unknown) => {
475
- const bee = new Bee(MOCK_SERVER_URL)
476
-
477
- return bee.makeFeedWriter('epoch', '123', input as string)
478
- })
479
- })
480
-
481
- describe('setJsonFeed', () => {
482
- testBatchIdAssertion(async (input: unknown) => {
483
- const bee = new Bee(MOCK_SERVER_URL)
484
-
485
- return bee.setJsonFeed(input as BatchId, 'epoch', '123', { signer: testIdentity.privateKey })
486
- })
487
-
488
- testFeedTypeAssertions(async (input: unknown) => {
489
- const bee = new Bee(MOCK_SERVER_URL)
490
-
491
- return bee.setJsonFeed(testBatchId, '123', 'data', { type: input as FeedType, signer: testIdentity.privateKey })
492
- }, false)
493
-
494
- testTopicAssertions(async (input: unknown) => {
495
- const bee = new Bee(MOCK_SERVER_URL)
496
-
497
- return bee.setJsonFeed('epoch', input as string, 'data', { signer: testIdentity.privateKey })
498
- })
499
-
500
- testMakeSignerAssertions(async (input: unknown) => {
501
- const bee = new Bee(MOCK_SERVER_URL)
502
-
503
- return bee.setJsonFeed('epoch', '123', 'data', { signer: input as string })
504
- })
505
- })
506
-
507
- describe('getJsonFeed', () => {
508
- it('should fetch with specified address', async () => {
509
- downloadDataMock(testJsonHash).reply(200, testJsonStringPayload)
510
- fetchFeedUpdateMock(testIdentity.address, HASHED_TOPIC).reply(200, {
511
- reference: testJsonHash,
512
- } as ReferenceResponse)
513
-
514
- const bee = new Bee(MOCK_SERVER_URL)
515
- const json = await bee.getJsonFeed(TOPIC, { address: testIdentity.address })
516
- expect(json).toEqual(testJsonPayload)
517
-
518
- assertAllIsDone()
519
- })
520
-
521
- it('should fetch with specified signer private key', async () => {
522
- downloadDataMock(testJsonHash).reply(200, testJsonStringPayload)
523
- fetchFeedUpdateMock(testIdentity.address, HASHED_TOPIC).reply(200, {
524
- reference: testJsonHash,
525
- } as ReferenceResponse)
526
-
527
- const bee = new Bee(MOCK_SERVER_URL)
528
- const json = await bee.getJsonFeed(TOPIC, { signer: testIdentity.privateKey })
529
- expect(json).toEqual(testJsonPayload)
530
-
531
- assertAllIsDone()
532
- })
533
-
534
- it('should fetch with default instance signer', async () => {
535
- downloadDataMock(testJsonHash).reply(200, testJsonStringPayload)
536
- fetchFeedUpdateMock(testIdentity.address, HASHED_TOPIC).reply(200, {
537
- reference: testJsonHash,
538
- } as ReferenceResponse)
539
-
540
- const bee = new Bee(MOCK_SERVER_URL, { signer: testIdentity.privateKey })
541
- const json = await bee.getJsonFeed(TOPIC)
542
- expect(json).toEqual(testJsonPayload)
543
-
544
- assertAllIsDone()
545
- })
546
-
547
- it('should prioritize address option over default instance signer', async () => {
548
- downloadDataMock(testJsonHash).reply(200, testJsonStringPayload)
549
- fetchFeedUpdateMock(testIdentity.address, HASHED_TOPIC).reply(200, {
550
- reference: testJsonHash,
551
- } as ReferenceResponse)
552
-
553
- const bee = new Bee(MOCK_SERVER_URL, {
554
- // Some other PK
555
- signer: '634fb5a811196d9693e5c9f9d7233cfa93f395c093371017ff44aa9ae6564cdd',
556
- })
557
- const json = await bee.getJsonFeed(TOPIC, { address: testIdentity.address })
558
- expect(json).toEqual(testJsonPayload)
559
-
560
- assertAllIsDone()
561
- })
562
-
563
- it('should prioritize signer option over default instance signer', async () => {
564
- downloadDataMock(testJsonHash).reply(200, testJsonStringPayload)
565
- fetchFeedUpdateMock(testIdentity.address, HASHED_TOPIC).reply(200, {
566
- reference: testJsonHash,
567
- } as ReferenceResponse)
568
-
569
- const bee = new Bee(MOCK_SERVER_URL, {
570
- // Some other PK
571
- signer: '634fb5a811196d9693e5c9f9d7233cfa93f395c093371017ff44aa9ae6564cdd',
572
- })
573
- const json = await bee.getJsonFeed(TOPIC, { signer: testIdentity.privateKey })
574
- expect(json).toEqual(testJsonPayload)
575
-
576
- assertAllIsDone()
577
- })
578
-
579
- it('should fail when both signer and address options are specified', async () => {
580
- const bee = new Bee(MOCK_SERVER_URL)
581
-
582
- await expect(
583
- bee.getJsonFeed(TOPIC, { address: testIdentity.address, signer: testIdentity.privateKey }),
584
- ).rejects.toThrow()
585
- })
586
-
587
- it('should fail if no signer or address is specified', async () => {
588
- const bee = new Bee(MOCK_SERVER_URL)
589
-
590
- await expect(bee.getJsonFeed(TOPIC)).rejects.toThrow()
591
- })
592
- })
593
-
594
- describe('makeSOCReader', () => {
595
- testEthAddressAssertions(async (input: unknown) => {
596
- const bee = new Bee(MOCK_SERVER_URL)
597
-
598
- return bee.makeSOCReader(input as string)
599
- })
600
- })
601
-
602
- describe('makeSOCWriter', () => {
603
- testMakeSignerAssertions(async (input: unknown) => {
604
- const bee = new Bee(MOCK_SERVER_URL)
605
-
606
- return bee.makeSOCWriter(input as string)
607
- }, false)
608
- })
609
-
610
- describe('createPostageBatch', () => {
611
- const BATCH_ID = '36b7efd913ca4cf880b8eeac5093fa27b0825906c600685b6abdd6566e6cfe8f'
612
- const BATCH_RESPONSE = {
613
- batchID: BATCH_ID,
614
- }
615
-
616
- it('should not pass headers if no gas price is specified', async () => {
617
- createPostageBatchMock('10', '17').reply(201, BATCH_RESPONSE)
618
-
619
- const bee = new Bee(MOCK_SERVER_URL)
620
- await expect(bee.createPostageBatch('10', 17)).resolves.toEqual(BATCH_ID)
621
- assertAllIsDone()
622
- })
623
-
624
- it('should pass headers if gas price is specified', async () => {
625
- createPostageBatchMock('10', '17', '100').reply(201, BATCH_RESPONSE)
626
-
627
- const bee = new Bee(MOCK_SERVER_URL)
628
- await expect(bee.createPostageBatch('10', 17, { gasPrice: '100' })).resolves.toEqual(BATCH_ID)
629
- assertAllIsDone()
630
- })
631
-
632
- it('should pass headers if immutable flag is specified', async () => {
633
- createPostageBatchMock('10', '17', undefined, undefined, 'true').reply(201, BATCH_RESPONSE)
634
-
635
- const bee = new Bee(MOCK_SERVER_URL)
636
- await expect(bee.createPostageBatch('10', 17, { immutableFlag: true })).resolves.toEqual(BATCH_ID)
637
- assertAllIsDone()
638
- })
639
-
640
- it('should throw error if passed wrong gas price input', async () => {
641
- const bee = new Bee(MOCK_SERVER_URL)
642
-
643
- // @ts-ignore: Input testing
644
- await expect(bee.createPostageBatch('10', 17, { gasPrice: 'asd' })).rejects.toThrow(TypeError)
645
-
646
- // @ts-ignore: Input testing
647
- await expect(bee.createPostageBatch('10', 17, { gasPrice: true })).rejects.toThrow(TypeError)
648
- await expect(bee.createPostageBatch('10', 17, { gasPrice: '-1' })).rejects.toThrow(BeeArgumentError)
649
- })
650
-
651
- it('should throw error if passed wrong immutable input', async () => {
652
- const bee = new Bee(MOCK_SERVER_URL)
653
-
654
- // @ts-ignore: Input testing
655
- await expect(bee.createPostageBatch('10', 17, { immutableFlag: 'asd' })).rejects.toThrow(TypeError)
656
-
657
- // @ts-ignore: Input testing
658
- await expect(bee.createPostageBatch('10', 17, { immutableFlag: -1 })).rejects.toThrow(TypeError)
659
-
660
- // @ts-ignore: Input testing
661
- await expect(bee.createPostageBatch('10', 17, { immutableFlag: 'true' })).rejects.toThrow(TypeError)
662
- })
663
-
664
- it('should throw error if too small depth', async () => {
665
- const bee = new Bee(MOCK_SERVER_URL)
666
-
667
- await expect(bee.createPostageBatch('10', -1)).rejects.toThrow(BeeArgumentError)
668
- await expect(bee.createPostageBatch('10', 15)).rejects.toThrow(BeeArgumentError)
669
- })
670
-
671
- it('should throw error if too big depth', async () => {
672
- const bee = new Bee(MOCK_SERVER_URL)
673
-
674
- await expect(bee.createPostageBatch('10', 256)).rejects.toThrow(BeeArgumentError)
675
- })
676
- })
677
-
678
- describe('getPostageBatch', () => {
679
- testBatchIdAssertion(async (input: unknown) => {
680
- const bee = new Bee(MOCK_SERVER_URL)
681
-
682
- return bee.getPostageBatch(input as BatchId)
683
- })
684
- })
685
- })