mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-21 23:23:13 +00:00
* fix: use pubsubTopic from current ones if not set * fix: improve type on dial method * enforce same pubusb on filter.subscribe, make content topic to pubsub mapping default for decoder / encoder * fix mapping problem * update tests * add error handling * fix typo * up lock * rm lock * up lock * remove only * fix content topic * fix ephemeral test * fix filter unsubscribe test * up utils * fix subscribe test * up interfaces and filter api * remove only * up ping test * fix subscribe test * fix push test * fix lightPush * fix multiple pubsub * remove only, fix subscribe filter test * remove only * fix cluster ID selection and named sharding subscription test * fix unsubscribe test * fix light push test * fix light push test * fix push test * fix relay publish * create runNode and fix relay tests * generalize runNodes, fix some tests * fix store tests * fix toAsyncIterator tests * remove only * fix lightPush * use generics * try fix test * run failing tests * remove only * address failed tests, remove DefaultPubsubTopic dependency in some tests
108 lines
3.0 KiB
TypeScript
108 lines
3.0 KiB
TypeScript
import { createDecoder, createEncoder } from "@waku/core";
|
|
import { type LightNode } from "@waku/interfaces";
|
|
import { toAsyncIterator } from "@waku/utils";
|
|
import { bytesToUtf8, utf8ToBytes } from "@waku/utils/bytes";
|
|
import chai, { expect } from "chai";
|
|
import chaiAsPromised from "chai-as-promised";
|
|
|
|
import {
|
|
afterEachCustom,
|
|
beforeEachCustom,
|
|
delay,
|
|
ServiceNode,
|
|
tearDownNodes
|
|
} from "../src/index.js";
|
|
|
|
import { runNodes } from "./filter/single_node/utils.js";
|
|
|
|
chai.use(chaiAsPromised);
|
|
|
|
const TestContentTopic = "/test/1/waku-filter/default";
|
|
const TestShardInfo = {
|
|
contentTopics: [TestContentTopic],
|
|
clusterId: 3
|
|
};
|
|
|
|
const TestEncoder = createEncoder({
|
|
contentTopic: TestContentTopic,
|
|
pubsubTopicShardInfo: TestShardInfo
|
|
});
|
|
const TestDecoder = createDecoder(TestContentTopic, TestShardInfo);
|
|
|
|
describe("Util: toAsyncIterator: Filter", function () {
|
|
let waku: LightNode;
|
|
let nwaku: ServiceNode;
|
|
|
|
beforeEachCustom(this, async () => {
|
|
[nwaku, waku] = await runNodes(this.ctx, TestShardInfo);
|
|
});
|
|
|
|
afterEachCustom(this, async () => {
|
|
await tearDownNodes(nwaku, waku);
|
|
});
|
|
|
|
it("creates an iterator", async function () {
|
|
this.timeout(10000);
|
|
const messageText = "hey, what's up?";
|
|
const sent = { payload: utf8ToBytes(messageText) };
|
|
|
|
const { iterator } = await toAsyncIterator(waku.filter, TestDecoder, {
|
|
timeoutMs: 1000
|
|
});
|
|
|
|
await waku.lightPush.send(TestEncoder, sent);
|
|
const { value } = await iterator.next();
|
|
|
|
expect(value.contentTopic).to.eq(TestContentTopic);
|
|
expect(value.pubsubTopic).to.eq(TestDecoder.pubsubTopic);
|
|
expect(bytesToUtf8(value.payload)).to.eq(messageText);
|
|
});
|
|
|
|
it("handles multiple messages", async function () {
|
|
this.timeout(10000);
|
|
const { iterator } = await toAsyncIterator(waku.filter, TestDecoder, {
|
|
timeoutMs: 1000
|
|
});
|
|
|
|
await waku.lightPush.send(TestEncoder, {
|
|
payload: utf8ToBytes("Filtering works!")
|
|
});
|
|
await waku.lightPush.send(TestEncoder, {
|
|
payload: utf8ToBytes("Filtering still works!")
|
|
});
|
|
|
|
let result = await iterator.next();
|
|
expect(bytesToUtf8(result.value.payload)).to.eq("Filtering works!");
|
|
|
|
result = await iterator.next();
|
|
expect(bytesToUtf8(result.value.payload)).to.eq("Filtering still works!");
|
|
});
|
|
|
|
it("unsubscribes", async function () {
|
|
this.timeout(10000);
|
|
const { iterator, stop } = await toAsyncIterator(waku.filter, TestDecoder, {
|
|
timeoutMs: 1000
|
|
});
|
|
|
|
await waku.lightPush.send(TestEncoder, {
|
|
payload: utf8ToBytes("This should be received")
|
|
});
|
|
|
|
await delay(400);
|
|
|
|
await stop();
|
|
|
|
await waku.lightPush.send(TestEncoder, {
|
|
payload: utf8ToBytes("This should not be received")
|
|
});
|
|
|
|
let result = await iterator.next();
|
|
expect(result.done).to.eq(true);
|
|
expect(bytesToUtf8(result.value.payload)).to.eq("This should be received");
|
|
|
|
result = await iterator.next();
|
|
expect(result.value).to.eq(undefined);
|
|
expect(result.done).to.eq(true);
|
|
});
|
|
});
|