use bitcoin_compat::*;
use bitcoin_imports::*;
#[traced_test]
fn verify_endian_roundtrips() {
let v16: u16 = 0x1234;
assert_eq!(be_16toh(htobe16(v16)), v16, "u16 BE round‑trip failed");
assert_eq!(le_16toh(htole16(v16)), v16, "u16 LE round‑trip failed");
let v32: u32 = 0x89ab_cdef;
assert_eq!(be_32toh(htobe32(v32)), v32, "u32 BE round‑trip failed");
assert_eq!(le_32toh(htole32(v32)), v32, "u32 LE round‑trip failed");
let v64: u64 = 0x0123_4567_89ab_cdef;
assert_eq!(be_64toh(htobe64(v64)), v64, "u64 BE round‑trip failed");
assert_eq!(le_64toh(htole64(v64)), v64, "u64 LE round‑trip failed");
}
#[traced_test]
fn verify_numeric_conversion() {
#[cfg(target_endian = "little")]
{
assert_eq!(htobe16(0x1234), 0x3412);
assert_eq!(htole16(0x1234), 0x1234);
}
#[cfg(target_endian = "big")]
{
assert_eq!(htobe16(0x1234), 0x1234);
assert_eq!(htole16(0x1234), 0x3412);
}
#[cfg(target_endian = "little")]
{
assert_eq!(htobe32(0x89ab_cdef), 0xefcd_ab89);
assert_eq!(htole32(0x89ab_cdef), 0x89ab_cdef);
}
#[cfg(target_endian = "big")]
{
assert_eq!(htobe32(0x89ab_cdef), 0x89ab_cdef);
assert_eq!(htole32(0x89ab_cdef), 0xefcd_ab89);
}
#[cfg(target_endian = "little")]
{
assert_eq!(htobe64(0x0123_4567_89ab_cdef), 0xefcd_ab89_6745_2301);
assert_eq!(htole64(0x0123_4567_89ab_cdef), 0x0123_4567_89ab_cdef);
}
#[cfg(target_endian = "big")]
{
assert_eq!(htobe64(0x0123_4567_89ab_cdef), 0x0123_4567_89ab_cdef);
assert_eq!(htole64(0x0123_4567_89ab_cdef), 0xefcd_ab89_6745_2301);
}
}