631 Tests for Autonomous Commerce: Why the Agent Economy Needs Battle-Tested Infrastructure

684 Tests for Autonomous Commerce: Why the Agent Economy Needs Battle-Tested Infrastructure

AI agents will need to pay for compute, data, and API calls — and the infrastructure to make that possible exists today, not in some speculative roadmap. If you're building systems where autonomous agents participate in real economic activity, the question isn't whether agents will need wallets, it's what kind of wallet infrastructure can actually support them without collapsing under the weight of real-world edge cases.

The Gap Nobody Talks About

There's a lot of discussion about what AI agents will do in the economy. Buy and sell assets. Pay for API calls. Take DeFi positions. Execute cross-chain trades. Less discussed is the unglamorous infrastructure layer that has to exist before any of that works reliably.

Wallets for humans were designed around human assumptions: a person is sitting there, they can read a confirmation dialog, they can reject a sketchy transaction, they can call their bank if something goes wrong. None of those assumptions hold for an autonomous agent. An agent executing at machine speed, across multiple protocols, on multiple chains, with no human in the loop — that's a fundamentally different use case. The infrastructure has to be built for it from the ground up.

This is exactly why WAIaaS ships with 684+ test files across all packages. That number isn't a flex. It's a signal about what it takes to trust autonomous financial infrastructure.

What "Autonomous Commerce" Actually Requires

Let's be concrete about what an agent doing real economic work needs:

Identity and authentication — Not a shared API key, but a proper session token scoped to a specific wallet with configurable lifetime, renewal limits, and an absolute expiry ceiling. An agent that can authenticate itself without a human handing it credentials every hour.

Transaction execution across chains — The agent economy isn't going to live on a single chain. WAIaaS supports 2 chain types (EVM and Solana) across 18 networks. An agent managing a cross-chain portfolio needs to be able to operate across all of them through a single interface.

Automatic payment for API calls — This is the piece that makes autonomous commerce actually autonomous. The x402 HTTP payment protocol lets AI agents pay for API calls automatically, without human intervention. An agent hits an endpoint, gets a 402 response, pays, and continues. No manual top-ups, no credit card on file, no human approving each transaction.

DeFi integration — 15 DeFi protocol providers are integrated: Aave v3, Across, D'CENT Swap, Drift, ERC-8004, Hyperliquid, Jito staking, Jupiter Swap, Kamino, Lido staking, LI.FI, Pendle, Polymarket, XRPL DEX, and 0x Swap. An agent that can participate in DeFi isn't just holding assets — it's a participant in the financial system.

Guardrails that work at machine speed — A human can notice something feels off. An agent can't. The policy engine needs to do that work automatically.

The Policy Engine: Guardrails for Machines

The part of this infrastructure that deserves the most attention — and gets the least — is the policy engine.

WAIaaS ships with 21 policy types and 4 security tiers (INSTANT, NOTIFY, DELAY, APPROVAL). The default is deny: transactions are blocked unless explicitly allowed. That's the right default when you're dealing with autonomous systems that can execute faster than any human can intervene.

Here's what a spending limit policy looks like in practice:

curl -X POST http://127.0.0.1:3100/v1/policies \
  -H "Content-Type: application/json" \
  -H "X-Master-Password: my-secret-password" \
  -d '{
    "walletId": "<wallet-uuid>",
    "type": "SPENDING_LIMIT",
    "rules": {
      "instant_max_usd": 100,
      "notify_max_usd": 500,
      "delay_max_usd": 2000,
      "delay_seconds": 900,
      "daily_limit_usd": 5000
    }
  }'

The tier logic is mechanical and fast: amount ≤ $100 executes instantly, ≤ $500 executes with a notification, ≤ $2000 is queued for 15 minutes (cancellable), above that requires human approval. An agent can operate at full autonomy within the boundaries you've set, while anything outside those boundaries escalates appropriately.

Beyond spending limits, the policy types cover the full surface area of what could go wrong with an autonomous financial agent:

That last one is worth pausing on. ERC-8004 provides onchain agent reputation and validation. An agent can be required to meet a reputation threshold before it's allowed to transact. This is infrastructure for a world where agents have persistent identities and track records — not just session tokens.

The 7-Stage Pipeline

Every transaction in WAIaaS goes through a 7-stage pipeline: validate → auth → policy → wait → execute → confirm. That sequence is not accidental. It's the difference between a system that works in demos and one that works under adversarial conditions.

Stage 3 (policy) is where all 21 policy types run. Stage 4 (wait) is where DELAY-tier transactions sit until the delay window expires or a human cancels. The pipeline architecture means you can add gas condition execution — transactions that only fire when gas prices meet a threshold — without touching the other stages.

The dry-run API lets you simulate any transaction before execution:

curl -X POST http://127.0.0.1:3100/v1/transactions/send \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer wai_sess_<token>" \
  -d '{
    "type": "TRANSFER",
    "to": "recipient-address",
    "amount": "0.1",
    "dryRun": true
  }'

