From fa017f9326d4fe1f7a971d12e5aafdeba5c36e23 Mon Sep 17 00:00:00 2001 From: Gregory Edison Date: Thu, 12 Sep 2024 14:07:07 +0200 Subject: [PATCH 1/2] print seed to stdout on test vectors generation --- crates/cli/commands/src/test_vectors/tables.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/crates/cli/commands/src/test_vectors/tables.rs b/crates/cli/commands/src/test_vectors/tables.rs index d7138444f69a..92b306c95f21 100644 --- a/crates/cli/commands/src/test_vectors/tables.rs +++ b/crates/cli/commands/src/test_vectors/tables.rs @@ -1,9 +1,10 @@ +use alloy_primitives::private::getrandom::getrandom; use arbitrary::Arbitrary; use eyre::Result; use proptest::{ prelude::ProptestConfig, strategy::{Strategy, ValueTree}, - test_runner::TestRunner, + test_runner::{TestRng, TestRunner}, }; use proptest_arbitrary_interop::arb; use reth_db::tables; @@ -17,7 +18,15 @@ const PER_TABLE: usize = 1000; /// Generates test vectors for specified `tables`. If list is empty, then generate for all tables. pub(crate) fn generate_vectors(mut tables: Vec) -> Result<()> { - let mut runner = TestRunner::new(ProptestConfig::default()); + // Prepare random seed for test (same method as used by proptest) + let mut seed = [0u8; 32]; + getrandom(&mut seed)?; + + // Start the runner with the seed + let config = ProptestConfig::default(); + let rng = TestRng::from_seed(config.rng_algorithm, &seed); + let mut runner = TestRunner::new_with_rng(config, rng); + fs::create_dir_all(VECTORS_FOLDER)?; macro_rules! generate_vector { @@ -37,6 +46,7 @@ pub(crate) fn generate_vectors(mut tables: Vec) -> Result<()> { tables = all_tables; } + println!("Seed for test vectors: {:?}", seed); for table in tables { match table.as_str() { $( From 9547105ea0c1816321135fc92c417d3f84239c08 Mon Sep 17 00:00:00 2001 From: Gregory Edison Date: Thu, 12 Sep 2024 18:54:32 +0200 Subject: [PATCH 2/2] move println! out of macro --- crates/cli/commands/src/test_vectors/tables.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/cli/commands/src/test_vectors/tables.rs b/crates/cli/commands/src/test_vectors/tables.rs index 92b306c95f21..112685251d08 100644 --- a/crates/cli/commands/src/test_vectors/tables.rs +++ b/crates/cli/commands/src/test_vectors/tables.rs @@ -21,6 +21,7 @@ pub(crate) fn generate_vectors(mut tables: Vec) -> Result<()> { // Prepare random seed for test (same method as used by proptest) let mut seed = [0u8; 32]; getrandom(&mut seed)?; + println!("Seed for test vectors: {:?}", seed); // Start the runner with the seed let config = ProptestConfig::default(); @@ -46,7 +47,6 @@ pub(crate) fn generate_vectors(mut tables: Vec) -> Result<()> { tables = all_tables; } - println!("Seed for test vectors: {:?}", seed); for table in tables { match table.as_str() { $(