// Self-test against a long-lived token (JUP on Solana). Run: node test.mjs import { pathToFileURL } from "node:url"; import { holders } from "./scripts/holders.mjs"; export default async function test() { const r = await holders("JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN", { rpcUrl: "" }); const checks = []; const check = (name, ok) => checks.push({ name, ok: Boolean(ok) }); check("finds the token", r.symbol === "JUP"); check("has a holder count", r.holderCount > 1000); check("top holder share is a percentage", r.topHoldersPct === null || (r.topHoldersPct >= 0 && r.topHoldersPct <= 100)); check("reports mint authority", typeof r.mintAuthorityDisabled === "boolean"); check("skips the RPC list without SOLANA_RPC_URL", r.largest === null); let rejected = false; try { await holders("not-a-mint"); } catch { rejected = true; } check("rejects a malformed mint", rejected); return { ok: checks.every((c) => c.ok), checks }; } if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) { test().then((r) => { console.log(JSON.stringify(r, null, 2)); process.exit(r.ok ? 0 : 1); }, (e) => { console.log(JSON.stringify({ ok: false, error: String(e?.message ?? e) })); process.exit(1); }); }