Skip to content

Commit

Permalink
Add makeInterfaceId.ERC165.
Browse files Browse the repository at this point in the history
  • Loading branch information
nventuro committed Mar 26, 2019
1 parent 3615de8 commit 72f8e1b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -128,7 +128,8 @@ Same as `inLogs`, but for events emitted in an arbitrary transaction (of hash `t


### makeInterfaceId (interfaces = [])
Calculates the [EIP 165](https://eips.ethereum.org/EIPS/eip-165) interface ID of a contract, given a series of function signatures.
#### ERC165
Calculates the [ERC165](https://eips.ethereum.org/EIPS/eip-165) interface ID of a contract, given a series of function signatures.

---

Expand Down
13 changes: 10 additions & 3 deletions src/makeInterfaceId.js
@@ -1,6 +1,6 @@
const INTERFACE_ID_LENGTH = 4;
function ERC165 (interfaces = []) {
const INTERFACE_ID_LENGTH = 4;

function makeInterfaceId (interfaces = []) {
const interfaceIdBuffer = interfaces
.map(methodSignature => web3.utils.soliditySha3(methodSignature)) // keccak256
.map(h =>
Expand All @@ -18,4 +18,11 @@ function makeInterfaceId (interfaces = []) {
return `0x${interfaceIdBuffer.toString('hex')}`;
}

module.exports = makeInterfaceId;
function ERC1820 (inteface) {

}

module.exports = {
ERC165,
ERC1820,
};
20 changes: 11 additions & 9 deletions test/src/makeInterfaceId.test.js
Expand Up @@ -5,15 +5,17 @@ const makeInterfaceId = require('../../src/makeInterfaceId');
const OwnableInterfaceId = artifacts.require('OwnableInterfaceId');

describe('makeInterfaceId', function () {
it('calculates the EIP165 interface id from function signatures', async function () {
const calculator = await OwnableInterfaceId.new();
const ownableId = await calculator.getInterfaceId();
describe('ERC165', function () {
it('calculates the interface id from function signatures', async function () {
const calculator = await OwnableInterfaceId.new();
const ownableId = await calculator.getInterfaceId();

expect(makeInterfaceId([
'owner()',
'isOwner()',
'renounceOwnership()',
'transferOwnership(address)',
])).to.equal(ownableId);
expect(makeInterfaceId.ERC165([
'owner()',
'isOwner()',
'renounceOwnership()',
'transferOwnership(address)',
])).to.equal(ownableId);
});
});
});

0 comments on commit 72f8e1b

Please sign in to comment.