From a3bc7dac8f56157e810a76ae2fa962c4eec9be3b Mon Sep 17 00:00:00 2001 From: npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 Date: Mon, 13 Jul 2026 12:15:14 -0400 Subject: [PATCH] fix(desktop): move pairing relay tests after production helpers Co-authored-by: Will Pfleger Signed-off-by: Will Pfleger --- desktop/src-tauri/src/commands/pairing.rs | 76 +++++++++++------------ 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/desktop/src-tauri/src/commands/pairing.rs b/desktop/src-tauri/src/commands/pairing.rs index eef99cb5dd..6bddca047c 100644 --- a/desktop/src-tauri/src/commands/pairing.rs +++ b/desktop/src-tauri/src/commands/pairing.rs @@ -482,6 +482,44 @@ fn pairing_relay_from_nip11(json: &serde_json::Value) -> PairingRelay { } } +fn parse_auth_challenge(text: &str) -> Option { + let arr: serde_json::Value = serde_json::from_str(text).ok()?; + let arr = arr.as_array()?; + if arr.len() >= 2 && arr[0].as_str()? == "AUTH" { + return arr[1].as_str().map(|s| s.to_string()); + } + None +} + +async fn wait_for_eose(read: &mut S, sub_id: &str, dur: Duration) -> Result<(), String> +where + S: StreamExt> + Unpin, +{ + tokio::time::timeout(dur, async { + loop { + let msg = read + .next() + .await + .ok_or_else(|| "relay closed waiting for EOSE".to_string())? + .map_err(|e| format!("WS error waiting for EOSE: {e}"))?; + if let Message::Text(text) = msg { + if let Ok(arr) = serde_json::from_str::(text.as_str()) { + if let Some(arr) = arr.as_array() { + if arr.len() >= 2 + && arr[0].as_str() == Some("EOSE") + && arr[1].as_str() == Some(sub_id) + { + return Ok(()); + } + } + } + } + } + }) + .await + .map_err(|_| "timeout waiting for EOSE".to_string())? +} + #[cfg(test)] mod pairing_relay_tests { use super::{pairing_relay_from_nip11, probe_pairing_relay, PairingRelay}; @@ -554,41 +592,3 @@ mod pairing_relay_tests { assert_eq!(pairing_relay_from_nip11(&document), PairingRelay::MainRelay); } } - -fn parse_auth_challenge(text: &str) -> Option { - let arr: serde_json::Value = serde_json::from_str(text).ok()?; - let arr = arr.as_array()?; - if arr.len() >= 2 && arr[0].as_str()? == "AUTH" { - return arr[1].as_str().map(|s| s.to_string()); - } - None -} - -async fn wait_for_eose(read: &mut S, sub_id: &str, dur: Duration) -> Result<(), String> -where - S: StreamExt> + Unpin, -{ - tokio::time::timeout(dur, async { - loop { - let msg = read - .next() - .await - .ok_or_else(|| "relay closed waiting for EOSE".to_string())? - .map_err(|e| format!("WS error waiting for EOSE: {e}"))?; - if let Message::Text(text) = msg { - if let Ok(arr) = serde_json::from_str::(text.as_str()) { - if let Some(arr) = arr.as_array() { - if arr.len() >= 2 - && arr[0].as_str() == Some("EOSE") - && arr[1].as_str() == Some(sub_id) - { - return Ok(()); - } - } - } - } - } - }) - .await - .map_err(|_| "timeout waiting for EOSE".to_string())? -}