fix: replace hardcoded WS/REST ports with constants/env vars

This commit is contained in:
Arseniy Klempner 2025-10-20 10:57:11 -07:00
parent 161d094c8c
commit b352825146
No known key found for this signature in database
GPG Key ID: 51653F18863BD24B
9 changed files with 63 additions and 29 deletions

View File

@ -4,13 +4,16 @@ import { execSync } from "child_process";
import { dirname, join } from "path";
import { fileURLToPath } from "url";
import { NODE1_PEER_ID, NODE2_PEER_ID } from "../src/constants.js";
import {
DEFAULT_NODE1_WS_PORT,
DEFAULT_NODE2_WS_PORT,
NODE1_PEER_ID,
NODE2_PEER_ID
} from "../src/constants.js";
import { getProjectName } from "../src/utils.js";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// In development: scripts are in packages/run/scripts
// In published package: scripts are in node_modules/@waku/run/dist/scripts
const packageRoot = __dirname.includes("dist")
? join(__dirname, "..", "..")
: join(__dirname, "..");
@ -53,8 +56,8 @@ try {
// Get cluster config from env or defaults
const clusterId: string = process.env.CLUSTER_ID || "0";
const node1Port: string = process.env.NODE1_WS_PORT || "60000";
const node2Port: string = process.env.NODE2_WS_PORT || "60001";
const node1Port: string = process.env.NODE1_WS_PORT || DEFAULT_NODE1_WS_PORT;
const node2Port: string = process.env.NODE2_WS_PORT || DEFAULT_NODE2_WS_PORT;
// Static peer IDs from --nodekey configuration
// cspell:ignore nodekey

View File

@ -8,8 +8,6 @@ import { getProjectName } from "../src/utils.js";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// In development: scripts are in packages/run/scripts
// In published package: scripts are in node_modules/@waku/run/dist/scripts
const packageRoot = __dirname.includes("dist")
? join(__dirname, "..", "..")
: join(__dirname, "..");

View File

@ -4,13 +4,16 @@ import { execSync } from "child_process";
import { dirname, join } from "path";
import { fileURLToPath } from "url";
import { NODE1_PEER_ID, NODE2_PEER_ID } from "../src/constants.js";
import {
DEFAULT_NODE1_WS_PORT,
DEFAULT_NODE2_WS_PORT,
NODE1_PEER_ID,
NODE2_PEER_ID
} from "../src/constants.js";
import { getProjectName } from "../src/utils.js";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// In development: scripts are in packages/run/scripts
// In published package: scripts are in node_modules/@waku/run/dist/scripts
const packageRoot = __dirname.includes("dist")
? join(__dirname, "..", "..")
: join(__dirname, "..");
@ -114,8 +117,8 @@ try {
// Get cluster config from env or defaults
const clusterId: string = process.env.CLUSTER_ID || "0";
const node1Port: string = process.env.NODE1_WS_PORT || "60000";
const node2Port: string = process.env.NODE2_WS_PORT || "60001";
const node1Port: string = process.env.NODE1_WS_PORT || DEFAULT_NODE1_WS_PORT;
const node2Port: string = process.env.NODE2_WS_PORT || DEFAULT_NODE2_WS_PORT;
// Static peer IDs from --nodekey configuration
// cspell:ignore nodekey

View File

@ -8,8 +8,6 @@ import { getProjectName } from "../src/utils.js";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// In development: scripts are in packages/run/scripts
// In published package: scripts are in node_modules/@waku/run/dist/scripts
const packageRoot = __dirname.includes("dist")
? join(__dirname, "..", "..")
: join(__dirname, "..");

View File

@ -11,8 +11,6 @@ import { getProjectName } from "../src/utils.js";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// In development: scripts are in packages/run/scripts
// In published package: scripts are in node_modules/@waku/run/dist/scripts
const packageRoot = __dirname.includes("dist")
? join(__dirname, "..", "..")
: join(__dirname, "..");

View File

@ -19,3 +19,11 @@ export const NODE2_PEER_ID =
// 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";
// Default WebSocket ports for local nodes
export const DEFAULT_NODE1_WS_PORT = "60000";
export const DEFAULT_NODE2_WS_PORT = "60001";
// Default REST API ports for local nodes
export const DEFAULT_NODE1_REST_PORT = "8646";
export const DEFAULT_NODE2_REST_PORT = "8647";

View File

@ -3,7 +3,12 @@ import type { LightNode } from "@waku/interfaces";
import { createLightNode } from "@waku/sdk";
import { createRoutingInfo } from "@waku/utils";
import { NODE1_PEER_ID, NODE2_PEER_ID } from "./constants.js";
import {
DEFAULT_NODE1_WS_PORT,
DEFAULT_NODE2_WS_PORT,
NODE1_PEER_ID,
NODE2_PEER_ID
} from "./constants.js";
export interface WakuTestClientOptions {
node1Port?: string;
@ -27,8 +32,10 @@ export class WakuTestClient {
public constructor(options: WakuTestClientOptions = {}) {
this.options = {
node1Port: options.node1Port || process.env.NODE1_WS_PORT || "60000",
node2Port: options.node2Port || process.env.NODE2_WS_PORT || "60001",
node1Port:
options.node1Port || process.env.NODE1_WS_PORT || DEFAULT_NODE1_WS_PORT,
node2Port:
options.node2Port || process.env.NODE2_WS_PORT || DEFAULT_NODE2_WS_PORT,
clusterId: options.clusterId ?? 0,
numShardsInCluster: options.numShardsInCluster ?? 8,
contentTopic: options.contentTopic || "/waku-run/1/test/proto"

View File

@ -5,6 +5,10 @@ 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";
@ -33,8 +37,12 @@ describe("Waku Run - Basic Test", function () {
for (let i = 0; i < maxRetries; i++) {
try {
await fetch("http://127.0.0.1:8646/debug/v1/info");
await fetch("http://127.0.0.1:8647/debug/v1/info");
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 {
@ -52,9 +60,9 @@ describe("Waku Run - Basic Test", function () {
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()
);
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;

View File

@ -4,7 +4,14 @@ 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 {
DEFAULT_NODE1_REST_PORT,
DEFAULT_NODE1_WS_PORT,
DEFAULT_NODE2_REST_PORT,
DEFAULT_NODE2_WS_PORT,
NODE1_PEER_ID,
NODE2_PEER_ID
} from "../src/constants.js";
import { getProjectName } from "../src/utils.js";
import { startTestServer, stopTestServer } from "./test-server.js";
@ -40,8 +47,12 @@ test.describe("Waku Run - Browser Test", () => {
for (let i = 0; i < maxRetries; i++) {
try {
await fetch("http://127.0.0.1:8646/debug/v1/info");
await fetch("http://127.0.0.1:8647/debug/v1/info");
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 {
@ -117,8 +128,8 @@ test.describe("Waku Run - Browser Test", () => {
test("should initialize Waku node in browser", async () => {
test.setTimeout(120000);
const node1Port = process.env.NODE1_WS_PORT || "60000";
const node2Port = process.env.NODE2_WS_PORT || "60001";
const node1Port = process.env.NODE1_WS_PORT || DEFAULT_NODE1_WS_PORT;
const node2Port = process.env.NODE2_WS_PORT || DEFAULT_NODE2_WS_PORT;
// Static peer IDs from --nodekey configuration
// cspell:ignore nodekey