fix: remove use of any

This commit is contained in:
Arseniy Klempner 2025-10-03 19:56:07 -07:00
parent 49e8b719b8
commit 20f33ff450
No known key found for this signature in database
GPG Key ID: 51653F18863BD24B
5 changed files with 35 additions and 18 deletions

View File

@ -7,7 +7,7 @@ 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";
import { DEFAULT_CLUSTER_ID, DEFAULT_NUM_SHARDS, Protocols } from "@waku/interfaces";
const log = new Logger("server");
const app = express();
@ -144,7 +144,7 @@ async function startServer(port: number = 3000): Promise<void> {
try {
await getPage()?.evaluate(() =>
window.wakuApi.waitForPeers?.(5000, ["lightpush"] as any),
window.wakuApi.waitForPeers?.(5000, [Protocols.LightPush]),
);
log.info("Auto-start completed with bootstrap peers");
} catch (peerError) {

View File

@ -78,7 +78,8 @@ export function createEndpointHandler<TInput = any, TOutput = any>(
throw new Error("window.wakuApi is not available");
}
const method = (testWindow.wakuApi as any)[methodName];
const wakuApi = testWindow.wakuApi as unknown as Record<string, unknown>;
const method = wakuApi[methodName];
if (typeof method !== "function") {
throw new Error(`window.wakuApi.${methodName} is not a function`);
}

View File

@ -117,9 +117,10 @@ export async function stopContainer(container: StartedTestContainer): Promise<vo
await container.stop({ timeout: 10000 });
log.info("Container stopped successfully");
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
log.warn(
"Container stop had issues (expected):",
(error as any).message
message
);
}
}

View File

@ -51,10 +51,11 @@ export async function createTwoNodeNetwork(): Promise<ServiceNodesFleet> {
await verifyNetworkFormation([lightPushNode, relayNode]);
// Return ServiceNodesFleet-compatible object
// Note: We're returning a partial ServiceNodesFleet for testing purposes
return {
nodes: [lightPushNode, relayNode],
messageCollector: null as any // Not needed for these tests
} as any;
messageCollector: null
} as ServiceNodesFleet;
}
/**
@ -97,8 +98,10 @@ export async function getDockerAccessibleMultiaddr(node: ServiceNode): Promise<s
throw new Error("Could not extract port from multiaddr: " + multiaddrStr);
}
// Get Docker container IP (accessing private field safely)
const containerIp = (node as any).docker?.containerIp;
// Get Docker container IP (accessing internal field)
// Note: This accesses an internal implementation detail of ServiceNode
const nodeWithDocker = node as ServiceNode & { docker?: { containerIp?: string } };
const containerIp = nodeWithDocker.docker?.containerIp;
if (!containerIp) {
throw new Error("Could not get container IP from node");
}
@ -123,6 +126,7 @@ export async function stopNwakuNodes(nodes: ServiceNode[]): Promise<void> {
await Promise.all(nodes.map(node => node.stop()));
log.info("Nwaku nodes stopped successfully");
} catch (error) {
log.warn("Nwaku nodes stop had issues:", (error as any).message);
const message = error instanceof Error ? error.message : String(error);
log.warn("Nwaku nodes stop had issues:", message);
}
}

View File

@ -11,9 +11,11 @@ import {
DEFAULT_NUM_SHARDS,
ShardId,
StaticSharding,
ShardInfo,
} from "@waku/interfaces";
import { bootstrap } from "@libp2p/bootstrap";
import { EnrDecoder, TransportProtocol } from "@waku/enr";
import type { Multiaddr } from "@multiformats/multiaddr";
import type { ITestBrowser } from "../types/global.js";
import { Logger, StaticShardingRoutingInfo } from "@waku/utils";
@ -78,7 +80,7 @@ export class WakuHeadless {
lightpushNode?: string | null,
enrBootstrap?: string | null,
) {
this.waku = null as unknown as LightNode;
this.waku = null;
this.networkConfig = this.buildNetworkConfig(networkConfig);
log.info("Network config on construction:", this.networkConfig);
this.lightpushNode = lightpushNode || null;
@ -118,11 +120,11 @@ export class WakuHeadless {
}
private buildNetworkConfig(
providedConfig?: Partial<NetworkConfig>,
providedConfig?: Partial<NetworkConfig> | Partial<ShardInfo>,
): NetworkConfig {
const clusterId = providedConfig?.clusterId ?? DEFAULT_CLUSTER_ID;
const staticShards = (providedConfig as any)?.shards;
const staticShards = (providedConfig as Partial<ShardInfo>)?.shards;
if (
staticShards &&
Array.isArray(staticShards) &&
@ -135,7 +137,7 @@ export class WakuHeadless {
}
const numShardsInCluster =
(providedConfig as any)?.numShardsInCluster ?? DEFAULT_NUM_SHARDS;
(providedConfig as Partial<AutoSharding>)?.numShardsInCluster ?? DEFAULT_NUM_SHARDS;
log.info(
"Using auto sharding with num shards in cluster:",
numShardsInCluster,
@ -374,7 +376,7 @@ export class WakuHeadless {
const addrs = this.waku.libp2p.getMultiaddrs();
return {
peerId: this.waku.libp2p.peerId.toString(),
multiaddrs: addrs.map((a: any) => a.toString()),
multiaddrs: addrs.map((a: Multiaddr) => a.toString()),
peers: [],
};
}
@ -400,10 +402,19 @@ export class WakuHeadless {
} catch (error) {
log.error("Error initializing WakuHeadless:", error);
const testWindow = window as ITestBrowser;
// Create a stub wakuApi that will reject all method calls
testWindow.wakuApi = {
start: () =>
Promise.reject(new Error("WakuHeadless failed to initialize")),
error: error,
} as any;
waku: null,
networkConfig: { clusterId: 0, numShardsInCluster: 0 },
lightpushNode: null,
enrBootstrap: null,
error,
createWakuNode: () => Promise.reject(new Error("WakuHeadless failed to initialize")),
startNode: () => Promise.reject(new Error("WakuHeadless failed to initialize")),
stopNode: () => Promise.reject(new Error("WakuHeadless failed to initialize")),
pushMessageV3: () => Promise.reject(new Error("WakuHeadless failed to initialize")),
waitForPeers: () => Promise.reject(new Error("WakuHeadless failed to initialize")),
getPeerInfo: () => { throw new Error("WakuHeadless failed to initialize"); },
} as unknown as WakuHeadless;
}
})();