tinyrelayfile
tinyrelay/scripts/conformance/nip40.test.ts/

scripts/conformance/nip40.test.ts raw
1import { describe, it, expect } from "vitest";
2import { newEvent, newKey, now, sleep, sockets } from "./helpers.ts";
3
4const connect = sockets();
5
6describe("NIP-40 expiration", () => {
7 it("refuses expired events, serves unexpired ones, and stops serving after expiry", async () => {
8 const sk = newKey();
9 const c = await connect();
10 const dead = newEvent(sk, 1, "gone", [["expiration", String(now() - 1)]]);
11 c.send("EVENT", dead);
12 expect(await c.expectOK(dead.id, false)).toMatch(/expired/);
13 const soon = newEvent(sk, 1, "soon", [["expiration", String(now() + 2)]]);
14 await c.publish(soon);
15 expect((await c.req({ ids: [soon.id] })).events.length).toBe(1);
16 await sleep(2500);
17 expect((await c.req({ ids: [soon.id] })).events.length).toBe(0);
18 c.send("COUNT", "q", { ids: [soon.id] });
19 expect((await c.expect("COUNT"))[2].count).toBe(0);
20 });
21});

About

ownerc01503e8035f
visibilitypublic
headd730679639bf

Maintainers

  • c01503e8035f owner
  • ba1b5beed5b5 agent hermes

Clone

  • https://012.run/npub1cq2s86qrtadf36eqq3epm38wmhdynrrcwxf84eldk3f94dkv7ttsrulrz5/tinyrelay.git

Refs