mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-05-04 01:13:09 +00:00
tests: use a generator for sharded pubsub topics set pubsub topic in encoder/decoder based on sharding type add function for grouping content topics by pubsub topic add autosharding config to create options add autoshard rpc endpoints to nwaku and use in tests set autoshard pubsub topics in all protocols fix rebase with static sharding removes unused function remove console logs remove autosharding from ShardInfo, add to EncoderOptions fix enr and encoder/decoder options test that same application/version hashes to same shard index update comment on shard field fix spelling of autosharding fix content topic protocol in tests add sharding type alias and function to determine topic in encoders/decoders move DefaultPubsubTopic from core to interfaces
131 lines
3.7 KiB
TypeScript
131 lines
3.7 KiB
TypeScript
import { DecodedMessage, PageDirection } from "@waku/core";
|
|
import type { IMessage, LightNode } from "@waku/interfaces";
|
|
import { DefaultPubsubTopic } from "@waku/interfaces";
|
|
import { expect } from "chai";
|
|
|
|
import { makeLogFileName, NimGoNode, tearDownNodes } from "../../src/index.js";
|
|
|
|
import {
|
|
chunkAndReverseArray,
|
|
sendMessages,
|
|
startAndConnectLightNode,
|
|
TestContentTopic,
|
|
TestDecoder,
|
|
totalMsgs
|
|
} from "./utils.js";
|
|
|
|
describe("Waku Store, order", function () {
|
|
this.timeout(15000);
|
|
let waku: LightNode;
|
|
let nwaku: NimGoNode;
|
|
|
|
beforeEach(async function () {
|
|
this.timeout(15000);
|
|
nwaku = new NimGoNode(makeLogFileName(this));
|
|
await nwaku.start({ store: true, lightpush: true, relay: true });
|
|
await nwaku.ensureSubscriptions();
|
|
});
|
|
|
|
afterEach(async function () {
|
|
this.timeout(15000);
|
|
await tearDownNodes(nwaku, waku);
|
|
});
|
|
|
|
[PageDirection.FORWARD, PageDirection.BACKWARD].forEach((pageDirection) => {
|
|
it(`Query Generator - ${pageDirection}`, async function () {
|
|
await sendMessages(
|
|
nwaku,
|
|
totalMsgs,
|
|
TestContentTopic,
|
|
DefaultPubsubTopic
|
|
);
|
|
waku = await startAndConnectLightNode(nwaku);
|
|
|
|
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,
|
|
TestContentTopic,
|
|
DefaultPubsubTopic
|
|
);
|
|
waku = await startAndConnectLightNode(nwaku);
|
|
|
|
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,
|
|
TestContentTopic,
|
|
DefaultPubsubTopic
|
|
);
|
|
waku = await startAndConnectLightNode(nwaku);
|
|
|
|
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()));
|
|
});
|
|
});
|
|
});
|