|
| 1 | +def _wallet_stub(chain, address): |
| 2 | + return { |
| 3 | + 'chain': chain, |
| 4 | + 'address_type': 'personal_wallet', |
| 5 | + 'rpc_used': False, |
| 6 | + 'details': 'stubbed for usage/account tests', |
| 7 | + } |
| 8 | + |
| 9 | + |
| 10 | +def test_account_endpoint_returns_client_metadata(client, api_headers): |
| 11 | + response = client.get('/api/account', headers=api_headers) |
| 12 | + body = response.get_json() |
| 13 | + |
| 14 | + assert response.status_code == 200 |
| 15 | + assert body['client']['client_label'] == 'ci-suite' |
| 16 | + assert body['client']['environment'] == 'live' |
| 17 | + assert body['client']['plan'] == 'pilot' |
| 18 | + assert 'records' in body['client']['scopes'] |
| 19 | + assert body['usage']['billable_checks'] == 0 |
| 20 | + |
| 21 | + |
| 22 | +def test_usage_summary_counts_checks(client, api_headers, app_module, monkeypatch): |
| 23 | + monkeypatch.setattr(app_module, 'classify_address', _wallet_stub) |
| 24 | + monkeypatch.setattr( |
| 25 | + app_module, |
| 26 | + 'analyze_transaction_on_chain', |
| 27 | + lambda chain, tx_hash, issue_type, intended_address, intended_chain: { |
| 28 | + 'status': 'found', |
| 29 | + 'reason_code': 'GENERAL_ONCHAIN_GUIDANCE', |
| 30 | + 'recoverability': 'depends', |
| 31 | + 'summary': 'stubbed transaction for usage summary tests', |
| 32 | + 'observed': { |
| 33 | + 'chain': chain, |
| 34 | + 'tx_status': 'confirmed', |
| 35 | + 'destination': '0x2222222222222222222222222222222222222222', |
| 36 | + 'destination_type': 'contract_or_app', |
| 37 | + }, |
| 38 | + }, |
| 39 | + ) |
| 40 | + |
| 41 | + preflight_payload = { |
| 42 | + 'expected': { |
| 43 | + 'network': 'ethereum', |
| 44 | + 'asset': 'USDT', |
| 45 | + 'address': '0x1111111111111111111111111111111111111111', |
| 46 | + }, |
| 47 | + 'provided': { |
| 48 | + 'network': 'ethereum', |
| 49 | + 'asset': 'USDT', |
| 50 | + 'address': '0x1111111111111111111111111111111111111111', |
| 51 | + }, |
| 52 | + } |
| 53 | + recovery_payload = { |
| 54 | + 'network': 'ethereum', |
| 55 | + 'tx_hash': '0x' + '3' * 64, |
| 56 | + 'issue_type': 'missing_memo', |
| 57 | + } |
| 58 | + |
| 59 | + preflight_response = client.post('/api/preflight-check', json=preflight_payload, headers=api_headers) |
| 60 | + recovery_response = client.post('/api/recovery-copilot', json=recovery_payload, headers=api_headers) |
| 61 | + summary_response = client.get('/api/usage-summary?period=this_month', headers=api_headers) |
| 62 | + body = summary_response.get_json() |
| 63 | + |
| 64 | + assert preflight_response.status_code == 200 |
| 65 | + assert recovery_response.status_code == 200 |
| 66 | + assert summary_response.status_code == 200 |
| 67 | + assert body['totals']['checks'] == 2 |
| 68 | + assert body['by_event']['preflight_run'] >= 1 |
| 69 | + assert body['by_event']['recovery_run'] >= 1 |
| 70 | + assert body['by_service']['preflight-check'] == 1 |
| 71 | + assert body['by_service']['recovery-copilot'] == 1 |
| 72 | + assert body['by_network']['ethereum'] >= 2 |
0 commit comments