This commit is contained in:
fbarbu15 2023-10-03 12:46:22 +03:00
parent a7ef4b80da
commit 6778eb3809
No known key found for this signature in database
GPG Key ID: D75221C8DEA22501
3 changed files with 46 additions and 11 deletions

View File

@ -1,8 +1,4 @@
import {
createDecoder,
DefaultPubSubTopic,
waitForRemotePeer
} from "@waku/core";
import { DefaultPubSubTopic, waitForRemotePeer } from "@waku/core";
import type { IMessage, LightNode } from "@waku/interfaces";
import { createLightNode, Protocols } from "@waku/sdk";
import { expect } from "chai";
@ -15,6 +11,9 @@ import {
} from "../../src/index.js";
import {
customContentTopic,
customPubSubTopic,
customTestDecoder,
processMessages,
sendMessages,
startAndConnectLightNode,
@ -23,10 +22,6 @@ import {
totalMsgs
} from "./utils.js";
const customContentTopic = "/test/2/waku-store/utf8";
const customPubSubTopic = "/waku/2/custom-dapp/proto";
const customTestDecoder = createDecoder(customContentTopic, customPubSubTopic);
describe("Waku Store, custom pubsub topic", function () {
this.timeout(15000);
let waku: LightNode;

View File

@ -33,6 +33,7 @@ import {
import { areUint8ArraysEqual } from "../../src/utils.js";
import {
customContentTopic,
log,
messageText,
processMessages,
@ -100,6 +101,8 @@ describe("Waku Store", function () {
[TestDecoder],
DefaultPubSubTopic
);
// checking that all message sent were retrieved
TEST_STRING.forEach((testItem) => {
expect(
messageCollector.hasMessage(TestContentTopic, testItem["value"])
@ -107,7 +110,36 @@ describe("Waku Store", function () {
});
});
it("Query generator for multiple messages with different message content topic format", async function () {
it("Query generator for multiple messages with multiple decoders", async function () {
await nwaku.sendMessage(
NimGoNode.toMessageRpcQuery({
payload: utf8ToBytes("M1"),
contentTopic: TestContentTopic
}),
DefaultPubSubTopic
);
await nwaku.sendMessage(
NimGoNode.toMessageRpcQuery({
payload: utf8ToBytes("M2"),
contentTopic: customContentTopic
}),
DefaultPubSubTopic
);
waku = await startAndConnectLightNode(nwaku);
const secondDecoder = createDecoder(customContentTopic, DefaultPubSubTopic);
const messageCollector = new MessageCollector();
messageCollector.list = await processMessages(
waku,
[TestDecoder, secondDecoder],
DefaultPubSubTopic
);
expect(messageCollector.hasMessage(TestContentTopic, "M1")).to.eq(true);
expect(messageCollector.hasMessage(customContentTopic, "M2")).to.eq(true);
});
it("Query generator for multiple messages with different content topic format", async function () {
for (const testItem of TEST_STRING) {
expect(
await nwaku.sendMessage(
@ -131,7 +163,9 @@ describe("Waku Store", function () {
const _promises = msgPromises.map(async (promise) => {
const msg = await promise;
if (msg) {
areUint8ArraysEqual(msg.payload, utf8ToBytes(messageText));
expect(
areUint8ArraysEqual(msg.payload, utf8ToBytes(messageText))
).to.eq(true);
}
});

View File

@ -18,6 +18,12 @@ export const log = debug("waku:test:store");
export const TestContentTopic = "/test/1/waku-store/utf8";
export const TestEncoder = createEncoder({ contentTopic: TestContentTopic });
export const TestDecoder = createDecoder(TestContentTopic);
export const customContentTopic = "/test/2/waku-store/utf8";
export const customPubSubTopic = "/waku/2/custom-dapp/proto";
export const customTestDecoder = createDecoder(
customContentTopic,
customPubSubTopic
);
export const totalMsgs = 20;
export const messageText = "Store Push works!";