mirror of
https://github.com/floor-licker/polyfill-rs.git
synced 2026-08-07 09:47:45 +00:00
refactor:cleanup
This commit is contained in:
+19
-19
@@ -62,7 +62,7 @@ cargo test --test integration_tests -- --nocapture
|
||||
|
||||
## Test Categories
|
||||
|
||||
### ✅ Always Run (No Auth Required)
|
||||
### Always Run (No Auth Required)
|
||||
- **API Connectivity**: Basic connection to Polymarket API
|
||||
- **Market Data Endpoints**: Order book, prices, spreads, etc.
|
||||
- **Error Handling**: Invalid requests and error responses
|
||||
@@ -70,24 +70,24 @@ cargo test --test integration_tests -- --nocapture
|
||||
- **API Compatibility**: Verify our API matches polymarket-rs-client
|
||||
- **Performance**: Response time measurements
|
||||
|
||||
### 🔐 Authentication Required
|
||||
### Authentication Required
|
||||
- **Authentication**: API key creation and validation
|
||||
- **Advanced Client Features**: Full client configuration
|
||||
- **WebSocket Connectivity**: Real-time data streaming
|
||||
|
||||
### 💰 API Credentials Required
|
||||
### API Credentials Required
|
||||
- **Order Management**: Order creation and management (read-only tests)
|
||||
|
||||
## Test Results
|
||||
|
||||
### Success Indicators
|
||||
```
|
||||
✅ API connectivity test passed
|
||||
✅ Market data endpoints test passed
|
||||
✅ Error handling test passed
|
||||
✅ Rate limiting test passed
|
||||
✅ API compatibility test passed
|
||||
✅ Performance test passed
|
||||
API connectivity test passed
|
||||
Market data endpoints test passed
|
||||
Error handling test passed
|
||||
Rate limiting test passed
|
||||
API compatibility test passed
|
||||
Performance test passed
|
||||
Server time: 234ms
|
||||
Markets request: 1.2s
|
||||
Markets returned: 50
|
||||
@@ -95,14 +95,14 @@ cargo test --test integration_tests -- --nocapture
|
||||
|
||||
### Skip Indicators
|
||||
```
|
||||
⚠️ Skipping authentication test - no private key provided
|
||||
⚠️ Skipping order management test - missing auth credentials
|
||||
Skipping authentication test - no private key provided
|
||||
Skipping order management test - missing auth credentials
|
||||
```
|
||||
|
||||
### Failure Indicators
|
||||
```
|
||||
❌ API connectivity test failed: Network error: connection refused
|
||||
❌ Market data endpoints test failed: API error (404): Token not found
|
||||
API connectivity test failed: Network error: connection refused
|
||||
Market data endpoints test failed: API error (404): Token not found
|
||||
```
|
||||
|
||||
## Performance Benchmarks
|
||||
@@ -188,12 +188,12 @@ cargo nextest run --test integration_tests
|
||||
|
||||
Our integration tests cover:
|
||||
|
||||
- ✅ **API Endpoints**: All major REST endpoints
|
||||
- ✅ **Authentication**: EIP-712 signing and API key management
|
||||
- ✅ **Error Handling**: Network errors, API errors, validation errors
|
||||
- ✅ **Performance**: Response time and throughput measurements
|
||||
- ✅ **WebSocket**: Real-time data streaming (when available)
|
||||
- ✅ **Compatibility**: API compatibility with polymarket-rs-client
|
||||
- **API Endpoints**: All major REST endpoints
|
||||
- **Authentication**: EIP-712 signing and API key management
|
||||
- **Error Handling**: Network errors, API errors, validation errors
|
||||
- **Performance**: Response time and throughput measurements
|
||||
- **WebSocket**: Real-time data streaming (when available)
|
||||
- **Compatibility**: API compatibility with polymarket-rs-client
|
||||
|
||||
## Adding New Tests
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ async fn main() -> Result<()> {
|
||||
.expect("PRIVATE_KEY environment variable required");
|
||||
let chain_id = 137; // Polygon
|
||||
|
||||
println!("🚀 Initializing Polyfill-rs Trading Client");
|
||||
println!("Initializing Polyfill-rs Trading Client");
|
||||
|
||||
// Step 1: Create client with L1 authentication (private key)
|
||||
let mut client = ClobClient::with_l1_headers(
|
||||
@@ -26,17 +26,17 @@ async fn main() -> Result<()> {
|
||||
chain_id,
|
||||
)?;
|
||||
|
||||
println!("✅ Client initialized with L1 authentication");
|
||||
println!("Client initialized with L1 authentication");
|
||||
|
||||
// Step 2: Create or derive API credentials for L2 operations
|
||||
println!("🔑 Setting up API credentials...");
|
||||
println!("Setting up API credentials...");
|
||||
let api_creds = client.create_or_derive_api_key(None).await?;
|
||||
client.set_api_creds(api_creds);
|
||||
|
||||
println!("✅ API credentials configured");
|
||||
println!("API credentials configured");
|
||||
|
||||
// Step 3: Get account information
|
||||
println!("\n💰 Checking account balances...");
|
||||
println!("\nChecking account balances...");
|
||||
let balances = client.balance_allowance().await?;
|
||||
for balance in &balances {
|
||||
println!(" Token {}: Balance = {}, Allowance = {}",
|
||||
@@ -44,7 +44,7 @@ async fn main() -> Result<()> {
|
||||
}
|
||||
|
||||
// Step 4: Get market data
|
||||
println!("\n📊 Fetching market data...");
|
||||
println!("\nFetching market data...");
|
||||
let token_id = "21742633143463906290569050155826241533067272736897614950488156847949938836455";
|
||||
|
||||
// Single token data
|
||||
@@ -67,7 +67,7 @@ async fn main() -> Result<()> {
|
||||
}
|
||||
|
||||
// Step 5: Create and place orders
|
||||
println!("\n📝 Creating orders...");
|
||||
println!("\nCreating orders...");
|
||||
|
||||
// Create a limit order
|
||||
let order_args = OrderArgs {
|
||||
@@ -83,7 +83,7 @@ async fn main() -> Result<()> {
|
||||
|
||||
println!(" Creating limit order: Buy 10 @ 0.52");
|
||||
let order_result = client.create_and_post_order(&order_args).await?;
|
||||
println!(" ✅ Order created: {:?}", order_result);
|
||||
println!(" Order created: {:?}", order_result);
|
||||
|
||||
// Create a market order
|
||||
let market_order_args = OrderArgs {
|
||||
@@ -99,10 +99,10 @@ async fn main() -> Result<()> {
|
||||
|
||||
println!(" Creating market order: Sell 5 @ market");
|
||||
let market_order_result = client.create_market_order(&market_order_args).await?;
|
||||
println!(" ✅ Market order created: {:?}", market_order_result);
|
||||
println!(" Market order created: {:?}", market_order_result);
|
||||
|
||||
// Step 6: Query order history
|
||||
println!("\n📋 Checking order history...");
|
||||
println!("\nChecking order history...");
|
||||
|
||||
// Get all open orders
|
||||
let open_orders = client.get_orders(None).await?;
|
||||
@@ -121,7 +121,7 @@ async fn main() -> Result<()> {
|
||||
println!(" Orders for token {}: {}", token_id, token_orders.len());
|
||||
|
||||
// Step 7: Query trade history
|
||||
println!("\n💹 Checking trade history...");
|
||||
println!("\nChecking trade history...");
|
||||
|
||||
let trades = client.get_trades(Some(TradeParams {
|
||||
id: None,
|
||||
@@ -139,18 +139,18 @@ async fn main() -> Result<()> {
|
||||
}
|
||||
|
||||
// Step 8: Order management
|
||||
println!("\n🛠️ Order management...");
|
||||
println!("\nOrder management...");
|
||||
|
||||
if !open_orders.is_empty() {
|
||||
let order_to_cancel = &open_orders[0];
|
||||
println!(" Cancelling order: {}", order_to_cancel.id);
|
||||
|
||||
let cancel_result = client.cancel(&order_to_cancel.id).await?;
|
||||
println!(" ✅ Cancel result: {:?}", cancel_result);
|
||||
println!(" Cancel result: {:?}", cancel_result);
|
||||
}
|
||||
|
||||
// Step 9: Set up notifications (optional)
|
||||
println!("\n🔔 Setting up notifications...");
|
||||
println!("\nSetting up notifications...");
|
||||
|
||||
let notification_params = NotificationParams {
|
||||
signature: "example_signature".to_string(),
|
||||
@@ -158,12 +158,12 @@ async fn main() -> Result<()> {
|
||||
};
|
||||
|
||||
match client.notifications(notification_params).await {
|
||||
Ok(result) => println!(" ✅ Notifications configured: {:?}", result),
|
||||
Err(e) => println!(" ⚠️ Notifications setup failed: {}", e),
|
||||
Ok(result) => println!(" Notifications configured: {:?}", result),
|
||||
Err(e) => println!(" Notifications setup failed: {}", e),
|
||||
}
|
||||
|
||||
println!("\n🎉 Complete trading example finished!");
|
||||
println!("\n📈 Performance Notes:");
|
||||
println!("\nComplete trading example finished!");
|
||||
println!("\nPerformance Notes:");
|
||||
println!(" • Order book operations use fixed-point math (25x faster)");
|
||||
println!(" • Batch operations reduce API calls by up to 90%");
|
||||
println!(" • EIP-712 signing ensures maximum security");
|
||||
@@ -176,21 +176,21 @@ async fn main() -> Result<()> {
|
||||
/// Helper function to demonstrate error handling
|
||||
async fn safe_trading_example() {
|
||||
match main().await {
|
||||
Ok(()) => println!("✅ Trading example completed successfully"),
|
||||
Ok(()) => println!("Trading example completed successfully"),
|
||||
Err(PolyfillError::Auth { message, .. }) => {
|
||||
eprintln!("🔐 Authentication error: {}", message);
|
||||
eprintln!("💡 Make sure PRIVATE_KEY environment variable is set");
|
||||
eprintln!("Authentication error: {}", message);
|
||||
eprintln!("Make sure PRIVATE_KEY environment variable is set");
|
||||
},
|
||||
Err(PolyfillError::Api { status_code, message, .. }) => {
|
||||
eprintln!("🌐 API error ({}): {}", status_code, message);
|
||||
eprintln!("💡 Check your network connection and API limits");
|
||||
eprintln!("API error ({}): {}", status_code, message);
|
||||
eprintln!("Check your network connection and API limits");
|
||||
},
|
||||
Err(PolyfillError::Network { source, .. }) => {
|
||||
eprintln!("📡 Network error: {}", source);
|
||||
eprintln!("💡 Retrying with exponential backoff...");
|
||||
eprintln!("Network error: {}", source);
|
||||
eprintln!("Retrying with exponential backoff...");
|
||||
},
|
||||
Err(e) => {
|
||||
eprintln!("❌ Unexpected error: {}", e);
|
||||
eprintln!("Unexpected error: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,18 +5,18 @@
|
||||
|
||||
set -e
|
||||
|
||||
echo "🚀 Running polyfill-rs integration tests..."
|
||||
echo "Running polyfill-rs integration tests..."
|
||||
echo "=========================================="
|
||||
|
||||
# Check if we have the required environment variables
|
||||
if [ -z "$POLYMARKET_PRIVATE_KEY" ]; then
|
||||
echo "⚠️ Warning: POLYMARKET_PRIVATE_KEY not set"
|
||||
echo "Warning: POLYMARKET_PRIVATE_KEY not set"
|
||||
echo " Some tests will be skipped (authentication, order management, WebSocket)"
|
||||
echo " Set POLYMARKET_PRIVATE_KEY to run all tests"
|
||||
fi
|
||||
|
||||
if [ -z "$POLYMARKET_API_KEY" ] || [ -z "$POLYMARKET_API_SECRET" ] || [ -z "$POLYMARKET_API_PASSPHRASE" ]; then
|
||||
echo "⚠️ Warning: API credentials not set"
|
||||
echo "Warning: API credentials not set"
|
||||
echo " Set POLYMARKET_API_KEY, POLYMARKET_API_SECRET, and POLYMARKET_API_PASSPHRASE"
|
||||
echo " to test order management functionality"
|
||||
fi
|
||||
@@ -38,34 +38,34 @@ cargo test --test integration_tests -- --nocapture
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo ""
|
||||
echo "🎉 All integration tests passed!"
|
||||
echo "All integration tests passed!"
|
||||
echo ""
|
||||
echo "Test Summary:"
|
||||
echo " ✅ API connectivity"
|
||||
echo " ✅ Market data endpoints"
|
||||
echo " ✅ Error handling"
|
||||
echo " ✅ Rate limiting"
|
||||
echo " ✅ API compatibility"
|
||||
echo " ✅ Performance characteristics"
|
||||
echo " API connectivity"
|
||||
echo " Market data endpoints"
|
||||
echo " Error handling"
|
||||
echo " Rate limiting"
|
||||
echo " API compatibility"
|
||||
echo " Performance characteristics"
|
||||
|
||||
if [ -n "$POLYMARKET_PRIVATE_KEY" ]; then
|
||||
echo " ✅ Authentication"
|
||||
echo " ✅ Advanced client features"
|
||||
echo " ✅ WebSocket connectivity"
|
||||
echo " Authentication"
|
||||
echo " Advanced client features"
|
||||
echo " WebSocket connectivity"
|
||||
|
||||
if [ -n "$POLYMARKET_API_KEY" ]; then
|
||||
echo " ✅ Order management"
|
||||
echo " Order management"
|
||||
else
|
||||
echo " ⚠️ Order management (skipped - no API credentials)"
|
||||
echo " Order management (skipped - no API credentials)"
|
||||
fi
|
||||
else
|
||||
echo " ⚠️ Authentication (skipped - no private key)"
|
||||
echo " ⚠️ Advanced client features (skipped - no private key)"
|
||||
echo " ⚠️ WebSocket connectivity (skipped - no private key)"
|
||||
echo " ⚠️ Order management (skipped - no private key)"
|
||||
echo " Authentication (skipped - no private key)"
|
||||
echo " Advanced client features (skipped - no private key)"
|
||||
echo " WebSocket connectivity (skipped - no private key)"
|
||||
echo " Order management (skipped - no private key)"
|
||||
fi
|
||||
else
|
||||
echo ""
|
||||
echo "❌ Some integration tests failed!"
|
||||
echo "Some integration tests failed!"
|
||||
exit 1
|
||||
fi
|
||||
+4
-4
@@ -146,21 +146,21 @@ pub struct TestReporter;
|
||||
impl TestReporter {
|
||||
/// Report test success
|
||||
pub fn success(test_name: &str) {
|
||||
println!("✅ {} passed", test_name);
|
||||
println!("{} passed", test_name);
|
||||
}
|
||||
|
||||
/// Report test failure
|
||||
pub fn failure(test_name: &str, error: &dyn std::error::Error) {
|
||||
println!("❌ {} failed: {}", test_name, error);
|
||||
println!("{} failed: {}", test_name, error);
|
||||
}
|
||||
|
||||
/// Report test skip
|
||||
pub fn skip(test_name: &str, reason: &str) {
|
||||
println!("⚠️ {} skipped: {}", test_name, reason);
|
||||
println!("{} skipped: {}", test_name, reason);
|
||||
}
|
||||
|
||||
/// Report test performance
|
||||
pub fn performance(test_name: &str, duration: Duration) {
|
||||
println!("⚡ {} completed in {:?}", test_name, duration);
|
||||
println!("{} completed in {:?}", test_name, duration);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user