mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-02 05:43:08 +00:00
* feat: create @waku/run package for local dev env * chore: add @waku/run to release please config * feat: test @waku/run with playwright * fix: don't run waku/run tests in CI * fix: cache images so docker-compose can work offline * feat: set nodekey and staticnode flags for each nwaku node * fix: use constants for node ids * chore: set directories for running via npx * fix: remove .env, support env vars for nwaku ports * fix: use separate db (same instance) for each node * feat: add command to test dev env * chore: use package version in container name * fix: replace hardcoded WS/REST ports with constants/env vars * chore: clean up README * fix: refactor config printing into own function * fix: add run package to release please manifest * fix: defer to root folder gitignore/cspell * fix: update node version and remove tsx * fix: remove browser tests and express dep * fix: replace magic values with constants * fix: move to root .gitignore * fix: move cspell to root
121 lines
3.4 KiB
TypeScript
121 lines
3.4 KiB
TypeScript
import { execSync } from "child_process";
|
|
import { dirname, join } from "path";
|
|
import { fileURLToPath } from "url";
|
|
|
|
import { Protocols } from "@waku/sdk";
|
|
import { expect } from "chai";
|
|
|
|
import {
|
|
DEFAULT_NODE1_REST_PORT,
|
|
DEFAULT_NODE2_REST_PORT
|
|
} from "../src/constants.js";
|
|
import { WakuTestClient } from "../src/test-client.js";
|
|
import { getProjectName } from "../src/utils.js";
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = dirname(__filename);
|
|
const packageRoot = join(__dirname, "..");
|
|
|
|
describe("Waku Run - Basic Test", function () {
|
|
this.timeout(90000);
|
|
|
|
let client: WakuTestClient;
|
|
|
|
before(async function () {
|
|
// Step 1: Start the nodes
|
|
const projectName = getProjectName(packageRoot);
|
|
execSync(`docker compose --project-name ${projectName} up -d`, {
|
|
cwd: packageRoot,
|
|
stdio: "inherit",
|
|
env: { ...process.env, COMPOSE_PROJECT_NAME: projectName }
|
|
});
|
|
|
|
// Wait for nodes to be ready
|
|
const maxRetries = 30;
|
|
const retryDelay = 2000;
|
|
let ready = false;
|
|
|
|
for (let i = 0; i < maxRetries; i++) {
|
|
try {
|
|
await fetch(
|
|
`http://127.0.0.1:${DEFAULT_NODE1_REST_PORT}/debug/v1/info`
|
|
);
|
|
await fetch(
|
|
`http://127.0.0.1:${DEFAULT_NODE2_REST_PORT}/debug/v1/info`
|
|
);
|
|
ready = true;
|
|
break;
|
|
} catch {
|
|
await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
}
|
|
}
|
|
|
|
if (!ready) {
|
|
throw new Error("Nodes failed to start within expected time");
|
|
}
|
|
|
|
// Nodes automatically connect via --staticnode configuration
|
|
// cspell:ignore staticnode
|
|
// Wait for nwaku nodes to connect to each other
|
|
let connected = false;
|
|
for (let i = 0; i < 15; i++) {
|
|
try {
|
|
const peers = await fetch(
|
|
`http://127.0.0.1:${DEFAULT_NODE1_REST_PORT}/admin/v1/peers`
|
|
).then((r) => r.json());
|
|
if (peers.length > 0 && peers[0].connected === "Connected") {
|
|
connected = true;
|
|
break;
|
|
}
|
|
} catch {
|
|
// Ignore errors
|
|
}
|
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
}
|
|
|
|
if (!connected) {
|
|
throw new Error("Nwaku nodes failed to connect to each other");
|
|
}
|
|
});
|
|
|
|
after(async function () {
|
|
// Step 4: Stop the nodes
|
|
if (client) {
|
|
await client.stop();
|
|
}
|
|
const projectName = getProjectName(packageRoot);
|
|
execSync(`docker compose --project-name ${projectName} down`, {
|
|
cwd: packageRoot,
|
|
stdio: "inherit",
|
|
env: { ...process.env, COMPOSE_PROJECT_NAME: projectName }
|
|
});
|
|
});
|
|
|
|
it("should connect to both nodes and send lightpush message to both peers", async function () {
|
|
// Step 2: Connect to nodes via js-waku using WakuTestClient
|
|
client = new WakuTestClient({
|
|
contentTopic: "/test/1/basic/proto"
|
|
});
|
|
|
|
await client.start();
|
|
|
|
// Wait for both peers to be connected
|
|
await client.waku!.waitForPeers([Protocols.LightPush]);
|
|
const connectedPeers = client.waku!.libp2p.getPeers().length;
|
|
expect(connectedPeers).to.equal(
|
|
2,
|
|
"Should be connected to both nwaku nodes"
|
|
);
|
|
|
|
// Step 3: Send lightpush message - it should be sent to both peers
|
|
const result = await client.sendTestMessage("Hello Waku!");
|
|
|
|
expect(result.success).to.be.true;
|
|
expect(result.messagesSent).to.equal(
|
|
2,
|
|
"Message should be sent to both peers"
|
|
);
|
|
expect(result.failures).to.equal(0, "Should have no failures");
|
|
});
|
|
});
|