scripts/smoke.ts
v0.1.0 · 1.6 KB
// Public reads only. No account, key, signing, simulation, or order endpoints.
import { createRestClient, decodeMarkets, MAX_LIMIT_ORDERS_PER_SIDE } from '../src/index.js';
let failures = 0;
function check(label: string, ok: boolean) {
if (!ok) failures++;
console.log(`${ok ? 'ok ' : 'FAIL'} ${label}`);
}
function policy(name: string): number {
const raw = process.env[`PHX_KIT_SMOKE_${name}`];
if (raw === undefined || !/^[0-9]+$/.test(raw)) throw new TypeError(`Set PHX_KIT_SMOKE_${name}`);
return Number(raw);
}
async function main() {
const client = createRestClient({
minGapMs: policy('GAP_MS'),
tries: policy('TRIES'),
timeoutMs: policy('TIMEOUT_MS'),
retryDelayMs: policy('RETRY_MS'),
retryAfterMaxMs: policy('RETRY_AFTER_MAX_MS'),
retryAfterFallbackMs: policy('RETRY_AFTER_FALLBACK_MS'),
});
const status = await client.exchangeStatus();
check('exchange status readable', typeof status.active === 'boolean');
const markets = decodeMarkets(await client.markets());
check('non-empty market list', markets.size > 0);
const mids = await client.allMids();
check('mark prices readable', Object.keys(mids).length > 0);
check('SDK side limit', MAX_LIMIT_ORDERS_PER_SIDE === 64);
const symbol = markets.keys().next().value;
if (symbol) check('orderbook readable', (await client.orderbook(symbol)) !== null);
}
main()
.catch((e) => {
failures++;
console.error('FAIL smoke crashed:', (e as Error).message);
})
.finally(() => {
console.log(failures === 0 ? 'SMOKE PASSED' : `SMOKE FAILED (${failures})`);
process.exitCode = failures === 0 ? 0 : 1;
});