Test cleanup

This commit is contained in:
Franck Royer 2021-04-06 11:06:10 +10:00
parent eb9f1c154b
commit 79a9520348
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
4 changed files with 20 additions and 14 deletions

View File

@ -11,12 +11,7 @@ describe('Waku', function () {
this.timeout(10_000); this.timeout(10_000);
const waku = await Waku.create({ staticNoiseKey: NOISE_KEY_1 }); const waku = await Waku.create({ staticNoiseKey: NOISE_KEY_1 });
const peerId = waku.libp2p.peerId.toB58String(); const multiAddrWithId = waku.getLocalMultiaddrWithID();
const localMultiaddr = waku.libp2p.multiaddrs.find((addr) =>
addr.toString().match(/127\.0\.0\.1/)
);
const multiAddrWithId = localMultiaddr + '/p2p/' + peerId;
const nimWaku = new NimWaku(makeLogFileName(this)); const nimWaku = new NimWaku(makeLogFileName(this));
await nimWaku.start({ staticnode: multiAddrWithId }); await nimWaku.start({ staticnode: multiAddrWithId });

View File

@ -67,4 +67,20 @@ export default class Waku {
async stop() { async stop() {
await this.libp2p.stop(); await this.libp2p.stop();
} }
/**
* Return the local multiaddr with peer id on which libp2p is listening.
* @throws if libp2p is not listening on localhost
*/
getLocalMultiaddrWithID(): string {
const localMultiaddr = this.libp2p.multiaddrs.find((addr) =>
addr.toString().match(/127\.0\.0\.1/)
);
if (!localMultiaddr || localMultiaddr.toString() === '') {
throw 'Not listening on localhost';
}
const multiAddrWithId =
localMultiaddr + '/p2p/' + this.libp2p.peerId.toB58String();
return multiAddrWithId;
}
} }

View File

@ -99,15 +99,10 @@ describe('Waku Relay', () => {
let nimWaku: NimWaku; let nimWaku: NimWaku;
beforeEach(async function () { beforeEach(async function () {
this.timeout(10_000); this.timeout(12_000);
waku = await Waku.create({ staticNoiseKey: NOISE_KEY_1 }); waku = await Waku.create({ staticNoiseKey: NOISE_KEY_1 });
const peerId = waku.libp2p.peerId.toB58String(); const multiAddrWithId = waku.getLocalMultiaddrWithID();
const localMultiaddr = waku.libp2p.multiaddrs.find((addr) =>
addr.toString().match(/127\.0\.0\.1/)
);
const multiAddrWithId = localMultiaddr + '/p2p/' + peerId;
nimWaku = new NimWaku(makeLogFileName(this)); nimWaku = new NimWaku(makeLogFileName(this));
await nimWaku.start({ staticnode: multiAddrWithId }); await nimWaku.start({ staticnode: multiAddrWithId });

View File

@ -117,7 +117,7 @@ export class NimWaku {
} }
public stop() { public stop() {
debug( dbg(
`nim-waku ${ `nim-waku ${
this.process ? this.process.pid : this.pid this.process ? this.process.pid : this.pid
} getting SIGINT at ${new Date().toLocaleTimeString()}` } getting SIGINT at ${new Date().toLocaleTimeString()}`