mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-10 01:33:13 +00:00
88 lines
2.3 KiB
TypeScript
88 lines
2.3 KiB
TypeScript
import { bootstrap } from "@libp2p/bootstrap";
|
|
import { waitForRemotePeer } from "@waku/core";
|
|
import {
|
|
Fleet,
|
|
getPredefinedBootstrapNodes,
|
|
} from "@waku/core/lib/predefined_bootstrap_nodes";
|
|
import { createLightNode } from "@waku/create";
|
|
import type { LightNode, PeerExchangeResponse } from "@waku/interfaces";
|
|
import { Protocols } from "@waku/interfaces";
|
|
import { wakuPeerExchangeDiscovery } from "@waku/peer-exchange";
|
|
import { expect } from "chai";
|
|
|
|
import { delay } from "../src/delay.js";
|
|
|
|
describe("Peer Exchange", () => {
|
|
let waku: LightNode;
|
|
|
|
before(async function () {
|
|
// skipping in CI as this test demonstrates Peer Exchange working with the test fleet
|
|
// but not with locally run nwaku nodes
|
|
if (process.env.CI) {
|
|
this.skip();
|
|
}
|
|
});
|
|
|
|
afterEach(async function () {
|
|
!!waku && waku.stop().catch((e) => console.log("Waku failed to stop", e));
|
|
});
|
|
|
|
it("Auto discovery", async function () {
|
|
this.timeout(60_000);
|
|
|
|
waku = await createLightNode({
|
|
libp2p: {
|
|
peerDiscovery: [
|
|
bootstrap({ list: getPredefinedBootstrapNodes(Fleet.Test) }),
|
|
wakuPeerExchangeDiscovery(),
|
|
],
|
|
},
|
|
});
|
|
|
|
await waku.start();
|
|
// we want to ensure that there is enough time for discv5 to discover peers
|
|
await delay(40000);
|
|
|
|
await waitForRemotePeer(waku, [Protocols.PeerExchange]);
|
|
const pxPeers = await waku.peerExchange.peers();
|
|
expect(pxPeers.length).to.be.greaterThan(0);
|
|
});
|
|
|
|
it("Manual query on test fleet", async function () {
|
|
this.timeout(60_000);
|
|
|
|
const waku = await createLightNode({
|
|
libp2p: {
|
|
peerDiscovery: [
|
|
bootstrap({ list: getPredefinedBootstrapNodes(Fleet.Test) }),
|
|
],
|
|
},
|
|
});
|
|
|
|
await waku.start();
|
|
|
|
await waitForRemotePeer(waku, [Protocols.PeerExchange]);
|
|
|
|
let receivedCallback = false;
|
|
const numPeersToRequest = 3;
|
|
const callback = (response: PeerExchangeResponse): void => {
|
|
receivedCallback = true;
|
|
expect(response.peerInfos.length).to.be.greaterThan(0);
|
|
expect(response.peerInfos.length).to.be.lessThanOrEqual(
|
|
numPeersToRequest
|
|
);
|
|
|
|
expect(response.peerInfos[0].ENR).to.not.be.null;
|
|
};
|
|
|
|
await waku.peerExchange.query(
|
|
{
|
|
numPeers: numPeersToRequest,
|
|
},
|
|
callback
|
|
);
|
|
|
|
expect(receivedCallback).to.be.true;
|
|
});
|
|
});
|