Filter market clarifications by durable event directory IDs

This commit is contained in:
2026-12-03 11:28:10 +08:00
parent 3495e8de3c
commit 9cbcc03681
9 changed files with 149 additions and 18 deletions
+67
View File
@@ -3237,3 +3237,70 @@ fn published_clarification_clears_only_its_market_and_replays_after_restart() {
assert_eq!(settled["clarifications"], resolution["clarifications"]);
assert!(e.execute(json!({"op":"publish_clarification","id":"late","market":"e","content":"late note","clear_book":false})).is_err());
}
#[test]
fn event_clarifications_span_sibling_markets_across_restart() {
let dir = tempdir().unwrap();
let path = dir.path().join("event-notes.sqlite");
let mut db = Exchange::open(&path).unwrap();
let mut event_ids = Vec::new();
for example in [
include_str!("../../../docs/examples/football.jsonl"),
include_str!("../../../docs/examples/topic.jsonl"),
] {
let mut commands = example
.lines()
.map(|line| serde_json::from_str::<Value>(line).unwrap());
let event = db.execute(commands.next().unwrap()).unwrap();
let event_id = event["event_id"].as_i64().unwrap();
assert!(event_id > 0);
event_ids.push(event_id);
for listing in commands.take(2) {
db.execute(listing).unwrap();
}
}
assert_ne!(event_ids[0], event_ids[1]);
db.execute(json!({"op":"list","id":"solo-list","market":"solo","rules":"Example."}))
.unwrap();
for market in ["full-2-1", "nvda-300", "solo", "half-1-0"] {
db.execute(json!({"op":"publish_clarification","id":format!("note-{market}"),"market":market,"content":market,"clear_book":false})).unwrap();
}
drop(db);
let mut db = Exchange::open(&path).unwrap();
let catalog = db
.execute(json!({"op":"catalog","slug":"nvda-closing-price-2027"}))
.unwrap();
assert_eq!(catalog["event"]["event_id"], event_ids[1]);
let events = db
.execute(json!({"op":"events","category":"sports","limit":10}))
.unwrap();
assert_eq!(events["events"][0]["event_id"], event_ids[0]);
let rows = db
.filtered_market_clarifications(&[], &event_ids, 10, 0, true)
.unwrap();
assert_eq!(
rows.iter()
.map(|r| r["content"].as_str().unwrap())
.collect::<Vec<_>>(),
["full-2-1", "nvda-300", "half-1-0"]
);
let sports = [event_ids[0], event_ids[0]];
assert_eq!(
db.filtered_market_clarifications(&[], &sports, 1, 1, true)
.unwrap(),
vec![rows[2].clone()]
);
let market = rows[2]["marketId"].as_i64().unwrap();
assert_eq!(
db.filtered_market_clarifications(&[market], &sports, 10, 0, false)
.unwrap(),
vec![rows[2].clone()]
);
assert!(db
.filtered_market_clarifications(&[market], &event_ids[1..], 10, 0, true)
.unwrap()
.is_empty());
let all = db.market_clarifications(&[], 10, 0, true).unwrap();
assert_eq!(all.len(), 4);
assert_eq!(all[2]["content"], "solo");
}