From 4a9360d4e3b8cbf580e5fb7199f7e6c001fa1ce1 Mon Sep 17 00:00:00 2001 From: "fryorcraken.eth" Date: Wed, 20 Sep 2023 15:12:32 +1000 Subject: [PATCH] test: fail on unhandled rejections and uncaught exceptions --- packages/tests/tests/waku.node.spec.ts | 41 +++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/packages/tests/tests/waku.node.spec.ts b/packages/tests/tests/waku.node.spec.ts index ea33231670..72bb3d8880 100644 --- a/packages/tests/tests/waku.node.spec.ts +++ b/packages/tests/tests/waku.node.spec.ts @@ -12,7 +12,11 @@ import { createEncoder, generateSymmetricKey } from "@waku/message-encryption/symmetric"; -import { createLightNode, createRelayNode } from "@waku/sdk"; +import { + createLightNode, + createEncoder as createPlainEncoder, + createRelayNode +} from "@waku/sdk"; import { bytesToUtf8, utf8ToBytes } from "@waku/utils/bytes"; import { expect } from "chai"; @@ -25,6 +29,8 @@ import { const TestContentTopic = "/test/1/waku/utf8"; +const TestEncoder = createPlainEncoder({ contentTopic: TestContentTopic }); + describe("Waku Dial [node only]", function () { describe("Interop: NimGoNode", function () { let waku: Waku; @@ -60,6 +66,39 @@ describe("Waku Dial [node only]", function () { const nimPeerId = await nwaku.getPeerId(); expect(await waku.libp2p.peerStore.has(nimPeerId)).to.be.true; }); + + it("Does not throw an exception when node disconnects", async function () { + this.timeout(20_000); + + process.on("unhandledRejection", (e) => + expect.fail("unhandledRejection", e) + ); + process.on("uncaughtException", (e) => + expect.fail("uncaughtException", e) + ); + + nwaku = new NimGoNode(makeLogFileName(this)); + await nwaku.start({ + filter: true, + store: true, + lightpush: true + }); + const multiAddrWithId = await nwaku.getMultiaddrWithId(); + + waku = await createLightNode({ + staticNoiseKey: NOISE_KEY_1 + }); + await waku.start(); + await waku.dial(multiAddrWithId); + await nwaku.stop(); + try { + await waku.lightPush?.send(TestEncoder, { + payload: utf8ToBytes("hello world") + }); + } catch (e) { + // We are not checking this exception + } + }); }); describe("Bootstrap", function () {