-
Notifications
You must be signed in to change notification settings - Fork 574
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
Handle new error types for solidity 0.8.4 #1108
Comments
Was this fixed in #1110 ? |
I think that #1110 made Brownie not crash on them but did not add any way to parse the info out of them and display it to the user. |
HI, im having trouble parsing custom errors in my tests. Im using solc
I get this error:
|
+1 for this feature. It's been almost 2 years that solidity announced Catch for custom error types: https://blog.ethereum.org/2020/01/29/solidity-0.6-try-catch/ |
Worth to mention I found this workaround to check for custom errors in tests. Replace
|
In case it is useful, I created some sample contracts and tests surrounding this: Note that when a custom error is raised by an imported/library contract, the exception and callstack does not reveal details about the error. |
Hey guys @julianmrodri workaround works perfect but does anybody knows how to do same thing when errors have parameters? If I have an error for example like this |
The selector is built the same way as for functions, i.e. includes parameter types. I.e. for your |
This is not exactly a solution for this issue but you should give a try to the new Python-based testing framework that was inspired by Brownie - Woke testing framework (spoiler alert - I am the lead developer). It handles user-defined errors in a form of dataclass exceptions. To do this, |
Attempt to fix issue eth-brownie#1108 (eth-brownie#1108). Can be used in testing as follows: with brownie.reverts(<DeployedContract>.encode_custom_error(<nameOfCustomError>, [params_of_custom_error]))
To anybody still struggling with this, I submitted a pull request.
For example if you want to test if a function checkIfPar(uint256 num) in your contract NumberGetter throws the error numberNotPa(num), for num = 10, you would do:
|
https://blog.soliditylang.org/2021/04/21/custom-errors/
This post has some example ethers js code that should be a decent guide.
The text was updated successfully, but these errors were encountered: