# Test scenarios

Force every outcome your product must handle, with a test key, before a real user meets it. Name a `scenario`, place the order as usual, and the [sandbox](https://maxy.co/docs/sandbox) walks it there by itself. This page lists each scenario, how to force it, and what your app should do when it happens live.

## Force an outcome

Name the scenario on the quote: `scenario` as a query parameter on `GET /price` or `GET /quote`, or `scenario` on the SDK's `swap.quote`, `swap.execute` and flow helpers. It stays with the order. You can also name one in the body of `POST /orders`. A live key ignores `scenario`. `GET /sandbox/scenarios` lists them, and `simulate` works the same way. The samples use the setup from [Get a quote](https://maxy.co/docs/buy-btc#get-a-quote).

```sh
curl -sG -H "x-maxy-key: $MAXY_API_KEY" "$BASE/quote" \
  --data-urlencode "from=ETH on base" -d to=BTC -d amount=0.01 \
  -d fromAddress="$WALLET" -d toAddress="$MY_BTC_ADDRESS" -d scenario=refund_available > quote.json
```

```ts
import { createMaxyClient, evmSignerFromWalletClient } from 'maxy-labs';

const maxy = createMaxyClient(); // reads MAXY_API_KEY
const evm = evmSignerFromWalletClient(walletClient);
const { status } = await maxy.swap.execute({
  from: 'ETH on base', to: 'BTC', amount: '0.01',
  evm, btcAddress, scenario: 'refund_available',
});
console.log(status.state); // refundable
const { txHash } = await maxy.swap.refund({ chainId: 8453, intentHash: status.orderId as `0x${string}`, evm });
```

```python
quote = requests.get(f"{BASE}/quote", headers={"x-maxy-key": KEY}, params={
    "from": "ETH on base", "to": "BTC", "amount": "0.01",
    "fromAddress": account.address, "toAddress": btc_address, "scenario": "refund_available",
}).json()
```

## Timing

An order starts when you submit it, or when you place it for a gasless order or a sale. One nobody submits starts by itself 30 seconds after it is placed. Webhooks follow each change within about 15 seconds.

| Route | States, in seconds from the start |
| --- | --- |
| Buying BTC, coin to coin, SOL to BTC | `pending`; `in_progress` at 8; `completed` at 20 |
| Selling BTC, BTC to SOL | `pending`; `awaiting_deposit` at 5; `in_progress` at 15; `completed` at 27 |

## Every scenario

| `scenario` | Name it on | What happens | What your app does |
| --- | --- | --- | --- |
| `success` | the quote | The default: `completed`, with a sandbox `btcTxId` | Show the receipt, with `btcTxId` |
| `refund_available` | the quote | `refundable`; `refunded` 15 seconds after `GET /orders/{id}/refund` | Offer the refund: the user's wallet sends it. [When it fails](https://maxy.co/docs/when-it-fails#refunds) |
| `order_expired` | the quote | `expired`: an escrow that was never sent | Say nothing moved; offer a new quote |
| `order_failed` | the quote | `failed` | Show `failureReason`; send Maxy the order id |
| `order_cancelled` | the quote | `cancelled` | Say nothing moved |
| `expired_quote` | the quote, or `POST /orders` | `409 quote_expired`, with a fresh quote in `details.freshQuote` | Show the new amount; the wallet signs again |
| `price_moved` | the quote, or `POST /orders` | `409 quote_mismatch` | Quote again |
| `over_cap` | the quote, or `POST /orders` | `issues.orderCap` and `steps: null`; then `422 order_cap_exceeded` | Show the amounts, keep the button live; on click, offer the cap |
| `unfillable` | the quote, or `POST /orders` | `liquidityAvailable: false`, no steps; then `422 insufficient_liquidity` | On click, offer a smaller amount. A router ranks the next source |
| `too_small` | the price or quote | `422 amount_out_of_range`, with `details.minSats` | Show the smallest order |
| `insufficient_funds` | the quote | `issues.balance`; a gasless quote has no steps, the other routes keep theirs | Show what is missing. Where there are steps, let the user go on: the wallet refuses a payment it cannot cover |
| `needs_approval` | the quote | `issues.allowance` and an `approve` step | Send the approval and wait for it to confirm, then sign |
| `simulation_fails` | the quote | `POST /orders` answers `simulation.ok: false` with a reason | Do not send the transaction; show the reason |
| `underpaid` | a sale's quote | `awaiting_deposit`, then `expired` with `rawStatus` `SANDBOX_UNDERPAID` | Explain the short payment: [Failed sells](https://maxy.co/docs/when-it-fails#failed-sells) |
| `rate_limited` | any call | `429 rate_limited` with `Retry-After: 5` | Wait `Retry-After` seconds, then retry |
| `webhook_replay` | the quote | `completed`; each webhook event arrives twice with the same `id` | Process each event `id` once |
| `payment_replaced` | the quote | `completed`, then the payment is replaced: a new `btcTxId`, and an `order.payment_replaced` webhook with `previousBtcTxId` | Follow the new `btcTxId`; report the transfer final at its first confirmation |
| `recipient_declined` | the quote, or `POST /orders` | `403 recipient_declined` | Say the order cannot be processed; do not retry it. A router skips Maxy for it |
| `jurisdiction_blocked` | the quote, or `POST /orders` | `403 jurisdiction_blocked` | Say Maxy does not serve the user's location; do not retry it |
| `open_sells_limit` | a sale's quote, or `POST /orders` | `409 open_sells_limit` | Ask the user to pay or let lapse their open sells first |

The order cap and the order size are explained on [Keys and limits](https://maxy.co/docs/keys-and-limits#order-size), and every code on [Error codes](https://maxy.co/docs/error-codes).

## Skip the wait

`POST /sandbox/orders/{id}/advance` moves a sandbox order to its next state now, or to a later state with `{ "to": "completed" }`; on a buy, `{ "to": "confirmed" }` brings in its payment's first confirmation. A state its scenario does not reach answers `409 order_state`, with `allowedStates`. `ORDER_ID` is from [Track the order](https://maxy.co/docs/buy-btc#track-the-order).

```sh
curl -s -X POST "$BASE/sandbox/orders/$ORDER_ID/advance" -H "x-maxy-key: $MAXY_API_KEY" -H "content-type: application/json" -d '{ "to": "completed" }'
```

From a terminal: `npx -p maxy-labs maxy sandbox advance <id> --to completed`. With the SDK: [Test your integration](https://maxy.co/docs/test-your-integration#skip-the-wait).

## Test that you skip Maxy

`GET /health?scenario=degraded` answers a degraded health, in the same shape, so a router can test the code that skips Maxy while it is degraded.

```sh
curl -s -H "x-maxy-key: $MAXY_API_KEY" "$BASE/health?scenario=degraded" | jq '{status, degraded}'
```

```json
{ "status": "degraded", "degraded": true }
```

Then, on mainnet, run one buy with $5 of USDC and one with 0.002 ETH, and work through the [launch checklist](https://maxy.co/docs/launch-checklist).

---
Source: https://maxy.co/docs/test-scenarios (Maxy Docs › Get integrated › Test)
