Skip to content
markpaper

src/index.test.ts

v0.2.0 · 2.8 KB

Download file
import { describe, expect, it } from 'vitest';
import * as kit from './index.js';

describe('package entry', () => {
  it('exposes the namespaces and the flat API', () => {
    expect(typeof kit.numbers.decimalToX18).toBe('function');
    expect(typeof kit.markets.parseSymbols).toBe('function');
    expect(typeof kit.signing.buildOrderTypedData).toBe('function');
    expect(typeof kit.transport.createGatewayClient).toBe('function');
    expect(typeof kit.account.parseSubaccountInfo).toBe('function');
    expect(typeof kit.orders.measureIocFill).toBe('function');

    expect(kit.decimalToX18).toBe(kit.numbers.decimalToX18);
    expect(kit.createQuantizer).toBe(kit.numbers.createQuantizer);
    expect(kit.parseSymbols).toBe(kit.markets.parseSymbols);
    expect(kit.createSymbolsCache).toBe(kit.markets.createSymbolsCache);
    expect(kit.subaccountBytes32).toBe(kit.signing.subaccountBytes32);
    expect(kit.buildNonce).toBe(kit.signing.buildNonce);
    expect(kit.buildAppendix).toBe(kit.signing.buildAppendix);
    expect(kit.createGatewayClient).toBe(kit.transport.createGatewayClient);
    expect(kit.createWeightThrottle).toBe(kit.transport.createWeightThrottle);
    expect(kit.interpretExecuteError).toBe(kit.transport.interpretExecuteError);
    expect(kit.readAccountSnapshot).toBe(kit.account.readAccountSnapshot);
    expect(kit.buildPlaceOrder).toBe(kit.orders.buildPlaceOrder);
    expect(kit.planOrderSize).toBe(kit.orders.planOrderSize);
  });

  it('every namespace member is reachable from the flat export (no name was silently dropped)', () => {
    const namespaces: Record<string, Record<string, unknown>> = {
      numbers: kit.numbers,
      markets: kit.markets,
      signing: kit.signing,
      transport: kit.transport,
      account: kit.account,
      orders: kit.orders,
    };
    const flat = new Map<string, unknown>(Object.entries(kit));
    const seen = new Map<string, string>();
    for (const [ns, members] of Object.entries(namespaces)) {
      for (const [name, value] of Object.entries(members)) {
        const prev = seen.get(name);
        expect(prev, `${name} exported by both ${prev} and ${ns}`).toBeUndefined();
        seen.set(name, ns);
        expect(flat.get(name), `flat export ${name} (${ns})`).toBe(value);
      }
    }
    expect(seen.size).toBeGreaterThan(100);
  });

  it('public constants match the knowledge base', () => {
    expect(kit.GATEWAY_URL.mainnet).toBe('https://gateway.prod.nado.xyz/v1');
    expect(kit.GATEWAY_URL.testnet).toBe('https://gateway.test.nado.xyz/v1');
    expect(kit.CHAIN_ID).toEqual({ mainnet: 57073, testnet: 763373 });
    expect(kit.NADO_DOMAIN_NAME).toBe('Nado');
    expect(kit.NADO_DOMAIN_VERSION).toBe('0.0.1');
    expect(kit.EXPIRATION_NEVER).toBe(18446744073709551615n);
    expect(kit.buildAppendix('ioc', true)).toBe(2561n);
    expect(kit.NADO_ERROR_CODES.MARKET_POST_ONLY).toBe(2117);
  });
});
All files