SupportsInterface.behavior.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. const { makeInterfaceId } = require('openzeppelin-test-helpers');
  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. (await this.thing.supportsInterface.estimateGas(interfaceId)).should.be.lte(30000);
  41. });
  42. it('is supported', async function () {
  43. (await this.thing.supportsInterface(interfaceId)).should.equal(true);
  44. });
  45. });
  46. }
  47. });
  48. }
  49. module.exports = {
  50. shouldSupportInterfaces,
  51. };