SupportsInterface.behavior.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. const { makeInterfaceId } = require('../helpers/makeInterfaceId');
  2. const INTERFACE_IDS = {
  3. ERC165: makeInterfaceId([
  4. 'supportsInterface(bytes4)',
  5. ]),
  6. ERC721: makeInterfaceId([
  7. 'balanceOf(address)',
  8. 'ownerOf(uint256)',
  9. 'approve(address,uint256)',
  10. 'getApproved(uint256)',
  11. 'setApprovalForAll(address,bool)',
  12. 'isApprovedForAll(address,address)',
  13. 'transferFrom(address,address,uint256)',
  14. 'safeTransferFrom(address,address,uint256)',
  15. 'safeTransferFrom(address,address,uint256,bytes)',
  16. ]),
  17. ERC721Enumerable: makeInterfaceId([
  18. 'totalSupply()',
  19. 'tokenOfOwnerByIndex(address,uint256)',
  20. 'tokenByIndex(uint256)',
  21. ]),
  22. ERC721Metadata: makeInterfaceId([
  23. 'name()',
  24. 'symbol()',
  25. 'tokenURI(uint256)',
  26. ]),
  27. ERC721Exists: makeInterfaceId([
  28. 'exists(uint256)',
  29. ]),
  30. };
  31. function shouldSupportInterfaces (interfaces = []) {
  32. describe('ERC165\'s supportsInterface(bytes4)', function () {
  33. beforeEach(function () {
  34. this.thing = this.mock || this.token;
  35. });
  36. for (const k of interfaces) {
  37. const interfaceId = INTERFACE_IDS[k];
  38. describe(k, function () {
  39. it('should use less than 30k gas', async function () {
  40. const gasEstimate = await this.thing.supportsInterface.estimateGas(interfaceId);
  41. gasEstimate.should.be.lte(30000);
  42. });
  43. it('is supported', async function () {
  44. const isSupported = await this.thing.supportsInterface(interfaceId);
  45. isSupported.should.eq(true);
  46. });
  47. });
  48. }
  49. });
  50. }
  51. module.exports = {
  52. shouldSupportInterfaces,
  53. };