diff options
Diffstat (limited to 'src/federation/attacks.rs')
| -rw-r--r-- | src/federation/attacks.rs | 56 |
1 files changed, 14 insertions, 42 deletions
diff --git a/src/federation/attacks.rs b/src/federation/attacks.rs index a7efd50..707e0e7 100644 --- a/src/federation/attacks.rs +++ b/src/federation/attacks.rs @@ -1,8 +1,7 @@ //! The attacks of `docs/federation.md` marked unit, each a test named by its row -//! (`docs/federation-tests.md`), on the federation's fold and the store in memory. A test -//! checks that every such row has its test, or waits for a later stage. - -use std::collections::{BTreeMap, BTreeSet}; +//! (`docs/federation-tests.md`), on the federation's fold and the store in memory; those +//! marked sim are simulations (`simtest::holding`). A test checks that every row has its +//! test, or waits for a later stage. use super::event::Checkpoint; use super::fold::Federation; @@ -12,9 +11,9 @@ use super::store::memory::{Offered, Refusal, Store}; use super::store::{Fold, Id}; use super::version::Version; -/// Rows marked unit whose tests wait for a later stage: what a node, a party's client or -/// a tool does (stage 3), and what a node tells of a fork (stage 4). -const LATER: &[u32] = &[35, 36, 39, 45, 51, 58, 63, 65, 68]; +/// Rows whose tests wait: what a node, a party's client or a tool does (stage 3), forks +/// (stage 4), a rule for two checkpoints proposed at once, and flooding. +const LATER: &[u32] = &[30, 33, 35, 36, 39, 45, 51, 58, 59, 63, 65, 68]; fn tv() -> Party { Party::new("tv", 1) @@ -100,41 +99,14 @@ fn s(text: &str) -> Json { } #[test] -fn every_row_marked_unit_has_its_test() { - let doc = include_str!("../../docs/federation.md"); - let source = include_str!("attacks.rs"); - let rows: BTreeMap<u32, String> = doc - .lines() - .filter_map(|line| { - let cells: Vec<&str> = line.split('|').map(str::trim).collect(); - let n = cells.get(1)?.parse().ok()?; - Some((n, cells.get(4)?.to_string())) - }) - .collect(); - let tested: BTreeSet<u32> = source - .lines() - .filter_map(|line| { - line.trim() - .strip_prefix("fn federation_attack_")? - .split('(') - .next()? - .parse() - .ok() - }) - .collect(); - let missing: Vec<&u32> = rows - .iter() - .filter(|(n, kind)| kind.starts_with("unit") && !tested.contains(n) && !LATER.contains(n)) - .map(|(n, _)| n) - .collect(); - assert!(missing.is_empty(), "rows without their test: {missing:?}"); - for n in &tested { - assert!(rows.contains_key(n), "a test of row {n}, which isn't there"); - } - for n in LATER { - assert!(!tested.contains(n), "row {n} has its test now"); - assert!(rows[n].starts_with("unit"), "row {n} isn't marked unit"); - } +fn every_row_has_its_test() { + harness::every_row_has_its_test( + include_str!("../../docs/federation.md"), + "federation_attack_", + &[include_str!("attacks.rs")], + &[include_str!("../simtest/holding.rs")], + LATER, + ); } #[test] |
