aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-16 23:49:56 +0000
committertv <tv@krebsco.de>2026-11-17 01:02:49 +0100
commitcd47b1fc79893507096d4b6b7e25f47ee8c7cdbb (patch)
treee553ded02d1c87f25ccc83e6859fa8186ba1c1c6
parentd8b8f01b08b31f5a10dad0a0d23727a8eabc5499 (diff)
federation: each attack table checked whole, its rows marked sim too
One check of an attack table (`harness::every_row_has_its_test`), for the federation's and the store's: every row has its test among the sources of its kind, unit tests or the simulations (`simtest::holding`), but for the rows whose tests wait for later; a row marked `—` has none; no test names a row that isn't there, nor two tests one row. The rows waiting: forks, the remakes, flooding, what a node, a client or a tool does that isn't built yet, and a rule for two checkpoints proposed at once.
-rw-r--r--src/federation/attacks.rs56
-rw-r--r--src/federation/harness.rs72
-rw-r--r--src/federation/held.rs67
3 files changed, 101 insertions, 94 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]
diff --git a/src/federation/harness.rs b/src/federation/harness.rs
index 42ee870..4baf049 100644
--- a/src/federation/harness.rs
+++ b/src/federation/harness.rs
@@ -259,3 +259,75 @@ impl Spec {
.bytes()
}
}
+
+/// Checks the attack table of `doc` (its section Attacks): every row has its test, named
+/// `{prefix}{row}`, among the sources of its kind, `unit` rows among `unit` and `sim`
+/// rows among `sim`, but for the rows `later`, whose tests come with later stages; a row
+/// marked `—` has none; and no test names a row that isn't there, nor two tests one row.
+pub(crate) fn every_row_has_its_test(
+ doc: &str,
+ prefix: &str,
+ unit: &[&str],
+ sim: &[&str],
+ later: &[u32],
+) {
+ let attacks = doc.split("\n## Attacks").nth(1).expect("an attack table");
+ let attacks = attacks.split("\n## ").next().unwrap_or(attacks);
+ let rows: std::collections::BTreeMap<u32, String> = attacks
+ .lines()
+ .filter_map(|line| {
+ let cells: Vec<&str> = line.split('|').map(str::trim).collect();
+ Some((cells.get(1)?.parse().ok()?, cells.get(4)?.to_string()))
+ })
+ .collect();
+ let tests = |sources: &[&str]| -> Vec<u32> {
+ sources
+ .iter()
+ .flat_map(|source| source.lines())
+ .filter_map(|line| {
+ let line = line.trim();
+ line.strip_prefix("async ")
+ .unwrap_or(line)
+ .strip_prefix("fn ")?
+ .strip_prefix(prefix)?
+ .split('(')
+ .next()?
+ .parse()
+ .ok()
+ })
+ .collect()
+ };
+ let (unit, sim) = (tests(unit), tests(sim));
+ let all: Vec<u32> = unit.iter().chain(&sim).copied().collect();
+ for n in &all {
+ assert!(rows.contains_key(n), "a test of row {n}, which isn't there");
+ assert_eq!(
+ all.iter().filter(|m| *m == n).count(),
+ 1,
+ "row {n} tested twice"
+ );
+ }
+ let mut missing = Vec::new();
+ for (n, kind) in &rows {
+ let none = kind == "—";
+ let tested = if kind.starts_with("unit") {
+ unit.contains(n)
+ } else if kind == "sim" {
+ sim.contains(n)
+ } else {
+ false
+ };
+ if later.contains(n) {
+ assert!(!all.contains(n), "row {n} has its test now");
+ assert!(!none, "row {n} asks for no test");
+ } else if none {
+ assert!(!all.contains(n), "row {n} asks for no test, and has one");
+ } else if !tested {
+ missing.push(*n);
+ }
+ }
+ assert!(
+ missing.is_empty(),
+ "rows without their test of their kind: {missing:?}"
+ );
+}
diff --git a/src/federation/held.rs b/src/federation/held.rs
index 6e075aa..ba7837b 100644
--- a/src/federation/held.rs
+++ b/src/federation/held.rs
@@ -1246,59 +1246,22 @@ mod tests {
assert_eq!(holding.passed(), Vec::<Vec<u8>>::new());
}
- /// Rows the next stages test.
- const LATER: &[u32] = &[21, 22];
+ /// Rows whose tests wait: remakes (stage 5), and flooding.
+ const LATER: &[u32] = &[11, 12, 13, 15, 16, 21, 22, 28, 29, 30, 31];
#[test]
- fn every_row_marked_unit_has_its_test() {
- let doc = include_str!("../../docs/store.md");
- let attacks = doc.split("\n## Attacks").nth(1).expect("its attacks");
- let attacks = attacks.split("\n## ").next().unwrap_or(attacks);
- let sources = [
- include_str!("held.rs"),
- include_str!("store/memory.rs"),
- include_str!("../access/holding.rs"),
- include_str!("../access/token.rs"),
- ];
- let rows: BTreeMap<u32, String> = attacks
- .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: Vec<u32> = sources
- .iter()
- .flat_map(|source| source.lines())
- .filter_map(|line| {
- line.trim()
- .strip_prefix("fn store_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");
- assert_eq!(
- tested.iter().filter(|m| *m == n).count(),
- 1,
- "row {n} tested twice"
- );
- }
- 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/store.md"),
+ "store_attack_",
+ &[
+ include_str!("held.rs"),
+ include_str!("store/memory.rs"),
+ include_str!("../access/holding.rs"),
+ include_str!("../access/token.rs"),
+ ],
+ &[include_str!("../simtest/holding.rs")],
+ LATER,
+ );
}
}