use serde::{Deserialize, Serialize};
use std::collections::{BTreeSet, HashMap};
#[derive(Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)]
pub struct Place {
pub id: String,
}
impl Place {
pub fn new(id: impl Into<String>) -> Self {
Self { id: id.into() }
}
}
#[derive(Debug, Clone, Default, Eq, PartialEq, Serialize, Deserialize)]
pub struct Marking {
pub tokens: HashMap<String, Vec<String>>,
}
impl Marking {
pub fn new() -> Self {
Self::default()
}
pub fn with_token(mut self, color: &str, hash: &str) -> Self {
self.tokens
.entry(color.to_string())
.or_default()
.push(hash.to_string());
self
}
pub fn restrict(&self, colors: &BTreeSet<String>) -> Self {
let mut tokens = HashMap::new();
for color in colors {
if let Some(vals) = self.tokens.get(color) {
tokens.insert(color.clone(), vals.clone());
}
}
Self { tokens }
}
}
#[derive(Debug, Clone, Default, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct OpenSet {
pub places: BTreeSet<Place>,
}
impl OpenSet {
pub fn new() -> Self {
Self::default()
}
pub fn from_places<I: IntoIterator<Item = Place>>(places: I) -> Self {
Self {
places: places.into_iter().collect(),
}
}
pub fn intersection(&self, other: &OpenSet) -> OpenSet {
OpenSet {
places: self
.places
.intersection(&other.places)
.cloned()
.collect(),
}
}
pub fn is_disjoint(&self, other: &OpenSet) -> bool {
self.places.is_disjoint(&other.places)
}
pub fn is_subset(&self, other: &OpenSet) -> bool {
self.places.is_subset(&other.places)
}
pub fn is_empty(&self) -> bool {
self.places.is_empty()
}
pub fn colors(&self) -> BTreeSet<String> {
self.places.iter().map(|p| p.id.clone()).collect()
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Section {
pub open_set: OpenSet,
pub marking: Marking,
}
impl Section {
pub fn new(open_set: OpenSet, marking: Marking) -> Self {
Self { open_set, marking }
}
pub fn restrict(&self, subset: &OpenSet) -> Result<Section, CohomologyError> {
if !subset.is_subset(&self.open_set) {
return Err(CohomologyError::InvalidRestriction {
subset: subset.clone(),
superset: self.open_set.clone(),
});
}
let colors = subset.colors();
let marking = self.marking.restrict(&colors);
Ok(Section {
open_set: subset.clone(),
marking,
})
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Sheaf {
pub sections: HashMap<OpenSet, Section>,
}
impl Default for Sheaf {
fn default() -> Self {
Self::new()
}
}
impl Sheaf {
pub fn new() -> Self {
Self {
sections: HashMap::new(),
}
}
pub fn restriction(&self, section: &Section, subset: &OpenSet) -> Result<Section, CohomologyError> {
section.restrict(subset)
}
pub fn gluing_check(
&self,
local_sections: &[Section],
open_cover: &[OpenSet],
) -> Result<Section, CohomologyError> {
if local_sections.len() != open_cover.len() {
return Err(CohomologyError::InputMismatch);
}
if local_sections.is_empty() {
return Ok(Section::new(OpenSet::new(), Marking::new()));
}
let merkle_trees: Vec<MerkleNode> =
local_sections.iter().map(section_to_merkle).collect();
let n = local_sections.len();
for i in 0..n {
for j in (i + 1)..n {
let intersection = open_cover[i].intersection(&open_cover[j]);
if intersection.is_empty() {
continue;
}
let root_i = merkle_sub_root(&merkle_trees[i], &intersection.places);
let root_j = merkle_sub_root(&merkle_trees[j], &intersection.places);
if root_i != root_j {
let left = self.restriction(&local_sections[i], &intersection)?;
let right = self.restriction(&local_sections[j], &intersection)?;
return Err(CohomologyError::GluingFailure {
place_i: local_sections[i].open_set.places.iter().next().cloned().unwrap_or(Place::new("?")),
place_j: local_sections[j].open_set.places.iter().next().cloned().unwrap_or(Place::new("?")),
intersection: intersection.clone(),
expected_marking: left.marking,
actual_marking: right.marking,
cohomology_class: "[delta_s]".to_string(),
});
}
}
}
let mut union = OpenSet::new();
let mut marking = Marking::new();
for (section, cover) in local_sections.iter().zip(open_cover.iter()) {
union.places.extend(cover.places.iter().cloned());
for (color, vals) in §ion.marking.tokens {
marking.tokens.insert(color.clone(), vals.clone());
}
}
Ok(Section::new(union, marking))
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum CohomologyError {
InputMismatch,
InvalidRestriction { subset: OpenSet, superset: OpenSet },
GluingFailure {
place_i: Place,
place_j: Place,
intersection: OpenSet,
expected_marking: Marking,
actual_marking: Marking,
cohomology_class: String,
},
}
impl std::fmt::Display for CohomologyError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
CohomologyError::InputMismatch => write!(f, "open cover and local sections have different lengths"),
CohomologyError::InvalidRestriction { subset, superset } => {
write!(f, "cannot restrict {:?} to subset {:?}", superset, subset)
}
CohomologyError::GluingFailure { place_i, place_j, intersection, .. } => {
write!(
f,
"COHOMOLOGICAL OBSTRUCTION: Sections disagree on intersection of {:?} and {:?}: {:?}",
place_i.id, place_j.id, intersection
)
}
}
}
}
impl std::error::Error for CohomologyError {}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MerkleNode {
pub hash: [u8; 32],
pub children: Vec<MerkleNode>,
pub place_id: Option<String>,
pub payload: Option<Vec<u8>>,
}
pub fn compute_merkle_root(payload: &[u8]) -> [u8; 32] {
crate::hash::raw_hash_bytes_32(payload)
}
pub fn compute_merkle_node(children: &[MerkleNode]) -> [u8; 32] {
let mut combined = Vec::new();
for child in children {
combined.extend_from_slice(&child.hash);
}
crate::hash::raw_hash_bytes_32(&combined)
}
pub fn section_to_merkle(section: &Section) -> MerkleNode {
let mut leaves: Vec<MerkleNode> = section
.open_set
.places
.iter()
.map(|place| {
let tokens = section.marking.tokens.get(&place.id);
let payload = match tokens {
Some(vals) => format!("{}:{}", place.id, vals.join(",")),
None => place.id.clone(),
};
let hash = compute_merkle_root(payload.as_bytes());
MerkleNode {
hash,
children: vec![],
place_id: Some(place.id.clone()),
payload: Some(payload.into_bytes()),
}
})
.collect();
leaves.sort_by(|a, b| a.place_id.cmp(&b.place_id));
let root_hash = compute_merkle_node(&leaves);
MerkleNode {
hash: root_hash,
children: leaves,
place_id: None,
payload: None,
}
}
pub fn merkle_sub_root(node: &MerkleNode, places: &BTreeSet<Place>) -> [u8; 32] {
let place_ids: BTreeSet<String> = places.iter().map(|p| p.id.clone()).collect();
let matching: Vec<&MerkleNode> = node
.children
.iter()
.filter(|c| {
c.place_id
.as_ref()
.map(|id| place_ids.contains(id))
.unwrap_or(false)
})
.collect();
if matching.is_empty() {
return [0u8; 32];
}
let mut combined = Vec::new();
for child in &matching {
combined.extend_from_slice(&child.hash);
}
crate::hash::raw_hash_bytes_32(&combined)
}
#[cfg(feature = "native")]
pub fn store_section_merkle(
section: &Section,
conn: &rusqlite::Connection,
) -> Result<[u8; 32], String> {
let node = section_to_merkle(section);
let yaml = serde_yaml::to_string(section).map_err(|e| e.to_string())?;
let hash_hex = hex::encode(node.hash);
let now = chrono::Local::now()
.format("%Y-%m-%dT%H:%M:%S%z")
.to_string();
conn.execute(
"INSERT OR IGNORE INTO card (hash, content, g_time) VALUES (?, ?, ?)",
rusqlite::params![hash_hex, yaml, now],
)
.map_err(|e| e.to_string())?;
Ok(node.hash)
}
#[cfg(feature = "native")]
pub fn load_section_merkle(
hash: &[u8; 32],
conn: &rusqlite::Connection,
) -> Result<Section, String> {
let hash_hex = hex::encode(hash);
let content: String = conn
.query_row(
"SELECT content FROM card WHERE hash = ?",
[&hash_hex],
|row| row.get(0),
)
.map_err(|e| format!("Failed to load section: {}", e))?;
serde_yaml::from_str(&content).map_err(|e| format!("Failed to deserialize section: {}", e))
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CohomologyConflictReport {
pub conflicting_places: (Place, Place),
pub intersection: OpenSet,
pub expected_marking: Marking,
pub actual_marking: Marking,
pub cohomology_class: String,
pub timestamp: String,
pub agent_dids: Vec<String>,
}
impl CohomologyConflictReport {
pub fn to_yaml(&self) -> String {
serde_yaml::to_string(self).unwrap_or_else(|_| "cohomology_conflict: <error>".to_string())
}
pub fn content_hash(&self) -> String {
crate::hash::raw_hash_string(&self.to_yaml())
}
pub fn from_error(
err: &CohomologyError,
agent_dids: Vec<String>,
) -> Option<Self> {
match err {
CohomologyError::GluingFailure {
place_i,
place_j,
intersection,
expected_marking,
actual_marking,
cohomology_class,
} => Some(CohomologyConflictReport {
conflicting_places: (place_i.clone(), place_j.clone()),
intersection: intersection.clone(),
expected_marking: expected_marking.clone(),
actual_marking: actual_marking.clone(),
cohomology_class: cohomology_class.clone(),
timestamp: chrono::Utc::now().to_rfc3339(),
agent_dids,
}),
_ => None,
}
}
}
#[cfg(feature = "native")]
pub fn store_conflict_report(
report: &CohomologyConflictReport,
conn: &rusqlite::Connection,
) -> Result<String, String> {
let yaml = report.to_yaml();
let hash = report.content_hash();
let now = chrono::Local::now()
.format("%Y-%m-%dT%H:%M:%S%z")
.to_string();
conn.execute(
"INSERT OR IGNORE INTO card (hash, content, g_time) VALUES (?, ?, ?)",
rusqlite::params![hash, yaml, now],
)
.map_err(|e| e.to_string())?;
Ok(hash)
}
#[cfg(test)]
mod tests {
use super::*;
#[cfg_attr(not(target_arch = "wasm32"), test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
fn test_disjoint_places_glue() {
let sheaf = Sheaf::new();
let s1 = Section::new(
OpenSet::from_places([Place::new("a")]),
Marking::new().with_token("a", "hash-a"),
);
let s2 = Section::new(
OpenSet::from_places([Place::new("b")]),
Marking::new().with_token("b", "hash-b"),
);
let global = sheaf.gluing_check(&[s1, s2], &[OpenSet::from_places([Place::new("a")]), OpenSet::from_places([Place::new("b")])]).unwrap();
assert_eq!(global.open_set.places.len(), 2);
}
#[cfg_attr(not(target_arch = "wasm32"), test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
fn test_overlapping_matching_restrictions_glue() {
let sheaf = Sheaf::new();
let _shared = OpenSet::from_places([Place::new("shared")]);
let s1 = Section::new(
OpenSet::from_places([Place::new("shared"), Place::new("a")]),
Marking::new().with_token("shared", "hash-s").with_token("a", "hash-a"),
);
let s2 = Section::new(
OpenSet::from_places([Place::new("shared"), Place::new("b")]),
Marking::new().with_token("shared", "hash-s").with_token("b", "hash-b"),
);
let global = sheaf.gluing_check(&[s1, s2], &[OpenSet::from_places([Place::new("shared"), Place::new("a")]), OpenSet::from_places([Place::new("shared"), Place::new("b")])]).unwrap();
assert!(global.open_set.places.contains(&Place::new("shared")));
}
#[cfg_attr(not(target_arch = "wasm32"), test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
fn test_overlapping_mismatched_restrictions_fail() {
let sheaf = Sheaf::new();
let s1 = Section::new(
OpenSet::from_places([Place::new("shared"), Place::new("a")]),
Marking::new().with_token("shared", "hash-s1"),
);
let s2 = Section::new(
OpenSet::from_places([Place::new("shared"), Place::new("b")]),
Marking::new().with_token("shared", "hash-s2"),
);
let result = sheaf.gluing_check(&[s1, s2], &[OpenSet::from_places([Place::new("shared"), Place::new("a")]), OpenSet::from_places([Place::new("shared"), Place::new("b")])]);
assert!(result.is_err());
let err = result.unwrap_err();
assert!(err.to_string().contains("COHOMOLOGICAL OBSTRUCTION"));
}
#[cfg_attr(not(target_arch = "wasm32"), test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
fn test_three_section_cover_glue() {
let sheaf = Sheaf::new();
let cover = [
OpenSet::from_places([Place::new("a"), Place::new("b")]),
OpenSet::from_places([Place::new("b"), Place::new("c")]),
OpenSet::from_places([Place::new("c"), Place::new("d")]),
];
let s1 = Section::new(cover[0].clone(), Marking::new().with_token("a", "h").with_token("b", "h"));
let s2 = Section::new(cover[1].clone(), Marking::new().with_token("b", "h").with_token("c", "h"));
let s3 = Section::new(cover[2].clone(), Marking::new().with_token("c", "h").with_token("d", "h"));
let global = sheaf.gluing_check(&[s1, s2, s3], &cover).unwrap();
assert_eq!(global.open_set.places.len(), 4);
}
#[cfg_attr(not(target_arch = "wasm32"), test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
fn test_three_sections_one_conflict() {
let sheaf = Sheaf::new();
let cover = [
OpenSet::from_places([Place::new("a"), Place::new("b")]),
OpenSet::from_places([Place::new("b"), Place::new("c")]),
OpenSet::from_places([Place::new("c"), Place::new("d")]),
];
let s1 = Section::new(cover[0].clone(), Marking::new().with_token("a", "h").with_token("b", "h1"));
let s2 = Section::new(cover[1].clone(), Marking::new().with_token("b", "h2").with_token("c", "h"));
let s3 = Section::new(cover[2].clone(), Marking::new().with_token("c", "h").with_token("d", "h"));
let result = sheaf.gluing_check(&[s1, s2, s3], &cover);
assert!(result.is_err());
}
#[cfg_attr(not(target_arch = "wasm32"), test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
fn test_open_set_operations() {
let a = OpenSet::from_places([Place::new("x"), Place::new("y")]);
let b = OpenSet::from_places([Place::new("y"), Place::new("z")]);
assert!(!a.is_disjoint(&b));
let inter = a.intersection(&b);
assert_eq!(inter.places, [Place::new("y")].iter().cloned().collect());
assert!(OpenSet::from_places([Place::new("y")]).is_subset(&a));
}
#[cfg_attr(not(target_arch = "wasm32"), test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
fn test_identical_sections_produce_identical_merkle_roots() {
let s1 = Section::new(
OpenSet::from_places([Place::new("a"), Place::new("b")]),
Marking::new().with_token("a", "h1").with_token("b", "h2"),
);
let s2 = Section::new(
OpenSet::from_places([Place::new("a"), Place::new("b")]),
Marking::new().with_token("a", "h1").with_token("b", "h2"),
);
let m1 = section_to_merkle(&s1);
let m2 = section_to_merkle(&s2);
assert_eq!(m1.hash, m2.hash);
}
#[cfg_attr(not(target_arch = "wasm32"), test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
fn test_different_sections_produce_different_merkle_roots() {
let s1 = Section::new(
OpenSet::from_places([Place::new("a"), Place::new("b")]),
Marking::new().with_token("a", "h1").with_token("b", "h2"),
);
let s2 = Section::new(
OpenSet::from_places([Place::new("a"), Place::new("b")]),
Marking::new().with_token("a", "h1").with_token("b", "h3"),
);
let m1 = section_to_merkle(&s1);
let m2 = section_to_merkle(&s2);
assert_ne!(m1.hash, m2.hash);
}
#[cfg_attr(not(target_arch = "wasm32"), test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
fn test_merkle_sub_root_detects_same_conflicts() {
let sheaf = Sheaf::new();
let s1 = Section::new(
OpenSet::from_places([Place::new("shared"), Place::new("a")]),
Marking::new().with_token("shared", "hash-s1"),
);
let s2 = Section::new(
OpenSet::from_places([Place::new("shared"), Place::new("b")]),
Marking::new().with_token("shared", "hash-s2"),
);
let cover = [
OpenSet::from_places([Place::new("shared"), Place::new("a")]),
OpenSet::from_places([Place::new("shared"), Place::new("b")]),
];
let result = sheaf.gluing_check(&[s1, s2], &cover);
assert!(result.is_err());
let err = result.unwrap_err();
assert!(err.to_string().contains("COHOMOLOGICAL OBSTRUCTION"));
}
#[cfg_attr(not(target_arch = "wasm32"), test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
fn test_merkle_sub_root_matching_sections_pass() {
let sheaf = Sheaf::new();
let s1 = Section::new(
OpenSet::from_places([Place::new("shared"), Place::new("a")]),
Marking::new().with_token("shared", "hash-s").with_token("a", "hash-a"),
);
let s2 = Section::new(
OpenSet::from_places([Place::new("shared"), Place::new("b")]),
Marking::new().with_token("shared", "hash-s").with_token("b", "hash-b"),
);
let cover = [
OpenSet::from_places([Place::new("shared"), Place::new("a")]),
OpenSet::from_places([Place::new("shared"), Place::new("b")]),
];
let result = sheaf.gluing_check(&[s1, s2], &cover);
assert!(result.is_ok());
}
#[cfg_attr(not(target_arch = "wasm32"), test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
fn test_conflict_report_from_gluing_failure() {
let sheaf = Sheaf::new();
let s1 = Section::new(
OpenSet::from_places([Place::new("shared"), Place::new("a")]),
Marking::new().with_token("shared", "hash-s1"),
);
let s2 = Section::new(
OpenSet::from_places([Place::new("shared"), Place::new("b")]),
Marking::new().with_token("shared", "hash-s2"),
);
let cover = [
OpenSet::from_places([Place::new("shared"), Place::new("a")]),
OpenSet::from_places([Place::new("shared"), Place::new("b")]),
];
let err = sheaf.gluing_check(&[s1, s2], &cover).unwrap_err();
let report = CohomologyConflictReport::from_error(
&err,
vec!["did:key:agent1".to_string(), "did:key:agent2".to_string()],
);
assert!(report.is_some());
let r = report.unwrap();
assert_eq!(r.expected_marking.tokens.get("shared"), Some(&vec!["hash-s1".to_string()]));
assert_eq!(r.actual_marking.tokens.get("shared"), Some(&vec!["hash-s2".to_string()]));
assert_eq!(r.cohomology_class, "[delta_s]");
assert_eq!(r.agent_dids.len(), 2);
}
#[cfg_attr(not(target_arch = "wasm32"), test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
fn test_conflict_report_yaml_serialization() {
let report = CohomologyConflictReport {
conflicting_places: (Place::new("a"), Place::new("b")),
intersection: OpenSet::from_places([Place::new("shared")]),
expected_marking: Marking::new().with_token("shared", "h1"),
actual_marking: Marking::new().with_token("shared", "h2"),
cohomology_class: "[delta_s]".to_string(),
timestamp: "2026-01-01T00:00:00Z".to_string(),
agent_dids: vec!["did:key:a1".to_string()],
};
let yaml = report.to_yaml();
assert!(yaml.contains("cohomology_class"));
assert!(yaml.contains("[delta_s]"));
assert!(yaml.contains("conflicting_places"));
let hash1 = report.content_hash();
let hash2 = report.content_hash();
assert_eq!(hash1, hash2);
}
#[cfg_attr(not(target_arch = "wasm32"), test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
fn test_conflict_report_deterministic_hash() {
let make_report = || CohomologyConflictReport {
conflicting_places: (Place::new("x"), Place::new("y")),
intersection: OpenSet::from_places([Place::new("z")]),
expected_marking: Marking::new().with_token("z", "h1"),
actual_marking: Marking::new().with_token("z", "h2"),
cohomology_class: "[delta_s]".to_string(),
timestamp: "2026-01-01T00:00:00Z".to_string(),
agent_dids: vec!["did:key:a".to_string()],
};
let r1 = make_report();
let r2 = make_report();
assert_eq!(r1.content_hash(), r2.content_hash());
}
#[cfg_attr(not(target_arch = "wasm32"), test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
fn test_benchmark_gluing_check_100_places_200_overlaps() {
let sheaf = Sheaf::new();
let mut sections = Vec::new();
let mut cover = Vec::new();
for i in 0..100 {
let p1 = format!("p{}", i);
let p2 = format!("p{}", (i + 1) % 100);
let os = OpenSet::from_places([Place::new(&p1), Place::new(&p2)]);
let marking = Marking::new()
.with_token(&p1, &format!("h{}", i))
.with_token(&p2, &format!("h{}", i));
sections.push(Section::new(os.clone(), marking));
cover.push(os);
}
let start = std::time::Instant::now();
let result = sheaf.gluing_check(§ions, &cover);
let elapsed = start.elapsed();
let _ = result;
assert!(
elapsed.as_millis() < 100,
"gluing_check took {}ms, expected < 100ms",
elapsed.as_millis()
);
}
#[cfg(feature = "native")]
#[test]
fn test_store_and_load_section_merkle() {
let conn = rusqlite::Connection::open_in_memory().unwrap();
conn.execute(
"CREATE TABLE card (hash TEXT PRIMARY KEY, content TEXT, g_time TEXT)",
[],
)
.unwrap();
let section = Section::new(
OpenSet::from_places([Place::new("a"), Place::new("b")]),
Marking::new().with_token("a", "h1").with_token("b", "h2"),
);
let hash = store_section_merkle(§ion, &conn).unwrap();
let loaded = load_section_merkle(&hash, &conn).unwrap();
assert_eq!(loaded.open_set, section.open_set);
assert_eq!(loaded.marking, section.marking);
}
#[cfg(feature = "native")]
#[test]
fn test_store_conflict_report_in_db() {
let conn = rusqlite::Connection::open_in_memory().unwrap();
conn.execute(
"CREATE TABLE card (hash TEXT PRIMARY KEY, content TEXT, g_time TEXT)",
[],
)
.unwrap();
let report = CohomologyConflictReport {
conflicting_places: (Place::new("a"), Place::new("b")),
intersection: OpenSet::from_places([Place::new("shared")]),
expected_marking: Marking::new().with_token("shared", "h1"),
actual_marking: Marking::new().with_token("shared", "h2"),
cohomology_class: "[delta_s]".to_string(),
timestamp: "2026-01-01T00:00:00Z".to_string(),
agent_dids: vec!["did:key:a1".to_string(), "did:key:a2".to_string()],
};
let hash = store_conflict_report(&report, &conn).unwrap();
let content: String = conn
.query_row(
"SELECT content FROM card WHERE hash = ?",
[&hash],
|row| row.get(0),
)
.unwrap();
assert!(content.contains("cohomology_class"));
assert!(content.contains("[delta_s]"));
assert!(content.contains("did:key:a1"));
}
}