mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-05 15:23:12 +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
128 lines
3.4 KiB
TypeScript
128 lines
3.4 KiB
TypeScript
import { DecodedMessage, PageDirection } from "@waku/core";
|
|
import type { IMessage, LightNode } from "@waku/interfaces";
|
|
import { expect } from "chai";
|
|
|
|
import {
|
|
afterEachCustom,
|
|
beforeEachCustom,
|
|
ServiceNode,
|
|
tearDownNodes
|
|
} from "../../src/index.js";
|
|
|
|
import {
|
|
chunkAndReverseArray,
|
|
runStoreNodes,
|
|
sendMessages,
|
|
TestDecoder,
|
|
TestShardInfo,
|
|
totalMsgs
|
|
} from "./utils.js";
|
|
|
|
describe("Waku Store, order", function () {
|
|
this.timeout(15000);
|
|
let waku: LightNode;
|
|
let nwaku: ServiceNode;
|
|
|
|
beforeEachCustom(this, async () => {
|
|
[nwaku, waku] = await runStoreNodes(this.ctx, TestShardInfo);
|
|
});
|
|
|
|
afterEachCustom(this, async () => {
|
|
await tearDownNodes(nwaku, waku);
|
|
});
|
|
|
|
[PageDirection.FORWARD, PageDirection.BACKWARD].forEach((pageDirection) => {
|
|
it(`Query Generator - ${pageDirection}`, async function () {
|
|
await sendMessages(
|
|
nwaku,
|
|
totalMsgs,
|
|
TestDecoder.contentTopic,
|
|
TestDecoder.pubsubTopic
|
|
);
|
|
|
|
const messages: IMessage[] = [];
|
|
for await (const query of waku.store.queryGenerator([TestDecoder], {
|
|
pageDirection: pageDirection
|
|
})) {
|
|
for await (const msg of query) {
|
|
if (msg) {
|
|
messages.push(msg as DecodedMessage);
|
|
}
|
|
}
|
|
}
|
|
|
|
let expectedPayloads = Array.from(Array(totalMsgs).keys());
|
|
if (pageDirection === PageDirection.BACKWARD) {
|
|
expectedPayloads = chunkAndReverseArray(expectedPayloads, 10);
|
|
}
|
|
|
|
expect(messages?.length).eq(totalMsgs);
|
|
const payloads = messages.map((msg) => msg.payload[0]!);
|
|
expect(payloads).to.deep.eq(expectedPayloads);
|
|
});
|
|
});
|
|
|
|
[PageDirection.FORWARD, PageDirection.BACKWARD].forEach((pageDirection) => {
|
|
it(`Promise Callback - ${pageDirection}`, async function () {
|
|
await sendMessages(
|
|
nwaku,
|
|
totalMsgs,
|
|
TestDecoder.contentTopic,
|
|
TestDecoder.pubsubTopic
|
|
);
|
|
|
|
const messages: IMessage[] = [];
|
|
await waku.store.queryWithPromiseCallback(
|
|
[TestDecoder],
|
|
async (msgPromise) => {
|
|
const msg = await msgPromise;
|
|
if (msg) {
|
|
messages.push(msg);
|
|
}
|
|
},
|
|
{
|
|
pageDirection: pageDirection
|
|
}
|
|
);
|
|
|
|
let expectedPayloads = Array.from(Array(totalMsgs).keys());
|
|
if (pageDirection === PageDirection.BACKWARD) {
|
|
expectedPayloads = chunkAndReverseArray(expectedPayloads, 10);
|
|
}
|
|
|
|
expect(messages?.length).eq(totalMsgs);
|
|
const payloads = messages.map((msg) => msg.payload[0]!);
|
|
expect(payloads).to.deep.eq(expectedPayloads);
|
|
});
|
|
});
|
|
|
|
[PageDirection.FORWARD, PageDirection.BACKWARD].forEach((pageDirection) => {
|
|
it(`Ordered Callback - ${pageDirection}`, async function () {
|
|
await sendMessages(
|
|
nwaku,
|
|
totalMsgs,
|
|
TestDecoder.contentTopic,
|
|
TestDecoder.pubsubTopic
|
|
);
|
|
|
|
const messages: IMessage[] = [];
|
|
await waku.store.queryWithOrderedCallback(
|
|
[TestDecoder],
|
|
async (msg) => {
|
|
messages.push(msg);
|
|
},
|
|
{
|
|
pageDirection: pageDirection
|
|
}
|
|
);
|
|
|
|
if (pageDirection === PageDirection.BACKWARD) {
|
|
messages.reverse();
|
|
}
|
|
expect(messages?.length).eq(totalMsgs);
|
|
const payloads = messages.map((msg) => msg.payload[0]!);
|
|
expect(payloads).to.deep.eq(Array.from(Array(totalMsgs).keys()));
|
|
});
|
|
});
|
|
});
|