From d07bdccc0c1badc46783783fa0ba94f2b9fdeada Mon Sep 17 00:00:00 2001 From: Matt Condon Date: Fri, 24 Nov 2017 15:37:36 +0200 Subject: [PATCH] feat: manually fix linting errors across tests --- test/BasicToken.test.js | 6 +++--- test/CanReclaimToken.test.js | 2 +- test/CappedToken.test.js | 3 +-- test/Contactable.test.js | 4 +--- test/DayLimit.test.js | 5 +++-- test/ECRecovery.test.js | 3 ++- test/HasNoContracts.test.js | 2 +- test/HasNoEther.test.js | 3 +-- test/HasNoTokens.test.js | 2 +- test/MerkleProof.test.js | 3 ++- test/PullPayment.test.js | 14 +++++++------- test/RefundVault.test.js | 6 +++--- test/RefundableCrowdsale.test.js | 3 ++- test/SafeMath.test.js | 12 ++++++------ test/SampleCrowdsale.test.js | 23 +++++++++++++++-------- test/SplitPayment.test.js | 2 +- test/StandardToken.test.js | 6 +++--- test/TokenTimelock.test.js | 6 +++--- test/TokenVesting.test.js | 10 +++++----- test/helpers/hashMessage.js | 2 +- test/helpers/merkleTree.js | 2 +- test/helpers/toPromise.js | 4 ++-- truffle-config.js | 10 +++++----- 23 files changed, 70 insertions(+), 63 deletions(-) diff --git a/test/BasicToken.test.js b/test/BasicToken.test.js index 093bcbfbf12..9775b704068 100644 --- a/test/BasicToken.test.js +++ b/test/BasicToken.test.js @@ -12,7 +12,7 @@ contract('BasicToken', function (accounts) { it('should return correct balances after transfer', async function () { let token = await BasicTokenMock.new(accounts[0], 100); - let transfer = await token.transfer(accounts[1], 100); + await token.transfer(accounts[1], 100); let firstAccountBalance = await token.balanceOf(accounts[0]); assert.equal(firstAccountBalance, 0); @@ -24,7 +24,7 @@ contract('BasicToken', function (accounts) { it('should throw an error when trying to transfer more than balance', async function () { let token = await BasicTokenMock.new(accounts[0], 100); try { - let transfer = await token.transfer(accounts[1], 101); + await token.transfer(accounts[1], 101); assert.fail('should have thrown before'); } catch (error) { assertRevert(error); @@ -34,7 +34,7 @@ contract('BasicToken', function (accounts) { it('should throw an error when trying to transfer to 0x0', async function () { let token = await BasicTokenMock.new(accounts[0], 100); try { - let transfer = await token.transfer(0x0, 100); + await token.transfer(0x0, 100); assert.fail('should have thrown before'); } catch (error) { assertRevert(error); diff --git a/test/CanReclaimToken.test.js b/test/CanReclaimToken.test.js index 638717f8666..8a4b927934a 100644 --- a/test/CanReclaimToken.test.js +++ b/test/CanReclaimToken.test.js @@ -1,6 +1,6 @@ import expectThrow from './helpers/expectThrow'; -import toPromise from './helpers/toPromise'; + const CanReclaimToken = artifacts.require('../contracts/ownership/CanReclaimToken.sol'); const BasicTokenMock = artifacts.require('./mocks/BasicTokenMock.sol'); diff --git a/test/CappedToken.test.js b/test/CappedToken.test.js index f8335e20263..d015c19118d 100644 --- a/test/CappedToken.test.js +++ b/test/CappedToken.test.js @@ -1,9 +1,8 @@ import expectThrow from './helpers/expectThrow'; import ether from './helpers/ether'; -var CappedToken = artifacts.require('../contracts/Tokens/CappedToken.sol'); -const BigNumber = web3.BigNumber; +var CappedToken = artifacts.require('../contracts/Tokens/CappedToken.sol'); contract('Capped', function (accounts) { const cap = ether(1000); diff --git a/test/Contactable.test.js b/test/Contactable.test.js index 9893e3a979a..bb7f6d684ba 100644 --- a/test/Contactable.test.js +++ b/test/Contactable.test.js @@ -1,6 +1,4 @@ -const assertRevert = require('./helpers/assertRevert'); - var Contactable = artifacts.require('../contracts/ownership/Contactable.sol'); contract('Contactable', function (accounts) { @@ -12,7 +10,7 @@ contract('Contactable', function (accounts) { it('should have an empty contact info', async function () { let info = await contactable.contactInformation(); - assert.isTrue(info == ''); + assert.isTrue(info === ''); }); describe('after setting the contact information', function () { diff --git a/test/DayLimit.test.js b/test/DayLimit.test.js index ab712d3546b..1378f862704 100644 --- a/test/DayLimit.test.js +++ b/test/DayLimit.test.js @@ -1,9 +1,10 @@ -const assertRevert = require('./helpers/assertRevert'); import latestTime from './helpers/latestTime'; import { increaseTimeTo, duration } from './helpers/increaseTime'; -var DayLimitMock = artifacts.require('./mocks/DayLimitMock.sol'); +const assertRevert = require('./helpers/assertRevert'); + +const DayLimitMock = artifacts.require('./mocks/DayLimitMock.sol'); contract('DayLimit', function (accounts) { let dayLimit; diff --git a/test/ECRecovery.test.js b/test/ECRecovery.test.js index 983816f7fbc..d59c29112a2 100644 --- a/test/ECRecovery.test.js +++ b/test/ECRecovery.test.js @@ -1,5 +1,4 @@ var ECRecovery = artifacts.require('../contracts/ECRecovery.sol'); -var utils = require('ethereumjs-util'); var hashMessage = require('./helpers/hashMessage.js'); contract('ECRecovery', function (accounts) { @@ -13,6 +12,7 @@ contract('ECRecovery', function (accounts) { // Signature generated outside testrpc with method web3.eth.sign(signer, message) let signer = '0x2cc1166f6212628a0deef2b33befb2187d35b86c'; let message = '0x7dbaf558b0a1a5dc7a67202117ab143c1d8605a983e4a743bc06fcc03162dc0d'; // web3.sha3('OpenZeppelin') + // eslint-disable-next-line max-len let signature = '0x5d99b6f7f6d1f73d1a26497f2b1c89b24c0993913f86e9a2d02cd69887d9c94f3c880358579d811b21dd1b7fd9bb01c1d81d10e69f0384e675c32b39643be89200'; assert.equal(signer, await ecrecovery.recover(message, signature)); }); @@ -21,6 +21,7 @@ contract('ECRecovery', function (accounts) { // Signature generated outside testrpc with method web3.eth.sign(signer, message) let signer = '0x1e318623ab09fe6de3c9b8672098464aeda9100e'; let message = '0x7dbaf558b0a1a5dc7a67202117ab143c1d8605a983e4a743bc06fcc03162dc0d'; // web3.sha3('OpenZeppelin') + // eslint-disable-next-line max-len let signature = '0x331fe75a821c982f9127538858900d87d3ec1f9f737338ad67cad133fa48feff48e6fa0c18abc62e42820f05943e47af3e9fbe306ce74d64094bdf1691ee53e001'; assert.equal(signer, await ecrecovery.recover(message, signature)); }); diff --git a/test/HasNoContracts.test.js b/test/HasNoContracts.test.js index 384e1d5abc8..e2743731f99 100644 --- a/test/HasNoContracts.test.js +++ b/test/HasNoContracts.test.js @@ -1,6 +1,6 @@ import expectThrow from './helpers/expectThrow'; -import toPromise from './helpers/toPromise'; + const Ownable = artifacts.require('../contracts/ownership/Ownable.sol'); const HasNoContracts = artifacts.require( '../contracts/ownership/HasNoContracts.sol', diff --git a/test/HasNoEther.test.js b/test/HasNoEther.test.js index 9e37ea35155..e7ec486a1dd 100644 --- a/test/HasNoEther.test.js +++ b/test/HasNoEther.test.js @@ -1,7 +1,6 @@ import expectThrow from './helpers/expectThrow'; import toPromise from './helpers/toPromise'; -const HasNoEther = artifacts.require('../contracts/lifecycle/HasNoEther.sol'); const HasNoEtherTest = artifacts.require('../mocks/HasNoEtherTest.sol'); const ForceEther = artifacts.require('../mocks/ForceEther.sol'); @@ -9,7 +8,7 @@ contract('HasNoEther', function (accounts) { const amount = web3.toWei('1', 'ether'); it('should be constructorable', async function () { - let hasNoEther = await HasNoEtherTest.new(); + await HasNoEtherTest.new(); }); it('should not accept ether in constructor', async function () { diff --git a/test/HasNoTokens.test.js b/test/HasNoTokens.test.js index a235fd11a3a..cb397deea56 100644 --- a/test/HasNoTokens.test.js +++ b/test/HasNoTokens.test.js @@ -1,6 +1,6 @@ import expectThrow from './helpers/expectThrow'; -import toPromise from './helpers/toPromise'; + const HasNoTokens = artifacts.require('../contracts/lifecycle/HasNoTokens.sol'); const ERC23TokenMock = artifacts.require('./mocks/ERC23TokenMock.sol'); diff --git a/test/MerkleProof.test.js b/test/MerkleProof.test.js index c0109398df7..f55d6ebc8b5 100644 --- a/test/MerkleProof.test.js +++ b/test/MerkleProof.test.js @@ -1,8 +1,9 @@ -var MerkleProof = artifacts.require('./MerkleProof.sol'); import MerkleTree from './helpers/merkleTree.js'; import { sha3, bufferToHex } from 'ethereumjs-util'; +var MerkleProof = artifacts.require('./MerkleProof.sol'); + contract('MerkleProof', function (accounts) { let merkleProof; diff --git a/test/PullPayment.test.js b/test/PullPayment.test.js index 3840bce6405..176b182dd4d 100644 --- a/test/PullPayment.test.js +++ b/test/PullPayment.test.js @@ -14,7 +14,7 @@ contract('PullPayment', function (accounts) { it('can record an async payment correctly', async function () { let AMOUNT = 100; - let callSend = await ppce.callSend(accounts[0], AMOUNT); + await ppce.callSend(accounts[0], AMOUNT); let paymentsToAccount0 = await ppce.payments(accounts[0]); let totalPayments = await ppce.totalPayments(); @@ -23,8 +23,8 @@ contract('PullPayment', function (accounts) { }); it('can add multiple balances on one account', async function () { - let call1 = await ppce.callSend(accounts[0], 200); - let call2 = await ppce.callSend(accounts[0], 300); + await ppce.callSend(accounts[0], 200); + await ppce.callSend(accounts[0], 300); let paymentsToAccount0 = await ppce.payments(accounts[0]); let totalPayments = await ppce.totalPayments(); @@ -33,8 +33,8 @@ contract('PullPayment', function (accounts) { }); it('can add balances on multiple accounts', async function () { - let call1 = await ppce.callSend(accounts[0], 200); - let call2 = await ppce.callSend(accounts[1], 300); + await ppce.callSend(accounts[0], 200); + await ppce.callSend(accounts[1], 300); let paymentsToAccount0 = await ppce.payments(accounts[0]); assert.equal(paymentsToAccount0, 200); @@ -50,7 +50,7 @@ contract('PullPayment', function (accounts) { let payee = accounts[1]; let initialBalance = web3.eth.getBalance(payee); - let call1 = await ppce.callSend(payee, amount); + await ppce.callSend(payee, amount); let payment1 = await ppce.payments(payee); assert.equal(payment1, amount); @@ -58,7 +58,7 @@ contract('PullPayment', function (accounts) { let totalPayments = await ppce.totalPayments(); assert.equal(totalPayments, amount); - let withdraw = await ppce.withdrawPayments({ from: payee }); + await ppce.withdrawPayments({ from: payee }); let payment2 = await ppce.payments(payee); assert.equal(payment2, 0); diff --git a/test/RefundVault.test.js b/test/RefundVault.test.js index fb22ded8ffe..0ce1dd74c68 100644 --- a/test/RefundVault.test.js +++ b/test/RefundVault.test.js @@ -1,3 +1,6 @@ +import ether from './helpers/ether'; +import EVMRevert from './helpers/EVMRevert'; + const BigNumber = web3.BigNumber; require('chai') @@ -5,9 +8,6 @@ require('chai') .use(require('chai-bignumber')(BigNumber)) .should(); -import ether from './helpers/ether'; -import EVMRevert from './helpers/EVMRevert'; - const RefundVault = artifacts.require('RefundVault'); contract('RefundVault', function ([_, owner, wallet, investor]) { diff --git a/test/RefundableCrowdsale.test.js b/test/RefundableCrowdsale.test.js index ad28799131a..84ced3bc7f1 100644 --- a/test/RefundableCrowdsale.test.js +++ b/test/RefundableCrowdsale.test.js @@ -33,7 +33,8 @@ contract('RefundableCrowdsale', function ([_, owner, wallet, investor]) { describe('creating a valid crowdsale', function () { it('should fail with zero goal', async function () { - await RefundableCrowdsale.new(this.startTime, this.endTime, rate, wallet, 0, { from: owner }).should.be.rejectedWith(EVMRevert); + await RefundableCrowdsale.new(this.startTime, this.endTime, rate, wallet, 0, { from: owner }) + .should.be.rejectedWith(EVMRevert); }); }); diff --git a/test/SafeMath.test.js b/test/SafeMath.test.js index 1098b579550..f2faaf638a1 100644 --- a/test/SafeMath.test.js +++ b/test/SafeMath.test.js @@ -12,7 +12,7 @@ contract('SafeMath', function (accounts) { it('multiplies correctly', async function () { let a = 5678; let b = 1234; - let mult = await safeMath.multiply(a, b); + await safeMath.multiply(a, b); let result = await safeMath.result(); assert.equal(result, a * b); }); @@ -20,7 +20,7 @@ contract('SafeMath', function (accounts) { it('adds correctly', async function () { let a = 5678; let b = 1234; - let add = await safeMath.add(a, b); + await safeMath.add(a, b); let result = await safeMath.result(); assert.equal(result, a + b); @@ -29,7 +29,7 @@ contract('SafeMath', function (accounts) { it('subtracts correctly', async function () { let a = 5678; let b = 1234; - let subtract = await safeMath.subtract(a, b); + await safeMath.subtract(a, b); let result = await safeMath.result(); assert.equal(result, a - b); @@ -39,7 +39,7 @@ contract('SafeMath', function (accounts) { let a = 1234; let b = 5678; try { - let subtract = await safeMath.subtract(a, b); + await safeMath.subtract(a, b); assert.fail('should have thrown before'); } catch (error) { assertJump(error); @@ -50,7 +50,7 @@ contract('SafeMath', function (accounts) { let a = 115792089237316195423570985008687907853269984665640564039457584007913129639935; let b = 1; try { - let add = await safeMath.add(a, b); + await safeMath.add(a, b); assert.fail('should have thrown before'); } catch (error) { assertRevert(error); @@ -61,7 +61,7 @@ contract('SafeMath', function (accounts) { let a = 115792089237316195423570985008687907853269984665640564039457584007913129639933; let b = 2; try { - let multiply = await safeMath.multiply(a, b); + await safeMath.multiply(a, b); assert.fail('should have thrown before'); } catch (error) { assertRevert(error); diff --git a/test/SampleCrowdsale.test.js b/test/SampleCrowdsale.test.js index cb904e07b07..9e3970ed817 100644 --- a/test/SampleCrowdsale.test.js +++ b/test/SampleCrowdsale.test.js @@ -6,7 +6,7 @@ import EVMRevert from './helpers/EVMRevert'; const BigNumber = web3.BigNumber; -const should = require('chai') +require('chai') .use(require('chai-as-promised')) .use(require('chai-bignumber')(BigNumber)) .should(); @@ -14,7 +14,7 @@ const should = require('chai') const SampleCrowdsale = artifacts.require('SampleCrowdsale'); const SampleCrowdsaleToken = artifacts.require('SampleCrowdsaleToken'); -contract('Crowdsale', function ([owner, wallet, investor]) { +contract('SampleCrowdsale', function ([owner, wallet, investor]) { const RATE = new BigNumber(10); const GOAL = ether(10); const CAP = ether(20); @@ -37,12 +37,19 @@ contract('Crowdsale', function ([owner, wallet, investor]) { this.crowdsale.should.exist; this.token.should.exist; - (await this.crowdsale.startTime()).should.be.bignumber.equal(this.startTime); - (await this.crowdsale.endTime()).should.be.bignumber.equal(this.endTime); - (await this.crowdsale.rate()).should.be.bignumber.equal(RATE); - (await this.crowdsale.wallet()).should.be.equal(wallet); - (await this.crowdsale.goal()).should.be.bignumber.equal(GOAL); - (await this.crowdsale.cap()).should.be.bignumber.equal(CAP); + const startTime = await this.crowdsale.startTime(); + const endTime = await this.crowdsale.endTime(); + const rate = await this.crowdsale.rate(); + const walletAddress = await this.crowdsale.wallet(); + const goal = await this.crowdsale.goal(); + const cap = await this.crowdsale.cap(); + + startTime.should.be.bignumber.equal(this.startTime); + endTime.should.be.bignumber.equal(this.endTime); + rate.should.be.bignumber.equal(RATE); + walletAddress.should.be.equal(wallet); + goal.should.be.bignumber.equal(GOAL); + cap.should.be.bignumber.equal(CAP); }); it('should not accept payments before start', async function () { diff --git a/test/SplitPayment.test.js b/test/SplitPayment.test.js index 3658d7f2f44..0a8987ea439 100644 --- a/test/SplitPayment.test.js +++ b/test/SplitPayment.test.js @@ -1,6 +1,6 @@ const BigNumber = web3.BigNumber; -const should = require('chai') +require('chai') .use(require('chai-as-promised')) .use(require('chai-bignumber')(BigNumber)) .should(); diff --git a/test/StandardToken.test.js b/test/StandardToken.test.js index 34440b028ed..f7461da089f 100644 --- a/test/StandardToken.test.js +++ b/test/StandardToken.test.js @@ -1,6 +1,6 @@ const assertRevert = require('./helpers/assertRevert'); -const expectThrow = require('./helpers/expectThrow'); + var StandardTokenMock = artifacts.require('./mocks/StandardTokenMock.sol'); contract('StandardToken', function (accounts) { @@ -108,7 +108,7 @@ contract('StandardToken', function (accounts) { it('should throw an error when trying to transfer to 0x0', async function () { let token = await StandardTokenMock.new(accounts[0], 100); try { - let transfer = await token.transfer(0x0, 100); + await token.transfer(0x0, 100); assert.fail('should have thrown before'); } catch (error) { assertRevert(error); @@ -119,7 +119,7 @@ contract('StandardToken', function (accounts) { let token = await StandardTokenMock.new(accounts[0], 100); await token.approve(accounts[1], 100); try { - let transfer = await token.transferFrom(accounts[0], 0x0, 100, { from: accounts[1] }); + await token.transferFrom(accounts[0], 0x0, 100, { from: accounts[1] }); assert.fail('should have thrown before'); } catch (error) { assertRevert(error); diff --git a/test/TokenTimelock.test.js b/test/TokenTimelock.test.js index c745edccdba..d7fbab990d9 100644 --- a/test/TokenTimelock.test.js +++ b/test/TokenTimelock.test.js @@ -1,3 +1,6 @@ +import latestTime from './helpers/latestTime'; +import { increaseTimeTo, duration } from './helpers/increaseTime'; + const BigNumber = web3.BigNumber; require('chai') @@ -5,9 +8,6 @@ require('chai') .use(require('chai-bignumber')(BigNumber)) .should(); -import latestTime from './helpers/latestTime'; -import { increaseTimeTo, duration } from './helpers/increaseTime'; - const MintableToken = artifacts.require('MintableToken'); const TokenTimelock = artifacts.require('TokenTimelock'); diff --git a/test/TokenVesting.test.js b/test/TokenVesting.test.js index 361037d47a9..e767ae1a811 100644 --- a/test/TokenVesting.test.js +++ b/test/TokenVesting.test.js @@ -1,3 +1,7 @@ +import EVMRevert from './helpers/EVMRevert'; +import latestTime from './helpers/latestTime'; +import { increaseTimeTo, duration } from './helpers/increaseTime'; + const BigNumber = web3.BigNumber; require('chai') @@ -5,10 +9,6 @@ require('chai') .use(require('chai-bignumber')(BigNumber)) .should(); -import EVMRevert from './helpers/EVMRevert'; -import latestTime from './helpers/latestTime'; -import { increaseTimeTo, duration } from './helpers/increaseTime'; - const MintableToken = artifacts.require('MintableToken'); const TokenVesting = artifacts.require('TokenVesting'); @@ -104,7 +104,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) { it('should fail to be revoked a second time', async function () { await increaseTimeTo(this.start + this.cliff + duration.weeks(12)); - const vested = await this.vesting.vestedAmount(this.token.address); + await this.vesting.vestedAmount(this.token.address); await this.vesting.revoke(this.token.address, { from: owner }); diff --git a/test/helpers/hashMessage.js b/test/helpers/hashMessage.js index c97340b64a9..6e8a1f74e7f 100644 --- a/test/helpers/hashMessage.js +++ b/test/helpers/hashMessage.js @@ -2,7 +2,7 @@ import utils from 'ethereumjs-util'; // Hash and add same prefix to the hash that testrpc use. module.exports = function (message) { - const messageHex = new Buffer(utils.sha3(message).toString('hex'), 'hex'); + const messageHex = Buffer.from(utils.sha3(message).toString('hex'), 'hex'); const prefix = utils.toBuffer('\u0019Ethereum Signed Message:\n' + messageHex.length.toString()); return utils.bufferToHex(utils.sha3(Buffer.concat([prefix, messageHex]))); }; diff --git a/test/helpers/merkleTree.js b/test/helpers/merkleTree.js index ae5a914c311..24d9f72f912 100644 --- a/test/helpers/merkleTree.js +++ b/test/helpers/merkleTree.js @@ -15,7 +15,7 @@ export default class MerkleTree { } getLayers (elements) { - if (elements.length == 0) { + if (elements.length === 0) { return [['']]; } diff --git a/test/helpers/toPromise.js b/test/helpers/toPromise.js index 6a24dc362d8..2e9bcfbd38c 100644 --- a/test/helpers/toPromise.js +++ b/test/helpers/toPromise.js @@ -1,4 +1,4 @@ export default func => (...args) => - new Promise((accept, reject) => - func(...args, (error, data) => error ? reject(error) : accept(data))); + new Promise((resolve, reject) => + func(...args, (error, data) => error ? reject(error) : resolve(data))); diff --git a/truffle-config.js b/truffle-config.js index 7fb6af361ba..bddce4915f7 100644 --- a/truffle-config.js +++ b/truffle-config.js @@ -21,15 +21,15 @@ module.exports = { development: { host: 'localhost', port: 8545, - network_id: '*', + network_id: '*', // eslint-disable-line camelcase }, ropsten: { provider: ropstenProvider, - network_id: 3, // official id of the ropsten network + network_id: 3, // eslint-disable-line camelcase }, coverage: { host: 'localhost', - network_id: '*', + network_id: '*', // eslint-disable-line camelcase port: 8555, gas: 0xfffffffffff, gasPrice: 0x01, @@ -37,12 +37,12 @@ module.exports = { testrpc: { host: 'localhost', port: 8545, - network_id: '*', + network_id: '*', // eslint-disable-line camelcase }, ganache: { host: 'localhost', port: 7545, - network_id: '*', + network_id: '*', // eslint-disable-line camelcase }, }, };