@ethersphere/bee-js 2.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/CHANGELOG.md +91 -0
  2. package/README.md +2 -2
  3. package/dist/index.browser.min.js +1 -1
  4. package/dist/index.browser.min.js.map +1 -1
  5. package/dist/index.min.js +1 -1
  6. package/dist/index.min.js.map +1 -1
  7. package/dist/src/bee-debug.d.ts +38 -6
  8. package/dist/src/bee.d.ts +34 -46
  9. package/dist/src/modules/chunk.d.ts +2 -10
  10. package/dist/src/modules/debug/stamps.d.ts +2 -0
  11. package/dist/src/modules/debug/status.d.ts +10 -4
  12. package/dist/src/modules/stewardship.d.ts +1 -0
  13. package/dist/src/types/debug.d.ts +11 -0
  14. package/dist/src/types/index.d.ts +6 -7
  15. package/dist/src/utils/bytes.d.ts +1 -1
  16. package/dist/src/utils/expose.d.ts +1 -0
  17. package/dist/src/utils/stamps.d.ts +12 -0
  18. package/package.json +10 -8
  19. package/.babelrc.js +0 -33
  20. package/.depcheckrc.json +0 -27
  21. package/.editorconfig +0 -6
  22. package/.eslintignore +0 -1
  23. package/.eslintrc.js +0 -109
  24. package/.gitattributes +0 -1
  25. package/.github/config.yaml +0 -23
  26. package/.github/workflows/check.yaml +0 -57
  27. package/.github/workflows/publish_npmjs.yaml +0 -20
  28. package/.github/workflows/release_github.yaml +0 -20
  29. package/.github/workflows/tests.yaml +0 -128
  30. package/.huskyrc +0 -5
  31. package/.prettierrc +0 -13
  32. package/.vscode/launch.json +0 -49
  33. package/.vscode/settings.json +0 -39
  34. package/CODEOWNERS +0 -1
  35. package/CODE_OF_CONDUCT.md +0 -76
  36. package/commitlint.config.js +0 -3
  37. package/dist/src/modules/stamps.d.ts +0 -4
  38. package/jest-puppeteer.config.js +0 -5
  39. package/jest.config.ts +0 -85
  40. package/src/bee-debug.ts +0 -559
  41. package/src/bee.ts +0 -1070
  42. package/src/chunk/bmt.ts +0 -55
  43. package/src/chunk/cac.ts +0 -79
  44. package/src/chunk/serialize.ts +0 -16
  45. package/src/chunk/signer.ts +0 -141
  46. package/src/chunk/soc.ts +0 -190
  47. package/src/chunk/span.ts +0 -33
  48. package/src/feed/index.ts +0 -217
  49. package/src/feed/json.ts +0 -33
  50. package/src/feed/topic.ts +0 -23
  51. package/src/feed/type.ts +0 -12
  52. package/src/index.ts +0 -24
  53. package/src/modules/bytes.ts +0 -70
  54. package/src/modules/bzz.ts +0 -179
  55. package/src/modules/chunk.ts +0 -69
  56. package/src/modules/debug/balance.ts +0 -63
  57. package/src/modules/debug/chequebook.ts +0 -175
  58. package/src/modules/debug/chunk.ts +0 -39
  59. package/src/modules/debug/connectivity.ts +0 -61
  60. package/src/modules/debug/settlements.ts +0 -33
  61. package/src/modules/debug/stamps.ts +0 -76
  62. package/src/modules/debug/states.ts +0 -35
  63. package/src/modules/debug/status.ts +0 -35
  64. package/src/modules/debug/tag.ts +0 -19
  65. package/src/modules/debug/transactions.ts +0 -79
  66. package/src/modules/feed.ts +0 -105
  67. package/src/modules/pinning.ts +0 -74
  68. package/src/modules/pss.ts +0 -49
  69. package/src/modules/soc.ts +0 -40
  70. package/src/modules/stamps.ts +0 -59
  71. package/src/modules/status.ts +0 -13
  72. package/src/modules/stewardship.ts +0 -18
  73. package/src/modules/tag.ts +0 -83
  74. package/src/types/debug.ts +0 -204
  75. package/src/types/index.ts +0 -566
  76. package/src/types/ky-universal/common.d.ts +0 -17
  77. package/src/types/ky-universal/hooks.d.ts +0 -103
  78. package/src/types/ky-universal/index.d.ts +0 -125
  79. package/src/types/ky-universal/options.d.ts +0 -235
  80. package/src/types/ky-universal/response.d.ts +0 -38
  81. package/src/types/ky-universal/retry.d.ts +0 -39
  82. package/src/types/tar-js.d.ts +0 -1
  83. package/src/types/webpack-bundle-analyzer/index.d.ts +0 -13
  84. package/src/utils/bytes.ts +0 -144
  85. package/src/utils/collection.ts +0 -151
  86. package/src/utils/data.browser.ts +0 -68
  87. package/src/utils/data.ts +0 -48
  88. package/src/utils/error.ts +0 -23
  89. package/src/utils/eth.ts +0 -229
  90. package/src/utils/expose.ts +0 -48
  91. package/src/utils/file.ts +0 -40
  92. package/src/utils/hash.ts +0 -16
  93. package/src/utils/headers.ts +0 -63
  94. package/src/utils/hex.ts +0 -186
  95. package/src/utils/http.ts +0 -141
  96. package/src/utils/merge.ts +0 -34
  97. package/src/utils/pss.ts +0 -16
  98. package/src/utils/stream.ts +0 -146
  99. package/src/utils/tar.ts +0 -30
  100. package/src/utils/type.ts +0 -394
  101. package/src/utils/uint64.ts +0 -31
  102. package/src/utils/url.ts +0 -52
  103. package/test/bee.sh +0 -187
  104. package/test/data/1.txt +0 -1
  105. package/test/data/2.txt +0 -0
  106. package/test/data/empty +0 -0
  107. package/test/data/sub/3.txt +0 -1
  108. package/test/data/sub//303/251 +0 -0
  109. package/test/data/sub//360/237/230/216 +0 -0
  110. package/test/integration/bee-class.browser.spec.ts +0 -272
  111. package/test/integration/bee-class.spec.ts +0 -631
  112. package/test/integration/bee-debug-class.spec.ts +0 -85
  113. package/test/integration/chunk/bmt.spec.ts +0 -33
  114. package/test/integration/chunk/cac.spec.ts +0 -27
  115. package/test/integration/chunk/soc.spec.ts +0 -38
  116. package/test/integration/feed/index.spec.ts +0 -84
  117. package/test/integration/modules/bytes.spec.ts +0 -23
  118. package/test/integration/modules/bzz.spec.ts +0 -265
  119. package/test/integration/modules/chunk.spec.ts +0 -29
  120. package/test/integration/modules/debug/balance.spec.ts +0 -70
  121. package/test/integration/modules/debug/chequebook.spec.ts +0 -64
  122. package/test/integration/modules/debug/connectivity.spec.ts +0 -69
  123. package/test/integration/modules/debug/settlements.spec.ts +0 -34
  124. package/test/integration/modules/debug/states.spec.ts +0 -34
  125. package/test/integration/modules/debug/status.spec.ts +0 -65
  126. package/test/integration/modules/debug/tag.spec.ts +0 -27
  127. package/test/integration/modules/debug/transactions.spec.ts +0 -10
  128. package/test/integration/modules/feed.spec.ts +0 -61
  129. package/test/integration/modules/pinning.spec.ts +0 -155
  130. package/test/integration/modules/pss.spec.ts +0 -97
  131. package/test/integration/modules/status.spec.ts +0 -10
  132. package/test/integration/modules/stewardship.spec.ts +0 -32
  133. package/test/integration/modules/tag.spec.ts +0 -51
  134. package/test/test-type-sequencer.js +0 -36
  135. package/test/testpage/testpage.html +0 -20
  136. package/test/tests-setup.ts +0 -94
  137. package/test/unit/assertions.ts +0 -460
  138. package/test/unit/bee-class.spec.ts +0 -976
  139. package/test/unit/bee-debug-class.spec.ts +0 -435
  140. package/test/unit/chunk/bmt.spec.ts +0 -16
  141. package/test/unit/chunk/cac.spec.ts +0 -29
  142. package/test/unit/chunk/serialize.spec.ts +0 -24
  143. package/test/unit/chunk/signer.spec.ts +0 -140
  144. package/test/unit/chunk/soc.spec.ts +0 -25
  145. package/test/unit/chunk/span.spec.ts +0 -38
  146. package/test/unit/feed/json.spec.ts +0 -73
  147. package/test/unit/nock.ts +0 -151
  148. package/test/unit/utils/bytes.spec.ts +0 -32
  149. package/test/unit/utils/collection.spec.ts +0 -22
  150. package/test/unit/utils/eth.spec.ts +0 -224
  151. package/test/unit/utils/hex.spec.ts +0 -115
  152. package/test/unit/utils/stream.spec.ts +0 -30
  153. package/test/unit/utils/type.spec.ts +0 -32
  154. package/test/unit/utils/uint64.spec.ts +0 -102
  155. package/test/utils.ts +0 -328
  156. package/tsconfig.json +0 -18
  157. package/tsconfig.test.json +0 -11
  158. package/typedoc.json +0 -7
  159. package/webpack.config.ts +0 -141
