Skip to content

Implement payment verification and settlement middleware in E2E test server #161

@holonbot

Description

@holonbot

Context

During review of PR #159, the test server endpoints (/api/protected, /api/extensions-echo) were identified as returning only payment requirements without actually processing payments. The tests expect result.success and result.message responses after payment, but the server doesn't verify or settle payments.

Requested Changes

Implement proper payment verification and settlement in the E2E test server:

  1. Add middleware to extract and verify payment headers from incoming requests
  2. Integrate with the @x402x/facilitator-sdk to verify payment signatures and commitments
  3. Call the facilitator's settle method to execute on-chain settlement
  4. Return appropriate success/error responses to the client

Suggested Approach

  1. Create a payment middleware utility in test/e2e/anvil/payment-middleware.ts
  2. Extract payment headers (PAYMENT-SIGNATURE, PAYMENT-PAYLOAD) from requests
  3. Use the facilitator SDK's verify() method to validate payment signatures
  4. Call settle() to execute the settlement transaction
  5. Return JSON response with success status and message
  6. Handle errors gracefully and return payment requirements for invalid payments

Files to Modify

  • test/e2e/anvil/local-chain.test.ts - Add payment middleware to test server endpoints
  • (Optional) Create test/e2e/anvil/payment-middleware.ts for reusable middleware

Related PR

Deferred from PR #159 comment #2652058521

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions