Serve priced open interest for active unarchived market listings
This commit is contained in:
@@ -1923,6 +1923,24 @@ fn priced_interest_follows_outstanding_tokens_through_transfer_merge_and_redempt
|
||||
let response = exchange.execute(cmd.clone()).unwrap();
|
||||
if cmd["op"] == "open_interest" {
|
||||
assert_eq!(response["data"].as_array().unwrap().len(), 1);
|
||||
let query = if cmd.get("market").is_some() {
|
||||
json!({"conditionId":"cup,cup"})
|
||||
} else {
|
||||
json!({})
|
||||
};
|
||||
let public = exchange.public_open_interest(serde_json::from_value(query).unwrap());
|
||||
let row = &response["data"][0];
|
||||
if row["value"].is_null() {
|
||||
assert!(matches!(
|
||||
public,
|
||||
Err(exchange::MarketDataError::Unavailable)
|
||||
));
|
||||
} else {
|
||||
let public = public.unwrap();
|
||||
assert_eq!(public["data"][0]["condition_id"], row["condition_id"]);
|
||||
assert_eq!(public["data"][0]["value"].as_f64(), row["value"].as_f64());
|
||||
assert_eq!(public["data"][0].as_object().unwrap().len(), 2);
|
||||
}
|
||||
snapshots.push(response["data"][0].clone());
|
||||
}
|
||||
}
|
||||
@@ -3615,3 +3633,62 @@ fn public_wallet_value_rounds_after_summing_and_scopes_each_condition() {
|
||||
Err(exchange::MarketDataError::Invalid(_))
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn public_interest_filters_archived_and_inactive_without_affecting_redemption() {
|
||||
let dir = tempdir().unwrap();
|
||||
let path = dir.path().join("visible-oi.sqlite");
|
||||
let market = format!("0x{}", "Ab".repeat(32));
|
||||
let mut db = Exchange::open(&path).unwrap();
|
||||
db.execute(json!({"op":"fund","id":"fund","account":"alice","cents":100}))
|
||||
.unwrap();
|
||||
db.execute(json!({"op":"list","id":"list","market":market,"rules":"official"}))
|
||||
.unwrap();
|
||||
db.execute(json!({"op":"split","id":"pair","market":market,"account":"alice","qty_micros":1}))
|
||||
.unwrap();
|
||||
db.execute(json!({"op":"close","id":"close","market":market}))
|
||||
.unwrap();
|
||||
db.execute(json!({"op":"finalize","id":"fin","market":market,"winner":"VOID"}))
|
||||
.unwrap();
|
||||
let read = |db: &Exchange, params: Value| {
|
||||
db.public_open_interest(serde_json::from_value(params).unwrap())
|
||||
.unwrap()["data"]
|
||||
.clone()
|
||||
};
|
||||
let query = json!({"condition_id":market.to_ascii_lowercase()});
|
||||
assert_eq!(read(&db, query.clone())[0]["value"], json!(0.000001));
|
||||
let visibility = |id: &str, active: bool, archived: bool| json!({"op":"set_market_visibility","id":id,"market":market,"active":active,"archived":archived});
|
||||
let archive = visibility("archive", true, true);
|
||||
let receipt = db.execute(archive.clone()).unwrap();
|
||||
drop(db);
|
||||
let mut db = Exchange::open(path).unwrap();
|
||||
assert_eq!(db.execute(archive).unwrap(), receipt);
|
||||
assert_eq!(read(&db, query.clone()), json!([]));
|
||||
assert_eq!(
|
||||
read(&db, json!({})),
|
||||
json!([{"condition_id":"GLOBAL","value":0}])
|
||||
);
|
||||
let detail = db
|
||||
.gamma_market(exchange::DirectoryKey::Slug(&market))
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert_eq!(detail["archived"], true);
|
||||
db.execute(visibility("inactive", false, false)).unwrap();
|
||||
assert_eq!(read(&db, query.clone()), json!([]));
|
||||
let filters = vec![
|
||||
("closed".into(), "true".into()),
|
||||
("active".into(), "false".into()),
|
||||
];
|
||||
assert_eq!(
|
||||
db.gamma_list(exchange::DirectoryResource::Markets, &filters)
|
||||
.unwrap()[0]["conditionId"],
|
||||
market
|
||||
);
|
||||
db.execute(visibility("restore", true, false)).unwrap();
|
||||
assert_eq!(read(&db, query.clone())[0]["value"], json!(0.000001));
|
||||
db.execute(visibility("archive-again", true, true)).unwrap();
|
||||
db.execute(json!({"op":"redeem","id":"claim","market":market,"account":"alice"}))
|
||||
.unwrap();
|
||||
db.execute(visibility("relist", true, false)).unwrap();
|
||||
assert_eq!(read(&db, query)[0]["value"], 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user