Skip to content

Structured Solidity Test Cheatcode Errors#8141

Merged
ChristopherDedominici merged 5 commits intomainfrom
add-err-cheatcodes
Apr 15, 2026
Merged

Structured Solidity Test Cheatcode Errors#8141
ChristopherDedominici merged 5 commits intomainfrom
add-err-cheatcodes

Conversation

@ChristopherDedominici
Copy link
Copy Markdown
Contributor

@ChristopherDedominici ChristopherDedominici commented Apr 14, 2026

Fixes: #7966

Example of error:
image

@ChristopherDedominici ChristopherDedominici added the no docs needed This PR doesn't require links to documentation label Apr 14, 2026
Copilot AI review requested due to automatic review settings April 14, 2026 12:05
@github-project-automation github-project-automation Bot moved this to Backlog in Hardhat Apr 14, 2026
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 14, 2026

🦋 Changeset detected

Latest commit: 2f801bf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
hardhat Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Integrates EDR’s structured Solidity Test cheatcode error details into Hardhat’s stack-trace message formatting so users get clearer “missing vs unsupported” cheatcode messages.

Changes:

  • Add cheatcode-specific message formatting for CHEATCODE_ERROR stack-trace entries (unsupported vs missing).
  • Re-export CheatcodeErrorCode (and CheatcodeErrorDetails type) through Hardhat’s EDR stack-trace wrapper.
  • Add unit tests for the Solidity Test stack-trace message formatter.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/hardhat/src/internal/builtin-plugins/solidity-test/stack-trace-solidity-errors.ts Formats CHEATCODE_ERROR messages using structured details.code for Solidity Test output.
packages/hardhat/src/internal/builtin-plugins/network-manager/edr/stack-traces/stack-trace-solidity-errors.ts Formats CHEATCODE_ERROR messages (with VM-exception prefix) using structured details for transaction errors.
packages/hardhat/src/internal/builtin-plugins/network-manager/edr/stack-traces/solidity-stack-trace.ts Re-exports CheatcodeErrorCode and CheatcodeErrorDetails to align Hardhat types with EDR.
packages/hardhat/test/internal/builtin-plugins/solidity-test/stack-trace-solidity-errors.ts Adds tests for Solidity Test getMessageFromLastStackTraceEntry cheatcode error formatting.
packages/hardhat/test/internal/builtin-plugins/network-manager/edr/stack-traces/stack-trace-solidity-errors.ts Adds imports and a duplicated test block for cheatcode message formatting (currently targeting the Solidity Test formatter).

@ChristopherDedominici ChristopherDedominici marked this pull request as draft April 14, 2026 12:18
Copilot AI review requested due to automatic review settings April 14, 2026 12:41
@ChristopherDedominici ChristopherDedominici moved this from Backlog to In Progress in Hardhat Apr 14, 2026
@ChristopherDedominici ChristopherDedominici marked this pull request as ready for review April 14, 2026 12:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Integrates EDR’s newly structured Solidity Test cheatcode error details into Hardhat’s stack-trace error message formatting, so users get clearer, Hardhat-specific explanations for missing/unsupported cheatcodes (per #7966).

Changes:

  • Add cheatcode-detail-aware message formatting for CHEATCODE_ERROR stack trace entries (missing vs unsupported cheatcodes).
  • Re-export EDR cheatcode error types/codes through Hardhat’s internal stack-trace module.
  • Add/extend internal tests to cover the new message behavior (both Solidity Test and network-manager error construction).

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/hardhat/src/internal/builtin-plugins/solidity-test/stack-trace-solidity-errors.ts Uses structured details.code to return Hardhat-specific messages for cheatcode errors.
packages/hardhat/src/internal/builtin-plugins/network-manager/edr/stack-traces/stack-trace-solidity-errors.ts Formats CHEATCODE_ERROR messages using structured details before prefixing with “VM Exception…”.
packages/hardhat/src/internal/builtin-plugins/network-manager/edr/stack-traces/solidity-stack-trace.ts Re-exports CheatcodeErrorCode and CheatcodeErrorDetails to support structured error handling downstream.
packages/hardhat/test/internal/builtin-plugins/solidity-test/stack-trace-solidity-errors.ts Adds tests asserting the new cheatcode error messages returned by getMessageFromLastStackTraceEntry.
packages/hardhat/test/internal/builtin-plugins/network-manager/edr/stack-traces/stack-trace-solidity-errors.ts Extends tests to assert createSolidityErrorWithStackTrace uses the new cheatcode message formatting.
.changeset/funny-socks-worry.md Adds a patch changeset describing the new structured cheatcode error support.

@ChristopherDedominici ChristopherDedominici moved this from In Progress to In Review in Hardhat Apr 14, 2026
Copy link
Copy Markdown
Member

@alcuadrado alcuadrado left a comment

Choose a reason for hiding this comment

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

LGTM, but let's wait for @popescuoctavian to see if the output matches his expectation

@popescuoctavian
Copy link
Copy Markdown
Contributor

LGTM, thanks for implementing this! For some context, when a call targets the cheatcode address the inspector tries to ABI-decode the cheatcode address to known cheatcodes -- if that fails with UnknownSelector there are 2 cases:

  1. Known upstream cheatcode => human-readable cheatcode signature is returned
  2. Completely unknown selector (not part of Foundry ABI) => 4-byte selector is returned

I am assuming the MissingCheatcode test that produced the output from the screenshot falls under the 2nd case.

@ChristopherDedominici @alcuadrado

@ChristopherDedominici
Copy link
Copy Markdown
Contributor Author

ChristopherDedominici commented Apr 15, 2026

LGTM, thanks for implementing this! For some context, when a call targets the cheatcode address the inspector tries to ABI-decode the cheatcode address to known cheatcodes -- if that fails with UnknownSelector there are 2 cases:

  1. Known upstream cheatcode => human-readable cheatcode signature is returned
  2. Completely unknown selector (not part of Foundry ABI) => 4-byte selector is returned

I am assuming the MissingCheatcode test that produced the output from the screenshot falls under the 2nd case.

@ChristopherDedominici @alcuadrado

@popescuoctavian Yes, that's correct, the MissingCheatcode case corresponds to case 2 (unknown selector). As you can see in the screenshot, EDR couldn't resolve it to a human-readable signature, so the message shows the raw 4-byte selector (0x7218e329). The key difference this PR introduces is that when EDR provides structured details, we use that to produce a clearer, Hardhat-specific message instead of the generic one. When details is undefined (e.g. older EDR versions), we fall back to the original raw message for backward compatibility.

@popescuoctavian
Copy link
Copy Markdown
Contributor

@ChristopherDedominici that's in line with what I had in mind when I added the structured errors (maximizing backward compatibility). Thanks!

@ChristopherDedominici ChristopherDedominici added this pull request to the merge queue Apr 15, 2026
Merged via the queue into main with commit bfa5864 Apr 15, 2026
558 of 662 checks passed
@ChristopherDedominici ChristopherDedominici deleted the add-err-cheatcodes branch April 15, 2026 11:58
@github-project-automation github-project-automation Bot moved this from In Review to Done in Hardhat Apr 15, 2026
@github-actions github-actions Bot mentioned this pull request Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no docs needed This PR doesn't require links to documentation no peer bump needed

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Display structured errors

5 participants