clone

nostr relays on demand at <name>.bind.ws: claim one with your key, pay in zaps past the free allowance

dependabot/npm_and_yarn/npm-f01a459b0f
bindws / test / object / templates.test.ts
templates.test.ts 2.6K
1// Every template in relay-templates/ boots a relay that says what the2// template declares: the features in the policy, the numbers in NIP-11,3// the doors that answer, and a dry run of the template afterwards that4// changes nothing. The schema the files reference is served at the apex.5import { SELF } from "cloudflare:test";6import { describe, it, expect } from "vitest";7import { generateSecretKey } from "nostr-tools/pure";8import { PRESETS } from "../../src/presets.ts";9import { FEATURE_NIPS } from "../../src/nip11.ts";10import { DEFAULT_FEATURES, FEATURE_NAMES, featureOn } from "../../src/settings.ts";11import { rpc, info, get } from "../helpers/relay.ts";1213describe("templates", () => {14 it("each boots a relay that matches its document, and a dry run of it afterwards changes nothing", async () => {15 for (const p of PRESETS) {16 const host = `tpl-${p.name}.bind.ws`;17 const owner = generateSecretKey();18 await rpc(host, owner, "claim");19 const r = await rpc(host, owner, "applypreset", p.name, p.source ? { source: "wss://source.example" } : undefined);20 expect(r.status, p.name + " " + JSON.stringify(r)).toBe(200);21 const policy = (await rpc(host, owner, "getpolicy")).result;22 const features = { ...DEFAULT_FEATURES, ...(p.config.policy.features ?? {}) };23 expect(policy.features, p.name).toEqual(features);24 expect(policy.writes).toBe(p.writes);25 const doc = await info(host);26 for (const f of FEATURE_NAMES) for (const n of FEATURE_NIPS[f]) expect(doc.supported_nips.includes(n), `${p.name}: NIP-${n}`).toBe(featureOn(policy, f));27 expect((await get(host, "/.well-known/nostr/nip96.json")).status).toBe(features.files ? 200 : 404);28 expect((await get(host, "/feed.xml")).status).toBe(features.pages && p.reads === "open" ? 200 : 404);29 const dry = (await rpc(host, owner, "importconfig", p.config === undefined ? {} : { format: "bind.ws/relay-config/2", policy: p.config.policy, kinds: p.config.kinds, retention: p.config.retention, ...(p.config.sections.includes("connections") ? { connections: p.config.connections } : {}) }, { dryRun: true })).result;30 expect(dry.changes.summary, p.name).toEqual([]);31 expect(dry.warnings, p.name).toEqual([]);32 }33 });3435 it("serves the configuration schema at the apex", async () => {36 const resp = await SELF.fetch("http://bind.ws/relay-config.schema.json");37 expect(resp.status).toBe(200);38 const schema: any = await resp.json();39 expect(schema.title).toBe("bind.ws relay configuration");40 expect(schema.properties.policy.properties.features.properties.search.enum).toEqual(["full", "prose", "off"]);41 });42});