Skip to content

Commit

Permalink
Add proptest for split_u256 (#1025)
Browse files Browse the repository at this point in the history
* Add proptest for split_u256

* fix comment

* clean up

* Empty-Commit
  • Loading branch information
tcoratger authored Apr 27, 2024
1 parent 39b5bdf commit e471f48
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ artifacts/
build/
.kakarot/

# ignore proptest-regressions
/proptest-regressions
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.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
16 changes: 16 additions & 0 deletions src/eth_provider/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ pub(crate) fn entrypoint_not_found<T>(err: &Result<T, Error>) -> bool {
#[cfg(test)]
mod tests {
use super::*;
use proptest::prelude::*;
use reth_primitives::B256;
use std::str::FromStr;

Expand All @@ -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::<U256>())| {
// Call the split_u256 function to split the U256 value into two u128 values
let result = split_u256::<u128>(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);
});
}
}

0 comments on commit e471f48

Please sign in to comment.