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

- 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:
aitbc
2026-04-23 16:43:17 +02:00
parent b8b1454573
commit e60cc3226c
134 changed files with 14321 additions and 1873 deletions

View File

@@ -0,0 +1,264 @@
"""Integration tests for trading engine service"""
import pytest
import sys
import sys
from pathlib import Path
from fastapi.testclient import TestClient
from datetime import datetime
from main import app, Order, order_books, orders, trades
@pytest.fixture(autouse=True)
def reset_state():
"""Reset global state before each test"""
order_books.clear()
orders.clear()
trades.clear()
yield
order_books.clear()
orders.clear()
trades.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 Trading Engine"
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 "active_order_books" in data
assert "total_orders" in data
@pytest.mark.integration
def test_submit_market_order():
"""Test submitting a market order"""
client = TestClient(app)
order = Order(
order_id="order_123",
symbol="AITBC/BTC",
side="buy",
type="market",
quantity=100.0,
user_id="user_123",
timestamp=datetime.utcnow()
)
response = client.post("/api/v1/orders/submit", json=order.model_dump(mode='json'))
assert response.status_code == 200
data = response.json()
assert data["order_id"] == "order_123"
assert "status" in data
@pytest.mark.integration
def test_submit_limit_order():
"""Test submitting a limit order"""
client = TestClient(app)
order = Order(
order_id="order_124",
symbol="AITBC/BTC",
side="buy",
type="limit",
quantity=100.0,
price=0.00001,
user_id="user_123",
timestamp=datetime.utcnow()
)
response = client.post("/api/v1/orders/submit", json=order.model_dump(mode='json'))
assert response.status_code == 200
data = response.json()
assert data["order_id"] == "order_124"
assert "status" in data
@pytest.mark.integration
def test_get_order():
"""Test getting order details"""
client = TestClient(app)
order = Order(
order_id="order_125",
symbol="AITBC/BTC",
side="buy",
type="limit",
quantity=100.0,
price=0.00001,
user_id="user_123",
timestamp=datetime.utcnow()
)
client.post("/api/v1/orders/submit", json=order.model_dump(mode='json'))
response = client.get("/api/v1/orders/order_125")
assert response.status_code == 200
data = response.json()
assert data["order_id"] == "order_125"
@pytest.mark.integration
def test_get_order_not_found():
"""Test getting nonexistent order"""
client = TestClient(app)
response = client.get("/api/v1/orders/nonexistent")
assert response.status_code == 404
@pytest.mark.integration
def test_list_orders():
"""Test listing all orders"""
client = TestClient(app)
response = client.get("/api/v1/orders")
assert response.status_code == 200
data = response.json()
assert "orders" in data
assert "total_orders" in data
@pytest.mark.integration
def test_get_order_book():
"""Test getting order book"""
client = TestClient(app)
# Create some orders first
order1 = Order(
order_id="order_126",
symbol="AITBC-BTC",
side="buy",
type="limit",
quantity=100.0,
price=0.00001,
user_id="user_123",
timestamp=datetime.utcnow()
)
client.post("/api/v1/orders/submit", json=order1.model_dump(mode='json'))
response = client.get("/api/v1/orderbook/AITBC-BTC")
assert response.status_code == 200
data = response.json()
assert data["symbol"] == "AITBC-BTC"
assert "bids" in data
assert "asks" in data
@pytest.mark.integration
def test_get_order_book_not_found():
"""Test getting order book for nonexistent symbol"""
client = TestClient(app)
response = client.get("/api/v1/orderbook/NONEXISTENT")
assert response.status_code == 404
@pytest.mark.integration
def test_list_trades():
"""Test listing trades"""
client = TestClient(app)
response = client.get("/api/v1/trades")
assert response.status_code == 200
data = response.json()
assert "trades" in data
assert "total_trades" in data
@pytest.mark.integration
def test_list_trades_by_symbol():
"""Test listing trades by symbol"""
client = TestClient(app)
response = client.get("/api/v1/trades?symbol=AITBC-BTC")
assert response.status_code == 200
data = response.json()
assert "trades" in data
@pytest.mark.integration
def test_get_ticker():
"""Test getting ticker information"""
client = TestClient(app)
# Create order book first
order = Order(
order_id="order_127",
symbol="AITBC-BTC",
side="buy",
type="limit",
quantity=100.0,
price=0.00001,
user_id="user_123",
timestamp=datetime.utcnow()
)
client.post("/api/v1/orders/submit", json=order.model_dump(mode='json'))
response = client.get("/api/v1/ticker/AITBC-BTC")
assert response.status_code == 200
data = response.json()
assert data["symbol"] == "AITBC-BTC"
@pytest.mark.integration
def test_get_ticker_not_found():
"""Test getting ticker for nonexistent symbol"""
client = TestClient(app)
response = client.get("/api/v1/ticker/NONEXISTENT")
assert response.status_code == 404
@pytest.mark.integration
def test_cancel_order():
"""Test cancelling an order"""
client = TestClient(app)
order = Order(
order_id="order_128",
symbol="AITBC/BTC",
side="buy",
type="limit",
quantity=100.0,
price=0.00001,
user_id="user_123",
timestamp=datetime.utcnow()
)
client.post("/api/v1/orders/submit", json=order.model_dump(mode='json'))
response = client.delete("/api/v1/orders/order_128")
assert response.status_code == 200
data = response.json()
assert data["status"] == "cancelled"
@pytest.mark.integration
def test_cancel_order_not_found():
"""Test cancelling nonexistent order"""
client = TestClient(app)
response = client.delete("/api/v1/orders/nonexistent")
assert response.status_code == 404
@pytest.mark.integration
def test_get_market_data():
"""Test getting market data"""
client = TestClient(app)
response = client.get("/api/v1/market-data")
assert response.status_code == 200
data = response.json()
assert "market_data" in data
assert "total_symbols" in data
@pytest.mark.integration
def test_get_engine_stats():
"""Test getting engine statistics"""
client = TestClient(app)
response = client.get("/api/v1/engine/stats")
assert response.status_code == 200
data = response.json()
assert "engine_stats" in data