mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-14 19:53:12 +00:00
fix: use constants for node ids
This commit is contained in:
parent
52a4a5d6c9
commit
3ea83f800d
@ -2,6 +2,8 @@
|
||||
|
||||
import { execSync } from "child_process";
|
||||
|
||||
import { NODE1_PEER_ID, NODE2_PEER_ID } from "../src/constants.js";
|
||||
|
||||
interface Colors {
|
||||
reset: string;
|
||||
cyan: string;
|
||||
@ -39,8 +41,8 @@ try {
|
||||
|
||||
// Static peer IDs from --nodekey configuration
|
||||
// cspell:ignore nodekey
|
||||
const peer1: string = "16Uiu2HAmF6oAsd23RMAnZb3NJgxXrExxBTPMdEoih232iAZkviU2";
|
||||
const peer2: string = "16Uiu2HAm5aZU47YkiUoARqivbCXwuFPzFFXXiURAorySqAQbL6EQ";
|
||||
const peer1: string = NODE1_PEER_ID;
|
||||
const peer2: string = NODE2_PEER_ID;
|
||||
|
||||
// Print TypeScript-style config
|
||||
process.stdout.write(
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
|
||||
import { execSync } from "child_process";
|
||||
|
||||
import { NODE1_PEER_ID, NODE2_PEER_ID } from "../src/constants.js";
|
||||
|
||||
interface Colors {
|
||||
reset: string;
|
||||
cyan: string;
|
||||
@ -103,8 +105,8 @@ try {
|
||||
|
||||
// Static peer IDs from --nodekey configuration
|
||||
// cspell:ignore nodekey
|
||||
const peer1: string = "16Uiu2HAmF6oAsd23RMAnZb3NJgxXrExxBTPMdEoih232iAZkviU2";
|
||||
const peer2: string = "16Uiu2HAm5aZU47YkiUoARqivbCXwuFPzFFXXiURAorySqAQbL6EQ";
|
||||
const peer1: string = NODE1_PEER_ID;
|
||||
const peer2: string = NODE2_PEER_ID;
|
||||
|
||||
// Print TypeScript-style config
|
||||
process.stdout.write(
|
||||
|
||||
21
packages/run/src/constants.ts
Normal file
21
packages/run/src/constants.ts
Normal file
@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Static configuration constants for the local Waku development environment.
|
||||
* These values are derived from the --nodekey configuration in docker-compose.yml
|
||||
* cspell:ignore nodekey
|
||||
*/
|
||||
|
||||
// Node private keys (from docker-compose.yml --nodekey)
|
||||
export const NODE1_PRIVATE_KEY =
|
||||
"e419c3cf4f09ac3babdf61856e6faa0e0c6a7d97674d5401a0114616549c7632";
|
||||
export const NODE2_PRIVATE_KEY =
|
||||
"50632ab0efd313bfb4aa842de716f03dacd181c863770abd145e3409290fdaa7";
|
||||
|
||||
// Derived peer IDs (libp2p identities from the private keys)
|
||||
export const NODE1_PEER_ID =
|
||||
"16Uiu2HAmF6oAsd23RMAnZb3NJgxXrExxBTPMdEoih232iAZkviU2";
|
||||
export const NODE2_PEER_ID =
|
||||
"16Uiu2HAm5aZU47YkiUoARqivbCXwuFPzFFXXiURAorySqAQbL6EQ";
|
||||
|
||||
// Static IP addresses (from docker-compose.yml network configuration)
|
||||
export const NODE1_IP = "172.20.0.10";
|
||||
export const NODE2_IP = "172.20.0.11";
|
||||
@ -6,6 +6,8 @@ import { createLightNode, Protocols } from "@waku/sdk";
|
||||
import { createRoutingInfo } from "@waku/utils";
|
||||
import { expect } from "chai";
|
||||
|
||||
import { NODE1_PEER_ID, NODE2_PEER_ID } from "../src/constants.js";
|
||||
|
||||
describe("Waku Run - Basic Test", function () {
|
||||
this.timeout(90000);
|
||||
|
||||
@ -39,8 +41,26 @@ describe("Waku Run - Basic Test", function () {
|
||||
|
||||
// Nodes automatically connect via --staticnode configuration
|
||||
// cspell:ignore staticnode
|
||||
// Wait a bit for the connection to establish
|
||||
await new Promise((resolve) => setTimeout(resolve, 2000));
|
||||
// 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:8646/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 () {
|
||||
@ -60,8 +80,8 @@ describe("Waku Run - Basic Test", function () {
|
||||
|
||||
// Static peer IDs from --nodekey configuration
|
||||
// cspell:ignore nodekey
|
||||
const peer1 = "16Uiu2HAmF6oAsd23RMAnZb3NJgxXrExxBTPMdEoih232iAZkviU2";
|
||||
const peer2 = "16Uiu2HAm5aZU47YkiUoARqivbCXwuFPzFFXXiURAorySqAQbL6EQ";
|
||||
const peer1 = NODE1_PEER_ID;
|
||||
const peer2 = NODE2_PEER_ID;
|
||||
|
||||
const networkConfig = {
|
||||
clusterId: 0,
|
||||
|
||||
@ -4,6 +4,8 @@ import { fileURLToPath } from "url";
|
||||
|
||||
import { Browser, chromium, expect, Page, test } from "@playwright/test";
|
||||
|
||||
import { NODE1_PEER_ID, NODE2_PEER_ID } from "../src/constants.js";
|
||||
|
||||
import { startTestServer, stopTestServer } from "./test-server.js";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
@ -47,18 +49,6 @@ test.describe("Waku Run - Browser Test", () => {
|
||||
throw new Error("Nodes failed to start within expected time");
|
||||
}
|
||||
|
||||
// Connect the two nwaku nodes together
|
||||
const node1Info = await fetch("http://127.0.0.1:8646/debug/v1/info").then(
|
||||
(r) => r.json()
|
||||
);
|
||||
const peer1Multiaddr = node1Info.listenAddresses[0];
|
||||
|
||||
await fetch("http://127.0.0.1:8647/admin/v1/peers", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify([peer1Multiaddr])
|
||||
});
|
||||
|
||||
// Wait for connection to establish
|
||||
await new Promise((resolve) => setTimeout(resolve, 2000));
|
||||
|
||||
@ -81,13 +71,11 @@ test.describe("Waku Run - Browser Test", () => {
|
||||
console.error("[Browser Page Error]", error.message);
|
||||
});
|
||||
|
||||
// Navigate to test page
|
||||
await page.goto(`${baseUrl}/index.html`, {
|
||||
// cspell:ignore networkidle - Playwright waitUntil option
|
||||
waitUntil: "networkidle"
|
||||
});
|
||||
|
||||
// Wait for wakuBrowser to be available
|
||||
await page.waitForFunction(
|
||||
() => {
|
||||
return (
|
||||
@ -121,21 +109,15 @@ test.describe("Waku Run - Browser Test", () => {
|
||||
});
|
||||
|
||||
test("should initialize Waku node in browser", async () => {
|
||||
test.setTimeout(120000); // 2 minutes timeout for this test
|
||||
test.setTimeout(120000);
|
||||
|
||||
const node1Port = process.env.NODE1_WS_PORT || "60000";
|
||||
const node2Port = process.env.NODE2_WS_PORT || "60001";
|
||||
|
||||
// Fetch node info to get peer IDs
|
||||
const node1Info = await fetch("http://127.0.0.1:8646/debug/v1/info").then(
|
||||
(r) => r.json()
|
||||
);
|
||||
const node2Info = await fetch("http://127.0.0.1:8647/debug/v1/info").then(
|
||||
(r) => r.json()
|
||||
);
|
||||
|
||||
const peer1 = node1Info.listenAddresses[0].split("/p2p/")[1];
|
||||
const peer2 = node2Info.listenAddresses[0].split("/p2p/")[1];
|
||||
// Static peer IDs from --nodekey configuration
|
||||
// cspell:ignore nodekey
|
||||
const peer1 = NODE1_PEER_ID;
|
||||
const peer2 = NODE2_PEER_ID;
|
||||
|
||||
const config = {
|
||||
bootstrapPeers: [
|
||||
|
||||
@ -21,39 +21,25 @@ class WakuBrowser {
|
||||
this.waku = await createLightNode({
|
||||
defaultBootstrap: false,
|
||||
bootstrapPeers: config.bootstrapPeers,
|
||||
networkConfig: config.networkConfig
|
||||
networkConfig: config.networkConfig,
|
||||
libp2p: {
|
||||
filterMultiaddrs: false
|
||||
}
|
||||
});
|
||||
|
||||
console.log("Starting node...");
|
||||
await this.waku.start();
|
||||
|
||||
// Explicitly dial each bootstrap peer
|
||||
console.log("Dialing bootstrap peers...");
|
||||
console.log("Connecting to bootstrap peers...");
|
||||
for (const peer of config.bootstrapPeers) {
|
||||
try {
|
||||
console.log(`Dialing ${peer}...`);
|
||||
await this.waku.dial(peer);
|
||||
console.log(`Successfully dialed ${peer}`);
|
||||
} catch (error) {
|
||||
console.warn(`Failed to dial ${peer}:`, error);
|
||||
}
|
||||
await this.waku.dial(peer);
|
||||
}
|
||||
|
||||
console.log("Waiting for peers...");
|
||||
try {
|
||||
await this.waku.waitForPeers([Protocols.LightPush], 30000); // 30 second timeout
|
||||
console.log("Peers found!");
|
||||
} catch (error) {
|
||||
console.warn("Timeout waiting for peers, continuing anyway:", error);
|
||||
// Continue anyway - we can still try to send messages
|
||||
}
|
||||
await this.waku.waitForPeers([Protocols.LightPush]);
|
||||
|
||||
// Check connected peers
|
||||
const peers = this.waku.libp2p.getPeers();
|
||||
console.log(
|
||||
`Connected to ${peers.length} peers:`,
|
||||
peers.map((p) => p.toString())
|
||||
);
|
||||
console.log(`Connected to ${peers.length} peers`);
|
||||
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user