Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

Commit

Permalink
chore: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
neriumrevolta authored and hopeyen committed Jul 7, 2023
1 parent a638b01 commit 016a9ac
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 27 deletions.
14 changes: 9 additions & 5 deletions poi-radio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,20 @@ 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<Self>) -> 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 == outer.graph_account;
let identifier_check = self.identifier == outer.identifier;

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
)))
}
}
Expand Down
17 changes: 14 additions & 3 deletions poi-radio/src/operator/mod.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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()
Expand Down
11 changes: 0 additions & 11 deletions poi-radio/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion test-runner/src/poi_divergent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test-runner/src/poi_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions test-sender/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<i64>().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::<i64>().unwrap();

match graphcast_message.send_to_waku(
&node_handle,
WakuPubSubTopic::from_str("/waku/2/graphcast-v0-testnet/proto").unwrap(),
Expand All @@ -124,7 +124,7 @@ async fn start_sender(config: TestSenderConfig) {
let graphcast_message = GraphcastMessage::build(
&wallet,
topic.clone(),
timestamp,
nonce,
"0x7e6528e4ce3055e829a32b5dc4450072bac28bc6".to_string(),
payload,
)
Expand Down

0 comments on commit 016a9ac

Please sign in to comment.