chore: new eslint rules (#1416)

* add new eslint rules

* remove eslint scripts for build-utils

* refactor all files to fix breaking changes with new rules

* add a basic eslintrc for build-utils

* test

* fix more linting errors

* test

* update package.lock

* update stopping container

* update px node spec

* enable tests

* fix: conn manager events

* fix: peer exchange

* increase timeout on px test
This commit is contained in:
Danish Arora 2023-07-24 16:04:24 +05:30 committed by GitHub
parent d2f675d690
commit 376bcf2a0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 181 additions and 135 deletions

View File

@ -49,7 +49,10 @@
"error", "error",
{ "ignoreDeclarationSort": true, "ignoreCase": true } { "ignoreDeclarationSort": true, "ignoreCase": true }
], ],
"no-console": "error" "no-console": "error",
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/no-misused-promises": "error"
}, },
"overrides": [ "overrides": [
{ {

15
package-lock.json generated
View File

@ -33,6 +33,7 @@
"gh-pages": "^5.0.0", "gh-pages": "^5.0.0",
"husky": "^8.0.3", "husky": "^8.0.3",
"lint-staged": "^13.2.2", "lint-staged": "^13.2.2",
"prettier": "^2.8.8",
"size-limit": "^8.1.2", "size-limit": "^8.1.2",
"typedoc": "^0.23.26", "typedoc": "^0.23.26",
"typedoc-plugin-resolve-crossmodule-references": "^0.3.3" "typedoc-plugin-resolve-crossmodule-references": "^0.3.3"
@ -31044,8 +31045,6 @@
"@types/debug": "^4.1.7", "@types/debug": "^4.1.7",
"@types/mocha": "^10.0.1", "@types/mocha": "^10.0.1",
"@types/uuid": "^9.0.1", "@types/uuid": "^9.0.1",
"@typescript-eslint/eslint-plugin": "^5.57.0",
"@typescript-eslint/parser": "^5.59.8",
"@waku/build-utils": "*", "@waku/build-utils": "*",
"chai": "^4.3.7", "chai": "^4.3.7",
"cspell": "^6.31.1", "cspell": "^6.31.1",
@ -31387,8 +31386,6 @@
"@rollup/plugin-commonjs": "^24.0.1", "@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-json": "^6.0.0", "@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.0.2", "@rollup/plugin-node-resolve": "^15.0.2",
"@typescript-eslint/eslint-plugin": "^5.57.0",
"@typescript-eslint/parser": "^5.59.8",
"@waku/build-utils": "*", "@waku/build-utils": "*",
"cspell": "^6.31.1", "cspell": "^6.31.1",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
@ -31575,6 +31572,8 @@
"@types/dockerode": "^3.3.17", "@types/dockerode": "^3.3.17",
"@types/mocha": "^10.0.1", "@types/mocha": "^10.0.1",
"@types/tail": "^2.2.1", "@types/tail": "^2.2.1",
"@typescript-eslint/eslint-plugin": "^5.57.0",
"@typescript-eslint/parser": "^5.59.8",
"@waku/dns-discovery": "*", "@waku/dns-discovery": "*",
"@waku/message-encryption": "*", "@waku/message-encryption": "*",
"@waku/peer-exchange": "*", "@waku/peer-exchange": "*",
@ -37031,8 +37030,6 @@
"@types/debug": "^4.1.7", "@types/debug": "^4.1.7",
"@types/mocha": "^10.0.1", "@types/mocha": "^10.0.1",
"@types/uuid": "^9.0.1", "@types/uuid": "^9.0.1",
"@typescript-eslint/eslint-plugin": "^5.57.0",
"@typescript-eslint/parser": "^5.59.8",
"@waku/build-utils": "*", "@waku/build-utils": "*",
"@waku/interfaces": "0.0.15", "@waku/interfaces": "0.0.15",
"@waku/proto": "0.0.5", "@waku/proto": "0.0.5",
@ -37272,8 +37269,6 @@
"@rollup/plugin-commonjs": "^24.0.1", "@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-json": "^6.0.0", "@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.0.2", "@rollup/plugin-node-resolve": "^15.0.2",
"@typescript-eslint/eslint-plugin": "^5.57.0",
"@typescript-eslint/parser": "^5.59.8",
"@waku/build-utils": "*", "@waku/build-utils": "*",
"cspell": "^6.31.1", "cspell": "^6.31.1",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
@ -37413,6 +37408,8 @@
"@types/dockerode": "^3.3.17", "@types/dockerode": "^3.3.17",
"@types/mocha": "^10.0.1", "@types/mocha": "^10.0.1",
"@types/tail": "^2.2.1", "@types/tail": "^2.2.1",
"@typescript-eslint/eslint-plugin": "^5.57.0",
"@typescript-eslint/parser": "^5.59.8",
"@waku/core": "*", "@waku/core": "*",
"@waku/dns-discovery": "*", "@waku/dns-discovery": "*",
"@waku/enr": "*", "@waku/enr": "*",
@ -37431,7 +37428,7 @@
"p-timeout": "^6.1.0", "p-timeout": "^6.1.0",
"portfinder": "^1.0.32", "portfinder": "^1.0.32",
"prettier": "^2.8.8", "prettier": "^2.8.8",
"sinon": "*", "sinon": "^15.2.0",
"tail": "^2.2.6", "tail": "^2.2.6",
"typescript": "^5.0.4" "typescript": "^5.0.4"
} }

View File

@ -0,0 +1,24 @@
module.exports = {
root: true,
parserOptions: {
ecmaVersion: 2021,
sourceType: "module",
},
env: {
browser: true,
es2021: true,
node: true,
},
extends: ["eslint:recommended"],
rules: {
indent: ["error", 2],
"linebreak-style": ["error", "unix"],
quotes: ["error", "double"],
semi: ["error", "always"],
"no-unused-vars": [
"error",
{ vars: "all", args: "after-used", ignoreRestSiblings: false },
],
"no-console": "warn",
},
};

View File

@ -69,7 +69,9 @@ export class ConnectionManager {
// libp2p emits `peer:discovery` events during its initialization // libp2p emits `peer:discovery` events during its initialization
// which means that before the ConnectionManager is initialized, some peers may have been discovered // which means that before the ConnectionManager is initialized, some peers may have been discovered
// we will dial the peers in peerStore ONCE before we start to listen to the `peer:discovery` events within the ConnectionManager // we will dial the peers in peerStore ONCE before we start to listen to the `peer:discovery` events within the ConnectionManager
this.dialPeerStorePeers(); this.dialPeerStorePeers().catch((error) =>
log(`Unexpected error while dialing peer store peers`, error)
);
} }
private async dialPeerStorePeers(): Promise<void> { private async dialPeerStorePeers(): Promise<void> {
@ -177,7 +179,7 @@ export class ConnectionManager {
} }
} }
private async processDialQueue(): Promise<void> { private processDialQueue(): void {
if ( if (
this.pendingPeerDialQueue.length > 0 && this.pendingPeerDialQueue.length > 0 &&
this.currentActiveDialCount < this.options.maxParallelDials this.currentActiveDialCount < this.options.maxParallelDials
@ -237,37 +239,43 @@ export class ConnectionManager {
} }
private onEventHandlers = { private onEventHandlers = {
"peer:discovery": async (evt: CustomEvent<PeerInfo>): Promise<void> => { "peer:discovery": (evt: CustomEvent<PeerInfo>): void => {
const { id: peerId } = evt.detail; void (async () => {
const { id: peerId } = evt.detail;
this.attemptDial(peerId).catch((err) => try {
log(`Error dialing peer ${peerId.toString()} : ${err}`) await this.attemptDial(peerId);
); } catch (error) {
}, log(`Error dialing peer ${peerId.toString()} : ${error}`);
"peer:connect": async (evt: CustomEvent<Connection>): Promise<void> => {
const { remotePeer: peerId } = evt.detail;
this.keepAliveManager.start(
peerId,
this.libp2pComponents.ping.bind(this)
);
const isBootstrap = (await this.getTagNamesForPeer(peerId)).includes(
Tags.BOOTSTRAP
);
if (isBootstrap) {
const bootstrapConnections = this.libp2pComponents
.getConnections()
.filter((conn) => conn.tags.includes(Tags.BOOTSTRAP));
// If we have too many bootstrap connections, drop one
if (
bootstrapConnections.length > this.options.maxBootstrapPeersAllowed
) {
await this.dropConnection(peerId);
} }
} })();
},
"peer:connect": (evt: CustomEvent<Connection>): void => {
void (async () => {
const { remotePeer: peerId } = evt.detail;
this.keepAliveManager.start(
peerId,
this.libp2pComponents.ping.bind(this)
);
const isBootstrap = (await this.getTagNamesForPeer(peerId)).includes(
Tags.BOOTSTRAP
);
if (isBootstrap) {
const bootstrapConnections = this.libp2pComponents
.getConnections()
.filter((conn) => conn.tags.includes(Tags.BOOTSTRAP));
// If we have too many bootstrap connections, drop one
if (
bootstrapConnections.length > this.options.maxBootstrapPeersAllowed
) {
await this.dropConnection(peerId);
}
}
})();
}, },
"peer:disconnect": () => { "peer:disconnect": () => {
return (evt: CustomEvent<Connection>): void => { return (evt: CustomEvent<Connection>): void => {

View File

@ -200,7 +200,7 @@ class Filter extends BaseProtocol implements IFilter {
// We don't want to wait for decoding failure, just attempt to decode // We don't want to wait for decoding failure, just attempt to decode
// all messages and do the call back on the one that works // all messages and do the call back on the one that works
// noinspection ES6MissingAwait // noinspection ES6MissingAwait
decoders.forEach(async (dec: IDecoder<T>) => { for (const dec of decoders) {
if (didDecodeMsg) return; if (didDecodeMsg) return;
const decoded = await dec.fromProtoObj( const decoded = await dec.fromProtoObj(
pubSubTopic, pubSubTopic,
@ -208,13 +208,13 @@ class Filter extends BaseProtocol implements IFilter {
); );
if (!decoded) { if (!decoded) {
log("Not able to decode message"); log("Not able to decode message");
return; continue;
} }
// This is just to prevent more decoding attempt // This is just to prevent more decoding attempt
// TODO: Could be better if we were to abort promises // TODO: Could be better if we were to abort promises
didDecodeMsg = Boolean(decoded); didDecodeMsg = Boolean(decoded);
await callback(decoded); await callback(decoded);
}); }
} }
} }

View File

@ -312,7 +312,7 @@ class FilterV2 extends BaseProtocol implements IReceiver {
): Promise<Unsubscribe> { ): Promise<Unsubscribe> {
const subscription = await this.createSubscription(undefined, opts?.peerId); const subscription = await this.createSubscription(undefined, opts?.peerId);
subscription.subscribe(decoders, callback); await subscription.subscribe(decoders, callback);
const contentTopics = Array.from( const contentTopics = Array.from(
groupByContentTopic( groupByContentTopic(
@ -394,20 +394,19 @@ async function pushMessage<T extends IDecodedMessage>(
// We don't want to wait for decoding failure, just attempt to decode // We don't want to wait for decoding failure, just attempt to decode
// all messages and do the call back on the one that works // all messages and do the call back on the one that works
// noinspection ES6MissingAwait // noinspection ES6MissingAwait
decoders.forEach(async (dec: IDecoder<T>) => { for (const dec of decoders) {
if (didDecodeMsg) return; if (didDecodeMsg) break;
const decoded = await dec.fromProtoObj( const decoded = await dec.fromProtoObj(
pubSubTopic, pubSubTopic,
message as IProtoMessage message as IProtoMessage
); );
// const decoded = await dec.fromProtoObj(pubSubTopic, message);
if (!decoded) { if (!decoded) {
log("Not able to decode message"); log("Not able to decode message");
return; continue;
} }
// This is just to prevent more decoding attempt // This is just to prevent more decoding attempt
// TODO: Could be better if we were to abort promises // TODO: Could be better if we were to abort promises
didDecodeMsg = Boolean(decoded); didDecodeMsg = Boolean(decoded);
await callback(decoded); await callback(decoded);
}); }
} }

View File

@ -129,11 +129,11 @@ describe("ENR", function () {
} }
}); });
it("should throw error - no public key", () => { it("should throw error - no public key", async () => {
try { try {
const txt = const txt =
"enr:-IS4QJ2d11eu6dC7E7LoXeLMgMP3kom1u3SE8esFSWvaHoo0dP1jg8O3-nx9ht-EO3CmG7L6OkHcMmoIh00IYWB92QABgmlkgnY0gmlwhH8AAAGJc2d11eu6dCsxoQIB_c-jQMOXsbjWkbN-kj99H57gfId5pfb4wa1qxwV4CIN1ZHCCIyk"; "enr:-IS4QJ2d11eu6dC7E7LoXeLMgMP3kom1u3SE8esFSWvaHoo0dP1jg8O3-nx9ht-EO3CmG7L6OkHcMmoIh00IYWB92QABgmlkgnY0gmlwhH8AAAGJc2d11eu6dCsxoQIB_c-jQMOXsbjWkbN-kj99H57gfId5pfb4wa1qxwV4CIN1ZHCCIyk";
EnrDecoder.fromString(txt); await EnrDecoder.fromString(txt);
assert.fail("Expect error here"); assert.fail("Expect error here");
} catch (err: unknown) { } catch (err: unknown) {
const e = err as Error; const e = err as Error;
@ -306,7 +306,7 @@ describe("ENR", function () {
}); });
}); });
describe("Location multiaddr", async () => { describe("Location multiaddr", () => {
const ip4 = "127.0.0.1"; const ip4 = "127.0.0.1";
const ip6 = "::1"; const ip6 = "::1";
const tcp = 8080; const tcp = 8080;
@ -414,7 +414,7 @@ describe("ENR", function () {
}); });
}); });
describe("waku2 key round trip", async () => { describe("waku2 key round trip", () => {
let peerId; let peerId;
let enr: ENR; let enr: ENR;
let waku2Protocols: Waku2; let waku2Protocols: Waku2;

View File

@ -127,7 +127,7 @@ export async function encrypt(
): Promise<Uint8Array> { ): Promise<Uint8Array> {
const ephemPrivateKey = randomBytes(32); const ephemPrivateKey = randomBytes(32);
const sharedPx = await derive(ephemPrivateKey, publicKeyTo); const sharedPx = derive(ephemPrivateKey, publicKeyTo);
const hash = await kdf(sharedPx, 32); const hash = await kdf(sharedPx, 32);

View File

@ -148,7 +148,7 @@ class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
return; return;
} }
const res = await postCipher(payload); const res = postCipher(payload);
if (!res) { if (!res) {
log(`Failed to decode payload for contentTopic ${this.contentTopic}`); log(`Failed to decode payload for contentTopic ${this.contentTopic}`);

View File

@ -138,7 +138,7 @@ class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
return; return;
} }
const res = await postCipher(payload); const res = postCipher(payload);
if (!res) { if (!res) {
log(`Failed to decode payload for contentTopic ${this.contentTopic}`); log(`Failed to decode payload for contentTopic ${this.contentTopic}`);

View File

@ -63,9 +63,9 @@ export class PeerExchangeDiscovery
private queryingPeers: Set<string> = new Set(); private queryingPeers: Set<string> = new Set();
private queryAttempts: Map<string, number> = new Map(); private queryAttempts: Map<string, number> = new Map();
private readonly eventHandler = async ( private readonly eventHandler = (
event: CustomEvent<PeerProtocolsChangeData> event: CustomEvent<PeerProtocolsChangeData>
): Promise<void> => { ): void => {
const { protocols, peerId } = event.detail; const { protocols, peerId } = event.detail;
if ( if (
!protocols.includes(PeerExchangeCodec) || !protocols.includes(PeerExchangeCodec) ||
@ -143,9 +143,11 @@ export class PeerExchangeDiscovery
return; return;
} }
setTimeout(async () => { setTimeout(() => {
this.queryAttempts.set(peerIdStr, currentAttempt + 1); this.queryAttempts.set(peerIdStr, currentAttempt + 1);
await this.startRecurringQueries(peerId); this.startRecurringQueries(peerId).catch((error) => {
log(`Error in startRecurringQueries: ${error}`);
});
}, queryInterval * currentAttempt); }, queryInterval * currentAttempt);
}; };

View File

@ -193,18 +193,26 @@ class Relay implements IRelay {
return; return;
} }
await Promise.all( await Promise.all(
Array.from(observers).map(async ({ decoder, callback }) => { Array.from(observers).map(({ decoder, callback }) => {
const protoMsg = await decoder.fromWireToProtoObj(bytes); return (async () => {
if (!protoMsg) { try {
log("Internal error: message previously decoded failed on 2nd pass."); const protoMsg = await decoder.fromWireToProtoObj(bytes);
return; if (!protoMsg) {
} log(
const msg = await decoder.fromProtoObj(pubSubTopic, protoMsg); "Internal error: message previously decoded failed on 2nd pass."
if (msg) { );
callback(msg); return;
} else { }
log("Failed to decode messages on", topicOnlyMsg.contentTopic); const msg = await decoder.fromProtoObj(pubSubTopic, protoMsg);
} if (msg) {
await callback(msg);
} else {
log("Failed to decode messages on", topicOnlyMsg.contentTopic);
}
} catch (error) {
log("Error while decoding message:", error);
}
})();
}) })
); );
} }
@ -217,7 +225,7 @@ class Relay implements IRelay {
private gossipSubSubscribe(pubSubTopic: string): void { private gossipSubSubscribe(pubSubTopic: string): void {
this.gossipSub.addEventListener( this.gossipSub.addEventListener(
"gossipsub:message", "gossipsub:message",
async (event: CustomEvent<GossipsubMessage>) => { (event: CustomEvent<GossipsubMessage>) => {
if (event.detail.msg.topic !== pubSubTopic) return; if (event.detail.msg.topic !== pubSubTopic) return;
log(`Message received on ${pubSubTopic}`); log(`Message received on ${pubSubTopic}`);

View File

@ -170,7 +170,7 @@ export default class Dockerode {
await this.container.stop(); await this.container.stop();
await this.container.remove(); await this.container.remove();
this.containerId = undefined; delete this.containerId;
} }
private async confirmImageExistsOrPull(): Promise<void> { private async confirmImageExistsOrPull(): Promise<void> {

View File

@ -165,7 +165,8 @@ export class NimGoNode {
} }
public async stop(): Promise<void> { public async stop(): Promise<void> {
this.docker?.stop(); await this.docker?.container?.stop();
delete this.docker;
} }
async waitForLog(msg: string, timeout: number): Promise<void> { async waitForLog(msg: string, timeout: number): Promise<void> {

View File

@ -17,7 +17,7 @@ import { delay } from "../src/delay.js";
const maxQuantity = 3; const maxQuantity = 3;
describe("DNS Discovery: Compliance Test", async function () { describe("DNS Discovery: Compliance Test", function () {
this.timeout(10000); this.timeout(10000);
tests({ tests({
async setup() { async setup() {

View File

@ -57,8 +57,8 @@ describe("Waku Light Push [node only]", () => {
afterEach(async function () { afterEach(async function () {
try { try {
nwaku?.stop(); await nwaku?.stop();
waku?.stop(); await waku?.stop();
} catch (e) { } catch (e) {
console.error("Failed to stop nodes: ", e); console.error("Failed to stop nodes: ", e);
} }
@ -124,8 +124,8 @@ describe("Waku Light Push [node only] - custom pubsub topic", () => {
afterEach(async function () { afterEach(async function () {
try { try {
nwaku?.stop(); await nwaku?.stop();
waku?.stop(); await waku?.stop();
} catch (e) { } catch (e) {
console.error("Failed to stop nodes: ", e); console.error("Failed to stop nodes: ", e);
} }

View File

@ -19,49 +19,51 @@ import { makeLogFileName } from "../src/log_file.js";
import { NimGoNode } from "../src/node/node.js"; import { NimGoNode } from "../src/node/node.js";
describe("Peer Exchange", () => { describe("Peer Exchange", () => {
let waku: LightNode; describe("Auto Discovery", function () {
let waku: LightNode;
afterEach(async function () { afterEach(async function () {
!!waku && waku.stop().catch((e) => console.log("Waku failed to stop", e)); await waku?.stop();
});
it("Auto discovery", async function () {
// skipping in CI as this test demonstrates Peer Exchange working with the test fleet
// but not with locally run nwaku nodes
if (process.env.CI) {
this.skip();
}
this.timeout(50_000);
waku = await createLightNode({
libp2p: {
peerDiscovery: [
bootstrap({ list: getPredefinedBootstrapNodes(Fleet.Test, 3) }),
wakuPeerExchangeDiscovery(),
],
},
}); });
await waku.start(); it("connection with fleet nodes", async function () {
// skipping in CI as this test demonstrates Peer Exchange working with the test fleet
// but not with locally run nwaku nodes
if (process.env.CI) {
this.skip();
}
const foundPxPeer = await new Promise<boolean>((resolve) => { this.timeout(50_000);
const testNodes = getPredefinedBootstrapNodes(Fleet.Test, 3);
waku.libp2p.addEventListener("peer:discovery", (evt) => { waku = await createLightNode({
const { multiaddrs } = evt.detail; libp2p: {
multiaddrs.forEach((ma) => { peerDiscovery: [
const isBootstrapNode = testNodes.find((n) => n === ma.toString()); bootstrap({ list: getPredefinedBootstrapNodes(Fleet.Test, 3) }),
if (!isBootstrapNode) { wakuPeerExchangeDiscovery(),
resolve(true); ],
} },
});
await waku.start();
const foundPxPeer = await new Promise<boolean>((resolve) => {
const testNodes = getPredefinedBootstrapNodes(Fleet.Test, 3);
waku.libp2p.addEventListener("peer:discovery", (evt) => {
const { multiaddrs } = evt.detail;
multiaddrs.forEach((ma) => {
const isBootstrapNode = testNodes.find((n) => n === ma.toString());
if (!isBootstrapNode) {
resolve(true);
}
});
}); });
}); });
});
expect(foundPxPeer).to.be.true; expect(foundPxPeer).to.be.true;
});
}); });
describe("Locally run nodes", () => { describe("Locally Run Nodes", () => {
let waku: LightNode; let waku: LightNode;
let nwaku1: NimGoNode; let nwaku1: NimGoNode;
let nwaku2: NimGoNode; let nwaku2: NimGoNode;
@ -72,9 +74,10 @@ describe("Peer Exchange", () => {
}); });
afterEach(async function () { afterEach(async function () {
!!nwaku1 && nwaku1.stop(); this.timeout(10_000);
!!nwaku2 && nwaku2.stop(); await nwaku1?.stop();
!!waku && waku.stop().catch((e) => console.log("Waku failed to stop", e)); await nwaku2?.stop();
await waku?.stop();
}); });
it("nwaku interop", async function () { it("nwaku interop", async function () {
@ -146,7 +149,7 @@ describe("Peer Exchange", () => {
}); });
}); });
describe("compliance test", async function () { describe("Compliance Test", function () {
this.timeout(55_000); this.timeout(55_000);
let waku: LightNode; let waku: LightNode;
@ -201,9 +204,9 @@ describe("Peer Exchange", () => {
return new PeerExchangeDiscovery(components); return new PeerExchangeDiscovery(components);
}, },
teardown: async () => { teardown: async () => {
!!nwaku1 && (await nwaku1.stop()); await nwaku1?.stop();
!!nwaku2 && (await nwaku2.stop()); await nwaku2?.stop();
!!waku && (await waku.stop()); await waku?.stop();
}, },
}); });
}); });

View File

@ -121,7 +121,7 @@ describe("Waku Relay [node only]", () => {
const receivedMsgPromise: Promise<DecodedMessage> = new Promise( const receivedMsgPromise: Promise<DecodedMessage> = new Promise(
(resolve) => { (resolve) => {
waku2.relay.subscribe([TestDecoder], resolve); void waku2.relay.subscribe([TestDecoder], resolve);
} }
); );
@ -152,12 +152,12 @@ describe("Waku Relay [node only]", () => {
const barDecoder = createDecoder(barContentTopic); const barDecoder = createDecoder(barContentTopic);
const fooMessages: DecodedMessage[] = []; const fooMessages: DecodedMessage[] = [];
waku2.relay.subscribe([fooDecoder], (msg) => { void waku2.relay.subscribe([fooDecoder], (msg) => {
fooMessages.push(msg); fooMessages.push(msg);
}); });
const barMessages: DecodedMessage[] = []; const barMessages: DecodedMessage[] = [];
waku2.relay.subscribe([barDecoder], (msg) => { void waku2.relay.subscribe([barDecoder], (msg) => {
barMessages.push(msg); barMessages.push(msg);
}); });
@ -207,10 +207,10 @@ describe("Waku Relay [node only]", () => {
const symDecoder = createSymDecoder(symTopic, symKey); const symDecoder = createSymDecoder(symTopic, symKey);
const msgs: DecodedMessage[] = []; const msgs: DecodedMessage[] = [];
waku2.relay.subscribe([eciesDecoder], (wakuMsg) => { void waku2.relay.subscribe([eciesDecoder], (wakuMsg) => {
msgs.push(wakuMsg); msgs.push(wakuMsg);
}); });
waku2.relay.subscribe([symDecoder], (wakuMsg) => { void waku2.relay.subscribe([symDecoder], (wakuMsg) => {
msgs.push(wakuMsg); msgs.push(wakuMsg);
}); });
@ -313,7 +313,7 @@ describe("Waku Relay [node only]", () => {
const waku2ReceivedMsgPromise: Promise<DecodedMessage> = new Promise( const waku2ReceivedMsgPromise: Promise<DecodedMessage> = new Promise(
(resolve) => { (resolve) => {
waku2.relay.subscribe([TestDecoder], resolve); void waku2.relay.subscribe([TestDecoder], resolve);
} }
); );
@ -321,7 +321,7 @@ describe("Waku Relay [node only]", () => {
// pubsub topic. // pubsub topic.
const waku3NoMsgPromise: Promise<DecodedMessage> = new Promise( const waku3NoMsgPromise: Promise<DecodedMessage> = new Promise(
(resolve, reject) => { (resolve, reject) => {
waku3.relay.subscribe([TestDecoder], reject); void waku3.relay.subscribe([TestDecoder], reject);
setTimeout(resolve, 1000); setTimeout(resolve, 1000);
} }
); );
@ -369,7 +369,7 @@ describe("Waku Relay [node only]", () => {
const waku2ReceivedMsgPromise: Promise<DecodedMessage> = new Promise( const waku2ReceivedMsgPromise: Promise<DecodedMessage> = new Promise(
(resolve) => { (resolve) => {
waku2.relay.subscribe([TestDecoder], () => void waku2.relay.subscribe([TestDecoder], () =>
resolve({ resolve({
payload: new Uint8Array([]), payload: new Uint8Array([]),
} as DecodedMessage) } as DecodedMessage)
@ -463,7 +463,7 @@ describe("Waku Relay [node only]", () => {
const receivedMsgPromise: Promise<DecodedMessage> = new Promise( const receivedMsgPromise: Promise<DecodedMessage> = new Promise(
(resolve) => { (resolve) => {
waku.relay.subscribe<DecodedMessage>(TestDecoder, (msg) => void waku.relay.subscribe<DecodedMessage>(TestDecoder, (msg) =>
resolve(msg) resolve(msg)
); );
} }
@ -535,7 +535,7 @@ describe("Waku Relay [node only]", () => {
const waku2ReceivedMsgPromise: Promise<DecodedMessage> = new Promise( const waku2ReceivedMsgPromise: Promise<DecodedMessage> = new Promise(
(resolve) => { (resolve) => {
waku2.relay.subscribe(TestDecoder, resolve); void waku2.relay.subscribe(TestDecoder, resolve);
} }
); );

View File

@ -90,7 +90,8 @@ describe("Wait for remote peer", function () {
done(); done();
} }
); );
}); })
.catch((e) => done(e));
}); });
it("Store - dialed first", async function () { it("Store - dialed first", async function () {

View File

@ -63,7 +63,7 @@ describe("Waku Dial [node only]", function () {
let nwaku: NimGoNode; let nwaku: NimGoNode;
afterEach(async function () { afterEach(async function () {
!!nwaku && nwaku.stop(); !!nwaku && (await nwaku.stop());
!!waku && waku.stop().catch((e) => console.log("Waku failed to stop", e)); !!waku && waku.stop().catch((e) => console.log("Waku failed to stop", e));
}); });
@ -175,7 +175,7 @@ describe("Decryption Keys", () => {
const receivedMsgPromise: Promise<DecodedMessage> = new Promise( const receivedMsgPromise: Promise<DecodedMessage> = new Promise(
(resolve) => { (resolve) => {
waku2.relay.subscribe([decoder], resolve); void waku2.relay.subscribe([decoder], resolve);
} }
); );