Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
42 changes: 15 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```


Expand Down
35 changes: 28 additions & 7 deletions tests/testu01_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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");
}
Loading