| 1 | import { describe, it, expect } from "vitest" ; |
| 2 | import { newEvent, newKey, now, sleep, sockets } from "./helpers.ts" ; |
| 3 | |
| 4 | const connect = sockets(); |
| 5 | |
| 6 | describe("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 | }); |