Testing

Run the SDK with no browser and no network.

The mock passkey

MockWebAuthnAdapter implements the same interface as the real adapter, but creates and signs with an in-memory P-256 key. It produces well-formed attestation and assertion data, so the SDK's registration and sign-in flows run end to end.

import { DattEx, MockWebAuthnAdapter } from '@dattex/sdk'

const sdk = new DattEx({
  apiKey: 'test',
  baseURL: 'http://localhost:4000',
  chain: { id: 31337 },
  viem: { chain: hardhat, transport: http('http://127.0.0.1:8545') },
  webauthnAdapter: new MockWebAuthnAdapter(),
})

Mocking the API

Everything the SDK sends goes through one object, sdk.getInternalClient(). In a unit test, replace the module that creates it and assert on what you send:

vi.mock('~@dattex/sdk/src/utils/createApiClient', () => ({
  createApiClient: () => ({
    accounts: {
      createRegistrationChallenge: vi.fn().mockResolvedValue({ challenge: { id: 'c1', hash: '0x…' } }),
      createSigner: vi.fn().mockResolvedValue({ aggregate: { id: 'sig_1' } }),
      getSigner: vi.fn().mockResolvedValue({ aggregate: signer }),
    },
  }),
}))

Running the SDK's own tests

npm run wagmi:generate   # builds the ABI file the SDK imports (it is not committed)
cd sdks/dattex
npm test

The suite is 369 tests in 13 files, with no network. It covers client configuration, signers, accounts, deposits, both passkey adapters, and the trade, borrow and repay execute flows: exact request payloads, buy and sell paths, call order in the batched operation, signature encoding, failure paths, double execution and boundary amounts. Every test also checks that no API key, invite code or signature is logged. One integration test (borrowing.integration.test.ts) needs a local Hardhat chain and is run separately.