Skip to content

Commit

Permalink
Subscription before each & renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
SionoiS committed Sep 19, 2023
1 parent 619dab4 commit c37f0fc
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 37 deletions.
2 changes: 1 addition & 1 deletion packages/tests/src/node/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export class NimGoNode {
return this.rpcCall<RpcInfoResponse>("get_waku_v2_debug_v1_info", []);
}

async sendSubscriptions(
async ensureSubscriptions(
pubsubTopics: [string] = [DefaultPubSubTopic]
): Promise<boolean> {
this.checkProcess();
Expand Down
15 changes: 3 additions & 12 deletions packages/tests/tests/filter/subscribe.node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ describe("Waku Filter V2: Subscribe", function () {
waku = setup.waku;
subscription = setup.subscription;
messageCollector = setup.messageCollector;
});

it("Subscribe and receive messages via lightPush", async function () {
// Nwaku subscribe to the default pubsub topic
await nwaku.sendSubscriptions();
await nwaku.ensureSubscriptions();
});

it("Subscribe and receive messages via lightPush", async function () {
await subscription.subscribe([TestDecoder], messageCollector.callback);

await waku.lightPush.send(TestEncoder, messagePayload);
Expand All @@ -64,9 +64,6 @@ describe("Waku Filter V2: Subscribe", function () {
});

it("Subscribe and receive messages via waku relay post", async function () {
// Nwaku subscribe to the default pubsub topic
await nwaku.sendSubscriptions();

await subscription.subscribe([TestDecoder], messageCollector.callback);

await delay(400);
Expand All @@ -85,9 +82,6 @@ describe("Waku Filter V2: Subscribe", function () {
});

it("Subscribe and receive 2 messages on the same topic", async function () {
// Nwaku subscribe to the default pubsub topic
await nwaku.sendSubscriptions();

await subscription.subscribe([TestDecoder], messageCollector.callback);

await waku.lightPush.send(TestEncoder, messagePayload);
Expand All @@ -111,9 +105,6 @@ describe("Waku Filter V2: Subscribe", function () {
});

it("Subscribe and receive messages on 2 different content topics", async function () {
// Nwaku subscribe to the default pubsub topic
await nwaku.sendSubscriptions();

// Subscribe to the first content topic and send a message.
await subscription.subscribe([TestDecoder], messageCollector.callback);
await waku.lightPush.send(TestEncoder, messagePayload);
Expand Down
21 changes: 3 additions & 18 deletions packages/tests/tests/filter/unsubscribe.node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ describe("Waku Filter V2: Unsubscribe", function () {
waku = setup.waku;
subscription = setup.subscription;
messageCollector = setup.messageCollector;
});

it("Unsubscribe 1 topic - node subscribed to 1 topic", async function () {
// Nwaku subscribe to the default pubsub topic
await nwaku.sendSubscriptions();
await nwaku.ensureSubscriptions();
});

it("Unsubscribe 1 topic - node subscribed to 1 topic", async function () {
await subscription.subscribe([TestDecoder], messageCollector.callback);
await waku.lightPush.send(TestEncoder, messagePayload);
expect(await messageCollector.waitForMessages(1)).to.eq(true);
Expand All @@ -57,9 +57,6 @@ describe("Waku Filter V2: Unsubscribe", function () {
});

it("Unsubscribe 1 topic - node subscribed to 2 topics", async function () {
// Nwaku subscribe to the default pubsub topic
await nwaku.sendSubscriptions();

// Subscribe to 2 topics and send messages
await subscription.subscribe([TestDecoder], messageCollector.callback);
const newContentTopic = "/test/2/waku-filter";
Expand All @@ -82,9 +79,6 @@ describe("Waku Filter V2: Unsubscribe", function () {
});

it("Unsubscribe 2 topics - node subscribed to 2 topics", async function () {
// Nwaku subscribe to the default pubsub topic
await nwaku.sendSubscriptions();

// Subscribe to 2 topics and send messages
await subscription.subscribe([TestDecoder], messageCollector.callback);
const newContentTopic = "/test/2/waku-filter";
Expand All @@ -107,9 +101,6 @@ describe("Waku Filter V2: Unsubscribe", function () {
});

it("Unsubscribe topics the node is not subscribed to", async function () {
// Nwaku subscribe to the default pubsub topic
await nwaku.sendSubscriptions();

// Subscribe to 1 topic and send message
await subscription.subscribe([TestDecoder], messageCollector.callback);
await waku.lightPush.send(TestEncoder, { payload: utf8ToBytes("M1") });
Expand All @@ -129,9 +120,6 @@ describe("Waku Filter V2: Unsubscribe", function () {
});

it("Unsubscribes all - node subscribed to 1 topic", async function () {
// Nwaku subscribe to the default pubsub topic
await nwaku.sendSubscriptions();

await subscription.subscribe([TestDecoder], messageCollector.callback);
await waku.lightPush.send(TestEncoder, { payload: utf8ToBytes("M1") });
expect(await messageCollector.waitForMessages(1)).to.eq(true);
Expand All @@ -148,9 +136,6 @@ describe("Waku Filter V2: Unsubscribe", function () {
});

it("Unsubscribes all - node subscribed to 10 topics", async function () {
// Nwaku subscribe to the default pubsub topic
await nwaku.sendSubscriptions();

// Subscribe to 10 topics and send message
const topicCount = 10;
const td = generateTestData(topicCount);
Expand Down
6 changes: 3 additions & 3 deletions packages/tests/tests/light_push.node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ describe("Waku Light Push [node only] - custom pubsub topic", () => {
beforeEach(async function () {
this.timeout(15_000);
[nwaku, waku] = await runNodes(this, customPubSubTopic);

log("Waiting for nwaku to subscribe to pubsub topic");
await nwaku.ensureSubscriptions([customPubSubTopic]);
});

afterEach(async function () {
Expand All @@ -136,9 +139,6 @@ describe("Waku Light Push [node only] - custom pubsub topic", () => {
it("Push message", async function () {
this.timeout(15_000);

log("Waiting for nwaku to subscribe to pubsub topic");
await nwaku.sendSubscriptions([customPubSubTopic]);

const nimPeerId = await nwaku.getPeerId();
const messageText = "Light Push works!";

Expand Down
6 changes: 3 additions & 3 deletions packages/tests/tests/relay.node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,9 @@ describe("Waku Relay [node only]", () => {

await waku.dial(await nwaku.getMultiaddrWithId());
await waitForRemotePeer(waku, [Protocols.Relay]);

// Nwaku subscribe to the default pubsub topic
await nwaku.ensureSubscriptions();
});

afterEach(async function () {
Expand All @@ -437,9 +440,6 @@ describe("Waku Relay [node only]", () => {
it("Publishes to nwaku", async function () {
this.timeout(30000);

// Nwaku subscribe to the default pubsub topic
await nwaku.sendSubscriptions();

const messageText = "This is a message";
await waku.relay.send(TestEncoder, { payload: utf8ToBytes(messageText) });

Expand Down

0 comments on commit c37f0fc

Please sign in to comment.