Skip to content

fix(forge): preserve invariant replay failure reason#14136

Merged
grandizzy merged 9 commits intofoundry-rs:masterfrom
0xWeakSheep:fix/invariant-replay-property-reason-14134
Apr 6, 2026
Merged

fix(forge): preserve invariant replay failure reason#14136
grandizzy merged 9 commits intofoundry-rs:masterfrom
0xWeakSheep:fix/invariant-replay-property-reason-14134

Conversation

@0xWeakSheep
Copy link
Copy Markdown
Contributor

Motivation

During invariant replay, Foundry shows a generic message like:

[FAIL: <invariant_name> replay failure]

This hides the actual property/assert message and makes debugging harder.

Closes #14134.

Solution

  • Preserve the replayed failure reason when available.
  • Use that reason in replay output.
  • Keep existing generic fallback if no reason is available.

So replay now shows the real failure message (for example never owner) instead of only <invariant_name> replay failure.

Tests

Updated invariant CLI replay-output assertions to match the new behavior.

AI Disclosure

This PR was developed with AI assistance.

Copy link
Copy Markdown
Collaborator

@grandizzy grandizzy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, overall lgtm! Could you pls add tests for invariants failing with fail() and custom error to make sure they properly displayed too?

@0xWeakSheep
Copy link
Copy Markdown
Contributor Author

Thanks for the review. I added two replay regression tests:

  • invariant_replay_preserves_fail_reason
  • invariant_replay_preserves_custom_error_reason

Both run the same invariant twice and assert that replay preserves the specific failure reason (panic: assertion failed (0x01) for fail() and InvariantCustomError(111, "custom") for custom error), rather than showing a generic replay failure message.

@0xWeakSheep
Copy link
Copy Markdown
Contributor Author

Thanks for the heads-up. I checked the CI failure and it appears unrelated to this PR’s changes.

The failing job is anvil::it proof::test_storage_proof with:
failed to spawn node: Address already in use (os error 98).

This PR only updates invariant replay tests under crates/forge/tests/cli/test_cmd/invariant/mod.rs, and does not touch Anvil/proof code paths. This looks like an infra/port-conflict flaky failure. I’m re-running CI.

@0xWeakSheep
Copy link
Copy Markdown
Contributor Author

I also added one more replay regression test for an invariant-level custom error:
invariant_replay_preserves_invariant_custom_error_reason.

It ensures that when the invariant function itself reverts with a custom error, replay still preserves and displays the same custom error message.

@grandizzy grandizzy self-requested a review April 6, 2026 05:25
Copy link
Copy Markdown
Collaborator

@grandizzy grandizzy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you, lgtm!

@grandizzy grandizzy merged commit bf9239e into foundry-rs:master Apr 6, 2026
15 checks passed
@github-project-automation github-project-automation Bot moved this to Done in Foundry Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

feat(invariant): replaying a broken invariant should show the property description being broken

2 participants