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.rs33
1 files changed, 21 insertions, 12 deletions
diff --git a/src/federation/properties.rs b/src/federation/properties.rs
index 214bb27..b45b664 100644
--- a/src/federation/properties.rs
+++ b/src/federation/properties.rs
@@ -17,7 +17,7 @@ use super::harness::{self, Party, Spec};
use super::held::Holding;
use super::jcs::Json;
use super::model::{Model, Verdict};
-use super::revision::Feature;
+use super::revision::{Feature, Revision};
use super::store::memory::{Offered, Refusal, Store};
use super::store::{Fold, Id};
use super::version::Version;
@@ -30,9 +30,9 @@ const MOST: usize = 30;
/// A root, and events in the order written.
#[derive(Clone)]
-struct History {
- root: Vec<u8>,
- events: Vec<Vec<u8>>,
+pub(super) struct History {
+ pub(super) root: Vec<u8>,
+ pub(super) events: Vec<Vec<u8>>,
}
impl History {
@@ -87,11 +87,11 @@ impl History {
/// How a history is written: whether an adversary takes part, whether versions name
/// checkpoints, and whether parties propose versions this continuum doesn't read, at
/// which a store stops, which events then take in the order they come.
-#[derive(Clone, Copy)]
-struct Kind {
- adversary: bool,
- checkpoints: bool,
- unread: bool,
+#[derive(Clone, Copy, Debug)]
+pub(super) struct Kind {
+ pub(super) adversary: bool,
+ pub(super) checkpoints: bool,
+ pub(super) unread: bool,
}
/// One of `ids`, of the latest five more often than not.
@@ -104,6 +104,12 @@ fn pick(rng: &mut Rng, ids: &[Id]) -> Id {
}
fn generate(rng: &mut Rng, kind: Kind) -> History {
+ generate_at(rng, kind, None)
+}
+
+/// A history of `kind`, its first version following `revision`, or, where none is given,
+/// the base revision or one with merge events alike.
+pub(super) fn generate_at(rng: &mut Rng, kind: Kind, revision: Option<Revision>) -> History {
let count = rng.between(3, 5);
let parties: Vec<Party> = (0..count)
.map(|i| Party::new(&format!("p{i}"), i as u8 + 1))
@@ -112,9 +118,12 @@ fn generate(rng: &mut Rng, kind: Kind) -> History {
let refs: Vec<&Party> = parties.iter().collect();
let mut first = Spec::first(&refs, &[("names/{party}", harness::str("{party}"))]);
// Half the federations begin at a revision with merge events, which nodes then sign.
- if rng.chance(0.5) {
- first.revision = Feature::MergeEvents.revision();
- }
+ let merging = rng.chance(0.5);
+ first.revision = revision.unwrap_or(if merging {
+ Feature::MergeEvents.revision()
+ } else {
+ Revision::default()
+ });
let root = first.root();
let root_id = Id::of(&root);
let mut world: Store<Federation> = Store::new(root.clone(), Vec::new()).expect("a root");