* Clean code - using type().interfaceId to improve readeability of ERC165 registration - hardcoding some keccak256 that are otherwise computed at construction. * hardcode keccak256 result * Improve code readeability using try/catch * Remove hardcoded hash tests show that solc 0.8.0 does the optimization as expected * Use try/catch to improve readability * ERC165Checker: Do not revert when returndata is empty + new test * Address PR comments * improve testing of ERC721Receiver errors * put back comment about invalid interface id * coverage does not support 0.8.1. Reverting back to 0.8.0 * bubble all data with length > 0 if onERC721Receive fails. * Fix test: revert without message trigger is bubble with the default message * using enum object to improve readability
40 lines
1.1 KiB
Solidity
40 lines
1.1 KiB
Solidity
// SPDX-License-Identifier: MIT
|
|
|
|
pragma solidity ^0.8.0;
|
|
|
|
import "../token/ERC721/IERC721Receiver.sol";
|
|
|
|
contract ERC721ReceiverMock is IERC721Receiver {
|
|
enum Error {
|
|
None,
|
|
RevertWithMessage,
|
|
RevertWithoutMessage,
|
|
Panic
|
|
}
|
|
|
|
bytes4 private immutable _retval;
|
|
Error private immutable _error;
|
|
|
|
event Received(address operator, address from, uint256 tokenId, bytes data, uint256 gas);
|
|
|
|
constructor (bytes4 retval, Error error) {
|
|
_retval = retval;
|
|
_error = error;
|
|
}
|
|
|
|
function onERC721Received(address operator, address from, uint256 tokenId, bytes memory data)
|
|
public override returns (bytes4)
|
|
{
|
|
if (_error == Error.RevertWithMessage) {
|
|
revert("ERC721ReceiverMock: reverting");
|
|
} else if (_error == Error.RevertWithoutMessage) {
|
|
revert();
|
|
} else if (_error == Error.Panic) {
|
|
uint256 a = uint256(0) / uint256(0);
|
|
a;
|
|
}
|
|
emit Received(operator, from, tokenId, data, gasleft());
|
|
return _retval;
|
|
}
|
|
}
|