diff --git a/Cargo.lock b/Cargo.lock index 6c49da8..926a003 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -143,10 +143,10 @@ dependencies = [ "rand_chacha 0.3.1", "rand_core 0.6.4", "reqwest", + "rng-statistical-tests", "serde", "serde_json", "sha2", - "testu01-runner", "thiserror 1.0.69", "zeroize", ] @@ -185,7 +185,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -909,6 +909,16 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "rng-statistical-tests" +version = "0.1.0" +source = "git+https://github.com/spacecomputer-io/statistical-verification.git#fd16ef0da4c74ed5e704e98a47d581e61a06ef71" +dependencies = [ + "bindgen", + "once_cell", + "rand_core 0.6.4", +] + [[package]] name = "rustc-hash" version = "1.1.0" @@ -1118,16 +1128,6 @@ dependencies = [ "syn", ] -[[package]] -name = "testu01-runner" -version = "0.1.0" -source = "git+https://github.com/spacecomputer-io/statistical-verification.git#2588081a7115db21fa595abf79395be76c8eb418" -dependencies = [ - "bindgen", - "once_cell", - "rand_core 0.6.4", -] - [[package]] name = "thiserror" version = "1.0.69" diff --git a/Cargo.toml b/Cargo.toml index af4a4a0..b2877de 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ hex = "0.4" [features] default = [] testu01 = [] +practrand = [] [dev-dependencies] -testu01-runner = { git = "https://github.com/spacecomputer-io/statistical-verification.git" } +rng-statistical-tests = { git = "https://github.com/spacecomputer-io/statistical-verification.git" } diff --git a/README.md b/README.md index 7807308..7c86ae4 100644 --- a/README.md +++ b/README.md @@ -134,42 +134,30 @@ cargo test --test e2e_ipfs cargo test --test e2e_mixed ``` -### TestU01 statistical runner +To run the IPFS-backed end-to-end tests : -Statistical testing is provided by the separate [`testu01-runner`](https://github.com/spacecomputer-io/statistical-verification) library. +```bash +cargo test test_e2e +``` -To use it, add to your `Cargo.toml`: +You can also run the dedicated e2e integration targets individually: -```toml -[dependencies] -testu01-runner = { git = "https://github.com/spacecomputer-io/statistical-verification.git" } -crypto-ctrng = { git = "https://github.com/spacecomputer-io/crypto-ctrng.git" } +```bash +cargo test --test e2e_ipfs +cargo test --test e2e_mixed ``` -TestU01 is automatically downloaded and built during compilation - no manual setup required. +### Statistical verification -To run TestU01 statistical tests: +Statistical testing is provided by the separate [`rng-statistical-tests`](https://github.com/spacecomputer-io/statistical-verification) library, which supports both **TestU01** and **PractRand**. -```bash -cargo test --features testu01 -``` +TestU01 and PractRand are automatically downloaded and built during compilation - no manual setup required. -Example usage: +To run statistical tests: -```rust -use rand_chacha::ChaCha20Rng; -use rand_core::SeedableRng; -use testu01_runner::{bbattery_BigCrush, register_rng, make_unif01_gen, delete_unif01_gen}; - -let seed = [0u8; 32]; -let rng = ChaCha20Rng::from_seed(seed); -register_rng(rng); - -unsafe { - let gen = make_unif01_gen("crypto-ctrng"); - bbattery_BigCrush(gen); - delete_unif01_gen(gen); -} +```bash +cargo test --features testu01 # TestU01 SmallCrush +cargo test --features practrand # PractRand (1 MiB) ``` diff --git a/tests/testu01_tests.rs b/tests/testu01_tests.rs index 62f900d..8d1caa8 100644 --- a/tests/testu01_tests.rs +++ b/tests/testu01_tests.rs @@ -5,9 +5,9 @@ use rand_chacha::ChaCha20Rng; #[cfg(feature = "testu01")] use rand_core::SeedableRng; #[cfg(feature = "testu01")] -use testu01_runner::bbattery_SmallCrush; -#[cfg(feature = "testu01")] -use testu01_runner::{delete_unif01_gen, make_unif01_gen, register_rng}; +use rng_statistical_tests::testu01::{ + bbattery_SmallCrush, delete_unif01_gen, make_unif01_gen, register_rng, +}; #[cfg(feature = "testu01")] fn build_ipfs_seeded_rng() -> ChaCha20Rng { @@ -20,18 +20,39 @@ fn build_ipfs_seeded_rng() -> ChaCha20Rng { #[test] #[cfg(feature = "testu01")] -fn test_ctrng_rng_smallcrush() { +fn testu01_smallcrush() { let rng = build_ipfs_seeded_rng(); register_rng(rng); unsafe { let generator = make_unif01_gen("crypto-ctrng-deterministic"); - println!("=== SmallCrush ==="); bbattery_SmallCrush(generator); - delete_unif01_gen(generator); } } -// Crush and BigCrush tests removed - TestU01 only allows one external generator at a time +#[test] +#[cfg(feature = "practrand")] +fn practrand_ctrng_seeded() { + use crypto_ctrng::{Ctrng, RandomBlockSource}; + use rand_chacha::ChaCha20Rng; + use rand_core::SeedableRng; + use rng_statistical_tests::practrand; + + let beacon_key = "k2k4r8lvomw737sajfnpav0dpeernugnryng50uheyk1k39lursmn09f"; + let mut ctrng = Ctrng::ipfs(beacon_key, None); + let seed = ctrng.next_block().expect("failed to fetch IPFS block"); + let rng = ChaCha20Rng::from_seed(seed); + + let result = practrand::run_test( + rng, + practrand::Config { + test_size_kb: Some(1024), + ..Default::default() + }, + ) + .expect("failed to run PractRand"); + + assert!(result.passed, "PractRand reported failure"); +}