This document provides an overview of the testing strategy for the EdgeX Python SDK, including which components are covered by tests and which are not.
- Test Structure
- Unit Tests
- Integration Tests
- Test Coverage
- Running Tests
- Test Environment
- Future Test Improvements
The EdgeX Python SDK test suite is organized into two main categories:
-
Unit Tests: Located in
python_sdk/tests/, these tests focus on individual components and functions without requiring external API connections. -
Integration Tests: Located in
python_sdk/tests/integration/, these tests verify the SDK's interaction with the EdgeX API endpoints.
File: tests/test_eip712_signing.py
These tests verify the v2 EIP-712 signing helpers used by order creation and signer address derivation.
Coverage:
- ✅ Address derivation from private keys
- ✅ Typed-data signing
- ✅ Basic signature shape validation
Test Cases:
test_derive_address_from_private_key: Tests address derivation from a v2 trading keytest_sign_typed_data: Tests typed-data signature generation
File: tests/test_client.py
These tests verify the functionality of the main client class, which serves as the entry point for the SDK.
Coverage:
- ✅ Client initialization
- ✅ Parameter validation
- ✅ Method delegation to specialized clients
Test Cases:
test_init: Tests client initialization with valid parameterstest_init_invalid_params: Tests client initialization with invalid parameters
File: tests/test_async_client.py
These tests verify the functionality of the async client helpers that handle low-level request preparation and signing helpers.
Coverage:
- ✅ Request signing
- ✅ Timestamp generation
- ✅ Header construction
- ✅ Parameter validation
Test Cases:
test_parse_resolution: Tests resolution parsingtest_resolve_trading_signer_address: Tests trading signer address derivationtest_sign_typed_data_with_trading_key: Tests typed-data signing with the trading private key
Integration tests verify the SDK's interaction with the EdgeX API endpoints. Most of these tests require valid API credentials to pass, except for tests of public endpoints.
Note: For information about public endpoints that can be tested without credentials, see PUBLIC_ENDPOINTS.md.
File: tests/integration/test_account.py
Coverage:
- ✅ Account retrieval
- ✅ Asset information retrieval
- ✅ Position information retrieval
- ✅ Transaction history retrieval
Test Cases:
test_get_account_by_id: Tests retrieving account informationtest_get_account_asset: Tests retrieving account asset informationtest_get_account_positions: Tests retrieving account positionstest_get_position_transaction_page: Tests retrieving position transaction historytest_get_collateral_transaction_page: Tests retrieving collateral transaction history
File: tests/integration/test_metadata.py
Coverage:
- ✅ Contract metadata retrieval
- ✅ Server time retrieval
Test Cases:
test_get_metadata: Tests retrieving contract metadatatest_get_server_time: Tests retrieving server timetest_contract_exists: Tests checking if a contract exists
File: tests/integration/test_order.py
Coverage:
- ✅ Order creation
- ✅ Order cancellation
- ✅ Active order retrieval
- ✅ Order fill transaction retrieval
- ✅ Maximum order size retrieval
Test Cases:
test_create_and_cancel_order: Tests creating and canceling an ordertest_get_active_orders: Tests retrieving active orderstest_get_order_fill_transactions: Tests retrieving order fill transactionstest_get_max_order_size: Tests retrieving maximum order size
File: tests/integration/test_quote.py
Coverage:
- ✅ 24-hour quote retrieval
- ✅ K-line data retrieval
- ✅ Order book depth retrieval
- ✅ Multi-contract K-line data retrieval
Test Cases:
test_get_24_hour_quote: Tests retrieving 24-hour quotestest_get_k_line: Tests retrieving K-line datatest_get_order_book_depth: Tests retrieving order book depthtest_get_multi_contract_k_line: Tests retrieving multi-contract K-line data
File: tests/integration/test_websocket.py
Coverage:
- ✅ Public WebSocket connection
- ✅ Private WebSocket connection
- ✅ Subscription to various channels
- ✅ Message handling
Test Cases:
test_public_websocket: Tests connecting to the public WebSockettest_private_websocket: Tests connecting to the private WebSocket
The following components have good test coverage:
- EIP-712 Signing Helpers: Comprehensive unit tests for the v2 order-signing flow
- Client Initialization: Thorough testing of parameter validation and initialization
- API Endpoint Structure: Integration tests cover all major API endpoints
The following components have partial test coverage:
- Error Handling: Some error conditions are tested, but not all possible error scenarios
- WebSocket Message Handling: Basic connection is tested, but not all message types
- Response Parsing: Basic parsing is tested, but not all edge cases
The following components could benefit from additional test coverage:
- Reconnection Logic: WebSocket reconnection logic is not thoroughly tested
- Rate Limiting: Handling of API rate limits is not tested
- Long-Running Operations: Tests for long-running operations or pagination
- Concurrency: Tests for concurrent API calls
- Transfer and Asset Clients: Missing dedicated integration tests
To run all unit tests:
cd python_sdk
python -m unittest discover testsTo run a specific test file:
cd python_sdk
python -m unittest tests/test_eip712_signing.pyTo run integration tests with real API credentials:
cd python_sdk
python run_integration_tests.pyNote: This requires setting the following environment variables:
EDGEX_BASE_URL: The base URL for the EdgeX APIEDGEX_WS_URL: The WebSocket URL for the EdgeX APIEDGEX_ACCOUNT_ID: Your EdgeX account IDEDGEX_TRADING_PRIVATE_KEY: Your trading private keyEDGEX_API_KEY: Your API keyEDGEX_API_PASSPHRASE: Your API passphraseEDGEX_API_SECRET: Your API secret
Example:
export EDGEX_ACCOUNT_ID="your_account_id_here"
export EDGEX_TRADING_PRIVATE_KEY="your_trading_private_key_here"
export EDGEX_API_KEY="your_api_key_here"
export EDGEX_API_PASSPHRASE="your_api_passphrase_here"
export EDGEX_API_SECRET="your_api_secret_here"To run only the tests for public endpoints (which don't require authentication):
cd python_sdk
python run_public_tests.pyThis script uses dummy values for the required environment variables and only tests endpoints that don't require authentication.
Note: Some tests, particularly the WebSocket test, may be skipped due to connection issues or API limitations. This is expected behavior and doesn't indicate a problem with the SDK.
To run integration tests with mock values (for testing the SDK structure without real API calls):
cd python_sdk
python run_mock_tests.pyThe tests are designed to run in the following environments:
- Unit Tests: Can run in any environment with Python 3.7+
- Integration Tests: Require access to the EdgeX API
- Mock Tests: Can run in any environment with Python 3.7+
The following improvements could be made to the test suite:
-
Separate Public and Private Endpoint Tests: Fully separate tests for public endpoints from those requiring authentication
-
Increased Unit Test Coverage: Add tests for edge cases and error conditions
-
Mocking External Dependencies: Use mocks for API responses to test more scenarios
-
Property-Based Testing: Implement property-based testing for cryptographic operations
-
Performance Testing: Add tests for performance and resource usage
-
Dedicated Transfer and Asset Tests: Add dedicated integration tests for these clients
-
WebSocket Message Testing: Add more tests for different WebSocket message types
-
Concurrency Testing: Add tests for concurrent API calls
-
Long-Running Operation Testing: Add tests for pagination and long-running operations