Mercurial > core / rust/lib/hash/src/tests.rs
changeset 698: |
96958d3eb5b0 |
parent: |
0ccbbd142694
|
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Fri, 04 Oct 2024 22:04:59 -0400 |
permissions: |
-rw-r--r-- |
description: |
fixes |
3 use std::convert::TryInto; 6 fn hex_hash() -> Result<(), Box<dyn std::error::Error>> { 7 let mut hasher1 = B3Hasher::new(); 8 hasher1.update(b"foo"); 9 hasher1.update(b"bar"); 10 hasher1.update(b"baz"); 11 let out1 = hasher1.finalize(); 12 let mut xof1 = [0; 301]; 13 hasher1.finalize_xof().fill(&mut xof1); 14 assert_eq!(out1.as_bytes(), &xof1[..32]); 17 "d74981efa70a0c880b8d8c1985d075dbcbf679b99a5f9914e5aaf96b831a9e24"; 18 let hash_bytes = decode(hash_hex).unwrap(); 19 let hash_array: [u8; OUT_LEN] = hash_bytes[..].try_into().unwrap(); 20 let _: B3Hash = hash_array.into(); 26 let id = Id(vec![0; crate::KEY_LEN]); 27 let hash = id.state_hash(&mut crate::B3Hasher::new()); 28 assert_eq!(hash, id.state_hash(&mut crate::B3Hasher::new())); 33 let id = crate::Id(vec![255; crate::KEY_LEN]); 37 "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" 46 let id = crate::Id::rand(); 47 let hash = id.state_hash(&mut crate::B3Hasher::new()); 48 assert_eq!(hash, id.state_hash(&mut crate::B3Hasher::new())); 52 fn random_demon_id_is_valid() { 55 let did = PeerId::rand(); 56 let did2 = PeerId::rand(); 58 assert_ne!(did, did2);