mirror of
https://github.com/waku-org/js-waku.git
synced 2025-01-26 20:30:07 +00:00
115 lines
3.2 KiB
TypeScript
115 lines
3.2 KiB
TypeScript
import { waitForRemotePeer } from "@waku/core/lib/wait_for_remote_peer";
|
|
import { createPrivacyNode } from "@waku/create";
|
|
import { ENR } from "@waku/enr";
|
|
import type { WakuPrivacy } from "@waku/interfaces";
|
|
import { Protocols } from "@waku/interfaces";
|
|
import { expect } from "chai";
|
|
|
|
import { makeLogFileName, NOISE_KEY_1, Nwaku } from "../src";
|
|
|
|
describe("ENR Interop: nwaku", function () {
|
|
let waku: WakuPrivacy;
|
|
let nwaku: Nwaku;
|
|
|
|
afterEach(async function () {
|
|
!!nwaku && nwaku.stop();
|
|
!!waku && waku.stop().catch((e) => console.log("Waku failed to stop", e));
|
|
});
|
|
|
|
it("Relay", async function () {
|
|
this.timeout(20_000);
|
|
nwaku = new Nwaku(makeLogFileName(this));
|
|
await nwaku.start({
|
|
relay: true,
|
|
store: false,
|
|
filter: false,
|
|
lightpush: false,
|
|
});
|
|
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
|
|
|
waku = await createPrivacyNode({
|
|
staticNoiseKey: NOISE_KEY_1,
|
|
});
|
|
await waku.start();
|
|
await waku.dial(multiAddrWithId);
|
|
await waitForRemotePeer(waku, [Protocols.Relay]);
|
|
|
|
const nwakuInfo = await nwaku.info();
|
|
const nimPeerId = await nwaku.getPeerId();
|
|
|
|
expect(nwakuInfo.enrUri).to.not.be.undefined;
|
|
const dec = await ENR.decodeTxt(nwakuInfo.enrUri ?? "");
|
|
expect(dec.peerId?.toString()).to.eq(nimPeerId.toString());
|
|
expect(dec.waku2).to.deep.eq({
|
|
relay: true,
|
|
store: false,
|
|
filter: false,
|
|
lightPush: false,
|
|
});
|
|
});
|
|
|
|
it("Relay + Store", async function () {
|
|
this.timeout(20_000);
|
|
nwaku = new Nwaku(makeLogFileName(this));
|
|
await nwaku.start({
|
|
relay: true,
|
|
store: true,
|
|
filter: false,
|
|
lightpush: false,
|
|
});
|
|
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
|
|
|
waku = await createPrivacyNode({
|
|
staticNoiseKey: NOISE_KEY_1,
|
|
});
|
|
await waku.start();
|
|
await waku.dial(multiAddrWithId);
|
|
await waitForRemotePeer(waku, [Protocols.Relay]);
|
|
|
|
const nwakuInfo = await nwaku.info();
|
|
const nimPeerId = await nwaku.getPeerId();
|
|
|
|
expect(nwakuInfo.enrUri).to.not.be.undefined;
|
|
const dec = await ENR.decodeTxt(nwakuInfo.enrUri ?? "");
|
|
expect(dec.peerId?.toString()).to.eq(nimPeerId.toString());
|
|
expect(dec.waku2).to.deep.eq({
|
|
relay: true,
|
|
store: true,
|
|
filter: false,
|
|
lightPush: false,
|
|
});
|
|
});
|
|
|
|
it("All", async function () {
|
|
this.timeout(20_000);
|
|
nwaku = new Nwaku(makeLogFileName(this));
|
|
await nwaku.start({
|
|
relay: true,
|
|
store: true,
|
|
filter: true,
|
|
lightpush: true,
|
|
});
|
|
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
|
|
|
waku = await createPrivacyNode({
|
|
staticNoiseKey: NOISE_KEY_1,
|
|
});
|
|
await waku.start();
|
|
await waku.dial(multiAddrWithId);
|
|
await waitForRemotePeer(waku, [Protocols.Relay]);
|
|
|
|
const nwakuInfo = await nwaku.info();
|
|
const nimPeerId = await nwaku.getPeerId();
|
|
|
|
expect(nwakuInfo.enrUri).to.not.be.undefined;
|
|
const dec = await ENR.decodeTxt(nwakuInfo.enrUri ?? "");
|
|
expect(dec.peerId?.toString()).to.eq(nimPeerId.toString());
|
|
expect(dec.waku2).to.deep.eq({
|
|
relay: true,
|
|
store: true,
|
|
filter: true,
|
|
lightPush: true,
|
|
});
|
|
});
|
|
});
|