Some checks failed
CLI Tests / test-cli (push) Failing after 4s
Deploy to Testnet / deploy-testnet (push) Successful in 1m40s
Documentation Validation / validate-docs (push) Failing after 12s
Documentation Validation / validate-policies-strict (push) Successful in 4s
Integration Tests / test-service-integration (push) Successful in 2m42s
Package Tests / Python package - aitbc-agent-sdk (push) Failing after 34s
Package Tests / Python package - aitbc-core (push) Successful in 27s
Package Tests / Python package - aitbc-crypto (push) Successful in 13s
Package Tests / Python package - aitbc-sdk (push) Successful in 16s
Package Tests / JavaScript package - aitbc-sdk-js (push) Successful in 8s
Package Tests / JavaScript package - aitbc-token (push) Successful in 18s
Python Tests / test-python (push) Failing after 50s
Security Scanning / security-scan (push) Failing after 43s
Multi-Node Stress Testing / stress-test (push) Successful in 12s
Cross-Node Transaction Testing / transaction-test (push) Successful in 9s
- Created aitbc/_version.py with centralized version definition - Updated aitbc/__init__.py to import __version__ from _version module - Updated constants.py to use __version__ for PACKAGE_VERSION - Replaced print() calls with logger in decorators.py, events.py, queue_manager.py, and state.py - Added logger initialization using get_logger(__name__) in config.py, decorators.py, events.py, queue_manager.py, and state.py - Added cli/commands
194 lines
5.5 KiB
Python
194 lines
5.5 KiB
Python
"""Edge case and error handling tests for compliance service"""
|
|
|
|
import pytest
|
|
import sys
|
|
import sys
|
|
from pathlib import Path
|
|
from unittest.mock import Mock, patch
|
|
from fastapi.testclient import TestClient
|
|
from datetime import datetime, timezone
|
|
|
|
|
|
from main import app, KYCRequest, ComplianceReport, TransactionMonitoring, kyc_records, compliance_reports, suspicious_transactions, compliance_rules
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def reset_state():
|
|
"""Reset global state before each test"""
|
|
kyc_records.clear()
|
|
compliance_reports.clear()
|
|
suspicious_transactions.clear()
|
|
compliance_rules.clear()
|
|
yield
|
|
kyc_records.clear()
|
|
compliance_reports.clear()
|
|
suspicious_transactions.clear()
|
|
compliance_rules.clear()
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_kyc_request_empty_fields():
|
|
"""Test KYCRequest with empty fields"""
|
|
kyc = KYCRequest(
|
|
user_id="",
|
|
name="",
|
|
email="",
|
|
document_type="",
|
|
document_number="",
|
|
address={}
|
|
)
|
|
assert kyc.user_id == ""
|
|
assert kyc.name == ""
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_compliance_report_invalid_severity():
|
|
"""Test ComplianceReport with invalid severity"""
|
|
report = ComplianceReport(
|
|
report_type="test",
|
|
description="test",
|
|
severity="invalid", # Not in low/medium/high/critical
|
|
details={}
|
|
)
|
|
assert report.severity == "invalid"
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_transaction_monitoring_zero_amount():
|
|
"""Test TransactionMonitoring with zero amount"""
|
|
tx = TransactionMonitoring(
|
|
transaction_id="tx123",
|
|
user_id="user123",
|
|
amount=0.0,
|
|
currency="BTC",
|
|
counterparty="counterparty1",
|
|
timestamp=datetime.now(timezone.utc)
|
|
)
|
|
assert tx.amount == 0.0
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_transaction_monitoring_negative_amount():
|
|
"""Test TransactionMonitoring with negative amount"""
|
|
tx = TransactionMonitoring(
|
|
transaction_id="tx123",
|
|
user_id="user123",
|
|
amount=-1000.0,
|
|
currency="BTC",
|
|
counterparty="counterparty1",
|
|
timestamp=datetime.now(timezone.utc)
|
|
)
|
|
assert tx.amount == -1000.0
|
|
|
|
|
|
@pytest.mark.integration
|
|
def test_kyc_with_missing_address_fields():
|
|
"""Test KYC submission with missing address fields"""
|
|
client = TestClient(app)
|
|
kyc = KYCRequest(
|
|
user_id="user123",
|
|
name="John Doe",
|
|
email="john@example.com",
|
|
document_type="passport",
|
|
document_number="ABC123",
|
|
address={"city": "New York"} # Missing other fields
|
|
)
|
|
response = client.post("/api/v1/kyc/submit", json=kyc.model_dump())
|
|
assert response.status_code == 200
|
|
|
|
|
|
@pytest.mark.integration
|
|
def test_compliance_report_empty_details():
|
|
"""Test compliance report with empty details"""
|
|
client = TestClient(app)
|
|
report = ComplianceReport(
|
|
report_type="test",
|
|
description="test",
|
|
severity="low",
|
|
details={}
|
|
)
|
|
response = client.post("/api/v1/compliance/report", json=report.model_dump())
|
|
assert response.status_code == 200
|
|
|
|
|
|
@pytest.mark.integration
|
|
def test_compliance_rule_missing_fields():
|
|
"""Test compliance rule with missing fields"""
|
|
client = TestClient(app)
|
|
rule_data = {
|
|
"name": "Test Rule"
|
|
# Missing description, type, etc.
|
|
}
|
|
response = client.post("/api/v1/rules/create", json=rule_data)
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["name"] == "Test Rule"
|
|
|
|
|
|
@pytest.mark.integration
|
|
def test_dashboard_with_no_data():
|
|
"""Test dashboard with no data"""
|
|
client = TestClient(app)
|
|
response = client.get("/api/v1/dashboard")
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["summary"]["total_users"] == 0
|
|
assert data["summary"]["total_reports"] == 0
|
|
assert data["summary"]["total_transactions"] == 0
|
|
|
|
|
|
@pytest.mark.integration
|
|
def test_monitor_transaction_with_future_timestamp():
|
|
"""Test monitoring transaction with future timestamp"""
|
|
client = TestClient(app)
|
|
tx = TransactionMonitoring(
|
|
transaction_id="tx123",
|
|
user_id="user123",
|
|
amount=1000.0,
|
|
currency="BTC",
|
|
counterparty="counterparty1",
|
|
timestamp=datetime(2030, 1, 1) # Future timestamp
|
|
)
|
|
response = client.post("/api/v1/monitoring/transaction", json=tx.model_dump(mode='json'))
|
|
assert response.status_code == 200
|
|
|
|
|
|
@pytest.mark.integration
|
|
def test_monitor_transaction_with_past_timestamp():
|
|
"""Test monitoring transaction with past timestamp"""
|
|
client = TestClient(app)
|
|
tx = TransactionMonitoring(
|
|
transaction_id="tx123",
|
|
user_id="user123",
|
|
amount=1000.0,
|
|
currency="BTC",
|
|
counterparty="counterparty1",
|
|
timestamp=datetime(2020, 1, 1) # Past timestamp
|
|
)
|
|
response = client.post("/api/v1/monitoring/transaction", json=tx.model_dump(mode='json'))
|
|
assert response.status_code == 200
|
|
|
|
|
|
@pytest.mark.integration
|
|
def test_kyc_list_with_multiple_records():
|
|
"""Test listing KYC with multiple records"""
|
|
client = TestClient(app)
|
|
|
|
# Create multiple KYC records
|
|
for i in range(5):
|
|
kyc = KYCRequest(
|
|
user_id=f"user{i}",
|
|
name=f"User {i}",
|
|
email=f"user{i}@example.com",
|
|
document_type="passport",
|
|
document_number=f"ABC{i}",
|
|
address={"city": "New York"}
|
|
)
|
|
client.post("/api/v1/kyc/submit", json=kyc.model_dump())
|
|
|
|
response = client.get("/api/v1/kyc")
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["total_records"] == 5
|
|
assert data["approved"] == 5
|