1#![no_std]
2#![doc = "Causal operation model types for BCX."]
3
4mod event;
5mod truth;
6
7pub use event::{
8 AdmissionResult, CauseCapsule, CauseCapsuleParts, CauseKind, EffectResult, OperationAction,
9 RelationshipKind,
10};
11pub use truth::{AssuranceLevel, TruthStatus};
12
13#[cfg(test)]
14mod tests {
15 use super::*;
16 use bcx_core::{Digest, EventId, ValidationError};
17 use bcx_wire::WireLimits;
18
19 fn event(byte: u8) -> Result<EventId, ValidationError> {
20 EventId::new(Digest::new([byte; Digest::LEN]))
21 }
22
23 #[test]
24 fn cause_capsule_rejects_empty_parents() -> Result<(), ValidationError> {
25 assert_eq!(
26 CauseCapsule::new(
27 CauseCapsuleParts {
28 event_id: event(1)?,
29 parents: &[],
30 relationship: RelationshipKind::CausedBy,
31 cause_kind: CauseKind::ApplicationAction,
32 action: OperationAction::Execute,
33 authority: None,
34 policy_epoch: None,
35 },
36 WireLimits::DEVELOPMENT,
37 ),
38 Err(ValidationError::Empty)
39 );
40 Ok(())
41 }
42
43 #[test]
44 fn cause_capsule_rejects_too_many_parents() -> Result<(), ValidationError> {
45 let parents = [event(2)?, event(3)?];
46 let limits = WireLimits::new(1, 1, 1, 1)?;
47
48 assert_eq!(
49 CauseCapsule::new(
50 CauseCapsuleParts {
51 event_id: event(1)?,
52 parents: &parents,
53 relationship: RelationshipKind::JoinedFrom,
54 cause_kind: CauseKind::ApplicationAction,
55 action: OperationAction::Execute,
56 authority: None,
57 policy_epoch: None,
58 },
59 limits,
60 ),
61 Err(ValidationError::TooLarge)
62 );
63 Ok(())
64 }
65}