Expose public resolution lifecycle and preserve arbitration after a reset
This commit is contained in:
@@ -3486,3 +3486,73 @@ fn trade_feed_replays_both_wallet_legs_and_keeps_the_cursor_after_restart() {
|
||||
.public_trade_feed(serde_json::from_value(json!({"cursor":cursor})).unwrap())
|
||||
.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resolution_feed_tracks_a_reset_and_final_split_after_reopening() {
|
||||
let dir = tempdir().unwrap();
|
||||
let path = dir.path().join("resolutions.db");
|
||||
let mut e = Exchange::open(&path).unwrap();
|
||||
let question = format!("0x{}", "ab".repeat(32));
|
||||
let listing = |market: &str, id: &str| {
|
||||
json!({
|
||||
"op":"list","id":market,"market":market,"rules":"Official result",
|
||||
"resolution":{"kind":"optimistic","eligible_at":0,"question_id":id}
|
||||
})
|
||||
};
|
||||
let lookup = |db: &Exchange, selector: Value| {
|
||||
db.public_resolutions(serde_json::from_value(selector).unwrap())
|
||||
.unwrap()["data"]
|
||||
.clone()
|
||||
};
|
||||
let view = |db: &Exchange| lookup(db, json!({"questionId":question}))[0].clone();
|
||||
e.execute(listing("m", &question)).unwrap();
|
||||
assert!(e.execute(listing("duplicate", &question)).is_err());
|
||||
assert!(e.execute(listing("bad", "0xabc")).is_err());
|
||||
assert_eq!(lookup(&e, json!({"condition":"duplicate,bad"})), json!([]));
|
||||
assert_eq!(view(&e)["status"], "posed");
|
||||
assert_eq!(view(&e)["price"], "69");
|
||||
e.execute(json!({"op":"close","id":"close","market":"m"}))
|
||||
.unwrap();
|
||||
for (i, result, expected) in [
|
||||
(1, "YES", "proposed"),
|
||||
(2, "NO", "reproposed"),
|
||||
(3, "VOID", "reproposed"),
|
||||
] {
|
||||
let p = e.execute(json!({"op":"propose","id":format!("p{i}"),"market":"m","winner":result,"proposer":"alice","evidence":"score"})).unwrap()["proposal"].clone();
|
||||
let live = view(&e);
|
||||
assert_eq!(live["status"], expected);
|
||||
assert_eq!(live["settlement_time_basis"], "proposal_expiration");
|
||||
e.execute(json!({"op":"dispute","id":format!("d{i}"),"market":"m","proposal":p,"challenger":"bob","evidence":"correction"})).unwrap();
|
||||
let challenged = view(&e);
|
||||
assert_eq!(
|
||||
challenged["status"],
|
||||
if i == 1 { "challenged" } else { "disputed" }
|
||||
);
|
||||
assert!(challenged.get("expected_settlement_time").is_none());
|
||||
if i >= 2 {
|
||||
e.execute(json!({"op":"adjudicate","id":format!("v{i}"),"market":"m","proposal":p,"verdict":if i==2 {"TOO_EARLY"} else {"VOID"},"evidence":"decision"})).unwrap();
|
||||
}
|
||||
if i == 2 {
|
||||
let reset = view(&e);
|
||||
assert_eq!(reset["status"], "challenged");
|
||||
assert_eq!(reset["proposed_price"], "0");
|
||||
assert_eq!(reset["reproposed_price"], "69");
|
||||
}
|
||||
}
|
||||
drop(e);
|
||||
let db = Exchange::open(path).unwrap();
|
||||
let final_question = view(&db);
|
||||
assert!(final_question.get("condition_id").is_none());
|
||||
assert_eq!(final_question["price"], "500000000000000000");
|
||||
assert_eq!(final_question["was_arbitrated"], true);
|
||||
let final_market = lookup(&db, json!({"conditionId":"m,m"}));
|
||||
assert_eq!(final_market.as_array().unwrap().len(), 1);
|
||||
assert_eq!(final_market[0]["question_id"], question);
|
||||
assert_eq!(final_market[0]["status"], "resolved");
|
||||
assert_eq!(final_market[0]["payouts"], json!([500000, 500000]));
|
||||
assert_eq!(
|
||||
final_market[0]["last_update_timestamp"],
|
||||
final_market[0]["resolved_at"]
|
||||
);
|
||||
assert!(final_market[0].get("resolved_block").is_none());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user