Bind verified Polymarket token families to local outcomes

This commit is contained in:
2026-12-05 05:09:23 +08:00
parent 2888563723
commit f8fbd68d19
12 changed files with 488 additions and 28 deletions
+43
View File
@@ -4219,3 +4219,46 @@ fn public_token_directory_routes_results_and_expands_negative_risk_groups() {
assert_eq!(voided[0]["final_price"], 0.5);
assert_eq!(voided[1]["final_price"], 0.5);
}
#[test]
fn polymarket_asset_bindings_preserve_protocols_and_explicit_outcome_direction() {
let dir = tempdir().unwrap();
let path = dir.path().join("venue-ids.db");
let mut e = Exchange::open(&path).unwrap();
setup(&mut e);
let fixture: Value = serde_json::from_str(include_str!(
"../../../docs/examples/polymarket-asset-binding.json"
))
.unwrap();
let mut command = json!({"op":"bind_polymarket_assets","id":"bind","market":"e","zero_outcome":"NO",
"external_condition":fixture["external_condition"], "data":fixture["data"]});
let receipt = e.execute(command.clone()).unwrap();
assert_eq!(receipt["tokens"], 4);
assert_eq!(e.execute(command.clone()).unwrap(), receipt);
command["id"] = json!("flipped");
command["zero_outcome"] = json!("YES");
assert!(e.execute(command).is_err());
drop(e);
let e = Exchange::open(path).unwrap();
let lookup = |query| {
e.public_tokens(serde_json::from_value(query).unwrap())
.unwrap()
};
let condition = lookup(json!({"condition":fixture["external_condition"]}));
let rows = condition["data"].as_array().unwrap();
assert_eq!(rows.len(), 4);
assert_eq!(rows[0]["module"], "v1_ctf");
assert_eq!(rows[2]["module"], "neg_risk");
assert_eq!(rows[2]["local_asset_id"], "eb:NO:e");
assert_eq!(rows[3]["local_asset_id"], "eb:YES:e");
let structural = rows[2]["structural_condition_id"].as_str().unwrap();
assert_eq!(
lookup(json!({"condition":&structural[..64]}))["data"],
json!([rows[2], rows[3]])
);
let token = rows[3]["token_id"].as_str().unwrap();
assert_eq!(
lookup(json!({"token_id":format!("00{token},00123,eb:NO:e")}))["data"][0],
rows[3]
);
}