121 lines
3.2 KiB
TypeScript
Raw Normal View History

import { waitForRemotePeer } from "@waku/core";
import { EnrDecoder } from "@waku/enr";
import type { RelayNode } from "@waku/interfaces";
2022-11-01 19:33:33 +11:00
import { Protocols } from "@waku/interfaces";
import { createRelayNode } from "@waku/sdk/relay";
2022-05-04 20:07:21 +10:00
import { expect } from "chai";
import {
afterEachCustom,
makeLogFileName,
NOISE_KEY_1,
ServiceNode,
tearDownNodes
} from "../src/index.js";
2022-05-04 20:07:21 +10:00
describe("ENR Interop: ServiceNode", function () {
let waku: RelayNode;
let nwaku: ServiceNode;
2022-05-04 20:07:21 +10:00
afterEachCustom(this, async () => {
await tearDownNodes(nwaku, waku);
2022-05-04 20:07:21 +10:00
});
it("Relay", async function () {
this.timeout(20_000);
nwaku = new ServiceNode(makeLogFileName(this));
2022-05-04 20:07:21 +10:00
await nwaku.start({
relay: true,
store: false,
filter: false,
lightpush: false
2022-05-04 20:07:21 +10:00
});
const multiAddrWithId = await nwaku.getMultiaddrWithId();
waku = await createRelayNode({
staticNoiseKey: NOISE_KEY_1
2022-05-04 20:07:21 +10:00
});
await waku.start();
2022-05-04 20:07:21 +10:00
await waku.dial(multiAddrWithId);
await waitForRemotePeer(waku, [Protocols.Relay]);
2022-05-04 20:07:21 +10:00
const nwakuInfo = await nwaku.info();
const nimPeerId = await nwaku.getPeerId();
expect(nwakuInfo.enrUri).to.not.be.undefined;
const dec = await EnrDecoder.fromString(nwakuInfo.enrUri ?? "");
expect(dec.peerId?.toString()).to.eq(nimPeerId.toString());
2022-05-04 20:07:21 +10:00
expect(dec.waku2).to.deep.eq({
relay: true,
store: false,
filter: false,
lightPush: false
2022-05-04 20:07:21 +10:00
});
});
it("Relay + Store", async function () {
this.timeout(20_000);
nwaku = new ServiceNode(makeLogFileName(this));
2022-05-04 20:07:21 +10:00
await nwaku.start({
relay: true,
store: true,
filter: false,
lightpush: false
2022-05-04 20:07:21 +10:00
});
const multiAddrWithId = await nwaku.getMultiaddrWithId();
waku = await createRelayNode({
staticNoiseKey: NOISE_KEY_1
2022-05-04 20:07:21 +10:00
});
await waku.start();
2022-05-04 20:07:21 +10:00
await waku.dial(multiAddrWithId);
await waitForRemotePeer(waku, [Protocols.Relay]);
2022-05-04 20:07:21 +10:00
const nwakuInfo = await nwaku.info();
const nimPeerId = await nwaku.getPeerId();
expect(nwakuInfo.enrUri).to.not.be.undefined;
const dec = await EnrDecoder.fromString(nwakuInfo.enrUri ?? "");
expect(dec.peerId?.toString()).to.eq(nimPeerId.toString());
2022-05-04 20:07:21 +10:00
expect(dec.waku2).to.deep.eq({
relay: true,
store: true,
filter: false,
lightPush: false
2022-05-04 20:07:21 +10:00
});
});
it("All", async function () {
this.timeout(20_000);
nwaku = new ServiceNode(makeLogFileName(this));
2022-05-04 20:07:21 +10:00
await nwaku.start({
relay: true,
store: true,
filter: true,
lightpush: true,
legacyFilter: true
2022-05-04 20:07:21 +10:00
});
const multiAddrWithId = await nwaku.getMultiaddrWithId();
waku = await createRelayNode({
staticNoiseKey: NOISE_KEY_1
2022-05-04 20:07:21 +10:00
});
await waku.start();
2022-05-04 20:07:21 +10:00
await waku.dial(multiAddrWithId);
await waitForRemotePeer(waku, [Protocols.Relay]);
2022-05-04 20:07:21 +10:00
const nwakuInfo = await nwaku.info();
const nimPeerId = await nwaku.getPeerId();
expect(nwakuInfo.enrUri).to.not.be.undefined;
const dec = await EnrDecoder.fromString(nwakuInfo.enrUri ?? "");
expect(dec.peerId?.toString()).to.eq(nimPeerId.toString());
2022-05-04 20:07:21 +10:00
expect(dec.waku2).to.deep.eq({
relay: true,
store: true,
filter: true,
lightPush: true
2022-05-04 20:07:21 +10:00
});
});
});