@ethersphere/bee-js 1.2.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. package/CHANGELOG.md +135 -2
  2. package/README.md +3 -1
  3. package/dist/index.browser.min.js +1 -1
  4. package/dist/index.browser.min.js.LICENSE.txt +51 -0
  5. package/dist/index.browser.min.js.map +1 -1
  6. package/dist/index.min.js +1 -1
  7. package/dist/index.min.js.LICENSE.txt +42 -0
  8. package/dist/index.min.js.map +1 -1
  9. package/dist/src/bee-debug.d.ts +75 -38
  10. package/dist/src/bee.d.ts +88 -82
  11. package/dist/src/chunk/soc.d.ts +6 -6
  12. package/dist/src/feed/index.d.ts +7 -7
  13. package/dist/src/feed/json.d.ts +2 -2
  14. package/dist/src/modules/bytes.d.ts +8 -11
  15. package/dist/src/modules/bzz.d.ts +9 -14
  16. package/dist/src/modules/chunk.d.ts +7 -11
  17. package/dist/src/modules/debug/balance.d.ts +9 -9
  18. package/dist/src/modules/debug/chequebook.d.ts +17 -18
  19. package/dist/src/modules/debug/chunk.d.ts +5 -5
  20. package/dist/src/modules/debug/connectivity.d.ts +7 -7
  21. package/dist/src/modules/debug/settlements.d.ts +5 -5
  22. package/dist/src/modules/debug/stamps.d.ts +7 -5
  23. package/dist/src/modules/debug/states.d.ts +5 -5
  24. package/dist/src/modules/debug/status.d.ts +5 -4
  25. package/dist/src/modules/debug/tag.d.ts +3 -3
  26. package/dist/src/modules/debug/transactions.d.ts +9 -9
  27. package/dist/src/modules/feed.d.ts +5 -5
  28. package/dist/src/modules/pinning.d.ts +9 -9
  29. package/dist/src/modules/pss.d.ts +4 -3
  30. package/dist/src/modules/soc.d.ts +3 -3
  31. package/dist/src/modules/status.d.ts +3 -2
  32. package/dist/src/modules/stewardship.d.ts +4 -4
  33. package/dist/src/modules/tag.d.ts +6 -6
  34. package/dist/src/types/debug.d.ts +4 -2
  35. package/dist/src/types/index.d.ts +71 -19
  36. package/dist/src/utils/bytes.d.ts +1 -1
  37. package/dist/src/utils/data.browser.d.ts +3 -1
  38. package/dist/src/utils/data.d.ts +7 -4
  39. package/dist/src/utils/expose.d.ts +6 -9
  40. package/dist/src/utils/headers.d.ts +3 -3
  41. package/dist/src/utils/http.d.ts +25 -0
  42. package/dist/src/utils/merge.d.ts +8 -0
  43. package/dist/src/utils/pss.d.ts +9 -0
  44. package/dist/src/utils/stream.d.ts +37 -0
  45. package/dist/src/utils/type.d.ts +19 -9
  46. package/package.json +15 -8
  47. package/.babelrc.js +0 -33
  48. package/.depcheckrc.json +0 -27
  49. package/.editorconfig +0 -6
  50. package/.eslintignore +0 -1
  51. package/.eslintrc.js +0 -108
  52. package/.gitattributes +0 -1
  53. package/.github/config.yaml +0 -23
  54. package/.github/workflows/check.yaml +0 -57
  55. package/.github/workflows/publish_npmjs.yaml +0 -20
  56. package/.github/workflows/release_github.yaml +0 -20
  57. package/.github/workflows/tests.yaml +0 -128
  58. package/.huskyrc +0 -5
  59. package/.prettierrc +0 -13
  60. package/.vscode/launch.json +0 -49
  61. package/.vscode/settings.json +0 -39
  62. package/CODEOWNERS +0 -1
  63. package/CODE_OF_CONDUCT.md +0 -76
  64. package/commitlint.config.js +0 -3
  65. package/dist/src/modules/stamps.d.ts +0 -4
  66. package/dist/src/utils/hooks.d.ts +0 -31
  67. package/dist/src/utils/safe-axios.d.ts +0 -8
  68. package/jest-puppeteer.config.js +0 -5
  69. package/jest.config.ts +0 -170
  70. package/src/bee-debug.ts +0 -440
  71. package/src/bee.ts +0 -941
  72. package/src/chunk/bmt.ts +0 -55
  73. package/src/chunk/cac.ts +0 -79
  74. package/src/chunk/serialize.ts +0 -16
  75. package/src/chunk/signer.ts +0 -141
  76. package/src/chunk/soc.ts +0 -190
  77. package/src/chunk/span.ts +0 -33
  78. package/src/feed/index.ts +0 -221
  79. package/src/feed/json.ts +0 -32
  80. package/src/feed/topic.ts +0 -23
  81. package/src/feed/type.ts +0 -12
  82. package/src/index.ts +0 -24
  83. package/src/modules/bytes.ts +0 -75
  84. package/src/modules/bzz.ts +0 -184
  85. package/src/modules/chunk.ts +0 -75
  86. package/src/modules/debug/balance.ts +0 -63
  87. package/src/modules/debug/chequebook.ts +0 -174
  88. package/src/modules/debug/chunk.ts +0 -39
  89. package/src/modules/debug/connectivity.ts +0 -61
  90. package/src/modules/debug/settlements.ts +0 -33
  91. package/src/modules/debug/stamps.ts +0 -69
  92. package/src/modules/debug/states.ts +0 -35
  93. package/src/modules/debug/status.ts +0 -34
  94. package/src/modules/debug/tag.ts +0 -19
  95. package/src/modules/debug/transactions.ts +0 -79
  96. package/src/modules/feed.ts +0 -92
  97. package/src/modules/pinning.ts +0 -74
  98. package/src/modules/pss.ts +0 -48
  99. package/src/modules/soc.ts +0 -41
  100. package/src/modules/stamps.ts +0 -59
  101. package/src/modules/status.ts +0 -13
  102. package/src/modules/stewardship.ts +0 -21
  103. package/src/modules/tag.ts +0 -83
  104. package/src/types/axios/index.d.ts +0 -18
  105. package/src/types/debug.ts +0 -204
  106. package/src/types/index.ts +0 -497
  107. package/src/types/tar-js.d.ts +0 -1
  108. package/src/types/webpack-bundle-analyzer/index.d.ts +0 -13
  109. package/src/utils/bytes.ts +0 -144
  110. package/src/utils/collection.ts +0 -151
  111. package/src/utils/data.browser.ts +0 -24
  112. package/src/utils/data.ts +0 -35
  113. package/src/utils/error.ts +0 -23
  114. package/src/utils/eth.ts +0 -229
  115. package/src/utils/expose.ts +0 -10
  116. package/src/utils/file.ts +0 -40
  117. package/src/utils/hash.ts +0 -16
  118. package/src/utils/headers.ts +0 -63
  119. package/src/utils/hex.ts +0 -186
  120. package/src/utils/hooks.ts +0 -89
  121. package/src/utils/safe-axios.ts +0 -98
  122. package/src/utils/tar.ts +0 -30
  123. package/src/utils/type.ts +0 -302
  124. package/src/utils/uint64.ts +0 -31
  125. package/src/utils/url.ts +0 -52
  126. package/test/bee.sh +0 -187
  127. package/test/data/1.txt +0 -1
  128. package/test/data/2.txt +0 -0
  129. package/test/data/empty +0 -0
  130. package/test/data/sub/3.txt +0 -1
  131. package/test/data/sub//303/251 +0 -0
  132. package/test/data/sub//360/237/230/216 +0 -0
  133. package/test/integration/bee-class.browser.spec.ts +0 -215
  134. package/test/integration/bee-class.spec.ts +0 -595
  135. package/test/integration/bee-debug-class.spec.ts +0 -85
  136. package/test/integration/chunk/bmt.spec.ts +0 -33
  137. package/test/integration/chunk/cac.spec.ts +0 -27
  138. package/test/integration/chunk/soc.spec.ts +0 -38
  139. package/test/integration/feed/index.spec.ts +0 -84
  140. package/test/integration/modules/bytes.spec.ts +0 -23
  141. package/test/integration/modules/bzz.spec.ts +0 -270
  142. package/test/integration/modules/chunk.spec.ts +0 -29
  143. package/test/integration/modules/debug/balance.spec.ts +0 -70
  144. package/test/integration/modules/debug/chequebook.spec.ts +0 -64
  145. package/test/integration/modules/debug/connectivity.spec.ts +0 -69
  146. package/test/integration/modules/debug/settlements.spec.ts +0 -34
  147. package/test/integration/modules/debug/states.spec.ts +0 -34
  148. package/test/integration/modules/debug/status.spec.ts +0 -65
  149. package/test/integration/modules/debug/tag.spec.ts +0 -27
  150. package/test/integration/modules/feed.spec.ts +0 -61
  151. package/test/integration/modules/pinning.spec.ts +0 -155
  152. package/test/integration/modules/pss.spec.ts +0 -92
  153. package/test/integration/modules/status.spec.ts +0 -10
  154. package/test/integration/modules/stewardship.spec.ts +0 -32
  155. package/test/integration/modules/tag.spec.ts +0 -51
  156. package/test/test-type-sequencer.js +0 -36
  157. package/test/testpage/testpage.html +0 -20
  158. package/test/unit/assertions.ts +0 -376
  159. package/test/unit/bee-class.spec.ts +0 -685
  160. package/test/unit/bee-debug-class.spec.ts +0 -365
  161. package/test/unit/chunk/bmt.spec.ts +0 -16
  162. package/test/unit/chunk/cac.spec.ts +0 -29
  163. package/test/unit/chunk/serialize.spec.ts +0 -24
  164. package/test/unit/chunk/signer.spec.ts +0 -140
  165. package/test/unit/chunk/soc.spec.ts +0 -25
  166. package/test/unit/chunk/span.spec.ts +0 -38
  167. package/test/unit/feed/json.spec.ts +0 -73
  168. package/test/unit/nock.ts +0 -134
  169. package/test/unit/utils/bytes.spec.ts +0 -32
  170. package/test/unit/utils/collection.spec.ts +0 -22
  171. package/test/unit/utils/eth.spec.ts +0 -224
  172. package/test/unit/utils/hex.spec.ts +0 -115
  173. package/test/unit/utils/hooks.spec.ts +0 -179
  174. package/test/unit/utils/safe-axios.spec.ts +0 -20
  175. package/test/unit/utils/type.spec.ts +0 -32
  176. package/test/unit/utils/uint64.spec.ts +0 -102
  177. package/test/utils.ts +0 -292
  178. package/tsconfig.json +0 -18
  179. package/tsconfig.test.json +0 -11
  180. package/typedoc.json +0 -7
  181. package/webpack.config.ts +0 -141
