mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-10 17:53:09 +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
57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
import { TopicValidatorResult } from "@libp2p/interface";
|
|
import type { UnsignedMessage } from "@libp2p/interface";
|
|
import { createSecp256k1PeerId } from "@libp2p/peer-id-factory";
|
|
import { createEncoder } from "@waku/core";
|
|
import { determinePubsubTopic } from "@waku/utils";
|
|
import { expect } from "chai";
|
|
import fc from "fast-check";
|
|
|
|
import { messageValidator } from "./message_validator.js";
|
|
|
|
const TestContentTopic = "/app/1/topic/utf8";
|
|
const TestPubsubTopic = determinePubsubTopic(TestContentTopic);
|
|
|
|
describe("Message Validator", () => {
|
|
it("Accepts a valid Waku Message", async () => {
|
|
await fc.assert(
|
|
fc.asyncProperty(fc.uint8Array({ minLength: 1 }), async (payload) => {
|
|
const peerId = await createSecp256k1PeerId();
|
|
|
|
const encoder = createEncoder({
|
|
contentTopic: TestContentTopic,
|
|
pubsubTopic: TestPubsubTopic
|
|
});
|
|
const bytes = await encoder.toWire({ payload });
|
|
|
|
const message: UnsignedMessage = {
|
|
type: "unsigned",
|
|
topic: TestPubsubTopic,
|
|
data: bytes
|
|
};
|
|
|
|
const result = messageValidator(peerId, message);
|
|
|
|
expect(result).to.eq(TopicValidatorResult.Accept);
|
|
})
|
|
);
|
|
});
|
|
|
|
it("Rejects garbage", async () => {
|
|
await fc.assert(
|
|
fc.asyncProperty(fc.uint8Array(), async (data) => {
|
|
const peerId = await createSecp256k1PeerId();
|
|
|
|
const message: UnsignedMessage = {
|
|
type: "unsigned",
|
|
topic: TestPubsubTopic,
|
|
data
|
|
};
|
|
|
|
const result = messageValidator(peerId, message);
|
|
|
|
expect(result).to.eq(TopicValidatorResult.Reject);
|
|
})
|
|
);
|
|
});
|
|
});
|