@ethersphere/bee-js 1.2.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +135 -2
- package/README.md +3 -1
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.LICENSE.txt +51 -0
- package/dist/index.browser.min.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.LICENSE.txt +42 -0
- package/dist/index.min.js.map +1 -1
- package/dist/src/bee-debug.d.ts +75 -38
- package/dist/src/bee.d.ts +88 -82
- package/dist/src/chunk/soc.d.ts +6 -6
- package/dist/src/feed/index.d.ts +7 -7
- package/dist/src/feed/json.d.ts +2 -2
- package/dist/src/modules/bytes.d.ts +8 -11
- package/dist/src/modules/bzz.d.ts +9 -14
- package/dist/src/modules/chunk.d.ts +7 -11
- package/dist/src/modules/debug/balance.d.ts +9 -9
- package/dist/src/modules/debug/chequebook.d.ts +17 -18
- package/dist/src/modules/debug/chunk.d.ts +5 -5
- package/dist/src/modules/debug/connectivity.d.ts +7 -7
- package/dist/src/modules/debug/settlements.d.ts +5 -5
- package/dist/src/modules/debug/stamps.d.ts +7 -5
- package/dist/src/modules/debug/states.d.ts +5 -5
- package/dist/src/modules/debug/status.d.ts +5 -4
- package/dist/src/modules/debug/tag.d.ts +3 -3
- package/dist/src/modules/debug/transactions.d.ts +9 -9
- package/dist/src/modules/feed.d.ts +5 -5
- package/dist/src/modules/pinning.d.ts +9 -9
- package/dist/src/modules/pss.d.ts +4 -3
- package/dist/src/modules/soc.d.ts +3 -3
- package/dist/src/modules/status.d.ts +3 -2
- package/dist/src/modules/stewardship.d.ts +4 -4
- package/dist/src/modules/tag.d.ts +6 -6
- package/dist/src/types/debug.d.ts +4 -2
- package/dist/src/types/index.d.ts +71 -19
- package/dist/src/utils/bytes.d.ts +1 -1
- package/dist/src/utils/data.browser.d.ts +3 -1
- package/dist/src/utils/data.d.ts +7 -4
- package/dist/src/utils/expose.d.ts +6 -9
- package/dist/src/utils/headers.d.ts +3 -3
- package/dist/src/utils/http.d.ts +25 -0
- package/dist/src/utils/merge.d.ts +8 -0
- package/dist/src/utils/pss.d.ts +9 -0
- package/dist/src/utils/stream.d.ts +37 -0
- package/dist/src/utils/type.d.ts +19 -9
- package/package.json +15 -8
- package/.babelrc.js +0 -33
- package/.depcheckrc.json +0 -27
- package/.editorconfig +0 -6
- package/.eslintignore +0 -1
- package/.eslintrc.js +0 -108
- package/.gitattributes +0 -1
- package/.github/config.yaml +0 -23
- package/.github/workflows/check.yaml +0 -57
- package/.github/workflows/publish_npmjs.yaml +0 -20
- package/.github/workflows/release_github.yaml +0 -20
- package/.github/workflows/tests.yaml +0 -128
- package/.huskyrc +0 -5
- package/.prettierrc +0 -13
- package/.vscode/launch.json +0 -49
- package/.vscode/settings.json +0 -39
- package/CODEOWNERS +0 -1
- package/CODE_OF_CONDUCT.md +0 -76
- package/commitlint.config.js +0 -3
- package/dist/src/modules/stamps.d.ts +0 -4
- package/dist/src/utils/hooks.d.ts +0 -31
- package/dist/src/utils/safe-axios.d.ts +0 -8
- package/jest-puppeteer.config.js +0 -5
- package/jest.config.ts +0 -170
- package/src/bee-debug.ts +0 -440
- package/src/bee.ts +0 -941
- package/src/chunk/bmt.ts +0 -55
- package/src/chunk/cac.ts +0 -79
- package/src/chunk/serialize.ts +0 -16
- package/src/chunk/signer.ts +0 -141
- package/src/chunk/soc.ts +0 -190
- package/src/chunk/span.ts +0 -33
- package/src/feed/index.ts +0 -221
- package/src/feed/json.ts +0 -32
- package/src/feed/topic.ts +0 -23
- package/src/feed/type.ts +0 -12
- package/src/index.ts +0 -24
- package/src/modules/bytes.ts +0 -75
- package/src/modules/bzz.ts +0 -184
- package/src/modules/chunk.ts +0 -75
- package/src/modules/debug/balance.ts +0 -63
- package/src/modules/debug/chequebook.ts +0 -174
- package/src/modules/debug/chunk.ts +0 -39
- package/src/modules/debug/connectivity.ts +0 -61
- package/src/modules/debug/settlements.ts +0 -33
- package/src/modules/debug/stamps.ts +0 -69
- package/src/modules/debug/states.ts +0 -35
- package/src/modules/debug/status.ts +0 -34
- package/src/modules/debug/tag.ts +0 -19
- package/src/modules/debug/transactions.ts +0 -79
- package/src/modules/feed.ts +0 -92
- package/src/modules/pinning.ts +0 -74
- package/src/modules/pss.ts +0 -48
- package/src/modules/soc.ts +0 -41
- package/src/modules/stamps.ts +0 -59
- package/src/modules/status.ts +0 -13
- package/src/modules/stewardship.ts +0 -21
- package/src/modules/tag.ts +0 -83
- package/src/types/axios/index.d.ts +0 -18
- package/src/types/debug.ts +0 -204
- package/src/types/index.ts +0 -497
- package/src/types/tar-js.d.ts +0 -1
- package/src/types/webpack-bundle-analyzer/index.d.ts +0 -13
- package/src/utils/bytes.ts +0 -144
- package/src/utils/collection.ts +0 -151
- package/src/utils/data.browser.ts +0 -24
- package/src/utils/data.ts +0 -35
- package/src/utils/error.ts +0 -23
- package/src/utils/eth.ts +0 -229
- package/src/utils/expose.ts +0 -10
- package/src/utils/file.ts +0 -40
- package/src/utils/hash.ts +0 -16
- package/src/utils/headers.ts +0 -63
- package/src/utils/hex.ts +0 -186
- package/src/utils/hooks.ts +0 -89
- package/src/utils/safe-axios.ts +0 -98
- package/src/utils/tar.ts +0 -30
- package/src/utils/type.ts +0 -302
- package/src/utils/uint64.ts +0 -31
- package/src/utils/url.ts +0 -52
- package/test/bee.sh +0 -187
- package/test/data/1.txt +0 -1
- package/test/data/2.txt +0 -0
- package/test/data/empty +0 -0
- package/test/data/sub/3.txt +0 -1
- package/test/data/sub//303/251 +0 -0
- package/test/data/sub//360/237/230/216 +0 -0
- package/test/integration/bee-class.browser.spec.ts +0 -215
- package/test/integration/bee-class.spec.ts +0 -595
- package/test/integration/bee-debug-class.spec.ts +0 -85
- package/test/integration/chunk/bmt.spec.ts +0 -33
- package/test/integration/chunk/cac.spec.ts +0 -27
- package/test/integration/chunk/soc.spec.ts +0 -38
- package/test/integration/feed/index.spec.ts +0 -84
- package/test/integration/modules/bytes.spec.ts +0 -23
- package/test/integration/modules/bzz.spec.ts +0 -270
- package/test/integration/modules/chunk.spec.ts +0 -29
- package/test/integration/modules/debug/balance.spec.ts +0 -70
- package/test/integration/modules/debug/chequebook.spec.ts +0 -64
- package/test/integration/modules/debug/connectivity.spec.ts +0 -69
- package/test/integration/modules/debug/settlements.spec.ts +0 -34
- package/test/integration/modules/debug/states.spec.ts +0 -34
- package/test/integration/modules/debug/status.spec.ts +0 -65
- package/test/integration/modules/debug/tag.spec.ts +0 -27
- package/test/integration/modules/feed.spec.ts +0 -61
- package/test/integration/modules/pinning.spec.ts +0 -155
- package/test/integration/modules/pss.spec.ts +0 -92
- package/test/integration/modules/status.spec.ts +0 -10
- package/test/integration/modules/stewardship.spec.ts +0 -32
- package/test/integration/modules/tag.spec.ts +0 -51
- package/test/test-type-sequencer.js +0 -36
- package/test/testpage/testpage.html +0 -20
- package/test/unit/assertions.ts +0 -376
- package/test/unit/bee-class.spec.ts +0 -685
- package/test/unit/bee-debug-class.spec.ts +0 -365
- package/test/unit/chunk/bmt.spec.ts +0 -16
- package/test/unit/chunk/cac.spec.ts +0 -29
- package/test/unit/chunk/serialize.spec.ts +0 -24
- package/test/unit/chunk/signer.spec.ts +0 -140
- package/test/unit/chunk/soc.spec.ts +0 -25
- package/test/unit/chunk/span.spec.ts +0 -38
- package/test/unit/feed/json.spec.ts +0 -73
- package/test/unit/nock.ts +0 -134
- package/test/unit/utils/bytes.spec.ts +0 -32
- package/test/unit/utils/collection.spec.ts +0 -22
- package/test/unit/utils/eth.spec.ts +0 -224
- package/test/unit/utils/hex.spec.ts +0 -115
- package/test/unit/utils/hooks.spec.ts +0 -179
- package/test/unit/utils/safe-axios.spec.ts +0 -20
- package/test/unit/utils/type.spec.ts +0 -32
- package/test/unit/utils/uint64.spec.ts +0 -102
- package/test/utils.ts +0 -292
- package/tsconfig.json +0 -18
- package/tsconfig.test.json +0 -11
- package/typedoc.json +0 -7
- package/webpack.config.ts +0 -141
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { bmtHash } from '../../../src/chunk/bmt'
|
|
2
|
-
import { beeUrl, 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(beeUrl(), 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(beeUrl(), 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 { beeUrl, 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(beeUrl(), 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(beeUrl(), 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 { beeUrl, 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(beeUrl(), soc, getPostageBatch())
|
|
25
|
-
|
|
26
|
-
expect(response).toEqual(socAddress)
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
test('download single owner chunk', async () => {
|
|
30
|
-
const data = await chunkAPI.download(beeUrl(), 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 { beeUrl, 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 { 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(url: string, index: number): Promise<ChunkReference> {
|
|
17
|
-
const chunk = makeChunk(index)
|
|
18
|
-
const reference = await chunkAPI.upload(url, 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(url: string, signer: Signer, topic: Topic, index: Index, reference: ChunkReference) {
|
|
27
|
-
try {
|
|
28
|
-
await uploadFeedUpdate(url, 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 url = beeUrl()
|
|
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(url, owner, emptyTopic)
|
|
49
|
-
|
|
50
|
-
expect(index).toEqual('0000000000000000')
|
|
51
|
-
},
|
|
52
|
-
ERR_TIMEOUT,
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
test('feed update', async () => {
|
|
56
|
-
const uploadedChunk = await uploadChunk(url, 0)
|
|
57
|
-
await tryUploadFeedUpdate(url, signer, topic, 0, uploadedChunk)
|
|
58
|
-
|
|
59
|
-
const feedUpdate = await fetchFeedUpdate(url, 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(url, 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(url, 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 { beeUrl, invalidReference, ERR_TIMEOUT, getPostageBatch } from '../../utils'
|
|
3
|
-
|
|
4
|
-
const BEE_URL = beeUrl()
|
|
5
|
-
|
|
6
|
-
describe('modules/bytes', () => {
|
|
7
|
-
it('should store and retrieve data', async () => {
|
|
8
|
-
const data = 'hello world'
|
|
9
|
-
|
|
10
|
-
const hash = await bytes.upload(BEE_URL, data, getPostageBatch())
|
|
11
|
-
const downloadedData = await bytes.download(BEE_URL, hash)
|
|
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_URL, invalidReference)).rejects.toThrow('Not Found')
|
|
20
|
-
},
|
|
21
|
-
ERR_TIMEOUT,
|
|
22
|
-
)
|
|
23
|
-
})
|
|
@@ -1,270 +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 { beeUrl, BIG_FILE_TIMEOUT, getPostageBatch, invalidReference, randomByteArray } from '../../utils'
|
|
6
|
-
import { Readable } from 'stream'
|
|
7
|
-
|
|
8
|
-
const BEE_URL = beeUrl()
|
|
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 hash = await bzz.uploadCollection(BEE_URL, directoryStructure, getPostageBatch())
|
|
21
|
-
const file = await bzz.downloadFile(BEE_URL, hash, 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 hash = await bzz.uploadCollection(BEE_URL, directoryStructure, getPostageBatch())
|
|
38
|
-
const file = await bzz.downloadFile(BEE_URL, hash, 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 hash = await bzz.uploadCollection(BEE_URL, directoryStructure, getPostageBatch(), { pin: true })
|
|
53
|
-
const file = await bzz.downloadFile(BEE_URL, hash, 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 hash = await bzz.uploadCollection(BEE_URL, directoryStructure, getPostageBatch(), { encrypt: true })
|
|
68
|
-
const file = await bzz.downloadFile(BEE_URL, hash, directoryStructure[0].path)
|
|
69
|
-
|
|
70
|
-
expect(file.name).toEqual(directoryStructure[0].path)
|
|
71
|
-
expect(file.data).toEqual(directoryStructure[0].data)
|
|
72
|
-
expect(hash.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_URL, directoryStructure, getPostageBatch())
|
|
86
|
-
|
|
87
|
-
expect(typeof response).toEqual('string')
|
|
88
|
-
},
|
|
89
|
-
BIG_FILE_TIMEOUT,
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
it('should throw error when the upload url is not set', async () => {
|
|
93
|
-
await expect(
|
|
94
|
-
bzz.uploadCollection(undefined as unknown as string, undefined as unknown as [], getPostageBatch()),
|
|
95
|
-
).rejects.toThrowError()
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
it('should throw error when the upload url is not empty', async () => {
|
|
99
|
-
const url = ''
|
|
100
|
-
await expect(bzz.uploadCollection(url, undefined as unknown as [], getPostageBatch())).rejects.toThrowError()
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
it('should throw error when the collection is empty', async () => {
|
|
104
|
-
await expect(bzz.uploadCollection(BEE_URL, [], getPostageBatch())).rejects.toThrowError()
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
it('should store and retrieve collection', async () => {
|
|
108
|
-
const directoryStructure: Collection<Uint8Array> = [
|
|
109
|
-
{
|
|
110
|
-
path: '0',
|
|
111
|
-
data: Uint8Array.from([0]),
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
path: '1',
|
|
115
|
-
data: Uint8Array.from([1]),
|
|
116
|
-
},
|
|
117
|
-
]
|
|
118
|
-
|
|
119
|
-
const hash = await bzz.uploadCollection(BEE_URL, directoryStructure, getPostageBatch())
|
|
120
|
-
|
|
121
|
-
const file0 = await bzz.downloadFile(BEE_URL, hash, directoryStructure[0].path)
|
|
122
|
-
expect(file0.name).toEqual(directoryStructure[0].path)
|
|
123
|
-
expect(file0.data).toEqual(directoryStructure[0].data)
|
|
124
|
-
|
|
125
|
-
const file1 = await bzz.downloadFile(BEE_URL, hash, directoryStructure[1].path)
|
|
126
|
-
expect(file1.name).toEqual(directoryStructure[1].path)
|
|
127
|
-
expect(file1.data).toEqual(directoryStructure[1].data)
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
it('should store and retrieve collection with index document', async () => {
|
|
131
|
-
const directoryStructure: Collection<Uint8Array> = [
|
|
132
|
-
{
|
|
133
|
-
path: '0',
|
|
134
|
-
data: Uint8Array.from([0]),
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
path: '1',
|
|
138
|
-
data: Uint8Array.from([1]),
|
|
139
|
-
},
|
|
140
|
-
]
|
|
141
|
-
|
|
142
|
-
const hash = await bzz.uploadCollection(BEE_URL, directoryStructure, getPostageBatch(), {
|
|
143
|
-
indexDocument: '0',
|
|
144
|
-
})
|
|
145
|
-
|
|
146
|
-
const indexFile = await bzz.downloadFile(BEE_URL, hash)
|
|
147
|
-
expect(indexFile.name).toEqual(directoryStructure[0].path)
|
|
148
|
-
expect(indexFile.data).toEqual(directoryStructure[0].data)
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
it('should store and retrieve collection with error document', async () => {
|
|
152
|
-
const directoryStructure: Collection<Uint8Array> = [
|
|
153
|
-
{
|
|
154
|
-
path: '0',
|
|
155
|
-
data: Uint8Array.from([0]),
|
|
156
|
-
},
|
|
157
|
-
{
|
|
158
|
-
path: '1',
|
|
159
|
-
data: Uint8Array.from([1]),
|
|
160
|
-
},
|
|
161
|
-
]
|
|
162
|
-
|
|
163
|
-
const hash = await bzz.uploadCollection(BEE_URL, directoryStructure, getPostageBatch(), {
|
|
164
|
-
errorDocument: '0',
|
|
165
|
-
})
|
|
166
|
-
|
|
167
|
-
const errorFile = await bzz.downloadFile(BEE_URL, hash, 'error')
|
|
168
|
-
expect(errorFile.name).toEqual(directoryStructure[0].path)
|
|
169
|
-
expect(errorFile.data).toEqual(directoryStructure[0].data)
|
|
170
|
-
})
|
|
171
|
-
|
|
172
|
-
it('should store and retrieve actual directory', async () => {
|
|
173
|
-
const path = 'test/data/'
|
|
174
|
-
const dir = `./${path}`
|
|
175
|
-
const file3Name = '3.txt'
|
|
176
|
-
const subDir = 'sub/'
|
|
177
|
-
const data = Uint8Array.from([51, 10])
|
|
178
|
-
const directoryStructure = await makeCollectionFromFS(dir)
|
|
179
|
-
const hash = await bzz.uploadCollection(BEE_URL, directoryStructure, getPostageBatch())
|
|
180
|
-
|
|
181
|
-
const file3 = await bzz.downloadFile(BEE_URL, hash, `${subDir}${file3Name}`)
|
|
182
|
-
expect(file3.name).toEqual(file3Name)
|
|
183
|
-
expect(file3.data).toEqual(data)
|
|
184
|
-
})
|
|
185
|
-
|
|
186
|
-
it('should store and retrieve actual directory with index document', async () => {
|
|
187
|
-
const path = 'test/data/'
|
|
188
|
-
const dir = `./${path}`
|
|
189
|
-
const fileName = '1.txt'
|
|
190
|
-
const data = Uint8Array.from([49, 10])
|
|
191
|
-
const directoryStructure = await makeCollectionFromFS(dir)
|
|
192
|
-
const hash = await bzz.uploadCollection(BEE_URL, directoryStructure, getPostageBatch(), {
|
|
193
|
-
indexDocument: `${fileName}`,
|
|
194
|
-
})
|
|
195
|
-
|
|
196
|
-
const file1 = await bzz.downloadFile(BEE_URL, hash)
|
|
197
|
-
expect(file1.name).toEqual(fileName)
|
|
198
|
-
expect(file1.data).toEqual(data)
|
|
199
|
-
})
|
|
200
|
-
})
|
|
201
|
-
|
|
202
|
-
describe('file', () => {
|
|
203
|
-
it('should store and retrieve file', async () => {
|
|
204
|
-
const data = 'hello world'
|
|
205
|
-
const filename = 'hello.txt'
|
|
206
|
-
|
|
207
|
-
const hash = await bzz.uploadFile(BEE_URL, data, getPostageBatch(), filename)
|
|
208
|
-
const fileData = await bzz.downloadFile(BEE_URL, hash)
|
|
209
|
-
|
|
210
|
-
expect(Buffer.from(fileData.data).toString()).toEqual(data)
|
|
211
|
-
expect(fileData.name).toEqual(filename)
|
|
212
|
-
})
|
|
213
|
-
|
|
214
|
-
it('should store file without filename', async () => {
|
|
215
|
-
const data = 'hello world'
|
|
216
|
-
|
|
217
|
-
const hash = await bzz.uploadFile(BEE_URL, data, getPostageBatch())
|
|
218
|
-
const fileData = await bzz.downloadFile(BEE_URL, hash)
|
|
219
|
-
|
|
220
|
-
expect(Buffer.from(fileData.data).toString()).toEqual(data)
|
|
221
|
-
})
|
|
222
|
-
|
|
223
|
-
it('should store readable file', async () => {
|
|
224
|
-
const data = randomByteArray(5000, 0)
|
|
225
|
-
const filename = 'hello.txt'
|
|
226
|
-
|
|
227
|
-
const hash = await bzz.uploadFile(BEE_URL, Readable.from([data]), getPostageBatch(), filename, {
|
|
228
|
-
size: data.length,
|
|
229
|
-
})
|
|
230
|
-
const fileData = await bzz.downloadFile(BEE_URL, hash)
|
|
231
|
-
|
|
232
|
-
expect(fileData.data).toEqual(data)
|
|
233
|
-
})
|
|
234
|
-
|
|
235
|
-
it('should store file with a tag', async () => {
|
|
236
|
-
// Relates to how many chunks is uploaded which depends on manifest serialization.
|
|
237
|
-
// https://github.com/ethersphere/bee/pull/1501#discussion_r611385602
|
|
238
|
-
const EXPECTED_TAGS_COUNT = 6
|
|
239
|
-
|
|
240
|
-
const data = randomByteArray(5000, 1)
|
|
241
|
-
const filename = 'hello.txt'
|
|
242
|
-
|
|
243
|
-
const tag1 = await tag.createTag(BEE_URL)
|
|
244
|
-
await bzz.uploadFile(BEE_URL, data, getPostageBatch(), filename, { tag: tag1.uid })
|
|
245
|
-
const tag2 = await tag.retrieveTag(BEE_URL, tag1.uid)
|
|
246
|
-
|
|
247
|
-
expect(tag2.total).toEqual(EXPECTED_TAGS_COUNT)
|
|
248
|
-
expect(tag2.processed).toEqual(EXPECTED_TAGS_COUNT)
|
|
249
|
-
}, 5000)
|
|
250
|
-
|
|
251
|
-
it(
|
|
252
|
-
'should catch error',
|
|
253
|
-
async () => {
|
|
254
|
-
await expect(bzz.downloadFile(BEE_URL, invalidReference)).rejects.toThrow('Not Found')
|
|
255
|
-
},
|
|
256
|
-
BIG_FILE_TIMEOUT,
|
|
257
|
-
)
|
|
258
|
-
|
|
259
|
-
it(
|
|
260
|
-
'should upload bigger file',
|
|
261
|
-
async () => {
|
|
262
|
-
const data = new Uint8Array(32 * 1024 * 1024)
|
|
263
|
-
const response = await bzz.uploadFile(BEE_URL, data, getPostageBatch())
|
|
264
|
-
|
|
265
|
-
expect(typeof response).toEqual('string')
|
|
266
|
-
},
|
|
267
|
-
BIG_FILE_TIMEOUT,
|
|
268
|
-
)
|
|
269
|
-
})
|
|
270
|
-
})
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import * as chunk from '../../../src/modules/chunk'
|
|
2
|
-
import { beeUrl, invalidReference, ERR_TIMEOUT, getPostageBatch } from '../../utils'
|
|
3
|
-
|
|
4
|
-
const BEE_URL = beeUrl()
|
|
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_URL, data, getPostageBatch())
|
|
16
|
-
expect(response).toEqual(reference)
|
|
17
|
-
|
|
18
|
-
const downloadedData = await chunk.download(BEE_URL, response)
|
|
19
|
-
expect(downloadedData).toEqual(data)
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
it(
|
|
23
|
-
'should catch error',
|
|
24
|
-
async () => {
|
|
25
|
-
await expect(chunk.download(BEE_URL, invalidReference)).rejects.toThrow('Not Found')
|
|
26
|
-
},
|
|
27
|
-
ERR_TIMEOUT,
|
|
28
|
-
)
|
|
29
|
-
})
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { beeDebugUrl, beePeerDebugUrl, 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(beePeerDebugUrl())
|
|
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(beeDebugUrl())
|
|
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(beeDebugUrl(), 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(beeDebugUrl())
|
|
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(beeDebugUrl(), peerOverlay)
|
|
65
|
-
|
|
66
|
-
expect(peerBalance.peer).toEqual(peerOverlay)
|
|
67
|
-
expect(peerBalance.balance).toBeNumberString()
|
|
68
|
-
})
|
|
69
|
-
})
|
|
70
|
-
})
|
|
@@ -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 { beeDebugUrl, 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(beeDebugUrl())
|
|
18
|
-
|
|
19
|
-
expect(isPrefixedHexString(response.chequebookAddress)).toBeTruthy()
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
test('balance', async () => {
|
|
23
|
-
const response = await getChequebookBalance(beeDebugUrl())
|
|
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(beeDebugUrl(), 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(beeDebugUrl(), 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(beeDebugUrl())
|
|
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
|
-
}
|