From b38634fd143d570239c4b87fee90d36a14b114b6 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Tue, 13 Apr 2021 15:22:29 +1000 Subject: [PATCH] Remove warnings --- src/lib/waku_relay/index.spec.ts | 25 +++++++++++-------------- src/lib/waku_relay/index.ts | 4 ++-- src/lib/waku_relay/relay_heartbeat.ts | 6 +++--- src/test_utils/log_file.ts | 4 ++-- src/test_utils/nim_waku.ts | 5 ++++- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/lib/waku_relay/index.spec.ts b/src/lib/waku_relay/index.spec.ts index ac83e30dfb..2b27b16ed3 100644 --- a/src/lib/waku_relay/index.spec.ts +++ b/src/lib/waku_relay/index.spec.ts @@ -12,7 +12,7 @@ import { RelayCodec, RelayDefaultTopic } from './index'; describe('Waku Relay', () => { afterEach(function () { - if (this.currentTest!.state === 'failed') { + if (this.currentTest?.state === 'failed') { console.log(`Test failed, log file name is ${makeLogFileName(this)}`); } }); @@ -41,15 +41,13 @@ describe('Waku Relay', () => { await Promise.all([ new Promise((resolve) => - waku1.libp2p.pubsub.once( - 'pubsub:subscription-change', - (...args: any[]) => resolve(args) + waku1.libp2p.pubsub.once('pubsub:subscription-change', () => + resolve(null) ) ), new Promise((resolve) => - waku2.libp2p.pubsub.once( - 'pubsub:subscription-change', - (...args: any[]) => resolve(args) + waku2.libp2p.pubsub.once('pubsub:subscription-change', () => + resolve(null) ) ), ]); @@ -173,7 +171,7 @@ describe('Waku Relay', () => { this.timeout(10_000); waku = await Waku.create({ staticNoiseKey: NOISE_KEY_1 }); - nimWaku = new NimWaku(this.test!.ctx!.currentTest!.title); + nimWaku = new NimWaku(this.test?.ctx?.currentTest?.title + ''); await nimWaku.start(); await waku.dial(await nimWaku.getMultiaddrWithId()); @@ -252,7 +250,7 @@ describe('Waku Relay', () => { Waku.create({ staticNoiseKey: NOISE_KEY_2 }), ]); - nimWaku = new NimWaku(this.test!.ctx!.currentTest!.title); + nimWaku = new NimWaku(this.test?.ctx?.currentTest?.title + ''); await nimWaku.start(); const nimWakuMultiaddr = await nimWaku.getMultiaddrWithId(); @@ -315,10 +313,9 @@ describe('Waku Relay', () => { }); }); -function waitForNextData(pubsub: Pubsub): Promise { - return new Promise((resolve) => { +async function waitForNextData(pubsub: Pubsub): Promise { + const msg = (await new Promise((resolve) => { pubsub.once(RelayDefaultTopic, resolve); - }).then((msg: any) => { - return WakuMessage.decode(msg.data); - }); + })) as Pubsub.InMessage; + return WakuMessage.decode(msg.data); } diff --git a/src/lib/waku_relay/index.ts b/src/lib/waku_relay/index.ts index 286aa874f8..018ca5fe20 100644 --- a/src/lib/waku_relay/index.ts +++ b/src/lib/waku_relay/index.ts @@ -94,7 +94,7 @@ export class WakuRelayPubsub extends Gossipsub { ); this.mesh.set(topic, peers); } - this.mesh.get(topic)!.forEach((id) => { + this.mesh.get(topic)?.forEach((id) => { this.log('JOIN: Add mesh link to %s in %s', id, topic); this._sendGraft(id, topic); }); @@ -156,7 +156,7 @@ export class WakuRelayPubsub extends Gossipsub { this.lastpub.set(topic, this._now()); } - meshPeers!.forEach((peer) => { + meshPeers?.forEach((peer) => { toSend.add(peer); }); }); diff --git a/src/lib/waku_relay/relay_heartbeat.ts b/src/lib/waku_relay/relay_heartbeat.ts index 7d418e945e..0dc6995e54 100644 --- a/src/lib/waku_relay/relay_heartbeat.ts +++ b/src/lib/waku_relay/relay_heartbeat.ts @@ -23,7 +23,7 @@ export class RelayHeartbeat extends Heartbeat { const timeout = setTimeout(() => { heartbeat(); - this._heartbeatTimer!.runPeriodically( + this._heartbeatTimer?.runPeriodically( heartbeat, constants.RelayHeartbeatInterval ); @@ -36,7 +36,7 @@ export class RelayHeartbeat extends Heartbeat { }, cancel: () => { clearTimeout(timeout); - clearInterval(this._heartbeatTimer!._intervalId as NodeJS.Timeout); + clearInterval(this._heartbeatTimer?._intervalId as NodeJS.Timeout); }, }; } @@ -323,7 +323,7 @@ export class RelayHeartbeat extends Heartbeat { const topicPeers = this.gossipsub.topics.get(topic); fanoutPeers.forEach((id) => { if ( - !topicPeers!.has(id) || + !topicPeers?.has(id) || getScore(id) < this.gossipsub._options.scoreThresholds.publishThreshold ) { diff --git a/src/test_utils/log_file.ts b/src/test_utils/log_file.ts index 74dbae5111..f15f8c4d8d 100644 --- a/src/test_utils/log_file.ts +++ b/src/test_utils/log_file.ts @@ -41,9 +41,9 @@ function clean(str: string): string { } export function makeLogFileName(ctx: Context): string { - const unitTest = ctx!.currentTest ? ctx!.currentTest : ctx.test; + const unitTest = ctx?.currentTest ? ctx!.currentTest : ctx.test; let name = clean(unitTest!.title); - let suite = unitTest!.parent; + let suite = unitTest?.parent; while (suite && suite.title) { name = clean(suite.title) + '_' + name; diff --git a/src/test_utils/nim_waku.ts b/src/test_utils/nim_waku.ts index 9b70b11201..61581c1702 100644 --- a/src/test_utils/nim_waku.ts +++ b/src/test_utils/nim_waku.ts @@ -213,7 +213,10 @@ export class NimWaku { return `http://localhost:${port}/`; } - private async rpcCall(method: string, params: any[]) { + private async rpcCall( + method: string, + params: Array + ) { const res = await axios.post( this.rpcUrl, {