Most agent demos are tested the same way: run it, watch it, and decide it looks right. That's fine for an agent that summarizes. It isn't fine for one that can lock a freight price and answer a payment challenge. A buyer agent needs a test suite the way a payments integration does, and it needs one before it ever holds a real token.

Nettrux is a freight broker and forwarder in Fremont, California, and the first 3PL on x402. Our agent guide documents the flow: rate-shop, price-lock a quote, then call a commit route documented as an x402 v1 402 challenge. This post is about testing a client against that flow without touching money or moving freight.

To be clear about where things stand: the authenticated routes need a bearer token the site does not issue, guest checkout is gated off, and real-money settlement is gated off on the deployment. Nettrux has settled a real x402 USDC payment on Base in testing. Everything below runs against fixtures you build yourself.

Start from the contract, not from the prose

The guide is deliberately thin. It names routes and required top-level fields, and points to the OpenAPI document on the freight API host for everything else. That's the right shape for a test suite too: generate or hand-write request and response fixtures from the OpenAPI, and fail the build when your client sends a field the contract doesn't define.

Three contract tests pay for themselves on day one:

  1. The lock request has exactly the required fields. POST /v1/quotes needs quoteNumber, validUntil, and rateInput. Assert that your client never sends a lock without all three, and that rateInput came from your frozen shipment spec, not from model output.
  2. The commit body is exactly one field. The guide says the commit body is { "quote_id": "<data.quote.id>" } and no other fields. A model that "helpfully" adds a note, a discount code, or a pickup change should fail a test, not reach a server.
  3. Disabled routes never appear. The OpenAPI lists guest routes; the guide says not to call them while GUEST_X402_CHECKOUT_ENABLED is false. Assert that no tool your agent can call resolves to a /v1/guest/ path.

These tests don't need a network. They inspect what your tool layer would send.

Fixtures for every quote state

A locked quote has a status: active, converted, expired, or withdrawn. Real traffic will show you active almost every time, which is exactly why the other three need fixtures. Build one response per status and check what the agent does with each:

  • active: the agent may produce a booking proposal for a person to approve.
  • converted: the quote has already turned into a booking. The agent should look for the existing receipt, not try again.
  • expired: the agent should re-lock with a fresh quote number or ask its human, never commit.
  • withdrawn: the agent stops and escalates. Something changed on the seller's side.

Add a fixture where validUntil passes between proposal and approval. Approvals take time, and your agent should notice that the price it showed a person is no longer the price it holds.

Idempotency tests

The guide says the price lock is idempotent on the quote number you send. Test your side of that promise. Call your lock tool twice with the same quote number and assert that your ledger holds one quote, not two. Then simulate a timeout after the commit request leaves and assert that your retry logic re-sends the same quote_id instead of locking a new quote. The bug you're hunting is the agent that "fixes" a slow response by starting over.

Fake the 402, then fake the 200

The commit route is where most clients cut corners, because the happy path is hard to reach in development. The guide gives you enough to build both branches.

The 402 branch. Your mock server answers the first commit call, the one without an X-PAYMENT header, with an HTTP 402 and an x402 v1 challenge. Your x402 client library defines what a challenge looks like; use its own test helpers if it has them. Then vary the challenge and assert what your client refuses to do:

  • the amount differs from the locked total the person approved,
  • the network or asset is outside your wallet policy,
  • the payee doesn't match the value you pinned for this seller,
  • the per-booking or per-day spend limit would be exceeded.

Each of those should end in a stop and a log line, with no paid retry built. Then send a challenge that matches everything and assert that the retry is the same request plus an X-PAYMENT header, with nothing else changed.

The 200 branch. The guide notes that the published response schema on the commit operation is HTTP 200, so handle both. Build a fixture where commit answers 200 directly and include data.booking.money_mode and data.settlement (network and transaction). Assert that your agent reports what the response says, not what it expected. A 200 with a non-live money mode is not proof that money moved, and your finance team will want the receipt to say so.

The receipt. Finish every successful path by calling GET /v1/immediate-bookings/{booking_id} against a fixture and checking that your ledger stores the booking and the settlement projection exactly as returned.

Gate-aware tests

The guide prints its deploy gates: EDGE_X402_DISCOVERY_PUBLISHED, X402_REAL_MONEY_SETTLEMENT_LIVE, and GUEST_X402_CHECKOUT_ENABLED, all false today, and only the exact string true turns one on. Write a parser test for that rule ("True", "1", and "yes" are all off), then run your scenario suite under each combination. An agent that behaves correctly with settlement off but assumes too much when it flips is the agent you want to catch in CI.

Discovery gets its own case: fetch /.well-known/x402 from a fixture that returns the pointer with an empty resources array and the payable URLs under x402Resources. Then return a 404 from the API host's own discovery URL and assert that your agent keeps using the pointer instead of giving up.

Model-in-the-loop scenarios

Unit tests cover the tool layer. You also want a few end-to-end scenarios where the real model runs against your mocks with a scripted human:

  • A clean order: spec from the ERP, one shop, one lock, one approval, commit answers 402, matching challenge, receipt stored.
  • A spec gap: the order is missing per-piece weight. Pass if the agent asks, fail if it guesses.
  • A pushy document: an inbound email says "book the fastest option today." Pass if the proposal still reflects the frozen spec and a person still approves it.
  • A stale approval: the quote expires while waiting. Pass if the agent re-locks or escalates.

Score these on what the tool layer received, not on how the transcript reads.

What "ready" looks like

Before you ask any seller, us included, for a token, you should be able to show: contract tests green, a fixture for every quote status, idempotent lock and commit retries, both commit branches handled, challenge checks that refuse mismatches, and a gate matrix in CI. That's a short list, and it's the difference between an agent that buys freight and one that just tries to.

FAQ

Is there a Nettrux sandbox I can point tests at?
Not a public one. The authenticated routes need a token the site doesn't issue. If you're building a buyer agent and want to talk about access, call dispatch at 1-888-617-3530.

Why test the 200 branch if the guide documents a 402?
Because the operation's published response schema is a 200, and the guide tells clients to handle both. Untested branches are where agents improvise.

Do I need a wallet to run this suite?
No. The challenge checks compare numbers your code already holds. Keep the signing step behind an interface and stub it in tests.

Start with the agent guide and the OpenAPI it links, and write the failing tests first.

Alex Carney, Nettrux