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(); + }); });