Skip to content

Commit

Permalink
proptest
Browse files Browse the repository at this point in the history
  • Loading branch information
dvush committed Oct 6, 2024
1 parent d0d1ea2 commit ef55a27
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ triehash = "0.8.4"
criterion = { version = "0.4", features = ["html_reports"] }
eyre = "0.6.12"
rand = { version = "0.8.5", features = ["small_rng"] }
#proptest = "1.5.0"
proptest = "1.5.0"

[[bench]]
name = "trie_insert_bench"
Expand Down
44 changes: 44 additions & 0 deletions src/sparse_mpt/diff_trie/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use alloy_primitives::{Bytes, B256};
use eyre::Context;
use rand::seq::SliceRandom;
use rand::SeedableRng;
use proptest::prelude::*;

fn convert_input_to_bytes(input: &[(Vec<u8>, Vec<u8>)]) -> Vec<(Bytes, Bytes)> {
input
Expand Down Expand Up @@ -500,3 +501,46 @@ fn known_failure_case_0() {
}
}
}


proptest! {
#[test]
fn proptest_random_insert_any_values(key_values in any::<Vec<([u8; 3], Vec<u8>)>>()) {
let data: Vec<_> = key_values.into_iter().map(|(k, v)| (k.to_vec(), v)).collect();
compare_impls(&data);
}


#[test]
fn proptest_random_insert_big_values(key_values in any::<Vec<([u8; 3], [u8; 64])>>()) {
let data: Vec<_> = key_values.into_iter().map(|(k, v)| (k.to_vec(), v.to_vec())).collect();
compare_impls(&data);
}

#[test]
fn proptest_random_insert_small_values(key_values in any::<Vec<([u8; 3], [u8; 3])>>()) {
let data: Vec<_> = key_values.into_iter().map(|(k, v)| (k.to_vec(), v.to_vec())).collect();
compare_impls(&data);
}

#[test]
fn proptest_random_insert_big_keys(key_values in any::<Vec<([u8; 32], Vec<u8>)>>()) {
let data: Vec<_> = key_values.into_iter().map(|(k, v)| (k.to_vec(), v)).collect();
compare_impls(&data);
}


#[test]
fn proptest_random_insert_remove_any_values(key_values in any::<Vec<(([u8; 3], bool), Vec<u8>)>>()) {
let mut keys_to_remove_set = HashSet::default();
let mut keys_to_remove = Vec::new();
let data: Vec<_> = key_values.into_iter().map(|((k, remove), v)| {
if remove && !keys_to_remove_set.contains(&k) {
keys_to_remove_set.insert(k.clone());
keys_to_remove.push(k.to_vec());
}
(k.to_vec(), v)
}).collect();
compare_with_removals(&data, &keys_to_remove).unwrap()
}
}

0 comments on commit ef55a27

Please sign in to comment.