mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-03 06:13:08 +00:00
* chore: update noise * update: package.lock * update: @chainsafe/libp2p-gossipsub * rm unwanted libp2p interface deps & bump up libp2p * refactor code for new deps * update: new package.lock * setup prettier, refactor eslint and rm trailing commas * update package.lock * fix build * import type for interface * fix imports for merge * update typedoc exports * add: CustomEvent import * use new libp2p interface * add aegir as dev dep for tests
59 lines
1.6 KiB
TypeScript
59 lines
1.6 KiB
TypeScript
import { TopicValidatorResult } from "@libp2p/interface/pubsub";
|
|
import type { UnsignedMessage } from "@libp2p/interface/pubsub";
|
|
import { createSecp256k1PeerId } from "@libp2p/peer-id-factory";
|
|
import { createEncoder } from "@waku/core";
|
|
import { expect } from "chai";
|
|
import fc from "fast-check";
|
|
|
|
import { messageValidator } from "./message_validator.js";
|
|
|
|
describe("Message Validator", () => {
|
|
it("Accepts a valid Waku Message", async () => {
|
|
await fc.assert(
|
|
fc.asyncProperty(
|
|
fc.uint8Array({ minLength: 1 }),
|
|
fc.string({ minLength: 1 }),
|
|
fc.string({ minLength: 1 }),
|
|
async (payload, pubSubTopic, contentTopic) => {
|
|
const peerId = await createSecp256k1PeerId();
|
|
|
|
const encoder = createEncoder({ contentTopic });
|
|
const bytes = await encoder.toWire({ payload });
|
|
|
|
const message: UnsignedMessage = {
|
|
type: "unsigned",
|
|
topic: pubSubTopic,
|
|
data: bytes
|
|
};
|
|
|
|
const result = messageValidator(peerId, message);
|
|
|
|
expect(result).to.eq(TopicValidatorResult.Accept);
|
|
}
|
|
)
|
|
);
|
|
});
|
|
|
|
it("Rejects garbage", async () => {
|
|
await fc.assert(
|
|
fc.asyncProperty(
|
|
fc.uint8Array(),
|
|
fc.string(),
|
|
async (data, pubSubTopic) => {
|
|
const peerId = await createSecp256k1PeerId();
|
|
|
|
const message: UnsignedMessage = {
|
|
type: "unsigned",
|
|
topic: pubSubTopic,
|
|
data
|
|
};
|
|
|
|
const result = messageValidator(peerId, message);
|
|
|
|
expect(result).to.eq(TopicValidatorResult.Reject);
|
|
}
|
|
)
|
|
);
|
|
});
|
|
});
|