Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aien-protocols-mv/blob/main/crates/aien-discovery-capsule/tests/vectors.rs # aien-protocols-mv Canonical specifications, wire protocols, and schemas for the AIEN sovereign ecosystem Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aien-protocols-mv / crates / aien-discovery-capsule / tests / vectors.rs` 56 lines ยท 1852 bytes Raw Blame History 1 //! Walks `specs/discovery-capsule/vectors/expected.txt` and requires the Rust reader to 2 //! print the same verdict line as the C reference checker 3 //! (`tools/dcp_verify.c`) for every file, and to write every accepted record 4 //! back out as the identical bytes. 5 6 use std::path::PathBuf; 7 8 use aien_discovery_capsule::{decode, verdict_line}; 9 10 fn vectors_dir() -> PathBuf { 11 PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../specs/discovery-capsule/vectors") 12 } 13 14 #[test] 15 fn every_expected_line_matches_the_c_checker() { 16 let dir = vectors_dir(); 17 let list = std::fs::read_to_string(dir.join("expected.txt")).expect("read expected.txt"); 18 let mut checked = 0usize; 19 let mut accepted = 0usize; 20 let mut failures = Vec::new(); 21 for line in list.lines() { 22 if line.is_empty() || line.starts_with('#') { 23 continue; 24 } 25 let (name, want) = line 26 .split_once(' ') 27 .expect("line has a file name and a verdict"); 28 let bytes = std::fs::read(dir.join(name)).expect("read vector"); 29 let got = verdict_line(&bytes); 30 if got != want { 31 failures.push(format!("{name}\n expected: {want}\n got: {got}")); 32 } 33 if let Ok(record) = decode(&bytes) { 34 let again = record.encode(); 35 if again != bytes { 36 failures.push(format!("{name}: round trip gave different bytes")); 37 } 38 accepted += 1; 39 } 40 checked += 1; 41 } 42 assert!( 43 failures.is_empty(), 44 "{} of {checked} vectors differ:\n{}", 45 failures.len(), 46 failures.join("\n") 47 ); 48 assert!( 49 checked >= 90, 50 "expected at least 90 vectors, found {checked}" 51 ); 52 assert!( 53 accepted >= 13, 54 "expected at least 13 accepted vectors, found {accepted}" 55 ); 56 }