aboutsummaryrefslogtreecommitdiffstats
path: root/src/federation/properties.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/federation/properties.rs')
-rw-r--r--src/federation/properties.rs62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/federation/properties.rs b/src/federation/properties.rs
index db11251..61d6adc 100644
--- a/src/federation/properties.rs
+++ b/src/federation/properties.rs
@@ -618,3 +618,65 @@ fn without_a_party_voting_twice_no_two_versions_change_one() {
},
);
}
+
+/// A fork at the heads of a history's first half, by the version current there, numbered
+/// one past it and changing it: its root keeps what counts at those heads, with its
+/// version current; it takes nothing else of the history; and the store it came from
+/// takes nothing built on the fork's root.
+#[test]
+fn a_fork_keeps_what_counts_at_its_heads_and_takes_nothing_of_the_other() {
+ check(
+ 32,
+ Kind {
+ adversary: false,
+ checkpoints: false,
+ },
+ |history| {
+ let (mut whole, _) = history.store(&history.written());
+ let half: Vec<usize> = (0..history.events.len() / 2).collect();
+ let (at, _) = history.store(&half);
+ let heads = at.heads();
+ let current = at.state().current();
+ let super::jcs::Json::Object(mut members) = current
+ .json
+ .without("number")
+ .without("changes")
+ .without("checkpoint")
+ else {
+ return Err("a version that is no object".to_owned());
+ };
+ members.push((
+ "number".to_owned(),
+ super::jcs::Json::Int(current.number as i64 + 1),
+ ));
+ members.push((
+ "changes".to_owned(),
+ super::jcs::Json::Str(current.hash.to_string()),
+ ));
+ let spec = super::jcs::Json::object(members).expect("names once each");
+ let (root, kept) = whole
+ .fork(&heads, &spec.bytes())
+ .map_err(|why| format!("no fork at {heads:?}: {}", why.0))?;
+ let mut fork: Store<Federation> =
+ Store::new(root.clone(), kept).map_err(|why| format!("no root: {}", why.0))?;
+ if fork.state().current().hash != Id::of(&spec.bytes()) {
+ return Err("the fork's version isn't current at its root".to_owned());
+ }
+ if fork.state().values() != at.state().values()
+ || fork.state().members() != at.state().members()
+ {
+ return Err("the fork's root doesn't keep what counts at its heads".to_owned());
+ }
+ for event in &history.events {
+ if let Offered::Taken(ids) = fork.offer(event.clone()) {
+ return Err(format!("the fork takes {ids:?} of the history"));
+ }
+ }
+ let on_the_fork = harness::version_event(&[Id::of(&root)], Id::of(b"a version"));
+ if matches!(whole.offer(on_the_fork), Offered::Taken(_)) {
+ return Err("the store it came from takes what builds on the fork".to_owned());
+ }
+ Ok(())
+ },
+ );
+}