mirror of
https://github.com/waku-org/js-waku.git
synced 2025-01-27 20:55:59 +00:00
test: group encoder/decoder declaration
This commit is contained in:
parent
8679adcf80
commit
ae46640ba8
@ -13,6 +13,8 @@ import { DecoderV0, EncoderV0 } from "../waku_message/version_0";
|
|||||||
const log = debug("waku:test");
|
const log = debug("waku:test");
|
||||||
|
|
||||||
const TestContentTopic = "/test/1/waku-filter";
|
const TestContentTopic = "/test/1/waku-filter";
|
||||||
|
const TestEncoder = new EncoderV0(TestContentTopic);
|
||||||
|
const TestDecoder = new DecoderV0(TestContentTopic);
|
||||||
|
|
||||||
describe("Waku Filter", () => {
|
describe("Waku Filter", () => {
|
||||||
let waku: WakuFull;
|
let waku: WakuFull;
|
||||||
@ -50,16 +52,13 @@ describe("Waku Filter", () => {
|
|||||||
expect(bytesToUtf8(msg.payload!)).to.eq(messageText);
|
expect(bytesToUtf8(msg.payload!)).to.eq(messageText);
|
||||||
};
|
};
|
||||||
|
|
||||||
const decoder = new DecoderV0(TestContentTopic);
|
await waku.filter.subscribe([TestDecoder], callback);
|
||||||
|
|
||||||
await waku.filter.subscribe([decoder], callback);
|
|
||||||
// As the filter protocol does not cater for an ack of subscription
|
// As the filter protocol does not cater for an ack of subscription
|
||||||
// we cannot know whether the subscription happened. Something we want to
|
// we cannot know whether the subscription happened. Something we want to
|
||||||
// correct in future versions of the protocol.
|
// correct in future versions of the protocol.
|
||||||
await delay(200);
|
await delay(200);
|
||||||
|
|
||||||
const encoder = new EncoderV0(TestContentTopic);
|
await waku.lightPush.push(TestEncoder, message);
|
||||||
await waku.lightPush.push(encoder, message);
|
|
||||||
while (messageCount === 0) {
|
while (messageCount === 0) {
|
||||||
await delay(250);
|
await delay(250);
|
||||||
}
|
}
|
||||||
@ -74,15 +73,13 @@ describe("Waku Filter", () => {
|
|||||||
messageCount++;
|
messageCount++;
|
||||||
expect(msg.contentTopic).to.eq(TestContentTopic);
|
expect(msg.contentTopic).to.eq(TestContentTopic);
|
||||||
};
|
};
|
||||||
const decoder = new DecoderV0(TestContentTopic);
|
await waku.filter.subscribe([TestDecoder], callback);
|
||||||
await waku.filter.subscribe([decoder], callback);
|
|
||||||
|
|
||||||
await delay(200);
|
await delay(200);
|
||||||
const encoder = new EncoderV0(TestContentTopic);
|
await waku.lightPush.push(TestEncoder, {
|
||||||
await waku.lightPush.push(encoder, {
|
|
||||||
payload: utf8ToBytes("Filtering works!"),
|
payload: utf8ToBytes("Filtering works!"),
|
||||||
});
|
});
|
||||||
await waku.lightPush.push(encoder, {
|
await waku.lightPush.push(TestEncoder, {
|
||||||
payload: utf8ToBytes("Filtering still works!"),
|
payload: utf8ToBytes("Filtering still works!"),
|
||||||
});
|
});
|
||||||
while (messageCount < 2) {
|
while (messageCount < 2) {
|
||||||
@ -96,19 +93,16 @@ describe("Waku Filter", () => {
|
|||||||
const callback = (): void => {
|
const callback = (): void => {
|
||||||
messageCount++;
|
messageCount++;
|
||||||
};
|
};
|
||||||
const decoder = new DecoderV0(TestContentTopic);
|
const unsubscribe = await waku.filter.subscribe([TestDecoder], callback);
|
||||||
const unsubscribe = await waku.filter.subscribe([decoder], callback);
|
|
||||||
|
|
||||||
const encoder = new EncoderV0(TestContentTopic);
|
|
||||||
|
|
||||||
await delay(200);
|
await delay(200);
|
||||||
await waku.lightPush.push(encoder, {
|
await waku.lightPush.push(TestEncoder, {
|
||||||
payload: utf8ToBytes("This should be received"),
|
payload: utf8ToBytes("This should be received"),
|
||||||
});
|
});
|
||||||
await delay(100);
|
await delay(100);
|
||||||
await unsubscribe();
|
await unsubscribe();
|
||||||
await delay(200);
|
await delay(200);
|
||||||
await waku.lightPush.push(encoder, {
|
await waku.lightPush.push(TestEncoder, {
|
||||||
payload: utf8ToBytes("This should not be received"),
|
payload: utf8ToBytes("This should not be received"),
|
||||||
});
|
});
|
||||||
await delay(100);
|
await delay(100);
|
||||||
|
@ -18,6 +18,7 @@ import { EncoderV0 } from "../waku_message/version_0";
|
|||||||
const log = debug("waku:test:lightpush");
|
const log = debug("waku:test:lightpush");
|
||||||
|
|
||||||
const TestContentTopic = "/test/1/waku-light-push/utf8";
|
const TestContentTopic = "/test/1/waku-light-push/utf8";
|
||||||
|
const TestEncoder = new EncoderV0(TestContentTopic);
|
||||||
|
|
||||||
describe("Waku Light Push [node only]", () => {
|
describe("Waku Light Push [node only]", () => {
|
||||||
let waku: WakuFull;
|
let waku: WakuFull;
|
||||||
@ -42,9 +43,8 @@ describe("Waku Light Push [node only]", () => {
|
|||||||
await waitForRemotePeer(waku, [Protocols.LightPush]);
|
await waitForRemotePeer(waku, [Protocols.LightPush]);
|
||||||
|
|
||||||
const messageText = "Light Push works!";
|
const messageText = "Light Push works!";
|
||||||
const encoder = new EncoderV0(TestContentTopic);
|
|
||||||
|
|
||||||
const pushResponse = await waku.lightPush.push(encoder, {
|
const pushResponse = await waku.lightPush.push(TestEncoder, {
|
||||||
payload: utf8ToBytes(messageText),
|
payload: utf8ToBytes(messageText),
|
||||||
});
|
});
|
||||||
expect(pushResponse?.isSuccess).to.be.true;
|
expect(pushResponse?.isSuccess).to.be.true;
|
||||||
@ -79,11 +79,10 @@ describe("Waku Light Push [node only]", () => {
|
|||||||
const nimPeerId = await nwaku.getPeerId();
|
const nimPeerId = await nwaku.getPeerId();
|
||||||
|
|
||||||
const messageText = "Light Push works!";
|
const messageText = "Light Push works!";
|
||||||
const encoder = new EncoderV0(TestContentTopic);
|
|
||||||
|
|
||||||
log("Send message via lightpush");
|
log("Send message via lightpush");
|
||||||
const pushResponse = await waku.lightPush.push(
|
const pushResponse = await waku.lightPush.push(
|
||||||
encoder,
|
TestEncoder,
|
||||||
{ payload: utf8ToBytes(messageText) },
|
{ payload: utf8ToBytes(messageText) },
|
||||||
{
|
{
|
||||||
peerId: nimPeerId,
|
peerId: nimPeerId,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user