mirror of
https://github.com/logos-messaging/logos-delivery-js.git
synced 2026-03-11 12:13:13 +00:00
* 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
102 lines
2.7 KiB
TypeScript
102 lines
2.7 KiB
TypeScript
import type { PeerId } from "@libp2p/interface";
|
|
import type { PeerInfo } from "@libp2p/interface";
|
|
import { CustomEvent } from "@libp2p/interface";
|
|
import { multiaddr } from "@multiformats/multiaddr";
|
|
import type { Multiaddr } from "@multiformats/multiaddr";
|
|
import type { IWaku } from "@waku/interfaces";
|
|
import { createLightNode } from "@waku/sdk";
|
|
import { expect } from "chai";
|
|
import Sinon, { SinonSpy, SinonStub } from "sinon";
|
|
|
|
import {
|
|
afterEachCustom,
|
|
beforeEachCustom,
|
|
delay,
|
|
makeLogFileName,
|
|
ServiceNode,
|
|
tearDownNodes
|
|
} from "../src/index.js";
|
|
|
|
describe("multiaddr: dialing", function () {
|
|
let waku: IWaku;
|
|
let nwaku: ServiceNode;
|
|
let dialPeerSpy: SinonSpy;
|
|
let isPeerTopicConfigured: SinonStub;
|
|
|
|
afterEachCustom(this, async () => {
|
|
await tearDownNodes(nwaku, waku);
|
|
});
|
|
|
|
it("can dial TLS multiaddrs", async function () {
|
|
this.timeout(20_000);
|
|
|
|
let tlsWorks = true;
|
|
|
|
waku = await createLightNode();
|
|
await waku.start();
|
|
try {
|
|
// dummy multiaddr, doesn't have to be valid
|
|
await waku.dial(multiaddr(`/ip4/127.0.0.1/tcp/30303/tls/ws`));
|
|
} catch (error) {
|
|
if (error instanceof Error) {
|
|
// if the error is of tls unsupported, the test should fail
|
|
// for any other dial errors, the test should pass
|
|
if (error.message === "Unsupported protocol tls") {
|
|
tlsWorks = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
expect(tlsWorks).to.eq(true);
|
|
});
|
|
|
|
describe("does not attempt the same peer discovered multiple times more than once", function () {
|
|
const PEER_DISCOVERY_COUNT = 3;
|
|
let peerId: PeerId;
|
|
let multiaddr: Multiaddr;
|
|
|
|
beforeEachCustom(this, async () => {
|
|
nwaku = new ServiceNode(makeLogFileName(this.ctx));
|
|
await nwaku.start();
|
|
|
|
waku = await createLightNode();
|
|
|
|
peerId = await nwaku.getPeerId();
|
|
multiaddr = await nwaku.getMultiaddrWithId();
|
|
|
|
isPeerTopicConfigured = Sinon.stub(
|
|
waku.connectionManager as any,
|
|
"isPeerTopicConfigured"
|
|
);
|
|
isPeerTopicConfigured.resolves(true);
|
|
dialPeerSpy = Sinon.spy(waku.connectionManager as any, "dialPeer");
|
|
});
|
|
|
|
afterEachCustom(this, async () => {
|
|
dialPeerSpy.restore();
|
|
});
|
|
|
|
it("through manual discovery", async function () {
|
|
this.timeout(20_000);
|
|
|
|
const discoverPeer = (): void => {
|
|
waku.libp2p.dispatchEvent(
|
|
new CustomEvent<PeerInfo>("peer:discovery", {
|
|
detail: {
|
|
id: peerId,
|
|
multiaddrs: [multiaddr]
|
|
}
|
|
})
|
|
);
|
|
};
|
|
|
|
for (let i = 0; i < PEER_DISCOVERY_COUNT; i++) {
|
|
discoverPeer();
|
|
await delay(100);
|
|
}
|
|
|
|
expect(dialPeerSpy.callCount).to.eq(1);
|
|
});
|
|
});
|
|
});
|