minPow 4 let one random id in sixteen through, so the assertion flaked.
- commit
- 17a6c6311335e4d891682a3b6533afab2d755076
- parent
- b534808e0097592d2fab57cd0043c9d5a52cda65
- author
- Dami <dami.etoile@gmail.com>
| M | test/ | 6 | +++++- |
@@ -3,6 +3,7 @@ import { describe, it, expect } from "vitest";
33 import { finalizeEvent, generateSecretKey, getPublicKey, type Event } from "nostr-tools/pure";44 import { getToken } from "nostr-tools/nip98";55 import type { Relay } from "../src/relay.ts";6+import { difficulty } from "../src/event.ts";67 78 const now = () => Math.floor(Date.now() / 1000);89 const ev = (sk: Uint8Array, kind: number, content: string, tags: string[][] = [], created_at = now()) => finalizeEvent({ kind, content, tags, created_at }, sk);@@ -172,7 +173,10 @@ describe("policy", () => {
172173 173174 // proof of work174175 await rpc(host, owner, "setpolicy", { minPow: 4 });175- expect((await c.ok(ev(stranger, 1, "weak"))).msg).toMatch(/^pow:/);176+ // One random id in sixteen starts with a zero nibble and would pass; pick one that does not.177+ let weak = ev(stranger, 1, "weak");178+ while (difficulty(weak).difficulty >= 4) weak = ev(stranger, 1, "weak " + Math.random());179+ expect((await c.ok(weak)).msg).toMatch(/^pow:/);176180 await rpc(host, owner, "setpolicy", { minPow: 0 });177181 178182 // reads need auth