diff --git a/.gitignore b/.gitignore index d13300d6a..7c72b246f 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,5 @@ artifacts/ build/ .kakarot/ +# ignore proptest-regressions +/proptest-regressions diff --git a/Cargo.lock b/Cargo.lock index a8836734a..edbf0099f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7570,6 +7570,7 @@ dependencies = [ "mongodb", "pin-project-lite", "prometheus", + "proptest", "rand 0.8.5", "rayon", "reqwest 0.12.3", diff --git a/Cargo.toml b/Cargo.toml index c5639bc5c..c2f6f941a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -175,6 +175,7 @@ starknet_api = { git = "https://github.com/starkware-libs/starknet-api.git", tag [dev-dependencies] rstest = { version = "0.19.0", default-features = false } toml = { version = "0.8.12", default-features = false } +proptest = { version = "1.4.0", default-features = false } [features] testing = [ diff --git a/src/eth_provider/utils.rs b/src/eth_provider/utils.rs index c74d00a50..518269447 100644 --- a/src/eth_provider/utils.rs +++ b/src/eth_provider/utils.rs @@ -69,6 +69,7 @@ pub(crate) fn entrypoint_not_found(err: &Result) -> bool { #[cfg(test)] mod tests { use super::*; + use proptest::prelude::*; use reth_primitives::B256; use std::str::FromStr; @@ -88,4 +89,19 @@ mod tests { doc! {"test_key": format!("0x{}", "0".repeat(64))} ); } + + #[test] + fn test_split_u256() { + // Define a property-based test using Proptest + proptest!(|(value in any::())| { + // Call the split_u256 function to split the U256 value into two u128 values + let result = split_u256::(value); + + // Combine the two u128 values into a hexadecimal string + let combined_hex = format!("{:#x}{:0width$x}", result[1], result[0], width = 32); + + // Assertion to check the equality with the original U256 value + assert_eq!(U256::from_str(&combined_hex).unwrap(), value); + }); + } }