Some checks failed
API Endpoint Tests / test-api-endpoints (push) Successful in 22s
Blockchain Synchronization Verification / sync-verification (push) Successful in 3s
CLI Tests / test-cli (push) Failing after 13s
Cross-Chain Functionality Tests / test-cross-chain-sync (push) Failing after 3s
Cross-Chain Functionality Tests / test-cross-chain-transactions (push) Successful in 3s
Cross-Chain Functionality Tests / test-cross-chain-bridge (push) Has been skipped
Cross-Chain Functionality Tests / test-multi-chain-consensus (push) Failing after 3s
Cross-Chain Functionality Tests / aggregate-results (push) Has been skipped
Cross-Node Transaction Testing / transaction-test (push) Successful in 2s
Deploy to Testnet / deploy-testnet (push) Successful in 1m34s
Documentation Validation / validate-docs (push) Failing after 10s
Documentation Validation / validate-policies-strict (push) Successful in 3s
Multi-Node Stress Testing / stress-test (push) Has been cancelled
Node Failover Simulation / failover-test (push) Has been cancelled
Python Tests / test-python (push) Has been cancelled
Integration Tests / test-service-integration (push) Successful in 2m42s
Multi-Chain Island Architecture Tests / test-multi-chain-island (push) Successful in 3s
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 5s
P2P Network Verification / p2p-verification (push) Successful in 3s
Package Tests / Python package - aitbc-agent-sdk (push) Failing after 33s
Package Tests / Python package - aitbc-core (push) Successful in 17s
Package Tests / Python package - aitbc-crypto (push) Successful in 11s
Security Scanning / security-scan (push) Has been cancelled
Package Tests / Python package - aitbc-sdk (push) Successful in 13s
Package Tests / JavaScript package - aitbc-sdk-js (push) Successful in 9s
Package Tests / JavaScript package - aitbc-token (push) Successful in 17s
Staking Tests / test-staking-service (push) Failing after 6s
Staking Tests / test-staking-integration (push) Has been skipped
Staking Tests / test-staking-contract (push) Has been skipped
Staking Tests / run-staking-test-runner (push) Has been skipped
253 lines
7.4 KiB
Python
253 lines
7.4 KiB
Python
"""Integration 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.integration
|
|
def test_root_endpoint():
|
|
"""Test root endpoint"""
|
|
client = TestClient(app)
|
|
response = client.get("/")
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["service"] == "AITBC Compliance Service"
|
|
assert data["status"] == "running"
|
|
|
|
|
|
@pytest.mark.integration
|
|
def test_health_check_endpoint():
|
|
"""Test health check endpoint"""
|
|
client = TestClient(app)
|
|
response = client.get("/health")
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["status"] == "healthy"
|
|
assert "kyc_records" in data
|
|
assert "compliance_reports" in data
|
|
|
|
|
|
@pytest.mark.integration
|
|
def test_submit_kyc():
|
|
"""Test KYC submission"""
|
|
client = TestClient(app)
|
|
kyc = KYCRequest(
|
|
user_id="user123",
|
|
name="John Doe",
|
|
email="john@example.com",
|
|
document_type="passport",
|
|
document_number="ABC123",
|
|
address={"street": "123 Main St", "city": "New York", "country": "USA"}
|
|
)
|
|
response = client.post("/api/v1/kyc/submit", json=kyc.model_dump())
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["user_id"] == "user123"
|
|
assert data["status"] == "approved"
|
|
assert data["risk_score"] == "low"
|
|
|
|
|
|
@pytest.mark.integration
|
|
def test_submit_duplicate_kyc():
|
|
"""Test submitting duplicate KYC"""
|
|
client = TestClient(app)
|
|
kyc = KYCRequest(
|
|
user_id="user123",
|
|
name="John Doe",
|
|
email="john@example.com",
|
|
document_type="passport",
|
|
document_number="ABC123",
|
|
address={"street": "123 Main St", "city": "New York", "country": "USA"}
|
|
)
|
|
|
|
# First submission
|
|
client.post("/api/v1/kyc/submit", json=kyc.model_dump())
|
|
|
|
# Second submission should fail
|
|
response = client.post("/api/v1/kyc/submit", json=kyc.model_dump())
|
|
assert response.status_code == 400
|
|
|
|
|
|
@pytest.mark.integration
|
|
def test_get_kyc_status():
|
|
"""Test getting KYC status"""
|
|
client = TestClient(app)
|
|
kyc = KYCRequest(
|
|
user_id="user123",
|
|
name="John Doe",
|
|
email="john@example.com",
|
|
document_type="passport",
|
|
document_number="ABC123",
|
|
address={"street": "123 Main St", "city": "New York", "country": "USA"}
|
|
)
|
|
|
|
# Submit KYC first
|
|
client.post("/api/v1/kyc/submit", json=kyc.model_dump())
|
|
|
|
# Get KYC status
|
|
response = client.get("/api/v1/kyc/user123")
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["user_id"] == "user123"
|
|
assert data["status"] == "approved"
|
|
|
|
|
|
@pytest.mark.integration
|
|
def test_get_kyc_status_not_found():
|
|
"""Test getting KYC status for nonexistent user"""
|
|
client = TestClient(app)
|
|
response = client.get("/api/v1/kyc/nonexistent")
|
|
assert response.status_code == 404
|
|
|
|
|
|
@pytest.mark.integration
|
|
def test_list_kyc_records():
|
|
"""Test listing KYC records"""
|
|
client = TestClient(app)
|
|
response = client.get("/api/v1/kyc")
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert "kyc_records" in data
|
|
assert "total_records" in data
|
|
|
|
|
|
@pytest.mark.integration
|
|
def test_create_compliance_report():
|
|
"""Test creating compliance report"""
|
|
client = TestClient(app)
|
|
report = ComplianceReport(
|
|
report_type="suspicious_activity",
|
|
description="Suspicious transaction detected",
|
|
severity="high",
|
|
details={"transaction_id": "tx123"}
|
|
)
|
|
response = client.post("/api/v1/compliance/report", json=report.model_dump())
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["severity"] == "high"
|
|
assert data["status"] == "created"
|
|
|
|
|
|
@pytest.mark.integration
|
|
def test_list_compliance_reports():
|
|
"""Test listing compliance reports"""
|
|
client = TestClient(app)
|
|
response = client.get("/api/v1/compliance/reports")
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert "reports" in data
|
|
assert "total_reports" in data
|
|
|
|
|
|
@pytest.mark.integration
|
|
def test_monitor_transaction():
|
|
"""Test transaction monitoring"""
|
|
client = TestClient(app)
|
|
tx = TransactionMonitoring(
|
|
transaction_id="tx123",
|
|
user_id="user123",
|
|
amount=1000.0,
|
|
currency="BTC",
|
|
counterparty="counterparty1",
|
|
timestamp=datetime.now(timezone.utc)
|
|
)
|
|
response = client.post("/api/v1/monitoring/transaction", json=tx.model_dump(mode='json'))
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["transaction_id"] == "tx123"
|
|
assert "risk_score" in data
|
|
|
|
|
|
@pytest.mark.integration
|
|
def test_monitor_suspicious_transaction():
|
|
"""Test monitoring suspicious transaction"""
|
|
client = TestClient(app)
|
|
tx = TransactionMonitoring(
|
|
transaction_id="tx123",
|
|
user_id="user123",
|
|
amount=100000.0,
|
|
currency="BTC",
|
|
counterparty="high_risk_entity_1",
|
|
timestamp=datetime.now(timezone.utc)
|
|
)
|
|
response = client.post("/api/v1/monitoring/transaction", json=tx.model_dump(mode='json'))
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["status"] == "flagged"
|
|
assert len(data["flags"]) > 0
|
|
|
|
|
|
@pytest.mark.integration
|
|
def test_list_monitored_transactions():
|
|
"""Test listing monitored transactions"""
|
|
client = TestClient(app)
|
|
response = client.get("/api/v1/monitoring/transactions")
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert "transactions" in data
|
|
assert "total_transactions" in data
|
|
|
|
|
|
@pytest.mark.integration
|
|
def test_create_compliance_rule():
|
|
"""Test creating compliance rule"""
|
|
client = TestClient(app)
|
|
rule_data = {
|
|
"name": "High Value Transaction Rule",
|
|
"description": "Flag transactions over $50,000",
|
|
"type": "transaction_monitoring",
|
|
"conditions": {"min_amount": 50000},
|
|
"actions": ["flag", "report"],
|
|
"severity": "high"
|
|
}
|
|
response = client.post("/api/v1/rules/create", json=rule_data)
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["name"] == "High Value Transaction Rule"
|
|
assert data["active"] is True
|
|
|
|
|
|
@pytest.mark.integration
|
|
def test_list_compliance_rules():
|
|
"""Test listing compliance rules"""
|
|
client = TestClient(app)
|
|
response = client.get("/api/v1/rules")
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert "rules" in data
|
|
assert "total_rules" in data
|
|
|
|
|
|
@pytest.mark.integration
|
|
def test_compliance_dashboard():
|
|
"""Test compliance dashboard"""
|
|
client = TestClient(app)
|
|
response = client.get("/api/v1/dashboard")
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert "summary" in data
|
|
assert "risk_distribution" in data
|
|
assert "recent_activity" in data
|