From f2e5ed160cf7b4338b554b77b425a79675fe05e6 Mon Sep 17 00:00:00 2001 From: Aniket Date: Sun, 11 Mar 2018 02:50:54 +0530 Subject: [PATCH 01/11] signing prefix added --- contracts/ECRecovery.sol | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/contracts/ECRecovery.sol b/contracts/ECRecovery.sol index 3876ca6e830..709ee43cb39 100644 --- a/contracts/ECRecovery.sol +++ b/contracts/ECRecovery.sol @@ -40,6 +40,13 @@ library ECRecovery { if (v != 27 && v != 28) { return (address(0)); } else { + + /* + * https://github.com/ethereum/go-ethereum/issues/3731 + */ + + bytes memory prefix = "\x19Ethereum Signed Message:\n32"; + hash = keccak256(prefix, hash); return ecrecover(hash, v, r, s); } } From 2bf341c178f8cc590f6791f7fc02db635ab57085 Mon Sep 17 00:00:00 2001 From: Aniket Date: Tue, 13 Mar 2018 15:24:23 +0530 Subject: [PATCH 02/11] Minor improvement --- contracts/ECRecovery.sol | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/contracts/ECRecovery.sol b/contracts/ECRecovery.sol index 709ee43cb39..c5b6d8f646c 100644 --- a/contracts/ECRecovery.sol +++ b/contracts/ECRecovery.sol @@ -41,13 +41,12 @@ library ECRecovery { return (address(0)); } else { - /* - * https://github.com/ethereum/go-ethereum/issues/3731 - */ + /* + * https://github.com/ethereum/go-ethereum/issues/3731 + */ - bytes memory prefix = "\x19Ethereum Signed Message:\n32"; - hash = keccak256(prefix, hash); - return ecrecover(hash, v, r, s); + bytes memory prefix = "\x19Ethereum Signed Message:\n32"; + return ecrecover(keccak256(prefix, hash), v, r, s); } } From bc7ea7ad913a9482fdb329b18b0151521ebd8f66 Mon Sep 17 00:00:00 2001 From: Aniket Date: Tue, 13 Mar 2018 15:50:25 +0530 Subject: [PATCH 03/11] Tests changed --- test/helpers/hashMessage.js | 2 +- test/library/ECRecovery.test.js | 38 ++++++++++++++++----------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/test/helpers/hashMessage.js b/test/helpers/hashMessage.js index 6e8a1f74e7f..08d965ccfc1 100644 --- a/test/helpers/hashMessage.js +++ b/test/helpers/hashMessage.js @@ -3,6 +3,6 @@ import utils from 'ethereumjs-util'; // Hash and add same prefix to the hash that testrpc use. module.exports = function (message) { const messageHex = Buffer.from(utils.sha3(message).toString('hex'), 'hex'); - const prefix = utils.toBuffer('\u0019Ethereum Signed Message:\n' + messageHex.length.toString()); + const prefix = utils.toBuffer(messageHex.length.toString()); return utils.bufferToHex(utils.sha3(Buffer.concat([prefix, messageHex]))); }; diff --git a/test/library/ECRecovery.test.js b/test/library/ECRecovery.test.js index 56852adf0af..405d5ff6782 100644 --- a/test/library/ECRecovery.test.js +++ b/test/library/ECRecovery.test.js @@ -13,25 +13,25 @@ contract('ECRecovery', function (accounts) { ecrecovery = await ECRecoveryMock.new(); }); - it('recover v0', async function () { - // Signature generated outside testrpc with method web3.eth.sign(signer, message) - let signer = '0x2cc1166f6212628a0deef2b33befb2187d35b86c'; - let message = web3.sha3(TEST_MESSAGE); - // eslint-disable-next-line max-len - let signature = '0x5d99b6f7f6d1f73d1a26497f2b1c89b24c0993913f86e9a2d02cd69887d9c94f3c880358579d811b21dd1b7fd9bb01c1d81d10e69f0384e675c32b39643be89200'; - await ecrecovery.recover(message, signature); - assert.equal(signer, await ecrecovery.addrRecovered()); - }); - - it('recover v1', async function () { - // Signature generated outside testrpc with method web3.eth.sign(signer, message) - let signer = '0x1e318623ab09fe6de3c9b8672098464aeda9100e'; - let message = web3.sha3(TEST_MESSAGE); - // eslint-disable-next-line max-len - let signature = '0x331fe75a821c982f9127538858900d87d3ec1f9f737338ad67cad133fa48feff48e6fa0c18abc62e42820f05943e47af3e9fbe306ce74d64094bdf1691ee53e001'; - await ecrecovery.recover(message, signature); - assert.equal(signer, await ecrecovery.addrRecovered()); - }); + // it('recover v0', async function () { + // // Signature generated outside testrpc with method web3.eth.sign(signer, message) + // let signer = '0x2cc1166f6212628a0deef2b33befb2187d35b86c'; + // let message = web3.sha3(TEST_MESSAGE); + // // eslint-disable-next-line max-len + // let signature = '0x5d99b6f7f6d1f73d1a26497f2b1c89b24c0993913f86e9a2d02cd69887d9c94f3c880358579d811b21dd1b7fd9bb01c1d81d10e69f0384e675c32b39643be89200'; + // await ecrecovery.recover(message, signature); + // assert.equal(signer, await ecrecovery.addrRecovered()); + // }); + + // it('recover v1', async function () { + // // Signature generated outside testrpc with method web3.eth.sign(signer, message) + // let signer = '0x1e318623ab09fe6de3c9b8672098464aeda9100e'; + // let message = web3.sha3(TEST_MESSAGE); + // // eslint-disable-next-line max-len + // let signature = '0x331fe75a821c982f9127538858900d87d3ec1f9f737338ad67cad133fa48feff48e6fa0c18abc62e42820f05943e47af3e9fbe306ce74d64094bdf1691ee53e001'; + // await ecrecovery.recover(message, signature); + // assert.equal(signer, await ecrecovery.addrRecovered()); + // }); it('recover using web3.eth.sign()', async function () { // Create the signature using account[0] From 5a720213d622650afc4c85b784c10d121615bc8d Mon Sep 17 00:00:00 2001 From: Aniket Date: Tue, 13 Mar 2018 16:30:25 +0530 Subject: [PATCH 04/11] Successfully tested --- test/helpers/hashMessage.js | 2 +- test/library/ECRecovery.test.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/helpers/hashMessage.js b/test/helpers/hashMessage.js index 08d965ccfc1..6e8a1f74e7f 100644 --- a/test/helpers/hashMessage.js +++ b/test/helpers/hashMessage.js @@ -3,6 +3,6 @@ import utils from 'ethereumjs-util'; // Hash and add same prefix to the hash that testrpc use. module.exports = function (message) { const messageHex = Buffer.from(utils.sha3(message).toString('hex'), 'hex'); - const prefix = utils.toBuffer(messageHex.length.toString()); + const prefix = utils.toBuffer('\u0019Ethereum Signed Message:\n' + messageHex.length.toString()); return utils.bufferToHex(utils.sha3(Buffer.concat([prefix, messageHex]))); }; diff --git a/test/library/ECRecovery.test.js b/test/library/ECRecovery.test.js index 405d5ff6782..fd99a0ae12f 100644 --- a/test/library/ECRecovery.test.js +++ b/test/library/ECRecovery.test.js @@ -38,7 +38,7 @@ contract('ECRecovery', function (accounts) { const signature = web3.eth.sign(accounts[0], web3.sha3(TEST_MESSAGE)); // Recover the signer address from the generated message and signature. - await ecrecovery.recover(hashMessage(TEST_MESSAGE), signature); + await ecrecovery.recover(web3.sha3(TEST_MESSAGE), signature); assert.equal(accounts[0], await ecrecovery.addrRecovered()); }); @@ -47,7 +47,7 @@ contract('ECRecovery', function (accounts) { const signature = web3.eth.sign(accounts[0], web3.sha3(TEST_MESSAGE)); // Recover the signer address from the generated message and wrong signature. - await ecrecovery.recover(hashMessage('Test'), signature); + await ecrecovery.recover(web3.sha3('Test'), signature); assert.notEqual(accounts[0], await ecrecovery.addrRecovered()); }); @@ -56,7 +56,7 @@ contract('ECRecovery', function (accounts) { let signature = web3.eth.sign(accounts[0], web3.sha3(TEST_MESSAGE)); // Recover the signer address from the generated message and wrong signature. - await ecrecovery.recover(hashMessage(TEST_MESSAGE).substring(2), signature); + await ecrecovery.recover(web3.sha3(TEST_MESSAGE).substring(2), signature); assert.equal('0x0000000000000000000000000000000000000000', await ecrecovery.addrRecovered()); }); }); From de0d2d46d0f544cd2a68bd56ea4237ca0dad2820 Mon Sep 17 00:00:00 2001 From: Aniket Date: Tue, 13 Mar 2018 17:12:10 +0530 Subject: [PATCH 05/11] Minor improvements --- test/library/ECRecovery.test.js | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/test/library/ECRecovery.test.js b/test/library/ECRecovery.test.js index fd99a0ae12f..1f9f41cd9ec 100644 --- a/test/library/ECRecovery.test.js +++ b/test/library/ECRecovery.test.js @@ -1,7 +1,6 @@ var ECRecoveryMock = artifacts.require('ECRecoveryMock'); var ECRecoveryLib = artifacts.require('ECRecovery'); -var hashMessage = require('../helpers/hashMessage.js'); contract('ECRecovery', function (accounts) { let ecrecovery; @@ -13,26 +12,6 @@ contract('ECRecovery', function (accounts) { ecrecovery = await ECRecoveryMock.new(); }); - // it('recover v0', async function () { - // // Signature generated outside testrpc with method web3.eth.sign(signer, message) - // let signer = '0x2cc1166f6212628a0deef2b33befb2187d35b86c'; - // let message = web3.sha3(TEST_MESSAGE); - // // eslint-disable-next-line max-len - // let signature = '0x5d99b6f7f6d1f73d1a26497f2b1c89b24c0993913f86e9a2d02cd69887d9c94f3c880358579d811b21dd1b7fd9bb01c1d81d10e69f0384e675c32b39643be89200'; - // await ecrecovery.recover(message, signature); - // assert.equal(signer, await ecrecovery.addrRecovered()); - // }); - - // it('recover v1', async function () { - // // Signature generated outside testrpc with method web3.eth.sign(signer, message) - // let signer = '0x1e318623ab09fe6de3c9b8672098464aeda9100e'; - // let message = web3.sha3(TEST_MESSAGE); - // // eslint-disable-next-line max-len - // let signature = '0x331fe75a821c982f9127538858900d87d3ec1f9f737338ad67cad133fa48feff48e6fa0c18abc62e42820f05943e47af3e9fbe306ce74d64094bdf1691ee53e001'; - // await ecrecovery.recover(message, signature); - // assert.equal(signer, await ecrecovery.addrRecovered()); - // }); - it('recover using web3.eth.sign()', async function () { // Create the signature using account[0] const signature = web3.eth.sign(accounts[0], web3.sha3(TEST_MESSAGE)); From 7f32e5ceaa62a458fd68591fe895e4d43685411d Mon Sep 17 00:00:00 2001 From: Aniket Date: Tue, 13 Mar 2018 17:17:29 +0530 Subject: [PATCH 06/11] Minor improvements --- test/library/ECRecovery.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/library/ECRecovery.test.js b/test/library/ECRecovery.test.js index 1f9f41cd9ec..ef354a76f05 100644 --- a/test/library/ECRecovery.test.js +++ b/test/library/ECRecovery.test.js @@ -1,7 +1,6 @@ var ECRecoveryMock = artifacts.require('ECRecoveryMock'); var ECRecoveryLib = artifacts.require('ECRecovery'); - contract('ECRecovery', function (accounts) { let ecrecovery; const TEST_MESSAGE = 'OpenZeppelin'; From 68de8409c2599a2617a78b2c856072e4d85a5881 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Mon, 1 Oct 2018 15:49:33 +0530 Subject: [PATCH 07/11] Revert "Dangling commas are now required. (#1359)" This reverts commit a6889776f46adca374b6ebf014aa7b0038112a9d. --- .eslintrc | 2 +- test/crowdsale/AllowanceCrowdsale.test.js | 2 +- test/crowdsale/Crowdsale.test.js | 4 ++-- test/crowdsale/MintedCrowdsale.behavior.js | 2 +- test/payment/Escrow.behavior.js | 4 ++-- test/token/ERC20/ERC20.test.js | 14 +++++++------- .../ERC20/behaviors/ERC20Burnable.behavior.js | 4 ++-- .../ERC20/behaviors/ERC20Mintable.behavior.js | 2 +- test/token/ERC721/ERC721.behavior.js | 14 +++++++------- test/token/ERC721/ERC721MintBurn.behavior.js | 4 ++-- 10 files changed, 26 insertions(+), 26 deletions(-) diff --git a/.eslintrc b/.eslintrc index c15a4d51515..117135b36f9 100644 --- a/.eslintrc +++ b/.eslintrc @@ -25,7 +25,7 @@ // Code style "camelcase": ["error", {"properties": "always"}], - "comma-dangle": ["error", "always-multiline"], + "comma-dangle": ["warn", "always-multiline"], "comma-spacing": ["error", {"before": false, "after": true}], "dot-notation": ["error", {"allowKeywords": true, "allowPattern": ""}], "eol-last": ["error", "always"], diff --git a/test/crowdsale/AllowanceCrowdsale.test.js b/test/crowdsale/AllowanceCrowdsale.test.js index c0ff4cd91ba..8e57a841b24 100644 --- a/test/crowdsale/AllowanceCrowdsale.test.js +++ b/test/crowdsale/AllowanceCrowdsale.test.js @@ -46,7 +46,7 @@ contract('AllowanceCrowdsale', function ([_, investor, wallet, purchaser, tokenW purchaser: investor, beneficiary: investor, value: value, - amount: expectedTokenAmount, + amount: expectedTokenAmount }); }); diff --git a/test/crowdsale/Crowdsale.test.js b/test/crowdsale/Crowdsale.test.js index 4113f7cb428..f691c951576 100644 --- a/test/crowdsale/Crowdsale.test.js +++ b/test/crowdsale/Crowdsale.test.js @@ -87,7 +87,7 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) { purchaser: investor, beneficiary: investor, value: value, - amount: expectedTokenAmount, + amount: expectedTokenAmount }); }); @@ -111,7 +111,7 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) { purchaser: purchaser, beneficiary: investor, value: value, - amount: expectedTokenAmount, + amount: expectedTokenAmount }); }); diff --git a/test/crowdsale/MintedCrowdsale.behavior.js b/test/crowdsale/MintedCrowdsale.behavior.js index ab8dc8259cc..c55850cd9a4 100644 --- a/test/crowdsale/MintedCrowdsale.behavior.js +++ b/test/crowdsale/MintedCrowdsale.behavior.js @@ -25,7 +25,7 @@ function shouldBehaveLikeMintedCrowdsale ([_, investor, wallet, purchaser], rate purchaser: investor, beneficiary: investor, value: value, - amount: expectedTokenAmount, + amount: expectedTokenAmount }); }); diff --git a/test/payment/Escrow.behavior.js b/test/payment/Escrow.behavior.js index 57f1fe5d0ac..fce4bd69217 100644 --- a/test/payment/Escrow.behavior.js +++ b/test/payment/Escrow.behavior.js @@ -34,7 +34,7 @@ function shouldBehaveLikeEscrow (primary, [payee1, payee2]) { const { logs } = await this.escrow.deposit(payee1, { from: primary, value: amount }); expectEvent.inLogs(logs, 'Deposited', { payee: payee1, - weiAmount: amount, + weiAmount: amount }); }); @@ -87,7 +87,7 @@ function shouldBehaveLikeEscrow (primary, [payee1, payee2]) { const { logs } = await this.escrow.withdraw(payee1, { from: primary }); expectEvent.inLogs(logs, 'Withdrawn', { payee: payee1, - weiAmount: amount, + weiAmount: amount }); }); }); diff --git a/test/token/ERC20/ERC20.test.js b/test/token/ERC20/ERC20.test.js index e991c2ae6d1..283e8752a09 100644 --- a/test/token/ERC20/ERC20.test.js +++ b/test/token/ERC20/ERC20.test.js @@ -65,7 +65,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) { expectEvent.inLogs(logs, 'Transfer', { from: owner, to: to, - value: amount, + value: amount }); }); }); @@ -93,7 +93,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) { expectEvent.inLogs(logs, 'Approval', { owner: owner, spender: spender, - value: amount, + value: amount }); }); @@ -127,7 +127,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) { expectEvent.inLogs(logs, 'Approval', { owner: owner, spender: spender, - value: amount, + value: amount }); }); @@ -197,7 +197,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) { expectEvent.inLogs(logs, 'Transfer', { from: owner, to: to, - value: amount, + value: amount }); }); }); @@ -272,7 +272,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) { expectEvent.inLogs(logs, 'Approval', { owner: owner, spender: spender, - value: 0, + value: 0 }); }); @@ -329,7 +329,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) { expectEvent.inLogs(logs, 'Approval', { owner: owner, spender: spender, - value: amount, + value: amount }); }); @@ -363,7 +363,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) { expectEvent.inLogs(logs, 'Approval', { owner: owner, spender: spender, - value: amount, + value: amount }); }); diff --git a/test/token/ERC20/behaviors/ERC20Burnable.behavior.js b/test/token/ERC20/behaviors/ERC20Burnable.behavior.js index c52594d1876..9c7bada7acc 100644 --- a/test/token/ERC20/behaviors/ERC20Burnable.behavior.js +++ b/test/token/ERC20/behaviors/ERC20Burnable.behavior.js @@ -32,7 +32,7 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) { expectEvent.inLogs(this.logs, 'Transfer', { from: owner, to: ZERO_ADDRESS, - value: amount, + value: amount }); }); } @@ -78,7 +78,7 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) { expectEvent.inLogs(this.logs, 'Transfer', { from: owner, to: ZERO_ADDRESS, - value: amount, + value: amount }); }); } diff --git a/test/token/ERC20/behaviors/ERC20Mintable.behavior.js b/test/token/ERC20/behaviors/ERC20Mintable.behavior.js index dbda9eeedbc..07b3837b086 100644 --- a/test/token/ERC20/behaviors/ERC20Mintable.behavior.js +++ b/test/token/ERC20/behaviors/ERC20Mintable.behavior.js @@ -38,7 +38,7 @@ function shouldBehaveLikeERC20Mintable (minter, [anyone]) { expectEvent.inLogs(this.logs, 'Transfer', { from: ZERO_ADDRESS, to: anyone, - value: amount, + value: amount }); }); } diff --git a/test/token/ERC721/ERC721.behavior.js b/test/token/ERC721/ERC721.behavior.js index ce56747def3..d2cefe743c7 100644 --- a/test/token/ERC721/ERC721.behavior.js +++ b/test/token/ERC721/ERC721.behavior.js @@ -92,7 +92,7 @@ function shouldBehaveLikeERC721 ( expectEvent.inLogs(logs, 'Transfer', { from: owner, to: this.toWhom, - tokenId: tokenId, + tokenId: tokenId }); }); } else { @@ -100,7 +100,7 @@ function shouldBehaveLikeERC721 ( expectEvent.inLogs(logs, 'Transfer', { from: owner, to: this.toWhom, - tokenId: tokenId, + tokenId: tokenId }); }); } @@ -165,7 +165,7 @@ function shouldBehaveLikeERC721 ( expectEvent.inLogs(logs, 'Transfer', { from: owner, to: owner, - tokenId: tokenId, + tokenId: tokenId }); }); @@ -341,7 +341,7 @@ function shouldBehaveLikeERC721 ( expectEvent.inLogs(logs, 'Approval', { owner: owner, approved: address, - tokenId: tokenId, + tokenId: tokenId }); }); }; @@ -451,7 +451,7 @@ function shouldBehaveLikeERC721 ( expectEvent.inLogs(logs, 'ApprovalForAll', { owner: owner, operator: operator, - approved: true, + approved: true }); }); }); @@ -473,7 +473,7 @@ function shouldBehaveLikeERC721 ( expectEvent.inLogs(logs, 'ApprovalForAll', { owner: owner, operator: operator, - approved: true, + approved: true }); }); @@ -501,7 +501,7 @@ function shouldBehaveLikeERC721 ( expectEvent.inLogs(logs, 'ApprovalForAll', { owner: owner, operator: operator, - approved: true, + approved: true }); }); }); diff --git a/test/token/ERC721/ERC721MintBurn.behavior.js b/test/token/ERC721/ERC721MintBurn.behavior.js index 8aeccd5d8b7..a4289d27a74 100644 --- a/test/token/ERC721/ERC721MintBurn.behavior.js +++ b/test/token/ERC721/ERC721MintBurn.behavior.js @@ -45,7 +45,7 @@ function shouldBehaveLikeMintAndBurnERC721 ( expectEvent.inLogs(logs, 'Transfer', { from: ZERO_ADDRESS, to: newOwner, - tokenId: thirdTokenId, + tokenId: thirdTokenId }); }); }); @@ -90,7 +90,7 @@ function shouldBehaveLikeMintAndBurnERC721 ( expectEvent.inLogs(logs, 'Transfer', { from: owner, to: ZERO_ADDRESS, - tokenId: tokenId, + tokenId: tokenId }); }); }); From 9427e0356ac47c2348f9de63e1fd8b565e6fc759 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Mon, 1 Oct 2018 19:05:04 +0530 Subject: [PATCH 08/11] fixex #1355 --- test/BreakInvariantBounty.test.js | 9 +++------ test/helpers/balanceDiff.js | 10 ++++++++++ 2 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 test/helpers/balanceDiff.js diff --git a/test/BreakInvariantBounty.test.js b/test/BreakInvariantBounty.test.js index 4c1f8b06c4e..d8e64bfc335 100644 --- a/test/BreakInvariantBounty.test.js +++ b/test/BreakInvariantBounty.test.js @@ -1,5 +1,6 @@ const { ethGetBalance, ethSendTransaction } = require('./helpers/web3'); const { sendEther } = require('./helpers/sendTransaction'); +const { balanceDifference } = require('./helpers/balanceDiff'); const expectEvent = require('./helpers/expectEvent'); const { assertRevert } = require('./helpers/assertRevert'); @@ -72,12 +73,8 @@ contract('BreakInvariantBounty', function ([_, owner, researcher, anyone, nonTar it('sends the reward to the researcher', async function () { await this.bounty.claim(this.target.address, { from: anyone }); - - const researcherPreBalance = await ethGetBalance(researcher); - await this.bounty.withdrawPayments(researcher); - const researcherPostBalance = await ethGetBalance(researcher); - - researcherPostBalance.sub(researcherPreBalance).should.be.bignumber.equal(reward); + let bal = await balanceDifference(researcher, () => this.bounty.withdrawPayments(researcher)); + bal.should.be.bignumber.equal(reward); (await ethGetBalance(this.bounty.address)).should.be.bignumber.equal(0); }); diff --git a/test/helpers/balanceDiff.js b/test/helpers/balanceDiff.js new file mode 100644 index 00000000000..e03059e21ae --- /dev/null +++ b/test/helpers/balanceDiff.js @@ -0,0 +1,10 @@ +async function balanceDifference (account, method) { + let balanceBefore = web3.eth.getBalance(account); + await method(account); + let balanceAfter = web3.eth.getBalance(account); + return balanceAfter.minus(balanceBefore); + } + + module.exports = { + balanceDifference + }; \ No newline at end of file From 84863fc6459eb6b8d72ac49204b70320b5a1456c Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Mon, 1 Oct 2018 19:15:25 +0530 Subject: [PATCH 09/11] linting --- contracts/ECRecovery.sol | 53 ------------------- test/BreakInvariantBounty.test.js | 2 +- test/crowdsale/AllowanceCrowdsale.test.js | 2 +- test/crowdsale/Crowdsale.test.js | 4 +- test/crowdsale/MintedCrowdsale.behavior.js | 2 +- test/helpers/balanceDiff.js | 18 +++---- test/library/ECRecovery.test.js | 6 +-- test/payment/Escrow.behavior.js | 4 +- test/token/ERC20/ERC20.test.js | 14 ++--- .../ERC20/behaviors/ERC20Burnable.behavior.js | 4 +- .../ERC20/behaviors/ERC20Mintable.behavior.js | 2 +- test/token/ERC721/ERC721.behavior.js | 14 ++--- test/token/ERC721/ERC721MintBurn.behavior.js | 4 +- 13 files changed, 38 insertions(+), 91 deletions(-) delete mode 100644 contracts/ECRecovery.sol diff --git a/contracts/ECRecovery.sol b/contracts/ECRecovery.sol deleted file mode 100644 index c5b6d8f646c..00000000000 --- a/contracts/ECRecovery.sol +++ /dev/null @@ -1,53 +0,0 @@ -pragma solidity ^0.4.18; - - -/** - * @title Eliptic curve signature operations - * - * @dev Based on https://gist.github.com/axic/5b33912c6f61ae6fd96d6c4a47afde6d - */ - -library ECRecovery { - - /** - * @dev Recover signer address from a message by using his signature - * @param hash bytes32 message, the hash is the signed message. What is recovered is the signer address. - * @param sig bytes signature, the signature is generated using web3.eth.sign() - */ - function recover(bytes32 hash, bytes sig) public pure returns (address) { - bytes32 r; - bytes32 s; - uint8 v; - - //Check the signature length - if (sig.length != 65) { - return (address(0)); - } - - // Divide the signature in r, s and v variables - assembly { - r := mload(add(sig, 32)) - s := mload(add(sig, 64)) - v := byte(0, mload(add(sig, 96))) - } - - // Version of signature should be 27 or 28, but 0 and 1 are also possible versions - if (v < 27) { - v += 27; - } - - // If the version is correct return the signer address - if (v != 27 && v != 28) { - return (address(0)); - } else { - - /* - * https://github.com/ethereum/go-ethereum/issues/3731 - */ - - bytes memory prefix = "\x19Ethereum Signed Message:\n32"; - return ecrecover(keccak256(prefix, hash), v, r, s); - } - } - -} diff --git a/test/BreakInvariantBounty.test.js b/test/BreakInvariantBounty.test.js index d8e64bfc335..1be0a168d58 100644 --- a/test/BreakInvariantBounty.test.js +++ b/test/BreakInvariantBounty.test.js @@ -73,7 +73,7 @@ contract('BreakInvariantBounty', function ([_, owner, researcher, anyone, nonTar it('sends the reward to the researcher', async function () { await this.bounty.claim(this.target.address, { from: anyone }); - let bal = await balanceDifference(researcher, () => this.bounty.withdrawPayments(researcher)); + const bal = await balanceDifference(researcher, () => this.bounty.withdrawPayments(researcher)); bal.should.be.bignumber.equal(reward); (await ethGetBalance(this.bounty.address)).should.be.bignumber.equal(0); }); diff --git a/test/crowdsale/AllowanceCrowdsale.test.js b/test/crowdsale/AllowanceCrowdsale.test.js index 8e57a841b24..c0ff4cd91ba 100644 --- a/test/crowdsale/AllowanceCrowdsale.test.js +++ b/test/crowdsale/AllowanceCrowdsale.test.js @@ -46,7 +46,7 @@ contract('AllowanceCrowdsale', function ([_, investor, wallet, purchaser, tokenW purchaser: investor, beneficiary: investor, value: value, - amount: expectedTokenAmount + amount: expectedTokenAmount, }); }); diff --git a/test/crowdsale/Crowdsale.test.js b/test/crowdsale/Crowdsale.test.js index f691c951576..4113f7cb428 100644 --- a/test/crowdsale/Crowdsale.test.js +++ b/test/crowdsale/Crowdsale.test.js @@ -87,7 +87,7 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) { purchaser: investor, beneficiary: investor, value: value, - amount: expectedTokenAmount + amount: expectedTokenAmount, }); }); @@ -111,7 +111,7 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) { purchaser: purchaser, beneficiary: investor, value: value, - amount: expectedTokenAmount + amount: expectedTokenAmount, }); }); diff --git a/test/crowdsale/MintedCrowdsale.behavior.js b/test/crowdsale/MintedCrowdsale.behavior.js index c55850cd9a4..ab8dc8259cc 100644 --- a/test/crowdsale/MintedCrowdsale.behavior.js +++ b/test/crowdsale/MintedCrowdsale.behavior.js @@ -25,7 +25,7 @@ function shouldBehaveLikeMintedCrowdsale ([_, investor, wallet, purchaser], rate purchaser: investor, beneficiary: investor, value: value, - amount: expectedTokenAmount + amount: expectedTokenAmount, }); }); diff --git a/test/helpers/balanceDiff.js b/test/helpers/balanceDiff.js index e03059e21ae..8478d21136e 100644 --- a/test/helpers/balanceDiff.js +++ b/test/helpers/balanceDiff.js @@ -1,10 +1,10 @@ async function balanceDifference (account, method) { - let balanceBefore = web3.eth.getBalance(account); - await method(account); - let balanceAfter = web3.eth.getBalance(account); - return balanceAfter.minus(balanceBefore); - } - - module.exports = { - balanceDifference - }; \ No newline at end of file + const balanceBefore = web3.eth.getBalance(account); + await method(account); + const balanceAfter = web3.eth.getBalance(account); + return balanceAfter.minus(balanceBefore); +} + +module.exports = { + balanceDifference, +}; diff --git a/test/library/ECRecovery.test.js b/test/library/ECRecovery.test.js index ef354a76f05..07d603d8ca6 100644 --- a/test/library/ECRecovery.test.js +++ b/test/library/ECRecovery.test.js @@ -1,5 +1,5 @@ -var ECRecoveryMock = artifacts.require('ECRecoveryMock'); -var ECRecoveryLib = artifacts.require('ECRecovery'); +const ECRecoveryMock = artifacts.require('ECRecoveryMock'); +const ECRecoveryLib = artifacts.require('ECRecovery'); contract('ECRecovery', function (accounts) { let ecrecovery; @@ -31,7 +31,7 @@ contract('ECRecovery', function (accounts) { it('recover should fail when a wrong hash is sent', async function () { // Create the signature using account[0] - let signature = web3.eth.sign(accounts[0], web3.sha3(TEST_MESSAGE)); + const signature = web3.eth.sign(accounts[0], web3.sha3(TEST_MESSAGE)); // Recover the signer address from the generated message and wrong signature. await ecrecovery.recover(web3.sha3(TEST_MESSAGE).substring(2), signature); diff --git a/test/payment/Escrow.behavior.js b/test/payment/Escrow.behavior.js index fce4bd69217..57f1fe5d0ac 100644 --- a/test/payment/Escrow.behavior.js +++ b/test/payment/Escrow.behavior.js @@ -34,7 +34,7 @@ function shouldBehaveLikeEscrow (primary, [payee1, payee2]) { const { logs } = await this.escrow.deposit(payee1, { from: primary, value: amount }); expectEvent.inLogs(logs, 'Deposited', { payee: payee1, - weiAmount: amount + weiAmount: amount, }); }); @@ -87,7 +87,7 @@ function shouldBehaveLikeEscrow (primary, [payee1, payee2]) { const { logs } = await this.escrow.withdraw(payee1, { from: primary }); expectEvent.inLogs(logs, 'Withdrawn', { payee: payee1, - weiAmount: amount + weiAmount: amount, }); }); }); diff --git a/test/token/ERC20/ERC20.test.js b/test/token/ERC20/ERC20.test.js index 283e8752a09..e991c2ae6d1 100644 --- a/test/token/ERC20/ERC20.test.js +++ b/test/token/ERC20/ERC20.test.js @@ -65,7 +65,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) { expectEvent.inLogs(logs, 'Transfer', { from: owner, to: to, - value: amount + value: amount, }); }); }); @@ -93,7 +93,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) { expectEvent.inLogs(logs, 'Approval', { owner: owner, spender: spender, - value: amount + value: amount, }); }); @@ -127,7 +127,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) { expectEvent.inLogs(logs, 'Approval', { owner: owner, spender: spender, - value: amount + value: amount, }); }); @@ -197,7 +197,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) { expectEvent.inLogs(logs, 'Transfer', { from: owner, to: to, - value: amount + value: amount, }); }); }); @@ -272,7 +272,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) { expectEvent.inLogs(logs, 'Approval', { owner: owner, spender: spender, - value: 0 + value: 0, }); }); @@ -329,7 +329,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) { expectEvent.inLogs(logs, 'Approval', { owner: owner, spender: spender, - value: amount + value: amount, }); }); @@ -363,7 +363,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) { expectEvent.inLogs(logs, 'Approval', { owner: owner, spender: spender, - value: amount + value: amount, }); }); diff --git a/test/token/ERC20/behaviors/ERC20Burnable.behavior.js b/test/token/ERC20/behaviors/ERC20Burnable.behavior.js index 9c7bada7acc..c52594d1876 100644 --- a/test/token/ERC20/behaviors/ERC20Burnable.behavior.js +++ b/test/token/ERC20/behaviors/ERC20Burnable.behavior.js @@ -32,7 +32,7 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) { expectEvent.inLogs(this.logs, 'Transfer', { from: owner, to: ZERO_ADDRESS, - value: amount + value: amount, }); }); } @@ -78,7 +78,7 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) { expectEvent.inLogs(this.logs, 'Transfer', { from: owner, to: ZERO_ADDRESS, - value: amount + value: amount, }); }); } diff --git a/test/token/ERC20/behaviors/ERC20Mintable.behavior.js b/test/token/ERC20/behaviors/ERC20Mintable.behavior.js index 07b3837b086..dbda9eeedbc 100644 --- a/test/token/ERC20/behaviors/ERC20Mintable.behavior.js +++ b/test/token/ERC20/behaviors/ERC20Mintable.behavior.js @@ -38,7 +38,7 @@ function shouldBehaveLikeERC20Mintable (minter, [anyone]) { expectEvent.inLogs(this.logs, 'Transfer', { from: ZERO_ADDRESS, to: anyone, - value: amount + value: amount, }); }); } diff --git a/test/token/ERC721/ERC721.behavior.js b/test/token/ERC721/ERC721.behavior.js index d2cefe743c7..ce56747def3 100644 --- a/test/token/ERC721/ERC721.behavior.js +++ b/test/token/ERC721/ERC721.behavior.js @@ -92,7 +92,7 @@ function shouldBehaveLikeERC721 ( expectEvent.inLogs(logs, 'Transfer', { from: owner, to: this.toWhom, - tokenId: tokenId + tokenId: tokenId, }); }); } else { @@ -100,7 +100,7 @@ function shouldBehaveLikeERC721 ( expectEvent.inLogs(logs, 'Transfer', { from: owner, to: this.toWhom, - tokenId: tokenId + tokenId: tokenId, }); }); } @@ -165,7 +165,7 @@ function shouldBehaveLikeERC721 ( expectEvent.inLogs(logs, 'Transfer', { from: owner, to: owner, - tokenId: tokenId + tokenId: tokenId, }); }); @@ -341,7 +341,7 @@ function shouldBehaveLikeERC721 ( expectEvent.inLogs(logs, 'Approval', { owner: owner, approved: address, - tokenId: tokenId + tokenId: tokenId, }); }); }; @@ -451,7 +451,7 @@ function shouldBehaveLikeERC721 ( expectEvent.inLogs(logs, 'ApprovalForAll', { owner: owner, operator: operator, - approved: true + approved: true, }); }); }); @@ -473,7 +473,7 @@ function shouldBehaveLikeERC721 ( expectEvent.inLogs(logs, 'ApprovalForAll', { owner: owner, operator: operator, - approved: true + approved: true, }); }); @@ -501,7 +501,7 @@ function shouldBehaveLikeERC721 ( expectEvent.inLogs(logs, 'ApprovalForAll', { owner: owner, operator: operator, - approved: true + approved: true, }); }); }); diff --git a/test/token/ERC721/ERC721MintBurn.behavior.js b/test/token/ERC721/ERC721MintBurn.behavior.js index a4289d27a74..8aeccd5d8b7 100644 --- a/test/token/ERC721/ERC721MintBurn.behavior.js +++ b/test/token/ERC721/ERC721MintBurn.behavior.js @@ -45,7 +45,7 @@ function shouldBehaveLikeMintAndBurnERC721 ( expectEvent.inLogs(logs, 'Transfer', { from: ZERO_ADDRESS, to: newOwner, - tokenId: thirdTokenId + tokenId: thirdTokenId, }); }); }); @@ -90,7 +90,7 @@ function shouldBehaveLikeMintAndBurnERC721 ( expectEvent.inLogs(logs, 'Transfer', { from: owner, to: ZERO_ADDRESS, - tokenId: tokenId + tokenId: tokenId, }); }); }); From 7d6e8d67c07921af902ba7484338b083800563f9 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Mon, 1 Oct 2018 20:32:13 +0530 Subject: [PATCH 10/11] suggested changes --- .eslintrc | 2 +- test/helpers/balanceDiff.js | 4 ++-- test/library/ECRecovery.test.js | 40 --------------------------------- 3 files changed, 3 insertions(+), 43 deletions(-) delete mode 100644 test/library/ECRecovery.test.js diff --git a/.eslintrc b/.eslintrc index 117135b36f9..c15a4d51515 100644 --- a/.eslintrc +++ b/.eslintrc @@ -25,7 +25,7 @@ // Code style "camelcase": ["error", {"properties": "always"}], - "comma-dangle": ["warn", "always-multiline"], + "comma-dangle": ["error", "always-multiline"], "comma-spacing": ["error", {"before": false, "after": true}], "dot-notation": ["error", {"allowKeywords": true, "allowPattern": ""}], "eol-last": ["error", "always"], diff --git a/test/helpers/balanceDiff.js b/test/helpers/balanceDiff.js index 8478d21136e..8f88ba40045 100644 --- a/test/helpers/balanceDiff.js +++ b/test/helpers/balanceDiff.js @@ -1,6 +1,6 @@ -async function balanceDifference (account, method) { +async function balanceDifference (account, promise) { const balanceBefore = web3.eth.getBalance(account); - await method(account); + await promise(); const balanceAfter = web3.eth.getBalance(account); return balanceAfter.minus(balanceBefore); } diff --git a/test/library/ECRecovery.test.js b/test/library/ECRecovery.test.js deleted file mode 100644 index 07d603d8ca6..00000000000 --- a/test/library/ECRecovery.test.js +++ /dev/null @@ -1,40 +0,0 @@ -const ECRecoveryMock = artifacts.require('ECRecoveryMock'); -const ECRecoveryLib = artifacts.require('ECRecovery'); - -contract('ECRecovery', function (accounts) { - let ecrecovery; - const TEST_MESSAGE = 'OpenZeppelin'; - - before(async function () { - const ecRecoveryLib = await ECRecoveryLib.new(); - ECRecoveryMock.link('ECRecovery', ecRecoveryLib.address); - ecrecovery = await ECRecoveryMock.new(); - }); - - it('recover using web3.eth.sign()', async function () { - // Create the signature using account[0] - const signature = web3.eth.sign(accounts[0], web3.sha3(TEST_MESSAGE)); - - // Recover the signer address from the generated message and signature. - await ecrecovery.recover(web3.sha3(TEST_MESSAGE), signature); - assert.equal(accounts[0], await ecrecovery.addrRecovered()); - }); - - it('recover using web3.eth.sign() should return wrong signer', async function () { - // Create the signature using account[0] - const signature = web3.eth.sign(accounts[0], web3.sha3(TEST_MESSAGE)); - - // Recover the signer address from the generated message and wrong signature. - await ecrecovery.recover(web3.sha3('Test'), signature); - assert.notEqual(accounts[0], await ecrecovery.addrRecovered()); - }); - - it('recover should fail when a wrong hash is sent', async function () { - // Create the signature using account[0] - const signature = web3.eth.sign(accounts[0], web3.sha3(TEST_MESSAGE)); - - // Recover the signer address from the generated message and wrong signature. - await ecrecovery.recover(web3.sha3(TEST_MESSAGE).substring(2), signature); - assert.equal('0x0000000000000000000000000000000000000000', await ecrecovery.addrRecovered()); - }); -}); From 07edee6beb7235cde27f3e84b0482257055c8d23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Venturo?= Date: Mon, 1 Oct 2018 12:20:21 -0300 Subject: [PATCH 11/11] Update BreakInvariantBounty.test.js --- test/BreakInvariantBounty.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/BreakInvariantBounty.test.js b/test/BreakInvariantBounty.test.js index 1be0a168d58..ff8e0f7bd03 100644 --- a/test/BreakInvariantBounty.test.js +++ b/test/BreakInvariantBounty.test.js @@ -73,8 +73,8 @@ contract('BreakInvariantBounty', function ([_, owner, researcher, anyone, nonTar it('sends the reward to the researcher', async function () { await this.bounty.claim(this.target.address, { from: anyone }); - const bal = await balanceDifference(researcher, () => this.bounty.withdrawPayments(researcher)); - bal.should.be.bignumber.equal(reward); + (await balanceDifference(researcher, () => this.bounty.withdrawPayments(researcher))) + .should.be.bignumber.equal(reward); (await ethGetBalance(this.bounty.address)).should.be.bignumber.equal(0); });