소스 검색

Added makeInterfaceId tests. (#1530)

Nicolás Venturo 6 년 전
부모
커밋
9faebb5365
2개의 변경된 파일35개의 추가작업 그리고 0개의 파일을 삭제
  1. 15 0
      contracts/mocks/OwnableInterfaceId.sol
  2. 20 0
      test/helpers/test/makeInterfaceId.test.js

+ 15 - 0
contracts/mocks/OwnableInterfaceId.sol

@@ -0,0 +1,15 @@
+pragma solidity ^0.4.24;
+
+import "../ownership/Ownable.sol";
+
+/**
+ * @title Ownable interface id calculator.
+ * @dev See the EIP165 specification for more information:
+ * https://github.com/ethereum/EIPs/blob/master/EIPS/eip-165.md#specification
+ */
+contract OwnableInterfaceId {
+    function getInterfaceId() public pure returns (bytes4) {
+        Ownable i;
+        return i.owner.selector ^ i.isOwner.selector ^ i.renounceOwnership.selector ^ i.transferOwnership.selector;
+    }
+}

+ 20 - 0
test/helpers/test/makeInterfaceId.test.js

@@ -0,0 +1,20 @@
+const { makeInterfaceId } = require('../makeInterfaceId');
+
+const OwnableInterfaceId = artifacts.require('OwnableInterfaceId');
+
+require('chai')
+  .should();
+
+describe('makeInterfaceId', function () {
+  it('calculates the EIP165 interface id from function signatures', async function () {
+    const calculator = await OwnableInterfaceId.new();
+    const ownableId = await calculator.getInterfaceId();
+
+    makeInterfaceId([
+      'owner()',
+      'isOwner()',
+      'renounceOwnership()',
+      'transferOwnership(address)',
+    ]).should.equal(ownableId);
+  });
+});