Browse Source

Added leading underscore to internal functions, renamed supportsInterfaces. (#1435)

Nicolás Venturo 7 years ago
parent
commit
0231fac514

+ 12 - 12
contracts/introspection/ERC165Checker.sol

@@ -20,15 +20,15 @@ library ERC165Checker {
    * @param account The address of the contract to query for support of ERC165
    * @return true if the contract at account implements ERC165
    */
-  function supportsERC165(address account)
+  function _supportsERC165(address account)
     internal
     view
     returns (bool)
   {
     // Any contract that implements ERC165 must explicitly indicate support of
     // InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid
-    return supportsERC165Interface(account, _InterfaceId_ERC165) &&
-      !supportsERC165Interface(account, _InterfaceId_Invalid);
+    return _supportsERC165Interface(account, _InterfaceId_ERC165) &&
+      !_supportsERC165Interface(account, _InterfaceId_Invalid);
   }
 
   /**
@@ -39,14 +39,14 @@ library ERC165Checker {
    * identifier interfaceId, false otherwise
    * @dev Interface identification is specified in ERC-165.
    */
-  function supportsInterface(address account, bytes4 interfaceId)
+  function _supportsInterface(address account, bytes4 interfaceId)
     internal
     view
     returns (bool)
   {
     // query support of both ERC165 as per the spec and support of _interfaceId
-    return supportsERC165(account) &&
-      supportsERC165Interface(account, interfaceId);
+    return _supportsERC165(account) &&
+      _supportsERC165Interface(account, interfaceId);
   }
 
   /**
@@ -57,19 +57,19 @@ library ERC165Checker {
    * interfaceIds list, false otherwise
    * @dev Interface identification is specified in ERC-165.
    */
-  function supportsInterfaces(address account, bytes4[] interfaceIds)
+  function _supportsAllInterfaces(address account, bytes4[] interfaceIds)
     internal
     view
     returns (bool)
   {
     // query support of ERC165 itself
-    if (!supportsERC165(account)) {
+    if (!_supportsERC165(account)) {
       return false;
     }
 
     // query support of each interface in _interfaceIds
     for (uint256 i = 0; i < interfaceIds.length; i++) {
-      if (!supportsERC165Interface(account, interfaceIds[i])) {
+      if (!_supportsERC165Interface(account, interfaceIds[i])) {
         return false;
       }
     }
@@ -89,14 +89,14 @@ library ERC165Checker {
    * with the `supportsERC165` method in this library.
    * Interface identification is specified in ERC-165.
    */
-  function supportsERC165Interface(address account, bytes4 interfaceId)
+  function _supportsERC165Interface(address account, bytes4 interfaceId)
     private
     view
     returns (bool)
   {
     // success determines whether the staticcall succeeded and result determines
     // whether the contract at account indicates support of _interfaceId
-    (bool success, bool result) = callERC165SupportsInterface(
+    (bool success, bool result) = _callERC165SupportsInterface(
       account, interfaceId);
 
     return (success && result);
@@ -110,7 +110,7 @@ library ERC165Checker {
    * @return result true if the STATICCALL succeeded and the contract at account
    * indicates support of the interface with identifier interfaceId, false otherwise
    */
-  function callERC165SupportsInterface(
+  function _callERC165SupportsInterface(
     address account,
     bytes4 interfaceId
   )

+ 4 - 4
contracts/mocks/ERC165CheckerMock.sol

@@ -10,7 +10,7 @@ contract ERC165CheckerMock {
     view
     returns (bool)
   {
-    return account.supportsERC165();
+    return account._supportsERC165();
   }
 
   function supportsInterface(address account, bytes4 interfaceId)
@@ -18,14 +18,14 @@ contract ERC165CheckerMock {
     view
     returns (bool)
   {
-    return account.supportsInterface(interfaceId);
+    return account._supportsInterface(interfaceId);
   }
 
-  function supportsInterfaces(address account, bytes4[] interfaceIds)
+  function supportsAllInterfaces(address account, bytes4[] interfaceIds)
     public
     view
     returns (bool)
   {
-    return account.supportsInterfaces(interfaceIds);
+    return account._supportsAllInterfaces(interfaceIds);
   }
 }

+ 14 - 14
test/introspection/ERC165Checker.test.js

@@ -32,8 +32,8 @@ contract('ERC165Checker', function () {
       supported.should.equal(false);
     });
 
-    it('does not support mock interface via supportsInterfaces', async function () {
-      const supported = await this.mock.supportsInterfaces(this.target.address, [DUMMY_ID]);
+    it('does not support mock interface via supportsAllInterfaces', async function () {
+      const supported = await this.mock.supportsAllInterfaces(this.target.address, [DUMMY_ID]);
       supported.should.equal(false);
     });
   });
@@ -53,8 +53,8 @@ contract('ERC165Checker', function () {
       supported.should.equal(false);
     });
 
-    it('does not support mock interface via supportsInterfaces', async function () {
-      const supported = await this.mock.supportsInterfaces(this.target.address, [DUMMY_ID]);
+    it('does not support mock interface via supportsAllInterfaces', async function () {
+      const supported = await this.mock.supportsAllInterfaces(this.target.address, [DUMMY_ID]);
       supported.should.equal(false);
     });
   });
@@ -74,8 +74,8 @@ contract('ERC165Checker', function () {
       supported.should.equal(true);
     });
 
-    it('supports mock interface via supportsInterfaces', async function () {
-      const supported = await this.mock.supportsInterfaces(this.target.address, [DUMMY_ID]);
+    it('supports mock interface via supportsAllInterfaces', async function () {
+      const supported = await this.mock.supportsAllInterfaces(this.target.address, [DUMMY_ID]);
       supported.should.equal(true);
     });
   });
@@ -98,22 +98,22 @@ contract('ERC165Checker', function () {
       };
     });
 
-    it('supports all interfaceIds via supportsInterfaces', async function () {
-      const supported = await this.mock.supportsInterfaces(this.target.address, this.supportedInterfaces);
+    it('supports all interfaceIds via supportsAllInterfaces', async function () {
+      const supported = await this.mock.supportsAllInterfaces(this.target.address, this.supportedInterfaces);
       supported.should.equal(true);
     });
 
-    it('supports none of the interfaces queried via supportsInterfaces', async function () {
+    it('supports none of the interfaces queried via supportsAllInterfaces', async function () {
       const interfaceIdsToTest = [DUMMY_UNSUPPORTED_ID, DUMMY_UNSUPPORTED_ID_2];
 
-      const supported = await this.mock.supportsInterfaces(this.target.address, interfaceIdsToTest);
+      const supported = await this.mock.supportsAllInterfaces(this.target.address, interfaceIdsToTest);
       supported.should.equal(false);
     });
 
-    it('supports not all of the interfaces queried via supportsInterfaces', async function () {
+    it('supports not all of the interfaces queried via supportsAllInterfaces', async function () {
       const interfaceIdsToTest = [...this.supportedInterfaces, DUMMY_UNSUPPORTED_ID];
 
-      const supported = await this.mock.supportsInterfaces(this.target.address, interfaceIdsToTest);
+      const supported = await this.mock.supportsAllInterfaces(this.target.address, interfaceIdsToTest);
       supported.should.equal(false);
     });
   });
@@ -129,8 +129,8 @@ contract('ERC165Checker', function () {
       supported.should.equal(false);
     });
 
-    it('does not support mock interface via supportsInterfaces', async function () {
-      const supported = await this.mock.supportsInterfaces(DUMMY_ACCOUNT, [DUMMY_ID]);
+    it('does not support mock interface via supportsAllInterfaces', async function () {
+      const supported = await this.mock.supportsAllInterfaces(DUMMY_ACCOUNT, [DUMMY_ID]);
       supported.should.equal(false);
     });
   });