mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-02 13:53:12 +00:00
fix: failing node_optional check (#2025)
* chore: remove predefine nodes list * remove import * chore: update & fix test * chore: remove console logs
This commit is contained in:
parent
16e9116c7c
commit
984fb94b5b
@ -9,10 +9,6 @@
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.js"
|
||||
},
|
||||
"./lib/predefined_bootstrap_nodes": {
|
||||
"types": "./dist/lib/predefined_bootstrap_nodes.d.ts",
|
||||
"import": "./dist/lib/predefined_bootstrap_nodes.js"
|
||||
},
|
||||
"./lib/message/version_0": {
|
||||
"types": "./dist/lib/message/version_0.d.ts",
|
||||
"import": "./dist/lib/message/version_0.js"
|
||||
|
||||
@ -1,68 +0,0 @@
|
||||
import { getPseudoRandomSubset } from "@waku/utils";
|
||||
|
||||
export const DefaultWantedNumber = 1;
|
||||
|
||||
export enum Fleet {
|
||||
Sandbox = "sandbox",
|
||||
Test = "test"
|
||||
}
|
||||
|
||||
/**
|
||||
* Return list of pre-defined (hardcoded) bootstrap nodes.
|
||||
*
|
||||
* Default behavior is to return nodes of the nwaku Status Sandbox fleet.
|
||||
*
|
||||
* @param fleet The fleet to be returned. Defaults to sandbox fleet.
|
||||
* @param wantedNumber The number of connections desired. Defaults to {@link DefaultWantedNumber}.
|
||||
*
|
||||
* @returns An array of multiaddresses.
|
||||
*/
|
||||
export function getPredefinedBootstrapNodes(
|
||||
fleet: Fleet = Fleet.Sandbox,
|
||||
wantedNumber: number = DefaultWantedNumber
|
||||
): string[] {
|
||||
if (wantedNumber <= 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
let nodes;
|
||||
switch (fleet) {
|
||||
case Fleet.Sandbox:
|
||||
nodes = fleets.fleets["waku.sandbox"]["waku-websocket"];
|
||||
break;
|
||||
case Fleet.Test:
|
||||
nodes = fleets.fleets["waku.test"]["waku-websocket"];
|
||||
break;
|
||||
default:
|
||||
nodes = fleets.fleets["waku.sandbox"]["waku-websocket"];
|
||||
}
|
||||
|
||||
nodes = Object.values(nodes) as string[];
|
||||
|
||||
return getPseudoRandomSubset(nodes, wantedNumber);
|
||||
}
|
||||
|
||||
export const fleets = {
|
||||
fleets: {
|
||||
"waku.sandbox": {
|
||||
"waku-websocket": {
|
||||
"node-01.ac-cn-hongkong-c.waku.sandbox":
|
||||
"/dns4/node-01.ac-cn-hongkong-c.waku.sandbox.status.im/tcp/8000/wss/p2p/16Uiu2HAmSJvSJphxRdbnigUV5bjRRZFBhTtWFTSyiKaQByCjwmpV",
|
||||
"node-01.do-ams3.waku.sandbox":
|
||||
"/dns4/node-01.do-ams3.waku.sandbox.status.im/tcp/8000/wss/p2p/16Uiu2HAmQSMNExfUYUqfuXWkD5DaNZnMYnigRxFKbk3tcEFQeQeE",
|
||||
"node-01.gc-us-central1-a.waku.sandbox":
|
||||
"/dns4/node-01.gc-us-central1-a.waku.sandbox.status.im/tcp/8000/wss/p2p/16Uiu2HAm6fyqE1jB5MonzvoMdU8v76bWV8ZeNpncDamY1MQXfjdB"
|
||||
}
|
||||
},
|
||||
"waku.test": {
|
||||
"waku-websocket": {
|
||||
"node-01.ac-cn-hongkong-c.waku.test":
|
||||
"/dns4/node-01.ac-cn-hongkong-c.waku.test.statusim.net/tcp/8000/wss/p2p/16Uiu2HAkzHaTP5JsUwfR9NR8Rj9HC24puS6ocaU8wze4QrXr9iXp",
|
||||
"node-01.do-ams3.waku.test":
|
||||
"/dns4/node-01.do-ams3.waku.test.statusim.net/tcp/8000/wss/p2p/16Uiu2HAkykgaECHswi3YKJ5dMLbq2kPVCo89fcyTd38UcQD6ej5W",
|
||||
"node-01.gc-us-central1-a.waku.test":
|
||||
"/dns4/node-01.gc-us-central1-a.waku.test.statusim.net/tcp/8000/wss/p2p/16Uiu2HAmDCp8XJ9z1ev18zuv8NHekAsjNyezAvmMfFEJkiharitG"
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -1,9 +1,9 @@
|
||||
import { bootstrap } from "@libp2p/bootstrap";
|
||||
import {
|
||||
Fleet,
|
||||
getPredefinedBootstrapNodes
|
||||
} from "@waku/core/lib/predefined_bootstrap_nodes";
|
||||
import { wakuPeerExchangeDiscovery } from "@waku/discovery";
|
||||
DnsNodeDiscovery,
|
||||
enrTree,
|
||||
wakuPeerExchangeDiscovery
|
||||
} from "@waku/discovery";
|
||||
import type { LightNode } from "@waku/interfaces";
|
||||
import { createLightNode } from "@waku/sdk";
|
||||
import {
|
||||
@ -17,50 +17,56 @@ import { afterEachCustom, tearDownNodes } from "../../src";
|
||||
describe("Peer Exchange", () => {
|
||||
describe("Auto Discovery", function () {
|
||||
let waku: LightNode;
|
||||
const predefinedNodes: string[] = [];
|
||||
|
||||
afterEachCustom(this, async () => {
|
||||
await tearDownNodes([], waku);
|
||||
});
|
||||
|
||||
const testCases: [Fleet, number][] = [
|
||||
[Fleet.Test, 2], // on test fleet there are only 3 peers
|
||||
[Fleet.Sandbox, 3]
|
||||
];
|
||||
it(`should discover peers other than used for bootstrapping`, async function () {
|
||||
this.timeout(50_000);
|
||||
|
||||
testCases.map(([name, nodes]) => {
|
||||
it(`should discover peers other than used for bootstrapping on ${name} fleet`, async function () {
|
||||
this.timeout(50_000);
|
||||
const predefinedNodes = getPredefinedBootstrapNodes(name, nodes);
|
||||
const dns = await DnsNodeDiscovery.dnsOverHttp();
|
||||
const dnsEnrs = await dns.getPeers(
|
||||
[enrTree["SANDBOX"], enrTree["TEST"]],
|
||||
{
|
||||
lightPush: 1
|
||||
}
|
||||
);
|
||||
const dnsPeerMultiaddrs = dnsEnrs
|
||||
.flatMap(
|
||||
(enr) => enr.peerInfo?.multiaddrs.map((ma) => ma.toString()) ?? []
|
||||
)
|
||||
.filter((ma) => ma.includes("wss"));
|
||||
|
||||
const singleShardInfo = { clusterId: 1, shard: 1 };
|
||||
const shardInfo = singleShardInfosToShardInfo([singleShardInfo]);
|
||||
const pubsubTopic = singleShardInfoToPubsubTopic(singleShardInfo);
|
||||
waku = await createLightNode({
|
||||
libp2p: {
|
||||
peerDiscovery: [
|
||||
bootstrap({ list: predefinedNodes }),
|
||||
wakuPeerExchangeDiscovery([pubsubTopic])
|
||||
]
|
||||
},
|
||||
shardInfo: shardInfo
|
||||
});
|
||||
|
||||
await waku.start();
|
||||
|
||||
const foundPxPeer = await new Promise<boolean>((resolve) => {
|
||||
waku.libp2p.addEventListener("peer:discovery", (evt) => {
|
||||
const peerId = evt.detail.id.toString();
|
||||
const isBootstrapNode = predefinedNodes.find((n) =>
|
||||
n.includes(peerId)
|
||||
);
|
||||
if (!isBootstrapNode) {
|
||||
resolve(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
expect(foundPxPeer).to.be.true;
|
||||
const singleShardInfo = { clusterId: 1, shard: 1 };
|
||||
const shardInfo = singleShardInfosToShardInfo([singleShardInfo]);
|
||||
const pubsubTopic = singleShardInfoToPubsubTopic(singleShardInfo);
|
||||
waku = await createLightNode({
|
||||
libp2p: {
|
||||
peerDiscovery: [
|
||||
bootstrap({ list: dnsPeerMultiaddrs }),
|
||||
wakuPeerExchangeDiscovery([pubsubTopic])
|
||||
]
|
||||
},
|
||||
shardInfo: shardInfo
|
||||
});
|
||||
|
||||
await waku.start();
|
||||
|
||||
const foundPxPeer = await new Promise<boolean>((resolve) => {
|
||||
waku.libp2p.addEventListener("peer:discovery", (evt) => {
|
||||
const peerId = evt.detail.id.toString();
|
||||
const isBootstrapNode = predefinedNodes.find((n) =>
|
||||
n.includes(peerId)
|
||||
);
|
||||
if (!isBootstrapNode) {
|
||||
resolve(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
expect(foundPxPeer).to.be.true;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user