@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,365 +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 } from '../../src'
10
- import { testAddress } from '../utils'
11
- import { testAddressAssertions, testBatchIdAssertion } from './assertions'
12
-
13
- describe('BeeDebug class', () => {
14
- function testUrl(url: unknown): void {
15
- it(`should not accept invalid url '${url}'`, () => {
16
- try {
17
- new BeeDebug(url as string)
18
- fail('BeeDebug constructor should have thrown error.')
19
- } catch (e) {
20
- if (e instanceof BeeArgumentError) {
21
- expect(e.value).toEqual(url)
22
-
23
- return
24
- }
25
-
26
- throw e
27
- }
28
- })
29
- }
30
-
31
- testUrl('')
32
- testUrl(null)
33
- testUrl(undefined)
34
- testUrl(1)
35
- testUrl('some-invalid-url')
36
- testUrl('invalid:protocol')
37
- // eslint-disable-next-line no-script-url
38
- testUrl('javascript:console.log()')
39
- testUrl('ws://localhost:1633')
40
-
41
- describe('removePeer', () => {
42
- testAddressAssertions(async (input: unknown) => {
43
- const bee = new BeeDebug(MOCK_SERVER_URL)
44
-
45
- return bee.removePeer(input as string)
46
- })
47
- })
48
-
49
- describe('pingPeer', () => {
50
- testAddressAssertions(async (input: unknown) => {
51
- const bee = new BeeDebug(MOCK_SERVER_URL)
52
-
53
- return bee.pingPeer(input as string)
54
- })
55
- })
56
-
57
- describe('getPeerBalance', () => {
58
- testAddressAssertions(async (input: unknown) => {
59
- const bee = new BeeDebug(MOCK_SERVER_URL)
60
-
61
- return bee.getPeerBalance(input as string)
62
- })
63
- })
64
-
65
- describe('getPastDueConsumptionPeerBalance', () => {
66
- testAddressAssertions(async (input: unknown) => {
67
- const bee = new BeeDebug(MOCK_SERVER_URL)
68
-
69
- return bee.getPastDueConsumptionPeerBalance(input as string)
70
- })
71
- })
72
-
73
- describe('getLastChequesForPeer', () => {
74
- testAddressAssertions(async (input: unknown) => {
75
- const bee = new BeeDebug(MOCK_SERVER_URL)
76
-
77
- return bee.getLastChequesForPeer(input as string)
78
- })
79
- })
80
-
81
- describe('getLastCashoutAction', () => {
82
- testAddressAssertions(async (input: unknown) => {
83
- const bee = new BeeDebug(MOCK_SERVER_URL)
84
-
85
- return bee.getLastCashoutAction(input as string)
86
- })
87
- })
88
-
89
- describe('getSettlements', () => {
90
- testAddressAssertions(async (input: unknown) => {
91
- const bee = new BeeDebug(MOCK_SERVER_URL)
92
-
93
- return bee.getSettlements(input as string)
94
- })
95
- })
96
-
97
- describe('cashoutLastCheque', () => {
98
- const TRANSACTION_HASH = '36b7efd913ca4cf880b8eeac5093fa27b0825906c600685b6abdd6566e6cfe8f'
99
- const CASHOUT_RESPONSE = {
100
- transactionHash: TRANSACTION_HASH,
101
- }
102
-
103
- it('should not pass headers if no gas price is specified', async () => {
104
- cashoutLastChequeMock(testAddress).reply(201, CASHOUT_RESPONSE)
105
-
106
- const bee = new BeeDebug(MOCK_SERVER_URL)
107
- await expect(bee.cashoutLastCheque(testAddress)).resolves.toEqual(TRANSACTION_HASH)
108
- assertAllIsDone()
109
- })
110
-
111
- it('should pass headers if gas price is specified', async () => {
112
- cashoutLastChequeMock(testAddress, '100000000000').reply(201, CASHOUT_RESPONSE)
113
-
114
- const bee = new BeeDebug(MOCK_SERVER_URL)
115
- await expect(bee.cashoutLastCheque(testAddress, { gasPrice: '100000000000' })).resolves.toEqual(TRANSACTION_HASH)
116
- assertAllIsDone()
117
- })
118
-
119
- it('should pass headers if gas limit is specified', async () => {
120
- cashoutLastChequeMock(testAddress, undefined, '100000000000').reply(201, CASHOUT_RESPONSE)
121
-
122
- const bee = new BeeDebug(MOCK_SERVER_URL)
123
- await expect(bee.cashoutLastCheque(testAddress, { gasLimit: '100000000000' })).resolves.toEqual(TRANSACTION_HASH)
124
- assertAllIsDone()
125
- })
126
-
127
- testAddressAssertions(async (input: unknown) => {
128
- const bee = new BeeDebug(MOCK_SERVER_URL)
129
-
130
- return bee.cashoutLastCheque(input as string)
131
- })
132
-
133
- it('should throw error if passed wrong gas price input', async () => {
134
- const bee = new BeeDebug(MOCK_SERVER_URL)
135
-
136
- // @ts-ignore: Input testing
137
- await expect(bee.cashoutLastCheque(testAddress, { gasPrice: 'asd' })).rejects.toThrow(TypeError)
138
-
139
- // @ts-ignore: Input testing
140
- await expect(bee.cashoutLastCheque(testAddress, { gasPrice: true })).rejects.toThrow(TypeError)
141
- await expect(bee.cashoutLastCheque(testAddress, { gasPrice: '-1' })).rejects.toThrow(BeeArgumentError)
142
- })
143
-
144
- it('should throw error if passed wrong gas limit input', async () => {
145
- const bee = new BeeDebug(MOCK_SERVER_URL)
146
-
147
- // @ts-ignore: Input testing
148
- await expect(bee.cashoutLastCheque(testAddress, { gasLimit: 'asd' })).rejects.toThrow(TypeError)
149
-
150
- // @ts-ignore: Input testing
151
- await expect(bee.cashoutLastCheque(testAddress, { gasLimit: true })).rejects.toThrow(TypeError)
152
- await expect(bee.cashoutLastCheque(testAddress, { gasLimit: '-1' })).rejects.toThrow(BeeArgumentError)
153
- })
154
- })
155
-
156
- describe('withdrawTokens', () => {
157
- const TRANSACTION_HASH = '36b7efd913ca4cf880b8eeac5093fa27b0825906c600685b6abdd6566e6cfe8f'
158
- const CASHOUT_RESPONSE = {
159
- transactionHash: TRANSACTION_HASH,
160
- }
161
-
162
- it('should not pass headers if no gas price is specified', async () => {
163
- withdrawTokensMock('10').reply(201, CASHOUT_RESPONSE)
164
-
165
- const bee = new BeeDebug(MOCK_SERVER_URL)
166
- await expect(bee.withdrawTokens('10')).resolves.toEqual(TRANSACTION_HASH)
167
- assertAllIsDone()
168
- })
169
-
170
- it('should pass headers if gas price is specified', async () => {
171
- withdrawTokensMock('10', '100000000000').reply(201, CASHOUT_RESPONSE)
172
-
173
- const bee = new BeeDebug(MOCK_SERVER_URL)
174
- await expect(bee.withdrawTokens('10', '100000000000')).resolves.toEqual(TRANSACTION_HASH)
175
- assertAllIsDone()
176
- })
177
-
178
- it('should throw error if passed wrong amount', async () => {
179
- const bee = new BeeDebug(MOCK_SERVER_URL)
180
-
181
- // @ts-ignore: Input testing
182
- await expect(bee.withdrawTokens(true)).rejects.toThrow(TypeError)
183
-
184
- // @ts-ignore: Input testing
185
- await expect(bee.withdrawTokens('asd')).rejects.toThrow(TypeError)
186
- // @ts-ignore: Input testing
187
- await expect(bee.withdrawTokens(null)).rejects.toThrow(TypeError)
188
- // @ts-ignore: Input testing
189
- await expect(bee.withdrawTokens()).rejects.toThrow(TypeError)
190
-
191
- await expect(bee.withdrawTokens('-1')).rejects.toThrow(BeeArgumentError)
192
- })
193
-
194
- it('should throw error if passed wrong gas price input', async () => {
195
- const bee = new BeeDebug(MOCK_SERVER_URL)
196
-
197
- // @ts-ignore: Input testing
198
- await expect(bee.withdrawTokens('1', true)).rejects.toThrow(TypeError)
199
- // @ts-ignore: Input testing
200
- await expect(bee.withdrawTokens('1', 'asd')).rejects.toThrow(TypeError)
201
- await expect(bee.withdrawTokens('1', '-1')).rejects.toThrow(BeeArgumentError)
202
- })
203
- })
204
-
205
- describe('depositTokens', () => {
206
- const TRANSACTION_HASH = '36b7efd913ca4cf880b8eeac5093fa27b0825906c600685b6abdd6566e6cfe8f'
207
- const CASHOUT_RESPONSE = {
208
- transactionHash: TRANSACTION_HASH,
209
- }
210
-
211
- it('should not pass headers if no gas price is specified', async () => {
212
- depositTokensMock('10').reply(201, CASHOUT_RESPONSE)
213
-
214
- const bee = new BeeDebug(MOCK_SERVER_URL)
215
- await expect(bee.depositTokens('10')).resolves.toEqual(TRANSACTION_HASH)
216
- assertAllIsDone()
217
- })
218
-
219
- it('should pass headers if gas price is specified', async () => {
220
- depositTokensMock('10', '100000000000').reply(201, CASHOUT_RESPONSE)
221
-
222
- const bee = new BeeDebug(MOCK_SERVER_URL)
223
- await expect(bee.depositTokens('10', '100000000000')).resolves.toEqual(TRANSACTION_HASH)
224
- assertAllIsDone()
225
- })
226
-
227
- it('should throw error if passed wrong amount', async () => {
228
- const bee = new BeeDebug(MOCK_SERVER_URL)
229
-
230
- // @ts-ignore: Input testing
231
- await expect(bee.depositTokens(true)).rejects.toThrow(TypeError)
232
-
233
- // @ts-ignore: Input testing
234
- await expect(bee.depositTokens('asd')).rejects.toThrow(TypeError)
235
- // @ts-ignore: Input testing
236
- await expect(bee.depositTokens(null)).rejects.toThrow(TypeError)
237
- // @ts-ignore: Input testing
238
- await expect(bee.depositTokens()).rejects.toThrow(TypeError)
239
-
240
- await expect(bee.depositTokens('-1')).rejects.toThrow(BeeArgumentError)
241
- })
242
-
243
- it('should throw error if passed wrong gas price input', async () => {
244
- const bee = new BeeDebug(MOCK_SERVER_URL)
245
-
246
- // @ts-ignore: Input testing
247
- await expect(bee.depositTokens('1', true)).rejects.toThrow(TypeError)
248
- // @ts-ignore: Input testing
249
- await expect(bee.depositTokens('1', 'asd')).rejects.toThrow(TypeError)
250
- await expect(bee.depositTokens('1', '-1')).rejects.toThrow(BeeArgumentError)
251
- })
252
- })
253
-
254
- describe('retrieveExtendedTag', () => {
255
- it('should throw exception for bad Tag', async () => {
256
- const bee = new BeeDebug(MOCK_SERVER_URL)
257
-
258
- // @ts-ignore: Type testing
259
- await expect(bee.retrieveExtendedTag('')).rejects.toThrow(TypeError)
260
- // @ts-ignore: Type testing
261
- await expect(bee.retrieveExtendedTag(true)).rejects.toThrow(TypeError)
262
- // @ts-ignore: Type testing
263
- await expect(bee.retrieveExtendedTag([])).rejects.toThrow(TypeError)
264
- // @ts-ignore: Type testing
265
- await expect(bee.retrieveExtendedTag({})).rejects.toThrow(TypeError)
266
- // @ts-ignore: Type testing
267
- await expect(bee.retrieveExtendedTag(null)).rejects.toThrow(TypeError)
268
- // @ts-ignore: Type testing
269
- await expect(bee.retrieveExtendedTag(undefined)).rejects.toThrow(TypeError)
270
-
271
- // @ts-ignore: Type testing
272
- await expect(bee.retrieveExtendedTag({ total: true })).rejects.toThrow(TypeError)
273
- // @ts-ignore: Type testing
274
- await expect(bee.retrieveExtendedTag({ total: 'asdf' })).rejects.toThrow(TypeError)
275
- // @ts-ignore: Type testing
276
- await expect(bee.retrieveExtendedTag({ total: null })).rejects.toThrow(TypeError)
277
-
278
- await expect(bee.retrieveExtendedTag(-1)).rejects.toThrow(BeeArgumentError)
279
- })
280
- })
281
-
282
- describe('createPostageBatch', () => {
283
- const BATCH_ID = '36b7efd913ca4cf880b8eeac5093fa27b0825906c600685b6abdd6566e6cfe8f'
284
- const BATCH_RESPONSE = {
285
- batchID: BATCH_ID,
286
- }
287
-
288
- it('should not pass headers if no gas price is specified', async () => {
289
- createPostageBatchMock('10', '17').reply(201, BATCH_RESPONSE)
290
-
291
- const bee = new BeeDebug(MOCK_SERVER_URL)
292
- await expect(bee.createPostageBatch('10', 17)).resolves.toEqual(BATCH_ID)
293
- assertAllIsDone()
294
- })
295
-
296
- it('should pass headers if gas price is specified', async () => {
297
- createPostageBatchMock('10', '17', '100').reply(201, BATCH_RESPONSE)
298
-
299
- const bee = new BeeDebug(MOCK_SERVER_URL)
300
- await expect(bee.createPostageBatch('10', 17, { gasPrice: '100' })).resolves.toEqual(BATCH_ID)
301
- assertAllIsDone()
302
- })
303
-
304
- it('should pass headers if immutable flag is specified', async () => {
305
- createPostageBatchMock('10', '17', undefined, undefined, 'true').reply(201, BATCH_RESPONSE)
306
-
307
- const bee = new BeeDebug(MOCK_SERVER_URL)
308
- await expect(bee.createPostageBatch('10', 17, { immutableFlag: true })).resolves.toEqual(BATCH_ID)
309
- assertAllIsDone()
310
- })
311
-
312
- it('should throw error if passed wrong gas price input', async () => {
313
- const bee = new BeeDebug(MOCK_SERVER_URL)
314
-
315
- // @ts-ignore: Input testing
316
- await expect(bee.createPostageBatch('10', 17, { gasPrice: 'asd' })).rejects.toThrow(TypeError)
317
-
318
- // @ts-ignore: Input testing
319
- await expect(bee.createPostageBatch('10', 17, { gasPrice: true })).rejects.toThrow(TypeError)
320
- await expect(bee.createPostageBatch('10', 17, { gasPrice: '-1' })).rejects.toThrow(BeeArgumentError)
321
- })
322
-
323
- it('should throw error if passed wrong immutable input', async () => {
324
- const bee = new BeeDebug(MOCK_SERVER_URL)
325
-
326
- // @ts-ignore: Input testing
327
- await expect(bee.createPostageBatch('10', 17, { immutableFlag: 'asd' })).rejects.toThrow(TypeError)
328
-
329
- // @ts-ignore: Input testing
330
- await expect(bee.createPostageBatch('10', 17, { immutableFlag: -1 })).rejects.toThrow(TypeError)
331
-
332
- // @ts-ignore: Input testing
333
- await expect(bee.createPostageBatch('10', 17, { immutableFlag: 'true' })).rejects.toThrow(TypeError)
334
- })
335
-
336
- it('should throw error if too small depth', async () => {
337
- const bee = new BeeDebug(MOCK_SERVER_URL)
338
-
339
- await expect(bee.createPostageBatch('10', -1)).rejects.toThrow(BeeArgumentError)
340
- await expect(bee.createPostageBatch('10', 15)).rejects.toThrow(BeeArgumentError)
341
- })
342
-
343
- it('should throw error if too big depth', async () => {
344
- const bee = new BeeDebug(MOCK_SERVER_URL)
345
-
346
- await expect(bee.createPostageBatch('10', 256)).rejects.toThrow(BeeArgumentError)
347
- })
348
- })
349
-
350
- describe('getPostageBatch', () => {
351
- testBatchIdAssertion(async (input: unknown) => {
352
- const bee = new BeeDebug(MOCK_SERVER_URL)
353
-
354
- return bee.getPostageBatch(input as BatchId)
355
- })
356
- })
357
-
358
- describe('getPostageBatchBuckets', () => {
359
- testBatchIdAssertion(async (input: unknown) => {
360
- const bee = new BeeDebug(MOCK_SERVER_URL)
361
-
362
- return bee.getPostageBatchBuckets(input as BatchId)
363
- })
364
- })
365
- })
@@ -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
- })
@@ -1,38 +0,0 @@
1
- import { makeSpan } from '../../../src/chunk/span'
2
- import { BeeArgumentError } from '../../../src/utils/error'
3
-
4
- describe('span', () => {
5
- it('should construct correct span', () => {
6
- const expected: [number, Uint8Array][] = [
7
- [2 ** 0, new Uint8Array([0x01, 0, 0, 0, 0, 0, 0, 0])],
8
- [2 ** 4, new Uint8Array([0x10, 0, 0, 0, 0, 0, 0, 0])],
9
- [2 ** 8, new Uint8Array([0, 0x01, 0, 0, 0, 0, 0, 0])],
10
- [2 ** 16, new Uint8Array([0, 0, 0x01, 0, 0, 0, 0, 0])],
11
- [2 ** 24, new Uint8Array([0, 0, 0, 0x01, 0, 0, 0, 0])],
12
- [2 ** 32 - 1, new Uint8Array([0xff, 0xff, 0xff, 0xff, 0, 0, 0, 0])],
13
- ]
14
-
15
- expected.forEach(elem => {
16
- const result = makeSpan(elem[0])
17
- expect(result).toEqual(elem[1])
18
- })
19
- })
20
-
21
- it('should throw error with negative length', () => {
22
- const length = -1
23
- const t = () => makeSpan(length)
24
- expect(t).toThrow(BeeArgumentError)
25
- })
26
-
27
- it('should throw error with zero length', () => {
28
- const length = 0
29
- const t = () => makeSpan(length)
30
- expect(t).toThrow(BeeArgumentError)
31
- })
32
-
33
- it('should throw error when it is too big', () => {
34
- const length = 2 ** 32
35
- const t = () => makeSpan(length)
36
- expect(t).toThrow(BeeArgumentError)
37
- })
38
- })