refactor: replace require strings with custom errors for gas optimiza…#42
Conversation
…tion - Define 11 custom errors: InvalidSignature, TestimonialDoesNotExist, TestimonialHasBeenDeleted, TokensAreNonTransferrable, OnlyRecipientCanDelete, TestimonialAlreadyDeleted, InsufficientFeePayment, FeeTransferFailed, RefundFailed, SetTreasuryBeforeEnablingFees, TreasuryCannotBeZeroAddress - Replace all 12 require(condition, string) with if/revert patterns - Update 20 expectRevert calls across 5 test files to use error selectors - All 65 tests pass
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (6)
WalkthroughThis PR replaces 11 string-based ChangesCustom Error Migration
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Pull request overview
Refactors VouchMe.sol to replace require(condition, "string") statements with custom errors and if (!condition) revert CustomError() patterns for gas optimization, and updates the Foundry test suite to assert on the new custom error selectors.
Changes:
- Declares 11 custom errors at contract scope and replaces 12
requirestatements inVouchMe.solwithif/revertpatterns. - Updates
vm.expectRevert(string)assertions across 5 test files to useVouchMe.<Error>.selector. - Preserves existing behavior (no logical changes); fee/refund/treasury/signature/deletion guards are equivalent.
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 |
|---|---|
| contracts/src/VouchMe.sol | Adds custom error declarations and swaps all require strings for if/revert equivalents. |
| contracts/test/VouchMe.t.sol | Updates revert expectations to custom error selectors for deletion, transfer, and signature checks. |
| contracts/test/VouchMeSignature.t.sol | Switches signature-validation revert assertions to InvalidSignature.selector. |
| contracts/test/VouchMeIntegration.t.sol | Updates testimonial-replacement revert assertions to TestimonialHasBeenDeleted.selector. |
| contracts/test/VouchMeFuzz.t.sol | Updates fuzz-test revert assertions to TestimonialHasBeenDeleted.selector. |
| contracts/test/VouchMeMonetization.t.sol | Updates monetization revert assertions (treasury, fee, refund, insufficient payment) to custom error selectors. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Addressed Issues:
Fixes #39
Screenshots/Recordings:
Not applicable. This is a smart contract optimization PR that does not affect the frontend UI.
Additional Notes:
This PR implements a major gas optimization refactor across the
VouchMesmart contract.require(condition, "string")statements withif (!condition) revert CustomError();patterns.InvalidSignature(),TestimonialDoesNotExist()).vm.expectRevert()statements across 5 test files to properly catch the new error selectors.AI Usage Disclosure:
We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact. AI slop is strongly discouraged and may lead to banning and blocking. Do not spam our repos with AI slop.
Check one of the checkboxes below:
I have used the following AI models and tools: Claude opus 4.6 via Antigravity
Checklist
Summary by CodeRabbit
Refactor
Tests