mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-16 20:53:08 +00:00
* up lock * make ConnectionManager use ctor * reform connection manager configurations * remove log param from peerManager * make PeerManager use only ConnectionManager, move getPeers to ConnectionManager, remove not needed code * remove allPeers and connectedPeers from BaseProtocolCore, update tests, add getPeers for IWaku * use only one peerManager from Waku object * remove IBaseProtocolSDK and merge with PeerManager * re-implement peerManager, remove ProtocolUseOptions * remove not needed test, up lock * update deps and lock * remove old test for peerManager, fix check and spell * rename to getConnectedPeers * feat: improve filter subscriptions (#2193) * add message cache to Filter * remove WakuOptions and use only ProtocolCreateOptions * move subscribe options to createLightNode Fitler protocol options * rename SubscriptionManager to Subscription * rename to CreateNodeOptions * add warning * feat: introduce subscription manager (#2202) * feat: inroduce subscription manager * fix: make pipeline succeed (#2238) * fix test * use hardcoded value * update playwright * fix test:browser * up lock * make peer retrieval probabilistic * add comments * up lightpush tests * add tests for peer_manager, improve folder structure * create named files for protocols * create named files, simplify project structure * remove only
263 lines
7.1 KiB
TypeScript
263 lines
7.1 KiB
TypeScript
import type { LightNode, RelayNode } from "@waku/interfaces";
|
|
import { Protocols } from "@waku/interfaces";
|
|
import { createRelayNode } from "@waku/relay";
|
|
import { createLightNode } from "@waku/sdk";
|
|
import { expect } from "chai";
|
|
|
|
import {
|
|
afterEachCustom,
|
|
DefaultTestPubsubTopic,
|
|
DefaultTestShardInfo,
|
|
delay,
|
|
makeLogFileName,
|
|
NOISE_KEY_1,
|
|
ServiceNode,
|
|
tearDownNodes
|
|
} from "../src/index.js";
|
|
|
|
import {
|
|
runRelayNodes,
|
|
TestPubsubTopic,
|
|
TestShardInfo
|
|
} from "./relay/utils.js";
|
|
|
|
describe("Wait for remote peer", function () {
|
|
let waku1: RelayNode;
|
|
let waku2: LightNode;
|
|
let nwaku: ServiceNode;
|
|
|
|
afterEachCustom(this, async () => {
|
|
await tearDownNodes(nwaku, [waku1, waku2]);
|
|
});
|
|
|
|
it("Relay - dialed first", async function () {
|
|
this.timeout(20_000);
|
|
[nwaku, waku1] = await runRelayNodes(this, TestShardInfo);
|
|
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
|
|
|
const peers = waku1.relay.getMeshPeers(TestPubsubTopic);
|
|
const nimPeerId = multiAddrWithId.getPeerId();
|
|
|
|
expect(nimPeerId).to.not.be.undefined;
|
|
expect(peers).to.includes(nimPeerId);
|
|
});
|
|
|
|
it("Relay - dialed after", async function () {
|
|
this.timeout(20_000);
|
|
nwaku = new ServiceNode(makeLogFileName(this));
|
|
await nwaku.start({
|
|
relay: true,
|
|
store: false,
|
|
filter: false,
|
|
lightpush: false,
|
|
pubsubTopic: [DefaultTestPubsubTopic]
|
|
});
|
|
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
|
|
|
waku1 = await createRelayNode({
|
|
staticNoiseKey: NOISE_KEY_1,
|
|
networkConfig: DefaultTestShardInfo
|
|
});
|
|
await waku1.start();
|
|
|
|
const waitPromise = waku1.waitForPeers([Protocols.Relay]);
|
|
await delay(1000);
|
|
await waku1.dial(multiAddrWithId);
|
|
await waitPromise;
|
|
|
|
const peers = waku1.relay.getMeshPeers(DefaultTestPubsubTopic);
|
|
const nimPeerId = multiAddrWithId.getPeerId();
|
|
|
|
expect(nimPeerId).to.not.be.undefined;
|
|
expect(peers).includes(nimPeerId);
|
|
});
|
|
|
|
it("Relay - times out", function (done) {
|
|
this.timeout(5000);
|
|
createRelayNode({
|
|
staticNoiseKey: NOISE_KEY_1,
|
|
networkConfig: DefaultTestShardInfo
|
|
})
|
|
.then((waku1) => waku1.start().then(() => waku1))
|
|
.then((waku1) => {
|
|
waku1.waitForPeers([Protocols.Relay], 200).then(
|
|
() => {
|
|
throw "Promise expected to reject on time out";
|
|
},
|
|
(reason) => {
|
|
expect(reason?.message).to.eq(
|
|
"Timed out waiting for a remote peer."
|
|
);
|
|
done();
|
|
}
|
|
);
|
|
})
|
|
.catch((e) => done(e));
|
|
});
|
|
|
|
it("Store - dialed first", async function () {
|
|
this.timeout(20_000);
|
|
nwaku = new ServiceNode(makeLogFileName(this));
|
|
await nwaku.start({
|
|
store: true,
|
|
relay: false,
|
|
lightpush: false,
|
|
filter: false
|
|
});
|
|
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
|
|
|
waku2 = await createLightNode({
|
|
staticNoiseKey: NOISE_KEY_1,
|
|
networkConfig: DefaultTestShardInfo
|
|
});
|
|
await waku2.start();
|
|
await waku2.dial(multiAddrWithId);
|
|
await delay(1000);
|
|
await waku2.waitForPeers([Protocols.Store]);
|
|
|
|
const peers = (await waku2.getConnectedPeers()).map((peer) =>
|
|
peer.id.toString()
|
|
);
|
|
const nimPeerId = multiAddrWithId.getPeerId();
|
|
|
|
expect(nimPeerId).to.not.be.undefined;
|
|
expect(peers.includes(nimPeerId as string)).to.be.true;
|
|
});
|
|
|
|
it("Store - dialed after - with timeout", async function () {
|
|
this.timeout(20_000);
|
|
nwaku = new ServiceNode(makeLogFileName(this));
|
|
await nwaku.start({
|
|
store: true,
|
|
relay: false,
|
|
lightpush: false,
|
|
filter: false
|
|
});
|
|
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
|
|
|
waku2 = await createLightNode({
|
|
staticNoiseKey: NOISE_KEY_1,
|
|
networkConfig: DefaultTestShardInfo
|
|
});
|
|
await waku2.start();
|
|
const waitPromise = waku2.waitForPeers([Protocols.Store], 2000);
|
|
await delay(1000);
|
|
await waku2.dial(multiAddrWithId);
|
|
await waitPromise;
|
|
|
|
const peers = (await waku2.getConnectedPeers()).map((peer) =>
|
|
peer.id.toString()
|
|
);
|
|
|
|
const nimPeerId = multiAddrWithId.getPeerId();
|
|
|
|
expect(nimPeerId).to.not.be.undefined;
|
|
expect(peers.includes(nimPeerId as string)).to.be.true;
|
|
});
|
|
|
|
it("LightPush", async function () {
|
|
this.timeout(20_000);
|
|
nwaku = new ServiceNode(makeLogFileName(this));
|
|
await nwaku.start({
|
|
lightpush: true,
|
|
filter: false,
|
|
relay: false,
|
|
store: false
|
|
});
|
|
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
|
|
|
waku2 = await createLightNode({
|
|
staticNoiseKey: NOISE_KEY_1,
|
|
networkConfig: DefaultTestShardInfo
|
|
});
|
|
await waku2.start();
|
|
await waku2.dial(multiAddrWithId);
|
|
await waku2.waitForPeers([Protocols.LightPush]);
|
|
|
|
const peers = (await waku2.getConnectedPeers()).map((peer) =>
|
|
peer.id.toString()
|
|
);
|
|
|
|
const nimPeerId = multiAddrWithId.getPeerId();
|
|
|
|
expect(nimPeerId).to.not.be.undefined;
|
|
expect(peers.includes(nimPeerId as string)).to.be.true;
|
|
});
|
|
|
|
it("Filter", async function () {
|
|
this.timeout(20_000);
|
|
nwaku = new ServiceNode(makeLogFileName(this));
|
|
await nwaku.start({
|
|
filter: true,
|
|
lightpush: false,
|
|
relay: false,
|
|
store: false
|
|
});
|
|
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
|
|
|
waku2 = await createLightNode({
|
|
staticNoiseKey: NOISE_KEY_1,
|
|
networkConfig: DefaultTestShardInfo
|
|
});
|
|
await waku2.start();
|
|
await waku2.dial(multiAddrWithId);
|
|
await waku2.waitForPeers([Protocols.Filter]);
|
|
|
|
const peers = (await waku2.getConnectedPeers()).map((peer) =>
|
|
peer.id.toString()
|
|
);
|
|
|
|
const nimPeerId = multiAddrWithId.getPeerId();
|
|
|
|
expect(nimPeerId).to.not.be.undefined;
|
|
expect(peers.includes(nimPeerId as string)).to.be.true;
|
|
});
|
|
|
|
// TODO: re-enable store once https://github.com/waku-org/js-waku/issues/2162 is fixed
|
|
it("Light Node - default protocols", async function () {
|
|
this.timeout(20_000);
|
|
nwaku = new ServiceNode(makeLogFileName(this));
|
|
await nwaku.start({
|
|
filter: true,
|
|
lightpush: true,
|
|
relay: false
|
|
// store: true
|
|
});
|
|
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
|
|
|
waku2 = await createLightNode({
|
|
staticNoiseKey: NOISE_KEY_1,
|
|
networkConfig: DefaultTestShardInfo
|
|
});
|
|
await waku2.start();
|
|
await waku2.dial(multiAddrWithId);
|
|
await waku2.waitForPeers([
|
|
Protocols.Filter,
|
|
// Protocols.Store,
|
|
Protocols.LightPush
|
|
]);
|
|
|
|
const peers = (await waku2.getConnectedPeers()).map((peer) =>
|
|
peer.id.toString()
|
|
);
|
|
|
|
const nimPeerId = multiAddrWithId.getPeerId();
|
|
|
|
expect(nimPeerId).to.not.be.undefined;
|
|
expect(peers.includes(nimPeerId as string)).to.be.true;
|
|
});
|
|
|
|
it("Privacy Node - default protocol", async function () {
|
|
this.timeout(20_000);
|
|
[nwaku, waku1] = await runRelayNodes(this, TestShardInfo);
|
|
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
|
|
|
const peers = waku1.relay.getMeshPeers(TestPubsubTopic);
|
|
|
|
const nimPeerId = multiAddrWithId.getPeerId();
|
|
|
|
expect(nimPeerId).to.not.be.undefined;
|
|
expect(peers.includes(nimPeerId as string)).to.be.true;
|
|
});
|
|
});
|