mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-08 00:33:12 +00:00
fix: replace magic values with constants
This commit is contained in:
parent
471d05467e
commit
ff730dbf2c
@ -5,6 +5,7 @@ import { dirname, join } from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
import {
|
||||
DEFAULT_CLUSTER_ID,
|
||||
DEFAULT_NODE1_WS_PORT,
|
||||
DEFAULT_NODE2_WS_PORT,
|
||||
NODE1_PEER_ID,
|
||||
@ -55,7 +56,7 @@ try {
|
||||
}
|
||||
|
||||
// Get cluster config from env or defaults
|
||||
const clusterId: string = process.env.CLUSTER_ID || "0";
|
||||
const clusterId: string = process.env.CLUSTER_ID || DEFAULT_CLUSTER_ID;
|
||||
const node1Port: string = process.env.NODE1_WS_PORT || DEFAULT_NODE1_WS_PORT;
|
||||
const node2Port: string = process.env.NODE2_WS_PORT || DEFAULT_NODE2_WS_PORT;
|
||||
|
||||
|
||||
@ -5,10 +5,14 @@ import { dirname, join } from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
import {
|
||||
DEFAULT_CLUSTER_ID,
|
||||
DEFAULT_NODE1_WS_PORT,
|
||||
DEFAULT_NODE2_WS_PORT,
|
||||
DEFAULT_NWAKU_IMAGE,
|
||||
NODE1_PEER_ID,
|
||||
NODE2_PEER_ID
|
||||
NODE2_PEER_ID,
|
||||
POSTGRES_IMAGE,
|
||||
STARTUP_WAIT_MS
|
||||
} from "../src/constants.js";
|
||||
import { getProjectName, printWakuConfig } from "../src/utils.js";
|
||||
|
||||
@ -38,8 +42,8 @@ const colors: Colors = {
|
||||
};
|
||||
|
||||
function checkAndPullImages(): void {
|
||||
const nwakuImage = process.env.NWAKU_IMAGE || "wakuorg/nwaku:v0.36.0";
|
||||
const postgresImage = "postgres:15.4-alpine3.18";
|
||||
const nwakuImage = process.env.NWAKU_IMAGE || DEFAULT_NWAKU_IMAGE;
|
||||
const postgresImage = POSTGRES_IMAGE;
|
||||
const images = [
|
||||
{ name: nwakuImage, label: "nwaku" },
|
||||
{ name: postgresImage, label: "postgres" }
|
||||
@ -113,10 +117,10 @@ try {
|
||||
});
|
||||
|
||||
// Wait for nodes to be ready
|
||||
await waitWithProgress(20000);
|
||||
await waitWithProgress(STARTUP_WAIT_MS);
|
||||
|
||||
// Get cluster config from env or defaults
|
||||
const clusterId: string = process.env.CLUSTER_ID || "0";
|
||||
const clusterId: string = process.env.CLUSTER_ID || DEFAULT_CLUSTER_ID;
|
||||
const node1Port: string = process.env.NODE1_WS_PORT || DEFAULT_NODE1_WS_PORT;
|
||||
const node2Port: string = process.env.NODE2_WS_PORT || DEFAULT_NODE2_WS_PORT;
|
||||
|
||||
|
||||
@ -27,3 +27,14 @@ 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";
|
||||
|
||||
// Docker images
|
||||
export const DEFAULT_NWAKU_IMAGE = "wakuorg/nwaku:v0.36.0";
|
||||
export const POSTGRES_IMAGE = "postgres:15.4-alpine3.18";
|
||||
|
||||
// Timing configuration
|
||||
export const STARTUP_WAIT_MS = 20000; // Time to wait for nodes to start
|
||||
|
||||
// Network configuration
|
||||
export const DEFAULT_CLUSTER_ID = "0";
|
||||
export const DEFAULT_NUM_SHARDS_IN_CLUSTER = 8;
|
||||
|
||||
@ -4,8 +4,10 @@ import { createLightNode } from "@waku/sdk";
|
||||
import { createRoutingInfo } from "@waku/utils";
|
||||
|
||||
import {
|
||||
DEFAULT_CLUSTER_ID,
|
||||
DEFAULT_NODE1_WS_PORT,
|
||||
DEFAULT_NODE2_WS_PORT,
|
||||
DEFAULT_NUM_SHARDS_IN_CLUSTER,
|
||||
NODE1_PEER_ID,
|
||||
NODE2_PEER_ID
|
||||
} from "./constants.js";
|
||||
@ -36,8 +38,9 @@ export class WakuTestClient {
|
||||
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,
|
||||
clusterId: options.clusterId ?? parseInt(DEFAULT_CLUSTER_ID),
|
||||
numShardsInCluster:
|
||||
options.numShardsInCluster ?? DEFAULT_NUM_SHARDS_IN_CLUSTER,
|
||||
contentTopic: options.contentTopic || "/waku-run/1/test/proto"
|
||||
};
|
||||
}
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
import { readFileSync } from "fs";
|
||||
import { join } from "path";
|
||||
|
||||
import { DEFAULT_NUM_SHARDS_IN_CLUSTER } from "./constants.js";
|
||||
|
||||
export function getProjectName(packageRoot: string): string {
|
||||
const packageJsonPath = join(packageRoot, "package.json");
|
||||
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
||||
@ -54,7 +56,7 @@ export function printWakuConfig(
|
||||
` clusterId: ${colors.cyan}${clusterId}${colors.reset},\n`
|
||||
);
|
||||
process.stdout.write(
|
||||
` numShardsInCluster: ${colors.cyan}8${colors.reset}\n`
|
||||
` numShardsInCluster: ${colors.cyan}${DEFAULT_NUM_SHARDS_IN_CLUSTER}${colors.reset}\n`
|
||||
);
|
||||
process.stdout.write(` }\n`);
|
||||
process.stdout.write(`});\n`);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user