SupportsInterface.behavior.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import makeInterfaceId from '../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. export default function (interfaces = []) {
  32. describe('ERC165\'s supportsInterface(bytes4)', function () {
  33. beforeEach(function () {
  34. this.thing = this.mock || this.token;
  35. });
  36. for (let 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. }