Skip to content

feat: add gas/s and tx/s throughput metrics to invariant test output#13898

Open
danieljrc888 wants to merge 1 commit intofoundry-rs:masterfrom
danieljrc888:feat/invariant-throughput-metrics
Open

feat: add gas/s and tx/s throughput metrics to invariant test output#13898
danieljrc888 wants to merge 1 commit intofoundry-rs:masterfrom
danieljrc888:feat/invariant-throughput-metrics

Conversation

@danieljrc888
Copy link
Copy Markdown

@danieljrc888 danieljrc888 commented Mar 23, 2026

Summary

  • Add throughput metrics (gas/s, tx/s) to invariant test output for benchmarking tools like scfuzzbench
  • Track cumulative gas and elapsed time during invariant campaigns
  • Add gas field to InvariantMetrics for per-selector gas tracking in the metrics table
  • Extend inline JSON progress logging with total_txs, total_gas, tx_per_sec, gas_per_sec
  • Display gas/s and tx/s in the human-readable test report line
  • Update snapshot parsing regex to handle new format

Example output

Ran 2 tests for test/Vault.invariant.t.sol:VaultInvariantTest
[PASS] invariant_depositWithdrawAccounting() (runs: 20, calls: 2000, reverts: 0, gas/s: 1054698686, tx/s: 15399)

╭--------------+----------+-------+---------+----------+----------╮
| Contract     | Selector | Calls | Reverts | Discards | Gas      |
+=================================================================+
| VaultHandler | deposit  | 1041  | 0       | 0        | 65616418 |
|--------------+----------+-------+---------+----------+----------|
| VaultHandler | withdraw | 959   | 0       | 0        | 71370771 |
╰--------------+----------+-------+---------+----------+----------╯

[PASS] invariant_solvency() (runs: 20, calls: 2000, reverts: 0, gas/s: 1171893077, tx/s: 17092)

╭--------------+----------+-------+---------+----------+----------╮
| Contract     | Selector | Calls | Reverts | Discards | Gas      |
+=================================================================+
| VaultHandler | deposit  | 1041  | 0       | 0        | 65559742 |
|--------------+----------+-------+---------+----------+----------|
| VaultHandler | withdraw | 959   | 0       | 0        | 71566351 |
╰--------------+----------+-------+---------+----------+----------╯

Suite result: ok. 2 passed; 0 failed; 0 skipped; finished in 140.49ms (265.67ms CPU time)

Closes #13575

Test plan

  • Unit tests for TestKindReport::Invariant display (normal, zero elapsed, optimization mode, failed corpus replays)
  • Unit test for metrics table with Gas column
  • Snapshot parsing tests updated for new format
  • Integration test snapshots updated across all invariant test files
  • cargo build -p forge passes
  • cargo test -p forge --lib passes (36 tests)

Add throughput metrics (gas/s, tx/s) to invariant test output to support
benchmarking tools like scfuzzbench. Metrics are shown in the human-readable
test report, inline JSON progress logging, and per-selector metrics table.

- Track cumulative gas and elapsed time during invariant campaigns
- Add `gas` field to `InvariantMetrics` for per-selector gas tracking
- Add `total_gas` and `elapsed` to `InvariantFuzzTestResult`
- Add `total_gas` and `elapsed_secs` to `TestKind::Invariant`
- Compute and display `gas/s` and `tx/s` in `TestKindReport` display
- Add Gas column to invariant metrics table
- Extend inline JSON progress with throughput fields
- Update snapshot regex to parse new format

Closes foundry-rs#13575
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Add gas/s and tx/s to the invariant metrics JSON

1 participant