import pytest
from app.tests.conftest import headers
@pytest.mark.asyncio
async def test_verified_payment_creates_ledger_once(client):
    await client.post("/api/v1/tenant-bundles",headers=headers(),json={"bundle_code":"payment.byo_psp.basic","is_active":True})
    req=(await client.post("/api/v1/payment-requests",headers={**headers(),"Idempotency-Key":"ledger"},json={"amount_minor":30,"source":{"service":"crm","ref_id":"abc"}})).json()
    await client.post(f"/api/v1/payment-requests/{req['id']}/verify",headers=headers(),json={"status":"paid","provider_transaction_id":"t"})
    await client.post(f"/api/v1/payment-requests/{req['id']}/verify",headers=headers(),json={"status":"paid","provider_transaction_id":"t"})
    assert len((await client.get("/api/v1/payment-transactions",headers=headers())).json())==1
    assert len((await client.get("/api/v1/payment-ledger-entries",headers=headers())).json())==1
