# Test allow, review, and deny

> Build policies that approve, hold, and deny test payments, then test blocked recipients and time windows before you go live.

- Human URL: https://conto.finance/docs/guides/policy-testing
- Raw Markdown: https://conto.finance/docs/guides/policy-testing.md
- Terminal view: https://conto.finance/ai/docs/guides/policy-testing

Documentation group: Spending controls

Build a three-tier test: one payment is approved, one waits for approval, and one is denied.
[More scenarios](#more-scenarios) covers blocked recipients and time windows.

## Prerequisites

To try rules without saving a policy or creating payment requests, use
[Try before saving](https://conto.finance/docs/policies/overview#test-a-policy-before-you-enable-it) in the policy editor.
The steps below test saved policies through the payment flow.

A Conto account and organization

  An active agent with a linked, funded wallet and an SDK key in `CONTO_API_KEY`. The
  [Quickstart](https://conto.finance/docs/quickstart/setup) walks through creating the wallet, connecting the agent, and
  generating the key

## Keep the test isolated

Use a dedicated test agent and its Tempo Testnet wallet. Other organization policies, approval
workflows, or wallet caps can change the result. Make sure the wallet's
[per-transaction cap](https://conto.finance/docs/policies/spend-limits#wallet-level-limits) is at least 20 and its remaining
daily budget covers the test. Pass its `walletId` when multiple wallets exist.
Authorization tests create request records and send no funds unless you execute. The starter
policies on a new agent ($25 per payment, review above $10) do not change these results. Use a `DEV`
agent, because a production agent holds its first payment to a new address for payee review.

| Test | Spend cap: 15 | Review above: 10     | Expected decision   | Permitted next action                             |
| ---- | ------------- | -------------------- | ------------------- | ------------------------------------------------- |
| 5    | Pass          | Not triggered        | `APPROVED`          | May execute before expiry                         |
| 12   | Pass          | Triggered            | `REQUIRES_APPROVAL` | Wait for review, then read the same request       |
| 20   | Fail          | Also above threshold | `DENIED`            | Stop. Review cannot override a failed cap         |

Conto re-checks controls before a managed payment executes, so a policy change can stop a request
that was approved earlier. Read [lifecycle and recovery](https://conto.finance/docs/guides/payment-lifecycle) before resuming.

## Step 1: Verify your setup

Confirm the agent is configured before you create policies:

```bash
curl https://conto.finance/api/sdk/setup \
  -H "Authorization: Bearer $CONTO_API_KEY"
```

Check that the setup summary shows:

- the agent is available for payment calls
- at least one wallet is available

If either check fails, go back to the [Quickstart](https://conto.finance/docs/quickstart/setup).

## Step 2: Create policies

### Policy A: Spend limit

    Go to **Policies > Create policy**.

    - **Policy Name**: "Manual Spend Test"
    - **Applies to**: **Specific agents**, then choose your test agent
    - **Policy Type**: **Spend Limit**
    - **Per payment ($)**: `15`
    - **Description**: "Deny transactions over $15"

    The form creates this rule:

    | Field | Value |
    |---|---|
    | Rule Type | `MAX_AMOUNT` |
    | Operator | `LTE` |
    | Value | `15` |
    | Action | `ALLOW` |

    This allows transactions up to $15. Anything above is denied.

Info:

    **How rule actions work:** an `ALLOW` rule is a required condition, so a transaction that does
    not match it is denied. A `DENY` or `REQUIRE_APPROVAL` rule triggers when its condition matches.
    `DENY` + `GREATER_THAN 15` has the same effect as this rule. `REQUIRE_APPROVAL` +
    `GREATER_THAN 10` requires manual approval when the amount is over $10. See
    [how policies are evaluated](https://conto.finance/docs/policies/evaluation#evaluation-semantics).

### Policy B: Approval threshold

    Go to **Policies > Create policy**.

    - **Policy Name**: "Manual Approval Test"
    - **Applies to**: **Specific agents**, then choose your test agent
    - **Policy Type**: **Approval Threshold**
    - **Require Approval Above ($)**: `10`
    - **Description**: "Require approval for transactions over $10"

    The form creates this rule:

    | Field | Value |
    |---|---|
    | Rule Type | `REQUIRE_APPROVAL_ABOVE` |
    | Operator | `GREATER_THAN` |
    | Value | `10` |
    | Action | `REQUIRE_APPROVAL` |

    Transactions over $10 require manual approval in the dashboard before they can execute.

## Step 3: Check the policies on the agent

Navigate to your agent's detail page.

Click the **Policies** tab.

    "Manual Spend Test" and "Manual Approval Test" should be listed. Use **Assign policy** to add
    one you left out. All assigned policies are evaluated with AND logic. The most restrictive rule
    wins.

To confirm, re-run the `GET /api/sdk/setup` call from Step 1 and check that the payment-control
summary reflects the assigned policies.

## Step 4: Run test transactions

Use `curl` or any HTTP client. With the SDK, call
`conto.payments.request({ amount, recipientAddress, walletId, idempotencyKey })` with amounts 5, 12,
and 20. Use a different key for each test, and reuse a key only to retry the same test. See
[Payments](https://conto.finance/docs/sdk/payments).

### Test 1: $5 payment (expect APPROVED)

```bash
curl -X POST https://conto.finance/api/sdk/payments/request \
  -H "Authorization: Bearer $CONTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 5,
    "recipientAddress": "0x0000000000000000000000000000000000000001",
    "purpose": "Test - under all limits",
    "category": "SAAS"
  }'
```

Expected response:

```json
{
  "requestId": "cmm...",
  "status": "APPROVED",
  "amount": 5,
  "currency": "pathUSD",
  "recipient": "0x0000000000000000000000000000000000000001",
  "reasons": []
}
```

### Test 2: $12 payment (expect REQUIRES_APPROVAL)

```bash
curl -X POST https://conto.finance/api/sdk/payments/request \
  -H "Authorization: Bearer $CONTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 12,
    "recipientAddress": "0x0000000000000000000000000000000000000001",
    "purpose": "Test - over approval threshold"
  }'
```

Expected response:

```json
{
  "requestId": "cmm...",
  "status": "REQUIRES_APPROVAL",
  "amount": 12,
  "currency": "pathUSD",
  "recipient": "0x0000000000000000000000000000000000000001",
  "reasons": ["This payment requires approval before it can proceed."]
}
```

### Test 3: $20 payment (expect DENIED)

```bash
curl -X POST https://conto.finance/api/sdk/payments/request \
  -H "Authorization: Bearer $CONTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 20,
    "recipientAddress": "0x0000000000000000000000000000000000000001",
    "purpose": "Test - over max amount"
  }'
```

Expected response:

```json
{
  "requestId": "cmm...",
  "status": "DENIED",
  "amount": 20,
  "currency": "pathUSD",
  "recipient": "0x0000000000000000000000000000000000000001",
  "reasons": ["This payment exceeds a configured spending limit."]
}
```

## Step 5: Execute an approved payment

If Test 1 returned `APPROVED`, you can execute it onchain:

```bash
curl -X POST https://conto.finance/api/sdk/payments/REQUEST_ID/execute \
  -H "Authorization: Bearer $CONTO_API_KEY"
```

The response includes `receipt.txHash`, `receipt.transactionId`, and `receipt.settlementMode`. Submission is not confirmation. Follow [Track and recover a payment](https://conto.finance/docs/guides/payment-lifecycle) to verify the final state.

Held and denied requests appear in **Inbox** and **Audit logs**, not on
**Transactions**, which lists executed payments. Each audit entry shows which policies were
evaluated, which rules matched, and the final decision.

## More scenarios

Both scenarios use the same agent and a $5 payment, so only the new policy can change the result.
Create each policy in **Policies > Create policy** with **Applies to** set to **Specific agents**,
and choose the agent.

### Blocked counterparty

| Field                  | Value                                        |
| ---------------------- | -------------------------------------------- |
| Policy Name            | Test: Blocked Address                        |
| Policy Type            | Counterparty                                 |
| Blocked Counterparties | `0x000000000000000000000000000000000000dEaD` |

```bash
curl -X POST https://conto.finance/api/sdk/payments/request \
  -H "Authorization: Bearer $CONTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 5,
    "recipientAddress": "0x000000000000000000000000000000000000dEaD",
    "purpose": "Test: blocked recipient"
  }'
```

Expect `DENIED` with the reason `This recipient is not allowed by the current payment controls.`
The amount does not matter. The address itself is blocked.

### Time window

| Field       | Value                     |
| ----------- | ------------------------- |
| Policy Name | Test: Business Hours Only |
| Policy Type | Time Window               |
| Start Time  | 09:00                     |
| End Time    | 17:00                     |

Send a $5 payment outside 9am to 5pm UTC, or set the window to a range that excludes the current
UTC time. Expect `DENIED` with the reason `This payment is outside the permitted schedule.` Remove
the policy afterward so it does not block your other tests.

Info:

  Time rules without a `timezone` are evaluated in UTC. To test a local schedule, create the rule
  over the API with an IANA `timezone` in its value. See [time windows](https://conto.finance/docs/policies/time-windows).

## Troubleshooting

For setup issues such as a lost SDK key or an unfunded wallet, see
[If the result needs attention](https://conto.finance/docs/quickstart/setup#if-the-result-needs-attention) in the Quickstart.

    Check the **Policies** tab on the agent detail page. Assigned policies apply only to the
    agents they are assigned to, and only while they are active. Also check that each policy has
    rules.

    Every applicable policy is evaluated with AND logic, whatever its priority. If one policy denies
    while another would require approval, the denial wins. For example, if both an approval
    threshold (`>$10`) and a spend limit (`>$15`) match, DENY wins over REQUIRES_APPROVAL. Priority
    changes sort order only. It does not override a failing rule. Check which policies are assigned
    on the **Policies** tab.

    Every applicable policy must pass, so the strictest cap wins. New agents are linked to the
    starter policies ($25 per payment, $100 per day, review above $10). If the starter cap is $25
    and your policy allows $100, the $25 cap wins. Edit or unassign the starter policy on the
    **Policies** tab.

## Next steps

### SDK reference
Link: https://conto.finance/docs/sdk/payments

    Full SDK payment methods and options

### Go live checklist
Link: https://conto.finance/docs/guides/production-readiness

    Checks before you enable live funds
