Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

test: cover the network identities, gateway race, curve gate and launch history

nirholas1fb13af009e8
diff --git a/api/_lib/x402/revenue-networks.js b/api/_lib/x402/revenue-networks.js
index 9239b305e..2efe172d3 100644
--- a/api/_lib/x402/revenue-networks.js
+++ b/api/_lib/x402/revenue-networks.js
@@ -150,7 +150,13 @@ export function resolveNetworkFilter(input) {
if (byId) return { family: byId.family, ids: [...byId.ids] };
const evm = /^(?:eip155-|eip155:)(\d{1,9})$/.exec(v);
- if (evm) return { family: `eip155-${evm[1]}`, ids: [`eip155:${evm[1]}`] };
+ if (evm) {
+ // A named chain reached through its numeric form still resolves to its
+ // family, so '?network=eip155-8453' and '?network=base' select the same rows.
+ const named = BY_ID.get(`eip155:${evm[1]}`);
+ if (named) return { family: named.family, ids: [...named.ids] };
+ return { family: `eip155-${evm[1]}`, ids: [`eip155:${evm[1]}`] };
+ }
return null;
}
diff --git a/src/pump/coin-status-card.curve.dom.test.js b/src/pump/coin-status-card.curve.dom.test.js
new file mode 100644
index 000000000..7ccf9437b
--- /dev/null
+++ b/src/pump/coin-status-card.curve.dom.test.js
@@ -0,0 +1,172 @@
+// @vitest-environment jsdom
+//
+// DOM-level tests for the cluster-sourced lane of mountCoinStatus: the bonding
+// curve read straight off Solana. This is the only market source that exists on
+// devnet (where every free agent-token rehearsal launch lands) and the fallback
+// on mainnet while pump.fun's indexer has not caught up to a fresh launch.
+//
+// fetch is stubbed at the global boundary and asserted on by URL, so these also
+// pin WHICH endpoint each network talks to.
+
+import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
+import { mountCoinStatus } from './coin-status-card.js';
+
+// A three.ws-launched mint: the "3ws" brand mark leads the address (pump.fun's
+// own launcher grinds a "pump" suffix instead — both carry a bonding curve).
+const MINT = '3wsSynthetic11111111111111111111111111111';
+
+function curveBody(overrides = {}) {
+ return {
+ mint: MINT,
+ network: 'devnet',
+ curve: { realSolReserves: '1200000000', complete: false },
+ price: { marketCap: '32000000000', buyPricePerToken: '32' },
+ graduation: { progressBps: 1500, solAccumulated: '1200000000' },
+ ...overrides,
+ };
+}
+
+function coinBody() {
+ return {
+ mint: MINT,
+ name: 'Indexed Coin',
+ symbol: 'IDX',
+ usd_market_cap: 34_500,
+ total_supply: 1_000_000_000_000_000,
+ complete: false,
+ created_timestamp: Date.now() - 60_000,
+ };
+}
+
+/** Route the stub by URL so a test asserts on real endpoint choice, not order. */
+function routedFetch(routes) {
+ return vi.fn((url) => {
+ const href = String(url);
+ for (const [needle, handler] of routes) {
+ if (href.includes(needle)) return handler(href);
+ }
+ return Promise.resolve({ ok: false, status: 404, json: () => Promise.resolve({}) });
+ });
+}
+
+const ok = (body) => () => Promise.resolve({ ok: true, status: 200, json: () => Promise.resolve(body) });
+const notFound = () => () => Promise.resolve({ ok: false, status: 404, json: () => Promise.resolve({}) });
+
+let container;
+
+beforeEach(() => {
+ container = document.createElement('div');
+ document.body.appendChild(container);
+});
+
+afterEach(() => {
+ container.remove();
+ vi.restoreAllMocks();
+ vi.useRealTimers();
+});
+
+describe('mountCoinStatus — devnet lane', () => {
+ it('reads the cluster curve and renders SOL-denominated market state', async () => {
+ const fetchMock = routedFetch([['/api/pump/curve', ok(curveBody())]]);
+ vi.stubGlobal('fetch', fetchMock);
+
+ const handle = mountCoinStatus(container, MINT, {
+ variant: 'chip',
+ refreshMs: 0,
+ network: 'devnet',
+ meta: { symbol: 'RSL', name: 'Rehearsal' },
+ });
+ await vi.waitFor(() => expect(container.querySelector('.csc-sym')).toBeTruthy());
+
+ expect(container.querySelector('.csc-sym').textContent).toBe('$RSL');
+ expect(container.querySelector('.csc-mcap').textContent).toBe('◎32.00');
+ expect(container.querySelector('.csc-price').textContent).toBe('◎0.000000032');
+ expect(container.querySelector('.csc-grad').textContent).toBe('15% to grad');
+ handle.destroy();
+ });
+
+ it('marks the coin DEVNET so real curve numbers never read as a live market', async () => {
+ vi.stubGlobal('fetch', routedFetch([['/api/pump/curve', ok(curveBody())]]));
+ const handle = mountCoinStatus(container, MINT, { variant: 'chip', refreshMs: 0, network: 'devnet' });
+ await vi.waitFor(() => expect(container.querySelector('.csc-net')).toBeTruthy());
+
+ expect(container.querySelector('.csc-net').textContent).toBe('DEVNET');
+ handle.destroy();
+ });
+
+ it('never asks the mainnet-only indexer or the Oracle about a devnet coin', async () => {
+ const fetchMock = routedFetch([['/api/pump/curve', ok(curveBody())]]);
+ vi.stubGlobal('fetch', fetchMock);
+
+ const handle = mountCoinStatus(container, MINT, { variant: 'card', refreshMs: 0, network: 'devnet' });
+ await vi.waitFor(() => expect(container.querySelector('.csc-card-name')).toBeTruthy());
+
+ const called = fetchMock.mock.calls.map(([u]) => String(u));
+ expect(called.some((u) => u.includes('/api/pump/curve'))).toBe(true);
+ expect(called.some((u) => u.includes('/api/pump/coin'))).toBe(false);
+ expect(called.some((u) => u.includes('/api/oracle/coin'))).toBe(false);
+ // Devnet SOL is not worth dollars, so no USD rate is fetched either.
+ expect(called.some((u) => u.includes('jup.ag'))).toBe(false);
+ handle.destroy();
+ });
+
+ it('links a devnet coin to the explorer, which is the only page it has', async () => {
+ vi.stubGlobal('fetch', routedFetch([['/api/pump/curve', ok(curveBody())]]));
+ const handle = mountCoinStatus(container, MINT, {
+ variant: 'card',
+ refreshMs: 0,
+ network: 'devnet',
+ showBuy: true,
+ });
+ await vi.waitFor(() => expect(container.querySelector('.csc-buy')).toBeTruthy());
+
+ const link = container.querySelector('.csc-buy');
+ expect(link.getAttribute('href')).toBe(`https://explorer.solana.com/address/${MINT}?cluster=devnet`);
+ expect(link.textContent).toBe('Explorer →');
+ handle.destroy();
+ });
+
+ it('shows the error state when the cluster has no curve for the mint', async () => {
+ vi.stubGlobal('fetch', routedFetch([['/api/pump/curve', notFound()]]));
+ const handle = mountCoinStatus(container, MINT, { variant: 'chip', refreshMs: 0, network: 'devnet' });
+ await vi.waitFor(() => expect(container.querySelector('.csc-error')).toBeTruthy());
+ handle.destroy();
+ });
+});
+
+describe('mountCoinStatus — mainnet indexer fallback', () => {
+ it('falls through to the bonding curve when the indexer does not know the coin', async () => {
+ const fetchMock = routedFetch([
+ ['/api/pump/coin', notFound()],
+ ['/api/pump/curve', ok(curveBody({ network: 'mainnet' }))],
+ ['jup.ag', ok({ So11111111111111111111111111111111111111112: { usdPrice: 200 } })],
+ ]);
+ vi.stubGlobal('fetch', fetchMock);
+
+ const handle = mountCoinStatus(container, MINT, { variant: 'chip', refreshMs: 0 });
+ await vi.waitFor(() => expect(container.querySelector('.csc-mcap')).toBeTruthy());
+
+ // 32 SOL × $200 — real on-chain state, priced in dollars because mainnet
+ // SOL has a dollar price.
+ expect(container.querySelector('.csc-mcap').textContent).toBe('$6.4K');
+ expect(container.querySelector('.csc-net')).toBeNull();
+ handle.destroy();
+ });
+
+ it('prefers the indexer when it does know the coin', async () => {
+ const fetchMock = routedFetch([
+ ['/api/pump/coin', ok(coinBody())],
+ ['/api/pump/curve', ok(curveBody({ network: 'mainnet' }))],
+ ]);
+ vi.stubGlobal('fetch', fetchMock);
+
+ const handle = mountCoinStatus(container, MINT, { variant: 'chip', refreshMs: 0 });
+ await vi.waitFor(() => expect(container.querySelector('.csc-sym')).toBeTruthy());
+
+ expect(container.querySelector('.csc-sym').textContent).toBe('$IDX');
+ expect(container.querySelector('.csc-mcap').textContent).toBe('$34.5K');
+ const called = fetchMock.mock.calls.map(([u]) => String(u));
+ expect(called.some((u) => u.includes('/api/pump/curve'))).toBe(false);
+ handle.destroy();
+ });
+});
diff --git a/tests/agent-detail-launch-history.test.js b/tests/agent-detail-launch-history.test.js
new file mode 100644
index 000000000..d792b7bee
--- /dev/null
+++ b/tests/agent-detail-launch-history.test.js
@@ -0,0 +1,169 @@
+// @vitest-environment jsdom
+//
+// The launch history on /agents/:id — the profile half of the agent-token lane.
+//
+// Every coin an agent launched through three.ws is registered in
+// pump_agent_mints and read back by GET /api/pump/by-agent. The property under
+// test is that each of those rows renders LIVE market state, on whichever
+// cluster it was launched on:
+//
+// · a mainnet coin reads pump.fun's indexer (falling back to its bonding
+// curve while the indexer catches up to a fresh mint), priced in USD;
+// · a devnet coin has no indexer anywhere, so it reads its bonding curve
+// straight off the cluster, priced in SOL and badged DEVNET.
+//
+// The devnet row used to render as a lifeless symbol-and-address line, which
+// meant the free rehearsal path — the only path that proves this lane end to end
+// without spending real money — produced no market data on the profile at all.
+
+import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
+import { renderLaunchHistory, destroyCoinStatus } from '../src/agent-detail.js';
+
+const AGENT_ID = '77777777-7777-4777-8777-777777777777';
+const DEVNET_MINT = '3wsRehearsal111111111111111111111111111111';
+const MAINNET_MINT = '3wsLivecoin1111111111111111111111111111111';
+
+function launches(coins) {
+ return { ok: true, status: 200, json: () => Promise.resolve({ coins }) };
+}
+
+function curveBody(network) {
+ return {
+ ok: true,
+ status: 200,
+ json: () =>
+ Promise.resolve({
+ mint: network === 'devnet' ? DEVNET_MINT : MAINNET_MINT,
+ network,
+ curve: { realSolReserves: '1200000000', complete: false },
+ price: { marketCap: '32000000000', buyPricePerToken: '32' },
+ graduation: { progressBps: 1500, solAccumulated: '1200000000' },
+ }),
+ };
+}
+
+function indexedCoin() {
+ return {
+ ok: true,
+ status: 200,
+ json: () =>
+ Promise.resolve({
+ mint: MAINNET_MINT,
+ symbol: 'LIVE',
+ name: 'Live Coin',
+ usd_market_cap: 34_500,
+ total_supply: 1_000_000_000_000_000,
+ complete: false,
+ created_timestamp: Date.now() - 60_000,
+ }),
+ };
+}
+
+const DEVNET_ROW = {
+ mint: DEVNET_MINT,
+ network: 'devnet',
+ name: 'Rehearsal',
+ symbol: 'RSL',
+ created_at: new Date(Date.now() - 3 * 60_000).toISOString(),
+};
+const MAINNET_ROW = {
+ mint: MAINNET_MINT,
+ network: 'mainnet',
+ name: 'Live Coin',
+ symbol: 'LIVE',
+ created_at: new Date(Date.now() - 9 * 60_000).toISOString(),
+};
+
+/** Stub fetch by URL so the assertions pin real endpoint choice, not call order. */
+function stubRoutes(routes) {
+ const mock = vi.fn((url) => {
+ const href = String(url);
+ for (const [needle, handler] of routes) {
+ if (href.includes(needle)) return Promise.resolve(handler());
+ }
+ return Promise.resolve({ ok: false, status: 404, json: () => Promise.resolve({}) });
+ });
+ vi.stubGlobal('fetch', mock);
+ return mock;
+}
+
+let container;
+
+beforeEach(() => {
+ document.body.innerHTML = '<div id="ad-token-card" hidden><div id="host"></div></div>';
+ container = document.getElementById('host');
+});
+
+afterEach(() => {
+ destroyCoinStatus();
+ vi.restoreAllMocks();
+});
+
+describe('renderLaunchHistory', () => {
+ it('renders a devnet launch with live SOL-denominated curve state', async () => {
+ stubRoutes([
+ ['/api/pump/by-agent', () => launches([DEVNET_ROW])],
+ ['/api/pump/curve', () => curveBody('devnet')],
+ ]);
+
+ await renderLaunchHistory(container, { id: AGENT_ID });
+ await vi.waitFor(() => expect(container.querySelector('.csc-mcap')).toBeTruthy());
+
+ expect(container.querySelector('.csc-sym').textContent).toBe('$RSL');
+ expect(container.querySelector('.csc-mcap').textContent).toBe('◎32.00');
+ expect(container.querySelector('.csc-net').textContent).toBe('DEVNET');
+ });
+
+ it('sends each row to the market source its own cluster has', async () => {
+ const fetchMock = stubRoutes([
+ ['/api/pump/by-agent', () => launches([DEVNET_ROW, MAINNET_ROW])],
+ ['/api/pump/curve', () => curveBody('devnet')],
+ ['/api/pump/coin', () => indexedCoin()],
+ ]);
+
+ await renderLaunchHistory(container, { id: AGENT_ID });
+ await vi.waitFor(() => expect(container.querySelectorAll('.csc-mcap').length).toBe(2));
+
+ const called = fetchMock.mock.calls.map(([u]) => String(u));
+ expect(called.some((u) => u.includes('/api/pump/curve') && u.includes('network=devnet'))).toBe(true);
+ expect(called.some((u) => u.includes(`/api/pump/coin?mint=${MAINNET_MINT}`))).toBe(true);
+ // The devnet mint must never be sent to the mainnet-only indexer.
+ expect(called.some((u) => u.includes('/api/pump/coin') && u.includes(DEVNET_MINT))).toBe(false);
+ });
+
+ it('links a devnet row to the explorer and a mainnet row to its three.ws coin page', async () => {
+ stubRoutes([
+ ['/api/pump/by-agent', () => launches([DEVNET_ROW, MAINNET_ROW])],
+ ['/api/pump/curve', () => curveBody('devnet')],
+ ['/api/pump/coin', () => indexedCoin()],
+ ]);
+
+ await renderLaunchHistory(container, { id: AGENT_ID });
+
+ const hrefs = [...container.querySelectorAll('a.ad-launch-row')].map((a) => a.getAttribute('href'));
+ expect(hrefs).toContain(`https://explorer.solana.com/address/${DEVNET_MINT}?cluster=devnet`);
+ expect(hrefs).toContain(`/launches/${MAINNET_MINT}`);
+ });
+
+ it('reveals the token card and the public feed link when any launch exists', async () => {
+ stubRoutes([
+ ['/api/pump/by-agent', () => launches([DEVNET_ROW])],
+ ['/api/pump/curve', () => curveBody('devnet')],
+ ]);
+
+ await renderLaunchHistory(container, { id: AGENT_ID });
+
+ expect(document.getElementById('ad-token-card').hidden).toBe(false);
+ const feed = container.querySelector('.ad-launch-feed-link');
+ expect(feed.getAttribute('href')).toBe(`/launches?agent_id=${AGENT_ID}`);
+ });
+
+ it('renders nothing when the agent has never launched a coin', async () => {
+ stubRoutes([['/api/pump/by-agent', () => launches([])]]);
+
+ await renderLaunchHistory(container, { id: AGENT_ID });
+
+ expect(container.querySelector('.ad-launch-history')).toBeNull();
+ expect(document.getElementById('ad-token-card').hidden).toBe(true);
+ });
+});
diff --git a/tests/ipfs-gateway-fetch.test.js b/tests/ipfs-gateway-fetch.test.js
new file mode 100644
index 000000000..2f553cc20
--- /dev/null
+++ b/tests/ipfs-gateway-fetch.test.js
@@ -0,0 +1,130 @@
+// Reading content-addressed bytes back off IPFS.
+//
+// This is the retrieval half of signed agent manifests (specs/AGENT_MANIFEST.md
+// § Signed envelope). It is the path an outside verifier walks, so its failure
+// modes are the ones that decide whether "anyone can check this" is true or
+// merely claimed. Two of them are covered here because both have bitten us:
+// a retired gateway left in the fallback chain, and a serial walk that lets one
+// hung gateway decide the whole read timed out.
+
+import { describe, it, expect, afterEach, vi } from 'vitest';
+
+import { IPFS_READ_GATEWAYS, fetchFromGateways } from '../api/_lib/ipfs-pin.js';
+
+const CID = 'Qmc2vc5fgpQX9m5d2YJS7XvdAfF1yQLJpRyQtrHyW3kVy1';
+
+const realFetch = globalThis.fetch;
+afterEach(() => {
+ globalThis.fetch = realFetch;
+ vi.restoreAllMocks();
+});
+
+/** A fetch stub driven by a per-host script of outcomes. */
+function stubFetch(plan) {
+ const seen = [];
+ globalThis.fetch = vi.fn(async (url) => {
+ seen.push(url);
+ const entry = Object.entries(plan).find(([host]) => String(url).includes(host));
+ const outcome = entry ? entry[1] : { status: 504 };
+ if (outcome.delayMs) await new Promise((r) => setTimeout(r, outcome.delayMs));
+ if (outcome.throws) throw new Error(outcome.throws);
+ return {
+ ok: !outcome.status || outcome.status === 200,
+ status: outcome.status || 200,
+ headers: { get: (h) => (h === 'content-length' ? String(outcome.length ?? (outcome.body || '').length) : null) },
+ text: async () => outcome.body ?? '',
+ };
+ });
+ return seen;
+}
+
+describe('IPFS_READ_GATEWAYS', () => {
+ // Cloudflare retired both of its public gateways in 2024 and flk-ipfs.xyz
+ // stopped accepting connections. A dead host in a fallback chain is worse
+ // than a missing one: it consumes the retry budget and reports a DNS failure
+ // as though the document were unretrievable.
+ it('lists no retired gateway hosts', () => {
+ const retired = ['cloudflare-ipfs.com', 'cf-ipfs.com', 'flk-ipfs.xyz'];
+ for (const host of retired) {
+ expect(IPFS_READ_GATEWAYS.some((g) => g.includes(host))).toBe(false);
+ }
+ });
+
+ it('leads with gateways that are independent of the platform and its pinning vendor', () => {
+ expect(IPFS_READ_GATEWAYS[0]).toContain('ipfs.io');
+ expect(IPFS_READ_GATEWAYS.some((g) => g.includes('three.ws'))).toBe(false);
+ });
+
+ // A freshly pinned CID can take hours to propagate across the DHT. Until it
+ // does, the pinning provider's own gateway is the only copy in existence, so
+ // dropping it would make every just-published manifest unverifiable.
+ it('keeps the pinning provider gateway as the guaranteed-complete copy', () => {
+ expect(IPFS_READ_GATEWAYS.some((g) => g.includes('pinata'))).toBe(true);
+ });
+});
+
+describe('fetchFromGateways', () => {
+ it('returns the body and the gateway that actually served it', async () => {
+ stubFetch({ 'ipfs.io': { body: '{"ok":true}' } });
+ const got = await fetchFromGateways(CID);
+ expect(JSON.parse(got.text)).toEqual({ ok: true });
+ expect(got.gateway).toBe(`https://ipfs.io/ipfs/${CID}`);
+ });
+
+ it('takes the one gateway holding the document when the rest 504', async () => {
+ stubFetch({
+ 'ipfs.io': { status: 504 },
+ 'dweb.link': { status: 504 },
+ 'w3s.link': { status: 504 },
+ 'pinata': { body: '{"pinned":true}' },
+ });
+ const got = await fetchFromGateways(CID);
+ expect(got.gateway).toContain('pinata');
+ expect(JSON.parse(got.text)).toEqual({ pinned: true });
+ });
+
+ // The regression this guards: walking the list serially made the slowest
+ // gateway the floor on every read, so a document one gateway could serve
+ // immediately sat behind the timeouts of the ones that could not.
+ it('queries every gateway concurrently rather than waiting out the slow ones', async () => {
+ const seen = stubFetch({
+ 'ipfs.io': { delayMs: 60, status: 504 },
+ 'dweb.link': { delayMs: 60, status: 504 },
+ 'w3s.link': { delayMs: 60, status: 504 },
+ 'pinata': { body: '{"fast":true}' },
+ });
+ const started = Date.now();
+ const got = await fetchFromGateways(CID);
+ const elapsed = Date.now() - started;
+
+ expect(got.gateway).toContain('pinata');
+ expect(seen).toHaveLength(IPFS_READ_GATEWAYS.length);
+ // Serial would have paid all three 60ms delays before reaching the winner.
+ expect(elapsed).toBeLessThan(120);
+ });
+
+ it('reports every gateway it tried when none of them serve the CID', async () => {
+ stubFetch({
+ 'ipfs.io': { status: 504 },
+ 'dweb.link': { throws: 'ENOTFOUND' },
+ 'w3s.link': { status: 404 },
+ 'pinata': { status: 403 },
+ });
+ await expect(fetchFromGateways(CID)).rejects.toMatchObject({ code: 'gateway_unreachable' });
+ await expect(fetchFromGateways(CID)).rejects.toThrow(/504.*ENOTFOUND|ENOTFOUND.*504/s);
+ });
+
+ it('refuses a body larger than the budget the caller set', async () => {
+ stubFetch({ 'ipfs.io': { body: 'x'.repeat(500), length: 500 } });
+ await expect(fetchFromGateways(CID, { maxBytes: 100 })).rejects.toMatchObject({
+ code: 'gateway_unreachable',
+ });
+ });
+
+ it('honors an explicit gateway list', async () => {
+ const seen = stubFetch({ 'example.test': { body: '{}' } });
+ const got = await fetchFromGateways(CID, { gateways: ['https://example.test/ipfs/'] });
+ expect(seen).toEqual([`https://example.test/ipfs/${CID}`]);
+ expect(got.gateway).toContain('example.test');
+ });
+});
diff --git a/tests/pump-curve-mint-gate.test.js b/tests/pump-curve-mint-gate.test.js
new file mode 100644
index 000000000..5e4101d66
--- /dev/null
+++ b/tests/pump-curve-mint-gate.test.js
@@ -0,0 +1,61 @@
+// The address-only pre-filter that decides whether a mint can carry a pump.fun
+// bonding curve at all.
+//
+// It exists in two copies on purpose — one in the API (api/_lib/pump-curve-view.js,
+// guarding an RPC read and a 300s-cached 404) and one in the browser widget
+// (src/widgets/bonding-curve.js, guarding the request itself). They must agree:
+// a mint the server would answer for and the widget refuses to ask about renders
+// as permanently empty, and the reverse produces a 404 storm.
+//
+// The case that matters here is three.ws's own launches. pump.fun grinds its
+// mints to END in "pump"; three.ws grinds its own to CARRY the "3ws" mark as a
+// PREFIX (src/solana/vanity/brand.js). Every agent token this platform mints
+// therefore fails a suffix-only test, which is what used to make the curve read
+// for our own coins impossible.
+
+import { describe, it, expect } from 'vitest';
+import { isPumpMint as isPumpMintServer } from '../api/_lib/pump-curve-view.js';
+import { isPumpMint as isPumpMintClient } from '../src/widgets/bonding-curve.js';
+import { THREE_WS_MARK } from '../src/solana/vanity/brand.js';
+
+// Every gate must answer identically on both sides of the wire.
+const GATES = [
+ ['api/_lib/pump-curve-view.js', isPumpMintServer],
+ ['src/widgets/bonding-curve.js', isPumpMintClient],
+];
+
+const THREE_WS_LAUNCH = '3wsSynthetic11111111111111111111111111111';
+const PUMP_LAUNCH = 'FeMbDoX7R1Psc4GEcvJdsbNbZA3bfztcyDCatJVJpump';
+const USDC_MAINNET = 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v';
+const USDC_DEVNET = '4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU';
+const WRAPPED_SOL = 'So11111111111111111111111111111111111111112';
+
+describe.each(GATES)('isPumpMint (%s)', (_label, isPumpMint) => {
+ it('accepts a three.ws-marked mint, which is what every agent token is', () => {
+ expect(isPumpMint(THREE_WS_LAUNCH)).toBe(true);
+ });
+
+ it('accepts the mark case-insensitively, matching how it is ground', () => {
+ expect(isPumpMint(`${THREE_WS_MARK.toUpperCase()}Synthetic1111111111111111111111111`)).toBe(true);
+ });
+
+ it('still accepts a pump.fun-ground mint', () => {
+ expect(isPumpMint(PUMP_LAUNCH)).toBe(true);
+ });
+
+ it('rejects settlement and native tokens, which never carry a curve', () => {
+ expect(isPumpMint(USDC_MAINNET)).toBe(false);
+ expect(isPumpMint(USDC_DEVNET)).toBe(false);
+ expect(isPumpMint(WRAPPED_SOL)).toBe(false);
+ });
+
+ it('rejects an unrelated address so a stray mount cannot start a 404 storm', () => {
+ expect(isPumpMint('9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM')).toBe(false);
+ });
+
+ it('rejects non-string input', () => {
+ expect(isPumpMint('')).toBe(false);
+ expect(isPumpMint(null)).toBe(false);
+ expect(isPumpMint(undefined)).toBe(false);
+ });
+});
diff --git a/tests/x402-revenue-networks.test.js b/tests/x402-revenue-networks.test.js
new file mode 100644
index 000000000..8aa33375a
--- /dev/null
+++ b/tests/x402-revenue-networks.test.js
@@ -0,0 +1,134 @@
+import { describe, it, expect } from 'vitest';
+
+import {
+ networkIdentity,
+ networkLabel,
+ resolveNetworkFilter,
+ revenueTxUrl,
+ foldNetworkRows,
+} from '../api/_lib/x402/revenue-networks.js';
+
+// The exact values the live revenue ledger stores (read off /api/x402-revenue on
+// 2026-08-13): CAIP-2 ids, not the bare chain names the page used to compare
+// against. Filtering by the bare name matched zero rows, which is what these
+// tests pin down.
+const SOLANA_MAINNET = 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp';
+const BASE_MAINNET = 'eip155:8453';
+const SOL_SIG =
+ '3ZARJ7836FfMZQzGNn73SToAgFqdqwSYALkR7WA6fSaBS8Lg6McBavUoUSiADiL3e8Df4TiX7sGNzswrrAVWwN4';
+const EVM_TX = '0x389dea3d9cd25ddaeb52187cd579e5c98c89204dd718c3948028f235926c6417';
+
+describe('revenue networks: identity', () => {
+ it('folds the ledger CAIP-2 ids to a family slug and a readable label', () => {
+ expect(networkIdentity(SOLANA_MAINNET)).toMatchObject({
+ family: 'solana',
+ label: 'Solana',
+ cluster: null,
+ });
+ expect(networkIdentity(BASE_MAINNET)).toMatchObject({
+ family: 'base',
+ label: 'Base',
+ chainId: 8453,
+ });
+ expect(networkLabel('eip155:56')).toBe('BNB Chain');
+ });
+
+ it('keeps the legacy bare names on the same family as their CAIP-2 form', () => {
+ expect(networkIdentity('solana').family).toBe(networkIdentity(SOLANA_MAINNET).family);
+ expect(networkIdentity('base').family).toBe(networkIdentity(BASE_MAINNET).family);
+ expect(networkIdentity('devnet').family).toBe('solana-devnet');
+ });
+
+ it('resolves an EVM chain it has no entry for from the chain table', () => {
+ expect(networkIdentity('eip155:42161')).toMatchObject({
+ family: 'arbitrum',
+ label: 'Arbitrum One',
+ });
+ expect(networkIdentity('eip155:987654')).toMatchObject({
+ family: 'eip155-987654',
+ label: 'EVM chain 987654',
+ explorer: null,
+ });
+ });
+
+ it('never throws on a missing or malformed value', () => {
+ for (const v of [null, undefined, '', ' ', 'nonsense', 42]) {
+ expect(networkIdentity(v).family).toBe('unknown');
+ }
+ });
+});
+
+describe('revenue networks: filter resolution', () => {
+ it('selects the raw ids the ledger actually holds for a family', () => {
+ const solana = resolveNetworkFilter('solana');
+ expect(solana.family).toBe('solana');
+ expect(solana.ids).toContain(SOLANA_MAINNET);
+
+ const base = resolveNetworkFilter('base');
+ expect(base.family).toBe('base');
+ expect(base.ids).toContain(BASE_MAINNET);
+ });
+
+ it('accepts a family slug, a legacy name, or a full CAIP-2 id', () => {
+ for (const input of ['solana', 'SOLANA', ' mainnet ', SOLANA_MAINNET]) {
+ expect(resolveNetworkFilter(input).family).toBe('solana');
+ }
+ expect(resolveNetworkFilter('eip155-8453').family).toBe('base');
+ expect(resolveNetworkFilter('eip155:8453').family).toBe('base');
+ });
+
+ it('returns null for an unknown value so the caller drops the filter', () => {
+ for (const v of [null, '', 'not-a-chain', '../../etc']) {
+ expect(resolveNetworkFilter(v)).toBeNull();
+ }
+ });
+
+ it('round-trips: every id a family selects folds back to that family', () => {
+ for (const family of ['solana', 'solana-devnet', 'base', 'bsc', 'ethereum', 'xlayer']) {
+ for (const id of resolveNetworkFilter(family).ids) {
+ expect(networkIdentity(id).family).toBe(family);
+ }
+ }
+ });
+});
+
+describe('revenue networks: explorer links', () => {
+ it('sends each chain to its own explorer', () => {
+ expect(revenueTxUrl(SOL_SIG, SOLANA_MAINNET)).toBe(`https://solscan.io/tx/${SOL_SIG}`);
+ expect(revenueTxUrl(EVM_TX, BASE_MAINNET)).toBe(`https://basescan.org/tx/${EVM_TX}`);
+ expect(revenueTxUrl(EVM_TX, 'eip155:56')).toBe(`https://bscscan.com/tx/${EVM_TX}`);
+ });
+
+ it('carries the cluster for non-mainnet Solana', () => {
+ expect(revenueTxUrl(SOL_SIG, 'solana:devnet')).toBe(
+ `https://solscan.io/tx/${SOL_SIG}?cluster=devnet`,
+ );
+ });
+
+ it('returns null rather than a link that lands on the wrong chain', () => {
+ expect(revenueTxUrl(EVM_TX, 'eip155:987654')).toBeNull();
+ expect(revenueTxUrl(EVM_TX, null)).toBeNull();
+ expect(revenueTxUrl('', SOLANA_MAINNET)).toBeNull();
+ expect(revenueTxUrl(null, SOLANA_MAINNET)).toBeNull();
+ });
+});
+
+describe('revenue networks: by-network folding', () => {
+ it('collapses raw ids into one row per chain, richest first', () => {
+ const folded = foldNetworkRows([
+ { network: SOLANA_MAINNET, count: 116657, gross_usd: 2145.706 },
+ { network: BASE_MAINNET, count: 45, gross_usd: 0.076 },
+ { network: 'solana', count: 3, gross_usd: 0.03 },
+ ]);
+ expect(folded).toHaveLength(2);
+ expect(folded[0]).toMatchObject({ network: 'solana', label: 'Solana', count: 116660 });
+ expect(folded[0].gross_usd).toBeCloseTo(2145.736, 6);
+ expect(folded[0].caip).toEqual([SOLANA_MAINNET, 'solana']);
+ expect(folded[1]).toMatchObject({ network: 'base', label: 'Base', count: 45 });
+ });
+
+ it('handles an empty ledger window', () => {
+ expect(foldNetworkRows([])).toEqual([]);
+ expect(foldNetworkRows(null)).toEqual([]);
+ });
+});