From 4367f2d0e3a5676c30c8fe8e12da78ad1c11bb4c Mon Sep 17 00:00:00 2001 From: axiomatic-aardvark Date: Fri, 7 Jul 2023 18:02:45 +0300 Subject: [PATCH] chore: fix tests --- poi-radio/src/lib.rs | 16 +++++++++++----- poi-radio/src/operator/mod.rs | 17 ++++++++++++++--- poi-radio/src/state.rs | 11 ----------- test-runner/src/poi_divergent.rs | 2 +- test-runner/src/poi_match.rs | 2 +- test-sender/src/main.rs | 12 ++++++------ 6 files changed, 33 insertions(+), 27 deletions(-) diff --git a/poi-radio/src/lib.rs b/poi-radio/src/lib.rs index cf5d1f5..80f3371 100644 --- a/poi-radio/src/lib.rs +++ b/poi-radio/src/lib.rs @@ -155,16 +155,22 @@ impl RadioPayloadMessage { /// Check duplicated fields: payload message has duplicated fields with GraphcastMessage, the values must be the same pub fn valid_outer(&self, outer: &GraphcastMessage) -> Result<&Self, BuildMessageError> { - if self.nonce == outer.nonce - && self.graph_account == outer.graph_account - && self.identifier == outer.identifier - { + let nonce_check = self.nonce == outer.nonce; + let account_check = + self.graph_account.to_ascii_lowercase() == outer.graph_account.to_ascii_lowercase(); + let identifier_check = + self.identifier.to_ascii_lowercase() == outer.identifier.to_ascii_lowercase(); + + if nonce_check && account_check && identifier_check { Ok(self) } else { Err(BuildMessageError::InvalidFields(anyhow::anyhow!( - "Radio message wrapped by inconsistent GraphcastMessage: {:#?} <- {:#?}", + "Radio message wrapped by inconsistent GraphcastMessage: {:#?} <- {:#?}\nNonce check: {:#?}\nAccount check: {:#?}\nIdentifier check: {:#?}", &self, &outer, + nonce_check, + account_check, + identifier_check ))) } } diff --git a/poi-radio/src/operator/mod.rs b/poi-radio/src/operator/mod.rs index 57ad4ef..bd3161b 100644 --- a/poi-radio/src/operator/mod.rs +++ b/poi-radio/src/operator/mod.rs @@ -1,7 +1,6 @@ use derive_getters::Getters; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{mpsc, Arc, Mutex as SyncMutex}; -use std::thread; use std::time::Duration; use tokio::sync::Mutex as AsyncMutex; use tokio::time::{interval, sleep, timeout}; @@ -150,14 +149,26 @@ impl RadioOperator { .register_handler(Arc::new(AsyncMutex::new(handler))) .expect("Could not register handler"); let state_ref = self.persisted_state.clone(); - thread::spawn(move || { + + let config = self.config.clone(); + + tokio::spawn(async move { for msg in receiver { trace!( "Radio operator received a validated message from Graphcast agent: {:#?}", msg ); let identifier = msg.identifier.clone(); - state_ref.add_remote_message(msg.clone()); + + let is_valid = msg + .payload + .validity_check(&msg, config.graph_node_endpoint()) + .await; + + if is_valid.is_ok() { + state_ref.add_remote_message(msg.clone()); + } + CACHED_MESSAGES.with_label_values(&[&identifier]).set( state_ref .remote_messages() diff --git a/poi-radio/src/state.rs b/poi-radio/src/state.rs index 0d60885..ba1ab64 100644 --- a/poi-radio/src/state.rs +++ b/poi-radio/src/state.rs @@ -125,16 +125,6 @@ impl PersistedState { self.remote_messages.lock().unwrap().push(msg) } - /// Update comparison_results - pub fn update_comparison_result(&self, comparison_result: ComparisonResult) { - let deployment = comparison_result.clone().deployment; - - self.comparison_results - .lock() - .unwrap() - .insert(deployment, comparison_result); - } - /// Add entry to comparison_results pub fn add_comparison_result(&self, comparison_result: ComparisonResult) { let deployment = comparison_result.clone().deployment; @@ -302,7 +292,6 @@ impl PersistedState { #[cfg(test)] mod tests { use super::*; - use graphcast_sdk::networks::NetworkName; use crate::operator::attestation::{save_local_attestation, ComparisonResultType}; diff --git a/test-runner/src/poi_divergent.rs b/test-runner/src/poi_divergent.rs index ef68505..647dd1f 100644 --- a/test-runner/src/poi_divergent.rs +++ b/test-runner/src/poi_divergent.rs @@ -31,7 +31,7 @@ pub async fn poi_divergent_test() { let process_manager = setup(&config, test_file_name, &mut test_sender_config).await; - sleep(Duration::from_secs(300)).await; + sleep(Duration::from_secs(550)).await; let persisted_state = PersistedState::load_cache(&store_path); debug!("persisted state {:?}", persisted_state); diff --git a/test-runner/src/poi_match.rs b/test-runner/src/poi_match.rs index 814a947..b2a314a 100644 --- a/test-runner/src/poi_match.rs +++ b/test-runner/src/poi_match.rs @@ -31,7 +31,7 @@ pub async fn poi_match_test() { let process_manager = setup(&config, test_file_name, &mut test_sender_config).await; - sleep(Duration::from_secs(300)).await; + sleep(Duration::from_secs(550)).await; let persisted_state = PersistedState::load_cache(&store_path); debug!("persisted state {:?}", persisted_state); diff --git a/test-sender/src/main.rs b/test-sender/src/main.rs index 6a12e5e..a9c8899 100644 --- a/test-sender/src/main.rs +++ b/test-sender/src/main.rs @@ -81,31 +81,31 @@ async fn start_sender(config: TestSenderConfig) { let content_topic = format!("/{}/0/{}/proto", config.radio_name, topic); let content_topic = WakuContentTopic::from_str(&content_topic).unwrap(); + let nonce = config.nonce.clone().unwrap().parse::().unwrap(); + let radio_payload_clone = config.radio_payload.clone(); match radio_payload_clone.as_deref() { Some("radio_payload_message") => { let radio_payload = RadioPayloadMessage::build( topic.clone(), config.poi.clone().unwrap(), - timestamp, + nonce, NetworkName::Goerli, timestamp.try_into().unwrap(), config.block_hash.clone().unwrap(), "0x7e6528e4ce3055e829a32b5dc4450072bac28bc6".to_string(), ); - let mut graphcast_message = GraphcastMessage::build( + let graphcast_message = GraphcastMessage::build( &wallet, topic.clone(), - timestamp, + nonce, "0x7e6528e4ce3055e829a32b5dc4450072bac28bc6".to_string(), radio_payload, ) .await .unwrap(); - graphcast_message.nonce = config.nonce.clone().unwrap().parse::().unwrap(); - match graphcast_message.send_to_waku( &node_handle, WakuPubSubTopic::from_str("/waku/2/graphcast-v0-testnet/proto").unwrap(), @@ -124,7 +124,7 @@ async fn start_sender(config: TestSenderConfig) { let graphcast_message = GraphcastMessage::build( &wallet, topic.clone(), - timestamp, + nonce, "0x7e6528e4ce3055e829a32b5dc4450072bac28bc6".to_string(), payload, )