// Self-test: a live 1 SOL -> USDC quote plus offline checks of the amount maths. Run: node test.mjs import { pathToFileURL } from "node:url"; import { quote, toBaseUnits, fromBaseUnits } from "./scripts/quote.mjs"; export default async function test() { const checks = []; const check = (name, ok) => checks.push({ name, ok: Boolean(ok) }); check("converts 2.5 SOL to lamports", toBaseUnits("2.5", 9) === 2500000000n); check("converts base units back", fromBaseUnits("1234500", 6) === 1.2345); const r = await quote("SOL", "USDC", "1", { slippageBps: 50 }); check("quotes a positive USDC amount", r.output.amount > 0); check("minimum is at most the quote", r.output.minimum <= r.output.amount); check("has a route", r.route.length > 0); check("price impact is a number", Number.isFinite(r.priceImpactPct)); let rejected = false; try { await quote("SOL", "SOL", "1"); } catch { rejected = true; } check("rejects a same-token swap", 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); }); }