-
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
Improve revert reason when assuming interface compliance #1727
Comments
A concrete example where whoever works on this should begin is this line in This line can revert if the receiver doesn't implement the This issue is about ensuring there is a nice error message in those cases. The way in we can achieve it is by performing a low-level (bool success, bytes returndata) = to.call( ... );
if (!success) {
// revert with custom reason (or use `returndata` if non-empty)
} else ... |
@nventuro I have started to look into it |
Hi @nventuro @frangio,
While running the test cases it fails: Any help on this will be much appreciated. |
Hi Team, I went through the specified issue. I have added the following code in ERC721.sol.
I have created a dummy contract which does not implement the IERC721Receiver interface and have updated test cases for the same in ERC721.behavior.js Please do let me know if this is the correct approach used or do I need to think of some other way to solve the issue. |
That's pretty good @NoopurShinde! It's also a possibility that the recipient does implement |
I have updated the code in ERC721.sol and ERC721Behavior.test.js as suggested by @frangio to solve the specified issues. |
Does someone want to pick up #1943 and continue the work? |
* adding mock contacts, test code * adding changes to ERC721.sol per @frangio's comments on original PR #1943 * fix solhint warnings * Update contracts/token/ERC721/ERC721.sol Co-Authored-By: Francisco Giordano <[email protected]> * same revert wording per @frangio's review suggestion * per @frangio's feedback, changing the inline assembly to accomplish: we want to ignore the first 4 bytes of content, so we should read the length and decrease it by 4, then take the memory location and add 4 to it, then store the new length at the new memory location, then that is the new byte array that we want. * change revert msg assembly per PR comment by @frangio * unify revert msg in test code * fix some failed tests, wording change * Update contracts/token/ERC721/ERC721.sol Co-Authored-By: Francisco Giordano <[email protected]> * Update contracts/token/ERC721/ERC721.sol Co-Authored-By: Francisco Giordano <[email protected]> * fix test case, revert without reason * fix 'ERC721ReceiverRevertsMock: Transaction rejected by receiver' * style change per review by @frangio * fix revert reason forwarding * remove duplicate contracts/mocks/ERC721ReceiverRevertsMock.sol per review https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2018\#issuecomment-574381034 * Add changelog entry * Fix tests * Make tests more clear Co-authored-by: Francisco Giordano <[email protected]> Co-authored-by: Nicolás Venturo <[email protected]>
* adding mock contacts, test code * adding changes to ERC721.sol per @frangio's comments on original PR OpenZeppelin#1943 * fix solhint warnings * Update contracts/token/ERC721/ERC721.sol Co-Authored-By: Francisco Giordano <[email protected]> * same revert wording per @frangio's review suggestion * per @frangio's feedback, changing the inline assembly to accomplish: we want to ignore the first 4 bytes of content, so we should read the length and decrease it by 4, then take the memory location and add 4 to it, then store the new length at the new memory location, then that is the new byte array that we want. * change revert msg assembly per PR comment by @frangio * unify revert msg in test code * fix some failed tests, wording change * Update contracts/token/ERC721/ERC721.sol Co-Authored-By: Francisco Giordano <[email protected]> * Update contracts/token/ERC721/ERC721.sol Co-Authored-By: Francisco Giordano <[email protected]> * fix test case, revert without reason * fix 'ERC721ReceiverRevertsMock: Transaction rejected by receiver' * style change per review by @frangio * fix revert reason forwarding * remove duplicate contracts/mocks/ERC721ReceiverRevertsMock.sol per review https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2018\#issuecomment-574381034 * Add changelog entry * Fix tests * Make tests more clear Co-authored-by: Francisco Giordano <[email protected]> Co-authored-by: Nicolás Venturo <[email protected]>
As discussed in this review comment, it'd be interesting to wrap calls to unknown contracts for which an interface is assumed in a low-level call that returns a custom revert reason on error, to better describe what went wrong.
The text was updated successfully, but these errors were encountered: