More tests
This commit is contained in:
parent
5f844e5158
commit
4a16fa0ffe
1 changed files with 60 additions and 0 deletions
|
|
@ -133,3 +133,63 @@ async fn test_fetch_last_close_before_returns_most_recent() {
|
|||
assert!(result.is_some());
|
||||
assert!((result.unwrap() - 50.0).abs() < f64::EPSILON);
|
||||
}
|
||||
|
||||
/// Trade exactly AT timestamp_end must be excluded — the query uses strict `<`.
|
||||
#[tokio::test]
|
||||
async fn test_fetch_last_close_before_boundary_excluded() {
|
||||
let db = mock_db_pool(setup_db).await;
|
||||
let token = TokenID::from_inner([0xAD; 32]);
|
||||
let token_blob = token.to_blob();
|
||||
|
||||
let mut conn = db.cauldron_w.acquire().await.unwrap();
|
||||
insert_trade_at(&mut conn, &token, 0x04, 1000, 100_000, 2_000).await;
|
||||
|
||||
// Query exactly at ts=1000: that trade must NOT be included (strict <).
|
||||
let result = super::fetch_last_close_before(&db.cauldron_r, &token_blob, 1000)
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(result.is_none(), "trade at cutoff must be excluded");
|
||||
}
|
||||
|
||||
/// Trades with net-zero token delta (signed_tokens == 0) are invisible to pricing.
|
||||
/// Only the last priceable trade before the cutoff should be returned.
|
||||
#[tokio::test]
|
||||
async fn test_fetch_last_close_before_skips_net_zero_token_trades() {
|
||||
let db = mock_db_pool(setup_db).await;
|
||||
let token = TokenID::from_inner([0xAE; 32]);
|
||||
let token_blob = token.to_blob();
|
||||
|
||||
let mut conn = db.cauldron_w.acquire().await.unwrap();
|
||||
// ts=500: priceable trade, price = 50_000/1_000 = 50
|
||||
insert_trade_at(&mut conn, &token, 0x05, 500, 50_000, 1_000).await;
|
||||
// ts=800: net-zero token trade — should be invisible to pricing
|
||||
insert_trade_at(&mut conn, &token, 0x06, 800, 10_000, 0).await;
|
||||
|
||||
let result = super::fetch_last_close_before(&db.cauldron_r, &token_blob, 1000)
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(result.is_some());
|
||||
// Must return the priceable trade's close (50), not be confused by the net-zero one.
|
||||
assert!(
|
||||
(result.unwrap() - 50.0).abs() < f64::EPSILON,
|
||||
"net-zero trade must not affect close price"
|
||||
);
|
||||
}
|
||||
|
||||
/// Trades for a different token must not bleed into results for the queried token.
|
||||
#[tokio::test]
|
||||
async fn test_fetch_last_close_before_token_isolation() {
|
||||
let db = mock_db_pool(setup_db).await;
|
||||
let token_a = TokenID::from_inner([0xAF; 32]);
|
||||
let token_b = TokenID::from_inner([0xBF; 32]);
|
||||
let token_a_blob = token_a.to_blob();
|
||||
|
||||
let mut conn = db.cauldron_w.acquire().await.unwrap();
|
||||
// Only insert a trade for token_b; token_a has nothing.
|
||||
insert_trade_at(&mut conn, &token_b, 0x07, 500, 100_000, 2_000).await;
|
||||
|
||||
let result = super::fetch_last_close_before(&db.cauldron_r, &token_a_blob, 1000)
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(result.is_none(), "other token's trade must not appear");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue