Rank market holders by net outcome exposure with per-token pagination
This commit is contained in:
@@ -1711,3 +1711,65 @@ fn valuation_counts_reserved_shares_and_distinguishes_unpriced_from_zero() {
|
||||
assert_eq!(snapshots[2]["value_micros"], 8000000);
|
||||
assert_eq!(snapshots[3]["value_micros"], 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn holders_net_reserved_and_hedged_balances_and_page_each_token() {
|
||||
let mut e = Exchange::open(":memory:").unwrap();
|
||||
let mut first = Value::Null;
|
||||
let mut gross = Value::Null;
|
||||
for line in include_str!("../../../docs/examples/holders.jsonl").lines() {
|
||||
let cmd: Value = serde_json::from_str(line).unwrap();
|
||||
let response = e.execute(cmd.clone()).unwrap();
|
||||
if cmd["op"] == "holders" {
|
||||
if cmd["basis"] == "gross" {
|
||||
gross = response;
|
||||
} else {
|
||||
first = response;
|
||||
}
|
||||
}
|
||||
}
|
||||
assert_eq!(first["data"].as_array().unwrap().len(), 2);
|
||||
assert_eq!(
|
||||
first["data"][0]["holders"][0],
|
||||
json!({"account":"alice","amount":3,"rank":1})
|
||||
);
|
||||
assert_eq!(
|
||||
first["data"][1]["holders"][0],
|
||||
json!({"account":"bob","amount":3,"rank":1})
|
||||
);
|
||||
let next = e
|
||||
.execute(json!({"op":"holders","cursor":first["next_cursor"]}))
|
||||
.unwrap();
|
||||
assert_eq!(next["data"].as_array().unwrap().len(), 1);
|
||||
assert_eq!(
|
||||
next["data"][0]["holders"][0],
|
||||
json!({"account":"carol","amount":0,"rank":2})
|
||||
);
|
||||
assert!(next["next_cursor"].is_null());
|
||||
assert!(e
|
||||
.execute(json!({"op":"holders","cursor":first["next_cursor"],"market":"different"}))
|
||||
.is_err());
|
||||
assert_eq!(gross["data"][0]["holders"][0]["amount"], 10);
|
||||
assert_eq!(gross["data"][1]["holders"][0]["amount"], 7);
|
||||
assert_eq!(
|
||||
gross["data"][1]["holders"][0]["current_value_micros"],
|
||||
2800000
|
||||
);
|
||||
assert_eq!(gross["data"][1]["holders"][1]["account"], "bob");
|
||||
assert_eq!(
|
||||
e.execute(json!({"op":"holders","markets":["missing","cup","cup"],"min_balance":3.5}))
|
||||
.unwrap()["data"],
|
||||
json!([])
|
||||
);
|
||||
e.execute(json!({"op":"close","id":"end","market":"cup"}))
|
||||
.unwrap();
|
||||
e.execute(json!({"op":"finalize","id":"result","market":"cup","winner":"YES"}))
|
||||
.unwrap();
|
||||
e.execute(json!({"op":"redeem","id":"collect","account":"alice","market":"cup"}))
|
||||
.unwrap();
|
||||
let after = e
|
||||
.execute(json!({"op":"holders","market":"cup","min_balance":1}))
|
||||
.unwrap();
|
||||
assert_eq!(after["data"].as_array().unwrap().len(), 1);
|
||||
assert_eq!(after["data"][0]["holders"][0]["account"], "bob");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user