mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-08 16:53:10 +00:00
Concepts are being mixed up between the global network config (static vs auto sharding), that needs to be the same of all nodes in the network, individual node configuration (eg relay node subscribing to a given shard), and the routing characteristic of a specific message (eg pubsub topic, shard). This stops proper configuration of nwaku post 0.36.0 because we know need to be deliberate on whether nwaku nodes are running with auto or static sharding. It also included various back and forth conversions between shards, pubsub topics, etc. With this change, we tidy up the network configuration, and make it explicit whether it is static or auto sharded. We also introduce the concept of routing info, which is specific to a message, and tied to the overall network configuration. Routing info abstract pubsub topic, shard, and autosharding needs. Which should lead to easier tidy up of the pubsub concept at a later stage.
168 lines
4.3 KiB
TypeScript
168 lines
4.3 KiB
TypeScript
import { IMessage, type LightNode } from "@waku/interfaces";
|
|
import { formatPubsubTopic } from "@waku/utils";
|
|
import { expect } from "chai";
|
|
|
|
import {
|
|
afterEachCustom,
|
|
beforeEachCustom,
|
|
ServiceNode,
|
|
tearDownNodes
|
|
} from "../../src/index.js";
|
|
|
|
import {
|
|
processQueriedMessages,
|
|
runStoreNodes,
|
|
TestDecoder,
|
|
TestDecoder2,
|
|
TestNetworkConfig
|
|
} from "./utils.js";
|
|
|
|
describe("Waku Store, error handling", function () {
|
|
this.timeout(15000);
|
|
let waku: LightNode;
|
|
let nwaku: ServiceNode;
|
|
|
|
beforeEachCustom(this, async () => {
|
|
[nwaku, waku] = await runStoreNodes(this.ctx, TestNetworkConfig);
|
|
});
|
|
|
|
afterEachCustom(this, async () => {
|
|
await tearDownNodes(nwaku, waku);
|
|
});
|
|
|
|
it("Query Generator, Multiple PubsubTopics", async function () {
|
|
try {
|
|
for await (const msgPromises of waku.store.queryGenerator([
|
|
TestDecoder,
|
|
TestDecoder2
|
|
])) {
|
|
void msgPromises;
|
|
}
|
|
throw new Error("QueryGenerator was successful but was expected to fail");
|
|
} catch (err) {
|
|
if (
|
|
!(err instanceof Error) ||
|
|
!err.message.includes(
|
|
"API does not support querying multiple pubsub topics at once"
|
|
)
|
|
) {
|
|
throw err;
|
|
}
|
|
}
|
|
});
|
|
|
|
it("Query Generator, No Decoder", async function () {
|
|
try {
|
|
for await (const msgPromises of waku.store.queryGenerator([])) {
|
|
void msgPromises;
|
|
}
|
|
throw new Error("QueryGenerator was successful but was expected to fail");
|
|
} catch (err) {
|
|
if (
|
|
!(err instanceof Error) ||
|
|
!err.message.includes("No decoders provided")
|
|
) {
|
|
throw err;
|
|
}
|
|
}
|
|
});
|
|
|
|
it("Query Generator, No message returned", async function () {
|
|
const WrongTestPubsubTopic = formatPubsubTopic(43, 53);
|
|
const messages = await processQueriedMessages(
|
|
waku,
|
|
[TestDecoder],
|
|
WrongTestPubsubTopic
|
|
);
|
|
expect(messages?.length).eq(0);
|
|
});
|
|
|
|
it("Query with Ordered Callback, Multiple PubsubTopics", async function () {
|
|
try {
|
|
await waku.store.queryWithOrderedCallback(
|
|
[TestDecoder, TestDecoder2],
|
|
async () => {}
|
|
);
|
|
throw new Error("QueryGenerator was successful but was expected to fail");
|
|
} catch (err) {
|
|
if (
|
|
!(err instanceof Error) ||
|
|
!err.message.includes(
|
|
"API does not support querying multiple pubsub topics at once"
|
|
)
|
|
) {
|
|
throw err;
|
|
}
|
|
}
|
|
});
|
|
|
|
it("Query with Ordered Callback, No Decoder", async function () {
|
|
try {
|
|
await waku.store.queryWithOrderedCallback([], async () => {});
|
|
throw new Error("QueryGenerator was successful but was expected to fail");
|
|
} catch (err) {
|
|
if (
|
|
!(err instanceof Error) ||
|
|
!err.message.includes("No decoders provided")
|
|
) {
|
|
throw err;
|
|
}
|
|
}
|
|
});
|
|
|
|
it("Query with Ordered Callback, No message returned", async function () {
|
|
const messages: IMessage[] = [];
|
|
await waku.store.queryWithOrderedCallback([TestDecoder], async (msg) => {
|
|
messages.push(msg);
|
|
});
|
|
expect(messages?.length).eq(0);
|
|
});
|
|
|
|
it("Query with Promise Callback, Multiple PubsubTopics", async function () {
|
|
try {
|
|
await waku.store.queryWithPromiseCallback(
|
|
[TestDecoder, TestDecoder2],
|
|
async () => {}
|
|
);
|
|
throw new Error("QueryGenerator was successful but was expected to fail");
|
|
} catch (err) {
|
|
if (
|
|
!(err instanceof Error) ||
|
|
!err.message.includes(
|
|
"API does not support querying multiple pubsub topics at once"
|
|
)
|
|
) {
|
|
throw err;
|
|
}
|
|
}
|
|
});
|
|
|
|
it("Query with Promise Callback, No Decoder", async function () {
|
|
try {
|
|
await waku.store.queryWithPromiseCallback([], async () => {});
|
|
throw new Error("QueryGenerator was successful but was expected to fail");
|
|
} catch (err) {
|
|
if (
|
|
!(err instanceof Error) ||
|
|
!err.message.includes("No decoders provided")
|
|
) {
|
|
throw err;
|
|
}
|
|
}
|
|
});
|
|
|
|
it("Query with Promise Callback, No message returned", async function () {
|
|
const messages: IMessage[] = [];
|
|
await waku.store.queryWithPromiseCallback(
|
|
[TestDecoder],
|
|
async (msgPromise) => {
|
|
const msg = await msgPromise;
|
|
if (msg) {
|
|
messages.push(msg);
|
|
}
|
|
}
|
|
);
|
|
expect(messages?.length).eq(0);
|
|
});
|
|
});
|