diff options
| author | tv <tv@krebsco.de> | 2026-11-16 22:56:25 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-17 00:09:47 +0100 |
| commit | ce8ccdc68f5b0cc52b380177665ee07505c5bfb5 (patch) | |
| tree | 339772ea691185c0d9d30c2927d83ab0e07623c3 /src/federation/attacks.rs | |
| parent | 9b20645df80363d922b25b8f2c0a531d060ff36f (diff) | |
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.
Diffstat (limited to 'src/federation/attacks.rs')
| -rw-r--r-- | src/federation/attacks.rs | 23 |
1 files changed, 7 insertions, 16 deletions
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<u8> { - 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<Federation> = - Store::new(root_of(&first), Vec::new()).expect("a root"); + Store::new(first.root(), Vec::new()).expect("a root"); let mut order: Vec<Vec<u8>> = 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<Federation> = - 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<Federation> = Store::new(root_of(&nobody), Vec::new()).expect("a root"); + let store: Store<Federation> = 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<Federation> = - 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()); } |
