From d39d4507efe75485fd00c0268e04f7ebb934ede1 Mon Sep 17 00:00:00 2001 From: Danish Arora <35004822+danisharora099@users.noreply.github.com> Date: Fri, 13 Oct 2023 16:53:15 +0530 Subject: [PATCH] chore: add a test that uses ping to check filter subscription (#1656) * add a test that uses ping to check filter subscription * remove comment --- packages/tests/tests/filter/ping.node.spec.ts | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/packages/tests/tests/filter/ping.node.spec.ts b/packages/tests/tests/filter/ping.node.spec.ts index 843133e5d8..5e48e0faf3 100644 --- a/packages/tests/tests/filter/ping.node.spec.ts +++ b/packages/tests/tests/filter/ping.node.spec.ts @@ -59,4 +59,40 @@ describe("Waku Filter V2: Ping", function () { // Ping imediately after unsubscribe await validatePingError(subscription); }); + + it("Reopen subscription with peer with lost subscription", async function () { + const openSubscription = async (): Promise => { + await subscription.subscribe([TestDecoder], messageCollector.callback); + }; + + const unsubscribe = async (): Promise => { + await subscription.unsubscribe([TestContentTopic]); + }; + + const pingAndReinitiateSubscription = async (): Promise => { + try { + await subscription.ping(); + } catch (error) { + if ( + error instanceof Error && + error.message.includes("peer has no subscriptions") + ) { + await openSubscription(); + } else { + throw error; + } + } + }; + + // open subscription & ping -> should pass + await openSubscription(); + await pingAndReinitiateSubscription(); + + // unsubscribe & ping -> should fail and reinitiate subscription + await unsubscribe(); + await pingAndReinitiateSubscription(); + + // ping -> should pass as subscription is reinitiated + await pingAndReinitiateSubscription(); + }); });