From 72f8e1be07211b224ff6650cdb295cf4c1f58eb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Venturo?= Date: Tue, 26 Mar 2019 20:05:39 -0300 Subject: [PATCH 1/5] Add makeInterfaceId.ERC165. --- README.md | 3 ++- src/makeInterfaceId.js | 13 ++++++++++--- test/src/makeInterfaceId.test.js | 20 +++++++++++--------- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 3d2512e..6ba768d 100644 --- a/README.md +++ b/README.md @@ -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. --- diff --git a/src/makeInterfaceId.js b/src/makeInterfaceId.js index c1a78b1..295c5c3 100644 --- a/src/makeInterfaceId.js +++ b/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 => @@ -18,4 +18,11 @@ function makeInterfaceId (interfaces = []) { return `0x${interfaceIdBuffer.toString('hex')}`; } -module.exports = makeInterfaceId; +function ERC1820 (inteface) { + +} + +module.exports = { + ERC165, + ERC1820, +}; diff --git a/test/src/makeInterfaceId.test.js b/test/src/makeInterfaceId.test.js index 8e9e1be..fed70bf 100644 --- a/test/src/makeInterfaceId.test.js +++ b/test/src/makeInterfaceId.test.js @@ -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); + }); }); }); From e27a90816d7c89147dd4d68e0a3082dc573683b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Venturo?= Date: Tue, 26 Mar 2019 20:59:04 -0300 Subject: [PATCH 2/5] Add makeInterfaceId.ERC1820. --- README.md | 3 +++ src/makeInterfaceId.js | 10 +++++----- test/src/makeInterfaceId.test.js | 8 ++++++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6ba768d..b75b7b2 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,9 @@ Same as `inLogs`, but for events emitted in an arbitrary transaction (of hash `t #### ERC165 Calculates the [ERC165](https://eips.ethereum.org/EIPS/eip-165) interface ID of a contract, given a series of function signatures. +#### ERC1820 +Calculates the [ERC1820](https://eips.ethereum.org/EIPS/eip-1820) interface hash of a function, given its signature. + --- ### send diff --git a/src/makeInterfaceId.js b/src/makeInterfaceId.js index 295c5c3..29fc1ac 100644 --- a/src/makeInterfaceId.js +++ b/src/makeInterfaceId.js @@ -1,8 +1,8 @@ -function ERC165 (interfaces = []) { +function ERC165 (functionSignatures = []) { const INTERFACE_ID_LENGTH = 4; - const interfaceIdBuffer = interfaces - .map(methodSignature => web3.utils.soliditySha3(methodSignature)) // keccak256 + const interfaceIdBuffer = functionSignatures + .map(signature => web3.utils.soliditySha3(signature)) // keccak256 .map(h => Buffer .from(h.substring(2), 'hex') @@ -18,8 +18,8 @@ function ERC165 (interfaces = []) { return `0x${interfaceIdBuffer.toString('hex')}`; } -function ERC1820 (inteface) { - +function ERC1820 (functionSignature) { + return web3.utils.soliditySha3(functionSignature); // keccak256 } module.exports = { diff --git a/test/src/makeInterfaceId.test.js b/test/src/makeInterfaceId.test.js index fed70bf..f2c3c91 100644 --- a/test/src/makeInterfaceId.test.js +++ b/test/src/makeInterfaceId.test.js @@ -18,4 +18,12 @@ describe('makeInterfaceId', function () { ])).to.equal(ownableId); }); }); + + describe('ERC165', function () { + it('calculates the interface id from function signatures', async function () { + expect(makeInterfaceId.ERC1820('ERC777Token')).to.equal( + '0xac7fbab5f54a3ca8194167523c6753bfeb96a445279294b6125b68cce2177054' + ); + }); + }); }); From 850ca0f0779ff6195c42efdeb4256c87217331b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Venturo?= Date: Wed, 27 Mar 2019 12:07:46 -0300 Subject: [PATCH 3/5] Update description. --- README.md | 8 ++++---- src/makeInterfaceId.js | 4 ++-- test/src/makeInterfaceId.test.js | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index b75b7b2..7388d2b 100644 --- a/README.md +++ b/README.md @@ -127,12 +127,12 @@ Same as `inLogs`, but for events emitted in an arbitrary transaction (of hash `t --- -### makeInterfaceId (interfaces = []) -#### ERC165 +### makeInterfaceId +#### ERC165 (interfaces = []) Calculates the [ERC165](https://eips.ethereum.org/EIPS/eip-165) interface ID of a contract, given a series of function signatures. -#### ERC1820 -Calculates the [ERC1820](https://eips.ethereum.org/EIPS/eip-1820) interface hash of a function, given its signature. +#### ERC1820 (name) +Calculates the [ERC1820](https://eips.ethereum.org/EIPS/eip-1820) interface hash of a contract, given its name. --- diff --git a/src/makeInterfaceId.js b/src/makeInterfaceId.js index 29fc1ac..7f82638 100644 --- a/src/makeInterfaceId.js +++ b/src/makeInterfaceId.js @@ -18,8 +18,8 @@ function ERC165 (functionSignatures = []) { return `0x${interfaceIdBuffer.toString('hex')}`; } -function ERC1820 (functionSignature) { - return web3.utils.soliditySha3(functionSignature); // keccak256 +function ERC1820 (interfaceName) { + return web3.utils.soliditySha3(interfaceName); // keccak256 } module.exports = { diff --git a/test/src/makeInterfaceId.test.js b/test/src/makeInterfaceId.test.js index f2c3c91..c29fdb6 100644 --- a/test/src/makeInterfaceId.test.js +++ b/test/src/makeInterfaceId.test.js @@ -19,8 +19,8 @@ describe('makeInterfaceId', function () { }); }); - describe('ERC165', function () { - it('calculates the interface id from function signatures', async function () { + describe('ERC1820', function () { + it('calculates the interface hash a from a contract name', async function () { expect(makeInterfaceId.ERC1820('ERC777Token')).to.equal( '0xac7fbab5f54a3ca8194167523c6753bfeb96a445279294b6125b68cce2177054' ); From 34546e805e453bd2bc61a0699fe311b9269f634e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Venturo?= Date: Fri, 26 Apr 2019 11:57:47 -0300 Subject: [PATCH 4/5] Add changelog entry. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed45e16..08bf424 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 0.4.0 (unreleased) * Fix `shouldFail.reverting.withMessage` on non-Ganache chains. ([#25](https://github.com/OpenZeppelin/openzeppelin-test-helpers/pull/25) * `shouldFail.reverting.withMessage` fails if no error string is provided. ([#28](https://github.com/OpenZeppelin/openzeppelin-test-helpers/pull/28) + * Rename `makeInterfaceId` to `makeInterfaceId.ERC165`, and add `makeInterfaceId.ERC1820`. ([#21](https://github.com/OpenZeppelin/openzeppelin-test-helpers/pull/21) ## 0.3.2 (2019-04-10) * Update ERC1820Registry address. ([#26](https://github.com/OpenZeppelin/openzeppelin-test-helpers/pull/26)) From 7b84a9114422bb965d746b0b332f43a7f2974ed2 Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Fri, 3 May 2019 18:30:13 -0300 Subject: [PATCH 5/5] Update CHANGELOG.md Co-Authored-By: nventuro --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08bf424..9a58c54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ * Fix `shouldFail.reverting.withMessage` on non-Ganache chains. ([#25](https://github.com/OpenZeppelin/openzeppelin-test-helpers/pull/25) * `shouldFail.reverting.withMessage` fails if no error string is provided. ([#28](https://github.com/OpenZeppelin/openzeppelin-test-helpers/pull/28) * Rename `makeInterfaceId` to `makeInterfaceId.ERC165`, and add `makeInterfaceId.ERC1820`. ([#21](https://github.com/OpenZeppelin/openzeppelin-test-helpers/pull/21) + +#### How to upgrade from 0.3 +- Change all occurences of `makeInterfaceId` to `makeInterfaceId.ERC165`. +- Some uses of `shouldFail.reverting.withMessage` may fail now. This means it was being used incorrectly and an error string to match against should be added. Alternatively, if the error message is unknown, use `shouldFail.reverting` instead. ## 0.3.2 (2019-04-10) * Update ERC1820Registry address. ([#26](https://github.com/OpenZeppelin/openzeppelin-test-helpers/pull/26))