Skip to content

Testing ​

An honest account of what test coverage exists, what does not, and what to actually run before shipping.

What exists ​

SuiteLocationCountRuns without a chain?
Autopilot contractbz-backend/contract-deployment/test/autopilot.test.cjs61 passingYes — Hardhat local
Autopilot trigger enginebz-backend/scripts/test-autopilot-engine.js13 passingYes
Policy toolkitbz-backend/scripts/test-policy.js—Yes
Wallet-auth digestbz-backend/scripts/test-wallet-auth.js—Yes
Blog APIbz-backend/scripts/testBlogAPI.js—Needs a running backend

What does not exist ​

There is no backend test suite

npm test in bz-backend runs echo "Error: no test specified" && exit 1. There are no unit tests for controllers, services, the quote fan-out, the provider proxies, the DCA cron, or anything in the ecosystem layer.

Also absent:

MissingConsequence
Frontend testsApp.test.tsx and setupTests.ts are Create React App leftovers. vite build is the only gate
bz-agent testsClassification quality has no evaluation harness. The only signal is the non-fallback rate — which does not catch a message routed to the wrong intent
swap-sdk tests26 aggregators, none covered. A provider silently breaking is invisible
Relayer contract testsThe contract handling every interactive trade on 22 chains has no test suite in the repo
DCA contract testsSame
Integration testsNo end-to-end coverage of quote → build → sign → settle

The relayer and DCA contracts have neither tests nor an adversarial audit

Autopilot got Slither plus an adversarial review (which found a critical drain vector). The relayer — which handles every swap on 22 chains — has had a hardening pass but no equivalent review, and no test suite. That is the largest coverage gap in the platform.

Before shipping — the practical checklist ​

Any change ​

bash
# frontend compiles?
cd defi-dex && npm run build:app

# agent types check?
cd bz-agent && npm run check-types

npx tsc --noEmit in defi-dex is not a gate

It reports roughly 3,300 pre-existing errors originating in node_modules type definitions. vite build is the real gate. Do not chase tsc to zero as part of an unrelated change.

Contract change ​

bash
cd bz-backend/contract-deployment
npx hardhat compile
npx hardhat test test/autopilot.test.cjs      # must stay at 61

# storage layout — MANDATORY for any upgrade
npx hardhat run scripts/simulate-upgrade.js --network <net>

Never upgrade a proxy without validating the storage layout

upgrades.validateUpgrade(V1 → V2) was run for the DCA upgrade and state was preserved on mainnet. A layout break on a live vault corrupts every user's position irrecoverably. simulate-upgrade.js and simulate-migration-upgrade.js exist for this.

Autopilot change ​

bash
cd bz-backend
node scripts/test-policy.js
node scripts/test-wallet-auth.js
node scripts/test-autopilot-engine.js

Plus the hash-parity check, which is the highest-value single test in the codebase:

Verify the FE/BE hash parity manually

js
// backend
import { hashPolicy } from './utils/policy.js'; console.log(hashPolicy(policy))
ts
// frontend browser console
import { hashPolicy } from './utils/autopilotPolicy'; console.log(hashPolicy(policy))

They must be identical strings. If not, the mirror has drifted and every Autopilot creation will fail.

swap-sdk change ​

There are no tests, so verification is manual:

□ Quote appears in the SSE stream on the target chain
□ Output amount and units are correct vs the provider's own UI
□ usdAmount populated (else the fee display shows $0)
□ allowanceTo is the real spender
□ sortQuotes gas estimate passes
□ A real trade completes and output arrives
□ getTxStatus resolves pending → success
□ Killing the provider's API does not break the stream

AI intent change ​

□ 5 different phrasings all classify to your intent
□ A neighbouring intent's phrasings do NOT hit yours
□ Missing a required field produces a question, not a guess
□ A hallucinated token name degrades gracefully
□ The data field exists in the Mongoose schema — reload and check the card
□ Old history still renders (optional chaining)

SEO change ​

bash
cd defi-dex && npm run build && npm run check:routes
□ dist/{path}/index.html contains real content, not the empty shell
□ Exactly one FAQPage per page
□ Canonical trailing slash matches the sitemap loc
□ dist/og/{key}.png generated
□ The footer renders in the static HTML with JS off

One-liner for the FAQPage audit: walk dist/, parse every ld+json block, count FAQPage per page. More than one means the dedupe rules were broken.

Testing against production data ​

Local dev points at production Atlas

There is no staging database. Set CRON=false before starting the backend, or your laptop becomes a second CSIP and Autopilot executor using the production PRIVATE_KEY_EXECUTOR.

Useful read-only scripts:

bash
cd bz-backend
node scripts/checkRelayerDeployed.js       # relayer presence per chain
node scripts/check-contract-owner.js       # owner/signer verification
node scripts/check-contract-state.js       # fee config, pause state
node scripts/checkDeployerBalance.js       # executor gas
node scripts/blazai-analytics.js           # chat usage figures

Many scripts in scripts/ and at the repo root are mutations

curate-token-order.js, enableChain.js, enableRelayerFees.js, and roughly 30 files at the repo root (fix_admin_and_txs.js, delete_remaining_anomalies.js, migrate_exempt.js, …). Several delete data and are not idempotent — they were written for a specific incident. Read before running.

Live end-to-end testing ​

The pattern used for Autopilot: a small real trade on mainnet.

□ ~$5 of value
□ Watch the transaction on the explorer
□ Confirm the measured delta credited matches
□ Confirm the fee accrued (check /defi/fees/summary?force=1)
□ Confirm the record in Mongo
□ Confirm the UI reflects it

The full Autopilot loop was proven this way on 2026-07-03: a probed route executed, credited the exact balance delta (0.000866… ETH), autoClaimFor delivered to the user's wallet, and platformEarnings accrued its first 0.00003 ETH.

Testnets exist but are thin

AUTOPILOT_ADDRESSES includes Arbitrum Sepolia (0x7cA5A09E…) and hardhat.config.js has arbitrum_sepolia. But there is no aggregator liquidity on testnets, so a route cannot be quoted — which means the interesting half of the flow cannot be tested there. A tiny mainnet trade is more informative than a testnet one.

Browser-driven verification ​

Several bugs were found this way and are hard to catch otherwise:

BugFound by
?q= left in the URL with an empty composerCDP testing
The vendor-react split being TDZ-safeHeadless Chrome on /defi/swap and /
~96 px dead space on the AI siteVisual inspection at multiple widths

Headless Chrome on macOS clamps --window-size to ~500 px wide

So mobile screenshots look like overflow bugs when they are not. Verify at 500 px or above.

What to add first, if you get time ​

Ranked by risk reduction per hour:

  1. Relayer contract tests. It handles every trade on 22 chains and has none.
  2. An adversarial audit of the relayer and DCA contracts. Autopilot's found a critical issue; there is no reason to assume these are cleaner.
  3. Per-provider quote smoke tests in swap-sdk. A broken provider currently disappears silently — see monitoring.
  4. An intent-classification eval set. 50 labelled messages, run on every prompt change. The current signal cannot detect mis-classification.
  5. A hash-parity test in CI. Automate the manual check above; the failure mode it prevents is total.
  6. Contract tests for the DCA vault, particularly around the V1 accounting legacy.

Internal + developer documentation. Usage figures are point-in-time snapshots — re-verify before publishing them.