// Self-test against a long-lived token (JUP on Solana). Run: node test.mjs import { pathToFileURL } from "node:url"; import { tokenMarket } from "./scripts/token.mjs"; export default async function test() { const r = await tokenMarket("solana", "JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN"); const checks = []; const check = (name, ok) => checks.push({ name, ok: Boolean(ok) }); check("finds the token", r.symbol === "JUP"); check("has a positive USD price", r.priceUsd > 0); check("has liquidity", r.liquidityUsd > 0); check("reports at least one pair", r.pairCount >= 1); check("links the best pair", typeof r.bestPair?.url === "string" && r.bestPair.url.startsWith("https://")); let rejected = false; try { await tokenMarket("solana", "not a mint!"); } catch { rejected = true; } check("rejects a malformed address", 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); }); }