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

Fix tests #205

Merged
merged 1 commit into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
196 changes: 103 additions & 93 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion one-shot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ keywords = ["graphprotocol", "data-integrity", "Indexer", "waku", "p2p"]
categories = ["network-programming", "web-programming::http-client"]

[dependencies]
graphcast-sdk = { package = "graphcast-sdk", git = "https://github.com/graphops/graphcast-sdk", rev = "99d942e" }
graphcast-sdk = { package = "graphcast-sdk", git = "https://github.com/graphops/graphcast-sdk", branch = "hope/subgraph-owner-check" }
poi-radio = { path = "../poi-radio" }
prost = "0.11"
once_cell = "1.17"
Expand Down
2 changes: 1 addition & 1 deletion poi-radio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ keywords = ["graphprotocol", "data-integrity", "Indexer", "waku", "p2p"]
categories = ["network-programming", "web-programming::http-client"]

[dependencies]
graphcast-sdk = { package = "graphcast-sdk", git = "https://github.com/graphops/graphcast-sdk", rev = "99d942e" }
graphcast-sdk = { package = "graphcast-sdk", git = "https://github.com/graphops/graphcast-sdk", branch = "hope/subgraph-owner-check" }
prost = "0.11"
once_cell = "1.17"
chrono = "0.4"
Expand Down
5 changes: 2 additions & 3 deletions poi-radio/src/operator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl RadioOperator {
let callbook = agent.callbook.clone();
let nonces = agent.nonces.clone();
let local_sender = agent.graphcast_identity.graphcast_id.clone();
if let Ok(msg) = agent.decoder::<PublicPoiMessage>(msg.payload()).await {
if let Ok(msg) = agent.decode::<PublicPoiMessage>(msg.payload()).await {
trace!(
message = tracing::field::debug(&msg),
"Parseable as Public PoI message, now validate",
Expand Down Expand Up @@ -175,8 +175,7 @@ impl RadioOperator {
.unwrap(),
);
};
} else if let Ok(msg) = agent.decoder::<VersionUpgradeMessage>(msg.payload()).await
{
} else if let Ok(msg) = agent.decode::<VersionUpgradeMessage>(msg.payload()).await {
trace!(
message = tracing::field::debug(&msg),
"Parseable as Version Upgrade message, now validate",
Expand Down
2 changes: 1 addition & 1 deletion test-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ categories = [
[dependencies]
waku = { version = "0.1.1", package = "waku-bindings" }
test-utils = { path = "../test-utils" }
graphcast-sdk = { package = "graphcast-sdk", git = "https://github.com/graphops/graphcast-sdk", rev = "99d942e" }
graphcast-sdk = { package = "graphcast-sdk", git = "https://github.com/graphops/graphcast-sdk", branch = "hope/subgraph-owner-check" }
poi-radio = { path = "../poi-radio" }
tokio = { version = "1.1.1", features = ["full", "rt"] }
tracing = "0.1"
Expand Down
102 changes: 48 additions & 54 deletions test-runner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ pub async fn main() {
let config = test_config();

std::env::set_var(
"RUST_LOG",
"off,hyper=off,graphcast_sdk=trace,poi_radio=trace,test_runner=trace,test_sender=trace,test_utils=trace",
);
"RUST_LOG",
"off,hyper=off,graphcast_sdk=trace,poi_radio=trace,test_runner=trace,test_sender=trace,test_utils=trace",
);
init_tracing(config.log_format).expect("Could not set up global default subscriber for logger, check environmental variable `RUST_LOG` or the CLI input `log-level");

let start_time = Instant::now();

let mut retry_count = 3;
let mut initial_test_results: HashMap<String, bool> = HashMap::new();
let mut retry_count = 5;
let mut initial_tests_passed = false;
let mut initial_test_results: HashMap<String, bool> = HashMap::new();

while retry_count > 0 && !initial_tests_passed {
let initial_tests = vec![
Expand All @@ -68,58 +68,51 @@ pub async fn main() {
}
}

if initial_tests_passed {
let poi_tests = vec![
("poi_divergent_test", tokio::spawn(poi_divergent_test())),
("poi_match_test", tokio::spawn(poi_match_test())),
];

let (poi_tests_passed, poi_test_results) = run_tests(poi_tests).await;
if poi_tests_passed {
let remaining_tests = vec![
(
"invalid_block_hash_test",
tokio::spawn(invalid_block_hash_test()),
),
("invalid_sender_test", tokio::spawn(invalid_sender_test())),
("invalid_nonce_test", tokio::spawn(invalid_nonce_test())),
("invalid_payload_test", tokio::spawn(invalid_payload_test())),
];

let (remaining_tests_passed, remaining_test_results) = run_tests(remaining_tests).await;

print_test_summary(
initial_test_results,
poi_test_results,
remaining_test_results,
remaining_tests_passed,
start_time,
);
} else {
print_test_summary(
initial_test_results,
poi_test_results,
HashMap::new(),
false,
start_time,
);
}
} else {
print_test_summary(
initial_test_results,
HashMap::new(),
HashMap::new(),
false,
start_time,
);
}
let poi_tests = vec![
("poi_divergent_test", tokio::spawn(poi_divergent_test())),
("poi_match_test", tokio::spawn(poi_match_test())),
];

let (poi_tests_passed, poi_test_results) = run_tests(poi_tests).await;

let validity_tests_group_1 = vec![
(
"invalid_block_hash_test",
tokio::spawn(invalid_block_hash_test()),
),
("invalid_sender_test", tokio::spawn(invalid_sender_test())),
];

let (validity_tests_group_1_passed, validity_test_results_group_1) =
run_tests(validity_tests_group_1).await;

let validity_tests_group_2 = vec![
("invalid_nonce_test", tokio::spawn(invalid_nonce_test())),
("invalid_payload_test", tokio::spawn(invalid_payload_test())),
];

let (validity_tests_group_2_passed, validity_test_results_group_2) =
run_tests(validity_tests_group_2).await;

print_test_summary(
initial_test_results,
poi_test_results,
validity_test_results_group_1,
validity_test_results_group_2,
initial_tests_passed
&& poi_tests_passed
&& validity_tests_group_1_passed
&& validity_tests_group_2_passed,
start_time,
);
}

fn print_test_summary(
initial_test_results: HashMap<String, bool>,
poi_test_results: HashMap<String, bool>,
remaining_test_results: HashMap<String, bool>,
remaining_tests_passed: bool,
validity_test_results_group_1: HashMap<String, bool>,
validity_test_results_group_2: HashMap<String, bool>,
tests_passed: bool,
start_time: Instant,
) {
let elapsed_time = start_time.elapsed();
Expand All @@ -128,7 +121,8 @@ fn print_test_summary(
for (test_name, passed) in initial_test_results
.iter()
.chain(&poi_test_results)
.chain(&remaining_test_results)
.chain(&validity_test_results_group_1)
.chain(&validity_test_results_group_2)
{
if *passed {
info!("{}: PASSED", test_name);
Expand All @@ -137,7 +131,7 @@ fn print_test_summary(
}
}

if remaining_tests_passed {
if tests_passed {
info!(
"All tests passed ✅. Time elapsed: {}s",
elapsed_time.as_secs()
Expand Down
30 changes: 10 additions & 20 deletions test-runner/src/topics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub async fn topics_test() {
let mut config = test_config();
config.persistence_file_path = Some(store_path.clone());
config.topics = radio_topics.clone();
config.topic_update_interval = 10;
config.topic_update_interval = 90;

let mut test_sender_config = TestSenderConfig {
topics: test_sender_topics,
Expand Down Expand Up @@ -108,16 +108,16 @@ pub async fn topics_test() {

tokio::time::sleep(Duration::from_secs(50)).await;

let persisted_state = PersistedState::load_cache(&store_path);
debug!("persisted state {:?}", persisted_state);

let remote_messages = persisted_state.remote_messages();

let test_hash = "QmonlyintestsenderXyZABCdeFgHIjklMNOpqrstuvWXYZabcdEFG";
let mut has_test_hash = test_result(&store_path, test_hash);

let max_test_attempts = 3;
let mut num_test_attempts = 0;
while num_test_attempts < max_test_attempts && !has_test_hash {
tokio::time::sleep(Duration::from_secs(config.topic_update_interval + 1)).await;
has_test_hash = test_result(&store_path, test_hash);
num_test_attempts += 1;
}
let has_test_hash = remote_messages
.iter()
.any(|msg| msg.identifier == test_hash);

assert!(
has_test_hash,
"Expected remote message not found with identifier {}",
Expand All @@ -126,13 +126,3 @@ pub async fn topics_test() {

teardown(process_manager, &store_path);
}

fn test_result(store_path: &str, test_hash: &str) -> bool {
let persisted_state = PersistedState::load_cache(store_path);
debug!("persisted state {:?}", persisted_state);

let remote_messages = persisted_state.remote_messages();
remote_messages
.iter()
.any(|msg| msg.identifier == test_hash)
}
2 changes: 1 addition & 1 deletion test-sender/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ categories = [

[dependencies]
waku = { version = "0.1.1", package = "waku-bindings" }
graphcast-sdk = { package = "graphcast-sdk", git = "https://github.com/graphops/graphcast-sdk", rev = "99d942e" }
graphcast-sdk = { package = "graphcast-sdk", git = "https://github.com/graphops/graphcast-sdk", branch = "hope/subgraph-owner-check" }
test-utils = { path = "../test-utils" }
poi-radio = { path = "../poi-radio" }
tokio = { version = "1.1.1", features = ["full", "rt"] }
Expand Down
11 changes: 4 additions & 7 deletions test-sender/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,9 @@ 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 timestamp =
if let Some(n) = config.nonce.clone().and_then(|x| x.parse::<i64>().ok()) {
n
} else {
Utc::now().timestamp()
};
let nonce = config.nonce.clone().and_then(|s| s.parse::<i64>().ok());

let timestamp = Utc::now().timestamp();
let block_number = (timestamp + 9) / 10 * 10;

let radio_payload_clone = config.radio_payload.clone();
Expand All @@ -92,7 +89,7 @@ async fn start_sender(config: TestSenderConfig) {
let radio_payload = PublicPoiMessage::build(
topic.clone(),
config.poi.clone().unwrap(),
timestamp,
nonce.unwrap_or(timestamp),
NetworkName::Goerli,
block_number.try_into().unwrap(),
config.block_hash.clone().unwrap(),
Expand Down
2 changes: 1 addition & 1 deletion test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ categories = [

[dependencies]
waku = { version = "0.1.1", package = "waku-bindings" }
graphcast-sdk = { package = "graphcast-sdk", git = "https://github.com/graphops/graphcast-sdk", rev = "99d942e" }
graphcast-sdk = { package = "graphcast-sdk", git = "https://github.com/graphops/graphcast-sdk", branch = "hope/subgraph-owner-check" }
poi-radio = { path = "../poi-radio" }
tokio = { version = "1.1.1", features = ["full", "rt"] }
tracing = "0.1"
Expand Down
8 changes: 1 addition & 7 deletions test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use std::{
time::Duration,
};

use chrono::Utc;
use config::TestSenderConfig;
use graphcast_sdk::graphcast_agent::message_typing::GraphcastMessage;
use graphcast_sdk::graphcast_agent::message_typing::IdentityValidation;
Expand Down Expand Up @@ -96,12 +95,7 @@ pub async fn setup(
"4dbba1ba9fb18b0034965712598be1368edcf91ae2c551d59462aab578dab9c5".to_string(),
))
.arg("--nonce")
.arg(
&test_sender_config
.nonce
.clone()
.unwrap_or(Utc::now().timestamp().to_string()),
)
.arg(test_sender_config.nonce.as_deref().unwrap_or("None"))
.arg("--radio-payload")
.arg(
test_sender_config
Expand Down
Loading