mirror of
https://github.com/floor-licker/polyfill-rs.git
synced 2026-08-24 18:08:10 +00:00
test: make real-api smoke tests robust
This commit is contained in:
@@ -22,9 +22,12 @@ if [[ -z "${POLYMARKET_PRIVATE_KEY:-}" ]]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
set -x
|
ARGS=(--ignored --test-threads=1)
|
||||||
|
if [[ "${NO_CAPTURE:-0}" == "1" ]]; then
|
||||||
|
ARGS+=(--nocapture)
|
||||||
|
fi
|
||||||
|
|
||||||
# Run serially to reduce the chance of hitting rate limits.
|
# Run serially to reduce the chance of hitting rate limits.
|
||||||
cargo test --all-features --test integration_tests -- --ignored --nocapture --test-threads=1
|
cargo test --all-features --test integration_tests -- "${ARGS[@]}"
|
||||||
cargo test --all-features --test simple_auth_test -- --ignored --nocapture --test-threads=1
|
cargo test --all-features --test simple_auth_test -- "${ARGS[@]}"
|
||||||
cargo test --all-features --test order_posting_test -- --ignored --nocapture --test-threads=1
|
cargo test --all-features --test order_posting_test -- "${ARGS[@]}"
|
||||||
|
|||||||
+28
-26
@@ -85,20 +85,23 @@ async fn test_real_api_authenticated_order_flow() {
|
|||||||
.expect("Failed to get midpoint");
|
.expect("Failed to get midpoint");
|
||||||
println!("PASS: Current midpoint: {}", midpoint.mid);
|
println!("PASS: Current midpoint: {}", midpoint.mid);
|
||||||
|
|
||||||
// Step 4: Create and post a small order well away from market price
|
// Step 4: Create and post a small order well away from market price (so it won't fill immediately).
|
||||||
// (so it won't fill immediately)
|
// IMPORTANT: choose side consistently with the price so we don't accidentally create a marketable order.
|
||||||
let order_price = if midpoint.mid > dec!(0.5) {
|
let (side, order_price) = if midpoint.mid > dec!(0.5) {
|
||||||
dec!(0.01) // Very low buy price, won't fill
|
(Side::BUY, dec!(0.01)) // Very low buy price, won't fill
|
||||||
} else {
|
} else {
|
||||||
dec!(0.99) // Very high sell price, won't fill
|
(Side::SELL, dec!(0.99)) // Very high sell price, won't fill
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("Step 4: Posting order at price {}...", order_price);
|
println!(
|
||||||
|
"Step 4: Posting {:?} order at price {}...",
|
||||||
|
side, order_price
|
||||||
|
);
|
||||||
let order_args = OrderArgs {
|
let order_args = OrderArgs {
|
||||||
token_id: token_id.clone(),
|
token_id: token_id.clone(),
|
||||||
price: order_price,
|
price: order_price,
|
||||||
size: dec!(1.0), // Minimum size
|
size: dec!(1.0), // Small size (auth is the thing we're testing here)
|
||||||
side: Side::BUY,
|
side,
|
||||||
};
|
};
|
||||||
|
|
||||||
let post_result = client.create_and_post_order(&order_args).await;
|
let post_result = client.create_and_post_order(&order_args).await;
|
||||||
@@ -126,24 +129,23 @@ async fn test_real_api_authenticated_order_flow() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let err_str = format!("{:?}", e);
|
// The critical failure: did we get a 401 (authentication failure)?
|
||||||
|
match &e {
|
||||||
// Check if it's a 401 (authentication failure)
|
polyfill_rs::PolyfillError::Api { status: 401, .. } => {
|
||||||
if err_str.contains("401") {
|
panic!(
|
||||||
panic!("FAIL: CRITICAL: 401 Unauthorized error - HMAC authentication is broken!");
|
"FAIL: CRITICAL: 401 Unauthorized error - HMAC authentication is broken!"
|
||||||
}
|
);
|
||||||
|
},
|
||||||
// Check if it's a 400 with specific validation errors (these are OK)
|
// Any 4xx other than 401 indicates auth succeeded and we reached server-side validation.
|
||||||
if err_str.contains("400")
|
polyfill_rs::PolyfillError::Api {
|
||||||
&& (err_str.contains("insufficient")
|
status: 400..=499, ..
|
||||||
|| err_str.contains("balance")
|
} => {
|
||||||
|| err_str.contains("allowance")
|
println!("PASS: Authentication successful (got expected validation error)");
|
||||||
|| err_str.contains("POLY_AMOUNT_TOO_SMALL"))
|
println!(" Error: {:?}", e);
|
||||||
{
|
},
|
||||||
println!("PASS: Authentication successful (got expected validation error)");
|
_ => {
|
||||||
println!(" Error: {}", err_str);
|
panic!("FAIL: Unexpected error: {:?}", e);
|
||||||
} else {
|
},
|
||||||
panic!("FAIL: Unexpected error: {:?}", e);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ async fn test_create_api_key_simple() {
|
|||||||
match result {
|
match result {
|
||||||
Ok(creds) => {
|
Ok(creds) => {
|
||||||
println!("Successfully created/derived API key");
|
println!("Successfully created/derived API key");
|
||||||
println!(" API Key: {}", creds.api_key);
|
println!(" API Key created (len={})", creds.api_key.len());
|
||||||
client.set_api_creds(creds);
|
client.set_api_creds(creds);
|
||||||
|
|
||||||
// Now try to get orders (requires auth)
|
// Now try to get orders (requires auth)
|
||||||
@@ -134,7 +134,11 @@ async fn test_get_notifications() {
|
|||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(notifs) => {
|
Ok(notifs) => {
|
||||||
println!("Authentication successful! Notifications: {:?}", notifs);
|
let count = notifs.as_array().map(|arr| arr.len());
|
||||||
|
match count {
|
||||||
|
Some(n) => println!("Authentication successful! Notifications: {n}"),
|
||||||
|
None => println!("Authentication successful! Notifications received"),
|
||||||
|
}
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let err_str = format!("{:?}", e);
|
let err_str = format!("{:?}", e);
|
||||||
|
|||||||
Reference in New Issue
Block a user