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/trading-engine/tests/__init__.py
Normal file
1
apps/trading-engine/tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Trading engine service tests"""
|
||||
208
apps/trading-engine/tests/test_edge_cases_trading_engine.py
Normal file
208
apps/trading-engine/tests/test_edge_cases_trading_engine.py
Normal file
@@ -0,0 +1,208 @@
|
||||
"""Edge case and error handling 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.unit
|
||||
def test_order_zero_quantity():
|
||||
"""Test Order with zero quantity"""
|
||||
order = Order(
|
||||
order_id="order_123",
|
||||
symbol="AITBC/BTC",
|
||||
side="buy",
|
||||
type="limit",
|
||||
quantity=0.0,
|
||||
price=0.00001,
|
||||
user_id="user_123",
|
||||
timestamp=datetime.utcnow()
|
||||
)
|
||||
assert order.quantity == 0.0
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_order_negative_quantity():
|
||||
"""Test Order with negative quantity"""
|
||||
order = Order(
|
||||
order_id="order_123",
|
||||
symbol="AITBC/BTC",
|
||||
side="buy",
|
||||
type="limit",
|
||||
quantity=-100.0,
|
||||
price=0.00001,
|
||||
user_id="user_123",
|
||||
timestamp=datetime.utcnow()
|
||||
)
|
||||
assert order.quantity == -100.0
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_order_negative_price():
|
||||
"""Test Order with negative price"""
|
||||
order = Order(
|
||||
order_id="order_123",
|
||||
symbol="AITBC/BTC",
|
||||
side="buy",
|
||||
type="limit",
|
||||
quantity=100.0,
|
||||
price=-0.00001,
|
||||
user_id="user_123",
|
||||
timestamp=datetime.utcnow()
|
||||
)
|
||||
assert order.price == -0.00001
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_order_empty_symbol():
|
||||
"""Test Order with empty symbol"""
|
||||
order = Order(
|
||||
order_id="order_123",
|
||||
symbol="",
|
||||
side="buy",
|
||||
type="limit",
|
||||
quantity=100.0,
|
||||
price=0.00001,
|
||||
user_id="user_123",
|
||||
timestamp=datetime.utcnow()
|
||||
)
|
||||
assert order.symbol == ""
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_cancel_filled_order():
|
||||
"""Test cancelling a filled order"""
|
||||
client = TestClient(app)
|
||||
order = Order(
|
||||
order_id="order_129",
|
||||
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'))
|
||||
|
||||
# Manually mark as filled
|
||||
orders["order_129"]["status"] = "filled"
|
||||
|
||||
response = client.delete("/api/v1/orders/order_129")
|
||||
assert response.status_code == 400
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_submit_order_with_slash_in_symbol():
|
||||
"""Test submitting order with slash in symbol"""
|
||||
client = TestClient(app)
|
||||
order = Order(
|
||||
order_id="order_130",
|
||||
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
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_submit_order_with_hyphen_in_symbol():
|
||||
"""Test submitting order with hyphen in symbol"""
|
||||
client = TestClient(app)
|
||||
order = Order(
|
||||
order_id="order_131",
|
||||
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
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_list_orders_with_no_orders():
|
||||
"""Test listing orders when no orders exist"""
|
||||
client = TestClient(app)
|
||||
response = client.get("/api/v1/orders")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["total_orders"] == 0
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_list_trades_with_no_trades():
|
||||
"""Test listing trades when no trades exist"""
|
||||
client = TestClient(app)
|
||||
response = client.get("/api/v1/trades")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["total_trades"] == 0
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_get_market_data_with_no_symbols():
|
||||
"""Test getting market data when no symbols exist"""
|
||||
client = TestClient(app)
|
||||
response = client.get("/api/v1/market-data")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["total_symbols"] == 0
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_order_book_depth_parameter():
|
||||
"""Test order book with depth parameter"""
|
||||
client = TestClient(app)
|
||||
order = Order(
|
||||
order_id="order_132",
|
||||
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/orderbook/AITBC-BTC?depth=5")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["symbol"] == "AITBC-BTC"
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_list_trades_limit_parameter():
|
||||
"""Test listing trades with limit parameter"""
|
||||
client = TestClient(app)
|
||||
response = client.get("/api/v1/trades?limit=10")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert "trades" in data
|
||||
264
apps/trading-engine/tests/test_integration_trading_engine.py
Normal file
264
apps/trading-engine/tests/test_integration_trading_engine.py
Normal 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
|
||||
89
apps/trading-engine/tests/test_unit_trading_engine.py
Normal file
89
apps/trading-engine/tests/test_unit_trading_engine.py
Normal file
@@ -0,0 +1,89 @@
|
||||
"""Unit tests for trading engine service"""
|
||||
|
||||
import pytest
|
||||
import sys
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
from main import app, Order, Trade, OrderBookEntry
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_app_initialization():
|
||||
"""Test that the FastAPI app initializes correctly"""
|
||||
assert app is not None
|
||||
assert app.title == "AITBC Trading Engine"
|
||||
assert app.version == "1.0.0"
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_order_model():
|
||||
"""Test Order model"""
|
||||
order = Order(
|
||||
order_id="order_123",
|
||||
symbol="AITBC/BTC",
|
||||
side="buy",
|
||||
type="limit",
|
||||
quantity=100.0,
|
||||
price=0.00001,
|
||||
user_id="user_123",
|
||||
timestamp=datetime.utcnow()
|
||||
)
|
||||
assert order.order_id == "order_123"
|
||||
assert order.symbol == "AITBC/BTC"
|
||||
assert order.side == "buy"
|
||||
assert order.type == "limit"
|
||||
assert order.quantity == 100.0
|
||||
assert order.price == 0.00001
|
||||
assert order.user_id == "user_123"
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_order_model_market_order():
|
||||
"""Test Order model for market order"""
|
||||
order = Order(
|
||||
order_id="order_123",
|
||||
symbol="AITBC/BTC",
|
||||
side="sell",
|
||||
type="market",
|
||||
quantity=50.0,
|
||||
user_id="user_123",
|
||||
timestamp=datetime.utcnow()
|
||||
)
|
||||
assert order.type == "market"
|
||||
assert order.price is None
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_trade_model():
|
||||
"""Test Trade model"""
|
||||
trade = Trade(
|
||||
trade_id="trade_123",
|
||||
symbol="AITBC/BTC",
|
||||
buy_order_id="buy_order_123",
|
||||
sell_order_id="sell_order_123",
|
||||
quantity=100.0,
|
||||
price=0.00001,
|
||||
timestamp=datetime.utcnow()
|
||||
)
|
||||
assert trade.trade_id == "trade_123"
|
||||
assert trade.symbol == "AITBC/BTC"
|
||||
assert trade.buy_order_id == "buy_order_123"
|
||||
assert trade.sell_order_id == "sell_order_123"
|
||||
assert trade.quantity == 100.0
|
||||
assert trade.price == 0.00001
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_order_book_entry_model():
|
||||
"""Test OrderBookEntry model"""
|
||||
entry = OrderBookEntry(
|
||||
price=0.00001,
|
||||
quantity=1000.0,
|
||||
orders_count=5
|
||||
)
|
||||
assert entry.price == 0.00001
|
||||
assert entry.quantity == 1000.0
|
||||
assert entry.orders_count == 5
|
||||
Reference in New Issue
Block a user