@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
package/src/utils/uint64.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Bytes, makeBytes } from './bytes'
|
|
2
|
-
|
|
3
|
-
// TODO handle bigger values than 32 bit
|
|
4
|
-
// For now it's good enough because we only use these functions
|
|
5
|
-
// sequential feed indexes.
|
|
6
|
-
export function writeUint64LittleEndian(value: number, bytes: Bytes<8> = makeBytes(8)): Bytes<8> {
|
|
7
|
-
const dataView = new DataView(bytes.buffer)
|
|
8
|
-
const valueLower32 = value & 0xffffffff
|
|
9
|
-
const littleEndian = true
|
|
10
|
-
|
|
11
|
-
dataView.setUint32(0, valueLower32, littleEndian)
|
|
12
|
-
dataView.setUint32(4, 0, littleEndian)
|
|
13
|
-
|
|
14
|
-
return bytes
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function writeUint64BigEndian(value: number, bytes: Bytes<8> = makeBytes(8)): Bytes<8> {
|
|
18
|
-
const dataView = new DataView(bytes.buffer)
|
|
19
|
-
const valueLower32 = value & 0xffffffff
|
|
20
|
-
|
|
21
|
-
dataView.setUint32(0, 0)
|
|
22
|
-
dataView.setUint32(4, valueLower32)
|
|
23
|
-
|
|
24
|
-
return bytes
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function readUint64BigEndian(bytes: Bytes<8>): number {
|
|
28
|
-
const dataView = new DataView(bytes.buffer)
|
|
29
|
-
|
|
30
|
-
return dataView.getUint32(4)
|
|
31
|
-
}
|
package/src/utils/url.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { BeeArgumentError } from './error'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Validates that passed string is valid URL of Bee.
|
|
5
|
-
* We support only HTTP and HTTPS protocols.
|
|
6
|
-
*
|
|
7
|
-
* @param url
|
|
8
|
-
*/
|
|
9
|
-
export function isValidBeeUrl(url: unknown): url is URL {
|
|
10
|
-
try {
|
|
11
|
-
if (typeof url !== 'string') {
|
|
12
|
-
return false
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const urlObject = new URL(url)
|
|
16
|
-
|
|
17
|
-
// There can be wide range of protocols passed.
|
|
18
|
-
return urlObject.protocol === 'http:' || urlObject.protocol === 'https:'
|
|
19
|
-
} catch (e) {
|
|
20
|
-
// URL constructor throws TypeError if not valid URL
|
|
21
|
-
// TODO: Drop the `.code` hack for NodeJS environment: https://github.com/ethersphere/bee-js/issues/204
|
|
22
|
-
if (e instanceof TypeError || (e.code && e.code === 'ERR_INVALID_URL')) {
|
|
23
|
-
return false
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
throw e
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Validates that passed string is valid URL of Bee, if not it throws BeeArgumentError.
|
|
32
|
-
* We support only HTTP and HTTPS protocols.
|
|
33
|
-
* @param url
|
|
34
|
-
* @throws BeeArgumentError if non valid URL
|
|
35
|
-
*/
|
|
36
|
-
export function assertBeeUrl(url: unknown): asserts url is URL {
|
|
37
|
-
if (!isValidBeeUrl(url)) {
|
|
38
|
-
throw new BeeArgumentError('URL is not valid!', url)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Removes trailing slash out of the given string.
|
|
44
|
-
* @param url
|
|
45
|
-
*/
|
|
46
|
-
export function stripLastSlash(url: string): string {
|
|
47
|
-
if (url.endsWith('/')) {
|
|
48
|
-
return url.slice(0, -1)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return url
|
|
52
|
-
}
|
package/test/bee.sh
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
echoerr() { if [[ $QUIET -ne 1 ]] ; then echo "$@" 1>&2; fi }
|
|
4
|
-
|
|
5
|
-
usage() {
|
|
6
|
-
cat << USAGE >&2
|
|
7
|
-
USAGE:
|
|
8
|
-
$ bee.sh [COMMAND] [PARAMETERS]
|
|
9
|
-
COMMANDS:
|
|
10
|
-
start create Bee cluster with the given parameters
|
|
11
|
-
stop stop Bee cluster
|
|
12
|
-
PARAMETERS:
|
|
13
|
-
--ephemeral create ephemeral container for bee-client. Data won't be persisted.
|
|
14
|
-
--workers=number all Bee nodes in the test environment. Default is 4.
|
|
15
|
-
--port-maps=number map ports of the cluster nodes to the hosting machine in the following manner:
|
|
16
|
-
1. 1633:1635
|
|
17
|
-
2. 11633:11635
|
|
18
|
-
3. 21633:21635 (...)
|
|
19
|
-
number represents the nodes number to map from. Default is 4.
|
|
20
|
-
--password=string password for Bee client(s).
|
|
21
|
-
--version=x.y.z used version of Bee client.
|
|
22
|
-
USAGE
|
|
23
|
-
exit 1
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
stop() {
|
|
27
|
-
echo "Stop following containers:"
|
|
28
|
-
docker container stop $QUEEN_CONTAINER_NAME;
|
|
29
|
-
WORKER_NAMES=`docker container ls -f name="$WORKER_CONTAINER_NAME*" --format "{{.Names}}"`
|
|
30
|
-
for WORKER_NAME in $WORKER_NAMES; do
|
|
31
|
-
docker container stop "$WORKER_NAME"
|
|
32
|
-
done
|
|
33
|
-
|
|
34
|
-
trap - SIGINT
|
|
35
|
-
exit 0;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
fetch_queen_underlay_addr() {
|
|
39
|
-
if [[ ! -z "$QUEEN_UNDERLAY_ADDRESS" ]] ; then return; fi
|
|
40
|
-
|
|
41
|
-
while : ; do
|
|
42
|
-
QUEEN_UNDERLAY_ADDRESS=$(curl -s localhost:1635/addresses | python -mjson.tool 2>&1 | grep "/ip4/" | awk '!/127.0.0.1/' | xargs)
|
|
43
|
-
if [[ -z "$QUEEN_UNDERLAY_ADDRESS" ]] ; then
|
|
44
|
-
echo "Waiting for the Queen initialization..."
|
|
45
|
-
sleep 5
|
|
46
|
-
else
|
|
47
|
-
break;
|
|
48
|
-
fi
|
|
49
|
-
done
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
log_queen() {
|
|
53
|
-
trap stop SIGINT
|
|
54
|
-
docker logs --tail 25 -f $QUEEN_CONTAINER_NAME
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
# Init variables
|
|
58
|
-
EPHEMERAL=false
|
|
59
|
-
WORKERS=4
|
|
60
|
-
QUEEN_CONTAINER_NAME="bee-queen-test"
|
|
61
|
-
WORKER_CONTAINER_NAME="bee-worker-test"
|
|
62
|
-
QUEEN_CONTAINER_IN_DOCKER=`docker container ls -qaf name=$QUEEN_CONTAINER_NAME`
|
|
63
|
-
BEE_VERSION="latest"
|
|
64
|
-
BEE_IMAGE="ethersphere/bee:$BEE_VERSION"
|
|
65
|
-
BEE_PASSWORD="password"
|
|
66
|
-
QUEEN_BOOTNODE=""
|
|
67
|
-
PORT_MAPS=2
|
|
68
|
-
|
|
69
|
-
# Decide script action
|
|
70
|
-
case "$1" in
|
|
71
|
-
start)
|
|
72
|
-
shift 1
|
|
73
|
-
;;
|
|
74
|
-
stop)
|
|
75
|
-
stop
|
|
76
|
-
;;
|
|
77
|
-
*)
|
|
78
|
-
echoerr "Unknown command: $1"
|
|
79
|
-
usage
|
|
80
|
-
;;
|
|
81
|
-
esac
|
|
82
|
-
|
|
83
|
-
# Alter variables from flags
|
|
84
|
-
while [ $# -gt 0 ]
|
|
85
|
-
do
|
|
86
|
-
case "$1" in
|
|
87
|
-
--ephemeral)
|
|
88
|
-
EPHEMERAL=true
|
|
89
|
-
shift 1
|
|
90
|
-
;;
|
|
91
|
-
--workers=*)
|
|
92
|
-
WORKERS=${1#*=}
|
|
93
|
-
shift 1
|
|
94
|
-
;;
|
|
95
|
-
--password=*)
|
|
96
|
-
BEE_PASSWORD="${1#*=}"
|
|
97
|
-
shift 1
|
|
98
|
-
;;
|
|
99
|
-
--version=*)
|
|
100
|
-
BEE_VERSION="${1#*=}"
|
|
101
|
-
BEE_IMAGE="ethersphere/bee:$BEE_VERSION"
|
|
102
|
-
shift 1
|
|
103
|
-
;;
|
|
104
|
-
--port-maps=*)
|
|
105
|
-
PORT_MAPS="${1#*=}"
|
|
106
|
-
shift 1
|
|
107
|
-
;;
|
|
108
|
-
--help)
|
|
109
|
-
usage
|
|
110
|
-
;;
|
|
111
|
-
*)
|
|
112
|
-
echoerr "Unknown argument: $1"
|
|
113
|
-
usage
|
|
114
|
-
;;
|
|
115
|
-
esac
|
|
116
|
-
done
|
|
117
|
-
|
|
118
|
-
if $EPHEMERAL ; then
|
|
119
|
-
EXTRA_DOCKER_PARAMS=" --rm"
|
|
120
|
-
fi
|
|
121
|
-
|
|
122
|
-
# Start Bee Queen
|
|
123
|
-
if [ -z "$QUEEN_CONTAINER_IN_DOCKER" ] || $EPHEMERAL ; then
|
|
124
|
-
EXTRA_QUEEN_PARAMS=""
|
|
125
|
-
if [ $PORT_MAPS -ge 1 ] ; then
|
|
126
|
-
EXTRA_QUEEN_PARAMS=" -p 127.0.0.1:1633-1635:1633-1635"
|
|
127
|
-
fi
|
|
128
|
-
|
|
129
|
-
echo "start Bee Queen process"
|
|
130
|
-
docker run \
|
|
131
|
-
-d \
|
|
132
|
-
--name $QUEEN_CONTAINER_NAME \
|
|
133
|
-
$EXTRA_DOCKER_PARAMS \
|
|
134
|
-
$EXTRA_QUEEN_PARAMS \
|
|
135
|
-
$BEE_IMAGE \
|
|
136
|
-
start \
|
|
137
|
-
--password $BEE_PASSWORD \
|
|
138
|
-
--bootnode=$QUEEN_BOOTNODE \
|
|
139
|
-
--swap-enable=false \
|
|
140
|
-
--debug-api-enable \
|
|
141
|
-
--verbosity=4 \
|
|
142
|
-
--welcome-message="You have found the queen of the beehive..." \
|
|
143
|
-
--cors-allowed-origins="*" \
|
|
144
|
-
--payment-tolerance=2147483647
|
|
145
|
-
else
|
|
146
|
-
docker start "$QUEEN_CONTAINER_IN_DOCKER"
|
|
147
|
-
fi
|
|
148
|
-
|
|
149
|
-
# Start Bee workers
|
|
150
|
-
for i in $(seq 1 1 $WORKERS); do
|
|
151
|
-
WORKER_NAME="$WORKER_CONTAINER_NAME-$i"
|
|
152
|
-
WORKER_CONTAINER_IN_DOCKER=`docker container ls -qaf name=$WORKER_NAME`
|
|
153
|
-
if [ -z "$WORKER_CONTAINER_IN_DOCKER" ] || $EPHEMERAL ; then
|
|
154
|
-
# fetch queen underlay address
|
|
155
|
-
fetch_queen_underlay_addr
|
|
156
|
-
|
|
157
|
-
# construct additional params
|
|
158
|
-
EXTRA_WORKER_PARAMS=""
|
|
159
|
-
if [ $PORT_MAPS -gt $i ] ; then
|
|
160
|
-
PORT_START=$((1633+(10000*$i)))
|
|
161
|
-
PORT_END=$(($PORT_START + 2))
|
|
162
|
-
EXTRA_WORKER_PARAMS=" -p 127.0.0.1:$PORT_START-$PORT_END:1633-1635"
|
|
163
|
-
fi
|
|
164
|
-
|
|
165
|
-
# run docker container
|
|
166
|
-
echo "start Bee worker $i process"
|
|
167
|
-
docker run \
|
|
168
|
-
-d \
|
|
169
|
-
--name $WORKER_NAME \
|
|
170
|
-
$EXTRA_DOCKER_PARAMS \
|
|
171
|
-
$EXTRA_WORKER_PARAMS \
|
|
172
|
-
$BEE_IMAGE \
|
|
173
|
-
start \
|
|
174
|
-
--password $BEE_PASSWORD \
|
|
175
|
-
--bootnode="$QUEEN_UNDERLAY_ADDRESS" \
|
|
176
|
-
--swap-enable=false \
|
|
177
|
-
--debug-api-enable \
|
|
178
|
-
--welcome-message="I'm just Bee worker ${i} in the beehive." \
|
|
179
|
-
--cors-allowed-origins="*" \
|
|
180
|
-
--payment-tolerance=2147483647
|
|
181
|
-
else
|
|
182
|
-
docker start "$WORKER_CONTAINER_IN_DOCKER"
|
|
183
|
-
fi
|
|
184
|
-
done
|
|
185
|
-
|
|
186
|
-
# log Bee Queen
|
|
187
|
-
log_queen
|
package/test/data/1.txt
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
1
|
package/test/data/2.txt
DELETED
|
File without changes
|
package/test/data/empty
DELETED
|
File without changes
|
package/test/data/sub/3.txt
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
3
|
package/test/data/sub//303/251
DELETED
|
File without changes
|
|
File without changes
|
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
import { join } from 'path'
|
|
2
|
-
import {
|
|
3
|
-
beeDebugUrl,
|
|
4
|
-
beePeerDebugUrl,
|
|
5
|
-
beePeerUrl,
|
|
6
|
-
beeUrl,
|
|
7
|
-
commonMatchers,
|
|
8
|
-
getPostageBatch,
|
|
9
|
-
PSS_TIMEOUT,
|
|
10
|
-
} from '../utils'
|
|
11
|
-
import '../../src'
|
|
12
|
-
import type { Address } from '../../src/types'
|
|
13
|
-
|
|
14
|
-
commonMatchers()
|
|
15
|
-
|
|
16
|
-
describe('Bee class - in browser', () => {
|
|
17
|
-
const BEE_URL = beeUrl()
|
|
18
|
-
const BEE_DEBUG_URL = beeDebugUrl()
|
|
19
|
-
const BEE_PEER_URL = beePeerUrl()
|
|
20
|
-
let batchId: Address, batchIdPeer: Address
|
|
21
|
-
|
|
22
|
-
beforeAll(async () => {
|
|
23
|
-
await jestPuppeteer.resetPage()
|
|
24
|
-
const testPage = join(__dirname, '..', 'testpage', 'testpage.html')
|
|
25
|
-
await page.goto(`file://${testPage}`)
|
|
26
|
-
|
|
27
|
-
batchId = await getPostageBatch()
|
|
28
|
-
batchIdPeer = await getPostageBatch(beePeerDebugUrl())
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
it('should create a new Bee instance in browser', async () => {
|
|
32
|
-
const testBeeInstance = await page.evaluate(BEE_URL => {
|
|
33
|
-
return new window.BeeJs.Bee(BEE_URL)
|
|
34
|
-
}, BEE_URL)
|
|
35
|
-
|
|
36
|
-
expect(testBeeInstance.url).toBe(BEE_URL)
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
function testUrl(url: unknown): void {
|
|
40
|
-
it(`should not accept invalid url '${url}'`, async () => {
|
|
41
|
-
await page.evaluate(url => {
|
|
42
|
-
try {
|
|
43
|
-
new window.BeeJs.Bee(url as string)
|
|
44
|
-
fail('Bee constructor should have thrown error.')
|
|
45
|
-
} catch (e) {
|
|
46
|
-
if (e instanceof window.BeeJs.BeeArgumentError) {
|
|
47
|
-
// We don't have `expect()` available in browser context
|
|
48
|
-
if (e.value !== url) {
|
|
49
|
-
throw new Error('Error value does not match the URL!')
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
throw e
|
|
56
|
-
}
|
|
57
|
-
}, url as string)
|
|
58
|
-
})
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
testUrl('')
|
|
62
|
-
testUrl(null)
|
|
63
|
-
testUrl(undefined)
|
|
64
|
-
testUrl(1)
|
|
65
|
-
testUrl('some-invalid-url')
|
|
66
|
-
testUrl('invalid:protocol')
|
|
67
|
-
// eslint-disable-next-line no-script-url
|
|
68
|
-
testUrl('javascript:console.log()')
|
|
69
|
-
testUrl('ws://localhost:1633')
|
|
70
|
-
|
|
71
|
-
it('should pin and unpin collection', async () => {
|
|
72
|
-
const fileHash = await page.evaluate(
|
|
73
|
-
async (BEE_URL, batchId) => {
|
|
74
|
-
const bee = new window.BeeJs.Bee(BEE_URL)
|
|
75
|
-
const files: File[] = [new File(['hello'], 'hello')]
|
|
76
|
-
|
|
77
|
-
return await bee.uploadFiles(batchId, files)
|
|
78
|
-
},
|
|
79
|
-
BEE_URL,
|
|
80
|
-
batchId,
|
|
81
|
-
)
|
|
82
|
-
expect(fileHash).toBeHashReference()
|
|
83
|
-
//pinning
|
|
84
|
-
await page.evaluate(
|
|
85
|
-
async (BEE_URL, fileHash) => {
|
|
86
|
-
const bee = new window.BeeJs.Bee(BEE_URL)
|
|
87
|
-
|
|
88
|
-
return await bee.pin(fileHash)
|
|
89
|
-
},
|
|
90
|
-
BEE_URL,
|
|
91
|
-
fileHash,
|
|
92
|
-
)
|
|
93
|
-
|
|
94
|
-
//unpinning
|
|
95
|
-
await page.evaluate(
|
|
96
|
-
async (BEE_URL, fileHash) => {
|
|
97
|
-
const bee = new window.BeeJs.Bee(BEE_URL)
|
|
98
|
-
|
|
99
|
-
return await bee.unpin(fileHash)
|
|
100
|
-
},
|
|
101
|
-
BEE_URL,
|
|
102
|
-
fileHash,
|
|
103
|
-
)
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
it('should get state of uploading on uploading file', async () => {
|
|
107
|
-
const uploadEvent = await page.evaluate(
|
|
108
|
-
async (BEE_URL, batchId) => {
|
|
109
|
-
const bee = new window.BeeJs.Bee(BEE_URL)
|
|
110
|
-
const filename = 'hello.txt'
|
|
111
|
-
const data = new Uint8Array([1, 2, 3, 4])
|
|
112
|
-
|
|
113
|
-
let uploadEvent: { loaded: number; total: number } = {
|
|
114
|
-
loaded: 0,
|
|
115
|
-
total: 4,
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
await bee.uploadFile(batchId, data, filename, {
|
|
119
|
-
contentType: 'text/html',
|
|
120
|
-
axiosOptions: {
|
|
121
|
-
onUploadProgress: ({ loaded, total }) => {
|
|
122
|
-
uploadEvent = { loaded, total }
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
return uploadEvent
|
|
128
|
-
},
|
|
129
|
-
BEE_URL,
|
|
130
|
-
batchId,
|
|
131
|
-
)
|
|
132
|
-
|
|
133
|
-
expect(uploadEvent).toEqual({ loaded: 4, total: 4 })
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
describe('pss', () => {
|
|
137
|
-
it(
|
|
138
|
-
'should send and receive pss message',
|
|
139
|
-
done => {
|
|
140
|
-
// Jest does not allow use `done` and return Promise so this wrapper work arounds that.
|
|
141
|
-
;(async () => {
|
|
142
|
-
const message = '1234'
|
|
143
|
-
|
|
144
|
-
const result = await page.evaluate(
|
|
145
|
-
async (BEE_URL, BEE_DEBUG_URL, BEE_PEER_URL, message, batchIdPeer) => {
|
|
146
|
-
const topic = 'browser-bee-class-topic1'
|
|
147
|
-
|
|
148
|
-
const bee = new window.BeeJs.Bee(BEE_URL)
|
|
149
|
-
const beeDebug = new window.BeeJs.BeeDebug(BEE_DEBUG_URL)
|
|
150
|
-
|
|
151
|
-
const { overlay } = await beeDebug.getNodeAddresses()
|
|
152
|
-
const beePeer = new window.BeeJs.Bee(BEE_PEER_URL)
|
|
153
|
-
|
|
154
|
-
const receive = bee.pssReceive(topic)
|
|
155
|
-
await beePeer.pssSend(batchIdPeer, topic, overlay, message)
|
|
156
|
-
|
|
157
|
-
const msg = await receive
|
|
158
|
-
|
|
159
|
-
// Need to pass it back as string
|
|
160
|
-
return new TextDecoder('utf-8').decode(new Uint8Array(msg))
|
|
161
|
-
},
|
|
162
|
-
BEE_URL,
|
|
163
|
-
BEE_DEBUG_URL,
|
|
164
|
-
BEE_PEER_URL,
|
|
165
|
-
message,
|
|
166
|
-
batchIdPeer,
|
|
167
|
-
)
|
|
168
|
-
|
|
169
|
-
expect(result).toEqual(message)
|
|
170
|
-
done()
|
|
171
|
-
})()
|
|
172
|
-
},
|
|
173
|
-
PSS_TIMEOUT,
|
|
174
|
-
)
|
|
175
|
-
|
|
176
|
-
it(
|
|
177
|
-
'should send and receive pss message encrypted with PSS key',
|
|
178
|
-
done => {
|
|
179
|
-
// Jest does not allow use `done` and return Promise so this wrapper work arounds that.
|
|
180
|
-
;(async () => {
|
|
181
|
-
const message = '1234'
|
|
182
|
-
|
|
183
|
-
const result = await page.evaluate(
|
|
184
|
-
async (BEE_URL, BEE_DEBUG_URL, BEE_PEER_URL, message, batchIdPeer) => {
|
|
185
|
-
const topic = 'browser-bee-class-topic2'
|
|
186
|
-
|
|
187
|
-
const bee = new window.BeeJs.Bee(BEE_URL)
|
|
188
|
-
const beeDebug = new window.BeeJs.BeeDebug(BEE_DEBUG_URL)
|
|
189
|
-
|
|
190
|
-
const { overlay, pssPublicKey } = await beeDebug.getNodeAddresses()
|
|
191
|
-
const beePeer = new window.BeeJs.Bee(BEE_PEER_URL)
|
|
192
|
-
|
|
193
|
-
const receive = bee.pssReceive(topic)
|
|
194
|
-
await beePeer.pssSend(batchIdPeer, topic, overlay, message, pssPublicKey)
|
|
195
|
-
|
|
196
|
-
const msg = await receive
|
|
197
|
-
|
|
198
|
-
// Need to pass it back as string
|
|
199
|
-
return new TextDecoder('utf-8').decode(new Uint8Array(msg))
|
|
200
|
-
},
|
|
201
|
-
BEE_URL,
|
|
202
|
-
BEE_DEBUG_URL,
|
|
203
|
-
BEE_PEER_URL,
|
|
204
|
-
message,
|
|
205
|
-
batchIdPeer,
|
|
206
|
-
)
|
|
207
|
-
|
|
208
|
-
expect(result).toEqual(message)
|
|
209
|
-
done()
|
|
210
|
-
})()
|
|
211
|
-
},
|
|
212
|
-
PSS_TIMEOUT,
|
|
213
|
-
)
|
|
214
|
-
})
|
|
215
|
-
})
|