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', () => {
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<WakuMessage> {
return new Promise((resolve) => {
async function waitForNextData(pubsub: Pubsub): Promise<WakuMessage> {
const msg = (await new Promise((resolve) => {
pubsub.once(RelayDefaultTopic, resolve);
}).then((msg: any) => {
})) as Pubsub.InMessage;
return WakuMessage.decode(msg.data);
});
}

View File

@ -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);
});
});

View File

@ -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
) {

View File

@ -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;

View File

@ -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<string | number | unknown>
) {
const res = await axios.post(
this.rpcUrl,
{