Skip to content

Commit

Permalink
make tests run fine both ways
Browse files Browse the repository at this point in the history
  • Loading branch information
fbarbu15 committed Jan 15, 2024
1 parent e2703a7 commit e9e56e9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/tests/src/node/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const WAKU_SERVICE_NODE_PARAMS =
process.env.WAKU_SERVICE_NODE_PARAMS ?? undefined;
const NODE_READY_LOG_LINE = "Node setup complete";

const DOCKER_IMAGE_NAME = process.env.WAKUNODE_IMAGE || "wakuorg/nwaku:v0.22.0";
export const DOCKER_IMAGE_NAME =
process.env.WAKUNODE_IMAGE || "wakuorg/nwaku:v0.22.0";

const isGoWaku = DOCKER_IMAGE_NAME.includes("go-waku");

Expand Down
18 changes: 18 additions & 0 deletions packages/tests/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { createDecoder, createEncoder, Decoder, Encoder } from "@waku/core";

import { DOCKER_IMAGE_NAME } from "./node/node";

// Utility to generate test data for multiple topics tests.
export function generateTestData(topicCount: number): {
contentTopics: string[];
Expand All @@ -20,3 +22,19 @@ export function generateTestData(topicCount: number): {
decoders
};
}

// Utility to add test conditions based on nwaku/gowaku versions
export function isNwakuAtLeast(requiredVersion: string): boolean {
const versionRegex = /(?:v)?(\d+\.\d+(?:\.\d+)?)/;
const match = DOCKER_IMAGE_NAME.match(versionRegex);

if (match) {
const version = match[0].substring(1); // Remove the 'v' prefix
return (
version.localeCompare(requiredVersion, undefined, { numeric: true }) >= 0
);
} else {
// If there is no match we assume that it's a version closed to master so we return True
return true;
}
}
15 changes: 12 additions & 3 deletions packages/tests/tests/filter/subscribe.node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { expect } from "chai";
import {
delay,
generateTestData,
isNwakuAtLeast,
makeLogFileName,
MessageCollector,
NimGoNode,
Expand Down Expand Up @@ -222,7 +223,10 @@ describe("Waku Filter V2: Subscribe", function () {

it("Subscribe to 100 topics at once and receives messages", async function () {
this.timeout(50000);
const topicCount = 100;
let topicCount = 30;
if (isNwakuAtLeast("0.24.0")) {
topicCount = 100;
}
const td = generateTestData(topicCount);

// Subscribe to all 100 topics.
Expand Down Expand Up @@ -254,7 +258,10 @@ describe("Waku Filter V2: Subscribe", function () {
});

it("Error when try to subscribe to more than 101 topics", async function () {
const topicCount = 101;
let topicCount = 31;
if (isNwakuAtLeast("0.24.0")) {
topicCount = 101;
}
const td = generateTestData(topicCount);

// Attempt to subscribe to 101 topics
Expand All @@ -266,7 +273,9 @@ describe("Waku Filter V2: Subscribe", function () {
} catch (err) {
if (
err instanceof Error &&
err.message.includes("exceeds maximum content topics: 100")
err.message.includes(
`exceeds maximum content topics: ${topicCount - 1}`
)
) {
return;
} else {
Expand Down

0 comments on commit e9e56e9

Please sign in to comment.