From ce8ccdc68f5b0cc52b380177665ee07505c5bfb5 Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 16 Nov 2026 22:56:25 +0000 Subject: federation: the tests' harness builds a federation's root `Spec::root`: the root whose first version a spec spells out, built in one place for the tests of the attacks, of the store read from a document, and the properties. --- src/federation/attacks.rs | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'src/federation/attacks.rs') diff --git a/src/federation/attacks.rs b/src/federation/attacks.rs index 80c9f9c..a7efd50 100644 --- a/src/federation/attacks.rs +++ b/src/federation/attacks.rs @@ -34,19 +34,10 @@ struct Fed { first: Spec, } -fn root_of(spec: &Spec) -> Vec { - Checkpoint { - at: Vec::new(), - keeps: Vec::new(), - version: Version::read(&spec.json()).expect("a version"), - } - .bytes() -} - fn fed(parties: &[&Party], rules: &[(&str, Json)]) -> Fed { let first = Spec::first(parties, rules); Fed { - store: Store::new(root_of(&first), Vec::new()).expect("a root"), + store: Store::new(first.root(), Vec::new()).expect("a root"), first, } } @@ -381,7 +372,7 @@ fn federation_attack_12() { for flip in [false, true] { for backwards in [false, true] { let mut store: Store = - Store::new(root_of(&first), Vec::new()).expect("a root"); + Store::new(first.root(), Vec::new()).expect("a root"); let mut order: Vec> = before.clone(); let mut written = versions.clone(); if flip { @@ -430,7 +421,7 @@ fn federation_attack_13() { permutations(&mut (0..4).collect(), 0, &mut orders); for order in orders { let mut store: Store = - Store::new(root_of(&fed.first), Vec::new()).expect("a root"); + Store::new(fed.first.root(), Vec::new()).expect("a root"); store.offer(proposal.clone()); for i in order { store.offer(votes[i].clone()); @@ -738,8 +729,8 @@ fn federation_attack_37() { assert_eq!(one, two); assert!(fed.store.checks_fork(&[here], &spec, &one.0)); // One first version, one federation. - assert_eq!(root_of(&fed.first), root_of(&fed.first.clone())); - assert_eq!(Id::of(&root_of(&fed.first)), root); + assert_eq!(fed.first.root(), fed.first.clone().root()); + assert_eq!(Id::of(&fed.first.root()), root); } #[test] @@ -805,7 +796,7 @@ fn federation_attack_41() { // A first version listing no node: a store no node is a member of. let mut nobody = first.clone(); nobody.parties[0].nodes.clear(); - let store: Store = Store::new(root_of(&nobody), Vec::new()).expect("a root"); + let store: Store = Store::new(nobody.root(), Vec::new()).expect("a root"); assert!(store.state().members().is_empty()); } @@ -1045,7 +1036,7 @@ fn federation_attack_56() { let v2 = harness::version_event(&[Id::of(&votes[2]), Id::of(&votes[3])], two.hash()); for (first, heads) in [(&v1, ia), (&v2, ib)] { let mut store: Store = - Store::new(root_of(&fed.first), Vec::new()).expect("a root"); + Store::new(fed.first.root(), Vec::new()).expect("a root"); for bytes in [&a, &b, &p1, &p2] { store.offer(bytes.clone()); } -- cgit v1.3.1