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