summaryrefslogtreecommitdiffstats
path: root/tests/crash.rs
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-11-08 03:29:35 +0100
committersalmonik <salmonik@tuta.io>2026-11-08 03:29:35 +0100
commit058432130628d00764663ecf819a9adc6793768d (patch)
treed3f49f111fbfaa48647cca2600adcf9017af2d30 /tests/crash.rs
parentweb: serve latest.php through PHP and refuse stray PHP files (diff)
downloadzagan-bet-058432130628d00764663ecf819a9adc6793768d.tar.gz
zagan-bet-058432130628d00764663ecf819a9adc6793768d.zip
v5.0.0: protocol v5 and the browser frontend
Protocol v5 replaces newline lines with bounded [u32 len][text] frames and REQ/RES/EVT envelopes. Requests carry correlation ids and the server replays the last 256 replies per connection, so a gateway retry cannot double-debit and a late reply cannot clobber a newer request. HELLO/PONG carry server time; crash rounds announce started_at and push coalesced 10 Hz ticks. Crash now commits sha256(seed) before a round and reveals the seed when it ends, so clients recompute the crash point. Adds the webd/ gateway: one blocking thread, one ClientCore and one pinned upstream TLS connection per session, an HttpOnly session cookie, takeover, and a 60-second grace window. The browser sends Command JSON and renders View JSON; it never speaks the game protocol or stores credentials. Adds the vanilla TypeScript browser app at /play/ (login, lobby, all four games, history, notices, crash verification), the nginx /play and /ws routes, and the headless DOM smoke test. webd and the app stay out of the TUI/GUI/server build graph. The client/server version moves to 5.0.0 in lockstep; v4 peers are refused at HELLO.
Diffstat (limited to 'tests/crash.rs')
-rw-r--r--tests/crash.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/crash.rs b/tests/crash.rs
index 797874b..513f9c8 100644
--- a/tests/crash.rs
+++ b/tests/crash.rs
@@ -102,3 +102,42 @@ fn crash_points_are_clamped_to_the_liability_cap() {
102 assert_eq!(crash_point_from_uniform(0.999_999), MAX_MULTIPLIER); 102 assert_eq!(crash_point_from_uniform(0.999_999), MAX_MULTIPLIER);
103 assert_eq!(crash_point_from_uniform(1.0), MAX_MULTIPLIER); 103 assert_eq!(crash_point_from_uniform(1.0), MAX_MULTIPLIER);
104} 104}
105
106#[test]
107fn a_seed_commits_to_its_crash_point_and_can_be_verified() {
108 use zagan_bet::crash::{
109 SEED_LEN, commit_seed, crash_point_from_seed, seed_from_hex, seed_to_uniform, verify_seed,
110 };
111
112 let mut seed = [0u8; SEED_LEN];
113 let value = (0.67_f64 * 18_446_744_073_709_551_616.0) as u64;
114 seed[..8].copy_from_slice(&value.to_be_bytes());
115 let commit = commit_seed(&seed);
116 let hex = format!(
117 "{}",
118 seed.iter()
119 .map(|byte| format!("{byte:02x}"))
120 .collect::<String>()
121 );
122
123 assert_eq!(seed_from_hex(&hex).as_deref(), Some(seed.as_slice()));
124 assert!(verify_seed(&hex, &commit));
125 assert!(!verify_seed(&hex, &"00".repeat(32)), "a wrong commit fails");
126 assert!(!verify_seed("nope", &commit), "bad hex fails");
127
128 // The point the client recomputes is the point the server committed to.
129 close(crash_point_from_seed(&seed), 3.0, 1e-9);
130 close(crash_point_from_seed(&seed), 3.0, 1e-9);
131
132 // The first eight bytes are the uniform; the rest are still hashed.
133 close(seed_to_uniform(&seed), 0.67, 1e-9);
134 let mut altered = seed;
135 altered[SEED_LEN - 1] = 1;
136 assert!(!verify_seed(
137 &altered
138 .iter()
139 .map(|byte| format!("{byte:02x}"))
140 .collect::<String>(),
141 &commit
142 ));
143}