@@ -1,69 +0,0 @@
1
- import {
2
- getPeers,
3
- getBlocklist,
4
- getTopology,
5
- getNodeAddresses,
6
- pingPeer,
7
- } from '../../../../src/modules/debug/connectivity'
8
- import { beeDebugUrl } from '../../../utils'
9
-
10
- describe('modules/debug/connectivity', () => {
11
- test('getPeers', async () => {
12
- const peers = await getPeers(beeDebugUrl())
13
-
14
- expect(Array.isArray(peers)).toBeTruthy()
15
- expect(peers.length).toBeGreaterThan(0)
16
-
17
- peers.forEach(peer => {
18
- expect(peer).toHaveProperty('address')
19
- expect(peer.address).toMatch(/^[0-9a-f]{64}$/i)
20
- })
21
- })
22
-
23
- test('getBlocklist', async () => {
24
- const peers = await getBlocklist(beeDebugUrl())
25
-
26
- expect(Array.isArray(peers)).toBeTruthy()
27
-
28
- peers.forEach(peer => {
29
- expect(peer).toHaveProperty('address')
30
- expect(peer.address).toMatch(/^[0-9a-f]{64}$/i)
31
- })
32
- })
33
-
34
- test('getTopology', async () => {
35
- const topology = await getTopology(beeDebugUrl())
36
-
37
- expect(topology.baseAddr).toMatch(/^[0-9a-f]{64}$/i)
38
- expect(topology.population).toBeGreaterThanOrEqual(0)
39
- expect(topology.connected).toBeGreaterThanOrEqual(0)
40
- expect(Date.parse(topology.timestamp) !== NaN).toBeTruthy()
41
- expect(topology.nnLowWatermark).toBeGreaterThanOrEqual(0)
42
- expect(topology.depth).toBeGreaterThanOrEqual(0)
43
-
44
- for (let i = 0; i < 16; ++i) {
45
- const bin = topology.bins[`bin_${i}` as keyof typeof topology.bins]
46
- expect(bin.population).toBeGreaterThanOrEqual(0)
47
- expect(bin.connected).toBeGreaterThanOrEqual(0)
48
- expect(Array.isArray(bin.disconnectedPeers) || bin.disconnectedPeers === null).toBeTruthy()
49
- expect(Array.isArray(bin.connectedPeers) || bin.connectedPeers === null).toBeTruthy()
50
- }
51
- })
52
-
53
- test('getNodeAddresses', async () => {
54
- const addresses = await getNodeAddresses(beeDebugUrl())
55
-
56
- expect(addresses.overlay).toMatch(/^[0-9a-f]{64}$/)
57
- expect(Array.isArray(addresses.underlay)).toBeTruthy()
58
- expect(addresses.ethereum).toMatch(/^0x[0-9a-f]{40}$/)
59
- expect(addresses.publicKey).toMatch(/^[0-9a-f]{66}$/)
60
- expect(addresses.pssPublicKey).toMatch(/^[0-9a-f]{66}$/)
61
- })
62
-
63
- test('pingPeer', async () => {
64
- const peers = await getPeers(beeDebugUrl())
65
- const res = await pingPeer(beeDebugUrl(), peers[0].address)
66
-
67
- expect(res.rtt).toMatch(/^\d+(\.\d+)[mnpµ]?s$/)
68
- })
69
- })
@@ -1,34 +0,0 @@
1
- import * as settlements from '../../../../src/modules/debug/settlements'
2
- import { beeDebugUrl, commonMatchers } from '../../../utils'
3
-
4
- commonMatchers()
5
-
6
- describe('settlements', () => {
7
- test('all settlements', async () => {
8
- const response = await settlements.getAllSettlements(beeDebugUrl())
9
-
10
- expect(response.totalReceived).toBeNumberString()
11
- expect(response.totalSent).toBeNumberString()
12
- expect(Array.isArray(response.settlements)).toBeTruthy()
13
-
14
- if (response.settlements.length > 0) {
15
- expect(response.settlements).toEqual(
16
- expect.arrayContaining([
17
- expect.objectContaining({
18
- peer: expect.any(String),
19
- received: expect.any(String),
20
- sent: expect.any(String),
21
- }),
22
- ]),
23
- )
24
-
25
- const peerSettlement = response.settlements[0]
26
-
27
- const peerSettlementResponse = await settlements.getSettlements(beeDebugUrl(), peerSettlement.peer)
28
-
29
- expect(peerSettlementResponse.peer).toEqual(peerSettlement.peer)
30
- expect(peerSettlementResponse.received).toBeNumberString()
31
- expect(peerSettlementResponse.sent).toBeNumberString()
32
- }
33
- })
34
- })
@@ -1,34 +0,0 @@
1
- import { beeDebugUrl, commonMatchers } from '../../../utils'
2
- import * as states from '../../../../src/modules/debug/states'
3
-
4
- const BEE_DEBUG_URL = beeDebugUrl()
5
- commonMatchers()
6
-
7
- describe('modules/states', () => {
8
- describe('chainstate', () => {
9
- it('should fetch the chainstate', async () => {
10
- const state = await states.getChainState(BEE_DEBUG_URL)
11
-
12
- expect(state).toHaveProperty('block')
13
- expect(state).toHaveProperty('totalAmount')
14
- expect(state).toHaveProperty('currentPrice')
15
- expect(state.block).toBeNumberString()
16
- expect(state.totalAmount).toBeNumberString()
17
- expect(state.currentPrice).toBeNumberString()
18
- })
19
- })
20
- describe('ReserveState', () => {
21
- it('should fetch the reserve state', async () => {
22
- const state = await states.getReserveState(BEE_DEBUG_URL)
23
-
24
- expect(state).toHaveProperty('radius')
25
- expect(state).toHaveProperty('available')
26
- expect(state).toHaveProperty('outer')
27
- expect(state).toHaveProperty('inner')
28
- expect(state.radius).toBeType('number')
29
- expect(state.available).toBeType('number')
30
- expect(state.outer).toBeNumberString()
31
- expect(state.inner).toBeNumberString()
32
- })
33
- })
34
- })
@@ -1,65 +0,0 @@
1
- import { engines } from '../../../../package.json'
2
- import {
3
- getHealth,
4
- isSupportedVersion,
5
- SUPPORTED_BEE_VERSION,
6
- SUPPORTED_BEE_VERSION_EXACT,
7
- } from '../../../../src/modules/debug/status'
8
- import { beeDebugUrl } from '../../../utils'
9
-
10
- /**
11
- * Matches these:
12
- * 0.5.3-c423a39c, 0.5.3-c423a39c-dirty, 0.5.3, 1.0.0-rc4, 1.0.0-rc4-02dd4346
13
- */
14
- const expectValidVersion = (string: string): void => {
15
- const parts = string.split('-')
16
- expect(parts.length).toBeGreaterThanOrEqual(1)
17
- expect(parts.length).toBeLessThanOrEqual(3)
18
- expect(parts[0]).toMatch(/^\d+\.\d+\.\d+$/)
19
-
20
- if (parts[1]) {
21
- if (parts[1].startsWith('rc')) {
22
- expect(parts[1]).toMatch(/^rc\d+$/)
23
-
24
- if (parts[2]) {
25
- expect(parts[2]).toMatch(/^[0-9a-f]{7,8}$/)
26
- }
27
- } else {
28
- expect(parts[1]).toMatch(/^[0-9a-f]{7,8}$/)
29
-
30
- if (parts[2]) {
31
- expect(parts[2]).toBe('dirty')
32
- }
33
- }
34
- }
35
- }
36
-
37
- const BEE_DEBUG_URL = beeDebugUrl()
38
-
39
- describe('modules/status', () => {
40
- test('getHealth', async () => {
41
- const health = await getHealth(BEE_DEBUG_URL)
42
-
43
- expect(health.status).toBe('ok')
44
- // Matches both versions like 0.5.3-c423a39c, 0.5.3-c423a39c-dirty and 0.5.3
45
- expectValidVersion(health.version)
46
- })
47
-
48
- test('isSupportedVersion', async () => {
49
- const isSupported = await isSupportedVersion(BEE_DEBUG_URL)
50
-
51
- expect(isSupported).toBe(true)
52
- })
53
-
54
- test('format of supported bee version', () => {
55
- // Matches semantic version e.g. 0.5.3
56
- expect(SUPPORTED_BEE_VERSION).toMatch(/^\d+\.\d+\.\d+$/i)
57
-
58
- // Matches semantic version with commit message e.g. 0.5.3-acbd0e2
59
- expectValidVersion(SUPPORTED_BEE_VERSION_EXACT)
60
- })
61
-
62
- test('SUPPORTED_BEE_VERSION_EXACT should come from package.json', () => {
63
- expect(SUPPORTED_BEE_VERSION_EXACT).toBe(engines.bee)
64
- })
65
- })
@@ -1,27 +0,0 @@
1
- import * as beeTag from '../../../../src/modules/tag'
2
- import * as beeDebugTag from '../../../../src/modules/debug/tag'
3
- import { beeDebugUrl, beeUrl } from '../../../utils'
4
-
5
- const BEE_URL = beeUrl()
6
- const BEE_DEBUG_URL = beeDebugUrl()
7
-
8
- describe('modules/tag', () => {
9
- it('should retrieve extended tag', async () => {
10
- const tag1 = await beeTag.createTag(BEE_URL)
11
- const tag2 = await beeDebugTag.retrieveExtendedTag(BEE_DEBUG_URL, tag1.uid)
12
-
13
- expect(tag2).toEqual(
14
- expect.objectContaining({
15
- total: expect.any(Number),
16
- split: expect.any(Number),
17
- seen: expect.any(Number),
18
- stored: expect.any(Number),
19
- sent: expect.any(Number),
20
- synced: expect.any(Number),
21
- uid: expect.any(Number),
22
- startedAt: expect.any(String),
23
- address: expect.any(String),
24
- }),
25
- )
26
- })
27
- })
@@ -1,61 +0,0 @@
1
- import { createFeedManifest, fetchFeedUpdate } from '../../../src/modules/feed'
2
- import { HexString, hexToBytes, makeHexString } from '../../../src/utils/hex'
3
- import {
4
- beeUrl,
5
- commonMatchers,
6
- ERR_TIMEOUT,
7
- getPostageBatch,
8
- testIdentity,
9
- tryDeleteChunkFromLocalStorage,
10
- } from '../../utils'
11
- import { upload as uploadSOC } from '../../../src/modules/soc'
12
- import type { Topic } from '../../../src/types'
13
-
14
- commonMatchers()
15
-
16
- describe('modules/feed', () => {
17
- const url = beeUrl()
18
- const owner = makeHexString(testIdentity.address, 40)
19
- const topic = '0000000000000000000000000000000000000000000000000000000000000000' as Topic
20
-
21
- test('feed manifest creation', async () => {
22
- const reference = '92442c3e08a308aeba8e2d231733ec57011a203354cad24129e7e0c37bac0cbe'
23
- const response = await createFeedManifest(url, owner, topic, getPostageBatch())
24
-
25
- expect(response).toEqual(reference)
26
- })
27
-
28
- test(
29
- 'empty feed update',
30
- async () => {
31
- const emptyTopic = '1000000000000000000000000000000000000000000000000000000000000000' as Topic
32
- const feedUpdate = fetchFeedUpdate(url, owner, emptyTopic)
33
-
34
- await expect(feedUpdate).rejects.toThrow('Not Found')
35
- },
36
- ERR_TIMEOUT,
37
- )
38
-
39
- test('one feed update', async () => {
40
- const oneUpdateTopic = '2000000000000000000000000000000000000000000000000000000000000000' as Topic
41
- const identifier = '7c5c4c857ed4cae434c2c737bad58a93719f9b678647310ffd03a20862246a3b'
42
- const signature =
43
- 'bba40ea2c87b7801f54f5cca70e06deaed5c366b588e38ce0c42f7f8f16562c3243b43101faa6dbaeaab3244b1a0ceaec92dd117995e19116a372eadbec945b01b'
44
- const socData = hexToBytes(
45
- '280000000000000000000000602a57df0000000000000000000000000000000000000000000000000000000000000000' as HexString,
46
- )
47
-
48
- // delete the chunk from local storage if already exists
49
- // this makes the test repeatable
50
- const cacAddress = '03e8eef6d72dbca9dfb7d2e15a5a305a152a3807ac7fd5ea52721a16972f3813'
51
- await tryDeleteChunkFromLocalStorage(cacAddress)
52
-
53
- const socResponse = await uploadSOC(url, owner, identifier, signature, socData, getPostageBatch())
54
- expect(socResponse).toBeType('string')
55
-
56
- const feedUpdate = await fetchFeedUpdate(url, owner, oneUpdateTopic)
57
- expect(feedUpdate.reference).toBeType('string')
58
- expect(feedUpdate.feedIndex).toEqual('0000000000000000')
59
- expect(feedUpdate.feedIndexNext).toEqual('0000000000000001')
60
- }, 21000)
61
- })
@@ -1,155 +0,0 @@
1
- import * as pinning from '../../../src/modules/pinning'
2
- import * as bzz from '../../../src/modules/bzz'
3
- import * as bytes from '../../../src/modules/bytes'
4
- import * as chunk from '../../../src/modules/chunk'
5
- import {
6
- beeUrl,
7
- invalidReference,
8
- randomByteArray,
9
- testChunkData,
10
- testChunkHash,
11
- ERR_TIMEOUT,
12
- getPostageBatch,
13
- commonMatchers,
14
- } from '../../utils'
15
- import { Collection } from '../../../src/types'
16
-
17
- const BEE_URL = beeUrl()
18
- commonMatchers()
19
-
20
- describe('modules/pin', () => {
21
- describe('should work with files', () => {
22
- const randomData = randomByteArray(5000)
23
-
24
- it('should pin an existing file', async () => {
25
- const hash = await bzz.uploadFile(BEE_URL, randomData, getPostageBatch())
26
- await pinning.pin(BEE_URL, hash)
27
- })
28
-
29
- it('should unpin an existing file', async () => {
30
- const hash = await bzz.uploadFile(BEE_URL, randomData, getPostageBatch())
31
- await pinning.unpin(BEE_URL, hash)
32
- })
33
-
34
- it(
35
- 'should not pin a non-existing file',
36
- async () => {
37
- await expect(pinning.pin(BEE_URL, invalidReference)).rejects.toThrow('Not Found')
38
- },
39
- ERR_TIMEOUT,
40
- )
41
-
42
- it('should not unpin a non-existing file', async () => {
43
- await expect(pinning.unpin(BEE_URL, invalidReference)).rejects.toThrow('Not Found')
44
- })
45
- })
46
-
47
- describe('should work with collections', () => {
48
- const testCollection: Collection<Uint8Array> = [
49
- {
50
- path: '0',
51
- data: Uint8Array.from([0]),
52
- },
53
- {
54
- path: '1',
55
- data: Uint8Array.from([1]),
56
- },
57
- ]
58
-
59
- it('should pin an existing collection', async () => {
60
- const hash = await bzz.uploadCollection(BEE_URL, testCollection, getPostageBatch())
61
- await pinning.pin(BEE_URL, hash) // Nothing is asserted as nothing is returned, will throw error if something is wrong
62
- })
63
-
64
- it('should unpin an existing collections', async () => {
65
- const hash = await bzz.uploadCollection(BEE_URL, testCollection, getPostageBatch())
66
- await pinning.unpin(BEE_URL, hash) // Nothing is asserted as nothing is returned, will throw error if something is wrong
67
- })
68
-
69
- it(
70
- 'should not pin a non-existing collections',
71
- async () => {
72
- await expect(pinning.pin(BEE_URL, invalidReference)).rejects.toThrow('Not Found')
73
- },
74
- ERR_TIMEOUT,
75
- )
76
-
77
- it('should not unpin a non-existing collections', async () => {
78
- await expect(pinning.unpin(BEE_URL, invalidReference)).rejects.toThrow('Not Found')
79
- })
80
- })
81
-
82
- describe('should work with data', () => {
83
- const randomData = randomByteArray(5000)
84
-
85
- it('should pin existing data', async () => {
86
- const hash = await bytes.upload(BEE_URL, randomData, getPostageBatch())
87
- await pinning.pin(BEE_URL, hash) // Nothing is asserted as nothing is returned, will throw error if something is wrong
88
- })
89
-
90
- it('should unpin existing data', async () => {
91
- const hash = await bytes.upload(BEE_URL, randomData, getPostageBatch())
92
- await pinning.pin(BEE_URL, hash) // Nothing is asserted as nothing is returned, will throw error if something is wrong
93
- })
94
-
95
- it(
96
- 'should not pin a non-existing data',
97
- async () => {
98
- await expect(pinning.pin(BEE_URL, invalidReference)).rejects.toThrow('Not Found')
99
- },
100
- ERR_TIMEOUT,
101
- )
102
-
103
- it('should not unpin a non-existing data', async () => {
104
- await expect(pinning.unpin(BEE_URL, invalidReference)).rejects.toThrow('Not Found')
105
- })
106
- })
107
-
108
- describe('should work with chunks', () => {
109
- it('should pin existing chunk', async () => {
110
- const chunkReference = await chunk.upload(BEE_URL, testChunkData, getPostageBatch())
111
- expect(chunkReference).toEqual(testChunkHash)
112
-
113
- await pinning.pin(BEE_URL, testChunkHash) // Nothing is asserted as nothing is returned, will throw error if something is wrong
114
- })
115
-
116
- it('should unpin existing chunk', async () => {
117
- const chunkReference = await chunk.upload(BEE_URL, testChunkData, getPostageBatch())
118
- expect(chunkReference).toEqual(testChunkHash)
119
-
120
- await pinning.unpin(BEE_URL, testChunkHash) // Nothing is asserted as nothing is returned, will throw error if something is wrong
121
- })
122
-
123
- it(
124
- 'should not pin a non-existing chunk',
125
- async () => {
126
- await expect(pinning.pin(BEE_URL, invalidReference)).rejects.toThrow('Not Found')
127
- },
128
- ERR_TIMEOUT,
129
- )
130
-
131
- it('should not unpin a non-existing chunk', async () => {
132
- await expect(pinning.unpin(BEE_URL, invalidReference)).rejects.toThrow('Not Found')
133
- })
134
-
135
- it('should return pinning status of existing chunk', async () => {
136
- const chunkReference = await chunk.upload(BEE_URL, testChunkData, getPostageBatch())
137
- expect(chunkReference).toEqual(testChunkHash)
138
-
139
- await pinning.pin(BEE_URL, testChunkHash) // Nothing is asserted as nothing is returned, will throw error if something is wrong
140
- const pinningStatus = await pinning.getPin(BEE_URL, testChunkHash)
141
- expect(pinningStatus.reference).toEqual(testChunkHash)
142
- })
143
-
144
- it('should not return pinning status of non-existing chunk', async () => {
145
- await expect(pinning.getPin(BEE_URL, invalidReference)).rejects.toThrow('Not Found')
146
- })
147
-
148
- it('should return list of pinned chunks', async () => {
149
- const chunkReference = await chunk.upload(BEE_URL, testChunkData, getPostageBatch())
150
- expect(chunkReference).toEqual(testChunkHash)
151
-
152
- await pinning.pin(BEE_URL, testChunkHash) // Nothing is asserted as nothing is returned, will throw error if something is wrong
153
- })
154
- })
155
- })
@@ -1,92 +0,0 @@
1
- import * as pss from '../../../src/modules/pss'
2
- import * as connectivity from '../../../src/modules/debug/connectivity'
3
- import { beeDebugUrl, beePeerDebugUrl, beePeerUrl, beeUrl, getPostageBatch, PSS_TIMEOUT } from '../../utils'
4
-
5
- const BEE_URL = beeUrl()
6
- const BEE_PEER_URL = beePeerUrl()
7
- const BEE_DEBUG_PEER_URL = beePeerDebugUrl()
8
-
9
- // these tests only work when there is at least one peer connected
10
- describe('modules/pss', () => {
11
- it(
12
- 'should send PSS message',
13
- async () => {
14
- const topic = 'send-pss-message'
15
- const message = 'hello'
16
-
17
- const debugUrl = beeDebugUrl()
18
- const peers = await connectivity.getPeers(debugUrl)
19
- expect(peers.length).toBeGreaterThan(0)
20
-
21
- const target = peers[0].address
22
- await pss.send(BEE_URL, topic, target, message, getPostageBatch()) // Nothing is asserted as nothing is returned, will throw error if something is wrong
23
- },
24
- PSS_TIMEOUT,
25
- )
26
-
27
- it(
28
- 'should send and receive PSS message',
29
- async () => {
30
- return new Promise<void>((resolve, reject) => {
31
- ;(async () => {
32
- const topic = 'send-receive-pss-message'
33
- const message = 'hello'
34
-
35
- const ws = pss.subscribe(BEE_URL, topic)
36
- ws.onmessage = ev => {
37
- const receivedMessage = Buffer.from(ev.data as string).toString()
38
-
39
- // ignore empty messages
40
- if (receivedMessage.length === 0) {
41
- return
42
- }
43
- ws.terminate()
44
- expect(receivedMessage).toEqual(message)
45
- resolve()
46
- }
47
-
48
- const debugUrl = beeDebugUrl()
49
-
50
- const addresses = await connectivity.getNodeAddresses(debugUrl)
51
- const target = addresses.overlay
52
- await pss.send(BEE_PEER_URL, topic, target, message, getPostageBatch(BEE_DEBUG_PEER_URL))
53
- })().catch(reject)
54
- })
55
- },
56
- PSS_TIMEOUT,
57
- )
58
-
59
- it(
60
- 'should send and receive PSS message with public key',
61
- async () => {
62
- // Jest does not allow use `done` and return Promise so this wrapper work arounds that.
63
- return new Promise<void>((resolve, reject) => {
64
- ;(async () => {
65
- const topic = 'send-receive-pss-public-key'
66
- const message = 'hello'
67
-
68
- const ws = pss.subscribe(BEE_URL, topic)
69
- ws.onmessage = ev => {
70
- const receivedMessage = Buffer.from(ev.data as string).toString()
71
-
72
- // ignore empty messages
73
- if (receivedMessage.length === 0) {
74
- return
75
- }
76
- ws.terminate()
77
- expect(receivedMessage).toEqual(message)
78
- resolve()
79
- }
80
-
81
- const debugUrl = beeDebugUrl()
82
-
83
- const addresses = await connectivity.getNodeAddresses(debugUrl)
84
- const target = addresses.overlay
85
- const recipient = addresses.pssPublicKey
86
- await pss.send(BEE_PEER_URL, topic, target, message, getPostageBatch(BEE_DEBUG_PEER_URL), recipient)
87
- })().catch(reject)
88
- })
89
- },
90
- PSS_TIMEOUT,
91
- )
92
- })
@@ -1,10 +0,0 @@
1
- import * as status from '../../../src/modules/status'
2
- import { beeUrl } from '../../utils'
3
-
4
- const BEE_URL = beeUrl()
5
-
6
- describe('checkConnection', () => {
7
- test('should connect to a running node', async () => {
8
- await status.checkConnection(BEE_URL)
9
- })
10
- })
@@ -1,32 +0,0 @@
1
- import * as bzz from '../../../src/modules/bzz'
2
- import * as stewardship from '../../../src/modules/stewardship'
3
- import { Collection } from '../../../src/types'
4
- import { beeUrl, getPostageBatch } from '../../utils'
5
-
6
- const BEE_URL = beeUrl()
7
-
8
- describe('modules/stewardship', () => {
9
- describe('collections', () => {
10
- it('should reupload directory', async () => {
11
- const directoryStructure: Collection<Uint8Array> = [
12
- {
13
- path: '0',
14
- data: Uint8Array.from([0]),
15
- },
16
- ]
17
-
18
- const hash = await bzz.uploadCollection(BEE_URL, directoryStructure, getPostageBatch(), { pin: true })
19
- await stewardship.reupload(BEE_URL, hash) // Does not return anything, but will throw error if something is wrong
20
- })
21
- })
22
-
23
- describe('file', () => {
24
- it('should reupload file', async () => {
25
- const data = 'hello world'
26
- const filename = 'hello.txt'
27
-
28
- const hash = await bzz.uploadFile(BEE_URL, data, getPostageBatch(), filename, { pin: true })
29
- await stewardship.reupload(BEE_URL, hash) // Does not return anything, but will throw error if something is wrong
30
- })
31
- })
32
- })
@@ -1,51 +0,0 @@
1
- import * as tag from '../../../src/modules/tag'
2
- import { beeUrl, commonMatchers } from '../../utils'
3
-
4
- const BEE_URL = beeUrl()
5
-
6
- commonMatchers()
7
-
8
- describe('modules/tag', () => {
9
- it('should list tags', async () => {
10
- await tag.createTag(BEE_URL)
11
- const tags = await tag.getAllTags(BEE_URL)
12
-
13
- expect(tags).toEqual(
14
- expect.arrayContaining([
15
- expect.objectContaining({
16
- total: expect.any(Number),
17
- processed: expect.any(Number),
18
- synced: expect.any(Number),
19
- uid: expect.any(Number),
20
- startedAt: expect.any(String),
21
- }),
22
- ]),
23
- )
24
- })
25
-
26
- it('should create empty tag', async () => {
27
- const tag1 = await tag.createTag(BEE_URL)
28
-
29
- expect(tag1.total).toBe(0)
30
- expect(tag1.processed).toBe(0)
31
- expect(tag1.synced).toBe(0)
32
- expect(Number.isInteger(tag1.uid)).toBeTruthy()
33
- expect(tag1.startedAt).toBeType('string')
34
- })
35
-
36
- it('should retrieve previously created empty tag', async () => {
37
- const tag1 = await tag.createTag(BEE_URL)
38
- const tag2 = await tag.retrieveTag(BEE_URL, tag1.uid)
39
-
40
- expect(tag1).toEqual(tag2)
41
- expect(tag1).toEqual(
42
- expect.objectContaining({
43
- total: expect.any(Number),
44
- processed: expect.any(Number),
45
- synced: expect.any(Number),
46
- uid: expect.any(Number),
47
- startedAt: expect.any(String),
48
- }),
49
- )
50
- })
51
- })
@@ -1,36 +0,0 @@
1
- // eslint-disable-next-line @typescript-eslint/no-var-requires
2
- const Sequencer = require('@jest/test-sequencer').default
3
-
4
- /**
5
- * Jest Sequencer that allows to specify order of execution of tests.
6
- * We are using it to first execute unit tests and then integration when
7
- * whole test suite is run.
8
- *
9
- * https://jestjs.io/docs/next/configuration#testsequencer-string
10
- */
11
- class TestTypeSequencer extends Sequencer {
12
- order = ['unit', 'integration']
13
-
14
- getType(test) {
15
- for (const type of this.order) {
16
- if (test.path.includes(type)) {
17
- return type
18
- }
19
- }
20
- }
21
-
22
- sort(tests) {
23
- // Test structure information
24
- // https://github.com/facebook/jest/blob/6b8b1404a1d9254e7d5d90a8934087a9c9899dab/packages/jest-runner/src/types.ts#L17-L21
25
- const copyTests = Array.from(tests)
26
-
27
- return copyTests.sort((testA, testB) => {
28
- const typeA = this.getType(testA)
29
- const typeB = this.getType(testB)
30
-
31
- return this.order.indexOf(typeA) - this.order.indexOf(typeB)
32
- })
33
- }
34
- }
35
-
36
- module.exports = TestTypeSequencer