| """ |
| Tests for SENTINEL Deep Threat Scanner. |
| """ |
|
|
| import pytest |
| import asyncio |
| from app.sentinel_deep import ( |
| SentinelDeepScanner, |
| SentinelDeepReport, |
| CollectionResult, |
| ThreatLevel, |
| CollectionName, |
| ) |
|
|
|
|
| class TestSentinelDeepScanner: |
| """Test SENTINEL Deep Scanner functionality.""" |
|
|
| @pytest.mark.asyncio |
| async def test_basic_scan(self): |
| """Should perform basic scan without errors.""" |
| scanner = SentinelDeepScanner() |
| report = await scanner.scan( |
| token_address="0x1234567890abcdef1234567890abcdef12345678", |
| chain="ethereum" |
| ) |
| assert report.token_address == "0x1234567890abcdef1234567890abcdef12345678" |
| assert report.chain == "ethereum" |
| assert len(report.collections) == 9 |
| await scanner.close() |
|
|
| @pytest.mark.asyncio |
| async def test_threat_level_safe(self): |
| """Should return SAFE threat level for low scores.""" |
| scanner = SentinelDeepScanner() |
| report = await scanner.scan( |
| token_address="0x1234567890abcdef1234567890abcdef12345678", |
| chain="ethereum" |
| ) |
| |
| assert report.threat_level == ThreatLevel.SAFE |
| await scanner.close() |
|
|
| @pytest.mark.asyncio |
| async def test_threat_level_critical(self): |
| """Should return CRITICAL threat level for high scores.""" |
| scanner = SentinelDeepScanner() |
| report = await scanner.scan( |
| token_address="0x1234567890abcdef1234567890abcdef12345678", |
| chain="ethereum", |
| lp_data={"lp_removed": True, "honeypot_detected": True, "sell_tax": 25} |
| ) |
| assert report.threat_level == ThreatLevel.CRITICAL |
| assert report.threat_score >= 80 |
| await scanner.close() |
|
|
| @pytest.mark.asyncio |
| async def test_collection_names(self): |
| """Should have all 9 security collections.""" |
| scanner = SentinelDeepScanner() |
| expected = { |
| "contract_health", |
| "liquidity_security", |
| "rug_imminence", |
| "mev_exposure", |
| "supply_manipulation", |
| "fee_manipulation", |
| "wash_trading", |
| "deployer_history", |
| "social_intelligence", |
| } |
| report = await scanner.scan( |
| token_address="0x1234567890abcdef1234567890abcdef12345678", |
| chain="ethereum" |
| ) |
| assert set(report.collections.keys()) == expected |
| await scanner.close() |
|
|
| @pytest.mark.asyncio |
| async def test_with_transaction_data(self): |
| """Should process transaction data for bundle detection.""" |
| scanner = SentinelDeepScanner() |
| txs = [ |
| {"from": f"0x{i:040x}"} for i in range(10) |
| ] |
| report = await scanner.scan( |
| token_address="0x1234567890abcdef1234567890abcdef12345678", |
| chain="ethereum", |
| transaction_data=txs |
| ) |
| assert report.collections["supply_manipulation"].score > 0 |
| await scanner.close() |
|
|
| @pytest.mark.asyncio |
| async def test_with_holder_data(self): |
| """Should process holder data for concentration analysis.""" |
| scanner = SentinelDeepScanner() |
| holders = [ |
| {"address": "addr1", "balance": 95}, |
| {"address": "addr2", "balance": 3}, |
| {"address": "addr3", "balance": 2}, |
| ] |
| report = await scanner.scan( |
| token_address="0x1234567890abcdef1234567890abcdef12345678", |
| chain="ethereum", |
| holder_data=holders |
| ) |
| assert report.collections["rug_imminence"].score > 0 |
| await scanner.close() |
|
|
| def test_threat_level_thresholds(self): |
| """Should correctly map scores to threat levels.""" |
| assert ThreatLevel(0).value == "safe" |
| assert ThreatLevel(1).value == "low" |
| |
| def test_report_to_dict(self): |
| """Should serialize report to dictionary.""" |
| report = SentinelDeepReport( |
| token_address="0xtest", |
| chain="ethereum", |
| threat_score=50.0, |
| threat_level=ThreatLevel.MEDIUM, |
| ) |
| result = report.to_dict() |
| assert result["token_address"] == "0xtest" |
| assert result["threat_score"] == 50.0 |
| assert result["threat_level"] == "medium" |
|
|
| def test_summary_generation(self): |
| """Should generate human-readable summary.""" |
| report = SentinelDeepReport( |
| token_address="0xtest", |
| chain="ethereum", |
| threat_score=25.0, |
| threat_level=ThreatLevel.LOW, |
| ) |
| summary = report.summary() |
| assert "🔵" in summary |
| assert "25" in summary or "25.0" in summary |
|
|
|
|
| if __name__ == "__main__": |
| asyncio.run(TestSentinelDeepScanner().test_basic_scan()) |
| print("All tests passed!") |