@ethersphere/bee-js 2.1.0 → 3.2.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 (160) hide show
  1. package/README.md +3 -3
  2. package/dist/index.browser.min.js +1 -1
  3. package/dist/index.browser.min.js.map +1 -1
  4. package/dist/index.min.js +1 -1
  5. package/dist/index.min.js.map +1 -1
  6. package/dist/src/bee-debug.d.ts +5 -1
  7. package/dist/src/bee.d.ts +23 -46
  8. package/dist/src/modules/chunk.d.ts +2 -10
  9. package/dist/src/modules/debug/status.d.ts +10 -4
  10. package/dist/src/types/debug.d.ts +19 -0
  11. package/dist/src/types/index.d.ts +31 -2
  12. package/dist/src/utils/bytes.d.ts +1 -1
  13. package/dist/src/utils/error.d.ts +21 -2
  14. package/dist/src/utils/expose.d.ts +1 -0
  15. package/dist/src/utils/http.d.ts +7 -9
  16. package/dist/src/utils/stamps.d.ts +12 -0
  17. package/dist/src/utils/type.d.ts +6 -0
  18. package/package.json +28 -27
  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/CHANGELOG.md +0 -520
  35. package/CODEOWNERS +0 -1
  36. package/CODE_OF_CONDUCT.md +0 -76
  37. package/commitlint.config.js +0 -3
  38. package/dist/src/modules/stamps.d.ts +0 -4
  39. package/jest-puppeteer.config.js +0 -5
  40. package/jest.config.ts +0 -85
  41. package/src/bee-debug.ts +0 -601
  42. package/src/bee.ts +0 -1087
  43. package/src/chunk/bmt.ts +0 -55
  44. package/src/chunk/cac.ts +0 -79
  45. package/src/chunk/serialize.ts +0 -16
  46. package/src/chunk/signer.ts +0 -141
  47. package/src/chunk/soc.ts +0 -190
  48. package/src/chunk/span.ts +0 -33
  49. package/src/feed/index.ts +0 -217
  50. package/src/feed/json.ts +0 -33
  51. package/src/feed/topic.ts +0 -23
  52. package/src/feed/type.ts +0 -12
  53. package/src/index.ts +0 -24
  54. package/src/modules/bytes.ts +0 -70
  55. package/src/modules/bzz.ts +0 -179
  56. package/src/modules/chunk.ts +0 -69
  57. package/src/modules/debug/balance.ts +0 -63
  58. package/src/modules/debug/chequebook.ts +0 -175
  59. package/src/modules/debug/chunk.ts +0 -39
  60. package/src/modules/debug/connectivity.ts +0 -61
  61. package/src/modules/debug/settlements.ts +0 -33
  62. package/src/modules/debug/stamps.ts +0 -96
  63. package/src/modules/debug/states.ts +0 -35
  64. package/src/modules/debug/status.ts +0 -34
  65. package/src/modules/debug/tag.ts +0 -19
  66. package/src/modules/debug/transactions.ts +0 -79
  67. package/src/modules/feed.ts +0 -105
  68. package/src/modules/pinning.ts +0 -74
  69. package/src/modules/pss.ts +0 -49
  70. package/src/modules/soc.ts +0 -40
  71. package/src/modules/stamps.ts +0 -59
  72. package/src/modules/status.ts +0 -13
  73. package/src/modules/stewardship.ts +0 -32
  74. package/src/modules/tag.ts +0 -83
  75. package/src/types/debug.ts +0 -204
  76. package/src/types/index.ts +0 -561
  77. package/src/types/ky-universal/common.d.ts +0 -17
  78. package/src/types/ky-universal/hooks.d.ts +0 -103
  79. package/src/types/ky-universal/index.d.ts +0 -125
  80. package/src/types/ky-universal/options.d.ts +0 -235
  81. package/src/types/ky-universal/response.d.ts +0 -38
  82. package/src/types/ky-universal/retry.d.ts +0 -39
  83. package/src/types/tar-js.d.ts +0 -1
  84. package/src/types/webpack-bundle-analyzer/index.d.ts +0 -13
  85. package/src/utils/bytes.ts +0 -144
  86. package/src/utils/collection.ts +0 -151
  87. package/src/utils/data.browser.ts +0 -68
  88. package/src/utils/data.ts +0 -48
  89. package/src/utils/error.ts +0 -23
  90. package/src/utils/eth.ts +0 -229
  91. package/src/utils/expose.ts +0 -48
  92. package/src/utils/file.ts +0 -40
  93. package/src/utils/hash.ts +0 -16
  94. package/src/utils/headers.ts +0 -63
  95. package/src/utils/hex.ts +0 -186
  96. package/src/utils/http.ts +0 -141
  97. package/src/utils/merge.ts +0 -34
  98. package/src/utils/pss.ts +0 -16
  99. package/src/utils/stream.ts +0 -146
  100. package/src/utils/tar.ts +0 -30
  101. package/src/utils/type.ts +0 -394
  102. package/src/utils/uint64.ts +0 -31
  103. package/src/utils/url.ts +0 -52
  104. package/test/bee.sh +0 -187
  105. package/test/data/1.txt +0 -1
  106. package/test/data/2.txt +0 -0
  107. package/test/data/empty +0 -0
  108. package/test/data/sub/3.txt +0 -1
  109. package/test/data/sub//303/251 +0 -0
  110. package/test/data/sub//360/237/230/216 +0 -0
  111. package/test/integration/bee-class.browser.spec.ts +0 -272
  112. package/test/integration/bee-class.spec.ts +0 -648
  113. package/test/integration/bee-debug-class.spec.ts +0 -114
  114. package/test/integration/chunk/bmt.spec.ts +0 -33
  115. package/test/integration/chunk/cac.spec.ts +0 -27
  116. package/test/integration/chunk/soc.spec.ts +0 -38
  117. package/test/integration/feed/index.spec.ts +0 -84
  118. package/test/integration/modules/bytes.spec.ts +0 -23
  119. package/test/integration/modules/bzz.spec.ts +0 -265
  120. package/test/integration/modules/chunk.spec.ts +0 -29
  121. package/test/integration/modules/debug/balance.spec.ts +0 -70
  122. package/test/integration/modules/debug/chequebook.spec.ts +0 -64
  123. package/test/integration/modules/debug/connectivity.spec.ts +0 -69
  124. package/test/integration/modules/debug/settlements.spec.ts +0 -34
  125. package/test/integration/modules/debug/states.spec.ts +0 -34
  126. package/test/integration/modules/debug/status.spec.ts +0 -65
  127. package/test/integration/modules/debug/tag.spec.ts +0 -27
  128. package/test/integration/modules/debug/transactions.spec.ts +0 -10
  129. package/test/integration/modules/feed.spec.ts +0 -61
  130. package/test/integration/modules/pinning.spec.ts +0 -155
  131. package/test/integration/modules/pss.spec.ts +0 -105
  132. package/test/integration/modules/status.spec.ts +0 -10
  133. package/test/integration/modules/stewardship.spec.ts +0 -32
  134. package/test/integration/modules/tag.spec.ts +0 -51
  135. package/test/test-type-sequencer.js +0 -36
  136. package/test/testpage/testpage.html +0 -20
  137. package/test/tests-setup.ts +0 -94
  138. package/test/unit/assertions.ts +0 -460
  139. package/test/unit/bee-class.spec.ts +0 -976
  140. package/test/unit/bee-debug-class.spec.ts +0 -435
  141. package/test/unit/chunk/bmt.spec.ts +0 -16
  142. package/test/unit/chunk/cac.spec.ts +0 -29
  143. package/test/unit/chunk/serialize.spec.ts +0 -24
  144. package/test/unit/chunk/signer.spec.ts +0 -140
  145. package/test/unit/chunk/soc.spec.ts +0 -25
  146. package/test/unit/chunk/span.spec.ts +0 -38
  147. package/test/unit/feed/json.spec.ts +0 -73
  148. package/test/unit/nock.ts +0 -151
  149. package/test/unit/utils/bytes.spec.ts +0 -32
  150. package/test/unit/utils/collection.spec.ts +0 -22
  151. package/test/unit/utils/eth.spec.ts +0 -224
  152. package/test/unit/utils/hex.spec.ts +0 -115
  153. package/test/unit/utils/stream.spec.ts +0 -30
  154. package/test/unit/utils/type.spec.ts +0 -32
  155. package/test/unit/utils/uint64.spec.ts +0 -102
  156. package/test/utils.ts +0 -426
  157. package/tsconfig.json +0 -18
  158. package/tsconfig.test.json +0 -11
  159. package/typedoc.json +0 -7
  160. package/webpack.config.ts +0 -141
