Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make gossip portal-interop test auto generate comments for errors #118

Merged
merged 3 commits into from
Jan 11, 2024
Merged
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
55 changes: 38 additions & 17 deletions simulators/history/portal-interop/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,33 +641,54 @@ dyn_async! {
}
}

// wait 8 seconds for data to propagate
// This value is determined by how long the sleeps are in the gossip code
// So we may lower this or remove it depending on what we find.
tokio::time::sleep(Duration::from_secs(8)).await;

let comments = vec!["1 header", "1 block body", "100 header",
"100 block body", "7000000 header", "7000000 block body",
"7000000 receipt", "15600000 (post-merge) header", "15600000 (post-merge) block body", "15600000 (post-merge) receipt",
"17510000 (post-shanghai) header", "17510000 (post-shanghai) block body", "17510000 (post-shanghai) receipt"];

// wait test_data.len() seconds for data to propagate, giving more time if more items are propagating
tokio::time::sleep(Duration::from_secs(test_data.len() as u64)).await;

// process raw test data to generate content details for error output
let (first_header_key, first_header_value) = test_data.get(0).unwrap();
let first_header_key: HistoryContentKey =
serde_json::from_value(json!(first_header_key)).unwrap();
let first_header_value: HistoryContentValue =
serde_json::from_value(json!(first_header_value)).unwrap();
let mut last_header_seen: (HistoryContentKey, HistoryContentValue) = (first_header_key, first_header_value);
let mut result = vec![];
for (index, (content_key, content_value)) in test_data.into_iter().enumerate() {
for (content_key, content_value) in test_data.into_iter() {
let content_key: HistoryContentKey =
serde_json::from_value(json!(content_key)).unwrap();
let content_value: HistoryContentValue =
serde_json::from_value(json!(content_value)).unwrap();

if let HistoryContentKey::BlockHeaderWithProof(_) = &content_key {
last_header_seen = (content_key.clone(), content_value.clone());
}
let content_details =
if let HistoryContentValue::BlockHeaderWithProof(header_with_proof) = &last_header_seen.1 {
let content_type = match &content_key {
HistoryContentKey::BlockHeaderWithProof(_) => "header".to_string(),
HistoryContentKey::BlockBody(_) => "body".to_string(),
HistoryContentKey::BlockReceipts(_) => "receipt".to_string(),
HistoryContentKey::EpochAccumulator(_) => "epoch accumulator".to_string(),
};
format!(
"{}{} {}",
header_with_proof.header.number,
get_flair(header_with_proof.header.number),
content_type
)
} else {
unreachable!("History test data is formatted incorrectly. Header wasn't infront of data. Please refer to test data file for more information")
};

match client_b.rpc.local_content(content_key.clone()).await {
Ok(possible_content) => {
match possible_content {
PossibleHistoryContentValue::ContentPresent(content) => {
if content != content_value {
result.push(format!("Error content received for block {} was different then expected", comments[index]));
Ok(expected_value) => {
match expected_value {
PossibleHistoryContentValue::ContentPresent(actual_value) => {
if actual_value != content_value {
result.push(format!("Error content received for block {content_details} was different then expected"));
}
}
PossibleHistoryContentValue::ContentAbsent => {
result.push(format!("Error content for block {} was absent", comments[index]));
result.push(format!("Error content for block {content_details} was absent"));
}
}
}
Expand Down