Serve condition-scoped portfolio valuations from marked holdings
This commit is contained in:
@@ -1759,7 +1759,19 @@ fn valuation_counts_reserved_shares_and_distinguishes_unpriced_from_zero() {
|
||||
let cmd: Value = serde_json::from_str(line).unwrap();
|
||||
let response = e.execute(cmd.clone()).unwrap();
|
||||
match cmd["op"].as_str().unwrap() {
|
||||
"portfolio_value" => snapshots.push(response),
|
||||
"portfolio_value" => {
|
||||
let query =
|
||||
serde_json::from_value(json!({"user":"alice","condition":"e,e"})).unwrap();
|
||||
let wire = e.public_portfolio_value(query);
|
||||
match response["value_micros"].as_i64() {
|
||||
Some(micros) => assert_eq!(
|
||||
wire.unwrap()["data"]["value"].as_f64(),
|
||||
Some(micros as f64 / 1_000_000.0)
|
||||
),
|
||||
None => assert!(matches!(wire, Err(exchange::MarketDataError::Unavailable))),
|
||||
}
|
||||
snapshots.push(response);
|
||||
}
|
||||
"positions" => {
|
||||
let yes = response["positions"]
|
||||
.as_array()
|
||||
@@ -3556,3 +3568,50 @@ fn resolution_feed_tracks_a_reset_and_final_split_after_reopening() {
|
||||
);
|
||||
assert!(final_market[0].get("resolved_block").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn public_wallet_value_rounds_after_summing_and_scopes_each_condition() {
|
||||
let dir = tempdir().unwrap();
|
||||
let path = dir.path().join("wallet-value.sqlite");
|
||||
let wallet = format!("0x{}", "aB".repeat(20));
|
||||
let condition = format!("0x{}", "AB".repeat(32));
|
||||
let mut db = Exchange::open(&path).unwrap();
|
||||
db.execute(json!({"op":"fund","id":"fund","account":wallet,"cents":100}))
|
||||
.unwrap();
|
||||
for market in [&condition[..], "final"] {
|
||||
db.execute(json!({"op":"list","id":format!("list-{market}"),"market":market,"rules":"official result"})).unwrap();
|
||||
db.execute(json!({"op":"split","id":format!("split-{market}"),"account":wallet,"market":market,"qty_micros":30})).unwrap();
|
||||
db.execute(json!({"op":"close","id":format!("close-{market}"),"market":market}))
|
||||
.unwrap();
|
||||
db.execute(
|
||||
json!({"op":"finalize","id":format!("final-{market}"),"market":market,"winner":"VOID"}),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
drop(db);
|
||||
let db = Exchange::open(path).unwrap();
|
||||
let value = |query: Value| db.public_portfolio_value(serde_json::from_value(query).unwrap());
|
||||
let user = wallet.to_ascii_lowercase();
|
||||
assert_eq!(
|
||||
value(json!({"user":user})).unwrap(),
|
||||
json!({"data":{"proxy_wallet":user,"value":0.0001}})
|
||||
);
|
||||
assert_eq!(
|
||||
value(json!({"user":wallet,"conditionId":condition.to_ascii_lowercase()})).unwrap()["data"]
|
||||
["value"],
|
||||
0
|
||||
);
|
||||
assert_eq!(
|
||||
value(json!({"user":user,"condition":format!("final,{condition},final")})).unwrap()["data"]
|
||||
["value"],
|
||||
json!(0.0001)
|
||||
);
|
||||
let too_many = (0..21)
|
||||
.map(|n| format!("0x{n:064x}"))
|
||||
.collect::<Vec<_>>()
|
||||
.join(",");
|
||||
assert!(matches!(
|
||||
value(json!({"user":user,"condition":too_many})),
|
||||
Err(exchange::MarketDataError::Invalid(_))
|
||||
));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user