mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-09 01:03:11 +00:00
* merge: master * fix: tests * update: interfafces * rm: comments * metadata: store peerIdStr instead of peerId * chore(utils): move fast-utils to dev deps * fix: allow autosharding nodes to get peers (#1785) * fix: merge * fix: build * fix: failing tests from master merge --------- Co-authored-by: Arseniy Klempner <arseniyk@status.im>
67 lines
1.9 KiB
TypeScript
67 lines
1.9 KiB
TypeScript
import { createEncoder, waitForRemotePeer } from "@waku/core";
|
|
import {
|
|
DefaultPubsubTopic,
|
|
LightNode,
|
|
Protocols,
|
|
ShardingParams
|
|
} from "@waku/interfaces";
|
|
import { createLightNode, utf8ToBytes } from "@waku/sdk";
|
|
import { Logger } from "@waku/utils";
|
|
|
|
import { makeLogFileName, NOISE_KEY_1, ServiceNode } from "../../src/index.js";
|
|
|
|
// Constants for test configuration.
|
|
export const log = new Logger("test:lightpush");
|
|
export const TestContentTopic = "/test/1/waku-light-push/utf8";
|
|
export const TestEncoder = createEncoder({ contentTopic: TestContentTopic });
|
|
export const messageText = "Light Push works!";
|
|
export const messagePayload = { payload: utf8ToBytes(messageText) };
|
|
|
|
export async function runNodes(
|
|
context: Mocha.Context,
|
|
pubsubTopics: string[],
|
|
shardInfo?: ShardingParams
|
|
): Promise<[ServiceNode, LightNode]> {
|
|
const nwaku = new ServiceNode(makeLogFileName(context));
|
|
await nwaku.start(
|
|
{
|
|
lightpush: true,
|
|
relay: true,
|
|
pubsubTopic: pubsubTopics,
|
|
...(shardInfo && { clusterId: shardInfo.clusterId })
|
|
},
|
|
{ retries: 3 }
|
|
);
|
|
|
|
let waku: LightNode | undefined;
|
|
try {
|
|
waku = await createLightNode({
|
|
...((pubsubTopics.length !== 1 ||
|
|
pubsubTopics[0] !== DefaultPubsubTopic) && {
|
|
shardInfo: shardInfo
|
|
}),
|
|
pubsubTopics: shardInfo ? undefined : pubsubTopics,
|
|
staticNoiseKey: NOISE_KEY_1
|
|
});
|
|
await waku.start();
|
|
} catch (error) {
|
|
log.error("jswaku node failed to start:", error);
|
|
}
|
|
|
|
if (waku) {
|
|
await waku.dial(await nwaku.getMultiaddrWithId());
|
|
await waitForRemotePeer(waku, [Protocols.LightPush]);
|
|
if (
|
|
shardInfo &&
|
|
"contentTopics" in shardInfo &&
|
|
shardInfo.contentTopics.length > 0
|
|
) {
|
|
await nwaku.ensureSubscriptionsAutosharding(shardInfo.contentTopics);
|
|
}
|
|
await nwaku.ensureSubscriptions(pubsubTopics);
|
|
return [nwaku, waku];
|
|
} else {
|
|
throw new Error("Failed to initialize waku");
|
|
}
|
|
}
|