Skip to content

Add error message assertions in Solidity tests#1272

Open
ericglau wants to merge 1 commit into
OpenZeppelin:masterfrom
ericglau:testmessageassert
Open

Add error message assertions in Solidity tests#1272
ericglau wants to merge 1 commit into
OpenZeppelin:masterfrom
ericglau:testmessageassert

Conversation

@ericglau
Copy link
Copy Markdown
Member

@ericglau ericglau commented Jun 3, 2026

Fixes #1242

Summary by CodeRabbit

  • Tests
    • Enhanced test validation to verify specific error messages for contract upgrade validation checks.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 3, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d0b74a00-da25-48b1-87d4-5ce54fefa438

📥 Commits

Reviewing files that changed from the base of the PR and between a4562e9 and d8b9c0a.

📒 Files selected for processing (1)
  • packages/plugin-hardhat/test/solidity/Upgrades.t.sol

Walkthrough

Test cases in Upgrades.t.sol replace bare catch blocks with typed revert data capture and substring assertions. Six negative test functions now verify that validation failures include specific expected error messages instead of accepting any revert reason.

Changes

Upgrade Validation Test Error Assertions

Layer / File(s) Summary
Error message validation across negative tests
packages/plugin-hardhat/test/solidity/Upgrades.t.sol
Six test functions update their catch blocks to capture revert data as bytes and assert the decoded error message contains specific validation failure substrings: "Use of delegatecall is not allowed" (testValidateImplementation), "Inserted `c`" (testValidateLayout, testValidateLayoutUpgradesFrom, testValidateNamespaced, testValidateNamespacedUpgradesFrom), and "does not specify what contract it upgrades from" (testValidateNamespacedNoReference).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 Six catches bloom with wisdom bright,
Where empty blocks now grip the light,
Each error message finds its voice,
A test refined, a revert's choice! 🌟

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: adding error message assertions to Solidity tests.
Linked Issues check ✅ Passed The PR successfully addresses issue #1242 by replacing bare catch blocks with specific error message assertions using StringFinder utility in all affected test methods.
Out of Scope Changes check ✅ Passed All changes are scoped to the Upgrades.t.sol test file and directly implement the proposed fix from issue #1242; no unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add specific error substring assertions to negative tests in Upgrades.t.sol

1 participant