From eae40c93b63995f1c1ebe3f16340177485003309 Mon Sep 17 00:00:00 2001 From: Aniket <30843294+Aniket-Engg@users.noreply.github.com> Date: Thu, 4 Oct 2018 18:27:37 +0530 Subject: [PATCH] `this` is used in tests (#1380) * signing prefix added * Minor improvement * Tests changed * Successfully tested * Minor improvements * Minor improvements * Revert "Dangling commas are now required. (#1359)" This reverts commit a6889776f46adca374b6ebf014aa7b0038112a9d. * updates * fixes #1200 * suggested change (cherry picked from commit b41b125c15c9ccf8a002a43ed64b5349982c2fb6) --- test/examples/SimpleToken.test.js | 18 ++++++++---------- test/library/MerkleProof.test.js | 10 ++++------ test/token/ERC20/ERC20Detailed.test.js | 10 ++++------ test/utils/ReentrancyGuard.test.js | 13 +++++-------- 4 files changed, 21 insertions(+), 30 deletions(-) diff --git a/test/examples/SimpleToken.test.js b/test/examples/SimpleToken.test.js index 49b8a7aa4..e7f8fa5c1 100644 --- a/test/examples/SimpleToken.test.js +++ b/test/examples/SimpleToken.test.js @@ -9,32 +9,30 @@ require('chai') .should(); contract('SimpleToken', function ([_, creator]) { - let token; - beforeEach(async function () { - token = await SimpleToken.new({ from: creator }); + this.token = await SimpleToken.new({ from: creator }); }); it('has a name', async function () { - (await token.name()).should.equal('SimpleToken'); + (await this.token.name()).should.equal('SimpleToken'); }); it('has a symbol', async function () { - (await token.symbol()).should.equal('SIM'); + (await this.token.symbol()).should.equal('SIM'); }); it('has 18 decimals', async function () { - (await token.decimals()).should.be.bignumber.equal(18); + (await this.token.decimals()).should.be.bignumber.equal(18); }); it('assigns the initial total supply to the creator', async function () { - const totalSupply = await token.totalSupply(); - const creatorBalance = await token.balanceOf(creator); + const totalSupply = await this.token.totalSupply(); + const creatorBalance = await this.token.balanceOf(creator); creatorBalance.should.be.bignumber.equal(totalSupply); - const receipt = await web3.eth.getTransactionReceipt(token.transactionHash); - const logs = decodeLogs(receipt.logs, SimpleToken, token.address); + const receipt = await web3.eth.getTransactionReceipt(this.token.transactionHash); + const logs = decodeLogs(receipt.logs, SimpleToken, this.token.address); logs.length.should.equal(1); logs[0].event.should.equal('Transfer'); logs[0].args.from.valueOf().should.equal(ZERO_ADDRESS); diff --git a/test/library/MerkleProof.test.js b/test/library/MerkleProof.test.js index 6674880b7..b5d8fbe07 100644 --- a/test/library/MerkleProof.test.js +++ b/test/library/MerkleProof.test.js @@ -7,10 +7,8 @@ require('chai') .should(); contract('MerkleProof', function () { - let merkleProof; - beforeEach(async function () { - merkleProof = await MerkleProofWrapper.new(); + this.merkleProof = await MerkleProofWrapper.new(); }); describe('verify', function () { @@ -24,7 +22,7 @@ contract('MerkleProof', function () { const leaf = bufferToHex(sha3(elements[0])); - (await merkleProof.verify(proof, root, leaf)).should.equal(true); + (await this.merkleProof.verify(proof, root, leaf)).should.equal(true); }); it('should return false for an invalid Merkle proof', async function () { @@ -40,7 +38,7 @@ contract('MerkleProof', function () { const badProof = badMerkleTree.getHexProof(badElements[0]); - (await merkleProof.verify(badProof, correctRoot, correctLeaf)).should.equal(false); + (await this.merkleProof.verify(badProof, correctRoot, correctLeaf)).should.equal(false); }); it('should return false for a Merkle proof of invalid length', async function () { @@ -54,7 +52,7 @@ contract('MerkleProof', function () { const leaf = bufferToHex(sha3(elements[0])); - (await merkleProof.verify(badProof, root, leaf)).should.equal(false); + (await this.merkleProof.verify(badProof, root, leaf)).should.equal(false); }); }); }); diff --git a/test/token/ERC20/ERC20Detailed.test.js b/test/token/ERC20/ERC20Detailed.test.js index 71b22a7b9..7965b7e9d 100644 --- a/test/token/ERC20/ERC20Detailed.test.js +++ b/test/token/ERC20/ERC20Detailed.test.js @@ -7,25 +7,23 @@ require('chai') const ERC20DetailedMock = artifacts.require('ERC20DetailedMock'); contract('ERC20Detailed', function () { - let detailedERC20 = null; - const _name = 'My Detailed ERC20'; const _symbol = 'MDT'; const _decimals = 18; beforeEach(async function () { - detailedERC20 = await ERC20DetailedMock.new(_name, _symbol, _decimals); + this.detailedERC20 = await ERC20DetailedMock.new(_name, _symbol, _decimals); }); it('has a name', async function () { - (await detailedERC20.name()).should.be.equal(_name); + (await this.detailedERC20.name()).should.be.equal(_name); }); it('has a symbol', async function () { - (await detailedERC20.symbol()).should.be.equal(_symbol); + (await this.detailedERC20.symbol()).should.be.equal(_symbol); }); it('has an amount of decimals', async function () { - (await detailedERC20.decimals()).should.be.bignumber.equal(_decimals); + (await this.detailedERC20.decimals()).should.be.bignumber.equal(_decimals); }); }); diff --git a/test/utils/ReentrancyGuard.test.js b/test/utils/ReentrancyGuard.test.js index 27430652c..3952b2fcb 100644 --- a/test/utils/ReentrancyGuard.test.js +++ b/test/utils/ReentrancyGuard.test.js @@ -9,17 +9,14 @@ require('chai') .should(); contract('ReentrancyGuard', function () { - let reentrancyMock; - beforeEach(async function () { - reentrancyMock = await ReentrancyMock.new(); - const initialCounter = await reentrancyMock.counter(); - initialCounter.should.be.bignumber.equal(0); + this.reentrancyMock = await ReentrancyMock.new(); + (await this.reentrancyMock.counter()).should.be.bignumber.equal(0); }); it('should not allow remote callback', async function () { const attacker = await ReentrancyAttack.new(); - await expectThrow(reentrancyMock.countAndCall(attacker.address)); + await expectThrow(this.reentrancyMock.countAndCall(attacker.address)); }); // The following are more side-effects than intended behavior: @@ -27,10 +24,10 @@ contract('ReentrancyGuard', function () { // in the side-effects. it('should not allow local recursion', async function () { - await expectThrow(reentrancyMock.countLocalRecursive(10)); + await expectThrow(this.reentrancyMock.countLocalRecursive(10)); }); it('should not allow indirect local recursion', async function () { - await expectThrow(reentrancyMock.countThisRecursive(10)); + await expectThrow(this.reentrancyMock.countThisRecursive(10)); }); });