diff --git a/README.md b/README.md index e3a0a28..9a7d0a0 100644 --- a/README.md +++ b/README.md @@ -614,7 +614,7 @@ These are community nodes that **DON'T** have ZMQ enabled but are fast and well- ### General Info You need [`cargo`](https://www.rust-lang.org/learn/get-started), Rust's build tool and package manager. -There are `40` unit tests, you should probably run: +There are `41` unit tests, you should probably run: ``` cargo test ``` diff --git a/src/disk.rs b/src/disk.rs index 562b64f..07c3595 100644 --- a/src/disk.rs +++ b/src/disk.rs @@ -1405,7 +1405,6 @@ mod test { #[test] fn create_and_serde_gupax_p2pool_api() { use crate::disk::GupaxP2poolApi; - use crate::regex::P2poolRegex; use crate::xmr::PayoutOrd; use crate::xmr::AtomicUnit; @@ -1421,7 +1420,7 @@ mod test { api.log = "NOTICE 2022-01-27 01:30:23.1377 P2Pool You received a payout of 0.000000000001 XMR in block 2642816".to_string(); api.payout_u64 = 1; api.xmr = AtomicUnit::from_u64(2); - let (date, atomic_unit, block) = PayoutOrd::parse_raw_payout_line(&api.log, &P2poolRegex::new()); + let (date, atomic_unit, block) = PayoutOrd::parse_raw_payout_line(&api.log); let formatted_log_line = GupaxP2poolApi::format_payout(&date, &atomic_unit, &block); GupaxP2poolApi::write_to_all_files(&api, &formatted_log_line).unwrap(); println!("AFTER WRITE: {:#?}", api); diff --git a/src/helper.rs b/src/helper.rs index 79eed00..0c2655e 100644 --- a/src/helper.rs +++ b/src/helper.rs @@ -2075,6 +2075,26 @@ mod test { drop(p); } + #[test] + fn set_xmrig_mining() { + use crate::helper::PubXmrigApi; + use std::sync::{Arc,Mutex}; + let public = Arc::new(Mutex::new(PubXmrigApi::new())); + let output_parse = Arc::new(Mutex::new(String::from("[2022-02-12 12:49:30.311] net no active pools, stop mining"))); + 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::Xmrig, "".to_string(), PathBuf::new()))); + + process.lock().unwrap().state = ProcessState::Alive; + PubXmrigApi::update_from_output(&public, &output_parse, &output_pub, elapsed, &process); + println!("{:#?}", process); + assert!(process.lock().unwrap().state == ProcessState::NotMining); + + let output_parse = Arc::new(Mutex::new(String::from("[2022-02-12 12:49:30.311] net new job from 192.168.2.1:3333 diff 402K algo rx/0 height 2241142 (11 tx)"))); + PubXmrigApi::update_from_output(&public, &output_parse, &output_pub, elapsed, &process); + assert!(process.lock().unwrap().state == ProcessState::Alive); + } + #[test] fn serde_priv_p2pool_local_api() { let data = diff --git a/src/main.rs b/src/main.rs index 9220362..da80bef 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1887,25 +1887,6 @@ path_xmr: {:#?}\n //---------------------------------------------------------------------------------------------------- TESTS #[cfg(test)] mod test { - #[test] - fn build_regex() { - use regex::Regex; - let r = crate::Regexes::new(); - assert!(Regex::is_match(&r.name, "_this_ is... a n-a-m-e.")); - assert!(Regex::is_match(&r.address, "44hintoFpuo3ugKfcqJvh5BmrsTRpnTasJmetKC4VXCt6QDtbHVuixdTtsm6Ptp7Y8haXnJ6j8Gj2dra8CKy5ewz7Vi9CYW")); - assert!(Regex::is_match(&r.ipv4, "192.168.1.2")); - assert!(Regex::is_match(&r.ipv4, "127.0.0.1")); - assert!(Regex::is_match(&r.domain, "my.node.com")); - assert!(Regex::is_match(&r.domain, "my.monero-node123.net")); - assert!(Regex::is_match(&r.domain, "www.my-node.org")); - assert!(Regex::is_match(&r.domain, "www.my-monero-node123.io")); - for i in 1..=65535 { - assert!(Regex::is_match(&r.port, &i.to_string())); - } - assert!(!Regex::is_match(&r.port, "0")); - assert!(!Regex::is_match(&r.port, "65536")); - } - #[test] fn detect_benchmark_cpu() { use super::{Benchmark,cmp_f64}; diff --git a/src/regex.rs b/src/regex.rs index 106f402..7089b11 100644 --- a/src/regex.rs +++ b/src/regex.rs @@ -119,10 +119,12 @@ impl XmrigRegex { //---------------------------------------------------------------------------------------------------- TESTS #[cfg(test)] mod test { + use regex::Regex; + use super::*; + #[test] fn build_regexes() { - use regex::Regex; - let r = crate::Regexes::new(); + let r = Regexes::new(); assert!(Regex::is_match(&r.name, "_this_ is... a n-a-m-e.")); assert!(Regex::is_match(&r.address, "44hintoFpuo3ugKfcqJvh5BmrsTRpnTasJmetKC4VXCt6QDtbHVuixdTtsm6Ptp7Y8haXnJ6j8Gj2dra8CKy5ewz7Vi9CYW")); assert!(Regex::is_match(&r.ipv4, "192.168.1.2")); @@ -140,8 +142,7 @@ mod test { #[test] fn build_p2pool_regex() { - use regex::Regex; - let r = crate::P2poolRegex::new(); + 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"; @@ -153,4 +154,13 @@ mod test { assert_eq!(r.block_comma.find(text2).unwrap().as_str(), "1,111,111"); assert_eq!(r.synchronized.find(text3).unwrap().as_str(), "SYNCHRONIZED"); } + + #[test] + fn build_xmrig_regex() { + let r = XmrigRegex::new(); + let text = "[2022-02-12 12:49:30.311] net no active pools, stop mining"; + let text2 = "[2022-02-12 12:49:30.311] net new job from 192.168.2.1:3333 diff 402K algo rx/0 height 2241142 (11 tx)"; + assert_eq!(r.not_mining.find(text).unwrap().as_str(), "no active pools, stop mining"); + assert_eq!(r.new_job.find(text2).unwrap().as_str(), "new job"); + } }