@@ -1,64 +0,0 @@
1
- import {
2
- depositTokens,
3
- getChequebookAddress,
4
- getChequebookBalance,
5
- getLastCheques,
6
- withdrawTokens,
7
- } from '../../../../src/modules/debug/chequebook'
8
- import { NumberString } from '../../../../src/types'
9
- import { isPrefixedHexString } from '../../../../src/utils/hex'
10
- import { beeDebugKy, commonMatchers, sleep } from '../../../utils'
11
-
12
- if (process.env.BEE_TEST_CHEQUEBOOK) {
13
- commonMatchers()
14
-
15
- describe('swap enabled chequebook', () => {
16
- test('address', async () => {
17
- const response = await getChequebookAddress(beeDebugKy())
18
-
19
- expect(isPrefixedHexString(response.chequebookAddress)).toBeTruthy()
20
- })
21
-
22
- test('balance', async () => {
23
- const response = await getChequebookBalance(beeDebugKy())
24
-
25
- expect(response.availableBalance).toBeNumberString()
26
- expect(response.totalBalance).toBeNumberString()
27
- })
28
-
29
- const TRANSACTION_TIMEOUT = 20 * 1000
30
-
31
- const withDrawDepositTest = (amount: number | NumberString) => async () => {
32
- const withdrawResponse = await withdrawTokens(beeDebugKy(), amount)
33
- expect(withdrawResponse).toBeType('string')
34
-
35
- // TODO avoid sleep in tests
36
- // See https://github.com/ethersphere/bee/issues/1191
37
- await sleep(TRANSACTION_TIMEOUT)
38
-
39
- const depositResponse = await depositTokens(beeDebugKy(), amount)
40
-
41
- expect(depositResponse).toBeType('string')
42
-
43
- // TODO avoid sleep in tests
44
- // See https://github.com/ethersphere/bee/issues/1191
45
- await sleep(TRANSACTION_TIMEOUT)
46
- }
47
-
48
- test('withdraw and deposit string', async () => await withDrawDepositTest('5'), 3 * TRANSACTION_TIMEOUT)
49
- test('withdraw and deposit integer', async () => await withDrawDepositTest(5), 3 * TRANSACTION_TIMEOUT)
50
-
51
- test('get last cheques for all peers', async () => {
52
- const response = await getLastCheques(beeDebugKy())
53
-
54
- expect(Array.isArray(response.lastcheques)).toBeTruthy()
55
- })
56
- })
57
- } else {
58
- test('swap disabled chequebook', () => {
59
- // eslint-disable-next-line no-console
60
- console.log(`
61
- Chequebook tests are disabled because BEE_TEST_CHEQUEBOOK environment variable is not set.
62
- `)
63
- })
64
- }
@@ -1,69 +0,0 @@
1
- import {
2
- getPeers,
3
- getBlocklist,
4
- getTopology,
5
- getNodeAddresses,
6
- pingPeer,
7
- } from '../../../../src/modules/debug/connectivity'
8
- import { beeDebugKy } from '../../../utils'
9
-
10
- describe('modules/debug/connectivity', () => {
11
- test('getPeers', async () => {
12
- const peers = await getPeers(beeDebugKy())
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(beeDebugKy())
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(beeDebugKy())
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(beeDebugKy())
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(beeDebugKy())
65
- const res = await pingPeer(beeDebugKy(), 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 { beeDebugKy, commonMatchers } from '../../../utils'
3
-
4
- commonMatchers()
5
-
6
- describe('settlements', () => {
7
- test('all settlements', async () => {
8
- const response = await settlements.getAllSettlements(beeDebugKy())
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(beeDebugKy(), 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 { beeDebugKy, commonMatchers } from '../../../utils'
2
- import * as states from '../../../../src/modules/debug/states'
3
-
4
- const BEE_DEBUG_URL = beeDebugKy()
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 { beeDebugKy } 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 = beeDebugKy()
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 { beeDebugKy, beeKy } from '../../../utils'
4
-
5
- const BEE_URL = beeKy()
6
- const BEE_DEBUG_KY = beeDebugKy()
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_KY, 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,10 +0,0 @@
1
- import * as transactions from '../../../../src/modules/debug/transactions'
2
- import { beeDebugKy, commonMatchers } from '../../../utils'
3
-
4
- commonMatchers()
5
-
6
- describe('transactions', () => {
7
- it('should get at least empty array for listing', async () => {
8
- await expect(transactions.getAllTransactions(beeDebugKy())).resolves.toBeType('array')
9
- })
10
- })
@@ -1,61 +0,0 @@
1
- import { createFeedManifest, fetchFeedUpdate } from '../../../src/modules/feed'
2
- import { HexString, hexToBytes, makeHexString } from '../../../src/utils/hex'
3
- import {
4
- beeKy,
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 BEE_KY = beeKy()
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(BEE_KY, 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(BEE_KY, 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(BEE_KY, owner, identifier, signature, socData, getPostageBatch())
54
- expect(socResponse).toBeType('string')
55
-
56
- const feedUpdate = await fetchFeedUpdate(BEE_KY, 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
- invalidReference,
7
- randomByteArray,
8
- testChunkData,
9
- testChunkHash,
10
- ERR_TIMEOUT,
11
- getPostageBatch,
12
- commonMatchers,
13
- beeKy,
14
- } from '../../utils'
15
- import { Collection } from '../../../src/types'
16
-
17
- const BEE_KY = beeKy()
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 result = await bzz.uploadFile(BEE_KY, randomData, getPostageBatch())
26
- await pinning.pin(BEE_KY, result.reference)
27
- })
28
-
29
- it('should unpin an existing file', async () => {
30
- const result = await bzz.uploadFile(BEE_KY, randomData, getPostageBatch())
31
- await pinning.unpin(BEE_KY, result.reference)
32
- })
33
-
34
- it(
35
- 'should not pin a non-existing file',
36
- async () => {
37
- await expect(pinning.pin(BEE_KY, 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_KY, 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 result = await bzz.uploadCollection(BEE_KY, testCollection, getPostageBatch())
61
- await pinning.pin(BEE_KY, result.reference) // 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 result = await bzz.uploadCollection(BEE_KY, testCollection, getPostageBatch())
66
- await pinning.unpin(BEE_KY, result.reference) // 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_KY, 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_KY, 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 result = await bytes.upload(BEE_KY, randomData, getPostageBatch())
87
- await pinning.pin(BEE_KY, result.reference) // 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 result = await bytes.upload(BEE_KY, randomData, getPostageBatch())
92
- await pinning.pin(BEE_KY, result.reference) // 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_KY, 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_KY, 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_KY, testChunkData, getPostageBatch())
111
- expect(chunkReference).toEqual(testChunkHash)
112
-
113
- await pinning.pin(BEE_KY, 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_KY, testChunkData, getPostageBatch())
118
- expect(chunkReference).toEqual(testChunkHash)
119
-
120
- await pinning.unpin(BEE_KY, 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_KY, 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_KY, invalidReference)).rejects.toThrow('Not Found')
133
- })
134
-
135
- it('should return pinning status of existing chunk', async () => {
136
- const chunkReference = await chunk.upload(BEE_KY, testChunkData, getPostageBatch())
137
- expect(chunkReference).toEqual(testChunkHash)
138
-
139
- await pinning.pin(BEE_KY, testChunkHash) // Nothing is asserted as nothing is returned, will throw error if something is wrong
140
- const pinningStatus = await pinning.getPin(BEE_KY, 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_KY, invalidReference)).rejects.toThrow('Not Found')
146
- })
147
-
148
- it('should return list of pinned chunks', async () => {
149
- const chunkReference = await chunk.upload(BEE_KY, testChunkData, getPostageBatch())
150
- expect(chunkReference).toEqual(testChunkHash)
151
-
152
- await pinning.pin(BEE_KY, testChunkHash) // Nothing is asserted as nothing is returned, will throw error if something is wrong
153
- })
154
- })
155
- })
@@ -1,105 +0,0 @@
1
- import * as pss from '../../../src/modules/pss'
2
- import * as connectivity from '../../../src/modules/debug/connectivity'
3
- import {
4
- beeDebugKy,
5
- beeKy,
6
- beePeerDebugUrl,
7
- beePeerKy,
8
- beeUrl,
9
- getPostageBatch,
10
- makeTestTarget,
11
- PSS_TIMEOUT,
12
- } from '../../utils'
13
-
14
- const BEE_KY = beeKy()
15
- const BEE_URL = beeUrl()
16
- const BEE_PEER_KY = beePeerKy()
17
- const BEE_DEBUG_KY = beeDebugKy()
18
- const BEE_DEBUG_PEER_URL = beePeerDebugUrl()
19
-
20
- // these tests only work when there is at least one peer connected
21
- describe('modules/pss', () => {
22
- it(
23
- 'should send PSS message',
24
- async () => {
25
- const topic = 'send-pss-message'
26
- const message = 'hello'
27
-
28
- const peers = await connectivity.getPeers(BEE_DEBUG_KY)
29
- expect(peers.length).toBeGreaterThan(0)
30
-
31
- const target = peers[0].address
32
- await pss.send(BEE_KY, topic, makeTestTarget(target), message, getPostageBatch()) // Nothing is asserted as nothing is returned, will throw error if something is wrong
33
- },
34
- PSS_TIMEOUT,
35
- )
36
-
37
- it(
38
- 'should send and receive PSS message',
39
- async () => {
40
- return new Promise<void>((resolve, reject) => {
41
- ;(async () => {
42
- const topic = 'send-receive-pss-message'
43
- const message = 'hello'
44
-
45
- const ws = pss.subscribe(BEE_URL, topic)
46
- ws.onmessage = ev => {
47
- const receivedMessage = Buffer.from(ev.data as string).toString()
48
-
49
- // ignore empty messages
50
- if (receivedMessage.length === 0) {
51
- return
52
- }
53
- ws.terminate()
54
- expect(receivedMessage).toEqual(message)
55
- resolve()
56
- }
57
-
58
- const addresses = await connectivity.getNodeAddresses(BEE_DEBUG_KY)
59
- const target = addresses.overlay
60
- await pss.send(BEE_PEER_KY, topic, makeTestTarget(target), message, getPostageBatch(BEE_DEBUG_PEER_URL))
61
- })().catch(reject)
62
- })
63
- },
64
- PSS_TIMEOUT,
65
- )
66
-
67
- it(
68
- 'should send and receive PSS message with public key',
69
- async () => {
70
- // Jest does not allow use `done` and return Promise so this wrapper work arounds that.
71
- return new Promise<void>((resolve, reject) => {
72
- ;(async () => {
73
- const topic = 'send-receive-pss-public-key'
74
- const message = 'hello'
75
-
76
- const ws = pss.subscribe(BEE_URL, topic)
77
- ws.onmessage = ev => {
78
- const receivedMessage = Buffer.from(ev.data as string).toString()
79
-
80
- // ignore empty messages
81
- if (receivedMessage.length === 0) {
82
- return
83
- }
84
- ws.terminate()
85
- expect(receivedMessage).toEqual(message)
86
- resolve()
87
- }
88
-
89
- const addresses = await connectivity.getNodeAddresses(BEE_DEBUG_KY)
90
- const target = addresses.overlay
91
- const recipient = addresses.pssPublicKey
92
- await pss.send(
93
- BEE_PEER_KY,
94
- topic,
95
- makeTestTarget(target),
96
- message,
97
- getPostageBatch(BEE_DEBUG_PEER_URL),
98
- recipient,
99
- )
100
- })().catch(reject)
101
- })
102
- },
103
- PSS_TIMEOUT,
104
- )
105
- })
@@ -1,10 +0,0 @@
1
- import * as status from '../../../src/modules/status'
2
- import { beeKy } from '../../utils'
3
-
4
- const BEE_KY = beeKy()
5
-
6
- describe('checkConnection', () => {
7
- test('should connect to a running node', async () => {
8
- await status.checkConnection(BEE_KY)
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 { beeKy, getPostageBatch } from '../../utils'
5
-
6
- const BEE_KY = beeKy()
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 result = await bzz.uploadCollection(BEE_KY, directoryStructure, getPostageBatch(), { pin: true })
19
- await stewardship.reupload(BEE_KY, result.reference) // 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 result = await bzz.uploadFile(BEE_KY, data, getPostageBatch(), filename, { pin: true })
29
- await stewardship.reupload(BEE_KY, result.reference) // Does not return anything, but will throw error if something is wrong
30
- })
31
- })
32
- })