MCPcopy Create free account
hub / github.com/BitVM/BitVM / test_official_test_vectors_with_limbs

Function test_official_test_vectors_with_limbs

bitvm/src/hash/blake3.rs:508–546  ·  view source on GitHub ↗
(limb_lens: &[u8])

Source from the content-addressed store, hash-verified

506 }
507
508 fn test_official_test_vectors_with_limbs(limb_lens: &[u8]) {
509 use serde::Deserialize;
510 use std::fs::File;
511 use std::io::BufReader;
512
513 #[derive(Debug, Deserialize)]
514 struct TestVectors {
515 cases: Vec<TestVector>,
516 }
517
518 #[derive(Debug, Deserialize)]
519 struct TestVector {
520 input_len: usize,
521 hash: String,
522 }
523
524 fn read_test_vectors() -> Vec<(Vec<u8>, [u8; 32])> {
525 let path = "src/hash/blake3_official_test_vectors.json";
526 let file = File::open(path).unwrap();
527 let reader = BufReader::new(file);
528
529 let test_vectors: TestVectors = serde_json::from_reader(reader).unwrap();
530 test_vectors
531 .cases
532 .iter()
533 .filter(|vector| vector.input_len <= 1024)
534 .map(|vector| {
535 let message = (0..251u8).cycle().take(vector.input_len).collect();
536 let expected_hash = <[u8; 32]>::from_hex(&vector.hash[0..64]).unwrap();
537 (message, expected_hash)
538 })
539 .collect()
540 }
541
542 let test_vectors = read_test_vectors();
543 for (message, expected_hash) in test_vectors {
544 verify_blake_output_with_limbs(&message, expected_hash, limb_lens);
545 }
546 }
547
548 #[test]
549 fn test_official_test_vectors() {

Calls 2

read_test_vectorsFunction · 0.85

Tested by

no test coverage detected