Use released universa-core2 alpha

This commit is contained in:
sergeych committed 2026-07-30 22:47:52 +04:00
1 parent 170ce43992
commit d84d085d8c
3 files changed
+33 -603

No files matched your search

+8 -33
View File
@@ -2,7 +2,7 @@
import { readFileSync } from 'node:fs';
import { createRequire } from 'node:module';
import { basename, dirname, resolve } from 'node:path';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
const require = createRequire(import.meta.url);
@@ -13,12 +13,12 @@ const {
SymmetricKey,
decode64,
encode64,
randomBytes
} = require('unicrypto');
randomBytes,
unicryptoReady
} = require('universa-core2');
const projectDirectory = resolve(dirname(fileURLToPath(import.meta.url)), '..');
const topologyFile = resolve(projectDirectory, 'src/universa.json');
const cryptoDist = resolve(projectDirectory, 'node_modules/unicrypto/dist');
const requestTimeoutMs = 5000;
const clientVersion = 3;
@@ -31,31 +31,6 @@ function describeError(error) {
}
}
async function withWasmLoader(callback) {
const savedFetch = globalThis.fetch;
const savedRead = globalThis.read;
const savedReadBinary = globalThis.readBinary;
globalThis.fetch = undefined;
globalThis.read = (fileName, binary) => {
const data = readFileSync(resolve(cryptoDist, basename(fileName)));
return binary ? data : data.toString('binary');
};
globalThis.readBinary = (fileName) => (
readFileSync(resolve(cryptoDist, basename(fileName)))
);
try {
return await callback(savedFetch);
} finally {
globalThis.fetch = savedFetch;
if (savedRead === undefined) delete globalThis.read;
else globalThis.read = savedRead;
if (savedReadBinary === undefined) delete globalThis.readBinary;
else globalThis.readBinary = savedReadBinary;
}
}
function loadTopology() {
const topology = JSON.parse(readFileSync(topologyFile, 'utf8'));
const nodes = Array.isArray(topology) ? topology : topology.list;
@@ -209,10 +184,10 @@ async function main(fetchImpl) {
}
try {
await withWasmLoader(async (fetchImpl) => {
if (!fetchImpl) throw new Error('This test requires the Node.js fetch API');
await main(fetchImpl);
});
await unicryptoReady;
const fetchImpl = globalThis.fetch;
if (!fetchImpl) throw new Error('This test requires the Node.js fetch API');
await main(fetchImpl);
} catch (error) {
console.error(describeError(error));
process.exitCode = 1;