-
Notifications
You must be signed in to change notification settings - Fork 11.8k
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
Added message string for require() #1704
Added message string for require() #1704
Conversation
Hey there @balajipachai! We have an outstanding issue open for this (#888), which we plan on tackling during these couple of days. I'm currently doing some testing regarding gas costs, user experience, etc., and trying to figure out what the best approach is for the messages themselves. I think we can safely skip the 'from OpenZeppelin' bit, and just include the contract name: I'd expect that to be enough to pinpoint the offending contract. Your suggestion to only include the function name is intriguing, since it'd make it easy to look into the code and find the root cause of the revert. That said, I think I favor having a more descriptive message (e.g. |
@nventuro |
To prevent work duplication, I'd rather we settle on a format first, so that everyone can then later contribute by adding these reason strings and associated tests (which are quite a lot). Please, come join the discussion on our forum and share your thoughts! |
@balajipachai I opened #1709 with some guidelines regarding message format, among other things, including some examples. Could you review it and update your PR accordingly? Thanks! |
@nventuro Sure, let me have a look at those guidelines and I'll update my PR accordingly. |
@nventuro Updated the PR as per #1709, please have a look and let me know in case of any changes. |
@nventuro Awaiting your reply, once you give a heads up, I can start with the changes in the test cases too for shouldFail.reverting.withMessage. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @balajipachai, thank you for your contribution! I left a couple comments to improve some of the messages :) I also noticed some of them are empty, did you not know what to put in those?
I may do a couple myself to serve as a guideline, since I fear the forum post may not be enough.
I didn't notice what was left empty, my bad, however, as per your guideline, I have started to make changes and will update the PR shortly. |
@nventuro The PR has been updated as per below guidelines:
|
Hello @balajipachai, thank you very much for your improvements! I did some changes to the revert strings, generally either making them more terse, or changing implementation details for the actual reason for failure. Could you add these strings to the test suite, to assert the actual failure reason? Thanks! |
Sure @nventuro , I'll add those changes and update !!! |
@nventuro I have started working on the shouldFail.reverting.withMessage, however, I have noticed that : In order to be sure about shouldFail.reverting.withMessage is working as expected I did a way around for testing purpose only and modified the below line: |
@balajipachai That's weird, you shouldn't be having any issues with that If you have an older version installed, you could delete |
…message-string-for-require
@balajipachai I've now reviewed and updated all reason strings. |
@nventuro Thanks!!! Test cases updation is in progress 👍 |
@frangio could you take a look at the reason strings? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @balajipachai, this must have taken quite a while to get done! I left a couple comments, but most are very minor, we should be able to merge this very soon!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work everyone!
Thank You @nventuro |
@balajipachai sorry we forgot to mention this, but we did some of the changes ourselves in the interest of getting this merged for the release, and to relieve some of the load from you, who has already done so much :) Thanks a lot everyone! |
@nventuro It's been more than couple of days, yet, I don't see my name listed amongst the Contributors. |
I am looking at this link: Could you share the link where my name is listed? |
That very same link, on number #56 when sorting by commits (PRs) made. |
Thank You 👍 |
Enhancement #
Added message string for require statements.
Many a time it happens, a transaction reverts with the message
Error: VM Exception while processing transaction: revert, for reasons such as trying to access a variable that is not in existence, trying to call a contract's function where the contract's address has been address(0) and not yet initialized etc.
The ways to find the reason for revert may include:
After the addition of message string for require statements, one can easily find the point of revocation and work on fixing the same.
The below approach has been used for adding message string
If there is only 1 require statement in a function then the message string is:
"from OpenZeppelin's:FileName.sol:functionName()."
If there are multiple require statement in a function then the message string is:
"from OpenZeppelin's:FileName.sol:functionName. Cause of the revert."