ERC165InterfacesSupported.sol 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. pragma solidity ^0.5.2;
  2. import "../../introspection/IERC165.sol";
  3. /**
  4. * https://eips.ethereum.org/EIPS/eip-214#specification
  5. * From the specification:
  6. * > Any attempts to make state-changing operations inside an execution instance with STATIC set to true will instead
  7. * throw an exception.
  8. * > These operations include [...], LOG0, LOG1, LOG2, [...]
  9. *
  10. * therefore, because this contract is staticcall'd we need to not emit events (which is how solidity-coverage works)
  11. * solidity-coverage ignores the /mocks folder, so we duplicate its implementation here to avoid instrumenting it
  12. */
  13. contract SupportsInterfaceWithLookupMock is IERC165 {
  14. bytes4 public constant INTERFACE_ID_ERC165 = 0x01ffc9a7;
  15. /*
  16. * 0x01ffc9a7 ===
  17. * bytes4(keccak256('supportsInterface(bytes4)'))
  18. */
  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 () public {
  28. _registerInterface(INTERFACE_ID_ERC165);
  29. }
  30. /**
  31. * @dev Implement supportsInterface(bytes4) using a lookup table.
  32. */
  33. function supportsInterface(bytes4 interfaceId) external view 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);
  41. _supportedInterfaces[interfaceId] = true;
  42. }
  43. }
  44. contract ERC165InterfacesSupported is SupportsInterfaceWithLookupMock {
  45. constructor (bytes4[] memory interfaceIds) public {
  46. for (uint256 i = 0; i < interfaceIds.length; i++) {
  47. _registerInterface(interfaceIds[i]);
  48. }
  49. }
  50. }