ERC165InterfacesSupported.sol 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.7.0;
  3. import "../../introspection/IERC165.sol";
  4. /**
  5. * https://eips.ethereum.org/EIPS/eip-214#specification
  6. * From the specification:
  7. * > Any attempts to make state-changing operations inside an execution instance with STATIC set to true will instead
  8. * throw an exception.
  9. * > These operations include [...], LOG0, LOG1, LOG2, [...]
  10. *
  11. * therefore, because this contract is staticcall'd we need to not emit events (which is how solidity-coverage works)
  12. * solidity-coverage ignores the /mocks folder, so we duplicate its implementation here to avoid instrumenting it
  13. */
  14. contract SupportsInterfaceWithLookupMock is IERC165 {
  15. /*
  16. * bytes4(keccak256('supportsInterface(bytes4)')) == 0x01ffc9a7
  17. */
  18. bytes4 public constant INTERFACE_ID_ERC165 = 0x01ffc9a7;
  19. /**
  20. * @dev A mapping of interface id to whether or not it's supported.
  21. */
  22. mapping(bytes4 => bool) private _supportedInterfaces;
  23. /**
  24. * @dev A contract implementing SupportsInterfaceWithLookup
  25. * implement ERC165 itself.
  26. */
  27. constructor () {
  28. _registerInterface(INTERFACE_ID_ERC165);
  29. }
  30. /**
  31. * @dev Implement supportsInterface(bytes4) using a lookup table.
  32. */
  33. function supportsInterface(bytes4 interfaceId) public view override returns (bool) {
  34. return _supportedInterfaces[interfaceId];
  35. }
  36. /**
  37. * @dev Private method for registering an interface.
  38. */
  39. function _registerInterface(bytes4 interfaceId) internal {
  40. require(interfaceId != 0xffffffff, "ERC165InterfacesSupported: invalid interface id");
  41. _supportedInterfaces[interfaceId] = true;
  42. }
  43. }
  44. contract ERC165InterfacesSupported is SupportsInterfaceWithLookupMock {
  45. constructor (bytes4[] memory interfaceIds) {
  46. for (uint256 i = 0; i < interfaceIds.length; i++) {
  47. _registerInterface(interfaceIds[i]);
  48. }
  49. }
  50. }