@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.
- package/CHANGELOG.md +91 -0
- package/README.md +2 -2
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/src/bee-debug.d.ts +38 -6
- package/dist/src/bee.d.ts +34 -46
- package/dist/src/modules/chunk.d.ts +2 -10
- package/dist/src/modules/debug/stamps.d.ts +2 -0
- package/dist/src/modules/debug/status.d.ts +10 -4
- package/dist/src/modules/stewardship.d.ts +1 -0
- package/dist/src/types/debug.d.ts +11 -0
- package/dist/src/types/index.d.ts +6 -7
- package/dist/src/utils/bytes.d.ts +1 -1
- package/dist/src/utils/expose.d.ts +1 -0
- package/dist/src/utils/stamps.d.ts +12 -0
- package/package.json +10 -8
- package/.babelrc.js +0 -33
- package/.depcheckrc.json +0 -27
- package/.editorconfig +0 -6
- package/.eslintignore +0 -1
- package/.eslintrc.js +0 -109
- package/.gitattributes +0 -1
- package/.github/config.yaml +0 -23
- package/.github/workflows/check.yaml +0 -57
- package/.github/workflows/publish_npmjs.yaml +0 -20
- package/.github/workflows/release_github.yaml +0 -20
- package/.github/workflows/tests.yaml +0 -128
- package/.huskyrc +0 -5
- package/.prettierrc +0 -13
- package/.vscode/launch.json +0 -49
- package/.vscode/settings.json +0 -39
- package/CODEOWNERS +0 -1
- package/CODE_OF_CONDUCT.md +0 -76
- package/commitlint.config.js +0 -3
- package/dist/src/modules/stamps.d.ts +0 -4
- package/jest-puppeteer.config.js +0 -5
- package/jest.config.ts +0 -85
- package/src/bee-debug.ts +0 -559
- package/src/bee.ts +0 -1070
- package/src/chunk/bmt.ts +0 -55
- package/src/chunk/cac.ts +0 -79
- package/src/chunk/serialize.ts +0 -16
- package/src/chunk/signer.ts +0 -141
- package/src/chunk/soc.ts +0 -190
- package/src/chunk/span.ts +0 -33
- package/src/feed/index.ts +0 -217
- package/src/feed/json.ts +0 -33
- package/src/feed/topic.ts +0 -23
- package/src/feed/type.ts +0 -12
- package/src/index.ts +0 -24
- package/src/modules/bytes.ts +0 -70
- package/src/modules/bzz.ts +0 -179
- package/src/modules/chunk.ts +0 -69
- package/src/modules/debug/balance.ts +0 -63
- package/src/modules/debug/chequebook.ts +0 -175
- package/src/modules/debug/chunk.ts +0 -39
- package/src/modules/debug/connectivity.ts +0 -61
- package/src/modules/debug/settlements.ts +0 -33
- package/src/modules/debug/stamps.ts +0 -76
- package/src/modules/debug/states.ts +0 -35
- package/src/modules/debug/status.ts +0 -35
- package/src/modules/debug/tag.ts +0 -19
- package/src/modules/debug/transactions.ts +0 -79
- package/src/modules/feed.ts +0 -105
- package/src/modules/pinning.ts +0 -74
- package/src/modules/pss.ts +0 -49
- package/src/modules/soc.ts +0 -40
- package/src/modules/stamps.ts +0 -59
- package/src/modules/status.ts +0 -13
- package/src/modules/stewardship.ts +0 -18
- package/src/modules/tag.ts +0 -83
- package/src/types/debug.ts +0 -204
- package/src/types/index.ts +0 -566
- package/src/types/ky-universal/common.d.ts +0 -17
- package/src/types/ky-universal/hooks.d.ts +0 -103
- package/src/types/ky-universal/index.d.ts +0 -125
- package/src/types/ky-universal/options.d.ts +0 -235
- package/src/types/ky-universal/response.d.ts +0 -38
- package/src/types/ky-universal/retry.d.ts +0 -39
- package/src/types/tar-js.d.ts +0 -1
- package/src/types/webpack-bundle-analyzer/index.d.ts +0 -13
- package/src/utils/bytes.ts +0 -144
- package/src/utils/collection.ts +0 -151
- package/src/utils/data.browser.ts +0 -68
- package/src/utils/data.ts +0 -48
- package/src/utils/error.ts +0 -23
- package/src/utils/eth.ts +0 -229
- package/src/utils/expose.ts +0 -48
- package/src/utils/file.ts +0 -40
- package/src/utils/hash.ts +0 -16
- package/src/utils/headers.ts +0 -63
- package/src/utils/hex.ts +0 -186
- package/src/utils/http.ts +0 -141
- package/src/utils/merge.ts +0 -34
- package/src/utils/pss.ts +0 -16
- package/src/utils/stream.ts +0 -146
- package/src/utils/tar.ts +0 -30
- package/src/utils/type.ts +0 -394
- package/src/utils/uint64.ts +0 -31
- package/src/utils/url.ts +0 -52
- package/test/bee.sh +0 -187
- package/test/data/1.txt +0 -1
- package/test/data/2.txt +0 -0
- package/test/data/empty +0 -0
- package/test/data/sub/3.txt +0 -1
- package/test/data/sub//303/251 +0 -0
- package/test/data/sub//360/237/230/216 +0 -0
- package/test/integration/bee-class.browser.spec.ts +0 -272
- package/test/integration/bee-class.spec.ts +0 -631
- package/test/integration/bee-debug-class.spec.ts +0 -85
- package/test/integration/chunk/bmt.spec.ts +0 -33
- package/test/integration/chunk/cac.spec.ts +0 -27
- package/test/integration/chunk/soc.spec.ts +0 -38
- package/test/integration/feed/index.spec.ts +0 -84
- package/test/integration/modules/bytes.spec.ts +0 -23
- package/test/integration/modules/bzz.spec.ts +0 -265
- package/test/integration/modules/chunk.spec.ts +0 -29
- package/test/integration/modules/debug/balance.spec.ts +0 -70
- package/test/integration/modules/debug/chequebook.spec.ts +0 -64
- package/test/integration/modules/debug/connectivity.spec.ts +0 -69
- package/test/integration/modules/debug/settlements.spec.ts +0 -34
- package/test/integration/modules/debug/states.spec.ts +0 -34
- package/test/integration/modules/debug/status.spec.ts +0 -65
- package/test/integration/modules/debug/tag.spec.ts +0 -27
- package/test/integration/modules/debug/transactions.spec.ts +0 -10
- package/test/integration/modules/feed.spec.ts +0 -61
- package/test/integration/modules/pinning.spec.ts +0 -155
- package/test/integration/modules/pss.spec.ts +0 -97
- package/test/integration/modules/status.spec.ts +0 -10
- package/test/integration/modules/stewardship.spec.ts +0 -32
- package/test/integration/modules/tag.spec.ts +0 -51
- package/test/test-type-sequencer.js +0 -36
- package/test/testpage/testpage.html +0 -20
- package/test/tests-setup.ts +0 -94
- package/test/unit/assertions.ts +0 -460
- package/test/unit/bee-class.spec.ts +0 -976
- package/test/unit/bee-debug-class.spec.ts +0 -435
- package/test/unit/chunk/bmt.spec.ts +0 -16
- package/test/unit/chunk/cac.spec.ts +0 -29
- package/test/unit/chunk/serialize.spec.ts +0 -24
- package/test/unit/chunk/signer.spec.ts +0 -140
- package/test/unit/chunk/soc.spec.ts +0 -25
- package/test/unit/chunk/span.spec.ts +0 -38
- package/test/unit/feed/json.spec.ts +0 -73
- package/test/unit/nock.ts +0 -151
- package/test/unit/utils/bytes.spec.ts +0 -32
- package/test/unit/utils/collection.spec.ts +0 -22
- package/test/unit/utils/eth.spec.ts +0 -224
- package/test/unit/utils/hex.spec.ts +0 -115
- package/test/unit/utils/stream.spec.ts +0 -30
- package/test/unit/utils/type.spec.ts +0 -32
- package/test/unit/utils/uint64.spec.ts +0 -102
- package/test/utils.ts +0 -328
- package/tsconfig.json +0 -18
- package/tsconfig.test.json +0 -11
- package/typedoc.json +0 -7
- package/webpack.config.ts +0 -141
|
@@ -1,976 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
assertAllIsDone,
|
|
3
|
-
createPostageBatchMock,
|
|
4
|
-
downloadDataMock,
|
|
5
|
-
fetchFeedUpdateMock,
|
|
6
|
-
MOCK_SERVER_URL,
|
|
7
|
-
uploadFileMock,
|
|
8
|
-
} from './nock'
|
|
9
|
-
import {
|
|
10
|
-
BatchId,
|
|
11
|
-
Bee,
|
|
12
|
-
BeeArgumentError,
|
|
13
|
-
CollectionUploadOptions,
|
|
14
|
-
PssMessageHandler,
|
|
15
|
-
ReferenceResponse,
|
|
16
|
-
UploadOptions,
|
|
17
|
-
RequestOptions,
|
|
18
|
-
PostageBatchOptions,
|
|
19
|
-
} from '../../src'
|
|
20
|
-
import {
|
|
21
|
-
testBatchId,
|
|
22
|
-
testChunkHash,
|
|
23
|
-
testIdentity,
|
|
24
|
-
testJsonHash,
|
|
25
|
-
testJsonPayload,
|
|
26
|
-
testJsonStringPayload,
|
|
27
|
-
} from '../utils'
|
|
28
|
-
import { makeTopicFromString } from '../../src/feed/topic'
|
|
29
|
-
import {
|
|
30
|
-
testAddressPrefixAssertions,
|
|
31
|
-
testBatchIdAssertion,
|
|
32
|
-
testCollectionUploadOptionsAssertions,
|
|
33
|
-
testDataAssertions,
|
|
34
|
-
testFileDataAssertions,
|
|
35
|
-
testFileUploadOptionsAssertions,
|
|
36
|
-
testPssMessageHandlerAssertions,
|
|
37
|
-
testPublicKeyAssertions,
|
|
38
|
-
testReferenceAssertions,
|
|
39
|
-
testTopicAssertions,
|
|
40
|
-
testUploadOptionsAssertions,
|
|
41
|
-
testFeedTypeAssertions,
|
|
42
|
-
testFeedTopicAssertions,
|
|
43
|
-
testEthAddressAssertions,
|
|
44
|
-
testMakeSignerAssertions,
|
|
45
|
-
testRequestOptionsAssertions,
|
|
46
|
-
testPostageBatchOptionsAssertions,
|
|
47
|
-
} from './assertions'
|
|
48
|
-
import { FeedType } from '../../src/feed/type'
|
|
49
|
-
import { isStrictlyObject } from '../../src/utils/type'
|
|
50
|
-
|
|
51
|
-
const TOPIC = 'some=very%nice#topic'
|
|
52
|
-
const HASHED_TOPIC = makeTopicFromString(TOPIC)
|
|
53
|
-
|
|
54
|
-
describe('Bee class', () => {
|
|
55
|
-
function testUrl(url: unknown): void {
|
|
56
|
-
it(`should not accept invalid url '${url}'`, () => {
|
|
57
|
-
try {
|
|
58
|
-
new Bee(url as string)
|
|
59
|
-
fail('Bee constructor should have thrown error.')
|
|
60
|
-
} catch (e) {
|
|
61
|
-
if (e instanceof BeeArgumentError) {
|
|
62
|
-
expect(e.value).toEqual(url)
|
|
63
|
-
|
|
64
|
-
return
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
throw e
|
|
68
|
-
}
|
|
69
|
-
})
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
testUrl('')
|
|
73
|
-
testUrl(null)
|
|
74
|
-
testUrl(undefined)
|
|
75
|
-
testUrl(1)
|
|
76
|
-
testUrl('some-invalid-url')
|
|
77
|
-
testUrl('invalid:protocol')
|
|
78
|
-
// eslint-disable-next-line no-script-url
|
|
79
|
-
testUrl('javascript:console.log()')
|
|
80
|
-
testUrl('ws://localhost:1633')
|
|
81
|
-
|
|
82
|
-
it('should set default headers and use them if specified', async () => {
|
|
83
|
-
const defaultHeaders = { 'X-Awesome-Header': '123' }
|
|
84
|
-
uploadFileMock(testBatchId, 'nice.txt', {}, defaultHeaders).reply(200, {
|
|
85
|
-
reference: testJsonHash,
|
|
86
|
-
} as ReferenceResponse)
|
|
87
|
-
|
|
88
|
-
const bee = new Bee(MOCK_SERVER_URL, { defaultHeaders })
|
|
89
|
-
const reference = await bee.uploadFile(testBatchId, 'hello world', 'nice.txt')
|
|
90
|
-
|
|
91
|
-
expect(reference).toEqual({
|
|
92
|
-
reference: testJsonHash,
|
|
93
|
-
tagUid: 123,
|
|
94
|
-
})
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
describe('uploadData', () => {
|
|
98
|
-
testBatchIdAssertion(async (input: unknown) => {
|
|
99
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
100
|
-
|
|
101
|
-
return bee.uploadData(input as BatchId, '')
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
testRequestOptionsAssertions(async (input, beeOptions) => {
|
|
105
|
-
const bee = new Bee(MOCK_SERVER_URL, beeOptions)
|
|
106
|
-
|
|
107
|
-
return bee.uploadData(testBatchId, '', input as RequestOptions)
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
testDataAssertions(async (input: unknown) => {
|
|
111
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
112
|
-
|
|
113
|
-
return bee.uploadData(testBatchId, input as string)
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
testUploadOptionsAssertions(async (input: unknown) => {
|
|
117
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
118
|
-
|
|
119
|
-
return bee.uploadData(testBatchId, '', input as UploadOptions)
|
|
120
|
-
})
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
describe('downloadData', () => {
|
|
124
|
-
testReferenceAssertions(async (input: unknown) => {
|
|
125
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
126
|
-
|
|
127
|
-
return bee.downloadData(input as string)
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
testRequestOptionsAssertions(async (input: unknown, beeOptions) => {
|
|
131
|
-
const bee = new Bee(MOCK_SERVER_URL, beeOptions)
|
|
132
|
-
|
|
133
|
-
return bee.downloadData(testChunkHash, input as RequestOptions)
|
|
134
|
-
})
|
|
135
|
-
})
|
|
136
|
-
|
|
137
|
-
describe('downloadReadableData', () => {
|
|
138
|
-
testReferenceAssertions(async (input: unknown) => {
|
|
139
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
140
|
-
|
|
141
|
-
return bee.downloadReadableData(input as string)
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
testRequestOptionsAssertions(async (input: unknown, beeOptions) => {
|
|
145
|
-
const bee = new Bee(MOCK_SERVER_URL, beeOptions)
|
|
146
|
-
|
|
147
|
-
return bee.downloadReadableData(testChunkHash, input as RequestOptions)
|
|
148
|
-
})
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
describe('uploadFile', () => {
|
|
152
|
-
testBatchIdAssertion(async (input: unknown) => {
|
|
153
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
154
|
-
|
|
155
|
-
return bee.uploadFile(input as BatchId, '')
|
|
156
|
-
})
|
|
157
|
-
|
|
158
|
-
testRequestOptionsAssertions(async (input: unknown, beeOptions) => {
|
|
159
|
-
const bee = new Bee(MOCK_SERVER_URL, beeOptions)
|
|
160
|
-
|
|
161
|
-
return bee.uploadFile(testBatchId, '', undefined, input as RequestOptions)
|
|
162
|
-
})
|
|
163
|
-
|
|
164
|
-
testFileDataAssertions(async (input: unknown) => {
|
|
165
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
166
|
-
|
|
167
|
-
return bee.uploadFile(testBatchId, input as string)
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
testUploadOptionsAssertions(async (input: unknown) => {
|
|
171
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
172
|
-
|
|
173
|
-
return bee.uploadFile(testBatchId, '', undefined, input as UploadOptions)
|
|
174
|
-
})
|
|
175
|
-
|
|
176
|
-
testFileUploadOptionsAssertions(async (input: unknown) => {
|
|
177
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
178
|
-
|
|
179
|
-
return bee.uploadFile(testBatchId, '', undefined, input as UploadOptions)
|
|
180
|
-
})
|
|
181
|
-
})
|
|
182
|
-
|
|
183
|
-
describe('downloadFile', () => {
|
|
184
|
-
testReferenceAssertions(async (input: unknown) => {
|
|
185
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
186
|
-
|
|
187
|
-
return bee.downloadFile(input as string)
|
|
188
|
-
})
|
|
189
|
-
|
|
190
|
-
testRequestOptionsAssertions(async (input: unknown, beeOptions) => {
|
|
191
|
-
const bee = new Bee(MOCK_SERVER_URL, beeOptions)
|
|
192
|
-
|
|
193
|
-
return bee.downloadFile(testChunkHash, '', input as RequestOptions)
|
|
194
|
-
})
|
|
195
|
-
})
|
|
196
|
-
|
|
197
|
-
describe('downloadReadableFile', () => {
|
|
198
|
-
testReferenceAssertions(async (input: unknown) => {
|
|
199
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
200
|
-
|
|
201
|
-
return bee.downloadReadableFile(input as string)
|
|
202
|
-
})
|
|
203
|
-
|
|
204
|
-
testRequestOptionsAssertions(async (input: unknown, beeOptions) => {
|
|
205
|
-
const bee = new Bee(MOCK_SERVER_URL, beeOptions)
|
|
206
|
-
|
|
207
|
-
return bee.downloadReadableFile(testChunkHash, '', input as RequestOptions)
|
|
208
|
-
})
|
|
209
|
-
})
|
|
210
|
-
|
|
211
|
-
describe('uploadFiles', () => {
|
|
212
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
213
|
-
const files = [{ name: 'some name', arrayBuffer() {} }] as File[]
|
|
214
|
-
|
|
215
|
-
testBatchIdAssertion(async (input: unknown) => {
|
|
216
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
217
|
-
|
|
218
|
-
return bee.uploadFiles(input as BatchId, files)
|
|
219
|
-
})
|
|
220
|
-
|
|
221
|
-
testUploadOptionsAssertions(async (input: unknown) => {
|
|
222
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
223
|
-
|
|
224
|
-
return bee.uploadFiles(testBatchId, files, input as UploadOptions)
|
|
225
|
-
})
|
|
226
|
-
|
|
227
|
-
testCollectionUploadOptionsAssertions(async (input: unknown) => {
|
|
228
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
229
|
-
|
|
230
|
-
return bee.uploadFiles(testBatchId, files, input as UploadOptions)
|
|
231
|
-
})
|
|
232
|
-
|
|
233
|
-
testRequestOptionsAssertions(async (input: unknown, beeOptions) => {
|
|
234
|
-
const bee = new Bee(MOCK_SERVER_URL, beeOptions)
|
|
235
|
-
|
|
236
|
-
return bee.uploadFiles(testBatchId, files, input as RequestOptions)
|
|
237
|
-
})
|
|
238
|
-
})
|
|
239
|
-
|
|
240
|
-
describe('uploadFilesFromDirectory', () => {
|
|
241
|
-
testBatchIdAssertion(async (input: unknown) => {
|
|
242
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
243
|
-
|
|
244
|
-
return bee.uploadFilesFromDirectory(input as BatchId, 'some path')
|
|
245
|
-
})
|
|
246
|
-
|
|
247
|
-
testUploadOptionsAssertions(async (input: unknown) => {
|
|
248
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
249
|
-
|
|
250
|
-
return bee.uploadFilesFromDirectory(testBatchId, 'some path', input as CollectionUploadOptions)
|
|
251
|
-
})
|
|
252
|
-
|
|
253
|
-
testCollectionUploadOptionsAssertions(async (input: unknown) => {
|
|
254
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
255
|
-
|
|
256
|
-
return bee.uploadFilesFromDirectory(testBatchId, 'some path', input as CollectionUploadOptions)
|
|
257
|
-
})
|
|
258
|
-
|
|
259
|
-
testRequestOptionsAssertions(async (input: unknown, beeOptions) => {
|
|
260
|
-
const bee = new Bee(MOCK_SERVER_URL, beeOptions)
|
|
261
|
-
|
|
262
|
-
return bee.uploadFilesFromDirectory(testBatchId, './test/data', input as RequestOptions)
|
|
263
|
-
})
|
|
264
|
-
|
|
265
|
-
it('should throw exception for bad Dir', async () => {
|
|
266
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
267
|
-
|
|
268
|
-
await expect(bee.uploadFilesFromDirectory(testBatchId, '')).rejects.toThrow(TypeError)
|
|
269
|
-
// @ts-ignore: Type testing
|
|
270
|
-
await expect(bee.uploadFilesFromDirectory(testBatchId, true)).rejects.toThrow(TypeError)
|
|
271
|
-
// @ts-ignore: Type testing
|
|
272
|
-
await expect(bee.uploadFilesFromDirectory(testBatchId, 1)).rejects.toThrow(TypeError)
|
|
273
|
-
// @ts-ignore: Type testing
|
|
274
|
-
await expect(bee.uploadFilesFromDirectory(testBatchId, [])).rejects.toThrow(TypeError)
|
|
275
|
-
// @ts-ignore: Type testing
|
|
276
|
-
await expect(bee.uploadFilesFromDirectory(testBatchId, {})).rejects.toThrow(TypeError)
|
|
277
|
-
// @ts-ignore: Type testing
|
|
278
|
-
await expect(bee.uploadFilesFromDirectory(testBatchId, null)).rejects.toThrow(TypeError)
|
|
279
|
-
// @ts-ignore: Type testing
|
|
280
|
-
await expect(bee.uploadFilesFromDirectory(testBatchId, undefined)).rejects.toThrow(TypeError)
|
|
281
|
-
})
|
|
282
|
-
})
|
|
283
|
-
|
|
284
|
-
describe('retrieveTag', () => {
|
|
285
|
-
testRequestOptionsAssertions(async (input: unknown, beeOptions) => {
|
|
286
|
-
const bee = new Bee(MOCK_SERVER_URL, beeOptions)
|
|
287
|
-
|
|
288
|
-
return bee.retrieveTag(0, input as RequestOptions)
|
|
289
|
-
})
|
|
290
|
-
|
|
291
|
-
it('should throw exception for bad Tag', async () => {
|
|
292
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
293
|
-
|
|
294
|
-
// @ts-ignore: Type testing
|
|
295
|
-
await expect(bee.retrieveTag('')).rejects.toThrow(TypeError)
|
|
296
|
-
// @ts-ignore: Type testing
|
|
297
|
-
await expect(bee.retrieveTag(true)).rejects.toThrow(TypeError)
|
|
298
|
-
// @ts-ignore: Type testing
|
|
299
|
-
await expect(bee.retrieveTag([])).rejects.toThrow(TypeError)
|
|
300
|
-
// @ts-ignore: Type testing
|
|
301
|
-
await expect(bee.retrieveTag({})).rejects.toThrow(TypeError)
|
|
302
|
-
// @ts-ignore: Type testing
|
|
303
|
-
await expect(bee.retrieveTag(null)).rejects.toThrow(TypeError)
|
|
304
|
-
// @ts-ignore: Type testing
|
|
305
|
-
await expect(bee.retrieveTag(undefined)).rejects.toThrow(TypeError)
|
|
306
|
-
|
|
307
|
-
// @ts-ignore: Type testing
|
|
308
|
-
await expect(bee.retrieveTag({ total: true })).rejects.toThrow(TypeError)
|
|
309
|
-
// @ts-ignore: Type testing
|
|
310
|
-
await expect(bee.retrieveTag({ total: 'asdf' })).rejects.toThrow(TypeError)
|
|
311
|
-
// @ts-ignore: Type testing
|
|
312
|
-
await expect(bee.retrieveTag({ total: null })).rejects.toThrow(TypeError)
|
|
313
|
-
|
|
314
|
-
await expect(bee.retrieveTag(-1)).rejects.toThrow(BeeArgumentError)
|
|
315
|
-
})
|
|
316
|
-
})
|
|
317
|
-
|
|
318
|
-
describe('deleteTag', () => {
|
|
319
|
-
testRequestOptionsAssertions(async (input: unknown, beeOptions) => {
|
|
320
|
-
const bee = new Bee(MOCK_SERVER_URL, beeOptions)
|
|
321
|
-
|
|
322
|
-
return bee.deleteTag(0, input as RequestOptions)
|
|
323
|
-
})
|
|
324
|
-
|
|
325
|
-
it('should throw exception for bad Tag', async () => {
|
|
326
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
327
|
-
|
|
328
|
-
// @ts-ignore: Type testing
|
|
329
|
-
await expect(bee.deleteTag('')).rejects.toThrow(TypeError)
|
|
330
|
-
// @ts-ignore: Type testing
|
|
331
|
-
await expect(bee.deleteTag(true)).rejects.toThrow(TypeError)
|
|
332
|
-
// @ts-ignore: Type testing
|
|
333
|
-
await expect(bee.deleteTag([])).rejects.toThrow(TypeError)
|
|
334
|
-
// @ts-ignore: Type testing
|
|
335
|
-
await expect(bee.deleteTag({})).rejects.toThrow(TypeError)
|
|
336
|
-
// @ts-ignore: Type testing
|
|
337
|
-
await expect(bee.deleteTag(null)).rejects.toThrow(TypeError)
|
|
338
|
-
// @ts-ignore: Type testing
|
|
339
|
-
await expect(bee.deleteTag(undefined)).rejects.toThrow(TypeError)
|
|
340
|
-
|
|
341
|
-
// @ts-ignore: Type testing
|
|
342
|
-
await expect(bee.deleteTag({ total: true })).rejects.toThrow(TypeError)
|
|
343
|
-
// @ts-ignore: Type testing
|
|
344
|
-
await expect(bee.deleteTag({ total: 'asdf' })).rejects.toThrow(TypeError)
|
|
345
|
-
// @ts-ignore: Type testing
|
|
346
|
-
await expect(bee.deleteTag({ total: null })).rejects.toThrow(TypeError)
|
|
347
|
-
|
|
348
|
-
await expect(bee.deleteTag(-1)).rejects.toThrow(BeeArgumentError)
|
|
349
|
-
})
|
|
350
|
-
})
|
|
351
|
-
|
|
352
|
-
describe('getAllTags', () => {
|
|
353
|
-
testRequestOptionsAssertions(async (input: unknown, beeOptions) => {
|
|
354
|
-
const bee = new Bee(MOCK_SERVER_URL, beeOptions)
|
|
355
|
-
|
|
356
|
-
return bee.getAllTags(input as RequestOptions)
|
|
357
|
-
})
|
|
358
|
-
|
|
359
|
-
it('should throw exception for bad options', async () => {
|
|
360
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
361
|
-
|
|
362
|
-
// @ts-ignore: Type testing
|
|
363
|
-
await expect(bee.getAllTags('')).rejects.toThrow(TypeError)
|
|
364
|
-
// @ts-ignore: Type testing
|
|
365
|
-
await expect(bee.getAllTags(true)).rejects.toThrow(TypeError)
|
|
366
|
-
// @ts-ignore: Type testing
|
|
367
|
-
await expect(bee.getAllTags(-1)).rejects.toThrow(TypeError)
|
|
368
|
-
// @ts-ignore: Type testing
|
|
369
|
-
await expect(bee.getAllTags([])).rejects.toThrow(TypeError)
|
|
370
|
-
// @ts-ignore: Type testing
|
|
371
|
-
await expect(bee.getAllTags(null)).rejects.toThrow(TypeError)
|
|
372
|
-
})
|
|
373
|
-
|
|
374
|
-
it('should throw exception for bad limit', async () => {
|
|
375
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
376
|
-
|
|
377
|
-
// @ts-ignore: Type testing
|
|
378
|
-
await expect(bee.getAllTags({ limit: '' })).rejects.toThrow(TypeError)
|
|
379
|
-
// @ts-ignore: Type testing
|
|
380
|
-
await expect(bee.getAllTags({ limit: true })).rejects.toThrow(TypeError)
|
|
381
|
-
// @ts-ignore: Type testing
|
|
382
|
-
await expect(bee.getAllTags({ limit: [] })).rejects.toThrow(TypeError)
|
|
383
|
-
// @ts-ignore: Type testing
|
|
384
|
-
await expect(bee.getAllTags({ limit: {} })).rejects.toThrow(TypeError)
|
|
385
|
-
// @ts-ignore: Type testing
|
|
386
|
-
await expect(bee.getAllTags({ limit: null })).rejects.toThrow(TypeError)
|
|
387
|
-
|
|
388
|
-
await expect(bee.getAllTags({ limit: -1 })).rejects.toThrow(BeeArgumentError)
|
|
389
|
-
await expect(bee.getAllTags({ limit: Number.MAX_VALUE })).rejects.toThrow(BeeArgumentError)
|
|
390
|
-
})
|
|
391
|
-
|
|
392
|
-
it('should throw exception for bad offset', async () => {
|
|
393
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
394
|
-
|
|
395
|
-
// @ts-ignore: Type testing
|
|
396
|
-
await expect(bee.getAllTags({ offset: '' })).rejects.toThrow(TypeError)
|
|
397
|
-
// @ts-ignore: Type testing
|
|
398
|
-
await expect(bee.getAllTags({ offset: true })).rejects.toThrow(TypeError)
|
|
399
|
-
// @ts-ignore: Type testing
|
|
400
|
-
await expect(bee.getAllTags({ offset: [] })).rejects.toThrow(TypeError)
|
|
401
|
-
// @ts-ignore: Type testing
|
|
402
|
-
await expect(bee.getAllTags({ offset: {} })).rejects.toThrow(TypeError)
|
|
403
|
-
// @ts-ignore: Type testing
|
|
404
|
-
await expect(bee.getAllTags({ offset: null })).rejects.toThrow(TypeError)
|
|
405
|
-
|
|
406
|
-
await expect(bee.getAllTags({ offset: -1 })).rejects.toThrow(BeeArgumentError)
|
|
407
|
-
})
|
|
408
|
-
})
|
|
409
|
-
|
|
410
|
-
describe('pin', () => {
|
|
411
|
-
testRequestOptionsAssertions(async (input: unknown, beeOptions) => {
|
|
412
|
-
const bee = new Bee(MOCK_SERVER_URL, beeOptions)
|
|
413
|
-
|
|
414
|
-
return bee.pin(testChunkHash, input as RequestOptions)
|
|
415
|
-
})
|
|
416
|
-
|
|
417
|
-
testReferenceAssertions(async (input: unknown) => {
|
|
418
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
419
|
-
|
|
420
|
-
return bee.pin(input as string)
|
|
421
|
-
})
|
|
422
|
-
})
|
|
423
|
-
|
|
424
|
-
describe('unpin', () => {
|
|
425
|
-
testRequestOptionsAssertions(async (input: unknown, beeOptions) => {
|
|
426
|
-
const bee = new Bee(MOCK_SERVER_URL, beeOptions)
|
|
427
|
-
|
|
428
|
-
return bee.unpin(testChunkHash, input as RequestOptions)
|
|
429
|
-
})
|
|
430
|
-
testReferenceAssertions(async (input: unknown) => {
|
|
431
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
432
|
-
|
|
433
|
-
return bee.unpin(input as string)
|
|
434
|
-
})
|
|
435
|
-
})
|
|
436
|
-
|
|
437
|
-
describe('getPin', () => {
|
|
438
|
-
testRequestOptionsAssertions(async (input: unknown, beeOptions) => {
|
|
439
|
-
const bee = new Bee(MOCK_SERVER_URL, beeOptions)
|
|
440
|
-
|
|
441
|
-
return bee.getPin(testChunkHash, input as RequestOptions)
|
|
442
|
-
})
|
|
443
|
-
testReferenceAssertions(async (input: unknown) => {
|
|
444
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
445
|
-
|
|
446
|
-
return bee.getPin(input as string)
|
|
447
|
-
})
|
|
448
|
-
})
|
|
449
|
-
|
|
450
|
-
describe('reuploadPinnedData', () => {
|
|
451
|
-
testRequestOptionsAssertions(async (input: unknown, beeOptions) => {
|
|
452
|
-
const bee = new Bee(MOCK_SERVER_URL, beeOptions)
|
|
453
|
-
|
|
454
|
-
return bee.reuploadPinnedData(testChunkHash, input as RequestOptions)
|
|
455
|
-
})
|
|
456
|
-
|
|
457
|
-
testReferenceAssertions(async (input: unknown) => {
|
|
458
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
459
|
-
|
|
460
|
-
return bee.reuploadPinnedData(input as string)
|
|
461
|
-
})
|
|
462
|
-
})
|
|
463
|
-
|
|
464
|
-
describe('pssSend', () => {
|
|
465
|
-
testRequestOptionsAssertions(async (input: unknown, beeOptions) => {
|
|
466
|
-
const bee = new Bee(MOCK_SERVER_URL, beeOptions)
|
|
467
|
-
|
|
468
|
-
return bee.pssSend(testBatchId, 'topic', '123', 'data', '', input as RequestOptions)
|
|
469
|
-
})
|
|
470
|
-
|
|
471
|
-
testBatchIdAssertion(async (input: unknown) => {
|
|
472
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
473
|
-
|
|
474
|
-
return bee.pssSend(input as BatchId, 'topic', '123', 'data')
|
|
475
|
-
})
|
|
476
|
-
|
|
477
|
-
testDataAssertions(async (input: unknown) => {
|
|
478
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
479
|
-
|
|
480
|
-
return bee.pssSend(testBatchId, 'topic', '123', input as string)
|
|
481
|
-
})
|
|
482
|
-
|
|
483
|
-
testAddressPrefixAssertions(async (input: unknown) => {
|
|
484
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
485
|
-
|
|
486
|
-
return bee.pssSend(testBatchId, 'topic', input as string, '123')
|
|
487
|
-
})
|
|
488
|
-
|
|
489
|
-
testPublicKeyAssertions(async (input: unknown) => {
|
|
490
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
491
|
-
|
|
492
|
-
return bee.pssSend(testBatchId, 'topic', '123', 'data', input as string)
|
|
493
|
-
})
|
|
494
|
-
|
|
495
|
-
testTopicAssertions(async (input: unknown) => {
|
|
496
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
497
|
-
|
|
498
|
-
return bee.pssSend(testBatchId, input as string, '123', 'data')
|
|
499
|
-
})
|
|
500
|
-
})
|
|
501
|
-
|
|
502
|
-
describe('pssSubscribe', () => {
|
|
503
|
-
testPssMessageHandlerAssertions(async (input: unknown) => {
|
|
504
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
505
|
-
|
|
506
|
-
return bee.pssSubscribe('topic', input as PssMessageHandler)
|
|
507
|
-
})
|
|
508
|
-
|
|
509
|
-
testTopicAssertions(async (input: unknown) => {
|
|
510
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
511
|
-
const handler = {
|
|
512
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
513
|
-
onMessage() {},
|
|
514
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
515
|
-
onError() {},
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
return bee.pssSubscribe(input as string, handler)
|
|
519
|
-
})
|
|
520
|
-
})
|
|
521
|
-
|
|
522
|
-
describe('pssReceive', () => {
|
|
523
|
-
testTopicAssertions(async (input: unknown) => {
|
|
524
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
525
|
-
|
|
526
|
-
return bee.pssReceive(input as string)
|
|
527
|
-
})
|
|
528
|
-
|
|
529
|
-
it('should throw exception for bad Timeout', async () => {
|
|
530
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
531
|
-
|
|
532
|
-
// @ts-ignore: Type testing
|
|
533
|
-
await expect(bee.pssReceive('topic', true)).rejects.toThrow(TypeError)
|
|
534
|
-
// @ts-ignore: Type testing
|
|
535
|
-
await expect(bee.pssReceive('topic', 'asd')).rejects.toThrow(TypeError)
|
|
536
|
-
// @ts-ignore: Type testing
|
|
537
|
-
await expect(bee.pssReceive('topic', [])).rejects.toThrow(TypeError)
|
|
538
|
-
// @ts-ignore: Type testing
|
|
539
|
-
await expect(bee.pssReceive('topic', {})).rejects.toThrow(TypeError)
|
|
540
|
-
})
|
|
541
|
-
})
|
|
542
|
-
|
|
543
|
-
describe('createFeedManifest', () => {
|
|
544
|
-
testRequestOptionsAssertions(async (input: unknown, beeOptions) => {
|
|
545
|
-
const bee = new Bee(MOCK_SERVER_URL, beeOptions)
|
|
546
|
-
|
|
547
|
-
return bee.createFeedManifest(testBatchId, 'epoch', testChunkHash, testIdentity.address, input as RequestOptions)
|
|
548
|
-
})
|
|
549
|
-
|
|
550
|
-
testBatchIdAssertion(async (input: unknown) => {
|
|
551
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
552
|
-
|
|
553
|
-
return bee.createFeedManifest(input as BatchId, 'epoch', '123', testIdentity.address)
|
|
554
|
-
})
|
|
555
|
-
|
|
556
|
-
testFeedTypeAssertions(async (input: unknown) => {
|
|
557
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
558
|
-
|
|
559
|
-
return bee.createFeedManifest(testBatchId, input as FeedType, '123', testIdentity.address)
|
|
560
|
-
})
|
|
561
|
-
|
|
562
|
-
testFeedTopicAssertions(async (input: unknown) => {
|
|
563
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
564
|
-
|
|
565
|
-
return bee.createFeedManifest(testBatchId, 'epoch', input as string, testIdentity.address)
|
|
566
|
-
})
|
|
567
|
-
|
|
568
|
-
testEthAddressAssertions(async (input: unknown) => {
|
|
569
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
570
|
-
|
|
571
|
-
return bee.createFeedManifest(testBatchId, 'epoch', '123', input as string)
|
|
572
|
-
})
|
|
573
|
-
})
|
|
574
|
-
|
|
575
|
-
describe('makeFeedReader', () => {
|
|
576
|
-
testRequestOptionsAssertions(async (input: unknown, beeOptions) => {
|
|
577
|
-
const bee = new Bee(MOCK_SERVER_URL, beeOptions)
|
|
578
|
-
|
|
579
|
-
return bee.makeFeedReader('epoch', testChunkHash, testIdentity.address, input as RequestOptions)
|
|
580
|
-
}, false)
|
|
581
|
-
|
|
582
|
-
testFeedTypeAssertions(async (input: unknown) => {
|
|
583
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
584
|
-
|
|
585
|
-
return bee.makeFeedReader(input as FeedType, '123', testIdentity.address)
|
|
586
|
-
})
|
|
587
|
-
|
|
588
|
-
testFeedTopicAssertions(async (input: unknown) => {
|
|
589
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
590
|
-
|
|
591
|
-
return bee.makeFeedReader('epoch', input as string, testIdentity.address)
|
|
592
|
-
})
|
|
593
|
-
|
|
594
|
-
testEthAddressAssertions(async (input: unknown) => {
|
|
595
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
596
|
-
|
|
597
|
-
return bee.makeFeedReader('epoch', '123', input as string)
|
|
598
|
-
})
|
|
599
|
-
})
|
|
600
|
-
|
|
601
|
-
describe('makeFeedWriter', () => {
|
|
602
|
-
testRequestOptionsAssertions(async (input: unknown, beeOptions) => {
|
|
603
|
-
const bee = new Bee(MOCK_SERVER_URL, beeOptions)
|
|
604
|
-
|
|
605
|
-
return bee.makeFeedWriter('epoch', testChunkHash, testIdentity.address, input as RequestOptions)
|
|
606
|
-
}, false)
|
|
607
|
-
|
|
608
|
-
testFeedTypeAssertions(async (input: unknown) => {
|
|
609
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
610
|
-
|
|
611
|
-
return bee.makeFeedWriter(input as FeedType, '123', testIdentity.privateKey)
|
|
612
|
-
})
|
|
613
|
-
|
|
614
|
-
testFeedTopicAssertions(async (input: unknown) => {
|
|
615
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
616
|
-
|
|
617
|
-
return bee.makeFeedWriter('epoch', input as string, testIdentity.privateKey)
|
|
618
|
-
})
|
|
619
|
-
|
|
620
|
-
testMakeSignerAssertions(async (input: unknown) => {
|
|
621
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
622
|
-
|
|
623
|
-
return bee.makeFeedWriter('epoch', '123', input as string)
|
|
624
|
-
})
|
|
625
|
-
})
|
|
626
|
-
|
|
627
|
-
describe('setJsonFeed', () => {
|
|
628
|
-
testRequestOptionsAssertions(async (input: unknown, beeOptions) => {
|
|
629
|
-
const bee = new Bee(MOCK_SERVER_URL, beeOptions)
|
|
630
|
-
|
|
631
|
-
let opts
|
|
632
|
-
|
|
633
|
-
if (isStrictlyObject(input)) {
|
|
634
|
-
opts = {
|
|
635
|
-
signer: testIdentity.privateKey,
|
|
636
|
-
...input,
|
|
637
|
-
}
|
|
638
|
-
} else {
|
|
639
|
-
opts = input
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
return bee.setJsonFeed(testBatchId, 'epoch', '123', opts as RequestOptions)
|
|
643
|
-
})
|
|
644
|
-
|
|
645
|
-
testBatchIdAssertion(async (input: unknown) => {
|
|
646
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
647
|
-
|
|
648
|
-
return bee.setJsonFeed(input as BatchId, 'epoch', '123', { signer: testIdentity.privateKey })
|
|
649
|
-
})
|
|
650
|
-
|
|
651
|
-
testFeedTypeAssertions(async (input: unknown) => {
|
|
652
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
653
|
-
|
|
654
|
-
return bee.setJsonFeed(testBatchId, '123', 'data', { type: input as FeedType, signer: testIdentity.privateKey })
|
|
655
|
-
}, false)
|
|
656
|
-
|
|
657
|
-
testTopicAssertions(async (input: unknown) => {
|
|
658
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
659
|
-
|
|
660
|
-
return bee.setJsonFeed('epoch', input as string, 'data', { signer: testIdentity.privateKey })
|
|
661
|
-
})
|
|
662
|
-
|
|
663
|
-
testMakeSignerAssertions(async (input: unknown) => {
|
|
664
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
665
|
-
|
|
666
|
-
return bee.setJsonFeed('epoch', '123', 'data', { signer: input as string })
|
|
667
|
-
})
|
|
668
|
-
})
|
|
669
|
-
|
|
670
|
-
describe('getJsonFeed', () => {
|
|
671
|
-
testRequestOptionsAssertions(async (input: unknown, beeOptions) => {
|
|
672
|
-
const bee = new Bee(MOCK_SERVER_URL, beeOptions)
|
|
673
|
-
|
|
674
|
-
let opts
|
|
675
|
-
|
|
676
|
-
if (isStrictlyObject(input)) {
|
|
677
|
-
opts = {
|
|
678
|
-
signer: testIdentity.privateKey,
|
|
679
|
-
...input,
|
|
680
|
-
}
|
|
681
|
-
} else {
|
|
682
|
-
opts = input
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
return bee.getJsonFeed(TOPIC, opts as RequestOptions)
|
|
686
|
-
})
|
|
687
|
-
|
|
688
|
-
it('should fetch with specified address', async () => {
|
|
689
|
-
downloadDataMock(testJsonHash).reply(200, testJsonStringPayload)
|
|
690
|
-
fetchFeedUpdateMock(testIdentity.address, HASHED_TOPIC).reply(200, {
|
|
691
|
-
reference: testJsonHash,
|
|
692
|
-
} as ReferenceResponse)
|
|
693
|
-
|
|
694
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
695
|
-
const json = await bee.getJsonFeed(TOPIC, { address: testIdentity.address })
|
|
696
|
-
expect(json).toEqual(testJsonPayload)
|
|
697
|
-
|
|
698
|
-
assertAllIsDone()
|
|
699
|
-
})
|
|
700
|
-
|
|
701
|
-
it('should fetch with specified signer private key', async () => {
|
|
702
|
-
downloadDataMock(testJsonHash).reply(200, testJsonStringPayload)
|
|
703
|
-
fetchFeedUpdateMock(testIdentity.address, HASHED_TOPIC).reply(200, {
|
|
704
|
-
reference: testJsonHash,
|
|
705
|
-
} as ReferenceResponse)
|
|
706
|
-
|
|
707
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
708
|
-
const json = await bee.getJsonFeed(TOPIC, { signer: testIdentity.privateKey })
|
|
709
|
-
expect(json).toEqual(testJsonPayload)
|
|
710
|
-
|
|
711
|
-
assertAllIsDone()
|
|
712
|
-
})
|
|
713
|
-
|
|
714
|
-
it('should fetch with default instance signer', async () => {
|
|
715
|
-
downloadDataMock(testJsonHash).reply(200, testJsonStringPayload)
|
|
716
|
-
fetchFeedUpdateMock(testIdentity.address, HASHED_TOPIC).reply(200, {
|
|
717
|
-
reference: testJsonHash,
|
|
718
|
-
} as ReferenceResponse)
|
|
719
|
-
|
|
720
|
-
const bee = new Bee(MOCK_SERVER_URL, { signer: testIdentity.privateKey })
|
|
721
|
-
const json = await bee.getJsonFeed(TOPIC)
|
|
722
|
-
expect(json).toEqual(testJsonPayload)
|
|
723
|
-
|
|
724
|
-
assertAllIsDone()
|
|
725
|
-
})
|
|
726
|
-
|
|
727
|
-
it('should prioritize address option over default instance signer', async () => {
|
|
728
|
-
downloadDataMock(testJsonHash).reply(200, testJsonStringPayload)
|
|
729
|
-
fetchFeedUpdateMock(testIdentity.address, HASHED_TOPIC).reply(200, {
|
|
730
|
-
reference: testJsonHash,
|
|
731
|
-
} as ReferenceResponse)
|
|
732
|
-
|
|
733
|
-
const bee = new Bee(MOCK_SERVER_URL, {
|
|
734
|
-
// Some other PK
|
|
735
|
-
signer: '634fb5a811196d9693e5c9f9d7233cfa93f395c093371017ff44aa9ae6564cdd',
|
|
736
|
-
})
|
|
737
|
-
const json = await bee.getJsonFeed(TOPIC, { address: testIdentity.address })
|
|
738
|
-
expect(json).toEqual(testJsonPayload)
|
|
739
|
-
|
|
740
|
-
assertAllIsDone()
|
|
741
|
-
})
|
|
742
|
-
|
|
743
|
-
it('should prioritize signer option over default instance signer', async () => {
|
|
744
|
-
downloadDataMock(testJsonHash).reply(200, testJsonStringPayload)
|
|
745
|
-
fetchFeedUpdateMock(testIdentity.address, HASHED_TOPIC).reply(200, {
|
|
746
|
-
reference: testJsonHash,
|
|
747
|
-
} as ReferenceResponse)
|
|
748
|
-
|
|
749
|
-
const bee = new Bee(MOCK_SERVER_URL, {
|
|
750
|
-
// Some other PK
|
|
751
|
-
signer: '634fb5a811196d9693e5c9f9d7233cfa93f395c093371017ff44aa9ae6564cdd',
|
|
752
|
-
})
|
|
753
|
-
const json = await bee.getJsonFeed(TOPIC, { signer: testIdentity.privateKey })
|
|
754
|
-
expect(json).toEqual(testJsonPayload)
|
|
755
|
-
|
|
756
|
-
assertAllIsDone()
|
|
757
|
-
})
|
|
758
|
-
|
|
759
|
-
it('should fail when both signer and address options are specified', async () => {
|
|
760
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
761
|
-
|
|
762
|
-
await expect(
|
|
763
|
-
bee.getJsonFeed(TOPIC, { address: testIdentity.address, signer: testIdentity.privateKey }),
|
|
764
|
-
).rejects.toThrow()
|
|
765
|
-
})
|
|
766
|
-
|
|
767
|
-
it('should fail if no signer or address is specified', async () => {
|
|
768
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
769
|
-
|
|
770
|
-
await expect(bee.getJsonFeed(TOPIC)).rejects.toThrow()
|
|
771
|
-
})
|
|
772
|
-
})
|
|
773
|
-
|
|
774
|
-
describe('makeSOCReader', () => {
|
|
775
|
-
testRequestOptionsAssertions(async (input: unknown, beeOptions) => {
|
|
776
|
-
const bee = new Bee(MOCK_SERVER_URL, beeOptions)
|
|
777
|
-
|
|
778
|
-
return bee.makeSOCReader(testIdentity.privateKey, input as RequestOptions)
|
|
779
|
-
}, false)
|
|
780
|
-
|
|
781
|
-
testEthAddressAssertions(async (input: unknown) => {
|
|
782
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
783
|
-
|
|
784
|
-
return bee.makeSOCReader(input as string)
|
|
785
|
-
})
|
|
786
|
-
})
|
|
787
|
-
|
|
788
|
-
describe('makeSOCWriter', () => {
|
|
789
|
-
testRequestOptionsAssertions(async (input: unknown, beeOptions) => {
|
|
790
|
-
const bee = new Bee(MOCK_SERVER_URL, beeOptions)
|
|
791
|
-
|
|
792
|
-
return bee.makeSOCWriter(testIdentity.privateKey, input as RequestOptions)
|
|
793
|
-
}, false)
|
|
794
|
-
|
|
795
|
-
testMakeSignerAssertions(async (input: unknown) => {
|
|
796
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
797
|
-
|
|
798
|
-
return bee.makeSOCWriter(input as string)
|
|
799
|
-
}, false)
|
|
800
|
-
})
|
|
801
|
-
|
|
802
|
-
describe('createPostageBatch', () => {
|
|
803
|
-
const BATCH_ID = '36b7efd913ca4cf880b8eeac5093fa27b0825906c600685b6abdd6566e6cfe8f'
|
|
804
|
-
const BATCH_RESPONSE = {
|
|
805
|
-
batchID: BATCH_ID,
|
|
806
|
-
}
|
|
807
|
-
|
|
808
|
-
testPostageBatchOptionsAssertions(async (input: unknown) => {
|
|
809
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
810
|
-
|
|
811
|
-
return bee.createPostageBatch('10', 17, input as PostageBatchOptions)
|
|
812
|
-
})
|
|
813
|
-
|
|
814
|
-
it('should not pass headers if no gas price is specified', async () => {
|
|
815
|
-
createPostageBatchMock('10', '17').reply(201, BATCH_RESPONSE)
|
|
816
|
-
|
|
817
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
818
|
-
await expect(bee.createPostageBatch('10', 17)).resolves.toEqual(BATCH_ID)
|
|
819
|
-
assertAllIsDone()
|
|
820
|
-
})
|
|
821
|
-
|
|
822
|
-
it('should pass headers if gas price is specified', async () => {
|
|
823
|
-
createPostageBatchMock('10', '17', '100').reply(201, BATCH_RESPONSE)
|
|
824
|
-
|
|
825
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
826
|
-
await expect(bee.createPostageBatch('10', 17, { gasPrice: '100' })).resolves.toEqual(BATCH_ID)
|
|
827
|
-
assertAllIsDone()
|
|
828
|
-
})
|
|
829
|
-
|
|
830
|
-
it('should pass headers if immutable flag is specified', async () => {
|
|
831
|
-
createPostageBatchMock('10', '17', undefined, undefined, 'true').reply(201, BATCH_RESPONSE)
|
|
832
|
-
|
|
833
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
834
|
-
await expect(bee.createPostageBatch('10', 17, { immutableFlag: true })).resolves.toEqual(BATCH_ID)
|
|
835
|
-
assertAllIsDone()
|
|
836
|
-
})
|
|
837
|
-
|
|
838
|
-
it('should throw error if passed wrong gas price input', async () => {
|
|
839
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
840
|
-
|
|
841
|
-
// @ts-ignore: Input testing
|
|
842
|
-
await expect(bee.createPostageBatch('10', 17, { gasPrice: 'asd' })).rejects.toThrow(TypeError)
|
|
843
|
-
|
|
844
|
-
// @ts-ignore: Input testing
|
|
845
|
-
await expect(bee.createPostageBatch('10', 17, { gasPrice: true })).rejects.toThrow(TypeError)
|
|
846
|
-
await expect(bee.createPostageBatch('10', 17, { gasPrice: '-1' })).rejects.toThrow(BeeArgumentError)
|
|
847
|
-
})
|
|
848
|
-
|
|
849
|
-
it('should throw error if passed wrong immutable input', async () => {
|
|
850
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
851
|
-
|
|
852
|
-
// @ts-ignore: Input testing
|
|
853
|
-
await expect(bee.createPostageBatch('10', 17, { immutableFlag: 'asd' })).rejects.toThrow(TypeError)
|
|
854
|
-
|
|
855
|
-
// @ts-ignore: Input testing
|
|
856
|
-
await expect(bee.createPostageBatch('10', 17, { immutableFlag: -1 })).rejects.toThrow(TypeError)
|
|
857
|
-
|
|
858
|
-
// @ts-ignore: Input testing
|
|
859
|
-
await expect(bee.createPostageBatch('10', 17, { immutableFlag: 'true' })).rejects.toThrow(TypeError)
|
|
860
|
-
})
|
|
861
|
-
|
|
862
|
-
it('should throw error if too small depth', async () => {
|
|
863
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
864
|
-
|
|
865
|
-
await expect(bee.createPostageBatch('10', -1)).rejects.toThrow(BeeArgumentError)
|
|
866
|
-
await expect(bee.createPostageBatch('10', 15)).rejects.toThrow(BeeArgumentError)
|
|
867
|
-
})
|
|
868
|
-
|
|
869
|
-
it('should throw error if too big depth', async () => {
|
|
870
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
871
|
-
|
|
872
|
-
await expect(bee.createPostageBatch('10', 256)).rejects.toThrow(BeeArgumentError)
|
|
873
|
-
})
|
|
874
|
-
})
|
|
875
|
-
|
|
876
|
-
describe('getPostageBatch', () => {
|
|
877
|
-
testBatchIdAssertion(async (input: unknown) => {
|
|
878
|
-
const bee = new Bee(MOCK_SERVER_URL)
|
|
879
|
-
|
|
880
|
-
return bee.getPostageBatch(input as BatchId)
|
|
881
|
-
})
|
|
882
|
-
})
|
|
883
|
-
|
|
884
|
-
describe('hooks', () => {
|
|
885
|
-
it('should call with request', async () => {
|
|
886
|
-
const requestSpy = jest.fn()
|
|
887
|
-
const responseSpy = jest.fn()
|
|
888
|
-
|
|
889
|
-
const bee = new Bee(MOCK_SERVER_URL, { onRequest: requestSpy, onResponse: responseSpy })
|
|
890
|
-
|
|
891
|
-
const topic = bee.makeFeedTopic('some-topic')
|
|
892
|
-
fetchFeedUpdateMock(testIdentity.address, topic).reply(200, {
|
|
893
|
-
reference: testJsonHash,
|
|
894
|
-
} as ReferenceResponse)
|
|
895
|
-
|
|
896
|
-
const feedReader = bee.makeFeedReader('sequence', topic, testIdentity.address)
|
|
897
|
-
const feedUpdate = await feedReader.download()
|
|
898
|
-
|
|
899
|
-
expect(feedUpdate.reference).toEqual(testJsonHash)
|
|
900
|
-
|
|
901
|
-
expect(requestSpy.mock.calls.length).toEqual(1)
|
|
902
|
-
expect(requestSpy.mock.calls[0].length).toEqual(1)
|
|
903
|
-
expect(requestSpy.mock.calls[0][0]).toMatchObject({
|
|
904
|
-
url: `${MOCK_SERVER_URL}feeds/${testIdentity.address}/${topic}?type=sequence`,
|
|
905
|
-
method: 'GET',
|
|
906
|
-
headers: { accept: 'application/json, text/plain, */*' },
|
|
907
|
-
})
|
|
908
|
-
|
|
909
|
-
expect(responseSpy.mock.calls.length).toEqual(1)
|
|
910
|
-
expect(responseSpy.mock.calls[0].length).toEqual(1)
|
|
911
|
-
expect(responseSpy.mock.calls[0][0]).toMatchObject({
|
|
912
|
-
status: 200,
|
|
913
|
-
statusText: '',
|
|
914
|
-
headers: {
|
|
915
|
-
'content-type': 'application/json',
|
|
916
|
-
},
|
|
917
|
-
request: {
|
|
918
|
-
url: `${MOCK_SERVER_URL}feeds/${testIdentity.address}/${topic}?type=sequence`,
|
|
919
|
-
method: 'GET',
|
|
920
|
-
headers: { accept: 'application/json, text/plain, */*' },
|
|
921
|
-
},
|
|
922
|
-
})
|
|
923
|
-
assertAllIsDone()
|
|
924
|
-
})
|
|
925
|
-
|
|
926
|
-
it('should call with request with correct headers', async () => {
|
|
927
|
-
const requestSpy = jest.fn()
|
|
928
|
-
const responseSpy = jest.fn()
|
|
929
|
-
const bee = new Bee(MOCK_SERVER_URL, { onRequest: requestSpy, onResponse: responseSpy })
|
|
930
|
-
|
|
931
|
-
uploadFileMock(testBatchId, 'nice.txt', { encrypt: true }).reply(200, {
|
|
932
|
-
reference: testJsonHash,
|
|
933
|
-
} as ReferenceResponse)
|
|
934
|
-
|
|
935
|
-
const reference = await bee.uploadFile(testBatchId, 'hello world', 'nice.txt', { encrypt: true })
|
|
936
|
-
|
|
937
|
-
expect(reference).toEqual({
|
|
938
|
-
reference: testJsonHash,
|
|
939
|
-
tagUid: 123,
|
|
940
|
-
})
|
|
941
|
-
|
|
942
|
-
expect(requestSpy.mock.calls.length).toEqual(1)
|
|
943
|
-
expect(requestSpy.mock.calls[0].length).toEqual(1)
|
|
944
|
-
expect(requestSpy.mock.calls[0][0]).toMatchObject({
|
|
945
|
-
url: `${MOCK_SERVER_URL}bzz?name=nice.txt`,
|
|
946
|
-
method: 'POST',
|
|
947
|
-
headers: {
|
|
948
|
-
accept: 'application/json, text/plain, */*',
|
|
949
|
-
'swarm-encrypt': 'true',
|
|
950
|
-
'swarm-postage-batch-id': testBatchId,
|
|
951
|
-
},
|
|
952
|
-
})
|
|
953
|
-
|
|
954
|
-
expect(responseSpy.mock.calls.length).toEqual(1)
|
|
955
|
-
expect(responseSpy.mock.calls[0].length).toEqual(1)
|
|
956
|
-
expect(responseSpy.mock.calls[0][0]).toMatchObject({
|
|
957
|
-
status: 200,
|
|
958
|
-
statusText: '',
|
|
959
|
-
headers: {
|
|
960
|
-
'content-type': 'application/json',
|
|
961
|
-
},
|
|
962
|
-
request: {
|
|
963
|
-
url: `${MOCK_SERVER_URL}bzz?name=nice.txt`,
|
|
964
|
-
method: 'POST',
|
|
965
|
-
headers: {
|
|
966
|
-
accept: 'application/json, text/plain, */*',
|
|
967
|
-
'swarm-encrypt': 'true',
|
|
968
|
-
'swarm-postage-batch-id': testBatchId,
|
|
969
|
-
},
|
|
970
|
-
},
|
|
971
|
-
})
|
|
972
|
-
|
|
973
|
-
assertAllIsDone()
|
|
974
|
-
})
|
|
975
|
-
})
|
|
976
|
-
})
|