Skip to content

Commit 84c65d9

Browse files
authored
Display fuzzing output without fractional parts (#3840)
<!-- Reference any GitHub issues resolved by this PR --> Related #3077
1 parent ea10048 commit 84c65d9

File tree

5 files changed

+18
-4
lines changed

5 files changed

+18
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Forge
11+
12+
#### Changed
13+
14+
- Gas values in fuzzing test output are now displayed as whole numbers without fractional parts
15+
1016
## [0.51.0] - 2025-10-21
1117

1218
### Forge

crates/forge-runner/src/gas/stats.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,20 @@ impl GasStats {
2323

2424
#[expect(clippy::cast_precision_loss)]
2525
fn mean(values: &[u64]) -> f64 {
26+
if values.is_empty() {
27+
return 0.0;
28+
}
29+
2630
let sum: f64 = values.iter().map(|&x| x as f64).sum();
2731
sum / values.len() as f64
2832
}
2933

3034
#[expect(clippy::cast_precision_loss)]
3135
fn std_deviation(mean: f64, values: &[u64]) -> f64 {
36+
if values.is_empty() {
37+
return 0.0;
38+
}
39+
3240
let sum_squared_diff = values
3341
.iter()
3442
.map(|&x| (x as f64 - mean).pow(2))

crates/forge-runner/src/test_case_summary.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl fmt::Display for GasStats {
3939
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4040
write!(
4141
f,
42-
"{{max: ~{}, min: ~{}, mean: ~{:.2}, std deviation: ~{:.2}}}",
42+
"{{max: ~{}, min: ~{}, mean: ~{:.0}, std deviation: ~{:.0}}}",
4343
self.max, self.min, self.mean, self.std_deviation
4444
)
4545
}

docs/src/snforge-advanced-features/fuzz-testing.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ $ snforge test
3434
```shell
3535
Collected 2 test(s) from fuzz_testing package
3636
Running 2 test(s) from src/
37-
[PASS] fuzz_testing::with_parameters::tests::test_sum (runs: 22, gas: {max: ~124, min: ~121, mean: ~123.00, std deviation: ~0.90})
38-
[PASS] fuzz_testing::basic_example::tests::test_sum (runs: 256, gas: {max: ~124, min: ~121, mean: ~123.00, std deviation: ~0.81})
37+
[PASS] fuzz_testing::with_parameters::tests::test_sum (runs: 22, (l1_gas: {max: ~0, min: ~0, mean: ~0, std deviation: ~0}, l1_data_gas: {max: ~0, min: ~0, mean: ~0, std deviation: ~0}, l2_gas: {max: ~1888390, min: ~1852630, mean: ~1881888, std deviation: ~9322}))
38+
[PASS] fuzz_testing::basic_example::tests::test_sum (runs: 256, (l1_gas: {max: ~0, min: ~0, mean: ~0, std deviation: ~0}, l1_data_gas: {max: ~0, min: ~0, mean: ~0, std deviation: ~0}, l2_gas: {max: ~1888390, min: ~1828790, mean: ~1882058, std deviation: ~8807}))
3939
Tests: 2 passed, 0 failed, 0 ignored, 0 filtered out
4040
Fuzzer seed: [..]
4141
```

docs/src/testing/gas-and-resource-estimation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ storage updates, events and l1 <> l2 messages.
2121

2222
While using the fuzzing feature additional gas statistics will be displayed:
2323
```shell
24-
[PASS] tests::fuzzing_test (runs: 256, l1_gas: {max: ~126, min: ~1, mean: ~65.00, std deviation: ~37.31}, l1_data_gas: {max: ~126, min: ~1, mean: ~65.00, std deviation: ~37.31}, l2_gas: {max: ~126, min: ~1, mean: ~65.00, std deviation: ~37.31})
24+
[PASS] tests::fuzzing_test (runs: 256, l1_gas: {max: ~126, min: ~1, mean: ~65, std deviation: ~37}, l1_data_gas: {max: ~96, min: ~96, mean: ~96, std deviation: ~0}, l2_gas: {max: ~1888390, min: ~1852630, mean: ~1881888, std deviation: ~9322}})
2525
```
2626

2727
> 📝 **Note**

0 commit comments

Comments
 (0)