Group independent binary markets under discoverable topic events
This commit is contained in:
@@ -1202,3 +1202,71 @@ fn market_estimate_uses_latest_committed_depth_without_reserving_it() {
|
||||
assert_eq!(buy["gross_cents"], 70);
|
||||
assert_eq!(buy["unspent_cents"], 11);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn topics_share_discovery_and_keep_distinct_tradable_assets_on_append() {
|
||||
let dir = tempdir().unwrap();
|
||||
let path = dir.path().join("topics.sqlite");
|
||||
let mut e = Exchange::open(&path).unwrap();
|
||||
let sport: Value = serde_json::from_str(
|
||||
include_str!("../../../docs/examples/football.jsonl")
|
||||
.lines()
|
||||
.next()
|
||||
.unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
e.execute(sport.clone()).unwrap();
|
||||
let commands: Vec<Value> = include_str!("../../../docs/examples/topic.jsonl")
|
||||
.lines()
|
||||
.map(|line| serde_json::from_str(line).unwrap())
|
||||
.collect();
|
||||
for cmd in &commands[..2] {
|
||||
e.execute(cmd.clone()).unwrap();
|
||||
}
|
||||
let original = e.execute(commands[4].clone()).unwrap()["markets"][0].clone();
|
||||
e.execute(commands[2].clone()).unwrap();
|
||||
drop(e);
|
||||
let mut e = Exchange::open(&path).unwrap();
|
||||
let detail = e.execute(commands[4].clone()).unwrap();
|
||||
assert_eq!(
|
||||
detail,
|
||||
e.execute(json!({"op":"catalog","event":"nvda-2027"}))
|
||||
.unwrap()
|
||||
);
|
||||
assert_eq!(detail["markets"][1], original);
|
||||
assert_eq!(detail["markets"][0]["group_order"], 200);
|
||||
let assets = e
|
||||
.execute(json!({"op":"assets","market":"nvda-200"}))
|
||||
.unwrap();
|
||||
assert_eq!(assets["outcomes"], detail["markets"][0]["outcomes"]);
|
||||
assert_ne!(
|
||||
assets["outcomes"][0]["asset_id"],
|
||||
original["outcomes"][0]["asset_id"]
|
||||
);
|
||||
assert_eq!(
|
||||
e.execute(commands[3].clone()).unwrap()["events"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.len(),
|
||||
1
|
||||
);
|
||||
let first = e.execute(json!({"op":"events","limit":1})).unwrap();
|
||||
assert_eq!(first["next"], "cup-a-b");
|
||||
let last = e
|
||||
.execute(json!({"op":"events","after":first["next"],"limit":1}))
|
||||
.unwrap();
|
||||
assert_eq!(last["events"][0]["id"], "nvda-2027");
|
||||
assert!(last["next"].is_null());
|
||||
let mut collision = sport;
|
||||
collision["id"] = json!("create-conflict");
|
||||
collision["event"] = detail["event"]["slug"].clone();
|
||||
assert!(e.execute(collision).is_err());
|
||||
let mut invalid = commands[2].clone();
|
||||
invalid["id"] = json!("invalid");
|
||||
invalid["market"] = json!("invalid");
|
||||
invalid["listing"]["event"] = json!("cup-a-b");
|
||||
assert!(e.execute(invalid).is_err());
|
||||
assert!(e
|
||||
.execute(json!({"op":"assets","market":"invalid"}))
|
||||
.is_err());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user