Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

x402-sessions end-to-end tests

Dry-run scripts that exercise the full pipeline: x402-sessions SDK → facilitator HTTP API → on-chain Soroban SAC approve + transfer_from.

Uses the native XLM SAC as the payment asset so you don't need testnet USDC — just friendbot XLM.

Setup

# from this directory
npm install

Run

1. Start the facilitator (in a separate terminal):

cd ../facilitator && npm run dev

2. Generate & fund user + recipient keypairs (one-time):

npm run gen

Writes .env with USER_SECRET, RECIPIENT_PUBLIC, etc. Both accounts are friendbot-funded with 10,000 XLM each.

3. (Optional) Check everything is ready:

npm run status

4. Run the dry-run:

npm run dry-run

This will:

  1. Call createSession(...) from the x402-sessions SDK. That signs & submits an on-chain SAC approve(user, facilitator, 10 XLM, expiration_ledger) transaction, then registers the session with the facilitator via POST /sessions.
  2. Call POST /settle on the facilitator three times in a row with amount = 0.1 XLM. Each call:
    • Re-verifies the session in the facilitator (cap, expiry, recipient, per-call limit)
    • Debits the session in sqlite atomically
    • Executes transfer_from(facilitator, user, recipient, 0.1 XLM) on-chain
  3. Fetches final session state via GET /sessions/:id and prints the recipient balance delta observed from Horizon.

Expected output (success)

━━━ x402-sessions dry-run ━━━
  facilitator: http://localhost:4021
  user:        G...
  recipient:   G...
  asset:       CDLZ...  (native XLM SAC)
  cap:         10.0000000 XLM
  per call:    0.1000000 XLM × 3

✓ facilitator reachable

recipient balance before: 10000.0000000 XLM

[1] createSession — signing SAC approve on-chain...
    ✓ session: <uuid>
      spender:  G...<facilitator>
      cap:      100000000 stroops
      spent:    0 stroops
      expires:  ledger <n>

[1] POST /settle — 0.1000000 XLM...
    ✓ tx: <hash>
      remaining: 99000000 stroops
[2] POST /settle — 0.1000000 XLM...
    ✓ tx: <hash>
      remaining: 98000000 stroops
[3] POST /settle — 0.1000000 XLM...
    ✓ tx: <hash>
      remaining: 97000000 stroops

[state] GET /sessions/:id
    cap:    100000000
    spent:  3000000
    expiry: ledger <n>

recipient balance after: 10000.3000000 XLM
delta: +0.3000000 XLM  (expected +0.3000000)

━━━ dry-run complete ✓ ━━━

Scripts

Script Purpose
npm run gen Generate + friendbot-fund user and recipient keypairs
npm run status Check facilitator liveness and keypair balances
npm run dry-run Full end-to-end flow: createSession + 3 settles + verify on-chain

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages