Payment testing

This guide covers testing x402 payment workflows in Regent agents.

Unit Testing (Mocked)

The existing test suite includes mocked payment tests that don't require real infrastructure:

Payment Tracking Tests

Location: packages/hono/src/__tests__/incoming-payments.test.ts

import { createInMemoryPaymentStorage, createPaymentTracker } from '@regent/x402';

// Create in-memory storage for tests
const storage = createInMemoryPaymentStorage();
const tracker = createPaymentTracker(storage);

// Record test payments
await tracker.recordIncoming(
  'test-group',
  'global',
  'test-route',
  1.5,
  '0xPayerAddress'
);

// Verify tracking
const summary = await tracker.getIncomingSummary({
  startTime: Date.now() - 3600000,
  endTime: Date.now(),
});

Policy Tests

Location: packages/x402/src/__tests__/policy.test.ts

Paywall Middleware Tests

Location: packages/express/src/__tests__/paywall.test.ts

Integration Testing (Testnet)

For real payment flow testing on testnet:

Prerequisites

  1. Test wallet with funds

  2. Environment variables

  3. Facilitator access

    • Register with x402 facilitator service

    • Get API credentials if required

Test Flow

Storage Backend Tests

Test with different storage backends:

E2E Test Checklist

For complete payment flow verification:

Mock Facilitator

For local development, you can mock the facilitator:

Running Tests

Last updated