Skip to content

Commit 2af9628

Browse files
fryorcrakenweboko
andauthored
test: ensure filter/light push work with message-encryption (#1671)
Co-authored-by: Sasha <118575614+weboko@users.noreply.github.com>
1 parent 6aade79 commit 2af9628

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

packages/tests/tests/filter/subscribe.node.spec.ts

+44
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
} from "@waku/core";
77
import type { IFilterSubscription, LightNode } from "@waku/interfaces";
88
import { Protocols } from "@waku/interfaces";
9+
import { ecies, symmetric } from "@waku/message-encryption";
910
import { utf8ToBytes } from "@waku/utils/bytes";
1011
import { expect } from "chai";
1112

@@ -65,6 +66,49 @@ describe("Waku Filter V2: Subscribe", function () {
6566
expect((await nwaku.messages()).length).to.eq(1);
6667
});
6768

69+
it("Subscribe and receive ecies encrypted messages via lightPush", async function () {
70+
const privateKey = ecies.generatePrivateKey();
71+
const publicKey = ecies.getPublicKey(privateKey);
72+
const encoder = ecies.createEncoder({
73+
contentTopic: TestContentTopic,
74+
publicKey
75+
});
76+
const decoder = ecies.createDecoder(TestContentTopic, privateKey);
77+
78+
await subscription.subscribe([decoder], messageCollector.callback);
79+
80+
await waku.lightPush.send(encoder, messagePayload);
81+
82+
expect(await messageCollector.waitForMessages(1)).to.eq(true);
83+
messageCollector.verifyReceivedMessage(0, {
84+
expectedMessageText: messageText,
85+
expectedContentTopic: TestContentTopic,
86+
expectedVersion: 1
87+
});
88+
expect((await nwaku.messages()).length).to.eq(1);
89+
});
90+
91+
it("Subscribe and receive symmetrically encrypted messages via lightPush", async function () {
92+
const symKey = symmetric.generateSymmetricKey();
93+
const encoder = symmetric.createEncoder({
94+
contentTopic: TestContentTopic,
95+
symKey
96+
});
97+
const decoder = symmetric.createDecoder(TestContentTopic, symKey);
98+
99+
await subscription.subscribe([decoder], messageCollector.callback);
100+
101+
await waku.lightPush.send(encoder, messagePayload);
102+
103+
expect(await messageCollector.waitForMessages(1)).to.eq(true);
104+
messageCollector.verifyReceivedMessage(0, {
105+
expectedMessageText: messageText,
106+
expectedContentTopic: TestContentTopic,
107+
expectedVersion: 1
108+
});
109+
expect((await nwaku.messages()).length).to.eq(1);
110+
});
111+
68112
it("Subscribe and receive messages via waku relay post", async function () {
69113
await subscription.subscribe([TestDecoder], messageCollector.callback);
70114

0 commit comments

Comments
 (0)