@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.
- package/CHANGELOG.md +135 -2
- package/README.md +3 -1
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.LICENSE.txt +51 -0
- package/dist/index.browser.min.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.LICENSE.txt +42 -0
- package/dist/index.min.js.map +1 -1
- package/dist/src/bee-debug.d.ts +75 -38
- package/dist/src/bee.d.ts +88 -82
- package/dist/src/chunk/soc.d.ts +6 -6
- package/dist/src/feed/index.d.ts +7 -7
- package/dist/src/feed/json.d.ts +2 -2
- package/dist/src/modules/bytes.d.ts +8 -11
- package/dist/src/modules/bzz.d.ts +9 -14
- package/dist/src/modules/chunk.d.ts +7 -11
- package/dist/src/modules/debug/balance.d.ts +9 -9
- package/dist/src/modules/debug/chequebook.d.ts +17 -18
- package/dist/src/modules/debug/chunk.d.ts +5 -5
- package/dist/src/modules/debug/connectivity.d.ts +7 -7
- package/dist/src/modules/debug/settlements.d.ts +5 -5
- package/dist/src/modules/debug/stamps.d.ts +7 -5
- package/dist/src/modules/debug/states.d.ts +5 -5
- package/dist/src/modules/debug/status.d.ts +5 -4
- package/dist/src/modules/debug/tag.d.ts +3 -3
- package/dist/src/modules/debug/transactions.d.ts +9 -9
- package/dist/src/modules/feed.d.ts +5 -5
- package/dist/src/modules/pinning.d.ts +9 -9
- package/dist/src/modules/pss.d.ts +4 -3
- package/dist/src/modules/soc.d.ts +3 -3
- package/dist/src/modules/status.d.ts +3 -2
- package/dist/src/modules/stewardship.d.ts +4 -4
- package/dist/src/modules/tag.d.ts +6 -6
- package/dist/src/types/debug.d.ts +4 -2
- package/dist/src/types/index.d.ts +71 -19
- package/dist/src/utils/bytes.d.ts +1 -1
- package/dist/src/utils/data.browser.d.ts +3 -1
- package/dist/src/utils/data.d.ts +7 -4
- package/dist/src/utils/expose.d.ts +6 -9
- package/dist/src/utils/headers.d.ts +3 -3
- package/dist/src/utils/http.d.ts +25 -0
- package/dist/src/utils/merge.d.ts +8 -0
- package/dist/src/utils/pss.d.ts +9 -0
- package/dist/src/utils/stream.d.ts +37 -0
- package/dist/src/utils/type.d.ts +19 -9
- package/package.json +15 -8
- package/.babelrc.js +0 -33
- package/.depcheckrc.json +0 -27
- package/.editorconfig +0 -6
- package/.eslintignore +0 -1
- package/.eslintrc.js +0 -108
- 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/dist/src/utils/hooks.d.ts +0 -31
- package/dist/src/utils/safe-axios.d.ts +0 -8
- package/jest-puppeteer.config.js +0 -5
- package/jest.config.ts +0 -170
- package/src/bee-debug.ts +0 -440
- package/src/bee.ts +0 -941
- 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 -221
- package/src/feed/json.ts +0 -32
- 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 -75
- package/src/modules/bzz.ts +0 -184
- package/src/modules/chunk.ts +0 -75
- package/src/modules/debug/balance.ts +0 -63
- package/src/modules/debug/chequebook.ts +0 -174
- 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 -69
- package/src/modules/debug/states.ts +0 -35
- package/src/modules/debug/status.ts +0 -34
- package/src/modules/debug/tag.ts +0 -19
- package/src/modules/debug/transactions.ts +0 -79
- package/src/modules/feed.ts +0 -92
- package/src/modules/pinning.ts +0 -74
- package/src/modules/pss.ts +0 -48
- package/src/modules/soc.ts +0 -41
- package/src/modules/stamps.ts +0 -59
- package/src/modules/status.ts +0 -13
- package/src/modules/stewardship.ts +0 -21
- package/src/modules/tag.ts +0 -83
- package/src/types/axios/index.d.ts +0 -18
- package/src/types/debug.ts +0 -204
- package/src/types/index.ts +0 -497
- 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 -24
- package/src/utils/data.ts +0 -35
- package/src/utils/error.ts +0 -23
- package/src/utils/eth.ts +0 -229
- package/src/utils/expose.ts +0 -10
- 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/hooks.ts +0 -89
- package/src/utils/safe-axios.ts +0 -98
- package/src/utils/tar.ts +0 -30
- package/src/utils/type.ts +0 -302
- 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 -215
- package/test/integration/bee-class.spec.ts +0 -595
- 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 -270
- 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/feed.spec.ts +0 -61
- package/test/integration/modules/pinning.spec.ts +0 -155
- package/test/integration/modules/pss.spec.ts +0 -92
- 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/unit/assertions.ts +0 -376
- package/test/unit/bee-class.spec.ts +0 -685
- package/test/unit/bee-debug-class.spec.ts +0 -365
- 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 -134
- 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/hooks.spec.ts +0 -179
- package/test/unit/utils/safe-axios.spec.ts +0 -20
- package/test/unit/utils/type.spec.ts +0 -32
- package/test/unit/utils/uint64.spec.ts +0 -102
- package/test/utils.ts +0 -292
- package/tsconfig.json +0 -18
- package/tsconfig.test.json +0 -11
- package/typedoc.json +0 -7
- package/webpack.config.ts +0 -141
|
@@ -1,595 +0,0 @@
|
|
|
1
|
-
import { Bee, BeeArgumentError, BeeDebug, Collection } from '../../src'
|
|
2
|
-
import { makeSigner } from '../../src/chunk/signer'
|
|
3
|
-
import { makeSOCAddress, uploadSingleOwnerChunkData } from '../../src/chunk/soc'
|
|
4
|
-
import { ChunkReference } from '../../src/feed'
|
|
5
|
-
import * as bzz from '../../src/modules/bzz'
|
|
6
|
-
import { REFERENCE_HEX_LENGTH } from '../../src/types'
|
|
7
|
-
import { makeBytes } from '../../src/utils/bytes'
|
|
8
|
-
import { makeEthAddress } from '../../src/utils/eth'
|
|
9
|
-
import { bytesToHex, HexString } from '../../src/utils/hex'
|
|
10
|
-
import {
|
|
11
|
-
beeDebugUrl,
|
|
12
|
-
beePeerDebugUrl,
|
|
13
|
-
beePeerUrl,
|
|
14
|
-
beeUrl,
|
|
15
|
-
commonMatchers,
|
|
16
|
-
createRandomReadable,
|
|
17
|
-
FEED_TIMEOUT,
|
|
18
|
-
getPostageBatch,
|
|
19
|
-
POSTAGE_BATCH_TIMEOUT,
|
|
20
|
-
PSS_TIMEOUT,
|
|
21
|
-
randomByteArray,
|
|
22
|
-
sleep,
|
|
23
|
-
testChunkPayload,
|
|
24
|
-
testIdentity,
|
|
25
|
-
testJsonHash,
|
|
26
|
-
testJsonPayload,
|
|
27
|
-
tryDeleteChunkFromLocalStorage,
|
|
28
|
-
} from '../utils'
|
|
29
|
-
import { Readable } from 'stream'
|
|
30
|
-
|
|
31
|
-
commonMatchers()
|
|
32
|
-
|
|
33
|
-
describe('Bee class', () => {
|
|
34
|
-
const BEE_URL = beeUrl()
|
|
35
|
-
const BEE_PEER_URL = beePeerUrl()
|
|
36
|
-
const BEE_DEBUG_PEER_URL = beePeerDebugUrl()
|
|
37
|
-
const bee = new Bee(BEE_URL)
|
|
38
|
-
const beePeer = new Bee(BEE_PEER_URL)
|
|
39
|
-
|
|
40
|
-
it('should strip trailing slash', () => {
|
|
41
|
-
const bee = new Bee('http://localhost:1633/')
|
|
42
|
-
expect(bee.url).toEqual('http://localhost:1633')
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
describe('files', () => {
|
|
46
|
-
it('should work with files', async () => {
|
|
47
|
-
const content = new Uint8Array([1, 2, 3])
|
|
48
|
-
const name = 'hello.txt'
|
|
49
|
-
const contentType = 'text/html'
|
|
50
|
-
|
|
51
|
-
const hash = await bee.uploadFile(getPostageBatch(), content, name, { contentType })
|
|
52
|
-
const file = await bee.downloadFile(hash)
|
|
53
|
-
|
|
54
|
-
expect(file.name).toEqual(name)
|
|
55
|
-
expect(file.data).toEqual(content)
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
it('should work with files and tags', async () => {
|
|
59
|
-
const tag = await bee.createTag()
|
|
60
|
-
|
|
61
|
-
// Should fit into 4 chunks
|
|
62
|
-
const content = randomByteArray(13000)
|
|
63
|
-
const name = 'hello.txt'
|
|
64
|
-
const contentType = 'text/html'
|
|
65
|
-
|
|
66
|
-
const hash = await bee.uploadFile(getPostageBatch(), content, name, { contentType, tag: tag.uid })
|
|
67
|
-
const file = await bee.downloadFile(hash)
|
|
68
|
-
|
|
69
|
-
expect(file.name).toEqual(name)
|
|
70
|
-
expect(file.data).toEqual(content)
|
|
71
|
-
|
|
72
|
-
const retrievedTag = await bee.retrieveTag(tag)
|
|
73
|
-
expect(retrievedTag.total).toEqual(8)
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
it('should work with file object', async () => {
|
|
77
|
-
const content = new Uint8Array([1, 2, 3])
|
|
78
|
-
const name = 'hello.txt'
|
|
79
|
-
const type = 'text/plain'
|
|
80
|
-
const file = {
|
|
81
|
-
arrayBuffer: () => content,
|
|
82
|
-
name,
|
|
83
|
-
type,
|
|
84
|
-
} as unknown as File
|
|
85
|
-
|
|
86
|
-
const hash = await bee.uploadFile(getPostageBatch(), file)
|
|
87
|
-
const downloadedFile = await bee.downloadFile(hash)
|
|
88
|
-
|
|
89
|
-
expect(downloadedFile.data).toEqual(content)
|
|
90
|
-
expect(downloadedFile.name).toEqual(name)
|
|
91
|
-
expect(downloadedFile.contentType).toEqual(type)
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
it('should work with file object and name overridden', async () => {
|
|
95
|
-
const content = new Uint8Array([1, 2, 3])
|
|
96
|
-
const name = 'hello.txt'
|
|
97
|
-
const file = {
|
|
98
|
-
arrayBuffer: () => content,
|
|
99
|
-
name,
|
|
100
|
-
} as unknown as File
|
|
101
|
-
const nameOverride = 'hello-override.txt'
|
|
102
|
-
|
|
103
|
-
const hash = await bee.uploadFile(getPostageBatch(), file, nameOverride)
|
|
104
|
-
const downloadedFile = await bee.downloadFile(hash)
|
|
105
|
-
|
|
106
|
-
expect(downloadedFile.data).toEqual(content)
|
|
107
|
-
expect(downloadedFile.name).toEqual(nameOverride)
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
it('should work with file object and content-type overridden', async () => {
|
|
111
|
-
const content = new Uint8Array([1, 2, 3])
|
|
112
|
-
const file = {
|
|
113
|
-
arrayBuffer: () => content,
|
|
114
|
-
name: 'hello.txt',
|
|
115
|
-
type: 'text/plain',
|
|
116
|
-
} as unknown as File
|
|
117
|
-
const contentTypeOverride = 'text/plain+override'
|
|
118
|
-
|
|
119
|
-
const hash = await bee.uploadFile(getPostageBatch(), file, undefined, { contentType: contentTypeOverride })
|
|
120
|
-
const downloadedFile = await bee.downloadFile(hash)
|
|
121
|
-
|
|
122
|
-
expect(downloadedFile.data).toEqual(content)
|
|
123
|
-
expect(downloadedFile.contentType).toEqual(contentTypeOverride)
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
it('should work with readable', async () => {
|
|
127
|
-
const readable = Readable.from(['hello world'])
|
|
128
|
-
const name = 'hello.txt'
|
|
129
|
-
const contentType = 'text/plain'
|
|
130
|
-
|
|
131
|
-
const hash = await bee.uploadFile(getPostageBatch(), readable, name, { contentType })
|
|
132
|
-
const file = await bee.downloadFile(hash)
|
|
133
|
-
|
|
134
|
-
expect(file.name).toEqual(name)
|
|
135
|
-
expect(file.data.text()).toEqual('hello world')
|
|
136
|
-
})
|
|
137
|
-
|
|
138
|
-
it('should work with readable and tags', async () => {
|
|
139
|
-
const tag = await bee.createTag()
|
|
140
|
-
|
|
141
|
-
const readable = createRandomReadable(13000)
|
|
142
|
-
const name = 'hello.txt'
|
|
143
|
-
const contentType = 'text/plain'
|
|
144
|
-
|
|
145
|
-
const hash = await bee.uploadFile(getPostageBatch(), readable, name, {
|
|
146
|
-
contentType,
|
|
147
|
-
tag: tag.uid,
|
|
148
|
-
})
|
|
149
|
-
|
|
150
|
-
const file = await bee.downloadFile(hash)
|
|
151
|
-
|
|
152
|
-
expect(file.name).toEqual(name)
|
|
153
|
-
expect(file.data.length).toEqual(13000)
|
|
154
|
-
|
|
155
|
-
const retrievedTag = await bee.retrieveTag(tag)
|
|
156
|
-
expect(retrievedTag.total).toEqual(8)
|
|
157
|
-
})
|
|
158
|
-
})
|
|
159
|
-
|
|
160
|
-
describe('collections', () => {
|
|
161
|
-
it('should work with directory with unicode filenames', async () => {
|
|
162
|
-
const hash = await bee.uploadFilesFromDirectory(getPostageBatch(), './test/data')
|
|
163
|
-
|
|
164
|
-
expect(hash.length).toEqual(REFERENCE_HEX_LENGTH)
|
|
165
|
-
})
|
|
166
|
-
})
|
|
167
|
-
|
|
168
|
-
describe('tags', () => {
|
|
169
|
-
it('should list tags', async () => {
|
|
170
|
-
const originalTags = await bee.getAllTags({ limit: 1000 })
|
|
171
|
-
const createdTag = await bee.createTag()
|
|
172
|
-
const updatedTags = await bee.getAllTags({ limit: 1000 })
|
|
173
|
-
|
|
174
|
-
expect(updatedTags.length - originalTags.length).toEqual(1)
|
|
175
|
-
expect(originalTags.find(tag => tag.uid === createdTag.uid)).toBeFalsy()
|
|
176
|
-
expect(updatedTags.find(tag => tag.uid === createdTag.uid)).toBeTruthy()
|
|
177
|
-
})
|
|
178
|
-
|
|
179
|
-
it('should retrieve previously created empty tag', async () => {
|
|
180
|
-
const tag = await bee.createTag()
|
|
181
|
-
const tag2 = await bee.retrieveTag(tag)
|
|
182
|
-
|
|
183
|
-
expect(tag).toEqual(tag2)
|
|
184
|
-
})
|
|
185
|
-
|
|
186
|
-
it('should delete tag', async () => {
|
|
187
|
-
const createdTag = await bee.createTag()
|
|
188
|
-
const originalTags = await bee.getAllTags({ limit: 1000 })
|
|
189
|
-
expect(originalTags.find(tag => tag.uid === createdTag.uid)).toBeTruthy()
|
|
190
|
-
|
|
191
|
-
await bee.deleteTag(createdTag)
|
|
192
|
-
const updatedTags = await bee.getAllTags({ limit: 1000 })
|
|
193
|
-
|
|
194
|
-
expect(updatedTags.length - originalTags.length).toEqual(-1)
|
|
195
|
-
expect(updatedTags.find(tag => tag.uid === createdTag.uid)).toBeFalsy()
|
|
196
|
-
})
|
|
197
|
-
})
|
|
198
|
-
|
|
199
|
-
describe('pinning', () => {
|
|
200
|
-
it('should list all pins', async () => {
|
|
201
|
-
const content = new Uint8Array([1, 2, 3])
|
|
202
|
-
const hash = await bee.uploadFile(getPostageBatch(), content)
|
|
203
|
-
|
|
204
|
-
await bee.pin(hash) // Nothing is asserted as nothing is returned, will throw error if something is wrong
|
|
205
|
-
|
|
206
|
-
const pinnedChunks = await bee.getAllPins()
|
|
207
|
-
expect(pinnedChunks).toBeType('array')
|
|
208
|
-
expect(pinnedChunks.includes(hash)).toBeTruthy()
|
|
209
|
-
})
|
|
210
|
-
|
|
211
|
-
it('should get pinning status', async () => {
|
|
212
|
-
const content = randomByteArray(16, Date.now())
|
|
213
|
-
const hash = await bee.uploadFile(getPostageBatch(), content, 'test', {
|
|
214
|
-
pin: false,
|
|
215
|
-
})
|
|
216
|
-
|
|
217
|
-
const statusBeforePinning = bee.getPin(hash)
|
|
218
|
-
await expect(statusBeforePinning).rejects.toThrowError('Not Found')
|
|
219
|
-
|
|
220
|
-
await bee.pin(hash) // Nothing is asserted as nothing is returned, will throw error if something is wrong
|
|
221
|
-
|
|
222
|
-
const statusAfterPinning = await bee.getPin(hash)
|
|
223
|
-
expect(statusAfterPinning).toHaveProperty('reference', hash)
|
|
224
|
-
})
|
|
225
|
-
|
|
226
|
-
it('should pin and unpin files', async () => {
|
|
227
|
-
const content = new Uint8Array([1, 2, 3])
|
|
228
|
-
|
|
229
|
-
const hash = await bee.uploadFile(getPostageBatch(), content)
|
|
230
|
-
|
|
231
|
-
await bee.pin(hash) // Nothing is asserted as nothing is returned, will throw error if something is wrong
|
|
232
|
-
await bee.unpin(hash) // Nothing is asserted as nothing is returned, will throw error if something is wrong
|
|
233
|
-
})
|
|
234
|
-
|
|
235
|
-
it('should pin and unpin collection', async () => {
|
|
236
|
-
const path = './test/data/'
|
|
237
|
-
const hash = await bee.uploadFilesFromDirectory(getPostageBatch(), path)
|
|
238
|
-
|
|
239
|
-
await bee.pin(hash) // Nothing is asserted as nothing is returned, will throw error if something is wrong
|
|
240
|
-
await bee.unpin(hash) // Nothing is asserted as nothing is returned, will throw error if something is wrong
|
|
241
|
-
})
|
|
242
|
-
|
|
243
|
-
it('should pin and unpin data', async () => {
|
|
244
|
-
const content = new Uint8Array([1, 2, 3])
|
|
245
|
-
|
|
246
|
-
const hash = await bee.uploadData(getPostageBatch(), content)
|
|
247
|
-
|
|
248
|
-
await bee.pin(hash) // Nothing is asserted as nothing is returned, will throw error if something is wrong
|
|
249
|
-
await bee.unpin(hash) // Nothing is asserted as nothing is returned, will throw error if something is wrong
|
|
250
|
-
})
|
|
251
|
-
})
|
|
252
|
-
|
|
253
|
-
describe('reupload', () => {
|
|
254
|
-
it('should reupload pinned data', async () => {
|
|
255
|
-
const content = randomByteArray(16, Date.now())
|
|
256
|
-
|
|
257
|
-
const hash = await bee.uploadData(getPostageBatch(), content, { pin: true })
|
|
258
|
-
|
|
259
|
-
await sleep(10)
|
|
260
|
-
await bee.reuploadPinnedData(hash) // Does not return anything, but will throw exception if something is going wrong
|
|
261
|
-
})
|
|
262
|
-
|
|
263
|
-
it('should throw error if data is not pinned', async () => {
|
|
264
|
-
const content = randomByteArray(16, Date.now())
|
|
265
|
-
|
|
266
|
-
const hash = await bee.uploadData(getPostageBatch(), content)
|
|
267
|
-
await expect(bee.reuploadPinnedData(hash)).rejects.toThrowError(BeeArgumentError)
|
|
268
|
-
})
|
|
269
|
-
})
|
|
270
|
-
|
|
271
|
-
describe('pss', () => {
|
|
272
|
-
it(
|
|
273
|
-
'should send and receive data',
|
|
274
|
-
async () => {
|
|
275
|
-
return new Promise<void>((resolve, reject) => {
|
|
276
|
-
;(async () => {
|
|
277
|
-
const topic = 'bee-class-topic'
|
|
278
|
-
const message = new Uint8Array([1, 2, 3])
|
|
279
|
-
const beeDebug = new BeeDebug(beeDebugUrl())
|
|
280
|
-
|
|
281
|
-
bee.pssReceive(topic).then(receivedMessage => {
|
|
282
|
-
expect(receivedMessage).toEqual(message)
|
|
283
|
-
resolve()
|
|
284
|
-
})
|
|
285
|
-
|
|
286
|
-
const { overlay } = await beeDebug.getNodeAddresses()
|
|
287
|
-
await beePeer.pssSend(getPostageBatch(BEE_DEBUG_PEER_URL), topic, overlay, message)
|
|
288
|
-
})().catch(reject)
|
|
289
|
-
})
|
|
290
|
-
},
|
|
291
|
-
PSS_TIMEOUT,
|
|
292
|
-
)
|
|
293
|
-
|
|
294
|
-
it(
|
|
295
|
-
'should send and receive data with public key',
|
|
296
|
-
async () => {
|
|
297
|
-
return new Promise<void>((resolve, reject) => {
|
|
298
|
-
// Jest does not allow use `done` and return Promise so this wrapper work arounds that.
|
|
299
|
-
;(async () => {
|
|
300
|
-
const topic = 'bee-class-topic-publickey'
|
|
301
|
-
const message = new Uint8Array([1, 2, 3])
|
|
302
|
-
const beeDebug = new BeeDebug(beeDebugUrl())
|
|
303
|
-
|
|
304
|
-
bee.pssReceive(topic).then(receivedMessage => {
|
|
305
|
-
expect(receivedMessage).toEqual(message)
|
|
306
|
-
resolve()
|
|
307
|
-
})
|
|
308
|
-
|
|
309
|
-
const { overlay, pssPublicKey } = await beeDebug.getNodeAddresses()
|
|
310
|
-
await beePeer.pssSend(getPostageBatch(BEE_DEBUG_PEER_URL), topic, overlay, message, pssPublicKey)
|
|
311
|
-
})().catch(reject)
|
|
312
|
-
})
|
|
313
|
-
},
|
|
314
|
-
PSS_TIMEOUT,
|
|
315
|
-
)
|
|
316
|
-
|
|
317
|
-
it(
|
|
318
|
-
'should subscribe to topic',
|
|
319
|
-
async () => {
|
|
320
|
-
return new Promise<void>((resolve, reject) => {
|
|
321
|
-
;(async () => {
|
|
322
|
-
const topic = 'bee-class-subscribe-topic'
|
|
323
|
-
const message = new Uint8Array([1, 2, 3])
|
|
324
|
-
const beeDebug = new BeeDebug(beeDebugUrl())
|
|
325
|
-
|
|
326
|
-
const subscription = bee.pssSubscribe(topic, {
|
|
327
|
-
onMessage: receivedMessage => {
|
|
328
|
-
// without cancel jest complains for leaking handles and may hang
|
|
329
|
-
subscription.cancel()
|
|
330
|
-
|
|
331
|
-
expect(receivedMessage).toEqual(message)
|
|
332
|
-
resolve()
|
|
333
|
-
},
|
|
334
|
-
onError: e => {
|
|
335
|
-
throw e
|
|
336
|
-
},
|
|
337
|
-
})
|
|
338
|
-
|
|
339
|
-
const { overlay } = await beeDebug.getNodeAddresses()
|
|
340
|
-
await beePeer.pssSend(getPostageBatch(BEE_DEBUG_PEER_URL), topic, overlay, message)
|
|
341
|
-
})().catch(reject)
|
|
342
|
-
})
|
|
343
|
-
},
|
|
344
|
-
PSS_TIMEOUT,
|
|
345
|
-
)
|
|
346
|
-
|
|
347
|
-
it('should time out', async () => {
|
|
348
|
-
const topic = 'bee-class-receive-timeout'
|
|
349
|
-
|
|
350
|
-
await expect(bee.pssReceive(topic, 1)).rejects.toThrow('pssReceive timeout')
|
|
351
|
-
})
|
|
352
|
-
})
|
|
353
|
-
|
|
354
|
-
describe('feeds', () => {
|
|
355
|
-
const owner = testIdentity.address
|
|
356
|
-
const signer = testIdentity.privateKey
|
|
357
|
-
const topic = randomByteArray(32, Date.now())
|
|
358
|
-
|
|
359
|
-
it(
|
|
360
|
-
'feed writer with two updates',
|
|
361
|
-
async () => {
|
|
362
|
-
const feed = bee.makeFeedWriter('sequence', topic, signer)
|
|
363
|
-
const referenceZero = makeBytes(32) // all zeroes
|
|
364
|
-
|
|
365
|
-
await feed.upload(getPostageBatch(), referenceZero)
|
|
366
|
-
const firstUpdateReferenceResponse = await feed.download()
|
|
367
|
-
|
|
368
|
-
expect(firstUpdateReferenceResponse.reference).toEqual(bytesToHex(referenceZero))
|
|
369
|
-
expect(firstUpdateReferenceResponse.feedIndex).toEqual('0000000000000000')
|
|
370
|
-
|
|
371
|
-
const referenceOne = new Uint8Array([...new Uint8Array([1]), ...new Uint8Array(31)]) as ChunkReference
|
|
372
|
-
|
|
373
|
-
await feed.upload(getPostageBatch(), referenceOne)
|
|
374
|
-
const secondUpdateReferenceResponse = await feed.download()
|
|
375
|
-
|
|
376
|
-
expect(secondUpdateReferenceResponse.reference).toEqual(bytesToHex(referenceOne))
|
|
377
|
-
expect(secondUpdateReferenceResponse.feedIndex).toEqual('0000000000000001')
|
|
378
|
-
// TODO the timeout was increased because this test is flaky
|
|
379
|
-
// most likely there is an issue with the lookup
|
|
380
|
-
// https://github.com/ethersphere/bee/issues/1248#issuecomment-786588911
|
|
381
|
-
},
|
|
382
|
-
FEED_TIMEOUT,
|
|
383
|
-
)
|
|
384
|
-
|
|
385
|
-
it(
|
|
386
|
-
'create feeds manifest and retrieve the data',
|
|
387
|
-
async () => {
|
|
388
|
-
const directoryStructure: Collection<Uint8Array> = [
|
|
389
|
-
{
|
|
390
|
-
path: 'index.html',
|
|
391
|
-
data: new TextEncoder().encode('some data'),
|
|
392
|
-
},
|
|
393
|
-
]
|
|
394
|
-
const cacHash = await bzz.uploadCollection(BEE_URL, directoryStructure, getPostageBatch())
|
|
395
|
-
|
|
396
|
-
const feed = bee.makeFeedWriter('sequence', topic, signer)
|
|
397
|
-
await feed.upload(getPostageBatch(), cacHash)
|
|
398
|
-
const manifestReference = await bee.createFeedManifest(getPostageBatch(), 'sequence', topic, owner)
|
|
399
|
-
|
|
400
|
-
expect(typeof manifestReference).toBe('string')
|
|
401
|
-
|
|
402
|
-
// this calls /bzz endpoint that should resolve the manifest and the feed returning the latest feed's content
|
|
403
|
-
const file = await bee.downloadFile(manifestReference, 'index.html')
|
|
404
|
-
expect(new TextDecoder().decode(file.data)).toEqual('some data')
|
|
405
|
-
},
|
|
406
|
-
FEED_TIMEOUT,
|
|
407
|
-
)
|
|
408
|
-
|
|
409
|
-
describe('topic', () => {
|
|
410
|
-
it('create feed topic', () => {
|
|
411
|
-
const topic = bee.makeFeedTopic('swarm.eth:application:handshake')
|
|
412
|
-
const feed = bee.makeFeedReader('sequence', topic, owner)
|
|
413
|
-
|
|
414
|
-
expect(feed.topic).toEqual(topic)
|
|
415
|
-
})
|
|
416
|
-
})
|
|
417
|
-
})
|
|
418
|
-
|
|
419
|
-
describe('soc', () => {
|
|
420
|
-
const socHash = '9d453ebb73b2fedaaf44ceddcf7a0aa37f3e3d6453fea5841c31f0ea6d61dc85' as HexString
|
|
421
|
-
|
|
422
|
-
describe('writer', () => {
|
|
423
|
-
it('should read and write', async () => {
|
|
424
|
-
const identifier = makeBytes(32) // all zeroes
|
|
425
|
-
const socAddress = makeSOCAddress(identifier, makeEthAddress(testIdentity.address))
|
|
426
|
-
await tryDeleteChunkFromLocalStorage(socAddress)
|
|
427
|
-
|
|
428
|
-
const socWriter = bee.makeSOCWriter(testIdentity.privateKey)
|
|
429
|
-
|
|
430
|
-
const reference = await socWriter.upload(getPostageBatch(), identifier, testChunkPayload)
|
|
431
|
-
expect(reference).toEqual(socHash)
|
|
432
|
-
|
|
433
|
-
const soc = await socWriter.download(identifier)
|
|
434
|
-
const payload = soc.payload()
|
|
435
|
-
expect(payload).toEqual(testChunkPayload)
|
|
436
|
-
})
|
|
437
|
-
})
|
|
438
|
-
|
|
439
|
-
describe('reader', () => {
|
|
440
|
-
it('should read', async () => {
|
|
441
|
-
const signer = makeSigner(testIdentity.privateKey)
|
|
442
|
-
const identifier = makeBytes(32) // all zeroes
|
|
443
|
-
const socAddress = makeSOCAddress(identifier, makeEthAddress(testIdentity.address))
|
|
444
|
-
await tryDeleteChunkFromLocalStorage(socAddress)
|
|
445
|
-
await uploadSingleOwnerChunkData(BEE_URL, signer, getPostageBatch(), identifier, testChunkPayload)
|
|
446
|
-
|
|
447
|
-
const socReader = bee.makeSOCReader(testIdentity.address)
|
|
448
|
-
const soc = await socReader.download(identifier)
|
|
449
|
-
const payload = soc.payload()
|
|
450
|
-
expect(payload).toEqual(testChunkPayload)
|
|
451
|
-
})
|
|
452
|
-
})
|
|
453
|
-
})
|
|
454
|
-
|
|
455
|
-
describe('signer', () => {
|
|
456
|
-
it('should be possible to pass it in constructor', async () => {
|
|
457
|
-
const identifier = makeBytes(32)
|
|
458
|
-
identifier[31] = 1
|
|
459
|
-
|
|
460
|
-
const socAddress = makeSOCAddress(identifier, makeEthAddress(testIdentity.address))
|
|
461
|
-
await tryDeleteChunkFromLocalStorage(socAddress)
|
|
462
|
-
|
|
463
|
-
const bee = new Bee(BEE_URL, { signer: testIdentity.privateKey })
|
|
464
|
-
const socWriter = bee.makeSOCWriter()
|
|
465
|
-
|
|
466
|
-
const reference = await socWriter.upload(getPostageBatch(), identifier, testChunkPayload)
|
|
467
|
-
expect(reference).toEqual('00019ec85e8859aa641cf149fbd1147ac7965a9cad1dfe4ab7beaa12d5dc8027')
|
|
468
|
-
})
|
|
469
|
-
|
|
470
|
-
it('should prioritize signer passed to method', async () => {
|
|
471
|
-
const identifier = makeBytes(32)
|
|
472
|
-
identifier[31] = 2
|
|
473
|
-
|
|
474
|
-
const socAddress = makeSOCAddress(identifier, makeEthAddress(testIdentity.address))
|
|
475
|
-
await tryDeleteChunkFromLocalStorage(socAddress)
|
|
476
|
-
|
|
477
|
-
// We pass different private key to the instance
|
|
478
|
-
const bee = new Bee(BEE_URL, {
|
|
479
|
-
signer: '634fb5a872396d9611e5c9f9d7233cfa93f395c093371017ff44aa9ae6564cdd',
|
|
480
|
-
})
|
|
481
|
-
const socWriter = bee.makeSOCWriter(testIdentity.privateKey)
|
|
482
|
-
|
|
483
|
-
const reference = await socWriter.upload(getPostageBatch(), identifier, testChunkPayload)
|
|
484
|
-
expect(reference).toEqual('d1a21cce4c86411f6af2f621ce9a3a0aa3cc5cea6cc9e1b28523d28411398cfb')
|
|
485
|
-
})
|
|
486
|
-
|
|
487
|
-
it('should throw if no signers are passed', () => {
|
|
488
|
-
const bee = new Bee(BEE_URL)
|
|
489
|
-
expect(() => bee.makeSOCWriter()).toThrow()
|
|
490
|
-
})
|
|
491
|
-
})
|
|
492
|
-
|
|
493
|
-
describe('JsonFeed', () => {
|
|
494
|
-
const TOPIC = 'some=very%nice#topic'
|
|
495
|
-
|
|
496
|
-
it(
|
|
497
|
-
'should set JSON to feed',
|
|
498
|
-
async () => {
|
|
499
|
-
await bee.setJsonFeed(getPostageBatch(), TOPIC, testJsonPayload, { signer: testIdentity.privateKey })
|
|
500
|
-
|
|
501
|
-
const hashedTopic = bee.makeFeedTopic(TOPIC)
|
|
502
|
-
const reader = bee.makeFeedReader('sequence', hashedTopic, testIdentity.address)
|
|
503
|
-
const chunkReferenceResponse = await reader.download()
|
|
504
|
-
expect(chunkReferenceResponse.reference).toEqual(testJsonHash)
|
|
505
|
-
|
|
506
|
-
const downloadedData = await bee.downloadData(chunkReferenceResponse.reference)
|
|
507
|
-
expect(downloadedData.json()).toEqual(testJsonPayload)
|
|
508
|
-
},
|
|
509
|
-
FEED_TIMEOUT,
|
|
510
|
-
)
|
|
511
|
-
|
|
512
|
-
it(
|
|
513
|
-
'should get JSON from feed',
|
|
514
|
-
async () => {
|
|
515
|
-
const data = [{ some: { other: 'object' } }]
|
|
516
|
-
|
|
517
|
-
const hashedTopic = bee.makeFeedTopic(TOPIC)
|
|
518
|
-
const writer = bee.makeFeedWriter('sequence', hashedTopic, testIdentity.privateKey)
|
|
519
|
-
const dataChunkReference = await bee.uploadData(getPostageBatch(), JSON.stringify(data))
|
|
520
|
-
await writer.upload(getPostageBatch(), dataChunkReference)
|
|
521
|
-
|
|
522
|
-
const fetchedData = await bee.getJsonFeed(TOPIC, { signer: testIdentity.privateKey })
|
|
523
|
-
expect(fetchedData).toEqual(data)
|
|
524
|
-
},
|
|
525
|
-
FEED_TIMEOUT,
|
|
526
|
-
)
|
|
527
|
-
it(
|
|
528
|
-
'should get JSON from feed with address',
|
|
529
|
-
async () => {
|
|
530
|
-
const data = [{ some: { other: 'object' } }]
|
|
531
|
-
|
|
532
|
-
const hashedTopic = bee.makeFeedTopic(TOPIC)
|
|
533
|
-
const writer = bee.makeFeedWriter('sequence', hashedTopic, testIdentity.privateKey)
|
|
534
|
-
const dataChunkReference = await bee.uploadData(getPostageBatch(), JSON.stringify(data))
|
|
535
|
-
await writer.upload(getPostageBatch(), dataChunkReference)
|
|
536
|
-
|
|
537
|
-
const fetchedData = await bee.getJsonFeed(TOPIC, { address: testIdentity.address })
|
|
538
|
-
expect(fetchedData).toEqual(data)
|
|
539
|
-
},
|
|
540
|
-
FEED_TIMEOUT,
|
|
541
|
-
)
|
|
542
|
-
})
|
|
543
|
-
|
|
544
|
-
describe('PostageBatch', () => {
|
|
545
|
-
it(
|
|
546
|
-
'should create a new postage batch with zero amount',
|
|
547
|
-
async () => {
|
|
548
|
-
const batchId = await bee.createPostageBatch('0', 17)
|
|
549
|
-
const allBatches = await bee.getAllPostageBatch()
|
|
550
|
-
|
|
551
|
-
expect(allBatches.find(batch => batch.batchID === batchId)).toBeTruthy()
|
|
552
|
-
},
|
|
553
|
-
POSTAGE_BATCH_TIMEOUT,
|
|
554
|
-
)
|
|
555
|
-
|
|
556
|
-
it(
|
|
557
|
-
'should have both immutable true and false',
|
|
558
|
-
async () => {
|
|
559
|
-
await bee.createPostageBatch('1', 17, { immutableFlag: true })
|
|
560
|
-
await bee.createPostageBatch('1', 17, { immutableFlag: false })
|
|
561
|
-
const allBatches = await bee.getAllPostageBatch()
|
|
562
|
-
|
|
563
|
-
expect(allBatches.find(batch => batch.immutableFlag === true)).toBeTruthy()
|
|
564
|
-
expect(allBatches.find(batch => batch.immutableFlag === false)).toBeTruthy()
|
|
565
|
-
},
|
|
566
|
-
POSTAGE_BATCH_TIMEOUT * 2,
|
|
567
|
-
)
|
|
568
|
-
|
|
569
|
-
it('should have all properties', async () => {
|
|
570
|
-
const allBatches = await bee.getAllPostageBatch()
|
|
571
|
-
|
|
572
|
-
expect(allBatches.length).toBeGreaterThan(0)
|
|
573
|
-
|
|
574
|
-
expect(allBatches).toEqual(
|
|
575
|
-
expect.arrayContaining([
|
|
576
|
-
expect.objectContaining({
|
|
577
|
-
batchID: expect.any(String),
|
|
578
|
-
utilization: expect.any(Number),
|
|
579
|
-
usable: expect.any(Boolean),
|
|
580
|
-
label: expect.any(String),
|
|
581
|
-
depth: expect.any(Number),
|
|
582
|
-
amount: expect.any(String),
|
|
583
|
-
bucketDepth: expect.any(Number),
|
|
584
|
-
blockNumber: expect.any(Number),
|
|
585
|
-
immutableFlag: expect.any(Boolean),
|
|
586
|
-
}),
|
|
587
|
-
]),
|
|
588
|
-
)
|
|
589
|
-
})
|
|
590
|
-
|
|
591
|
-
it('should error with negative amount', async () => {
|
|
592
|
-
await expect(bee.createPostageBatch('-1', 17)).rejects.toThrowError(BeeArgumentError)
|
|
593
|
-
})
|
|
594
|
-
})
|
|
595
|
-
})
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { BeeArgumentError, BeeDebug } from '../../src'
|
|
2
|
-
import { beeDebugUrl, commonMatchers, POSTAGE_BATCH_TIMEOUT } from '../utils'
|
|
3
|
-
|
|
4
|
-
commonMatchers()
|
|
5
|
-
|
|
6
|
-
describe('Bee Debug class', () => {
|
|
7
|
-
const BEE_DEBUG_URL = beeDebugUrl()
|
|
8
|
-
const beeDebug = new BeeDebug(BEE_DEBUG_URL)
|
|
9
|
-
|
|
10
|
-
describe('PostageBatch', () => {
|
|
11
|
-
it(
|
|
12
|
-
'should create a new postage batch with zero amount',
|
|
13
|
-
async () => {
|
|
14
|
-
const batchId = await beeDebug.createPostageBatch('0', 17)
|
|
15
|
-
const allBatches = await beeDebug.getAllPostageBatch()
|
|
16
|
-
|
|
17
|
-
expect(allBatches.find(batch => batch.batchID === batchId)).toBeTruthy()
|
|
18
|
-
},
|
|
19
|
-
POSTAGE_BATCH_TIMEOUT,
|
|
20
|
-
)
|
|
21
|
-
|
|
22
|
-
it(
|
|
23
|
-
'should have both immutable true and false',
|
|
24
|
-
async () => {
|
|
25
|
-
await beeDebug.createPostageBatch('1', 17, { immutableFlag: true })
|
|
26
|
-
await beeDebug.createPostageBatch('1', 17, { immutableFlag: false })
|
|
27
|
-
const allBatches = await beeDebug.getAllPostageBatch()
|
|
28
|
-
|
|
29
|
-
expect(allBatches.find(batch => batch.immutableFlag === true)).toBeTruthy()
|
|
30
|
-
expect(allBatches.find(batch => batch.immutableFlag === false)).toBeTruthy()
|
|
31
|
-
},
|
|
32
|
-
POSTAGE_BATCH_TIMEOUT * 2,
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
it('should have all properties', async () => {
|
|
36
|
-
const allBatches = await beeDebug.getAllPostageBatch()
|
|
37
|
-
|
|
38
|
-
expect(allBatches.length).toBeGreaterThan(0)
|
|
39
|
-
|
|
40
|
-
expect(allBatches).toEqual(
|
|
41
|
-
expect.arrayContaining([
|
|
42
|
-
expect.objectContaining({
|
|
43
|
-
batchID: expect.any(String),
|
|
44
|
-
utilization: expect.any(Number),
|
|
45
|
-
usable: expect.any(Boolean),
|
|
46
|
-
label: expect.any(String),
|
|
47
|
-
depth: expect.any(Number),
|
|
48
|
-
amount: expect.any(String),
|
|
49
|
-
bucketDepth: expect.any(Number),
|
|
50
|
-
blockNumber: expect.any(Number),
|
|
51
|
-
immutableFlag: expect.any(Boolean),
|
|
52
|
-
batchTTL: expect.any(Number),
|
|
53
|
-
exists: expect.any(Boolean),
|
|
54
|
-
}),
|
|
55
|
-
]),
|
|
56
|
-
)
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
it('buckets should have all properties', async () => {
|
|
60
|
-
const allBatches = await beeDebug.getAllPostageBatch()
|
|
61
|
-
|
|
62
|
-
expect(allBatches.length).toBeGreaterThan(0)
|
|
63
|
-
const batchId = allBatches[0].batchID
|
|
64
|
-
const buckets = await beeDebug.getPostageBatchBuckets(batchId)
|
|
65
|
-
|
|
66
|
-
expect(buckets).toEqual(
|
|
67
|
-
expect.objectContaining({
|
|
68
|
-
depth: expect.any(Number),
|
|
69
|
-
bucketDepth: expect.any(Number),
|
|
70
|
-
bucketUpperBound: expect.any(Number),
|
|
71
|
-
buckets: expect.arrayContaining([
|
|
72
|
-
expect.objectContaining({
|
|
73
|
-
bucketID: expect.any(Number),
|
|
74
|
-
collisions: expect.any(Number),
|
|
75
|
-
}),
|
|
76
|
-
]),
|
|
77
|
-
}),
|
|
78
|
-
)
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
it('should error with negative amount', async () => {
|
|
82
|
-
await expect(beeDebug.createPostageBatch('-1', 17)).rejects.toThrowError(BeeArgumentError)
|
|
83
|
-
})
|
|
84
|
-
})
|
|
85
|
-
})
|