ERC721ReceiverMockUpgradeable.sol 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.0;
  3. import "../token/ERC721/IERC721ReceiverUpgradeable.sol";
  4. import "../proxy/utils/Initializable.sol";
  5. contract ERC721ReceiverMockUpgradeable is Initializable, IERC721ReceiverUpgradeable {
  6. enum Error {
  7. None,
  8. RevertWithMessage,
  9. RevertWithoutMessage,
  10. Panic
  11. }
  12. bytes4 private _retval;
  13. Error private _error;
  14. event Received(address operator, address from, uint256 tokenId, bytes data, uint256 gas);
  15. function __ERC721ReceiverMock_init(bytes4 retval, Error error) internal onlyInitializing {
  16. __ERC721ReceiverMock_init_unchained(retval, error);
  17. }
  18. function __ERC721ReceiverMock_init_unchained(bytes4 retval, Error error) internal onlyInitializing {
  19. _retval = retval;
  20. _error = error;
  21. }
  22. function onERC721Received(
  23. address operator,
  24. address from,
  25. uint256 tokenId,
  26. bytes memory data
  27. ) public override returns (bytes4) {
  28. if (_error == Error.RevertWithMessage) {
  29. revert("ERC721ReceiverMock: reverting");
  30. } else if (_error == Error.RevertWithoutMessage) {
  31. revert();
  32. } else if (_error == Error.Panic) {
  33. uint256 a = uint256(0) / uint256(0);
  34. a;
  35. }
  36. emit Received(operator, from, tokenId, data, gasleft());
  37. return _retval;
  38. }
  39. /**
  40. * @dev This empty reserved space is put in place to allow future versions to add new
  41. * variables without shifting down storage in the inheritance chain.
  42. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
  43. */
  44. uint256[50] private __gap;
  45. }