@@ -1,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
- })
@@ -1,33 +0,0 @@
1
- import { bmtHash } from '../../../src/chunk/bmt'
2
- import { beeKy, getPostageBatch, randomByteArray } from '../../utils'
3
- import * as chunk from '../../../src/modules/chunk'
4
- import { makeSpan } from '../../../src/chunk/span'
5
- import { bytesToHex } from '../../../src/utils/hex'
6
-
7
- describe('bmt', () => {
8
- it('should produce the same hash as Bee', async () => {
9
- /**
10
- * We upload chunks smaller than 4096 bytes on the /bytes
11
- * endpoint therefore it is stored in a single chunk.
12
- */
13
- for (let i = 1; i <= 4096; i *= 2) {
14
- const payload = new Uint8Array(i)
15
- const span = makeSpan(i)
16
- const data = new Uint8Array([...span, ...payload])
17
-
18
- const reference = bytesToHex(bmtHash(data))
19
- const response = await chunk.upload(beeKy(), data, getPostageBatch())
20
- expect(response).toEqual(reference)
21
- }
22
- })
23
-
24
- it('should produce the same hash as Bee for random content', async () => {
25
- const payload = randomByteArray(4096)
26
- const span = makeSpan(payload.length)
27
- const data = new Uint8Array([...span, ...payload])
28
-
29
- const reference = bytesToHex(bmtHash(data))
30
- const response = await chunk.upload(beeKy(), data, getPostageBatch())
31
- expect(response).toEqual(reference)
32
- })
33
- })
@@ -1,27 +0,0 @@
1
- import { assertBytes } from '../../../src/utils/bytes'
2
- import { makeContentAddressedChunk, assertValidChunkData } from '../../../src/chunk/cac'
3
- import { beeKy, getPostageBatch } from '../../utils'
4
- import * as chunkAPI from '../../../src/modules/chunk'
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('upload content address chunk', async () => {
12
- const cac = makeContentAddressedChunk(payload)
13
- const address = cac.address()
14
- const reference = bytesToHex(address)
15
- const response = await chunkAPI.upload(beeKy(), cac.data, getPostageBatch())
16
-
17
- expect(response).toEqual(reference)
18
- })
19
-
20
- test('download content address chunk', async () => {
21
- const address = hexToBytes(contentHash)
22
- assertBytes(address, 32)
23
- const data = await chunkAPI.download(beeKy(), contentHash)
24
-
25
- expect(() => assertValidChunkData(data, address)).not.toThrow()
26
- })
27
- })
@@ -1,38 +0,0 @@
1
- import { Bytes, assertBytes } from '../../../src/utils/bytes'
2
- import { makeSingleOwnerChunk, makeSingleOwnerChunkFromData, uploadSingleOwnerChunk } from '../../../src/chunk/soc'
3
- import { makeContentAddressedChunk } from '../../../src/chunk/cac'
4
- import { beeKy, getPostageBatch, testIdentity, tryDeleteChunkFromLocalStorage } from '../../utils'
5
- import { makePrivateKeySigner } from '../../../src/chunk/signer'
6
- import * as chunkAPI from '../../../src/modules/chunk'
7
- import { HexString, hexToBytes, bytesToHex } from '../../../src/utils/hex'
8
-
9
- describe('soc', () => {
10
- const privateKey = hexToBytes(testIdentity.privateKey)
11
- assertBytes(privateKey, 32)
12
- const signer = makePrivateKeySigner(privateKey)
13
- const payload = new Uint8Array([1, 2, 3])
14
- const socHash = '9d453ebb73b2fedaaf44ceddcf7a0aa37f3e3d6453fea5841c31f0ea6d61dc85' as HexString
15
- const identifier = new Uint8Array(32) as Bytes<32>
16
-
17
- test('upload single owner chunk', async () => {
18
- const cac = makeContentAddressedChunk(payload)
19
- const soc = await makeSingleOwnerChunk(cac, identifier, signer)
20
- const socAddress = bytesToHex(soc.address())
21
-
22
- await tryDeleteChunkFromLocalStorage(socHash)
23
-
24
- const response = await uploadSingleOwnerChunk(beeKy(), soc, getPostageBatch())
25
-
26
- expect(response).toEqual(socAddress)
27
- })
28
-
29
- test('download single owner chunk', async () => {
30
- const data = await chunkAPI.download(beeKy(), socHash)
31
- const address = hexToBytes(socHash)
32
- assertBytes(address, 32)
33
- const soc = makeSingleOwnerChunkFromData(data, address)
34
- const socAddress = soc.address()
35
-
36
- expect(socAddress).toEqual(address)
37
- })
38
- })
@@ -1,84 +0,0 @@
1
- import { fetchFeedUpdate } from '../../../src/modules/feed'
2
- import { hexToBytes, makeHexString } from '../../../src/utils/hex'
3
- import { beeKy, ERR_TIMEOUT, getPostageBatch, testIdentity } from '../../utils'
4
- import { ChunkReference, downloadFeedUpdate, findNextIndex, Index, uploadFeedUpdate } from '../../../src/feed'
5
- import { Bytes, assertBytes } from '../../../src/utils/bytes'
6
- import { makePrivateKeySigner } from '../../../src/chunk/signer'
7
- import { makeContentAddressedChunk } from '../../../src/chunk/cac'
8
- import * as chunkAPI from '../../../src/modules/chunk'
9
- import type { Ky, PrivateKeyBytes, Signer, Topic } from '../../../src/types'
10
- import { BeeResponseError } from '../../../src'
11
-
12
- function makeChunk(index: number) {
13
- return makeContentAddressedChunk(new Uint8Array([index]))
14
- }
15
-
16
- async function uploadChunk(ky: Ky, index: number): Promise<ChunkReference> {
17
- const chunk = makeChunk(index)
18
- const reference = await chunkAPI.upload(ky, chunk.data, getPostageBatch())
19
-
20
- return hexToBytes(reference) as ChunkReference
21
- }
22
-
23
- // FIXME helper function for setting up test state for testing finding feed updates
24
- // it is not intended as a replacement in tests for `uploadFeedUpdate`
25
- // https://github.com/ethersphere/bee-js/issues/154
26
- async function tryUploadFeedUpdate(ky: Ky, signer: Signer, topic: Topic, index: Index, reference: ChunkReference) {
27
- try {
28
- await uploadFeedUpdate(ky, signer, topic, index, reference, getPostageBatch())
29
- } catch (e) {
30
- if (e instanceof BeeResponseError && e.status === 409) {
31
- // ignore conflict errors when uploading the same feed update twice
32
- return
33
- }
34
- throw e
35
- }
36
- }
37
-
38
- describe('feed', () => {
39
- const BEE_KY = beeKy()
40
- const owner = makeHexString(testIdentity.address, 40)
41
- const signer = makePrivateKeySigner(hexToBytes(testIdentity.privateKey) as PrivateKeyBytes)
42
- const topic = '0000000000000000000000000000000000000000000000000000000000000000' as Topic
43
-
44
- test(
45
- 'empty feed update',
46
- async () => {
47
- const emptyTopic = '1000000000000000000000000000000000000000000000000000000000000000' as Topic
48
- const index = await findNextIndex(BEE_KY, owner, emptyTopic)
49
-
50
- expect(index).toEqual('0000000000000000')
51
- },
52
- ERR_TIMEOUT,
53
- )
54
-
55
- test('feed update', async () => {
56
- const uploadedChunk = await uploadChunk(BEE_KY, 0)
57
- await tryUploadFeedUpdate(BEE_KY, signer, topic, 0, uploadedChunk)
58
-
59
- const feedUpdate = await fetchFeedUpdate(BEE_KY, owner, topic)
60
-
61
- expect(feedUpdate.feedIndex).toEqual('0000000000000000')
62
- expect(feedUpdate.feedIndexNext).toEqual('0000000000000001')
63
- }, 21000)
64
-
65
- test('multiple updates and lookup', async () => {
66
- const reference = makeHexString('0000000000000000000000000000000000000000000000000000000000000000', 64)
67
- const referenceBytes = hexToBytes(reference)
68
- assertBytes(referenceBytes, 32)
69
- const multipleUpdateTopic = '3000000000000000000000000000000000000000000000000000000000000000' as Topic
70
-
71
- const numUpdates = 5
72
-
73
- for (let i = 0; i < numUpdates; i++) {
74
- const referenceI = new Uint8Array([i, ...referenceBytes.slice(1)]) as Bytes<32>
75
- await tryUploadFeedUpdate(BEE_KY, signer, multipleUpdateTopic, i, referenceI)
76
- }
77
-
78
- for (let i = 0; i < numUpdates; i++) {
79
- const referenceI = new Uint8Array([i, ...referenceBytes.slice(1)]) as Bytes<32>
80
- const feedUpdateResponse = await downloadFeedUpdate(BEE_KY, signer.address, multipleUpdateTopic, i)
81
- expect(feedUpdateResponse.reference).toEqual(referenceI)
82
- }
83
- }, 15000)
84
- })
@@ -1,23 +0,0 @@
1
- import * as bytes from '../../../src/modules/bytes'
2
- import { invalidReference, ERR_TIMEOUT, getPostageBatch, beeKy } from '../../utils'
3
-
4
- const BEE_KY = beeKy()
5
-
6
- describe('modules/bytes', () => {
7
- it('should store and retrieve data', async () => {
8
- const data = 'hello world'
9
-
10
- const result = await bytes.upload(BEE_KY, data, getPostageBatch())
11
- const downloadedData = await bytes.download(BEE_KY, result.reference)
12
-
13
- expect(Buffer.from(downloadedData).toString()).toEqual(data)
14
- })
15
-
16
- it(
17
- 'should catch error',
18
- async () => {
19
- await expect(bytes.download(BEE_KY, invalidReference)).rejects.toThrow('Not Found')
20
- },
21
- ERR_TIMEOUT,
22
- )
23
- })
@@ -1,265 +0,0 @@
1
- import * as bzz from '../../../src/modules/bzz'
2
- import * as tag from '../../../src/modules/tag'
3
- import { Collection, ENCRYPTED_REFERENCE_HEX_LENGTH } from '../../../src/types'
4
- import { makeCollectionFromFS } from '../../../src/utils/collection'
5
- import { beeKy, BIG_FILE_TIMEOUT, getPostageBatch, invalidReference, randomByteArray } from '../../utils'
6
- import { Readable } from 'stream'
7
-
8
- const BEE_KY = beeKy()
9
-
10
- describe('modules/bzz', () => {
11
- describe('collections', () => {
12
- it('should store and retrieve collection with single file', async () => {
13
- const directoryStructure: Collection<Uint8Array> = [
14
- {
15
- path: '0',
16
- data: Uint8Array.from([0]),
17
- },
18
- ]
19
-
20
- const result = await bzz.uploadCollection(BEE_KY, directoryStructure, getPostageBatch())
21
- const file = await bzz.downloadFile(BEE_KY, result.reference, directoryStructure[0].path)
22
-
23
- expect(file.name).toEqual(directoryStructure[0].path)
24
- expect(file.data).toEqual(directoryStructure[0].data)
25
- })
26
-
27
- it('should retrieve the filename but not the complete path', async () => {
28
- const path = 'a/b/c/d/'
29
- const name = '0'
30
- const directoryStructure: Collection<Uint8Array> = [
31
- {
32
- path: `${path}${name}`,
33
- data: Uint8Array.from([0]),
34
- },
35
- ]
36
-
37
- const result = await bzz.uploadCollection(BEE_KY, directoryStructure, getPostageBatch())
38
- const file = await bzz.downloadFile(BEE_KY, result.reference, directoryStructure[0].path)
39
-
40
- expect(file.name).toEqual(name)
41
- expect(file.data).toEqual(directoryStructure[0].data)
42
- })
43
-
44
- it('should work with pinning', async () => {
45
- const directoryStructure: Collection<Uint8Array> = [
46
- {
47
- path: '0',
48
- data: Uint8Array.from([0]),
49
- },
50
- ]
51
-
52
- const result = await bzz.uploadCollection(BEE_KY, directoryStructure, getPostageBatch(), { pin: true })
53
- const file = await bzz.downloadFile(BEE_KY, result.reference, directoryStructure[0].path)
54
-
55
- expect(file.name).toEqual(directoryStructure[0].path)
56
- expect(file.data).toEqual(directoryStructure[0].data)
57
- })
58
-
59
- it('should work with encryption', async () => {
60
- const directoryStructure: Collection<Uint8Array> = [
61
- {
62
- path: '0',
63
- data: Uint8Array.from([0]),
64
- },
65
- ]
66
-
67
- const result = await bzz.uploadCollection(BEE_KY, directoryStructure, getPostageBatch(), { encrypt: true })
68
- const file = await bzz.downloadFile(BEE_KY, result.reference, directoryStructure[0].path)
69
-
70
- expect(file.name).toEqual(directoryStructure[0].path)
71
- expect(file.data).toEqual(directoryStructure[0].data)
72
- expect(result.reference.length).toEqual(ENCRYPTED_REFERENCE_HEX_LENGTH)
73
- })
74
-
75
- it(
76
- 'should upload bigger file',
77
- async () => {
78
- const directoryStructure: Collection<Uint8Array> = [
79
- {
80
- path: '0',
81
- data: new Uint8Array(32 * 1024 * 1024),
82
- },
83
- ]
84
-
85
- const response = await bzz.uploadCollection(BEE_KY, directoryStructure, getPostageBatch())
86
-
87
- expect(response).toEqual(
88
- expect.objectContaining({
89
- reference: expect.any(String),
90
- tagUid: expect.any(Number),
91
- }),
92
- )
93
- },
94
- BIG_FILE_TIMEOUT,
95
- )
96
-
97
- it('should store and retrieve collection', async () => {
98
- const directoryStructure: Collection<Uint8Array> = [
99
- {
100
- path: '0',
101
- data: Uint8Array.from([0]),
102
- },
103
- {
104
- path: '1',
105
- data: Uint8Array.from([1]),
106
- },
107
- ]
108
-
109
- const result = await bzz.uploadCollection(BEE_KY, directoryStructure, getPostageBatch())
110
-
111
- const file0 = await bzz.downloadFile(BEE_KY, result.reference, directoryStructure[0].path)
112
- expect(file0.name).toEqual(directoryStructure[0].path)
113
- expect(file0.data).toEqual(directoryStructure[0].data)
114
-
115
- const file1 = await bzz.downloadFile(BEE_KY, result.reference, directoryStructure[1].path)
116
- expect(file1.name).toEqual(directoryStructure[1].path)
117
- expect(file1.data).toEqual(directoryStructure[1].data)
118
- })
119
-
120
- it('should store and retrieve collection with index document', async () => {
121
- const directoryStructure: Collection<Uint8Array> = [
122
- {
123
- path: '0',
124
- data: Uint8Array.from([0]),
125
- },
126
- {
127
- path: '1',
128
- data: Uint8Array.from([1]),
129
- },
130
- ]
131
-
132
- const result = await bzz.uploadCollection(BEE_KY, directoryStructure, getPostageBatch(), {
133
- indexDocument: '0',
134
- })
135
-
136
- const indexFile = await bzz.downloadFile(BEE_KY, result.reference)
137
- expect(indexFile.name).toEqual(directoryStructure[0].path)
138
- expect(indexFile.data).toEqual(directoryStructure[0].data)
139
- })
140
-
141
- it('should store and retrieve collection with error document', async () => {
142
- const directoryStructure: Collection<Uint8Array> = [
143
- {
144
- path: '0',
145
- data: Uint8Array.from([0]),
146
- },
147
- {
148
- path: '1',
149
- data: Uint8Array.from([1]),
150
- },
151
- ]
152
-
153
- const result = await bzz.uploadCollection(BEE_KY, directoryStructure, getPostageBatch(), {
154
- errorDocument: '0',
155
- })
156
-
157
- const errorFile = await bzz.downloadFile(BEE_KY, result.reference, 'error')
158
- expect(errorFile.name).toEqual(directoryStructure[0].path)
159
- expect(errorFile.data).toEqual(directoryStructure[0].data)
160
- })
161
-
162
- it('should store and retrieve actual directory', async () => {
163
- const path = 'test/data/'
164
- const dir = `./${path}`
165
- const file3Name = '3.txt'
166
- const subDir = 'sub/'
167
- const data = Uint8Array.from([51, 10])
168
- const directoryStructure = await makeCollectionFromFS(dir)
169
- const result = await bzz.uploadCollection(BEE_KY, directoryStructure, getPostageBatch())
170
-
171
- const file3 = await bzz.downloadFile(BEE_KY, result.reference, `${subDir}${file3Name}`)
172
- expect(file3.name).toEqual(file3Name)
173
- expect(file3.data).toEqual(data)
174
- })
175
-
176
- it('should store and retrieve actual directory with index document', async () => {
177
- const path = 'test/data/'
178
- const dir = `./${path}`
179
- const fileName = '1.txt'
180
- const data = Uint8Array.from([49, 10])
181
- const directoryStructure = await makeCollectionFromFS(dir)
182
- const result = await bzz.uploadCollection(BEE_KY, directoryStructure, getPostageBatch(), {
183
- indexDocument: `${fileName}`,
184
- })
185
-
186
- const file1 = await bzz.downloadFile(BEE_KY, result.reference)
187
- expect(file1.name).toEqual(fileName)
188
- expect(file1.data).toEqual(data)
189
- })
190
- })
191
-
192
- describe('file', () => {
193
- it('should store and retrieve file', async () => {
194
- const data = 'hello world'
195
- const filename = 'hello.txt'
196
-
197
- const result = await bzz.uploadFile(BEE_KY, data, getPostageBatch(), filename)
198
- const fileData = await bzz.downloadFile(BEE_KY, result.reference)
199
-
200
- expect(Buffer.from(fileData.data).toString()).toEqual(data)
201
- expect(fileData.name).toEqual(filename)
202
- })
203
-
204
- it('should store file without filename', async () => {
205
- const data = 'hello world'
206
-
207
- const result = await bzz.uploadFile(BEE_KY, data, getPostageBatch())
208
- const fileData = await bzz.downloadFile(BEE_KY, result.reference)
209
-
210
- expect(Buffer.from(fileData.data).toString()).toEqual(data)
211
- })
212
-
213
- it('should store readable file', async () => {
214
- const data = randomByteArray(5000, 1)
215
- const filename = 'hello.txt'
216
-
217
- const result = await bzz.uploadFile(BEE_KY, Readable.from([data]), getPostageBatch(), filename, {
218
- size: data.length,
219
- })
220
- const fileData = await bzz.downloadFile(BEE_KY, result.reference)
221
-
222
- expect(fileData.data).toEqual(data)
223
- })
224
-
225
- it('should store file with a tag', async () => {
226
- // Relates to how many chunks is uploaded which depends on manifest serialization.
227
- // https://github.com/ethersphere/bee/pull/1501#discussion_r611385602
228
- const EXPECTED_TAGS_COUNT = 6
229
-
230
- const data = randomByteArray(5000, 2)
231
- const filename = 'hello.txt'
232
-
233
- const tag1 = await tag.createTag(BEE_KY)
234
- await bzz.uploadFile(BEE_KY, data, getPostageBatch(), filename, { tag: tag1.uid })
235
- const tag2 = await tag.retrieveTag(BEE_KY, tag1.uid)
236
-
237
- expect(tag2.total).toEqual(EXPECTED_TAGS_COUNT)
238
- expect(tag2.processed).toEqual(EXPECTED_TAGS_COUNT)
239
- }, 5000)
240
-
241
- it(
242
- 'should catch error',
243
- async () => {
244
- await expect(bzz.downloadFile(BEE_KY, invalidReference)).rejects.toThrow('Not Found')
245
- },
246
- BIG_FILE_TIMEOUT,
247
- )
248
-
249
- it(
250
- 'should upload bigger file',
251
- async () => {
252
- const data = new Uint8Array(32 * 1024 * 1024)
253
- const response = await bzz.uploadFile(BEE_KY, data, getPostageBatch())
254
-
255
- expect(response).toEqual(
256
- expect.objectContaining({
257
- reference: expect.any(String),
258
- tagUid: expect.any(Number),
259
- }),
260
- )
261
- },
262
- BIG_FILE_TIMEOUT,
263
- )
264
- })
265
- })
@@ -1,29 +0,0 @@
1
- import * as chunk from '../../../src/modules/chunk'
2
- import { invalidReference, ERR_TIMEOUT, getPostageBatch, beeKy } from '../../utils'
3
-
4
- const BEE_KY = beeKy()
5
-
6
- describe('modules/chunk', () => {
7
- it('should store and retrieve data', async () => {
8
- const payload = new Uint8Array([1, 2, 3])
9
- // span is the payload length encoded as uint64 little endian
10
- const span = new Uint8Array([payload.length, 0, 0, 0, 0, 0, 0, 0])
11
- const data = new Uint8Array([...span, ...payload])
12
- // the hash is hardcoded because we would need the bmt hasher otherwise
13
- const reference = 'ca6357a08e317d15ec560fef34e4c45f8f19f01c372aa70f1da72bfa7f1a4338'
14
-
15
- const response = await chunk.upload(BEE_KY, data, getPostageBatch())
16
- expect(response).toEqual(reference)
17
-
18
- const downloadedData = await chunk.download(BEE_KY, response)
19
- expect(downloadedData).toEqual(data)
20
- })
21
-
22
- it(
23
- 'should catch error',
24
- async () => {
25
- await expect(chunk.download(BEE_KY, invalidReference)).rejects.toThrow('Not Found')
26
- },
27
- ERR_TIMEOUT,
28
- )
29
- })
@@ -1,70 +0,0 @@
1
- import { beeDebugKy, beePeerDebugKy, commonMatchers } from '../../../utils'
2
- import * as balance from '../../../../src/modules/debug/balance'
3
- import * as connectivity from '../../../../src/modules/debug/connectivity'
4
-
5
- // helper function to get the peer overlay address
6
- async function getPeerOverlay() {
7
- const nodeAddresses = await connectivity.getNodeAddresses(beePeerDebugKy())
8
-
9
- return nodeAddresses.overlay
10
- }
11
-
12
- commonMatchers()
13
-
14
- describe('balance', () => {
15
- describe('balances', () => {
16
- test('Get the balances with all known peers including prepaid services', async () => {
17
- const peerOverlay = await getPeerOverlay()
18
- const response = await balance.getAllBalances(beeDebugKy())
19
-
20
- expect(response.balances).toEqual(
21
- expect.arrayContaining([
22
- expect.objectContaining({
23
- peer: expect.any(String),
24
- balance: expect.any(String),
25
- }),
26
- ]),
27
- )
28
-
29
- const peerBalances = response.balances.map(peerBalance => peerBalance.peer)
30
-
31
- expect(peerBalances.includes(peerOverlay)).toBeTruthy()
32
- })
33
-
34
- test('Get the balances with all known peers including prepaid services', async () => {
35
- const peerOverlay = await getPeerOverlay()
36
- const peerBalance = await balance.getPeerBalance(beeDebugKy(), peerOverlay)
37
-
38
- expect(peerBalance.peer).toEqual(peerOverlay)
39
- expect(peerBalance.balance).toBeNumberString()
40
- })
41
- })
42
-
43
- describe('consumed', () => {
44
- test('Get the past due consumption balances with all known peers', async () => {
45
- const peerOverlay = await getPeerOverlay()
46
- const response = await balance.getPastDueConsumptionBalances(beeDebugKy())
47
-
48
- expect(response.balances).toEqual(
49
- expect.arrayContaining([
50
- expect.objectContaining({
51
- peer: expect.any(String),
52
- balance: expect.any(String),
53
- }),
54
- ]),
55
- )
56
-
57
- const peerBalances = response.balances.map(peerBalance => peerBalance.peer)
58
-
59
- expect(peerBalances.includes(peerOverlay)).toBeTruthy()
60
- })
61
-
62
- test('Get the past due consumption balance with a specific peer', async () => {
63
- const peerOverlay = await getPeerOverlay()
64
- const peerBalance = await balance.getPastDueConsumptionPeerBalance(beeDebugKy(), peerOverlay)
65
-
66
- expect(peerBalance.peer).toEqual(peerOverlay)
67
- expect(peerBalance.balance).toBeNumberString()
68
- })
69
- })
70
- })