Skip to content

Commit

Permalink
fix: failing node_optional check (#2025)
Browse files Browse the repository at this point in the history
* chore: remove predefine nodes list

* remove import

* chore: update & fix test

* chore: remove console logs
  • Loading branch information
danisharora099 authored Jun 18, 2024
1 parent 16e9116 commit 984fb94
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 109 deletions.
4 changes: 0 additions & 4 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
68 changes: 0 additions & 68 deletions packages/core/src/lib/predefined_bootstrap_nodes.ts

This file was deleted.

80 changes: 43 additions & 37 deletions packages/tests/tests/peer-exchange/pe.optional.spec.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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
});
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();
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);
}
});
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;
});

expect(foundPxPeer).to.be.true;
});
});
});

0 comments on commit 984fb94

Please sign in to comment.