Add sys import to test files and remove obsolete integration tests
Some checks failed
API Endpoint Tests / test-api-endpoints (push) Successful in 9s
Blockchain Synchronization Verification / sync-verification (push) Failing after 1s
CLI Tests / test-cli (push) Failing after 3s
Documentation Validation / validate-docs (push) Successful in 6s
Documentation Validation / validate-policies-strict (push) Successful in 2s
Integration Tests / test-service-integration (push) Successful in 40s
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 1s
P2P Network Verification / p2p-verification (push) Successful in 2s
Production Tests / Production Integration Tests (push) Successful in 21s
Python Tests / test-python (push) Successful in 13s
Security Scanning / security-scan (push) Failing after 46s
Smart Contract Tests / test-solidity (map[name:aitbc-token path:packages/solidity/aitbc-token]) (push) Successful in 17s
Smart Contract Tests / lint-solidity (push) Successful in 10s
Some checks failed
API Endpoint Tests / test-api-endpoints (push) Successful in 9s
Blockchain Synchronization Verification / sync-verification (push) Failing after 1s
CLI Tests / test-cli (push) Failing after 3s
Documentation Validation / validate-docs (push) Successful in 6s
Documentation Validation / validate-policies-strict (push) Successful in 2s
Integration Tests / test-service-integration (push) Successful in 40s
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 1s
P2P Network Verification / p2p-verification (push) Successful in 2s
Production Tests / Production Integration Tests (push) Successful in 21s
Python Tests / test-python (push) Successful in 13s
Security Scanning / security-scan (push) Failing after 46s
Smart Contract Tests / test-solidity (map[name:aitbc-token path:packages/solidity/aitbc-token]) (push) Successful in 17s
Smart Contract Tests / lint-solidity (push) Successful in 10s
- Add sys import to 29 test files across agent-coordinator, blockchain-event-bridge, blockchain-node, and coordinator-api - Remove apps/blockchain-event-bridge/tests/test_integration.py (obsolete bridge integration tests) - Remove apps/coordinator-api/tests/test_integration.py (obsolete API integration tests) - Implement GPU registration in marketplace_gpu.py with GPURegistry model persistence
This commit is contained in:
1
apps/simple-explorer/tests/__init__.py
Normal file
1
apps/simple-explorer/tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Simple explorer service tests"""
|
||||
221
apps/simple-explorer/tests/test_edge_cases_simple_explorer.py
Normal file
221
apps/simple-explorer/tests/test_edge_cases_simple_explorer.py
Normal file
@@ -0,0 +1,221 @@
|
||||
"""Edge case and error handling tests for simple explorer service"""
|
||||
|
||||
import pytest
|
||||
import sys
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from unittest.mock import Mock, patch, AsyncMock
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
|
||||
# Mock httpx before importing
|
||||
sys.modules['httpx'] = Mock()
|
||||
|
||||
from main import app
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_get_transaction_missing_fields():
|
||||
"""Test transaction mapping with missing fields"""
|
||||
client = TestClient(app)
|
||||
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 200
|
||||
mock_response.json.return_value = {
|
||||
"tx_hash": "0x" + "a" * 64,
|
||||
# Missing sender, recipient, payload
|
||||
"created_at": "2026-01-01T00:00:00"
|
||||
}
|
||||
|
||||
mock_client = AsyncMock()
|
||||
mock_client.__aenter__.return_value = mock_client
|
||||
mock_client.get.return_value = mock_response
|
||||
|
||||
with patch('main.httpx.AsyncClient', return_value=mock_client):
|
||||
response = client.get("/api/transactions/" + "a" * 64)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["from"] == "unknown"
|
||||
assert data["to"] == "unknown"
|
||||
assert data["amount"] == "0"
|
||||
assert data["fee"] == "0"
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_get_transaction_empty_payload():
|
||||
"""Test transaction mapping with empty payload"""
|
||||
client = TestClient(app)
|
||||
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 200
|
||||
mock_response.json.return_value = {
|
||||
"tx_hash": "0x" + "a" * 64,
|
||||
"sender": "0xsender",
|
||||
"recipient": "0xrecipient",
|
||||
"payload": {},
|
||||
"created_at": "2026-01-01T00:00:00"
|
||||
}
|
||||
|
||||
mock_client = AsyncMock()
|
||||
mock_client.__aenter__.return_value = mock_client
|
||||
mock_client.get.return_value = mock_response
|
||||
|
||||
with patch('main.httpx.AsyncClient', return_value=mock_client):
|
||||
response = client.get("/api/transactions/" + "a" * 64)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["amount"] == "0"
|
||||
assert data["fee"] == "0"
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_get_transaction_missing_created_at():
|
||||
"""Test transaction mapping with missing created_at"""
|
||||
client = TestClient(app)
|
||||
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 200
|
||||
mock_response.json.return_value = {
|
||||
"tx_hash": "0x" + "a" * 64,
|
||||
"sender": "0xsender",
|
||||
"recipient": "0xrecipient",
|
||||
"payload": {"value": "1000", "fee": "10"}
|
||||
# Missing created_at
|
||||
}
|
||||
|
||||
mock_client = AsyncMock()
|
||||
mock_client.__aenter__.return_value = mock_client
|
||||
mock_client.get.return_value = mock_response
|
||||
|
||||
with patch('main.httpx.AsyncClient', return_value=mock_client):
|
||||
response = client.get("/api/transactions/" + "a" * 64)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["timestamp"] is None
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_get_transaction_missing_block_height():
|
||||
"""Test transaction mapping with missing block_height"""
|
||||
client = TestClient(app)
|
||||
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 200
|
||||
mock_response.json.return_value = {
|
||||
"tx_hash": "0x" + "a" * 64,
|
||||
"sender": "0xsender",
|
||||
"recipient": "0xrecipient",
|
||||
"payload": {"value": "1000", "fee": "10"},
|
||||
"created_at": "2026-01-01T00:00:00"
|
||||
# Missing block_height
|
||||
}
|
||||
|
||||
mock_client = AsyncMock()
|
||||
mock_client.__aenter__.return_value = mock_client
|
||||
mock_client.get.return_value = mock_response
|
||||
|
||||
with patch('main.httpx.AsyncClient', return_value=mock_client):
|
||||
response = client.get("/api/transactions/" + "a" * 64)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["block_height"] == "pending"
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_get_block_negative_height():
|
||||
"""Test /api/blocks/{height} with negative height"""
|
||||
client = TestClient(app)
|
||||
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 200
|
||||
mock_response.json.return_value = {
|
||||
"height": -1,
|
||||
"hash": "0xblock",
|
||||
"timestamp": 1234567890,
|
||||
"transactions": []
|
||||
}
|
||||
|
||||
mock_client = AsyncMock()
|
||||
mock_client.__aenter__.return_value = mock_client
|
||||
mock_client.get.return_value = mock_response
|
||||
|
||||
with patch('main.httpx.AsyncClient', return_value=mock_client):
|
||||
response = client.get("/api/blocks/-1")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["height"] == -1
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_get_block_zero_height():
|
||||
"""Test /api/blocks/{height} with zero height"""
|
||||
client = TestClient(app)
|
||||
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 200
|
||||
mock_response.json.return_value = {
|
||||
"height": 0,
|
||||
"hash": "0xgenesis",
|
||||
"timestamp": 1234567890,
|
||||
"transactions": []
|
||||
}
|
||||
|
||||
mock_client = AsyncMock()
|
||||
mock_client.__aenter__.return_value = mock_client
|
||||
mock_client.get.return_value = mock_response
|
||||
|
||||
with patch('main.httpx.AsyncClient', return_value=mock_client):
|
||||
response = client.get("/api/blocks/0")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["height"] == 0
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_get_transaction_short_hash():
|
||||
"""Test /api/transactions/{tx_hash} with short hash"""
|
||||
client = TestClient(app)
|
||||
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 200
|
||||
mock_response.json.return_value = {
|
||||
"tx_hash": "0x" + "a" * 64,
|
||||
"sender": "0xsender",
|
||||
"recipient": "0xrecipient",
|
||||
"payload": {"value": "1000", "fee": "10"},
|
||||
"created_at": "2026-01-01T00:00:00",
|
||||
"block_height": 100
|
||||
}
|
||||
|
||||
mock_client = AsyncMock()
|
||||
mock_client.__aenter__.return_value = mock_client
|
||||
mock_client.get.return_value = mock_response
|
||||
|
||||
with patch('main.httpx.AsyncClient', return_value=mock_client):
|
||||
response = client.get("/api/transactions/abc")
|
||||
assert response.status_code in [200, 404, 500] # Any valid response
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_get_transaction_invalid_hex_hash():
|
||||
"""Test /api/transactions/{tx_hash} with invalid hex characters"""
|
||||
client = TestClient(app)
|
||||
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 200
|
||||
mock_response.json.return_value = {
|
||||
"tx_hash": "0x" + "a" * 64,
|
||||
"sender": "0xsender",
|
||||
"recipient": "0xrecipient",
|
||||
"payload": {"value": "1000", "fee": "10"},
|
||||
"created_at": "2026-01-01T00:00:00",
|
||||
"block_height": 100
|
||||
}
|
||||
|
||||
mock_client = AsyncMock()
|
||||
mock_client.__aenter__.return_value = mock_client
|
||||
mock_client.get.return_value = mock_response
|
||||
|
||||
with patch('main.httpx.AsyncClient', return_value=mock_client):
|
||||
response = client.get("/api/transactions/" + "z" * 64)
|
||||
assert response.status_code in [200, 404, 500]
|
||||
170
apps/simple-explorer/tests/test_integration_simple_explorer.py
Normal file
170
apps/simple-explorer/tests/test_integration_simple_explorer.py
Normal file
@@ -0,0 +1,170 @@
|
||||
"""Integration tests for simple explorer service"""
|
||||
|
||||
import pytest
|
||||
import sys
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from unittest.mock import Mock, patch, AsyncMock
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
|
||||
# Mock httpx before importing
|
||||
sys.modules['httpx'] = Mock()
|
||||
|
||||
from main import app
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_root_endpoint():
|
||||
"""Test root endpoint serves HTML"""
|
||||
client = TestClient(app)
|
||||
response = client.get("/")
|
||||
assert response.status_code == 200
|
||||
assert "text/html" in response.headers["content-type"]
|
||||
assert "AITBC Blockchain Explorer" in response.text
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_get_chain_head_success():
|
||||
"""Test /api/chain/head endpoint with successful response"""
|
||||
client = TestClient(app)
|
||||
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 200
|
||||
mock_response.json.return_value = {"height": 100, "hash": "0xabc123", "timestamp": 1234567890}
|
||||
|
||||
mock_client = AsyncMock()
|
||||
mock_client.__aenter__.return_value = mock_client
|
||||
mock_client.get.return_value = mock_response
|
||||
|
||||
with patch('main.httpx.AsyncClient', return_value=mock_client):
|
||||
response = client.get("/api/chain/head")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["height"] == 100
|
||||
assert data["hash"] == "0xabc123"
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_get_chain_head_error():
|
||||
"""Test /api/chain/head endpoint with error"""
|
||||
client = TestClient(app)
|
||||
|
||||
mock_client = AsyncMock()
|
||||
mock_client.__aenter__.return_value = mock_client
|
||||
mock_client.get.side_effect = Exception("RPC error")
|
||||
|
||||
with patch('main.httpx.AsyncClient', return_value=mock_client):
|
||||
response = client.get("/api/chain/head")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["height"] == 0
|
||||
assert data["hash"] == ""
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_get_block_success():
|
||||
"""Test /api/blocks/{height} endpoint with successful response"""
|
||||
client = TestClient(app)
|
||||
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 200
|
||||
mock_response.json.return_value = {
|
||||
"height": 50,
|
||||
"hash": "0xblock50",
|
||||
"timestamp": 1234567890,
|
||||
"transactions": []
|
||||
}
|
||||
|
||||
mock_client = AsyncMock()
|
||||
mock_client.__aenter__.return_value = mock_client
|
||||
mock_client.get.return_value = mock_response
|
||||
|
||||
with patch('main.httpx.AsyncClient', return_value=mock_client):
|
||||
response = client.get("/api/blocks/50")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["height"] == 50
|
||||
assert data["hash"] == "0xblock50"
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_get_block_error():
|
||||
"""Test /api/blocks/{height} endpoint with error"""
|
||||
client = TestClient(app)
|
||||
|
||||
mock_client = AsyncMock()
|
||||
mock_client.__aenter__.return_value = mock_client
|
||||
mock_client.get.side_effect = Exception("RPC error")
|
||||
|
||||
with patch('main.httpx.AsyncClient', return_value=mock_client):
|
||||
response = client.get("/api/blocks/50")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["height"] == 50
|
||||
assert data["hash"] == ""
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_get_transaction_success():
|
||||
"""Test /api/transactions/{tx_hash} endpoint with successful response"""
|
||||
client = TestClient(app)
|
||||
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 200
|
||||
mock_response.json.return_value = {
|
||||
"tx_hash": "0x" + "a" * 64,
|
||||
"sender": "0xsender",
|
||||
"recipient": "0xrecipient",
|
||||
"payload": {
|
||||
"value": "1000",
|
||||
"fee": "10"
|
||||
},
|
||||
"created_at": "2026-01-01T00:00:00",
|
||||
"block_height": 100
|
||||
}
|
||||
|
||||
mock_client = AsyncMock()
|
||||
mock_client.__aenter__.return_value = mock_client
|
||||
mock_client.get.return_value = mock_response
|
||||
|
||||
with patch('main.httpx.AsyncClient', return_value=mock_client):
|
||||
response = client.get("/api/transactions/" + "a" * 64)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["hash"] == "0x" + "a" * 64
|
||||
assert data["from"] == "0xsender"
|
||||
assert data["to"] == "0xrecipient"
|
||||
assert data["amount"] == "1000"
|
||||
assert data["fee"] == "10"
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_get_transaction_not_found():
|
||||
"""Test /api/transactions/{tx_hash} endpoint with 404 response"""
|
||||
client = TestClient(app)
|
||||
|
||||
mock_response = Mock()
|
||||
mock_response.status_code = 404
|
||||
|
||||
mock_client = AsyncMock()
|
||||
mock_client.__aenter__.return_value = mock_client
|
||||
mock_client.get.return_value = mock_response
|
||||
|
||||
with patch('main.httpx.AsyncClient', return_value=mock_client):
|
||||
response = client.get("/api/transactions/" + "a" * 64)
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_get_transaction_error():
|
||||
"""Test /api/transactions/{tx_hash} endpoint with error"""
|
||||
client = TestClient(app)
|
||||
|
||||
mock_client = AsyncMock()
|
||||
mock_client.__aenter__.return_value = mock_client
|
||||
mock_client.get.side_effect = Exception("RPC error")
|
||||
|
||||
with patch('main.httpx.AsyncClient', return_value=mock_client):
|
||||
response = client.get("/api/transactions/" + "a" * 64)
|
||||
assert response.status_code == 500
|
||||
70
apps/simple-explorer/tests/test_unit_simple_explorer.py
Normal file
70
apps/simple-explorer/tests/test_unit_simple_explorer.py
Normal file
@@ -0,0 +1,70 @@
|
||||
"""Unit tests for simple explorer service"""
|
||||
|
||||
import pytest
|
||||
import sys
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from unittest.mock import Mock, patch, AsyncMock
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
# Mock httpx before importing
|
||||
sys.modules['httpx'] = Mock()
|
||||
|
||||
from main import app, BLOCKCHAIN_RPC_URL, HTML_TEMPLATE
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_app_initialization():
|
||||
"""Test that the FastAPI app initializes correctly"""
|
||||
assert app is not None
|
||||
assert app.title == "Simple AITBC Explorer"
|
||||
assert app.version == "0.1.0"
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_blockchain_rpc_url():
|
||||
"""Test that the blockchain RPC URL is configured"""
|
||||
assert BLOCKCHAIN_RPC_URL == "http://localhost:8025"
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_html_template_exists():
|
||||
"""Test that the HTML template is defined"""
|
||||
assert HTML_TEMPLATE is not None
|
||||
assert "<!DOCTYPE html>" in HTML_TEMPLATE
|
||||
assert "AITBC Blockchain Explorer" in HTML_TEMPLATE
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_html_template_has_search():
|
||||
"""Test that the HTML template has search functionality"""
|
||||
assert "search-input" in HTML_TEMPLATE
|
||||
assert "performSearch()" in HTML_TEMPLATE
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_html_template_has_blocks_section():
|
||||
"""Test that the HTML template has blocks section"""
|
||||
assert "Latest Blocks" in HTML_TEMPLATE
|
||||
assert "blocks-list" in HTML_TEMPLATE
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_html_template_has_results_section():
|
||||
"""Test that the HTML template has results section"""
|
||||
assert "Transaction Details" in HTML_TEMPLATE
|
||||
assert "tx-details" in HTML_TEMPLATE
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_html_template_has_tailwind():
|
||||
"""Test that the HTML template includes Tailwind CSS"""
|
||||
assert "tailwindcss" in HTML_TEMPLATE
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_html_template_format_timestamp_function():
|
||||
"""Test that the HTML template has formatTimestamp function"""
|
||||
assert "formatTimestamp" in HTML_TEMPLATE
|
||||
assert "toLocaleString" in HTML_TEMPLATE
|
||||
Reference in New Issue
Block a user