mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-10 01:33:13 +00:00
fix: replace console with logger
This commit is contained in:
parent
797311a405
commit
49e8b719b8
195
package-lock.json
generated
195
package-lock.json
generated
@ -4715,7 +4715,6 @@
|
||||
"version": "1.53.1",
|
||||
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.53.1.tgz",
|
||||
"integrity": "sha512-Z4c23LHV0muZ8hfv4jw6HngPJkbbtZxTkxPNIg7cJcTc9C28N/p2q7g3JZS2SiKBBHJ3uM1dgDye66bB7LEk5w==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"playwright": "1.53.1"
|
||||
@ -7542,6 +7541,46 @@
|
||||
"node": ">=20"
|
||||
}
|
||||
},
|
||||
"node_modules/@waku/message-hash/node_modules/@waku/interfaces": {
|
||||
"version": "0.0.30",
|
||||
"resolved": "https://registry.npmjs.org/@waku/interfaces/-/interfaces-0.0.30.tgz",
|
||||
"integrity": "sha512-2cR8+u0CePmUFBB4vVL1zw403Rki5hK+7rKQH0WikDT4SD4lJTdMV4j3q3+YBfPTsMJrFCVFhLcqpeBADgavAw==",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"dependencies": {
|
||||
"@waku/proto": "^0.0.10"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
}
|
||||
},
|
||||
"node_modules/@waku/message-hash/node_modules/@waku/proto": {
|
||||
"version": "0.0.10",
|
||||
"resolved": "https://registry.npmjs.org/@waku/proto/-/proto-0.0.10.tgz",
|
||||
"integrity": "sha512-dgBOjwRtduZSHxmr2IqDfrzgDnog8f/qiseLV39W1WNDkVLqpNT7K2bPDPz5/e2e7EtVtTAzbGPZPakOswn5FQ==",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"dependencies": {
|
||||
"protons-runtime": "^5.4.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
}
|
||||
},
|
||||
"node_modules/@waku/message-hash/node_modules/@waku/utils": {
|
||||
"version": "0.0.23",
|
||||
"resolved": "https://registry.npmjs.org/@waku/utils/-/utils-0.0.23.tgz",
|
||||
"integrity": "sha512-8abBIAI7hq1kb5WVpv0o6CCW5Go3bwxo1xovKXfTZfdERwgV7/R6VcijKaUWOHF9SYIskyJuC98TFx/1HgrUBw==",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"dependencies": {
|
||||
"@noble/hashes": "^1.3.2",
|
||||
"@waku/interfaces": "0.0.30",
|
||||
"chai": "^4.3.10",
|
||||
"debug": "^4.3.4",
|
||||
"uint8arrays": "^5.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
}
|
||||
},
|
||||
"node_modules/@waku/proto": {
|
||||
"resolved": "packages/proto",
|
||||
"link": true
|
||||
@ -26487,7 +26526,6 @@
|
||||
"version": "1.53.1",
|
||||
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.53.1.tgz",
|
||||
"integrity": "sha512-LJ13YLr/ocweuwxyGf1XNFWIU4M2zUSo149Qbp+A4cpwDjsxRPj7k6H25LBrEHiEwxvRbD8HdwvQmRMSvquhYw==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"playwright-core": "1.53.1"
|
||||
@ -26506,7 +26544,6 @@
|
||||
"version": "1.53.1",
|
||||
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.53.1.tgz",
|
||||
"integrity": "sha512-Z46Oq7tLAyT0lGoFx4DOuB1IA9D1TPj0QkYxpPVUnGDqHHvDpCftu1J2hM2PiWsNMoZh8+LQaarAWcDfPBc6zg==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"bin": {
|
||||
"playwright-core": "cli.js"
|
||||
@ -27234,7 +27271,6 @@
|
||||
"version": "2.3.2",
|
||||
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
|
||||
"integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
|
||||
"dev": true,
|
||||
"hasInstallScript": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
@ -34344,9 +34380,11 @@
|
||||
"name": "@waku/browser-tests",
|
||||
"version": "0.1.0",
|
||||
"dependencies": {
|
||||
"@playwright/test": "^1.51.1",
|
||||
"@waku/discovery": "^0.0.11",
|
||||
"@waku/interfaces": "^0.0.33",
|
||||
"@waku/sdk": "^0.0.34",
|
||||
"@waku/utils": "0.0.27",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv-flow": "^0.4.0",
|
||||
"express": "^4.21.2",
|
||||
@ -34354,10 +34392,10 @@
|
||||
"it-first": "^3.0.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@playwright/test": "^1.51.1",
|
||||
"@types/cors": "^2.8.15",
|
||||
"@types/express": "^4.17.21",
|
||||
"@types/node": "^20.10.0",
|
||||
"@waku/tests": "*",
|
||||
"axios": "^1.8.4",
|
||||
"esbuild": "^0.21.5",
|
||||
"npm-run-all": "^4.1.5",
|
||||
@ -34764,17 +34802,131 @@
|
||||
"undici-types": "~6.19.2"
|
||||
}
|
||||
},
|
||||
"packages/browser-tests/node_modules/@waku/discovery/node_modules/@waku/interfaces": {
|
||||
"version": "0.0.26",
|
||||
"resolved": "https://registry.npmjs.org/@waku/interfaces/-/interfaces-0.0.26.tgz",
|
||||
"integrity": "sha512-YZU4+1j8n7lEKFTz3RTHaNm4Jsv1kurG87G7ZZZwFRuzHjTVizGldI5Nfu8eUemr8dGIBCgadybXqJY/GjsLcA==",
|
||||
"extraneous": true,
|
||||
"packages/browser-tests/node_modules/@waku/core": {
|
||||
"version": "0.0.38",
|
||||
"resolved": "https://registry.npmjs.org/@waku/core/-/core-0.0.38.tgz",
|
||||
"integrity": "sha512-Vm7o5uA7oQDc5tL6UHWUCsNqk8U7Dw+jAzbIjfsUJjNCtWov/8e1+ysrihcJfz0YmQnXfiuGA/rJSaJwMhtiNQ==",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"dependencies": {
|
||||
"@waku/proto": "^0.0.8"
|
||||
"@libp2p/ping": "2.0.35",
|
||||
"@noble/hashes": "^1.3.2",
|
||||
"@waku/enr": "^0.0.32",
|
||||
"@waku/interfaces": "0.0.33",
|
||||
"@waku/proto": "0.0.13",
|
||||
"@waku/utils": "0.0.26",
|
||||
"debug": "^4.3.4",
|
||||
"it-all": "^3.0.4",
|
||||
"it-length-prefixed": "^9.0.4",
|
||||
"it-pipe": "^3.0.1",
|
||||
"uint8arraylist": "^2.4.3",
|
||||
"uuid": "^9.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
"node": ">=22"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@multiformats/multiaddr": "^12.0.0",
|
||||
"libp2p": "2.8.11"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@multiformats/multiaddr": {
|
||||
"optional": true
|
||||
},
|
||||
"libp2p": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"packages/browser-tests/node_modules/@waku/discovery": {
|
||||
"version": "0.0.11",
|
||||
"resolved": "https://registry.npmjs.org/@waku/discovery/-/discovery-0.0.11.tgz",
|
||||
"integrity": "sha512-PeL1nECYHnkCAZlIAl72JBqnuKOABlaxU0LydhH6gyCuwfilw09aWD8JFk6oVwLyW2LhUpckkUWP8Gg18qIW8g==",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"dependencies": {
|
||||
"@waku/core": "0.0.38",
|
||||
"@waku/enr": "0.0.32",
|
||||
"@waku/interfaces": "0.0.33",
|
||||
"@waku/proto": "^0.0.13",
|
||||
"@waku/utils": "0.0.26",
|
||||
"debug": "^4.3.4",
|
||||
"dns-over-http-resolver": "^3.0.8",
|
||||
"hi-base32": "^0.5.1",
|
||||
"uint8arrays": "^5.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=22"
|
||||
}
|
||||
},
|
||||
"packages/browser-tests/node_modules/@waku/enr": {
|
||||
"version": "0.0.32",
|
||||
"resolved": "https://registry.npmjs.org/@waku/enr/-/enr-0.0.32.tgz",
|
||||
"integrity": "sha512-bAC/uYV9L25mCjoFY0Z9dQzrZr8/OV60GhNGbbqvRi9uX/k6suiT4guWATzW01c3p1TsWEO1uJS2zDzSPvgcWg==",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"dependencies": {
|
||||
"@ethersproject/rlp": "^5.7.0",
|
||||
"@libp2p/crypto": "5.1.6",
|
||||
"@libp2p/peer-id": "5.1.7",
|
||||
"@multiformats/multiaddr": "^12.0.0",
|
||||
"@noble/secp256k1": "^1.7.1",
|
||||
"@waku/utils": "0.0.26",
|
||||
"debug": "^4.3.4",
|
||||
"js-sha3": "^0.9.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=22"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@multiformats/multiaddr": "^12.0.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@multiformats/multiaddr": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"packages/browser-tests/node_modules/@waku/interfaces": {
|
||||
"version": "0.0.33",
|
||||
"resolved": "https://registry.npmjs.org/@waku/interfaces/-/interfaces-0.0.33.tgz",
|
||||
"integrity": "sha512-+DAc6l/pxW+o8a9NQb3bjZ0auwItXGuamqJe8UmjJd5w70RVqNZgl8WNH9lAkOH2UswYBdQjKaS5VNxBMFj8ew==",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"engines": {
|
||||
"node": ">=22"
|
||||
}
|
||||
},
|
||||
"packages/browser-tests/node_modules/@waku/proto": {
|
||||
"version": "0.0.13",
|
||||
"resolved": "https://registry.npmjs.org/@waku/proto/-/proto-0.0.13.tgz",
|
||||
"integrity": "sha512-t2ZFQ4TSJWsyljxBIRhA1lOvmgqDCReiX2GaRoJEXWnglOYxWlHzQ7rkIq1aONAiRqG6JWB4nfE4FcJVSE7TkA==",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"dependencies": {
|
||||
"protons-runtime": "^5.4.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=22"
|
||||
}
|
||||
},
|
||||
"packages/browser-tests/node_modules/@waku/sdk": {
|
||||
"version": "0.0.34",
|
||||
"resolved": "https://registry.npmjs.org/@waku/sdk/-/sdk-0.0.34.tgz",
|
||||
"integrity": "sha512-1kLafimSX9QeSk2/W/V+ErcekZgMR/OmtqmtM78BhW7n+Yo9XpI1ZVsGGKIu3mXnt/mKgCt0Pg4mViEl4PIlIg==",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"dependencies": {
|
||||
"@chainsafe/libp2p-noise": "16.1.3",
|
||||
"@libp2p/bootstrap": "11.0.42",
|
||||
"@libp2p/identify": "3.0.36",
|
||||
"@libp2p/mplex": "11.0.42",
|
||||
"@libp2p/ping": "2.0.35",
|
||||
"@libp2p/websockets": "9.2.16",
|
||||
"@noble/hashes": "^1.3.3",
|
||||
"@waku/core": "0.0.38",
|
||||
"@waku/discovery": "0.0.11",
|
||||
"@waku/interfaces": "0.0.33",
|
||||
"@waku/proto": "^0.0.13",
|
||||
"@waku/utils": "0.0.26",
|
||||
"libp2p": "2.8.11"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=22"
|
||||
}
|
||||
},
|
||||
"packages/browser-tests/node_modules/dotenv": {
|
||||
@ -34830,11 +34982,30 @@
|
||||
"@esbuild/win32-x64": "0.21.5"
|
||||
}
|
||||
},
|
||||
"packages/browser-tests/node_modules/js-sha3": {
|
||||
"version": "0.9.3",
|
||||
"resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.9.3.tgz",
|
||||
"integrity": "sha512-BcJPCQeLg6WjEx3FE591wVAevlli8lxsxm9/FzV4HXkV49TmBH38Yvrpce6fjbADGMKFrBMGTqrVz3qPIZ88Gg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"packages/browser-tests/node_modules/undici-types": {
|
||||
"version": "6.19.8",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"packages/browser-tests/node_modules/uuid": {
|
||||
"version": "9.0.1",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz",
|
||||
"integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==",
|
||||
"funding": [
|
||||
"https://github.com/sponsors/broofa",
|
||||
"https://github.com/sponsors/ctavan"
|
||||
],
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"uuid": "dist/bin/uuid"
|
||||
}
|
||||
},
|
||||
"packages/build-utils": {
|
||||
"name": "@waku/build-utils",
|
||||
"version": "1.0.0",
|
||||
|
||||
@ -21,6 +21,7 @@
|
||||
"@waku/discovery": "^0.0.11",
|
||||
"@waku/interfaces": "^0.0.33",
|
||||
"@waku/sdk": "^0.0.34",
|
||||
"@waku/utils": "0.0.27",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv-flow": "^0.4.0",
|
||||
"express": "^4.21.2",
|
||||
|
||||
@ -1,10 +1,13 @@
|
||||
import { defineConfig, devices } from "@playwright/test";
|
||||
import { Logger } from "@waku/utils";
|
||||
|
||||
const log = new Logger("playwright-config");
|
||||
|
||||
if (!process.env.CI) {
|
||||
try {
|
||||
await import("dotenv-flow/config.js");
|
||||
} catch (e) {
|
||||
console.warn("dotenv-flow not found; skipping env loading");
|
||||
log.warn("dotenv-flow not found; skipping env loading");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,7 @@
|
||||
import { Browser, chromium, Page } from "@playwright/test";
|
||||
import { Logger } from "@waku/utils";
|
||||
|
||||
const log = new Logger("browser");
|
||||
|
||||
let browser: Browser | undefined;
|
||||
let page: Page | undefined;
|
||||
@ -22,11 +25,11 @@ export async function initBrowser(appPort: number): Promise<void> {
|
||||
page.on('console', msg => {
|
||||
const type = msg.type();
|
||||
const text = msg.text();
|
||||
console.log(`[Browser Console ${type.toUpperCase()}] ${text}`);
|
||||
log.info(`[Browser Console ${type.toUpperCase()}] ${text}`);
|
||||
});
|
||||
|
||||
page.on('pageerror', error => {
|
||||
console.error('[Browser Page Error]', error.message);
|
||||
log.error('[Browser Page Error]', error.message);
|
||||
});
|
||||
|
||||
await page.goto(`http://localhost:${appPort}/app/index.html`, {
|
||||
@ -40,9 +43,9 @@ export async function initBrowser(appPort: number): Promise<void> {
|
||||
{ timeout: 30000 }
|
||||
);
|
||||
|
||||
console.log("Browser initialized successfully with wakuApi");
|
||||
log.info("Browser initialized successfully with wakuApi");
|
||||
} catch (error) {
|
||||
console.error("Error initializing browser:", error);
|
||||
log.error("Error initializing browser:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
import { Router } from "express";
|
||||
import { Logger } from "@waku/utils";
|
||||
import {
|
||||
createEndpointHandler,
|
||||
validators,
|
||||
errorHandlers,
|
||||
} from "../utils/endpoint-handler.js";
|
||||
|
||||
const log = new Logger("routes:waku");
|
||||
const router = Router();
|
||||
|
||||
const corsEndpoints = [
|
||||
@ -58,7 +60,7 @@ router.post(
|
||||
handleError: errorHandlers.lightpushError,
|
||||
transformResult: (result) => {
|
||||
if (result && result.successes && result.successes.length > 0) {
|
||||
console.log("[Server] Message successfully sent via v3 lightpush!");
|
||||
log.info("[Server] Message successfully sent via v3 lightpush!");
|
||||
return {
|
||||
success: true,
|
||||
result,
|
||||
|
||||
@ -3,11 +3,13 @@ import * as path from "path";
|
||||
|
||||
import cors from "cors";
|
||||
import express, { Request, Response } from "express";
|
||||
import { Logger } from "@waku/utils";
|
||||
|
||||
import wakuRouter from "./routes/waku.js";
|
||||
import { initBrowser, getPage, closeBrowser } from "./browser/index.js";
|
||||
import { DEFAULT_CLUSTER_ID, DEFAULT_NUM_SHARDS } from "@waku/interfaces";
|
||||
|
||||
const log = new Logger("server");
|
||||
const app = express();
|
||||
|
||||
app.use(cors());
|
||||
@ -31,13 +33,13 @@ app.get("/app/index.html", (_req: Request, res: Response) => {
|
||||
}
|
||||
if (process.env.WAKU_SHARD) {
|
||||
networkConfig.shards = [parseInt(process.env.WAKU_SHARD, 10)];
|
||||
console.log("Using static shard:", networkConfig.shards);
|
||||
log.info("Using static shard:", networkConfig.shards);
|
||||
}
|
||||
|
||||
const lightpushNode = process.env.WAKU_LIGHTPUSH_NODE || null;
|
||||
const enrBootstrap = process.env.WAKU_ENR_BOOTSTRAP || null;
|
||||
|
||||
console.log("Network config on server start, pre headless:", networkConfig);
|
||||
log.info("Network config on server start, pre headless:", networkConfig);
|
||||
|
||||
const configScript = ` <script>
|
||||
window.__WAKU_NETWORK_CONFIG = ${JSON.stringify(networkConfig)};
|
||||
@ -53,7 +55,7 @@ app.get("/app/index.html", (_req: Request, res: Response) => {
|
||||
res.setHeader("Content-Type", "text/html");
|
||||
res.send(htmlContent);
|
||||
} catch (error) {
|
||||
console.error("Error serving dynamic index.html:", error);
|
||||
log.error("Error serving dynamic index.html:", error);
|
||||
res.status(500).send("Error loading page");
|
||||
}
|
||||
});
|
||||
@ -70,22 +72,22 @@ async function startAPI(requestedPort: number): Promise<number> {
|
||||
|
||||
app
|
||||
.listen(requestedPort, () => {
|
||||
console.log(`API server running on http://localhost:${requestedPort}`);
|
||||
log.info(`API server running on http://localhost:${requestedPort}`);
|
||||
})
|
||||
.on("error", (error: any) => {
|
||||
if (error.code === "EADDRINUSE") {
|
||||
console.error(
|
||||
log.error(
|
||||
`Port ${requestedPort} is already in use. Please close the application using this port and try again.`,
|
||||
);
|
||||
} else {
|
||||
console.error("Error starting server:", error);
|
||||
log.error("Error starting server:", error);
|
||||
}
|
||||
throw error;
|
||||
});
|
||||
|
||||
return requestedPort;
|
||||
} catch (error: any) {
|
||||
console.error("Error starting server:", error);
|
||||
log.error("Error starting server:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@ -96,7 +98,7 @@ async function startServer(port: number = 3000): Promise<void> {
|
||||
await initBrowser(actualPort);
|
||||
|
||||
try {
|
||||
console.log("Auto-starting node with CLI configuration...");
|
||||
log.info("Auto-starting node with CLI configuration...");
|
||||
|
||||
const hasEnrBootstrap = Boolean(process.env.WAKU_ENR_BOOTSTRAP);
|
||||
const networkConfig: any = {
|
||||
@ -110,11 +112,11 @@ async function startServer(port: number = 3000): Promise<void> {
|
||||
}),
|
||||
};
|
||||
|
||||
// console.log(
|
||||
// log.info(
|
||||
// `Bootstrap mode: ${hasEnrBootstrap ? "ENR-only (defaultBootstrap=false)" : "default bootstrap (defaultBootstrap=true)"}`,
|
||||
// );
|
||||
if (hasEnrBootstrap) {
|
||||
console.log(`ENR bootstrap peers: ${process.env.WAKU_ENR_BOOTSTRAP}`);
|
||||
log.info(`ENR bootstrap peers: ${process.env.WAKU_ENR_BOOTSTRAP}`);
|
||||
}
|
||||
|
||||
networkConfig.networkConfig = {
|
||||
@ -131,7 +133,7 @@ async function startServer(port: number = 3000): Promise<void> {
|
||||
delete networkConfig.networkConfig.numShardsInCluster;
|
||||
}
|
||||
|
||||
console.log(
|
||||
log.info(
|
||||
`Network config: ${JSON.stringify(networkConfig.networkConfig)}`,
|
||||
);
|
||||
|
||||
@ -144,40 +146,40 @@ async function startServer(port: number = 3000): Promise<void> {
|
||||
await getPage()?.evaluate(() =>
|
||||
window.wakuApi.waitForPeers?.(5000, ["lightpush"] as any),
|
||||
);
|
||||
console.log("Auto-start completed with bootstrap peers");
|
||||
log.info("Auto-start completed with bootstrap peers");
|
||||
} catch (peerError) {
|
||||
console.log(
|
||||
log.info(
|
||||
"Auto-start completed (no bootstrap peers found - may be expected with test ENRs)",
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn("Auto-start failed:", e);
|
||||
log.warn("Auto-start failed:", e);
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error("Error starting server:", error);
|
||||
log.error("Error starting server:", error);
|
||||
}
|
||||
}
|
||||
|
||||
process.on("uncaughtException", (error) => {
|
||||
console.error("Uncaught Exception:", error);
|
||||
log.error("Uncaught Exception:", error);
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
process.on("unhandledRejection", (reason, promise) => {
|
||||
console.error("Unhandled Rejection at:", promise, "reason:", reason);
|
||||
log.error("Unhandled Rejection at:", promise, "reason:", reason);
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
const gracefulShutdown = async (signal: string) => {
|
||||
console.log(`Received ${signal}, gracefully shutting down...`);
|
||||
log.info(`Received ${signal}, gracefully shutting down...`);
|
||||
try {
|
||||
await closeBrowser();
|
||||
} catch (e) {
|
||||
console.warn("Error closing browser:", e);
|
||||
log.warn("Error closing browser:", e);
|
||||
}
|
||||
process.exit(0);
|
||||
};
|
||||
@ -194,13 +196,13 @@ function parseCliArgs() {
|
||||
if (arg.startsWith("--cluster-id=")) {
|
||||
clusterId = parseInt(arg.split("=")[1], 10);
|
||||
if (isNaN(clusterId)) {
|
||||
console.error("Invalid cluster-id value. Must be a number.");
|
||||
log.error("Invalid cluster-id value. Must be a number.");
|
||||
process.exit(1);
|
||||
}
|
||||
} else if (arg.startsWith("--shard=")) {
|
||||
shard = parseInt(arg.split("=")[1], 10);
|
||||
if (isNaN(shard)) {
|
||||
console.error("Invalid shard value. Must be a number.");
|
||||
log.error("Invalid shard value. Must be a number.");
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
@ -217,11 +219,11 @@ if (isMainModule) {
|
||||
|
||||
if (cliArgs.clusterId !== undefined) {
|
||||
process.env.WAKU_CLUSTER_ID = cliArgs.clusterId.toString();
|
||||
console.log(`Using CLI cluster ID: ${cliArgs.clusterId}`);
|
||||
log.info(`Using CLI cluster ID: ${cliArgs.clusterId}`);
|
||||
}
|
||||
if (cliArgs.shard !== undefined) {
|
||||
process.env.WAKU_SHARD = cliArgs.shard.toString();
|
||||
console.log(`Using CLI shard: ${cliArgs.shard}`);
|
||||
log.info(`Using CLI shard: ${cliArgs.shard}`);
|
||||
}
|
||||
|
||||
void startServer(port);
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
import { Request, Response } from "express";
|
||||
import { Logger } from "@waku/utils";
|
||||
import { getPage } from "../browser/index.js";
|
||||
import type { ITestBrowser } from "../../types/global.js";
|
||||
|
||||
const log = new Logger("endpoint-handler");
|
||||
|
||||
export interface LightpushV3Request {
|
||||
pubsubTopic: string;
|
||||
message: {
|
||||
@ -92,7 +95,7 @@ export function createEndpointHandler<TInput = any, TOutput = any>(
|
||||
);
|
||||
|
||||
if (config.logResult !== false) {
|
||||
console.log(
|
||||
log.info(
|
||||
`[${config.methodName}] Result:`,
|
||||
JSON.stringify(result, null, 2),
|
||||
);
|
||||
@ -112,7 +115,7 @@ export function createEndpointHandler<TInput = any, TOutput = any>(
|
||||
});
|
||||
}
|
||||
|
||||
console.error(`[${config.methodName}] Error:`, error);
|
||||
log.error(`[${config.methodName}] Error:`, error);
|
||||
res.status(500).json({
|
||||
code: 500,
|
||||
message: `Could not execute ${config.methodName}: ${error.message}`,
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
import axios from "axios";
|
||||
import { GenericContainer, StartedTestContainer } from "testcontainers";
|
||||
import { Logger } from "@waku/utils";
|
||||
|
||||
const log = new Logger("container-helpers");
|
||||
|
||||
export interface ContainerSetupOptions {
|
||||
environment?: Record<string, string>;
|
||||
@ -27,8 +30,8 @@ export async function startBrowserTestsContainer(
|
||||
maxAttempts = 60
|
||||
} = options;
|
||||
|
||||
console.log("Starting waku-browser-tests container...");
|
||||
|
||||
log.info("Starting waku-browser-tests container...");
|
||||
|
||||
let generic = new GenericContainer("waku-browser-tests:local")
|
||||
.withExposedPorts(8080)
|
||||
.withNetworkMode(networkMode);
|
||||
@ -44,7 +47,7 @@ export async function startBrowserTestsContainer(
|
||||
await new Promise((r) => setTimeout(r, 5000));
|
||||
const logs = await container.logs({ tail: 100 });
|
||||
logs.on("data", (b) => process.stdout.write("[container] " + b.toString()));
|
||||
logs.on("error", (err) => console.error("[container log error]", err));
|
||||
logs.on("error", (err) => log.error("[container log error]", err));
|
||||
|
||||
const mappedPort = container.getMappedPort(8080);
|
||||
const baseUrl = `http://127.0.0.1:${mappedPort}`;
|
||||
@ -57,7 +60,7 @@ export async function startBrowserTestsContainer(
|
||||
throw new Error("Container failed to become ready");
|
||||
}
|
||||
|
||||
console.log("✅ Browser tests container ready");
|
||||
log.info("✅ Browser tests container ready");
|
||||
await new Promise((r) => setTimeout(r, 500)); // Final settling time
|
||||
|
||||
return { container, baseUrl };
|
||||
@ -76,12 +79,12 @@ async function waitForServerReady(
|
||||
try {
|
||||
const res = await axios.get(`${baseUrl}/`, { timeout });
|
||||
if (res.status === 200) {
|
||||
console.log(`Server is ready after ${i + 1} attempts`);
|
||||
log.info(`Server is ready after ${i + 1} attempts`);
|
||||
return true;
|
||||
}
|
||||
} catch (error: any) {
|
||||
if (i % 10 === 0) {
|
||||
console.log(`Attempt ${i + 1}/${maxAttempts} failed:`, error.code || error.message);
|
||||
log.info(`Attempt ${i + 1}/${maxAttempts} failed:`, error.code || error.message);
|
||||
}
|
||||
}
|
||||
await new Promise((r) => setTimeout(r, 1000));
|
||||
@ -95,11 +98,11 @@ async function waitForServerReady(
|
||||
async function logFinalContainerState(container: StartedTestContainer): Promise<void> {
|
||||
try {
|
||||
const finalLogs = await container.logs({ tail: 50 });
|
||||
console.log("=== Final Container Logs ===");
|
||||
finalLogs.on("data", (b) => console.log(b.toString()));
|
||||
log.info("=== Final Container Logs ===");
|
||||
finalLogs.on("data", (b) => log.info(b.toString()));
|
||||
await new Promise((r) => setTimeout(r, 1000));
|
||||
} catch (logError) {
|
||||
console.error("Failed to get container logs:", logError);
|
||||
log.error("Failed to get container logs:", logError);
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,12 +112,12 @@ async function logFinalContainerState(container: StartedTestContainer): Promise<
|
||||
export async function stopContainer(container: StartedTestContainer): Promise<void> {
|
||||
if (!container) return;
|
||||
|
||||
console.log("Stopping container gracefully...");
|
||||
log.info("Stopping container gracefully...");
|
||||
try {
|
||||
await container.stop({ timeout: 10000 });
|
||||
console.log("Container stopped successfully");
|
||||
log.info("Container stopped successfully");
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
log.warn(
|
||||
"Container stop had issues (expected):",
|
||||
(error as any).message
|
||||
);
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
import { ServiceNode, ServiceNodesFleet } from "@waku/tests";
|
||||
import { DefaultTestRoutingInfo } from "@waku/tests";
|
||||
import { Logger } from "@waku/utils";
|
||||
|
||||
const log = new Logger("nwaku-helpers");
|
||||
|
||||
/**
|
||||
* Creates a two-node nwaku network following waku/tests patterns.
|
||||
@ -7,7 +10,7 @@ import { DefaultTestRoutingInfo } from "@waku/tests";
|
||||
* Node 2: Relay only (network peer)
|
||||
*/
|
||||
export async function createTwoNodeNetwork(): Promise<ServiceNodesFleet> {
|
||||
console.log("Creating nwaku node 1 (Relay + Light Push)...");
|
||||
log.info("Creating nwaku node 1 (Relay + Light Push)...");
|
||||
const lightPushNode = new ServiceNode("lightpush-node-" + Math.random().toString(36).substring(7));
|
||||
|
||||
const lightPushArgs = {
|
||||
@ -22,7 +25,7 @@ export async function createTwoNodeNetwork(): Promise<ServiceNodesFleet> {
|
||||
|
||||
await lightPushNode.start(lightPushArgs, { retries: 3 });
|
||||
|
||||
console.log("Creating nwaku node 2 (Relay only)...");
|
||||
log.info("Creating nwaku node 2 (Relay only)...");
|
||||
const relayNode = new ServiceNode("relay-node-" + Math.random().toString(36).substring(7));
|
||||
|
||||
// Connect second node to first node (following ServiceNodesFleet pattern)
|
||||
@ -41,7 +44,7 @@ export async function createTwoNodeNetwork(): Promise<ServiceNodesFleet> {
|
||||
await relayNode.start(relayArgs, { retries: 3 });
|
||||
|
||||
// Wait for network formation (following waku/tests timing patterns)
|
||||
console.log("Waiting for nwaku network formation...");
|
||||
log.info("Waiting for nwaku network formation...");
|
||||
await new Promise((r) => setTimeout(r, 5000));
|
||||
|
||||
// Verify connectivity (optional, for debugging)
|
||||
@ -63,16 +66,16 @@ async function verifyNetworkFormation(nodes: ServiceNode[]): Promise<void> {
|
||||
const peerCounts = await Promise.all(
|
||||
nodes.map(async (node, index) => {
|
||||
const peers = await node.peers();
|
||||
console.log(`Node ${index + 1} has ${peers.length} peer(s)`);
|
||||
log.info(`Node ${index + 1} has ${peers.length} peer(s)`);
|
||||
return peers.length;
|
||||
})
|
||||
);
|
||||
|
||||
if (peerCounts.every(count => count === 0)) {
|
||||
console.warn("⚠️ Nodes may not be properly connected yet");
|
||||
log.warn("⚠️ Nodes may not be properly connected yet");
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn("Could not verify peer connections:", error);
|
||||
log.warn("Could not verify peer connections:", error);
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,8 +106,8 @@ export async function getDockerAccessibleMultiaddr(node: ServiceNode): Promise<s
|
||||
// Build Docker network accessible multiaddr
|
||||
const dockerMultiaddr = `/ip4/${containerIp}/tcp/${port}/ws/p2p/${peerId}`;
|
||||
|
||||
console.log("Original multiaddr:", multiaddrStr);
|
||||
console.log("Docker accessible multiaddr:", dockerMultiaddr);
|
||||
log.info("Original multiaddr:", multiaddrStr);
|
||||
log.info("Docker accessible multiaddr:", dockerMultiaddr);
|
||||
|
||||
return dockerMultiaddr;
|
||||
}
|
||||
@ -115,11 +118,11 @@ export async function getDockerAccessibleMultiaddr(node: ServiceNode): Promise<s
|
||||
export async function stopNwakuNodes(nodes: ServiceNode[]): Promise<void> {
|
||||
if (!nodes || nodes.length === 0) return;
|
||||
|
||||
console.log("Stopping nwaku nodes...");
|
||||
log.info("Stopping nwaku nodes...");
|
||||
try {
|
||||
await Promise.all(nodes.map(node => node.stop()));
|
||||
console.log("Nwaku nodes stopped successfully");
|
||||
log.info("Nwaku nodes stopped successfully");
|
||||
} catch (error) {
|
||||
console.warn("Nwaku nodes stop had issues:", (error as any).message);
|
||||
log.warn("Nwaku nodes stop had issues:", (error as any).message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,7 +15,9 @@ import {
|
||||
import { bootstrap } from "@libp2p/bootstrap";
|
||||
import { EnrDecoder, TransportProtocol } from "@waku/enr";
|
||||
import type { ITestBrowser } from "../types/global.js";
|
||||
import { StaticShardingRoutingInfo } from "@waku/utils";
|
||||
import { Logger, StaticShardingRoutingInfo } from "@waku/utils";
|
||||
|
||||
const log = new Logger("waku-headless");
|
||||
|
||||
export interface SerializableSDKProtocolResult {
|
||||
successes: string[];
|
||||
@ -78,15 +80,15 @@ export class WakuHeadless {
|
||||
) {
|
||||
this.waku = null as unknown as LightNode;
|
||||
this.networkConfig = this.buildNetworkConfig(networkConfig);
|
||||
console.log("Network config on construction:", this.networkConfig);
|
||||
log.info("Network config on construction:", this.networkConfig);
|
||||
this.lightpushNode = lightpushNode || null;
|
||||
this.enrBootstrap = enrBootstrap || null;
|
||||
|
||||
if (this.lightpushNode) {
|
||||
console.log(`Configured preferred lightpush node: ${this.lightpushNode}`);
|
||||
log.info(`Configured preferred lightpush node: ${this.lightpushNode}`);
|
||||
}
|
||||
if (this.enrBootstrap) {
|
||||
console.log(`Configured ENR bootstrap: ${this.enrBootstrap}`);
|
||||
log.info(`Configured ENR bootstrap: ${this.enrBootstrap}`);
|
||||
}
|
||||
}
|
||||
|
||||
@ -126,7 +128,7 @@ export class WakuHeadless {
|
||||
Array.isArray(staticShards) &&
|
||||
staticShards.length > 0
|
||||
) {
|
||||
console.log("Using static sharding with shards:", staticShards);
|
||||
log.info("Using static sharding with shards:", staticShards);
|
||||
return {
|
||||
clusterId,
|
||||
} as StaticSharding;
|
||||
@ -134,7 +136,7 @@ export class WakuHeadless {
|
||||
|
||||
const numShardsInCluster =
|
||||
(providedConfig as any)?.numShardsInCluster ?? DEFAULT_NUM_SHARDS;
|
||||
console.log(
|
||||
log.info(
|
||||
"Using auto sharding with num shards in cluster:",
|
||||
numShardsInCluster,
|
||||
);
|
||||
@ -163,14 +165,14 @@ export class WakuHeadless {
|
||||
if (!this.waku) {
|
||||
throw new Error("Waku node not started");
|
||||
}
|
||||
console.log(
|
||||
log.info(
|
||||
"Pushing message via v3 lightpush:",
|
||||
contentTopic,
|
||||
payload,
|
||||
pubsubTopic,
|
||||
);
|
||||
console.log("Waku node:", this.waku);
|
||||
console.log("Network config:", this.networkConfig);
|
||||
log.info("Waku node:", this.waku);
|
||||
log.info("Network config:", this.networkConfig);
|
||||
|
||||
let processedPayload: Uint8Array;
|
||||
try {
|
||||
@ -204,12 +206,12 @@ export class WakuHeadless {
|
||||
contentTopic,
|
||||
shardId,
|
||||
});
|
||||
console.log("Encoder:", encoder);
|
||||
console.log("Pubsub topic:", pubsubTopic);
|
||||
console.log("Encoder pubsub topic:", encoder.pubsubTopic);
|
||||
log.info("Encoder:", encoder);
|
||||
log.info("Pubsub topic:", pubsubTopic);
|
||||
log.info("Encoder pubsub topic:", encoder.pubsubTopic);
|
||||
|
||||
if (pubsubTopic && pubsubTopic !== encoder.pubsubTopic) {
|
||||
console.warn(
|
||||
log.warn(
|
||||
`Explicit pubsubTopic ${pubsubTopic} provided, but auto-sharding determined ${encoder.pubsubTopic}. Using auto-sharding.`,
|
||||
);
|
||||
}
|
||||
@ -222,14 +224,14 @@ export class WakuHeadless {
|
||||
);
|
||||
if (preferredPeerId) {
|
||||
result = await this.send(lightPush, encoder, processedPayload);
|
||||
console.log("✅ Message sent via preferred lightpush node");
|
||||
log.info("✅ Message sent via preferred lightpush node");
|
||||
} else {
|
||||
throw new Error(
|
||||
"Could not extract peer ID from preferred node address",
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(
|
||||
log.error(
|
||||
"Couldn't send message via preferred lightpush node:",
|
||||
error,
|
||||
);
|
||||
@ -243,7 +245,7 @@ export class WakuHeadless {
|
||||
|
||||
return serializableResult;
|
||||
} catch (error) {
|
||||
console.error("Error sending message via v3 lightpush:", error);
|
||||
log.error("Error sending message via v3 lightpush:", error);
|
||||
throw new Error(
|
||||
`Failed to send v3 message: ${error instanceof Error ? error.message : String(error)}`,
|
||||
);
|
||||
@ -274,7 +276,7 @@ export class WakuHeadless {
|
||||
};
|
||||
} catch (error) {
|
||||
const elapsed = Date.now() - startTime;
|
||||
console.error(`Failed to find peers after ${elapsed}ms:`, error);
|
||||
log.error(`Failed to find peers after ${elapsed}ms:`, error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@ -285,12 +287,12 @@ export class WakuHeadless {
|
||||
await this.waku.stop();
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn("ignore previous waku stop error");
|
||||
log.warn("ignore previous waku stop error");
|
||||
}
|
||||
|
||||
// if (options.networkConfig) {
|
||||
// this.networkConfig = options.networkConfig;
|
||||
// console.log("Network config on createWakuNode:", this.networkConfig);
|
||||
// log.info("Network config on createWakuNode:", this.networkConfig);
|
||||
// }
|
||||
|
||||
let libp2pConfig: any = {
|
||||
@ -341,7 +343,7 @@ export class WakuHeadless {
|
||||
await this.waku.dial(this.lightpushNode);
|
||||
} catch {
|
||||
// Ignore dial errors
|
||||
console.warn(
|
||||
log.warn(
|
||||
"Failed to dial preferred lightpush node:",
|
||||
this.lightpushNode,
|
||||
);
|
||||
@ -380,7 +382,7 @@ export class WakuHeadless {
|
||||
|
||||
(() => {
|
||||
try {
|
||||
console.log("Initializing WakuHeadless...");
|
||||
log.info("Initializing WakuHeadless...");
|
||||
|
||||
const testWindow = window as ITestBrowser;
|
||||
const globalNetworkConfig = testWindow.__WAKU_NETWORK_CONFIG;
|
||||
@ -394,9 +396,9 @@ export class WakuHeadless {
|
||||
);
|
||||
|
||||
testWindow.wakuApi = instance;
|
||||
console.log("WakuHeadless initialized successfully:", !!testWindow.wakuApi);
|
||||
log.info("WakuHeadless initialized successfully:", !!testWindow.wakuApi);
|
||||
} catch (error) {
|
||||
console.error("Error initializing WakuHeadless:", error);
|
||||
log.error("Error initializing WakuHeadless:", error);
|
||||
const testWindow = window as ITestBrowser;
|
||||
testWindow.wakuApi = {
|
||||
start: () =>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user