clone

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

dependabot/github_actions/actions-9b61906d8b
bindws / test / unit / margin.test.ts
margin.test.ts 1.6K
1import { spawnSync } from "node:child_process";2import { fileURLToPath } from "node:url";3import { describe, expect, it } from "vitest";45const script = fileURLToPath(new URL("../../scripts/ops/margin.mjs", import.meta.url).href);6const forecast = (...args: string[]) => spawnSync(process.execPath, [script, ...args], { encoding: "utf8" });78describe("margin", () => {9 it("uses gross margin for target prices and keeps the default target unchanged", () => {10 const result = forecast("--btc", "80000", "--target", "0.4");11 expect(result.status).toBe(1);12 expect(result.stdout).toContain("price is cost / 0.60; 67% markup on cost");13 expect(result.stdout).toContain("$83,333 | 417 sats");14 expect(result.stdout).toContain("$83,333 | 32 sats");15 expect(result.stdout).toContain("$87,273 | 13 sats");16 expect(result.stdout).toContain("$83,333 | 2,084 sats");17 const normal = forecast("--btc", "80000");18 expect(normal.status).toBe(0);19 expect(normal.stdout).toContain("Target gross margin 33%");20 });2122 it("discounts incoming socket messages once and pools the account request allowance once", () => {23 const result = forecast("--btc", "100000", "--relays", "1000");24 expect(result.status).toBe(0);25 // 950 * (10k + 290k/20) + 50 * (200k + 4.8M/20) = 45.275M.26 // Less one pooled 1M allowance, at $0.15/M, gives $6.64125.27 expect(result.stdout).toContain("DO requests $6.64");28 // 950 * 10k + 50 * 200k = 19.5M Worker requests; frames stay in the DO.29 expect(result.stdout).toContain("Worker requests $2.85");30 expect(result.stdout).toContain("not an invoice");31 });32});