> For the complete documentation index, see [llms.txt](https://docs.anchored.finance/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.anchored.finance/trading-api/reference/integration-test-checklist.md).

# Integration Test Checklist

Use this checklist before granting production access or enabling real user trading.

## Test Accounts and Scope

| Check                   | Expected                                |
| ----------------------- | --------------------------------------- |
| API key active          | Requests authenticate successfully      |
| IP whitelist configured | Requests only work from approved IPs    |
| `READ_ONLY` key         | GET works; POST/DELETE fails            |
| `WRITABLE` key          | GET/POST/DELETE work for approved scope |
| Product scope           | Only configured `x-api-p` works         |
| Chain scope             | Only configured `x-api-chain-id` works  |

## Authentication Tests

Required cases:

* Valid GET with sorted query params.
* Valid POST with exact raw body.
* Invalid timestamp older than 45 seconds.
* Duplicate nonce within the replay window.
* Body changed after signature.
* Missing `x-api-chain-id`.
* Wrong `x-api-p` casing.

Expected result: valid requests pass, and each invalid case fails with a clear auth or validation error.

## Market and Portfolio Tests

| Test                          | Expected                                                                                        |
| ----------------------------- | ----------------------------------------------------------------------------------------------- |
| `GET /config`                 | Returns `cashierBuffer`, `exchangeFeeConfig`, and `cashierTokenConfig` for scoped chain/product |
| `GET /symbols`                | Returns at least one known tradable stock                                                       |
| `GET /prices/{symbol}`        | Returns quote context                                                                           |
| `GET /corporate-action`       | Returns list or empty list without error                                                        |
| `GET /users/{userId}/balance` | Returns `mUsdBalance` and `tokenBalances`                                                       |
| `spenderAddress` query        | Returns `walletAllowance` for spender                                                           |

## Cash Tests

Required cases:

* Deposit calldata with valid `userAddress`, `tokenAddress`, `tokenAmount`.
* Deposit tx succeeds after approval.
* Deposit tx reverts or is blocked when allowance is missing.
* `POST /cash/deposits/tx` is idempotent for the same API key and tx.
* Deposit detail eventually reaches final status.
* Withdrawal calldata builds for available `mUsdBalance`.
* Withdrawal detail can be polled by `operationId`.

## Stock Movement Tests

Required cases:

* Stock deposit calldata builds for valid `userAddress`, `tokenAddress`, `tokenAmount`.
* Stock deposit tx succeeds after stock token approval.
* Stock withdrawal calldata builds for available `exchangeBalance`.
* Stock deposit and withdrawal details can be polled by `operationId`.

## Order Tests

| Test                             | Expected                                                                                                                                                                                                         |
| -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Market buy calldata              | Returns router `toAddress`, `value`, `callData`                                                                                                                                                                  |
| Market sell calldata             | Plain sell requires sufficient `exchangeBalance`; wallet-held stock can be moved with `/stock/deposits/*` first                                                                                                  |
| Order-with-deposit buy calldata  | Requires cash token allowance and instant deposit eligibility                                                                                                                                                    |
| Order-with-deposit sell calldata | Requires stock token allowance and wallet stock balance                                                                                                                                                          |
| Limit buy calldata               | Requires `quantity`, `price`, and `timeInForce`; current production contracts accept only `DAY`                                                                                                                  |
| Limit sell calldata              | Requires `quantity`, `price`, and `timeInForce`; current production contracts accept only `DAY`. Plain sell requires sufficient `exchangeBalance`; wallet-held stock can be moved with `/stock/deposits/*` first |
| Cancel calldata                  | Works only for open limit orders                                                                                                                                                                                 |
| Record order tx                  | Backfills mapping/orderId                                                                                                                                                                                        |
| Order detail                     | Moves from open to history after settlement                                                                                                                                                                      |

Include negative tests:

* Missing `notional` for market buy.
* Missing `quantity` for market sell.
* Missing `price` for limit order.
* Non-`DAY` `timeInForce` for limit order.
* Expired `deadline`.
* Cancel market order.
* Cancel order owned by different API key.

## One Click Tests

Required cases:

* Status before enable.
* Prepare returns signer-matching `signPayload`.
* Signature by wrong wallet is rejected.
* Expired deadline is rejected.
* Enable succeeds with correct signature.
* `/send` order succeeds after enable.
* Deposit `/send` fails without token approval.
* Disable succeeds and blocks future `/send`.

## Reconciliation Tests

After each state-changing test, verify:

* API response `code` is `200`.
* Tx receipt succeeded.
* Mapping endpoint finds tx.
* Detail endpoint reaches expected state.
* Portfolio reflects final balances.
* Fees and partial fills are shown correctly when present.

## Production Readiness

Before go-live:

* Store API secrets securely.
* Log request path, response `uuid`, txHash, orderId, operationId.
* Never log API secret, wallet private key, or raw authorization material.
* Monitor delayed `processing` operations.
* Document queued cash behavior and async order settlement.
* Provide a manual support path for stuck tx/order/operation IDs.
