Skip to content

Commit d2f675d

Browse files
feat: spec test for connection manager (#1417)
* add sinon * use new API for libp2p to attach event listener * add a test for event emitter/listening * add tests to check peer dials happen as expected for bootstrap peers * add tests for peer-exchange * remove only and run all tests * chore: rm extra packages * chore(deps): revert temp * chore(deps): revert temp * add sinon --------- Co-authored-by: jacques metevier <jmetevier@gmail.com>
1 parent 2ceac3b commit d2f675d

File tree

4 files changed

+431
-12
lines changed

4 files changed

+431
-12
lines changed

package-lock.json

+225-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/src/lib/connection_manager.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ export class ConnectionManager {
191191
}
192192

193193
private startPeerDiscoveryListener(): void {
194-
this.libp2pComponents.peerStore.addEventListener(
195-
"peer",
194+
this.libp2pComponents.addEventListener(
195+
"peer:discovery",
196196
this.onEventHandlers["peer:discovery"]
197197
);
198198
}
@@ -286,15 +286,15 @@ export class ConnectionManager {
286286

287287
if (isConnected) return false;
288288

289-
const isBootstrap = (await this.getTagNamesForPeer(peerId)).some(
290-
(tagName) => tagName === Tags.BOOTSTRAP
291-
);
289+
const tagNames = await this.getTagNamesForPeer(peerId);
290+
291+
const isBootstrap = tagNames.some((tagName) => tagName === Tags.BOOTSTRAP);
292292

293293
if (isBootstrap) {
294294
const currentBootstrapConnections = this.libp2pComponents
295295
.getConnections()
296296
.filter((conn) => {
297-
conn.tags.find((name) => name === Tags.BOOTSTRAP);
297+
return conn.tags.find((name) => name === Tags.BOOTSTRAP);
298298
}).length;
299299
if (currentBootstrapConnections < this.options.maxBootstrapPeersAllowed)
300300
return true;

0 commit comments

Comments
 (0)