139 lines
3.9 KiB
TypeScript
Raw Normal View History

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/relay";
2022-05-04 20:07:21 +10:00
import { expect } from "chai";
import {
afterEachCustom,
DefaultTestClusterId,
DefaultTestContentTopic,
DefaultTestNetworkConfig,
DefaultTestNumShardsInCluster,
DefaultTestRoutingInfo,
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,
clusterId: DefaultTestClusterId,
numShardsInNetwork: DefaultTestNumShardsInCluster,
contentTopic: [DefaultTestContentTopic]
2022-05-04 20:07:21 +10:00
});
const multiAddrWithId = await nwaku.getMultiaddrWithId();
waku = await createRelayNode({
staticNoiseKey: NOISE_KEY_1,
networkConfig: DefaultTestNetworkConfig,
routingInfos: [DefaultTestRoutingInfo]
2022-05-04 20:07:21 +10:00
});
await waku.start();
2022-05-04 20:07:21 +10:00
await waku.dial(multiAddrWithId);
feat: replace `waitForRemotePeers()` with `waku.waitForPeer()` method (#2161) * fix comment of default number of peers * export default number of peers from base protocol sdk * rename to light_push, move class to separate file * move waitForRemotePeer to sdk package * add todo to move waitForGossipSubPeerInMesh into @waku/relay * clean up waitForRemotePeer, split metadata await from event and optimise, decouple from protocol implementations * simplify and rename ILightPush interface * use only connected peers in light push based on connections instead of peer renewal mechanism * improve readability of result processing in light push * fix check & update tests * address tests, add new test cases, fix racing condition in StreamManager * use libp2p.getPeers * feat: confirm metadata and protocols needed in waitForRemotePeer * rely on passed protocols and fallback to mounted * add I prefix to Waku interface * implement waku.connect method * add docs to IWaku interface * remove export and usage of waitForRemotePeer * move wait for remote peer related to Realy out of @waku/sdk * change tests to use new API * fix linting * update size limit * rename .connect to .waitForPeer * export waitForRemotePeer and mark as deprecated * feat: add mocha tests to @waku/sdk and cover waitForRemotePeer (#2163) * feat: add mocha tests to @waku/sdk and cover waitForRemotePeer * add waitForRemote UTs * remove junk * feat: expose peerId and protocols from WakuNode (#2166) * chore: expose peerId and protocols from WakuNode * remove unused method * move to private method * rename to waitForPeers * up test
2024-10-09 00:43:34 +02:00
await waku.waitForPeers([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,
clusterId: DefaultTestClusterId,
numShardsInNetwork: DefaultTestNumShardsInCluster,
contentTopic: [DefaultTestContentTopic]
2022-05-04 20:07:21 +10:00
});
const multiAddrWithId = await nwaku.getMultiaddrWithId();
waku = await createRelayNode({
staticNoiseKey: NOISE_KEY_1,
networkConfig: DefaultTestNetworkConfig,
routingInfos: [DefaultTestRoutingInfo]
2022-05-04 20:07:21 +10:00
});
await waku.start();
2022-05-04 20:07:21 +10:00
await waku.dial(multiAddrWithId);
feat: replace `waitForRemotePeers()` with `waku.waitForPeer()` method (#2161) * fix comment of default number of peers * export default number of peers from base protocol sdk * rename to light_push, move class to separate file * move waitForRemotePeer to sdk package * add todo to move waitForGossipSubPeerInMesh into @waku/relay * clean up waitForRemotePeer, split metadata await from event and optimise, decouple from protocol implementations * simplify and rename ILightPush interface * use only connected peers in light push based on connections instead of peer renewal mechanism * improve readability of result processing in light push * fix check & update tests * address tests, add new test cases, fix racing condition in StreamManager * use libp2p.getPeers * feat: confirm metadata and protocols needed in waitForRemotePeer * rely on passed protocols and fallback to mounted * add I prefix to Waku interface * implement waku.connect method * add docs to IWaku interface * remove export and usage of waitForRemotePeer * move wait for remote peer related to Realy out of @waku/sdk * change tests to use new API * fix linting * update size limit * rename .connect to .waitForPeer * export waitForRemotePeer and mark as deprecated * feat: add mocha tests to @waku/sdk and cover waitForRemotePeer (#2163) * feat: add mocha tests to @waku/sdk and cover waitForRemotePeer * add waitForRemote UTs * remove junk * feat: expose peerId and protocols from WakuNode (#2166) * chore: expose peerId and protocols from WakuNode * remove unused method * move to private method * rename to waitForPeers * up test
2024-10-09 00:43:34 +02:00
await waku.waitForPeers([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,
clusterId: DefaultTestClusterId,
numShardsInNetwork: DefaultTestNumShardsInCluster,
contentTopic: [DefaultTestContentTopic]
2022-05-04 20:07:21 +10:00
});
const multiAddrWithId = await nwaku.getMultiaddrWithId();
waku = await createRelayNode({
staticNoiseKey: NOISE_KEY_1,
networkConfig: DefaultTestNetworkConfig,
routingInfos: [DefaultTestRoutingInfo]
2022-05-04 20:07:21 +10:00
});
await waku.start();
2022-05-04 20:07:21 +10:00
await waku.dial(multiAddrWithId);
feat: replace `waitForRemotePeers()` with `waku.waitForPeer()` method (#2161) * fix comment of default number of peers * export default number of peers from base protocol sdk * rename to light_push, move class to separate file * move waitForRemotePeer to sdk package * add todo to move waitForGossipSubPeerInMesh into @waku/relay * clean up waitForRemotePeer, split metadata await from event and optimise, decouple from protocol implementations * simplify and rename ILightPush interface * use only connected peers in light push based on connections instead of peer renewal mechanism * improve readability of result processing in light push * fix check & update tests * address tests, add new test cases, fix racing condition in StreamManager * use libp2p.getPeers * feat: confirm metadata and protocols needed in waitForRemotePeer * rely on passed protocols and fallback to mounted * add I prefix to Waku interface * implement waku.connect method * add docs to IWaku interface * remove export and usage of waitForRemotePeer * move wait for remote peer related to Realy out of @waku/sdk * change tests to use new API * fix linting * update size limit * rename .connect to .waitForPeer * export waitForRemotePeer and mark as deprecated * feat: add mocha tests to @waku/sdk and cover waitForRemotePeer (#2163) * feat: add mocha tests to @waku/sdk and cover waitForRemotePeer * add waitForRemote UTs * remove junk * feat: expose peerId and protocols from WakuNode (#2166) * chore: expose peerId and protocols from WakuNode * remove unused method * move to private method * rename to waitForPeers * up test
2024-10-09 00:43:34 +02:00
await waku.waitForPeers([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
});
});
});