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/held.rs | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) (limited to 'src/federation/held.rs') diff --git a/src/federation/held.rs b/src/federation/held.rs index 3c8bafb..ae2264b 100644 --- a/src/federation/held.rs +++ b/src/federation/held.rs @@ -791,19 +791,8 @@ async fn put_again(state: &crate::state::AppState) { mod tests { use super::*; use crate::document::Document; - use crate::federation::event::Checkpoint; use crate::federation::harness::{self, Party, Spec}; use crate::federation::store::memory::Refusal; - use crate::federation::version::Version; - - fn root_of(spec: &Spec) -> Vec { - Checkpoint { - at: Vec::new(), - keeps: Vec::new(), - version: Version::read(&spec.json()).expect("a version"), - } - .bytes() - } fn put(doc: &mut Document, event: &[u8]) { events::put(doc, &[event]); @@ -823,7 +812,7 @@ mod tests { Party::new("makefu", 3), ); let first = Spec::first(&[&tv, &lass, &makefu], &[]); - let root = root_of(&first); + let root = first.root(); let on = first.hash(); let gone = tv.write(&[Id::of(&root)], "home/tv/a", harness::str("1")); let kept = tv.write(&[Id::of(&gone)], "home/tv/a", harness::str("2")); @@ -875,7 +864,7 @@ mod tests { fn an_operator_drops_what_its_node_took_and_allows_it_again() { let tv = Party::new("tv", 1); let first = Spec::first(&[&tv], &[]); - let root = root_of(&first); + let root = first.root(); let write = tv.write(&[Id::of(&root)], "home/tv/x", harness::str("1")); let on = tv.write(&[Id::of(&write)], "home/tv/x", harness::str("2")); let holding = Holding::default(); @@ -905,7 +894,7 @@ mod tests { fn a_node_puts_again_what_its_document_lacks() { let tv = Party::new("tv", 1); let first = Spec::first(&[&tv], &[]); - let root = root_of(&first); + let root = first.root(); let write = tv.write(&[Id::of(&root)], "home/tv/x", harness::str("1")); let on = tv.write(&[Id::of(&write)], "home/tv/x", harness::str("2")); let mut left = events::started(Federation::NAME, &root).unwrap(); @@ -930,7 +919,7 @@ mod tests { fn the_store_takes_the_events_the_document_holds() { let tv = Party::new("tv", 1); let first = Spec::first(&[&tv], &[]); - let root = root_of(&first); + let root = first.root(); let mut doc = events::started(Federation::NAME, &root).unwrap(); let holding = Holding::default(); assert!(holding.unread(&Document::new(), 0).is_none()); @@ -972,7 +961,7 @@ mod tests { Party::new("makefu", 3), ); let first = Spec::first(&[&tv, &lass, &makefu], &[]); - let root = root_of(&first); + let root = first.root(); let on = first.hash(); let one = first.after(on); let mut two = first.after(on); @@ -1032,7 +1021,7 @@ mod tests { /// tv's federation, its root, and a document started from it. fn tv_alone() -> (Party, Vec, Document) { let tv = Party::new("tv", 1); - let root = root_of(&Spec::first(&[&tv], &[])); + let root = Spec::first(&[&tv], &[]).root(); let doc = events::started(Federation::NAME, &root).unwrap(); (tv, root, doc) } @@ -1097,7 +1086,7 @@ mod tests { fn store_attack_8() { let (_, _, mut doc) = tv_alone(); let junk = b"{\"not\":\"an event\"}".to_vec(); - let other = root_of(&Spec::first(&[&Party::new("lass", 2)], &[])); + let other = Spec::first(&[&Party::new("lass", 2)], &[]).root(); put(&mut doc, &junk); put(&mut doc, &other); let holding = Holding::default(); @@ -1142,7 +1131,7 @@ mod tests { let (tv, lass) = (Party::new("tv", 1), Party::new("lass", 2)); let makefu = Party::new("makefu", 3); let first = Spec::first(&[&tv, &lass, &makefu], &[]); - let root = root_of(&first); + let root = first.root(); let on = first.hash(); let head = tv.write(&[Id::of(&root)], "home/tv/a", harness::str("1")); let mut next = first.after(on); -- cgit v1.3.1