From 1d7837e700685749b89ec34e63877239b71c32d3 Mon Sep 17 00:00:00 2001 From: Cyrix126 Date: Fri, 11 Oct 2024 17:49:00 +0200 Subject: [PATCH] Revert "fix: tests" This reverts commit 0949458d8562558016e24ed9dd594412e8372d71. --- src/helper/tests.rs | 87 +++++++++++++++++++++++++++++++++++++++++++++ src/utils/regex.rs | 1 + 2 files changed, 88 insertions(+) diff --git a/src/helper/tests.rs b/src/helper/tests.rs index 6941fcb..260980d 100644 --- a/src/helper/tests.rs +++ b/src/helper/tests.rs @@ -135,6 +135,93 @@ Uptime = 0h 2m 4s assert_eq!(public.xmr_month, 648000.0000001296); } + #[test] + fn set_p2pool_synchronized() { + use crate::helper::PubP2poolApi; + use std::sync::{Arc, Mutex}; + let public = Arc::new(Mutex::new(PubP2poolApi::new())); + let output_parse = Arc::new(Mutex::new(String::from( + r#"payout of 5.000000000001 XMR in block 1111 + NOTICE 2021-12-27 21:42:17.2008 SideChain SYNCHRONIZED + payout of 5.000000000001 XMR in block 1113"#, + ))); + let output_pub = Arc::new(Mutex::new(String::new())); + let elapsed = std::time::Duration::from_secs(60); + let process = Arc::new(Mutex::new(Process::new( + ProcessName::P2pool, + "".to_string(), + PathBuf::new(), + ))); + + // It only gets checked if we're `Syncing`. + process.lock().unwrap().state = ProcessState::Syncing; + PubP2poolApi::update_from_output(&public, &output_parse, &output_pub, elapsed, &process); + println!("{:#?}", process); + assert!(process.lock().unwrap().state == ProcessState::Alive); + } + + #[test] + fn p2pool_synchronized_false_positive() { + use crate::helper::PubP2poolApi; + use std::sync::{Arc, Mutex}; + let public = Arc::new(Mutex::new(PubP2poolApi::new())); + + // The SideChain that is "SYNCHRONIZED" in this output is + // probably not main/mini, but the sidechain started on height 1, + // so this should _not_ trigger alive state. + let output_parse = Arc::new(Mutex::new(String::from( + r#"payout of 5.000000000001 XMR in block 1111 + SideChain new chain tip: next height = 1 + NOTICE 2021-12-27 21:42:17.2008 SideChain SYNCHRONIZED + payout of 5.000000000001 XMR in block 1113"#, + ))); + let output_pub = Arc::new(Mutex::new(String::new())); + let elapsed = std::time::Duration::from_secs(60); + let process = Arc::new(Mutex::new(Process::new( + ProcessName::P2pool, + "".to_string(), + PathBuf::new(), + ))); + + // It only gets checked if we're `Syncing`. + process.lock().unwrap().state = ProcessState::Syncing; + PubP2poolApi::update_from_output(&public, &output_parse, &output_pub, elapsed, &process); + println!("{:#?}", process); + assert!(process.lock().unwrap().state == ProcessState::Syncing); // still syncing + } + + #[test] + fn p2pool_synchronized_double_synchronized() { + use crate::helper::PubP2poolApi; + use std::sync::{Arc, Mutex}; + let public = Arc::new(Mutex::new(PubP2poolApi::new())); + + // The 1st SideChain that is "SYNCHRONIZED" in this output is + // the sidechain started on height 1, but there is another one + // which means the real main/mini is probably synced, + // so this _should_ trigger alive state. + let output_parse = Arc::new(Mutex::new(String::from( + r#"payout of 5.000000000001 XMR in block 1111 + SideChain new chain tip: next height = 1 + NOTICE 2021-12-27 21:42:17.2008 SideChain SYNCHRONIZED + payout of 5.000000000001 XMR in block 1113 + NOTICE 2021-12-27 21:42:17.2100 SideChain SYNCHRONIZED"#, + ))); + let output_pub = Arc::new(Mutex::new(String::new())); + let elapsed = std::time::Duration::from_secs(60); + let process = Arc::new(Mutex::new(Process::new( + ProcessName::P2pool, + "".to_string(), + PathBuf::new(), + ))); + + // It only gets checked if we're `Syncing`. + process.lock().unwrap().state = ProcessState::Syncing; + PubP2poolApi::update_from_output(&public, &output_parse, &output_pub, elapsed, &process); + println!("{:#?}", process); + assert!(process.lock().unwrap().state == ProcessState::Alive); + } + #[test] fn update_pub_p2pool_from_local_network_pool() { use crate::helper::p2pool::PoolStatistics; diff --git a/src/utils/regex.rs b/src/utils/regex.rs index 0b07c73..ac747f9 100644 --- a/src/utils/regex.rs +++ b/src/utils/regex.rs @@ -284,6 +284,7 @@ mod test { let r = P2poolRegex::new(); let text = "NOTICE 2022-11-11 11:11:11.1111 P2Pool You received a payout of 0.111111111111 XMR in block 1111111"; let text2 = "2022-11-11 11:11:11.1111 | 0.111111111111 XMR | Block 1,111,111"; + let text3 = "NOTICE 2020-12-11 12:35:41.3150 SideChain SYNCHRONIZED"; assert_eq!( r.payout.find(text).unwrap().as_str(), "payout of 0.111111111111 XMR"