Gate optimistic market payouts on proposal and dispute rounds
This commit is contained in:
@@ -850,3 +850,89 @@ fn account_fills_page_both_order_legs_and_reconcile_after_restart() {
|
||||
json!([])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn contested_resolution_blocks_both_payout_paths_until_a_verdict() {
|
||||
let dir = tempdir().unwrap();
|
||||
let path = dir.path().join("oracle.db");
|
||||
let mut e = Exchange::open(&path).unwrap();
|
||||
e.execute(json!({"op":"fund","id":"fund","account":"alice","cents":1000}))
|
||||
.unwrap();
|
||||
e.execute(
|
||||
json!({"op":"list","id":"list","market":"m","rules":"official outcome",
|
||||
"resolution":{"kind":"optimistic","eligible_at":0}}),
|
||||
)
|
||||
.unwrap();
|
||||
e.execute(json!({"op":"split","id":"split","account":"alice","market":"m","qty":2}))
|
||||
.unwrap();
|
||||
e.execute(json!({"op":"close","id":"close","market":"m"}))
|
||||
.unwrap();
|
||||
let status = json!({"op":"resolution","market":"m"});
|
||||
let make = |id: &str| json!({"op":"propose","id":id,"market":"m","winner":"YES","proposer":"alice","evidence":"score sheet"});
|
||||
let challenge = |id: &str, p: &Value| json!({"op":"dispute","id":id,"market":"m","proposal":p,"challenger":"bob","evidence":"corrected score"});
|
||||
let first = e.execute(make("p1")).unwrap()["proposal"].clone();
|
||||
for op in ["finalize", "resolve"] {
|
||||
assert!(e
|
||||
.execute(json!({"op":op,"id":op,"market":"m","winner":"YES"}))
|
||||
.is_err());
|
||||
}
|
||||
let c = challenge("d1", &first);
|
||||
let receipt = e.execute(c.clone()).unwrap();
|
||||
assert_eq!(receipt["status"], "awaiting_second_proposal");
|
||||
let second = e.execute(make("p2")).unwrap()["proposal"].clone();
|
||||
assert!(e.execute(challenge("obsolete", &first)).is_err());
|
||||
assert_eq!(e.execute(c).unwrap(), receipt);
|
||||
e.execute(challenge("d2", &second)).unwrap();
|
||||
drop(e);
|
||||
let mut e = Exchange::open(path).unwrap();
|
||||
assert_eq!(
|
||||
e.execute(status.clone()).unwrap()["status"],
|
||||
"awaiting_arbitration"
|
||||
);
|
||||
let redeem = json!({"op":"redeem","id":"claim","market":"m","account":"alice"});
|
||||
assert!(e.execute(redeem.clone()).is_err());
|
||||
let decision = json!({"op":"adjudicate","id":"verdict","market":"m","proposal":second,"verdict":"NO","evidence":"simulated vote record"});
|
||||
let finalized = e.execute(decision.clone()).unwrap();
|
||||
assert_eq!(e.execute(decision).unwrap(), finalized);
|
||||
let resolved = e.execute(status).unwrap();
|
||||
assert_eq!(resolved["winner"], "NO");
|
||||
assert_eq!(resolved["proposals"][1]["verdict"], "NO");
|
||||
assert_eq!(resolved["proposals"][0]["challenger"], "bob");
|
||||
assert_eq!(e.execute(redeem).unwrap()["paid"], 200);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unchallenged_second_proposal_only_clears_its_own_outcome() {
|
||||
let dir = tempdir().unwrap();
|
||||
let path = dir.path().join("unchallenged.db");
|
||||
let mut e = Exchange::open(&path).unwrap();
|
||||
e.execute(
|
||||
json!({"op":"list","id":"list","market":"m","rules":"official",
|
||||
"resolution":{"kind":"optimistic","eligible_at":0}}),
|
||||
)
|
||||
.unwrap();
|
||||
e.execute(json!({"op":"close","id":"close","market":"m"}))
|
||||
.unwrap();
|
||||
let proposal = |id: &str, winner: &str| {
|
||||
json!({"op":"propose","id":id,"market":"m","winner":winner,
|
||||
"proposer":"a","evidence":"observed result"})
|
||||
};
|
||||
let first = e.execute(proposal("first", "YES")).unwrap();
|
||||
e.execute(
|
||||
json!({"op":"dispute","id":"challenge","market":"m","proposal":first["proposal"],
|
||||
"challenger":"b","evidence":"corrected result"}),
|
||||
)
|
||||
.unwrap();
|
||||
let second = e.execute(proposal("second", "NO")).unwrap();
|
||||
let finalize =
|
||||
|winner: &str| json!({"op":"finalize","id":"finish","market":"m","winner":winner});
|
||||
assert!(e.execute(finalize("NO")).is_err());
|
||||
let db = rusqlite::Connection::open(&path).unwrap();
|
||||
db.execute(
|
||||
"UPDATE resolution_proposals SET proposed_at=unixepoch()-7200 WHERE id=?",
|
||||
[second["proposal"].as_i64().unwrap()],
|
||||
)
|
||||
.unwrap();
|
||||
assert!(e.execute(finalize("YES")).is_err());
|
||||
assert_eq!(e.execute(finalize("NO")).unwrap()["winner"], "NO");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user