ERC165InterfacesSupported.sol 1.8 KB

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