-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Actionable List] Replace revert strings with custom errors #3614
Comments
Hi I'd really like to take up this issue. |
Thank you @akhil-is-watching, but I think the next steps for now are mostly internal discussion with the team. While let everyone know on the issue if we can use any help. |
There are two testing development tools had supported the custom error. I recommend hardhat-chai-matchers. it provide better readability. // hardhat-chai-matchers
await expect(contract.call()).to.be.revertedWithCustomError(
contract,
"SomeCustomError"
); but waffle provider a matcher combined reason string and custom error // waffle
// reason string
await expect(token.checkRole('ADMIN'))
.to.be.revertedWith(/AccessControl: account .* is missing role .*/);
// custom error
await expect(token.transfer(receiver, 100))
.to.be.revertedWith('InsufficientBalance')
.withArgs(0, 100); |
I like waffle's "withArgs" (its the same for events) |
@Amxx Hardhat supports await expect(contract.call())
.to.be.revertedWithCustomError(contract, "SomeCustomError")
.withArgs(anyValue, "some error data string"); |
hardhat-chai-matchers should be preferred over Waffle nowadays. |
I believe both supports Custom Errors, and the implementation can be tested with either. We use Custom Error all over our codebase where possible. It is lighter. |
Closing in favor of #2839 since there's more activity and attention over there |
Foundry can be also included on the list with |
Our tests are written in JS for many reasons (including ensuring compatibility with libraries frequently used by frontends). We are not going to migrate everything to foundry. That would require a tremendous effort, and the added value to our end users is debatable. We do use foundry to fusing though. |
🧐 Motivation
Custom Errors, which were introduced in 0.8.4, contribute to reduce the contract size and improve clarity of revert reasons.
A quick study shows that replacing a (short) revert string with a custom error can save 8.5k gas, and slightly decrease the run cost.
📝 Next steps
There are some question to resolve before moving forward with that change:
InsufficientBalance
for ERCs 20, 777, 1155)See
The text was updated successfully, but these errors were encountered: