use super::*;
fn h(byte: u8) -> B256 {
B256::repeat_byte(byte)
}
#[test]
fn stale_client_beats_every_other_signal() {
assert_eq!(decide(true, true, h(0xAA), h(0xBB)), Decision::StaleClient);
assert_eq!(
decide(false, false, h(0xAA), h(0xBB)),
Decision::StaleClient
);
}
#[test]
fn matching_hash_with_flag_proceeds() {
assert_eq!(decide(true, true, h(0x11), h(0x11)), Decision::Proceed);
assert_eq!(decide(true, false, h(0x11), h(0x11)), Decision::Proceed);
}
#[test]
fn matching_hash_on_tty_without_flag_prompts() {
assert_eq!(decide(false, true, h(0x11), h(0x11)), Decision::Prompt);
}
#[test]
fn matching_hash_headless_without_flag_needs_flag() {
assert_eq!(decide(false, false, h(0x11), h(0x11)), Decision::NeedFlag);
}
#[test]
fn embedded_terms_hash_is_nonzero_and_versioned() {
assert_ne!(terms_hash(), B256::ZERO, "TERMS.md must embed and hash");
assert_ne!(
terms_version(),
"unknown",
"TERMS.md must carry a Version line"
);
}
#[test]
fn embedded_terms_hash_matches_committed_terms_md() {
let expected = alloy::primitives::b256!(
"7da33feb48d0b64ca41a4478ea67aeb13832b56b7598cca803bc2b9f5ec37f4b"
);
assert_eq!(
terms_hash(),
expected,
"TERMS.md changed — update this lock AND the network's currentTermsHash \
(governance setCurrentTermsHash + CURRENT_TERMS_HASH deploy value)"
);
}
#[test]
fn ensure_accepted_headless_requires_the_flag() {
assert!(ensure_accepted(terms_hash(), false).is_err());
}
#[test]
fn ensure_accepted_with_flag_and_matching_terms_ok() {
assert!(ensure_accepted(terms_hash(), true).is_ok());
}
#[test]
fn ensure_accepted_stale_terms_refused_even_with_flag() {
assert!(ensure_accepted(B256::repeat_byte(0x99), true).is_err());
}