An agent can simulate before committing. That's not just useful for debugging — it's how you build agents that don't drain wallets on misconfigured transactions.

x402: Machines Paying for What They Use

The x402 HTTP payment protocol deserves its own section because it's the clearest example of infrastructure that enables genuinely autonomous commerce.

The premise is simple: an HTTP endpoint returns a 402 status code when it wants payment before serving a response. An agent using x402Fetch handles that automatically — it detects the 402, pays, and retries. No human in the loop. No pre-authorization. The agent pays for exactly what it uses, when it uses it.

This is the mechanism that lets agents pay for compute, data APIs, and services without custodied accounts that humans have to top up. Combine it with the X402_ALLOWED_DOMAINS policy type and you have an agent that autonomously pays for API calls, but only to domains you've pre-approved.

The TypeScript SDK exposes this directly:

import { WAIaaSClient } from '@waiaas/sdk';

const client = new WAIaaSClient({
  baseUrl: 'http://127.0.0.1:3100',
  sessionToken: process.env.WAIAAS_SESSION_TOKEN,
});

// x402Fetch handles 402 payment responses automatically
// The agent pays for the API call without human intervention

The MCP tool list includes x402-fetch as one of 45 tools available to AI agents integrating through the Model Context Protocol. An agent running in Claude Desktop can call that tool directly.

The Authentication Model

Three distinct authentication layers matter here, and they're worth understanding separately:

masterAuth (Argon2id) — This is system administration. Creating wallets, managing sessions, setting policies. The system operator uses this. Agents never have this.

sessionAuth (JWT HS256) — This is what agents use. Scoped to a specific wallet, with configurable TTL, max renewals, and an absolute lifetime ceiling. An agent gets a session token and operates within its allowed scope.

ownerAuth (SIWS/SIWE) — This is the fund owner's layer. Approving transactions that hit the APPROVAL tier, using WalletConnect for mobile signing, exercising the kill switch. The human who owns the funds can always reach in.

The layering is important: agents operate autonomously within sessionAuth scope, but the masterAuth layer controls what sessions can do, and the ownerAuth layer provides the human override when needed. No single key controls everything.

Why 684 Test Files Is the Right Number

Infrastructure that moves money needs to be tested against the scenarios that actually break things, not just the happy path.

A 7-stage transaction pipeline has failure modes at every stage. A policy engine with 21 policy types has interaction effects between policies. A DeFi layer with 15 protocol integrations has edge cases unique to each protocol. An authentication system with 3 distinct layers has boundary conditions between them.

684+ test files across a 15-package monorepo isn't padding. It's the cost of building infrastructure you can trust with autonomous agents operating at machine speed, executing real transactions, with real consequences.

The alternative — shipping leaner test coverage to move faster — is a reasonable choice for a todo app. It's not a reasonable choice for the wallet infrastructure layer of the autonomous agent economy.

Quick Start

Getting a wallet running that an AI agent can use takes under five minutes:

Step 1: Install the CLI and initialize

npm install -g @waiaas/cli
waiaas init --auto-provision
waiaas start

Step 2: Create wallets and sessions in one command

waiaas quickset --mode mainnet

Step 3: Register with Claude Desktop

waiaas mcp setup --all

At this point Claude has access to 45 MCP tools covering wallet operations, transactions, DeFi positions, NFTs, and x402 payments. The agent is operating with a real wallet, under real policies, on real networks.

Step 4: Set policies before funding

Use the policy API to configure spending limits, token whitelists, and contract whitelists before putting funds in the wallet. The default-deny stance means nothing moves until you explicitly allow it.

Step 5: Fund and verify

curl http://127.0.0.1:3100/v1/wallet/balance \
  -H "Authorization: Bearer wai_sess_<your-token>"

The Infrastructure Layer That Has to Exist

The agent economy is not a hypothetical. Agents are executing DeFi trades, paying for API calls, managing cross-chain positions today. What determines whether that goes well or badly is almost entirely about the infrastructure layer underneath.

Autonomous wallet infrastructure needs: proper session scoping, default-deny policies, human override capability, multi-chain support, protocol integrations that have been tested against real edge cases, and — when something does go wrong — clear error semantics that an agent can reason about rather than just crash on.

{
  "error": {
    "code": "POLICY_DENIED",
    "message": "Transaction denied by SPENDING_LIMIT policy",
    "domain": "POLICY",
    "retryable": false
  }
}

That error response is designed for an agent to handle programmatically. retryable: false tells the agent not to retry. code: POLICY_DENIED tells it why. The agent can surface that to the user, log it, or route around it — without crashing or silently failing.

That's what battle-tested infrastructure looks like in practice: not just the happy path working, but the failure modes being handled with enough structure that the systems built on top can respond sensibly.

What's Next

WAIaaS is open source and self-hosted — the full codebase, including all 684+ test files, is on GitHub. The OpenAPI 3.0 spec is available at /doc and the interactive reference at /reference once you're running locally. If you're building agents that participate in real economic activity, this is the infrastructure layer worth examining carefully.