minerva 0.2.0

Causal ordering for distributed systems
extern crate alloc;

use alloc::vec::Vec;

use crate::metis::DotSet;

use super::super::editor::{Replica, gossip_text};
use super::{split_two, type_run};

#[test]
fn test_wire_round_trip_of_a_session_snapshot() {
    // Multi-station contexts survive the have-set wire frame byte-identically
    // after concurrent typing, partial gossip, and deletes.
    let roster = [1u32, 2u32, 3u32];
    let mut replicas: Vec<Replica> = roster.iter().map(|&s| Replica::new(s, &roster)).collect();

    for replica in &mut replicas {
        let _ = type_run(replica, "abcdef", None);
    }
    for i in 0..replicas.len() - 1 {
        let (from, into) = split_two(&mut replicas, i, i + 1);
        gossip_text(from, into);
    }
    let order0 = replicas[0].order();
    if order0.len() >= 2 {
        replicas[0].delete(order0[0]);
        replicas[0].delete(order0[1]);
    }

    for r in &replicas {
        let context = r.text_context();
        let bytes = context.to_bytes();
        let decoded = DotSet::from_bytes(&bytes).expect("a canonical frame decodes");
        assert_eq!(&decoded, context, "context survives the wire byte-for-byte");
        assert_eq!(decoded.to_bytes(), bytes);
    }
}