Remove warnings

This commit is contained in:
Franck Royer 2021-04-13 15:22:29 +10:00
parent 09d89ebd78
commit b38634fd14
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
5 changed files with 22 additions and 22 deletions

View File

@ -12,7 +12,7 @@ import { RelayCodec, RelayDefaultTopic } from './index';
describe('Waku Relay', () => { describe('Waku Relay', () => {
afterEach(function () { afterEach(function () {
if (this.currentTest!.state === 'failed') { if (this.currentTest?.state === 'failed') {
console.log(`Test failed, log file name is ${makeLogFileName(this)}`); console.log(`Test failed, log file name is ${makeLogFileName(this)}`);
} }
}); });
@ -41,15 +41,13 @@ describe('Waku Relay', () => {
await Promise.all([ await Promise.all([
new Promise((resolve) => new Promise((resolve) =>
waku1.libp2p.pubsub.once( waku1.libp2p.pubsub.once('pubsub:subscription-change', () =>
'pubsub:subscription-change', resolve(null)
(...args: any[]) => resolve(args)
) )
), ),
new Promise((resolve) => new Promise((resolve) =>
waku2.libp2p.pubsub.once( waku2.libp2p.pubsub.once('pubsub:subscription-change', () =>
'pubsub:subscription-change', resolve(null)
(...args: any[]) => resolve(args)
) )
), ),
]); ]);
@ -173,7 +171,7 @@ describe('Waku Relay', () => {
this.timeout(10_000); this.timeout(10_000);
waku = await Waku.create({ staticNoiseKey: NOISE_KEY_1 }); 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 nimWaku.start();
await waku.dial(await nimWaku.getMultiaddrWithId()); await waku.dial(await nimWaku.getMultiaddrWithId());
@ -252,7 +250,7 @@ describe('Waku Relay', () => {
Waku.create({ staticNoiseKey: NOISE_KEY_2 }), 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(); await nimWaku.start();
const nimWakuMultiaddr = await nimWaku.getMultiaddrWithId(); const nimWakuMultiaddr = await nimWaku.getMultiaddrWithId();
@ -315,10 +313,9 @@ describe('Waku Relay', () => {
}); });
}); });
function waitForNextData(pubsub: Pubsub): Promise<WakuMessage> { async function waitForNextData(pubsub: Pubsub): Promise<WakuMessage> {
return new Promise((resolve) => { const msg = (await new Promise((resolve) => {
pubsub.once(RelayDefaultTopic, resolve); pubsub.once(RelayDefaultTopic, resolve);
}).then((msg: any) => { })) as Pubsub.InMessage;
return WakuMessage.decode(msg.data); return WakuMessage.decode(msg.data);
});
} }

View File

@ -94,7 +94,7 @@ export class WakuRelayPubsub extends Gossipsub {
); );
this.mesh.set(topic, peers); 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.log('JOIN: Add mesh link to %s in %s', id, topic);
this._sendGraft(id, topic); this._sendGraft(id, topic);
}); });
@ -156,7 +156,7 @@ export class WakuRelayPubsub extends Gossipsub {
this.lastpub.set(topic, this._now()); this.lastpub.set(topic, this._now());
} }
meshPeers!.forEach((peer) => { meshPeers?.forEach((peer) => {
toSend.add(peer); toSend.add(peer);
}); });
}); });

View File

@ -23,7 +23,7 @@ export class RelayHeartbeat extends Heartbeat {
const timeout = setTimeout(() => { const timeout = setTimeout(() => {
heartbeat(); heartbeat();
this._heartbeatTimer!.runPeriodically( this._heartbeatTimer?.runPeriodically(
heartbeat, heartbeat,
constants.RelayHeartbeatInterval constants.RelayHeartbeatInterval
); );
@ -36,7 +36,7 @@ export class RelayHeartbeat extends Heartbeat {
}, },
cancel: () => { cancel: () => {
clearTimeout(timeout); 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); const topicPeers = this.gossipsub.topics.get(topic);
fanoutPeers.forEach((id) => { fanoutPeers.forEach((id) => {
if ( if (
!topicPeers!.has(id) || !topicPeers?.has(id) ||
getScore(id) < getScore(id) <
this.gossipsub._options.scoreThresholds.publishThreshold this.gossipsub._options.scoreThresholds.publishThreshold
) { ) {

View File

@ -41,9 +41,9 @@ function clean(str: string): string {
} }
export function makeLogFileName(ctx: Context): 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 name = clean(unitTest!.title);
let suite = unitTest!.parent; let suite = unitTest?.parent;
while (suite && suite.title) { while (suite && suite.title) {
name = clean(suite.title) + '_' + name; name = clean(suite.title) + '_' + name;

View File

@ -213,7 +213,10 @@ export class NimWaku {
return `http://localhost:${port}/`; return `http://localhost:${port}/`;
} }
private async rpcCall(method: string, params: any[]) { private async rpcCall(
method: string,
params: Array<string | number | unknown>
) {
const res = await axios.post( const res = await axios.post(
this.rpcUrl, this.rpcUrl,
{ {