Skip to content

Commit ff730db

Browse files
committed
fix: replace magic values with constants
1 parent 471d054 commit ff730db

File tree

5 files changed

+30
-9
lines changed

5 files changed

+30
-9
lines changed

packages/run/scripts/info.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { dirname, join } from "path";
55
import { fileURLToPath } from "url";
66

77
import {
8+
DEFAULT_CLUSTER_ID,
89
DEFAULT_NODE1_WS_PORT,
910
DEFAULT_NODE2_WS_PORT,
1011
NODE1_PEER_ID,
@@ -55,7 +56,7 @@ try {
5556
}
5657

5758
// Get cluster config from env or defaults
58-
const clusterId: string = process.env.CLUSTER_ID || "0";
59+
const clusterId: string = process.env.CLUSTER_ID || DEFAULT_CLUSTER_ID;
5960
const node1Port: string = process.env.NODE1_WS_PORT || DEFAULT_NODE1_WS_PORT;
6061
const node2Port: string = process.env.NODE2_WS_PORT || DEFAULT_NODE2_WS_PORT;
6162

packages/run/scripts/start.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ import { dirname, join } from "path";
55
import { fileURLToPath } from "url";
66

77
import {
8+
DEFAULT_CLUSTER_ID,
89
DEFAULT_NODE1_WS_PORT,
910
DEFAULT_NODE2_WS_PORT,
11+
DEFAULT_NWAKU_IMAGE,
1012
NODE1_PEER_ID,
11-
NODE2_PEER_ID
13+
NODE2_PEER_ID,
14+
POSTGRES_IMAGE,
15+
STARTUP_WAIT_MS
1216
} from "../src/constants.js";
1317
import { getProjectName, printWakuConfig } from "../src/utils.js";
1418

@@ -38,8 +42,8 @@ const colors: Colors = {
3842
};
3943

4044
function checkAndPullImages(): void {
41-
const nwakuImage = process.env.NWAKU_IMAGE || "wakuorg/nwaku:v0.36.0";
42-
const postgresImage = "postgres:15.4-alpine3.18";
45+
const nwakuImage = process.env.NWAKU_IMAGE || DEFAULT_NWAKU_IMAGE;
46+
const postgresImage = POSTGRES_IMAGE;
4347
const images = [
4448
{ name: nwakuImage, label: "nwaku" },
4549
{ name: postgresImage, label: "postgres" }
@@ -113,10 +117,10 @@ try {
113117
});
114118

115119
// Wait for nodes to be ready
116-
await waitWithProgress(20000);
120+
await waitWithProgress(STARTUP_WAIT_MS);
117121

118122
// Get cluster config from env or defaults
119-
const clusterId: string = process.env.CLUSTER_ID || "0";
123+
const clusterId: string = process.env.CLUSTER_ID || DEFAULT_CLUSTER_ID;
120124
const node1Port: string = process.env.NODE1_WS_PORT || DEFAULT_NODE1_WS_PORT;
121125
const node2Port: string = process.env.NODE2_WS_PORT || DEFAULT_NODE2_WS_PORT;
122126

packages/run/src/constants.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,14 @@ export const DEFAULT_NODE2_WS_PORT = "60001";
2727
// Default REST API ports for local nodes
2828
export const DEFAULT_NODE1_REST_PORT = "8646";
2929
export const DEFAULT_NODE2_REST_PORT = "8647";
30+
31+
// Docker images
32+
export const DEFAULT_NWAKU_IMAGE = "wakuorg/nwaku:v0.36.0";
33+
export const POSTGRES_IMAGE = "postgres:15.4-alpine3.18";
34+
35+
// Timing configuration
36+
export const STARTUP_WAIT_MS = 20000; // Time to wait for nodes to start
37+
38+
// Network configuration
39+
export const DEFAULT_CLUSTER_ID = "0";
40+
export const DEFAULT_NUM_SHARDS_IN_CLUSTER = 8;

packages/run/src/test-client.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import { createLightNode } from "@waku/sdk";
44
import { createRoutingInfo } from "@waku/utils";
55

66
import {
7+
DEFAULT_CLUSTER_ID,
78
DEFAULT_NODE1_WS_PORT,
89
DEFAULT_NODE2_WS_PORT,
10+
DEFAULT_NUM_SHARDS_IN_CLUSTER,
911
NODE1_PEER_ID,
1012
NODE2_PEER_ID
1113
} from "./constants.js";
@@ -36,8 +38,9 @@ export class WakuTestClient {
3638
options.node1Port || process.env.NODE1_WS_PORT || DEFAULT_NODE1_WS_PORT,
3739
node2Port:
3840
options.node2Port || process.env.NODE2_WS_PORT || DEFAULT_NODE2_WS_PORT,
39-
clusterId: options.clusterId ?? 0,
40-
numShardsInCluster: options.numShardsInCluster ?? 8,
41+
clusterId: options.clusterId ?? parseInt(DEFAULT_CLUSTER_ID),
42+
numShardsInCluster:
43+
options.numShardsInCluster ?? DEFAULT_NUM_SHARDS_IN_CLUSTER,
4144
contentTopic: options.contentTopic || "/waku-run/1/test/proto"
4245
};
4346
}

packages/run/src/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { readFileSync } from "fs";
22
import { join } from "path";
33

4+
import { DEFAULT_NUM_SHARDS_IN_CLUSTER } from "./constants.js";
5+
46
export function getProjectName(packageRoot: string): string {
57
const packageJsonPath = join(packageRoot, "package.json");
68
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
@@ -54,7 +56,7 @@ export function printWakuConfig(
5456
` clusterId: ${colors.cyan}${clusterId}${colors.reset},\n`
5557
);
5658
process.stdout.write(
57-
` numShardsInCluster: ${colors.cyan}8${colors.reset}\n`
59+
` numShardsInCluster: ${colors.cyan}${DEFAULT_NUM_SHARDS_IN_CLUSTER}${colors.reset}\n`
5860
);
5961
process.stdout.write(` }\n`);
6062
process.stdout.write(`});\n`);

0 commit comments

Comments
 (0)