# Ostium Rust SDK Tests
This directory contains comprehensive tests for the Ostium Rust SDK.
## Test Files
### `error_mapping_test.rs`
Unit tests for the error mapping functionality that converts Ethereum contract errors into human-readable messages.
**Coverage:**
- Contract error selector mapping (24 different error types)
- Error pattern recognition (gas estimation, execution reverted, etc.)
- Suggestion generation for common error scenarios
- Error selector extraction from various message formats
- Error data structure validation
- Performance testing (1000 mappings < 100ms)
**Key Features Tested:**
- Maps contract error selectors (e.g., `0x5863f789`) to readable names (e.g., "WrongParams")
- Provides actionable suggestions for fixing errors
- Handles both direct contract errors and gas estimation errors
- Extracts error selectors from complex error messages
- Case-insensitive selector extraction
- Performance optimized for production use
### `integration_test.rs`
Integration tests that verify the SDK works correctly against the testnet.
**Coverage:**
- Client creation and configuration
- Market data retrieval (pairs, prices, trading hours)
- Account operations (balance, positions, orders)
- Error handling for invalid inputs
- Retry mechanisms and rate limiting
- Performance testing with concurrent requests
### `minimum_size_validation_test.rs`
Demonstrates and tests the minimum position size validation constraints.
**Coverage:**
- Minimum collateral requirements (7-10 USDC baseline per Ostium documentation)
- Position size validation for different asset classes (crypto, forex, commodities, indices)
- Trading constraint validation without executing actual trades
- Minimum position size calculation based on current market prices
- Asset-specific minimum requirements and collateral calculations
**Key Features Tested:**
- Validates positions meet minimum 7 USDC collateral requirement
- Tests various assets: BTC/USD, ETH/USD, EUR/USD, SPX/USD, GOLD/USD
- Calculates minimum position sizes based on current market prices
- Provides detailed error messages when positions are too small
- Shows collateral requirements at different leverage levels
- References official Ostium documentation for minimum requirements
### `unsigned_transactions.rs`
Tests for unsigned transaction generation functionality.
**Coverage:**
- Building unsigned transactions for various operations
- Transaction parameter validation
- Gas estimation for unsigned transactions
- Serialization/deserialization of transaction data
## Running Tests
```bash
# Run all tests
cargo test
# Run specific test file
cargo test --test error_mapping_test
cargo test --test integration_test
cargo test --test minimum_size_validation_test
cargo test --test unsigned_transactions
# Run library unit tests only
cargo test --lib
# Run with output
cargo test -- --nocapture
```
## Test Environment
- **Integration tests** require network access to testnet
- **Unit tests** run offline and are fast
- **Error mapping tests** are pure unit tests with no external dependencies
- Some integration tests require `OSTIUM_PRIVATE_KEY` environment variable
## Test Data
The error mapping tests use real contract error selectors from the Ostium trading contracts:
- `0x5863f789` - WrongParams
- `0xcb87b762` - PairNotListed
- `0x35fe85c5` - WrongLeverage
- `0xeca695e1` - BelowMinLevPos
- And 20+ more contract-specific errors
These selectors are derived from the Keccak-256 hash of the error function signatures in the Solidity contracts.