Files
arcanum/tests/common/mod.rs
T

26 lines
827 B
Rust

//! Helpers shared by the integration tests. Test fixtures only: no real keys, no network.
#![allow(dead_code)]
use chacha20::ChaCha20Rng;
use rand_core::SeedableRng;
use sha2::{Digest, Sha256};
/// A deterministic RNG for tests. Never used outside tests.
pub fn rng(label: u8) -> ChaCha20Rng {
ChaCha20Rng::from_seed([label; 32])
}
pub fn hex(s: &str) -> Vec<u8> {
hex::decode(s).expect("vector hex")
}
pub fn arr<const N: usize>(s: &str) -> [u8; N] {
hex(s).try_into().expect("vector length")
}
/// Fail loudly if a pinned vector file is not the one recorded in tests/vectors/SOURCES.md.
pub fn assert_sha256(bytes: &[u8], expected_hex: &str, name: &str) {
let got = hex::encode(Sha256::digest(bytes));
assert_eq!(got, expected_hex, "{name} is not the pinned file (see tests/vectors/SOURCES.md)");
}