ERC165InterfacesSupported.sol 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. pragma solidity ^0.5.2;
  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
  6. * throw an exception.
  7. * > These operations include [...], LOG0, LOG1, LOG2, [...]
  8. *
  9. * therefore, because this contract is staticcall'd we need to not emit events (which is how solidity-coverage works)
  10. * solidity-coverage ignores the /mocks folder, so we duplicate its implementation here to avoid instrumenting it
  11. */
  12. contract SupportsInterfaceWithLookupMock is IERC165 {
  13. bytes4 public constant INTERFACE_ID_ERC165 = 0x01ffc9a7;
  14. /**
  15. * 0x01ffc9a7 ===
  16. * bytes4(keccak256('supportsInterface(bytes4)'))
  17. */
  18. /**
  19. * @dev a mapping of interface id to whether or not it's supported
  20. */
  21. mapping(bytes4 => bool) private _supportedInterfaces;
  22. /**
  23. * @dev A contract implementing SupportsInterfaceWithLookup
  24. * implement ERC165 itself
  25. */
  26. constructor () public {
  27. _registerInterface(INTERFACE_ID_ERC165);
  28. }
  29. /**
  30. * @dev implement supportsInterface(bytes4) using a lookup table
  31. */
  32. function supportsInterface(bytes4 interfaceId) external view returns (bool) {
  33. return _supportedInterfaces[interfaceId];
  34. }
  35. /**
  36. * @dev private method for registering an interface
  37. */
  38. function _registerInterface(bytes4 interfaceId) internal {
  39. require(interfaceId != 0xffffffff);
  40. _supportedInterfaces[interfaceId] = true;
  41. }
  42. }
  43. contract ERC165InterfacesSupported is SupportsInterfaceWithLookupMock {
  44. constructor (bytes4[] memory interfaceIds) public {
  45. for (uint256 i = 0; i < interfaceIds.length; i++) {
  46. _registerInterface(interfaceIds[i]);
  47. }
  48. }
  49. }