tests: add p2pool sync test

This commit is contained in:
hinto.janai 2023-04-14 13:45:30 -04:00
parent 7d9ed1b0b8
commit 34a840cfac
No known key found for this signature in database
GPG key ID: D47CE05FA175A499
2 changed files with 28 additions and 2 deletions

View file

@ -121,6 +121,7 @@ impl Default for Sys { fn default() -> Self { Self::new() } }
//---------------------------------------------------------------------------------------------------- [Process] Struct
// This holds all the state of a (child) process.
// The main GUI thread will use this to display console text, online state, etc.
#[derive(Debug)]
pub struct Process {
pub name: ProcessName, // P2Pool or XMRig?
pub state: ProcessState, // The state of the process (alive, dead, etc)
@ -1900,6 +1901,8 @@ impl Hashrate {
//---------------------------------------------------------------------------------------------------- TESTS
#[cfg(test)]
mod test {
use super::*;
#[test]
fn reset_gui_output() {
let max = crate::helper::GUI_OUTPUT_LEEWAY;
@ -1955,7 +1958,8 @@ mod test {
let output_pub = Arc::new(Mutex::new(String::new()));
let elapsed = std::time::Duration::from_secs(60);
let regex = P2poolRegex::new();
PubP2poolApi::update_from_output(&public, &output_parse, &output_pub, elapsed, &regex);
let process = Arc::new(Mutex::new(Process::new(ProcessName::P2pool, "".to_string(), PathBuf::new())));
PubP2poolApi::update_from_output(&public, &output_parse, &output_pub, elapsed, &regex, &process);
let public = public.lock().unwrap();
println!("{:#?}", public);
assert_eq!(public.payouts, 3);
@ -1968,6 +1972,28 @@ mod test {
assert_eq!(public.xmr_month, 648000.0000001296);
}
#[test]
fn set_p2pool_synchronized() {
use crate::helper::{PubP2poolApi,P2poolRegex};
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 regex = P2poolRegex::new();
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, &regex, &process);
println!("{:#?}", process);
assert!(process.lock().unwrap().state == ProcessState::Alive);
}
#[test]
fn update_pub_p2pool_from_local_network_pool() {
use std::sync::{Arc,Mutex};

View file

@ -127,6 +127,6 @@ mod test {
assert_eq!(r.block.find(text).unwrap().as_str(), "block 1111111");
assert_eq!(r.block_int.find(text).unwrap().as_str(), "1111111");
assert_eq!(r.block_comma.find(text2).unwrap().as_str(), "1,111,111");
assert_eq!(r.synchronized.find(text2).unwrap().as_str(), "SYNCHRONIZED");
assert_eq!(r.synchronized.find(text3).unwrap().as_str(), "SYNCHRONIZED");
}
}