From 313e036c15df3468cb3568df98ee980740cd9929 Mon Sep 17 00:00:00 2001 From: mfw78 Date: Fri, 24 Jul 2026 00:25:54 +0000 Subject: [PATCH] test: round-trip the no_std IntentBody derive probe --- crates/no-std-probe/src/lib.rs | 37 ++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/crates/no-std-probe/src/lib.rs b/crates/no-std-probe/src/lib.rs index fd455704..89603613 100644 --- a/crates/no-std-probe/src/lib.rs +++ b/crates/no-std-probe/src/lib.rs @@ -1,5 +1,10 @@ -//! Compile-only `#![no_std]` probe: `#[derive(IntentBody)]` must expand -//! without the consumer's std prelude or an `extern crate alloc`. +//! `no_std` derive-hygiene probe for `#[derive(IntentBody)]`. The claim +//! is scoped to the derive, not the whole SDK: the expansion names only +//! `::core` and the SDK's `__private` re-exports (borsh, `alloc`), so it +//! compiles without the consumer's std prelude or an `extern crate +//! alloc`. The crate is `#![no_std]`; the `tests` module (std-exempt) +//! exercises an actual encode/decode round-trip, so the generated codec +//! is verified correct, not merely expanded. #![no_std] #![warn(missing_docs)] @@ -12,3 +17,31 @@ pub enum ProbeBody { /// First published version. V1(u8), } + +#[cfg(test)] +mod tests { + use super::*; + use videre_sdk::BodyError; + + #[test] + fn round_trip() { + let body = ProbeBody::V1(7); + let bytes = body.to_bytes().expect("encode"); + // One-byte version tag (0) then the borsh u8 payload. + assert_eq!(bytes, [0u8, 7u8]); + assert_eq!(ProbeBody::from_bytes(&bytes).expect("decode"), body); + } + + #[test] + fn unknown_version() { + assert!(matches!( + ProbeBody::from_bytes(&[9, 7]), + Err(BodyError::UnknownVersion { version: 9 }), + )); + } + + #[test] + fn empty() { + assert!(matches!(ProbeBody::from_bytes(&[]), Err(BodyError::Empty))); + } +}