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
145 lines
3.3 KiB
Python
145 lines
3.3 KiB
Python
"""Unit tests for exchange service"""
|
|
|
|
import pytest
|
|
import sys
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
from exchange_api import app, OrderCreate, OrderResponse, TradeResponse, OrderBookResponse
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_app_initialization():
|
|
"""Test that the FastAPI app initializes correctly"""
|
|
assert app is not None
|
|
assert app.title == "AITBC Trade Exchange API"
|
|
assert app.version == "1.0.0"
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_order_create_model():
|
|
"""Test OrderCreate model"""
|
|
order = OrderCreate(
|
|
order_type="BUY",
|
|
amount=100.0,
|
|
price=0.00001
|
|
)
|
|
assert order.order_type == "BUY"
|
|
assert order.amount == 100.0
|
|
assert order.price == 0.00001
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_order_create_model_sell():
|
|
"""Test OrderCreate model with SELL"""
|
|
order = OrderCreate(
|
|
order_type="SELL",
|
|
amount=50.0,
|
|
price=0.00002
|
|
)
|
|
assert order.order_type == "SELL"
|
|
assert order.amount == 50.0
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_order_response_model():
|
|
"""Test OrderResponse model"""
|
|
from datetime import datetime
|
|
order = OrderResponse(
|
|
id=1,
|
|
order_type="BUY",
|
|
amount=100.0,
|
|
price=0.00001,
|
|
total=0.001,
|
|
filled=0.0,
|
|
remaining=100.0,
|
|
status="OPEN",
|
|
created_at=datetime.utcnow()
|
|
)
|
|
assert order.id == 1
|
|
assert order.order_type == "BUY"
|
|
assert order.amount == 100.0
|
|
assert order.status == "OPEN"
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_trade_response_model():
|
|
"""Test TradeResponse model"""
|
|
from datetime import datetime
|
|
trade = TradeResponse(
|
|
id=1,
|
|
amount=50.0,
|
|
price=0.00001,
|
|
total=0.0005,
|
|
created_at=datetime.utcnow()
|
|
)
|
|
assert trade.id == 1
|
|
assert trade.amount == 50.0
|
|
assert trade.total == 0.0005
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_order_book_response_model():
|
|
"""Test OrderBookResponse model"""
|
|
from datetime import datetime
|
|
buy_order = OrderResponse(
|
|
id=1,
|
|
order_type="BUY",
|
|
amount=100.0,
|
|
price=0.00001,
|
|
total=0.001,
|
|
filled=0.0,
|
|
remaining=100.0,
|
|
status="OPEN",
|
|
created_at=datetime.utcnow()
|
|
)
|
|
sell_order = OrderResponse(
|
|
id=2,
|
|
order_type="SELL",
|
|
amount=50.0,
|
|
price=0.00002,
|
|
total=0.001,
|
|
filled=0.0,
|
|
remaining=50.0,
|
|
status="OPEN",
|
|
created_at=datetime.utcnow()
|
|
)
|
|
orderbook = OrderBookResponse(buys=[buy_order], sells=[sell_order])
|
|
assert len(orderbook.buys) == 1
|
|
assert len(orderbook.sells) == 1
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_order_create_negative_amount():
|
|
"""Test OrderCreate with negative amount"""
|
|
order = OrderCreate(
|
|
order_type="BUY",
|
|
amount=-10.0,
|
|
price=0.00001
|
|
)
|
|
assert order.amount == -10.0
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_order_create_zero_price():
|
|
"""Test OrderCreate with zero price"""
|
|
order = OrderCreate(
|
|
order_type="BUY",
|
|
amount=100.0,
|
|
price=0.0
|
|
)
|
|
assert order.price == 0.0
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_order_create_invalid_type():
|
|
"""Test OrderCreate with invalid order type"""
|
|
# Model accepts any string, validation happens at endpoint level
|
|
order = OrderCreate(
|
|
order_type="INVALID",
|
|
amount=100.0,
|
|
price=0.00001
|
|
)
|
|
assert order.order_type == "INVALID"
|