use wasm4pm_compat::receipt::{
Digest, ReceiptChainConst, ReceiptEnvelope, ReceiptRefusal, ReplayHint,
};
fn envelope(subject: &str) -> ReceiptEnvelope {
ReceiptEnvelope::new(subject, "witness", Digest::new("d"), ReplayHint::new("h"))
}
#[test]
fn valid_two_link_chain_exposes_arity_root_tip_iter() {
let a = envelope("root");
let b = envelope("step");
let chain =
ReceiptChainConst::try_new("run-001", [a, b]).expect("two well-shaped links seed a chain");
assert_eq!(chain.arity(), 2, "const arity reflects the array length");
assert_eq!(chain.root().subject, "root", "root is the first link");
assert_eq!(chain.tip().subject, "step", "tip is the last link");
assert_eq!(chain.iter().count(), 2, "iter walks every link");
}
#[test]
fn empty_chain_is_refused_at_zero_arity() {
let empty: [ReceiptEnvelope; 0] = [];
let result = ReceiptChainConst::try_new("run-x", empty);
assert_eq!(
result,
Err(ReceiptRefusal::EmptyChain),
"a zero-arity chain is refused by name"
);
}
#[test]
fn ill_shaped_link_is_refused_by_index() {
let broken = ReceiptEnvelope::new("", "witness", Digest::new("d"), ReplayHint::new("h"));
assert!(
!broken.is_well_shaped(),
"the empty-subject envelope is genuinely ill-shaped"
);
let result = ReceiptChainConst::try_new("run-x", [broken]);
assert_eq!(
result,
Err(ReceiptRefusal::BrokenChainLink(0)),
"the first ill-shaped link is refused at index 0",
);
}