From a5bd2cdcf600bb21d49f980372c9c53fbf15bcba Mon Sep 17 00:00:00 2001 From: danisharora099 Date: Thu, 6 Jun 2024 12:33:30 -0400 Subject: [PATCH] chore: update & fix test --- .../tests/peer-exchange/pe.optional.spec.ts | 82 ++++++++++--------- 1 file changed, 45 insertions(+), 37 deletions(-) diff --git a/packages/tests/tests/peer-exchange/pe.optional.spec.ts b/packages/tests/tests/peer-exchange/pe.optional.spec.ts index 4428b19398..ea65eddb15 100644 --- a/packages/tests/tests/peer-exchange/pe.optional.spec.ts +++ b/packages/tests/tests/peer-exchange/pe.optional.spec.ts @@ -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,58 @@ 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((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((resolve) => { + waku.libp2p.addEventListener("peer:discovery", (evt) => { + const peerId = evt.detail.id.toString(); + console.log({ peerId }); + const isBootstrapNode = predefinedNodes.find((n) => + n.includes(peerId) + ); + console.log({ isBootstrapNode }); + if (!isBootstrapNode) { + resolve(true); + } }); - - expect(foundPxPeer).to.be.true; }); + + expect(foundPxPeer).to.be.true; }); }); });