ERC165Checker.test.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. const ERC165CheckerMock = artifacts.require('ERC165CheckerMock');
  2. const ERC165NotSupported = artifacts.require('ERC165NotSupported');
  3. const ERC165InterfacesSupported = artifacts.require('ERC165InterfacesSupported');
  4. const DUMMY_ID = '0xdeadbeef';
  5. const DUMMY_ID_2 = '0xcafebabe';
  6. const DUMMY_ID_3 = '0xdecafbad';
  7. const DUMMY_UNSUPPORTED_ID = '0xbaddcafe';
  8. const DUMMY_UNSUPPORTED_ID_2 = '0xbaadcafe';
  9. const DUMMY_ACCOUNT = '0x1111111111111111111111111111111111111111';
  10. require('../helpers/setup');
  11. contract('ERC165Checker', function () {
  12. beforeEach(async function () {
  13. this.mock = await ERC165CheckerMock.new();
  14. });
  15. context('ERC165 not supported', function () {
  16. beforeEach(async function () {
  17. this.target = await ERC165NotSupported.new();
  18. });
  19. it('does not support ERC165', async function () {
  20. const supported = await this.mock.supportsERC165(this.target.address);
  21. supported.should.equal(false);
  22. });
  23. it('does not support mock interface via supportsInterface', async function () {
  24. const supported = await this.mock.supportsInterface(this.target.address, DUMMY_ID);
  25. supported.should.equal(false);
  26. });
  27. it('does not support mock interface via supportsAllInterfaces', async function () {
  28. const supported = await this.mock.supportsAllInterfaces(this.target.address, [DUMMY_ID]);
  29. supported.should.equal(false);
  30. });
  31. });
  32. context('ERC165 supported', function () {
  33. beforeEach(async function () {
  34. this.target = await ERC165InterfacesSupported.new([]);
  35. });
  36. it('supports ERC165', async function () {
  37. const supported = await this.mock.supportsERC165(this.target.address);
  38. supported.should.equal(true);
  39. });
  40. it('does not support mock interface via supportsInterface', async function () {
  41. const supported = await this.mock.supportsInterface(this.target.address, DUMMY_ID);
  42. supported.should.equal(false);
  43. });
  44. it('does not support mock interface via supportsAllInterfaces', async function () {
  45. const supported = await this.mock.supportsAllInterfaces(this.target.address, [DUMMY_ID]);
  46. supported.should.equal(false);
  47. });
  48. });
  49. context('ERC165 and single interface supported', function () {
  50. beforeEach(async function () {
  51. this.target = await ERC165InterfacesSupported.new([DUMMY_ID]);
  52. });
  53. it('supports ERC165', async function () {
  54. const supported = await this.mock.supportsERC165(this.target.address);
  55. supported.should.equal(true);
  56. });
  57. it('supports mock interface via supportsInterface', async function () {
  58. const supported = await this.mock.supportsInterface(this.target.address, DUMMY_ID);
  59. supported.should.equal(true);
  60. });
  61. it('supports mock interface via supportsAllInterfaces', async function () {
  62. const supported = await this.mock.supportsAllInterfaces(this.target.address, [DUMMY_ID]);
  63. supported.should.equal(true);
  64. });
  65. });
  66. context('ERC165 and many interfaces supported', function () {
  67. beforeEach(async function () {
  68. this.supportedInterfaces = [DUMMY_ID, DUMMY_ID_2, DUMMY_ID_3];
  69. this.target = await ERC165InterfacesSupported.new(this.supportedInterfaces);
  70. });
  71. it('supports ERC165', async function () {
  72. const supported = await this.mock.supportsERC165(this.target.address);
  73. supported.should.equal(true);
  74. });
  75. it('supports each interfaceId via supportsInterface', async function () {
  76. for (const interfaceId of this.supportedInterfaces) {
  77. const supported = await this.mock.supportsInterface(this.target.address, interfaceId);
  78. supported.should.equal(true);
  79. };
  80. });
  81. it('supports all interfaceIds via supportsAllInterfaces', async function () {
  82. const supported = await this.mock.supportsAllInterfaces(this.target.address, this.supportedInterfaces);
  83. supported.should.equal(true);
  84. });
  85. it('supports none of the interfaces queried via supportsAllInterfaces', async function () {
  86. const interfaceIdsToTest = [DUMMY_UNSUPPORTED_ID, DUMMY_UNSUPPORTED_ID_2];
  87. const supported = await this.mock.supportsAllInterfaces(this.target.address, interfaceIdsToTest);
  88. supported.should.equal(false);
  89. });
  90. it('supports not all of the interfaces queried via supportsAllInterfaces', async function () {
  91. const interfaceIdsToTest = [...this.supportedInterfaces, DUMMY_UNSUPPORTED_ID];
  92. const supported = await this.mock.supportsAllInterfaces(this.target.address, interfaceIdsToTest);
  93. supported.should.equal(false);
  94. });
  95. });
  96. context('account address does not support ERC165', function () {
  97. it('does not support ERC165', async function () {
  98. const supported = await this.mock.supportsERC165(DUMMY_ACCOUNT);
  99. supported.should.equal(false);
  100. });
  101. it('does not support mock interface via supportsInterface', async function () {
  102. const supported = await this.mock.supportsInterface(DUMMY_ACCOUNT, DUMMY_ID);
  103. supported.should.equal(false);
  104. });
  105. it('does not support mock interface via supportsAllInterfaces', async function () {
  106. const supported = await this.mock.supportsAllInterfaces(DUMMY_ACCOUNT, [DUMMY_ID]);
  107. supported.should.equal(false);
  108. });
  109. });
  110. });