@ethersphere/bee-js 4.1.0 → 5.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/README.md +2 -2
- package/dist/cjs/{src/bee-debug.js → bee-debug.js} +8 -4
- package/dist/cjs/{src/bee.js → bee.js} +9 -3
- package/dist/cjs/{src/chunk → chunk}/bmt.js +0 -0
- package/dist/cjs/{src/chunk → chunk}/cac.js +0 -0
- package/dist/cjs/{src/chunk → chunk}/serialize.js +0 -0
- package/dist/cjs/{src/chunk → chunk}/signer.js +0 -0
- package/dist/cjs/{src/chunk → chunk}/soc.js +5 -1
- package/dist/cjs/{src/chunk → chunk}/span.js +0 -0
- package/dist/cjs/{src/feed → feed}/identifier.js +0 -0
- package/dist/cjs/{src/feed → feed}/index.js +5 -1
- package/dist/cjs/{src/feed → feed}/json.js +0 -0
- package/dist/cjs/{src/feed → feed}/retrievable.js +0 -0
- package/dist/cjs/{src/feed → feed}/topic.js +0 -0
- package/dist/cjs/{src/feed → feed}/type.js +0 -0
- package/dist/cjs/{src/index.js → index.js} +5 -1
- package/dist/cjs/{src/modules → modules}/bytes.js +0 -0
- package/dist/cjs/{src/modules → modules}/bzz.js +0 -0
- package/dist/cjs/{src/modules → modules}/chunk.js +0 -0
- package/dist/cjs/{src/modules → modules}/debug/balance.js +0 -0
- package/dist/cjs/{src/modules → modules}/debug/chequebook.js +0 -0
- package/dist/cjs/{src/modules → modules}/debug/chunk.js +0 -0
- package/dist/cjs/{src/modules → modules}/debug/connectivity.js +2 -2
- package/dist/cjs/{src/modules → modules}/debug/settlements.js +0 -0
- package/dist/cjs/{src/modules → modules}/debug/stamps.js +1 -1
- package/dist/cjs/{src/modules → modules}/debug/states.js +0 -0
- package/dist/cjs/{src/modules → modules}/debug/status.js +3 -3
- package/dist/cjs/{src/modules → modules}/debug/tag.js +0 -0
- package/dist/cjs/{src/modules → modules}/debug/transactions.js +0 -0
- package/dist/cjs/{src/modules → modules}/feed.js +0 -0
- package/dist/cjs/{src/modules → modules}/pinning.js +1 -5
- package/dist/cjs/{src/modules → modules}/pss.js +0 -0
- package/dist/cjs/{src/modules → modules}/soc.js +0 -0
- package/dist/cjs/{src/modules → modules}/status.js +0 -0
- package/dist/cjs/{src/modules → modules}/stewardship.js +0 -0
- package/dist/cjs/{src/modules → modules}/tag.js +0 -0
- package/dist/cjs/{src/types → types}/debug.js +0 -0
- package/dist/cjs/{src/types → types}/index.js +5 -1
- package/dist/cjs/{src/types → types}/ky-options.js +0 -0
- package/dist/cjs/{src/types → types}/ky-universal/common.js +0 -0
- package/dist/cjs/{src/types → types}/ky-universal/hooks.js +0 -0
- package/dist/cjs/{src/types → types}/ky-universal/retry.js +0 -0
- package/dist/cjs/{src/utils → utils}/bytes.js +0 -0
- package/dist/cjs/{src/utils → utils}/collection.browser.js +0 -0
- package/dist/cjs/{src/utils → utils}/collection.js +0 -0
- package/dist/cjs/{src/utils → utils}/collection.node.js +0 -0
- package/dist/cjs/{src/utils → utils}/data.browser.js +0 -0
- package/dist/cjs/{src/utils → utils}/data.js +0 -0
- package/dist/cjs/{src/utils → utils}/error.js +0 -0
- package/dist/cjs/{src/utils → utils}/eth.js +0 -0
- package/dist/cjs/{src/utils → utils}/expose.js +0 -0
- package/dist/cjs/{src/utils → utils}/file.js +0 -0
- package/dist/cjs/{src/utils → utils}/hash.js +0 -0
- package/dist/cjs/{src/utils → utils}/headers.js +0 -0
- package/dist/cjs/{src/utils → utils}/hex.js +0 -0
- package/dist/cjs/{src/utils → utils}/http.js +0 -0
- package/dist/cjs/{src/utils → utils}/merge.js +0 -0
- package/dist/cjs/{src/utils → utils}/pss.js +0 -0
- package/dist/cjs/{src/utils → utils}/reference.js +0 -0
- package/dist/cjs/utils/sleep.js +23 -0
- package/dist/cjs/{src/utils → utils}/stamps.js +0 -0
- package/dist/cjs/{src/utils → utils}/stream.js +0 -0
- package/dist/cjs/{src/utils → utils}/tar.js +0 -0
- package/dist/cjs/{src/utils → utils}/type.js +1 -1
- package/dist/cjs/{src/utils → utils}/uint64.js +0 -0
- package/dist/cjs/{src/utils → utils}/url.js +0 -0
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/{src/bee-debug.js → bee-debug.js} +2 -2
- package/dist/mjs/{src/bee.js → bee.js} +4 -2
- package/dist/mjs/{src/chunk → chunk}/bmt.js +0 -0
- package/dist/mjs/{src/chunk → chunk}/cac.js +0 -0
- package/dist/mjs/{src/chunk → chunk}/serialize.js +0 -0
- package/dist/mjs/{src/chunk → chunk}/signer.js +0 -0
- package/dist/mjs/{src/chunk → chunk}/soc.js +0 -0
- package/dist/mjs/{src/chunk → chunk}/span.js +0 -0
- package/dist/mjs/{src/feed → feed}/identifier.js +0 -0
- package/dist/mjs/{src/feed → feed}/index.js +0 -0
- package/dist/mjs/{src/feed → feed}/json.js +0 -0
- package/dist/mjs/{src/feed → feed}/retrievable.js +0 -0
- package/dist/mjs/{src/feed → feed}/topic.js +0 -0
- package/dist/mjs/{src/feed → feed}/type.js +0 -0
- package/dist/mjs/{src/index.js → index.js} +0 -0
- package/dist/mjs/{src/modules → modules}/bytes.js +0 -0
- package/dist/mjs/{src/modules → modules}/bzz.js +0 -0
- package/dist/mjs/{src/modules → modules}/chunk.js +0 -0
- package/dist/mjs/{src/modules → modules}/debug/balance.js +0 -0
- package/dist/mjs/{src/modules → modules}/debug/chequebook.js +0 -0
- package/dist/mjs/{src/modules → modules}/debug/chunk.js +0 -0
- package/dist/mjs/{src/modules → modules}/debug/connectivity.js +2 -2
- package/dist/mjs/{src/modules → modules}/debug/settlements.js +0 -0
- package/dist/mjs/{src/modules → modules}/debug/stamps.js +1 -1
- package/dist/mjs/{src/modules → modules}/debug/states.js +0 -0
- package/dist/mjs/{src/modules → modules}/debug/status.js +3 -3
- package/dist/mjs/{src/modules → modules}/debug/tag.js +0 -0
- package/dist/mjs/{src/modules → modules}/debug/transactions.js +0 -0
- package/dist/mjs/{src/modules → modules}/feed.js +0 -0
- package/dist/mjs/{src/modules → modules}/pinning.js +1 -7
- package/dist/mjs/{src/modules → modules}/pss.js +0 -0
- package/dist/mjs/{src/modules → modules}/soc.js +0 -0
- package/dist/mjs/{src/modules → modules}/status.js +0 -0
- package/dist/mjs/{src/modules → modules}/stewardship.js +0 -0
- package/dist/mjs/{src/modules → modules}/tag.js +0 -0
- package/dist/mjs/{src/types → types}/debug.js +0 -0
- package/dist/mjs/{src/types → types}/index.js +0 -0
- package/dist/mjs/{src/types → types}/ky-options.js +0 -0
- package/dist/mjs/{src/types → types}/ky-universal/common.js +0 -0
- package/dist/mjs/{src/types → types}/ky-universal/hooks.js +0 -0
- package/dist/mjs/{src/types → types}/ky-universal/retry.js +0 -0
- package/dist/mjs/{src/utils → utils}/bytes.js +0 -0
- package/dist/mjs/{src/utils → utils}/collection.browser.js +0 -0
- package/dist/mjs/{src/utils → utils}/collection.js +0 -0
- package/dist/mjs/{src/utils → utils}/collection.node.js +0 -0
- package/dist/mjs/{src/utils → utils}/data.browser.js +0 -0
- package/dist/mjs/{src/utils → utils}/data.js +0 -0
- package/dist/mjs/{src/utils → utils}/error.js +0 -0
- package/dist/mjs/{src/utils → utils}/eth.js +0 -0
- package/dist/mjs/{src/utils → utils}/expose.js +0 -0
- package/dist/mjs/{src/utils → utils}/file.js +0 -0
- package/dist/mjs/{src/utils → utils}/hash.js +0 -0
- package/dist/mjs/{src/utils → utils}/headers.js +0 -0
- package/dist/mjs/{src/utils → utils}/hex.js +0 -0
- package/dist/mjs/{src/utils → utils}/http.js +0 -0
- package/dist/mjs/{src/utils → utils}/merge.js +0 -0
- package/dist/mjs/{src/utils → utils}/pss.js +0 -0
- package/dist/mjs/{src/utils → utils}/reference.js +0 -0
- package/dist/mjs/utils/sleep.js +43 -0
- package/dist/mjs/{src/utils → utils}/stamps.js +0 -0
- package/dist/mjs/{src/utils → utils}/stream.js +0 -0
- package/dist/mjs/{src/utils → utils}/tar.js +0 -0
- package/dist/mjs/{src/utils → utils}/type.js +1 -1
- package/dist/mjs/{src/utils → utils}/uint64.js +0 -0
- package/dist/mjs/{src/utils → utils}/url.js +0 -0
- package/dist/types/{src/bee-debug.d.ts → bee-debug.d.ts} +0 -0
- package/dist/types/{src/bee.d.ts → bee.d.ts} +2 -3
- package/dist/types/{src/chunk → chunk}/bmt.d.ts +0 -0
- package/dist/types/{src/chunk → chunk}/cac.d.ts +0 -0
- package/dist/types/{src/chunk → chunk}/serialize.d.ts +0 -0
- package/dist/types/{src/chunk → chunk}/signer.d.ts +0 -0
- package/dist/types/{src/chunk → chunk}/soc.d.ts +0 -0
- package/dist/types/{src/chunk → chunk}/span.d.ts +0 -0
- package/dist/types/{src/feed → feed}/identifier.d.ts +0 -0
- package/dist/types/{src/feed → feed}/index.d.ts +0 -0
- package/dist/types/{src/feed → feed}/json.d.ts +0 -0
- package/dist/types/{src/feed → feed}/retrievable.d.ts +0 -0
- package/dist/types/{src/feed → feed}/topic.d.ts +0 -0
- package/dist/types/{src/feed → feed}/type.d.ts +0 -0
- package/dist/types/{src/index.d.ts → index.d.ts} +0 -0
- package/dist/types/{src/modules → modules}/bytes.d.ts +0 -0
- package/dist/types/{src/modules → modules}/bzz.d.ts +0 -0
- package/dist/types/{src/modules → modules}/chunk.d.ts +0 -0
- package/dist/types/{src/modules → modules}/debug/balance.d.ts +0 -0
- package/dist/types/{src/modules → modules}/debug/chequebook.d.ts +0 -0
- package/dist/types/{src/modules → modules}/debug/chunk.d.ts +0 -0
- package/dist/types/{src/modules → modules}/debug/connectivity.d.ts +0 -0
- package/dist/types/{src/modules → modules}/debug/settlements.d.ts +0 -0
- package/dist/types/{src/modules → modules}/debug/stamps.d.ts +0 -0
- package/dist/types/{src/modules → modules}/debug/states.d.ts +0 -0
- package/dist/types/{src/modules → modules}/debug/status.d.ts +3 -3
- package/dist/types/{src/modules → modules}/debug/tag.d.ts +0 -0
- package/dist/types/{src/modules → modules}/debug/transactions.d.ts +0 -0
- package/dist/types/{src/modules → modules}/feed.d.ts +0 -0
- package/dist/types/{src/modules → modules}/pinning.d.ts +1 -1
- package/dist/types/{src/modules → modules}/pss.d.ts +0 -0
- package/dist/types/{src/modules → modules}/soc.d.ts +0 -0
- package/dist/types/{src/modules → modules}/status.d.ts +0 -0
- package/dist/types/{src/modules → modules}/stewardship.d.ts +0 -0
- package/dist/types/{src/modules → modules}/tag.d.ts +0 -0
- package/dist/types/{src/types → types}/debug.d.ts +2 -7
- package/dist/types/{src/types → types}/index.d.ts +25 -8
- package/dist/types/{src/types → types}/ky-options.d.ts +0 -0
- package/dist/types/{src/types → types}/ky-universal/common.d.ts +0 -0
- package/dist/types/{src/types → types}/ky-universal/hooks.d.ts +0 -0
- package/dist/types/{src/types → types}/ky-universal/retry.d.ts +0 -0
- package/dist/types/{src/utils → utils}/bytes.d.ts +0 -0
- package/dist/types/{src/utils → utils}/collection.browser.d.ts +0 -0
- package/dist/types/{src/utils → utils}/collection.d.ts +0 -0
- package/dist/types/{src/utils → utils}/collection.node.d.ts +0 -0
- package/dist/types/{src/utils → utils}/data.browser.d.ts +0 -0
- package/dist/types/{src/utils → utils}/data.d.ts +0 -0
- package/dist/types/{src/utils → utils}/error.d.ts +0 -0
- package/dist/types/{src/utils → utils}/eth.d.ts +0 -0
- package/dist/types/{src/utils → utils}/expose.d.ts +0 -0
- package/dist/types/{src/utils → utils}/file.d.ts +0 -0
- package/dist/types/{src/utils → utils}/hash.d.ts +0 -0
- package/dist/types/{src/utils → utils}/headers.d.ts +0 -0
- package/dist/types/{src/utils → utils}/hex.d.ts +0 -0
- package/dist/types/{src/utils → utils}/http.d.ts +0 -0
- package/dist/types/{src/utils → utils}/merge.d.ts +0 -0
- package/dist/types/{src/utils → utils}/pss.d.ts +0 -0
- package/dist/types/{src/utils → utils}/reference.d.ts +0 -0
- package/dist/types/utils/sleep.d.ts +6 -0
- package/dist/types/{src/utils → utils}/stamps.d.ts +0 -0
- package/dist/types/{src/utils → utils}/stream.d.ts +0 -0
- package/dist/types/{src/utils → utils}/tar.d.ts +0 -0
- package/dist/types/{src/utils → utils}/type.d.ts +6 -2
- package/dist/types/{src/utils → utils}/uint64.d.ts +0 -0
- package/dist/types/{src/utils → utils}/url.d.ts +0 -0
- package/package.json +10 -10
- package/dist/cjs/test/utils.js +0 -419
- package/dist/mjs/test/utils.js +0 -458
- package/dist/types/test/utils.d.ts +0 -119
package/dist/mjs/test/utils.js
DELETED
|
@@ -1,458 +0,0 @@
|
|
|
1
|
-
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) {
|
|
3
|
-
return value instanceof P ? value : new P(function (resolve) {
|
|
4
|
-
resolve(value);
|
|
5
|
-
});
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
-
function fulfilled(value) {
|
|
10
|
-
try {
|
|
11
|
-
step(generator.next(value));
|
|
12
|
-
} catch (e) {
|
|
13
|
-
reject(e);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function rejected(value) {
|
|
18
|
-
try {
|
|
19
|
-
step(generator["throw"](value));
|
|
20
|
-
} catch (e) {
|
|
21
|
-
reject(e);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function step(result) {
|
|
26
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
import { Readable } from 'stream';
|
|
34
|
-
import { ReadableStream as ReadableStreamPolyfill } from 'web-streams-polyfill';
|
|
35
|
-
import ky from 'ky-universal';
|
|
36
|
-
import { bytesToHex } from "../src/utils/hex.js";
|
|
37
|
-
import { deleteChunkFromLocalStorage } from "../src/modules/debug/chunk.js";
|
|
38
|
-
import { BeeResponseError } from "../src/index.js";
|
|
39
|
-
import { assertBytes } from "../src/utils/bytes.js";
|
|
40
|
-
import * as stamps from "../src/modules/debug/stamps.js";
|
|
41
|
-
/**
|
|
42
|
-
* Load common own Jest Matchers which can be used to check particular return values.
|
|
43
|
-
*/
|
|
44
|
-
|
|
45
|
-
export function commonMatchers() {
|
|
46
|
-
expect.extend({
|
|
47
|
-
toBeHashReference(received) {
|
|
48
|
-
const result = {
|
|
49
|
-
pass: false,
|
|
50
|
-
message: () => 'Given input is not a Swarm hash reference'
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
if (typeof received === 'string' && /^[0-9a-fA-F]{64}$/.test(received)) {
|
|
54
|
-
result.pass = true;
|
|
55
|
-
|
|
56
|
-
result.message = () => 'Given string is semantically valid Swarm hash reference';
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return result;
|
|
60
|
-
},
|
|
61
|
-
|
|
62
|
-
toBeBeeResponse(received, expectedStatusCode) {
|
|
63
|
-
const result = {
|
|
64
|
-
pass: false,
|
|
65
|
-
message: () => `Bee response does not have status code ${expectedStatusCode}. Got: ${received.code}\nResponse message: ${received.message}`
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
if (received.code === expectedStatusCode) {
|
|
69
|
-
result.pass = true;
|
|
70
|
-
|
|
71
|
-
result.message = () => 'Bee response meets with its requirements';
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return result;
|
|
75
|
-
},
|
|
76
|
-
|
|
77
|
-
toBeOneOf(received, argument) {
|
|
78
|
-
const validValues = Array.isArray(argument) ? argument : [argument];
|
|
79
|
-
let containsValidValue = false;
|
|
80
|
-
|
|
81
|
-
for (const validValue of validValues) {
|
|
82
|
-
try {
|
|
83
|
-
expect(received).toEqual(validValue);
|
|
84
|
-
containsValidValue = true; // eslint-disable-next-line no-empty
|
|
85
|
-
} catch (e) {}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (containsValidValue) {
|
|
89
|
-
return {
|
|
90
|
-
message: () => `expected ${JSON.stringify(received)} not to be one of [${validValues.join(', ')}]`,
|
|
91
|
-
pass: true
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return {
|
|
96
|
-
message: () => `expected ${JSON.stringify(received)} to be one of [${validValues.join(', ')}]`,
|
|
97
|
-
pass: false
|
|
98
|
-
};
|
|
99
|
-
},
|
|
100
|
-
|
|
101
|
-
toBeType(received, argument) {
|
|
102
|
-
const initialType = typeof received;
|
|
103
|
-
const isArray = Array.isArray(received) ? 'array' : initialType;
|
|
104
|
-
const type = initialType === 'object' ? isArray : initialType;
|
|
105
|
-
return type === argument ? {
|
|
106
|
-
message: () => `expected ${received} to be type ${argument}`,
|
|
107
|
-
pass: true
|
|
108
|
-
} : {
|
|
109
|
-
message: () => `expected ${received} to be type ${argument}`,
|
|
110
|
-
pass: false
|
|
111
|
-
};
|
|
112
|
-
},
|
|
113
|
-
|
|
114
|
-
toBeNumberString(received) {
|
|
115
|
-
const message = () => `expected ${received} to be a number in a string type`;
|
|
116
|
-
|
|
117
|
-
return /^-?(0|[1-9][0-9]*)$/g.test(received) ? {
|
|
118
|
-
message,
|
|
119
|
-
pass: true
|
|
120
|
-
} : {
|
|
121
|
-
message,
|
|
122
|
-
pass: false
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Sleep for N miliseconds
|
|
130
|
-
*
|
|
131
|
-
* @param ms Number of miliseconds to sleep
|
|
132
|
-
*/
|
|
133
|
-
|
|
134
|
-
export function sleep(ms) {
|
|
135
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
-
return new Promise(resolve => setTimeout(() => resolve(), ms));
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Helper function that reads whole content of ReadableStream
|
|
141
|
-
* @param stream
|
|
142
|
-
*/
|
|
143
|
-
|
|
144
|
-
export function readWholeUint8ArrayReadableStream(stream) {
|
|
145
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
146
|
-
const reader = stream.getReader();
|
|
147
|
-
let buff = [];
|
|
148
|
-
let readResult;
|
|
149
|
-
|
|
150
|
-
do {
|
|
151
|
-
readResult = yield reader.read();
|
|
152
|
-
if (readResult.value) buff = [...buff, ...readResult.value];
|
|
153
|
-
} while (!readResult.done);
|
|
154
|
-
|
|
155
|
-
return new Uint8Array(buff);
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
export function createRandomNodeReadable(totalSize, chunkSize = 1000) {
|
|
159
|
-
if (totalSize % chunkSize !== 0) {
|
|
160
|
-
throw new Error(`totalSize ${totalSize} is not dividable without remainder by chunkSize ${chunkSize}`);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
const stream = new Readable(); // eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
164
|
-
|
|
165
|
-
stream._read = () => {};
|
|
166
|
-
|
|
167
|
-
for (let i = 0; i < totalSize / chunkSize; i++) {
|
|
168
|
-
stream.push(randomByteArray(chunkSize));
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
stream.push(null);
|
|
172
|
-
return stream;
|
|
173
|
-
}
|
|
174
|
-
export function createReadableStream(iterable) {
|
|
175
|
-
const iter = iterable[Symbol.iterator]();
|
|
176
|
-
return new ReadableStreamPolyfill({
|
|
177
|
-
pull(controller) {
|
|
178
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
179
|
-
const result = iter.next();
|
|
180
|
-
|
|
181
|
-
if (result.done) {
|
|
182
|
-
controller.close();
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
controller.enqueue(result.value);
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Lehmer random number generator with seed (minstd_rand in C++11)
|
|
194
|
-
* !!! Very fast but not well distributed pseudo-random function !!!
|
|
195
|
-
*
|
|
196
|
-
* @param seed Seed for the pseudo-random generator
|
|
197
|
-
*/
|
|
198
|
-
|
|
199
|
-
function lrng(seed) {
|
|
200
|
-
return () => (Math.pow(2, 31) - 1 & (seed = Math.imul(48271, seed))) / Math.pow(2, 31);
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Utility function for generating random Buffer
|
|
204
|
-
* !!! IT IS NOT CRYPTO SAFE !!!
|
|
205
|
-
* For that use `crypto.randomBytes()`
|
|
206
|
-
*
|
|
207
|
-
* @param length Number of bytes to generate
|
|
208
|
-
* @param seed Seed for the pseudo-random generator
|
|
209
|
-
*/
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
export function randomByteArray(length, seed = 500) {
|
|
213
|
-
const rand = lrng(seed);
|
|
214
|
-
const buf = new Uint8Array(length);
|
|
215
|
-
|
|
216
|
-
for (let i = 0; i < length; ++i) {
|
|
217
|
-
buf[i] = rand() * 0xff << 0;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
return buf;
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Returns a url for testing the Bee public API
|
|
224
|
-
*/
|
|
225
|
-
|
|
226
|
-
export function beeUrl() {
|
|
227
|
-
return process.env.BEE_API_URL || 'http://127.0.0.1:1633';
|
|
228
|
-
}
|
|
229
|
-
export function beeKy() {
|
|
230
|
-
return ky.create({
|
|
231
|
-
prefixUrl: beeUrl(),
|
|
232
|
-
timeout: false
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* Returns a url of another peer for testing the Bee public API
|
|
237
|
-
*/
|
|
238
|
-
|
|
239
|
-
export function beePeerUrl() {
|
|
240
|
-
return process.env.BEE_PEER_API_URL || 'http://127.0.0.1:11633';
|
|
241
|
-
}
|
|
242
|
-
export function beePeerKy() {
|
|
243
|
-
return ky.create({
|
|
244
|
-
prefixUrl: beePeerUrl(),
|
|
245
|
-
timeout: false
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Helper function that create monster batch for all the tests.
|
|
250
|
-
* There is semaphore mechanism that allows only creation of one batch across all the
|
|
251
|
-
* parallel running tests that have to wait until it is created.
|
|
252
|
-
*/
|
|
253
|
-
|
|
254
|
-
export function getPostageBatch(url = beeDebugUrl()) {
|
|
255
|
-
let stamp;
|
|
256
|
-
|
|
257
|
-
switch (url) {
|
|
258
|
-
case beeDebugUrl():
|
|
259
|
-
stamp = process.env.BEE_POSTAGE;
|
|
260
|
-
break;
|
|
261
|
-
|
|
262
|
-
case beePeerDebugUrl():
|
|
263
|
-
stamp = process.env.BEE_PEER_POSTAGE;
|
|
264
|
-
break;
|
|
265
|
-
|
|
266
|
-
default:
|
|
267
|
-
throw new Error('Unknown URL ' + url);
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
if (!stamp) {
|
|
271
|
-
throw new Error('There is no postage stamp configured for URL ' + url);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
return stamp;
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* Returns a url for testing the Bee Debug API
|
|
278
|
-
*/
|
|
279
|
-
|
|
280
|
-
export function beeDebugUrl() {
|
|
281
|
-
return process.env.BEE_DEBUG_API_URL || 'http://127.0.0.1:1635';
|
|
282
|
-
}
|
|
283
|
-
export function beeDebugKy() {
|
|
284
|
-
return ky.create({
|
|
285
|
-
prefixUrl: beeDebugUrl(),
|
|
286
|
-
timeout: false
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
/**
|
|
290
|
-
* Returns a url for testing the Bee Debug API
|
|
291
|
-
*/
|
|
292
|
-
|
|
293
|
-
export function beePeerDebugUrl() {
|
|
294
|
-
return process.env.BEE_PEER_DEBUG_API_URL || 'http://127.0.0.1:11635';
|
|
295
|
-
}
|
|
296
|
-
export function beePeerDebugKy() {
|
|
297
|
-
return ky.create({
|
|
298
|
-
prefixUrl: beePeerDebugUrl(),
|
|
299
|
-
timeout: false
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* Try to delete a chunk from local storage, ignoring all errors
|
|
304
|
-
*
|
|
305
|
-
* @param address Swarm address of chunk
|
|
306
|
-
*/
|
|
307
|
-
|
|
308
|
-
export function tryDeleteChunkFromLocalStorage(address) {
|
|
309
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
310
|
-
if (typeof address !== 'string') {
|
|
311
|
-
assertBytes(address, 32);
|
|
312
|
-
address = bytesToHex(address);
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
try {
|
|
316
|
-
yield deleteChunkFromLocalStorage(beeDebugKy(), address);
|
|
317
|
-
} catch (e) {
|
|
318
|
-
// ignore not found errors
|
|
319
|
-
if (e instanceof BeeResponseError && e.status === 404) {
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
throw e;
|
|
324
|
-
}
|
|
325
|
-
});
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* Formatting utility for displaying long strings like hexstrings.
|
|
329
|
-
*
|
|
330
|
-
* @param inputStr
|
|
331
|
-
* @param len
|
|
332
|
-
*/
|
|
333
|
-
|
|
334
|
-
export function shorten(inputStr, len = 17) {
|
|
335
|
-
const str = typeof inputStr === 'string' ? inputStr : inputStr.toString();
|
|
336
|
-
|
|
337
|
-
if (str.length <= len) {
|
|
338
|
-
return str;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
return `${str.slice(0, 6)}...${str.slice(-6)} (length: ${str.length})`;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
function timeout(ms, message = 'Execution reached timeout!') {
|
|
345
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
346
|
-
yield sleep(ms);
|
|
347
|
-
throw new Error(message);
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
export function waitForBatchToBeUsable(batchId, pollingInterval = 200) {
|
|
352
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
353
|
-
yield Promise.race([timeout(USABLE_TIMEOUT, 'Awaiting of usable postage batch timed out!'), () => __awaiter(this, void 0, void 0, function* () {
|
|
354
|
-
let stamp;
|
|
355
|
-
|
|
356
|
-
do {
|
|
357
|
-
yield sleep(pollingInterval);
|
|
358
|
-
stamp = yield stamps.getPostageBatch(beeDebugKy(), batchId);
|
|
359
|
-
} while (!stamp.usable);
|
|
360
|
-
})]);
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
const DEFAULT_BATCH_AMOUNT = '1';
|
|
364
|
-
const DEFAULT_BATCH_DEPTH = 17;
|
|
365
|
-
/**
|
|
366
|
-
* Returns already existing batch or will create one.
|
|
367
|
-
*
|
|
368
|
-
* If some specification is passed then it is guaranteed that the batch will have this property(ies)
|
|
369
|
-
*
|
|
370
|
-
* @param amount
|
|
371
|
-
* @param depth
|
|
372
|
-
* @param immutable
|
|
373
|
-
*/
|
|
374
|
-
|
|
375
|
-
export function getOrCreatePostageBatch(amount, depth, immutable) {
|
|
376
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
377
|
-
// Non-usable stamps are ignored by Bee
|
|
378
|
-
const allUsableStamps = (yield stamps.getAllPostageBatches(beeDebugKy())).filter(stamp => stamp.usable);
|
|
379
|
-
|
|
380
|
-
if (allUsableStamps.length === 0) {
|
|
381
|
-
const batchId = yield stamps.createPostageBatch(beeDebugKy(), amount !== null && amount !== void 0 ? amount : DEFAULT_BATCH_AMOUNT, depth !== null && depth !== void 0 ? depth : DEFAULT_BATCH_DEPTH);
|
|
382
|
-
yield waitForBatchToBeUsable(batchId);
|
|
383
|
-
return stamps.getPostageBatch(beeDebugKy(), batchId);
|
|
384
|
-
} // User does not want any specific batch, lets give him the first one
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
if (amount === undefined && depth === undefined && immutable === undefined) {
|
|
388
|
-
return allUsableStamps[0];
|
|
389
|
-
} // User wants some specific batch
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
for (const stamp of allUsableStamps) {
|
|
393
|
-
let meetingAllCriteria = false;
|
|
394
|
-
|
|
395
|
-
if (amount !== undefined) {
|
|
396
|
-
meetingAllCriteria = amount === stamp.amount;
|
|
397
|
-
} else {
|
|
398
|
-
meetingAllCriteria = true;
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
if (depth !== undefined) {
|
|
402
|
-
meetingAllCriteria = meetingAllCriteria && depth === stamp.depth;
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
if (immutable !== undefined) {
|
|
406
|
-
meetingAllCriteria = meetingAllCriteria && immutable === stamp.immutableFlag;
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
if (meetingAllCriteria) {
|
|
410
|
-
return stamp;
|
|
411
|
-
}
|
|
412
|
-
} // No stamp meeting the criteria was found ==> we need to create a new one
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
const batchId = yield stamps.createPostageBatch(beeDebugKy(), amount !== null && amount !== void 0 ? amount : DEFAULT_BATCH_AMOUNT, depth !== null && depth !== void 0 ? depth : DEFAULT_BATCH_DEPTH);
|
|
416
|
-
yield waitForBatchToBeUsable(batchId);
|
|
417
|
-
return stamps.getPostageBatch(beeDebugKy(), batchId);
|
|
418
|
-
});
|
|
419
|
-
}
|
|
420
|
-
export function makeTestTarget(target) {
|
|
421
|
-
return target.slice(0, 2);
|
|
422
|
-
}
|
|
423
|
-
export const invalidReference = '0000000000000000000000000000000000000000000000000000000000000000';
|
|
424
|
-
export const okResponse = {
|
|
425
|
-
code: 200,
|
|
426
|
-
message: 'OK'
|
|
427
|
-
};
|
|
428
|
-
export const createdResponse = {
|
|
429
|
-
code: 201,
|
|
430
|
-
message: 'Created'
|
|
431
|
-
};
|
|
432
|
-
const USABLE_TIMEOUT = 7000;
|
|
433
|
-
export const ERR_TIMEOUT = 40000;
|
|
434
|
-
export const BIG_FILE_TIMEOUT = 100000;
|
|
435
|
-
export const PSS_TIMEOUT = 120000;
|
|
436
|
-
export const FEED_TIMEOUT = 120000;
|
|
437
|
-
export const BLOCKCHAIN_TRANSACTION_TIMEOUT = 40000;
|
|
438
|
-
export const WAITING_USABLE_STAMP_TIMEOUT = 130000;
|
|
439
|
-
export const testChunkPayload = new Uint8Array([1, 2, 3]); // span is the payload length encoded as uint64 little endian
|
|
440
|
-
|
|
441
|
-
export const testChunkSpan = new Uint8Array([testChunkPayload.length, 0, 0, 0, 0, 0, 0, 0]);
|
|
442
|
-
export const testChunkData = new Uint8Array([...testChunkSpan, ...testChunkPayload]); // the hash is hardcoded because we would need the bmt hasher otherwise
|
|
443
|
-
|
|
444
|
-
export const testChunkHash = 'ca6357a08e317d15ec560fef34e4c45f8f19f01c372aa70f1da72bfa7f1a4338';
|
|
445
|
-
export const testAddress = 'ca6357a08e317d15ec560fef34e4c45f8f19f01c372aa70f1da72bfa7f1a4338';
|
|
446
|
-
export const testBatchId = 'ca6357a08e317d15ec560fef34e4c45f8f19f01c372aa70f1da72bfa7f1a4338';
|
|
447
|
-
export const testJsonPayload = [{
|
|
448
|
-
some: 'object'
|
|
449
|
-
}];
|
|
450
|
-
export const testJsonStringPayload = JSON.stringify(testJsonPayload);
|
|
451
|
-
export const testJsonHash = '872a858115b8bee4408b1427b49e472883fdc2512d5a8f2d428b97ecc8f7ccfa';
|
|
452
|
-
export const testJsonCid = 'bah5acgzaq4vilaivxc7oiqelcqt3jhshfcb73qsrfvni6lkcrol6zshxzt5a';
|
|
453
|
-
export const testJsonEns = 'testing.eth';
|
|
454
|
-
export const testIdentity = {
|
|
455
|
-
privateKey: '634fb5a872396d9693e5c9f9d7233cfa93f395c093371017ff44aa9ae6564cdd',
|
|
456
|
-
publicKey: '03c32bb011339667a487b6c1c35061f15f7edc36aa9a0f8648aba07a4b8bd741b4',
|
|
457
|
-
address: '8d3766440f0d7b949a5e32995d09619a7f86e632'
|
|
458
|
-
};
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { Readable } from 'stream';
|
|
3
|
-
import type { Ky, BeeGenericResponse, Reference, Address, BatchId, PostageBatch, PlainBytesReference } from '../src/types';
|
|
4
|
-
import { HexString } from '../src/utils/hex';
|
|
5
|
-
declare global {
|
|
6
|
-
namespace jest {
|
|
7
|
-
interface Matchers<R> {
|
|
8
|
-
toBeHashReference(): R;
|
|
9
|
-
toBeBeeResponse(expectedStatusCode: number): R;
|
|
10
|
-
toBeOneOf(el: unknown[]): R;
|
|
11
|
-
toBeType(type: string): R;
|
|
12
|
-
toBeNumberString(): R;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Load common own Jest Matchers which can be used to check particular return values.
|
|
18
|
-
*/
|
|
19
|
-
export declare function commonMatchers(): void;
|
|
20
|
-
/**
|
|
21
|
-
* Sleep for N miliseconds
|
|
22
|
-
*
|
|
23
|
-
* @param ms Number of miliseconds to sleep
|
|
24
|
-
*/
|
|
25
|
-
export declare function sleep(ms: number): Promise<void>;
|
|
26
|
-
/**
|
|
27
|
-
* Helper function that reads whole content of ReadableStream
|
|
28
|
-
* @param stream
|
|
29
|
-
*/
|
|
30
|
-
export declare function readWholeUint8ArrayReadableStream(stream: ReadableStream<Uint8Array>): Promise<Uint8Array>;
|
|
31
|
-
export declare function createRandomNodeReadable(totalSize: number, chunkSize?: number): Readable;
|
|
32
|
-
export declare function createReadableStream(iterable: Iterable<Uint8Array>): ReadableStream;
|
|
33
|
-
/**
|
|
34
|
-
* Utility function for generating random Buffer
|
|
35
|
-
* !!! IT IS NOT CRYPTO SAFE !!!
|
|
36
|
-
* For that use `crypto.randomBytes()`
|
|
37
|
-
*
|
|
38
|
-
* @param length Number of bytes to generate
|
|
39
|
-
* @param seed Seed for the pseudo-random generator
|
|
40
|
-
*/
|
|
41
|
-
export declare function randomByteArray(length: number, seed?: number): Uint8Array;
|
|
42
|
-
/**
|
|
43
|
-
* Returns a url for testing the Bee public API
|
|
44
|
-
*/
|
|
45
|
-
export declare function beeUrl(): string;
|
|
46
|
-
export declare function beeKy(): Ky;
|
|
47
|
-
/**
|
|
48
|
-
* Returns a url of another peer for testing the Bee public API
|
|
49
|
-
*/
|
|
50
|
-
export declare function beePeerUrl(): string;
|
|
51
|
-
export declare function beePeerKy(): Ky;
|
|
52
|
-
/**
|
|
53
|
-
* Helper function that create monster batch for all the tests.
|
|
54
|
-
* There is semaphore mechanism that allows only creation of one batch across all the
|
|
55
|
-
* parallel running tests that have to wait until it is created.
|
|
56
|
-
*/
|
|
57
|
-
export declare function getPostageBatch(url?: string): BatchId;
|
|
58
|
-
/**
|
|
59
|
-
* Returns a url for testing the Bee Debug API
|
|
60
|
-
*/
|
|
61
|
-
export declare function beeDebugUrl(): string;
|
|
62
|
-
export declare function beeDebugKy(): Ky;
|
|
63
|
-
/**
|
|
64
|
-
* Returns a url for testing the Bee Debug API
|
|
65
|
-
*/
|
|
66
|
-
export declare function beePeerDebugUrl(): string;
|
|
67
|
-
export declare function beePeerDebugKy(): Ky;
|
|
68
|
-
/**
|
|
69
|
-
* Try to delete a chunk from local storage, ignoring all errors
|
|
70
|
-
*
|
|
71
|
-
* @param address Swarm address of chunk
|
|
72
|
-
*/
|
|
73
|
-
export declare function tryDeleteChunkFromLocalStorage(address: string | PlainBytesReference): Promise<void>;
|
|
74
|
-
/**
|
|
75
|
-
* Formatting utility for displaying long strings like hexstrings.
|
|
76
|
-
*
|
|
77
|
-
* @param inputStr
|
|
78
|
-
* @param len
|
|
79
|
-
*/
|
|
80
|
-
export declare function shorten(inputStr: unknown, len?: number): string;
|
|
81
|
-
export declare function waitForBatchToBeUsable(batchId: string, pollingInterval?: number): Promise<void>;
|
|
82
|
-
/**
|
|
83
|
-
* Returns already existing batch or will create one.
|
|
84
|
-
*
|
|
85
|
-
* If some specification is passed then it is guaranteed that the batch will have this property(ies)
|
|
86
|
-
*
|
|
87
|
-
* @param amount
|
|
88
|
-
* @param depth
|
|
89
|
-
* @param immutable
|
|
90
|
-
*/
|
|
91
|
-
export declare function getOrCreatePostageBatch(amount?: string, depth?: number, immutable?: boolean): Promise<PostageBatch>;
|
|
92
|
-
export declare function makeTestTarget(target: string): string;
|
|
93
|
-
export declare const invalidReference: Reference;
|
|
94
|
-
export declare const okResponse: BeeGenericResponse;
|
|
95
|
-
export declare const createdResponse: BeeGenericResponse;
|
|
96
|
-
export declare const ERR_TIMEOUT = 40000;
|
|
97
|
-
export declare const BIG_FILE_TIMEOUT = 100000;
|
|
98
|
-
export declare const PSS_TIMEOUT = 120000;
|
|
99
|
-
export declare const FEED_TIMEOUT = 120000;
|
|
100
|
-
export declare const BLOCKCHAIN_TRANSACTION_TIMEOUT = 40000;
|
|
101
|
-
export declare const WAITING_USABLE_STAMP_TIMEOUT = 130000;
|
|
102
|
-
export declare const testChunkPayload: Uint8Array;
|
|
103
|
-
export declare const testChunkSpan: Uint8Array;
|
|
104
|
-
export declare const testChunkData: Uint8Array;
|
|
105
|
-
export declare const testChunkHash: Reference;
|
|
106
|
-
export declare const testAddress: Address;
|
|
107
|
-
export declare const testBatchId: BatchId;
|
|
108
|
-
export declare const testJsonPayload: {
|
|
109
|
-
some: string;
|
|
110
|
-
}[];
|
|
111
|
-
export declare const testJsonStringPayload: string;
|
|
112
|
-
export declare const testJsonHash = "872a858115b8bee4408b1427b49e472883fdc2512d5a8f2d428b97ecc8f7ccfa";
|
|
113
|
-
export declare const testJsonCid = "bah5acgzaq4vilaivxc7oiqelcqt3jhshfcb73qsrfvni6lkcrol6zshxzt5a";
|
|
114
|
-
export declare const testJsonEns = "testing.eth";
|
|
115
|
-
export declare const testIdentity: {
|
|
116
|
-
privateKey: HexString<number>;
|
|
117
|
-
publicKey: HexString<number>;
|
|
118
|
-
address: HexString<number>;
|
|
119
|
-
};
|