From 65e9d86e48e3fd182882ceb54b9b8b1ff475369d Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 16 Nov 2026 22:47:30 +0000 Subject: store: a test per attack row marked unit Each row of `docs/store.md`, Attacks, marked unit has its test, `store_attack_`: where it is judged (`access::holding`, `access::token`), where the store held in memory meets it (`federation::store::memory`), and where a node reads its store from its document (`federation::held`). Tests that checked a row already take its name; a check reads the doc's rows and fails on a unit row without its test, but for rows 21 and 22, which the remakes bring. --- src/federation/store/memory.rs | 54 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 10 deletions(-) (limited to 'src/federation/store') diff --git a/src/federation/store/memory.rs b/src/federation/store/memory.rs index b8035d7..bc0c672 100644 --- a/src/federation/store/memory.rs +++ b/src/federation/store/memory.rs @@ -805,6 +805,47 @@ mod tests { assert_eq!(anew.own(), (own, drops)); } + /// Heads for a checkpoint before the store's, or one in another's history: no move + /// (`docs/store.md`, Attacks, 25). + #[test] + fn store_attack_25() { + let (mut store, cut, _, first) = cut_at_a_lock(); + let checkpoint = store.checkpoint().to_vec(); + store.offer(testfold::cut(&[cut], 2, &[first])); + assert_eq!(store.checkpoint(), checkpoint.as_slice()); + let mut store = self::store(); + let root = store.id(); + let one = taken(store.offer(testfold::put(&[root], "a", "1"))); + let two = taken(store.offer(testfold::put(&[one], "a", "2"))); + let checkpoint = store.checkpoint().to_vec(); + store.offer(testfold::cut(&[two], 1, &[one, two])); + assert_eq!(store.checkpoint(), checkpoint.as_slice()); + } + + /// A head brought again after a move: taken as held, and not read anew; so is what + /// came before it (`docs/store.md`, Attacks, 26). + #[test] + fn store_attack_26() { + let (mut store, _, lock, first) = cut_at_a_lock(); + let root = store.id(); + let second = Id::of(&testfold::put(&[first], "a", "2")); + let state = store.state().clone(); + assert_eq!(store.offer(testfold::lock(&[second], "b")), Offered::Held); + assert_eq!(Id::of(&testfold::lock(&[second], "b")), lock); + assert_eq!(store.offer(testfold::put(&[root], "a", "1")), Offered::Held); + assert!(store.state() == &state); + } + + /// An operator has its node drop an event its checkpoint keeps, or one of its heads: + /// refused (`docs/store.md`, Attacks, 27). + #[test] + fn store_attack_27() { + let (mut store, _, lock, first) = cut_at_a_lock(); + let second = Id::of(&testfold::put(&[first], "a", "2")); + assert!(store.drop_taken(&[second]).is_err()); + assert!(store.drop_taken(&[lock]).is_err()); + } + /// Heads leave out what is neither among them, in their history, nor above them. #[test] fn heads_leave_out_what_is_beside_them() { @@ -869,15 +910,6 @@ mod tests { store.offer(testfold::put(&[root], "c", "1")), Offered::Refused(Refusal::NotAbove) ); - // A head brought again is held; so is what came before it. - assert_eq!( - store.offer(testfold::lock( - &[Id::of(&testfold::put(&[first], "a", "2"))], - "b" - )), - Offered::Held - ); - assert_eq!(store.offer(testfold::put(&[root], "a", "1")), Offered::Held); } /// The checkpoint a store builds at heads it holds is the one it moves to there. @@ -932,8 +964,10 @@ mod tests { ); } + /// A fork's events brought to the store it came from, or the other way: never taken + /// (`docs/store.md`, Attacks, 9). #[test] - fn a_fork_and_the_store_it_left_take_nothing_of_each_other() { + fn store_attack_9() { let mut store = store(); let root = store.id(); let here = taken(store.offer(testfold::put(&[root], "a", "1"))); -- cgit v1.3.1