mirror of https://github.com/waku-org/js-waku.git
feat: compliance test for peer-exchange discovery (#1186)
* skip fleet test for CI * add: compliance test * fix: check CI * fix: nwaku node name * remove: setTimeout * force typecasting instead of ts-ignore * rm: only for the test * increase readability
This commit is contained in:
parent
3059a652dc
commit
5b0c3c3cac
|
@ -6,7 +6,7 @@ import { symbol } from "@libp2p/interface-peer-discovery";
|
||||||
import type { PeerId } from "@libp2p/interface-peer-id";
|
import type { PeerId } from "@libp2p/interface-peer-id";
|
||||||
import type { PeerInfo } from "@libp2p/interface-peer-info";
|
import type { PeerInfo } from "@libp2p/interface-peer-info";
|
||||||
import type { PeerProtocolsChangeData } from "@libp2p/interface-peer-store";
|
import type { PeerProtocolsChangeData } from "@libp2p/interface-peer-store";
|
||||||
import { EventEmitter } from "@libp2p/interfaces/events";
|
import { CustomEvent, EventEmitter } from "@libp2p/interfaces/events";
|
||||||
import debug from "debug";
|
import debug from "debug";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
import { bootstrap } from "@libp2p/bootstrap";
|
import { bootstrap } from "@libp2p/bootstrap";
|
||||||
|
import tests from "@libp2p/interface-peer-discovery-compliance-tests";
|
||||||
import {
|
import {
|
||||||
Fleet,
|
Fleet,
|
||||||
getPredefinedBootstrapNodes,
|
getPredefinedBootstrapNodes,
|
||||||
} from "@waku/core/lib/predefined_bootstrap_nodes";
|
} from "@waku/core/lib/predefined_bootstrap_nodes";
|
||||||
import { createLightNode } from "@waku/create";
|
import { createLightNode, Libp2pComponents } from "@waku/create";
|
||||||
import { PeerInfo } from "@waku/interfaces";
|
import type { LightNode, PeerInfo } from "@waku/interfaces";
|
||||||
import type { LightNode } from "@waku/interfaces";
|
|
||||||
import {
|
import {
|
||||||
PeerExchangeCodec,
|
PeerExchangeCodec,
|
||||||
|
PeerExchangeDiscovery,
|
||||||
WakuPeerExchange,
|
WakuPeerExchange,
|
||||||
wakuPeerExchangeDiscovery,
|
wakuPeerExchangeDiscovery,
|
||||||
} from "@waku/peer-exchange";
|
} from "@waku/peer-exchange";
|
||||||
|
@ -108,13 +109,16 @@ describe("Peer Exchange", () => {
|
||||||
|
|
||||||
await nwaku2.waitForLog("Discovered px peers via discv5", 10);
|
await nwaku2.waitForLog("Discovered px peers via discv5", 10);
|
||||||
|
|
||||||
// the ts-ignores are added ref: https://github.com/libp2p/js-libp2p-interfaces/issues/338#issuecomment-1431643645
|
// the forced type casting is done in ref to https://github.com/libp2p/js-libp2p-interfaces/issues/338#issuecomment-1431643645
|
||||||
const peerExchange = new WakuPeerExchange({
|
const { connectionManager, registrar, peerStore } =
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
waku.libp2p as unknown as Libp2pComponents;
|
||||||
// @ts-ignore
|
const components = {
|
||||||
connectionManager: waku.libp2p.connectionManager,
|
connectionManager: connectionManager,
|
||||||
peerStore: waku.libp2p.peerStore,
|
registrar: registrar,
|
||||||
});
|
peerStore: peerStore,
|
||||||
|
};
|
||||||
|
|
||||||
|
const peerExchange = new WakuPeerExchange(components);
|
||||||
|
|
||||||
const numPeersToRequest = 1;
|
const numPeersToRequest = 1;
|
||||||
|
|
||||||
|
@ -138,4 +142,64 @@ describe("Peer Exchange", () => {
|
||||||
expect(waku.libp2p.peerStore.has(await nwaku2.getPeerId())).to.be.true;
|
expect(waku.libp2p.peerStore.has(await nwaku2.getPeerId())).to.be.true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("compliance test", async function () {
|
||||||
|
this.timeout(25_000);
|
||||||
|
|
||||||
|
let waku: LightNode;
|
||||||
|
let nwaku1: Nwaku;
|
||||||
|
let nwaku2: Nwaku;
|
||||||
|
|
||||||
|
beforeEach(async function () {
|
||||||
|
nwaku1 = new Nwaku(makeLogFileName(this) + "1");
|
||||||
|
nwaku2 = new Nwaku(makeLogFileName(this) + "2");
|
||||||
|
});
|
||||||
|
|
||||||
|
tests({
|
||||||
|
async setup() {
|
||||||
|
await nwaku1.start({
|
||||||
|
discv5Discovery: true,
|
||||||
|
peerExchange: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const enr = (await nwaku1.info()).enrUri;
|
||||||
|
|
||||||
|
await nwaku2.start({
|
||||||
|
discv5Discovery: true,
|
||||||
|
peerExchange: true,
|
||||||
|
discv5BootstrapNode: enr,
|
||||||
|
});
|
||||||
|
|
||||||
|
waku = await createLightNode();
|
||||||
|
|
||||||
|
await waku.start();
|
||||||
|
const nwaku2Ma = await nwaku2.getMultiaddrWithId();
|
||||||
|
|
||||||
|
await waku.libp2p.dialProtocol(nwaku2Ma, PeerExchangeCodec);
|
||||||
|
await new Promise<void>((resolve) => {
|
||||||
|
waku.libp2p.peerStore.addEventListener("change:protocols", (evt) => {
|
||||||
|
if (evt.detail.protocols.includes(PeerExchangeCodec)) {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// the forced type casting is done in ref to https://github.com/libp2p/js-libp2p-interfaces/issues/338#issuecomment-1431643645
|
||||||
|
const { connectionManager, registrar, peerStore } =
|
||||||
|
waku.libp2p as unknown as Libp2pComponents;
|
||||||
|
const components = {
|
||||||
|
connectionManager: connectionManager,
|
||||||
|
registrar: registrar,
|
||||||
|
peerStore: peerStore,
|
||||||
|
};
|
||||||
|
|
||||||
|
return new PeerExchangeDiscovery(components);
|
||||||
|
},
|
||||||
|
teardown: async () => {
|
||||||
|
!!nwaku1 && nwaku1.stop();
|
||||||
|
!!nwaku2 && nwaku2.stop();
|
||||||
|
!!waku && (await waku.stop());
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue