34 lines
1.0 KiB
JavaScript
34 lines
1.0 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
import assert from 'node:assert/strict';
|
|
import { readFile } from 'node:fs/promises';
|
|
import { dirname, resolve } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import {
|
|
Network,
|
|
PrivateKey,
|
|
Topology,
|
|
unicryptoReady
|
|
} from 'universa-core2';
|
|
|
|
const sourceDirectory = dirname(fileURLToPath(import.meta.url));
|
|
const topologyFile = resolve(sourceDirectory, 'universa.json');
|
|
|
|
await unicryptoReady;
|
|
|
|
const topologyData = JSON.parse(await readFile(topologyFile, 'utf8'));
|
|
const topology = await Topology.load(topologyData);
|
|
const privateKey = await PrivateKey.generate({ strength: 2048 });
|
|
const network = new Network(privateKey, {
|
|
topology,
|
|
directConnection: true
|
|
});
|
|
|
|
console.log(`Connecting to ${topology.size()} Universa nodes from ${topologyFile}`);
|
|
await network.connect();
|
|
|
|
const response = await network.command('sping');
|
|
assert.equal(response?.sping, 'spong', 'unexpected network state response');
|
|
|
|
console.log(`Universa network is functioning: ${network.size()} nodes, sping=spong`);
|