File size: 1,856 Bytes
1d3f990 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | //! Proof event schemas for audit trail
use serde::{Deserialize, Serialize};
/// Proof events for Bifrost audit chain
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ProofEvent {
/// Proof successfully validated
Validated {
mutation: String,
},
/// Proof validation failed
Violated {
mutation: String,
error: String,
violation_id: u64,
},
/// Rollback executed
RolledBack {
checkpoint: String,
violation_id: u64,
},
}
/// Violation record
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ViolationEvent {
pub violation_id: u64,
pub timestamp: u64,
pub address: usize,
pub old_value: i64,
pub new_value: i64,
pub reason: String,
pub checkpoint_id: Option<String>,
}
impl ProofEvent {
pub fn to_json(&self) -> serde_json::Value {
serde_json::to_value(self).unwrap_or(serde_json::json!({}))
}
}
impl ViolationEvent {
pub fn to_json(&self) -> serde_json::Value {
serde_json::to_value(self).unwrap_or(serde_json::json!({}))
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_proof_event_serialization() {
let event = ProofEvent::Validated {
mutation: "M[0] ← 42".into(),
};
let json = event.to_json();
assert!(json.is_object());
}
#[test]
fn test_violation_event() {
let event = ViolationEvent {
violation_id: 1,
timestamp: 0,
address: 0,
old_value: 5,
new_value: 10,
reason: "invariant_breach".into(),
checkpoint_id: Some("cp1".into()),
};
let json = event.to_json();
assert!(json["violation_id"].is_number());
}
}
|