Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 25 additions & 22 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,34 @@
"rules": {

// Strict mode
"strict": [2, "global"],
"strict": ["error", "global"],

// Code style
"indent": [2, 2],
"quotes": [2, "single"],
"camelcase": ["error", {"properties": "always"}],
"comma-dangle": ["warn", "always-multiline"],
"comma-spacing": ["error", {"before": false, "after": true}],
"dot-notation": ["error", {"allowKeywords": true, "allowPattern": ""}],
"eol-last": "warn",
"eqeqeq": ["error", "smart"],
"generator-star-spacing": ["error", "before"],
"indent": ["error", 2],
"max-len": ["error", 120, 2],
"no-debugger": "off",
"no-dupe-args": "error",
"no-dupe-keys": "error",
"no-mixed-spaces-and-tabs": ["error", "smart-tabs"],
"no-redeclare": ["error", {"builtinGlobals": true}],
"no-trailing-spaces": ["error", { "skipBlankLines": true }],
"no-undef": "error",
"no-use-before-define": "off",
"no-var": "error",
"object-curly-spacing": ["error", "always"],
"prefer-const": "error",
"quotes": ["error", "single"],
"semi": ["error", "always"],
"space-before-function-paren": ["error", "always"],
"no-use-before-define": 0,
"eqeqeq": [2, "smart"],
"dot-notation": [2, {"allowKeywords": true, "allowPattern": ""}],
"no-redeclare": [2, {"builtinGlobals": true}],
"no-trailing-spaces": [2, { "skipBlankLines": true }],
"eol-last": 1,
"comma-spacing": [2, {"before": false, "after": true}],
"camelcase": [2, {"properties": "always"}],
"no-mixed-spaces-and-tabs": [2, "smart-tabs"],
"comma-dangle": [1, "always-multiline"],
"no-dupe-args": 2,
"no-dupe-keys": 2,
"no-debugger": 0,
"no-undef": 2,
"object-curly-spacing": [2, "always"],
"max-len": [2, 120, 2],
"generator-star-spacing": ["error", "before"],
"promise/avoid-new": 0,
"promise/always-return": 0

"promise/always-return": "off",
"promise/avoid-new": "off",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't like to delay this branch, and I love what you are doing with style.
But, this changes are not related to const. For the future branches, please split the things that are not related into small focused PRs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgive me father for I have sinned :(

I know I shouldn't have, but I couldn't stand the ugly and unsorted eslint file. Didn't add any new rules other than the const related ones though.

}
}
4 changes: 2 additions & 2 deletions test/AutoIncrementing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ contract('AutoIncrementing', function ([_, owner]) {

context('custom key', async function () {
it('should return expected values', async function () {
for (let expectedId of EXPECTED) {
for (const expectedId of EXPECTED) {
await this.mock.doThing(KEY1, { from: owner });
const actualId = await this.mock.theId();
actualId.should.be.bignumber.eq(expectedId);
Expand All @@ -27,7 +27,7 @@ contract('AutoIncrementing', function ([_, owner]) {

context('parallel keys', async function () {
it('should return expected values for each counter', async function () {
for (let expectedId of EXPECTED) {
for (const expectedId of EXPECTED) {
await this.mock.doThing(KEY1, { from: owner });
let actualId = await this.mock.theId();
actualId.should.be.bignumber.eq(expectedId);
Expand Down
48 changes: 24 additions & 24 deletions test/Bounty.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { ethGetBalance, ethSendTransaction } = require('./helpers/web3');

var SecureTargetBounty = artifacts.require('SecureTargetBounty');
var InsecureTargetBounty = artifacts.require('InsecureTargetBounty');
const SecureTargetBounty = artifacts.require('SecureTargetBounty');
const InsecureTargetBounty = artifacts.require('InsecureTargetBounty');

const sendReward = async (from, to, value) => ethSendTransaction({
from, to, value,
Expand All @@ -19,19 +19,19 @@ function awaitEvent (event, handler) {

contract('Bounty', function (accounts) {
it('sets reward', async function () {
let owner = accounts[0];
let reward = web3.toWei(1, 'ether');
let bounty = await SecureTargetBounty.new();
const owner = accounts[0];
const reward = web3.toWei(1, 'ether');
const bounty = await SecureTargetBounty.new();
await sendReward(owner, bounty.address, reward);

const balance = await ethGetBalance(bounty.address);
assert.equal(reward, balance.toNumber());
});

it('empties itself when destroyed', async function () {
let owner = accounts[0];
let reward = web3.toWei(1, 'ether');
let bounty = await SecureTargetBounty.new();
const owner = accounts[0];
const reward = web3.toWei(1, 'ether');
const bounty = await SecureTargetBounty.new();
await sendReward(owner, bounty.address, reward);

const balance = await ethGetBalance(bounty.address);
Expand All @@ -44,17 +44,17 @@ contract('Bounty', function (accounts) {

describe('Against secure contract', function () {
it('cannot claim reward', async function () {
let owner = accounts[0];
let researcher = accounts[1];
let reward = web3.toWei(1, 'ether');
let bounty = await SecureTargetBounty.new();
let event = bounty.TargetCreated({});
const owner = accounts[0];
const researcher = accounts[1];
const reward = web3.toWei(1, 'ether');
const bounty = await SecureTargetBounty.new();
const event = bounty.TargetCreated({});

let watcher = async function (err, result) {
const watcher = async function (err, result) {
event.stopWatching();
if (err) { throw err; }

var targetAddress = result.args.createdAddress;
const targetAddress = result.args.createdAddress;
await sendReward(owner, bounty.address, reward);

const balance = await ethGetBalance(bounty.address);
Expand All @@ -64,7 +64,7 @@ contract('Bounty', function (accounts) {
await bounty.claim(targetAddress, { from: researcher });
assert.isTrue(false); // should never reach here
} catch (error) {
let reClaimedBounty = await bounty.claimed.call();
const reClaimedBounty = await bounty.claimed.call();
assert.isFalse(reClaimedBounty);
}
try {
Expand All @@ -82,23 +82,23 @@ contract('Bounty', function (accounts) {

describe('Against broken contract', function () {
it('claims reward', async function () {
let owner = accounts[0];
let researcher = accounts[1];
let reward = web3.toWei(1, 'ether');
let bounty = await InsecureTargetBounty.new();
let event = bounty.TargetCreated({});
const owner = accounts[0];
const researcher = accounts[1];
const reward = web3.toWei(1, 'ether');
const bounty = await InsecureTargetBounty.new();
const event = bounty.TargetCreated({});

let watcher = async function (err, result) {
const watcher = async function (err, result) {
event.stopWatching();
if (err) { throw err; }
let targetAddress = result.args.createdAddress;
const targetAddress = result.args.createdAddress;
await sendReward(owner, bounty.address, reward);

const balance = await ethGetBalance(bounty.address);
assert.equal(reward, balance.toNumber());

await bounty.claim(targetAddress, { from: researcher });
let claim = await bounty.claimed.call();
const claim = await bounty.claimed.call();

assert.isTrue(claim);

Expand Down
38 changes: 19 additions & 19 deletions test/LimitBalance.test.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
const { assertRevert } = require('./helpers/assertRevert');
const { ethGetBalance } = require('./helpers/web3');

var LimitBalanceMock = artifacts.require('LimitBalanceMock');
const LimitBalanceMock = artifacts.require('LimitBalanceMock');

contract('LimitBalance', function (accounts) {
let lb;
let limitBalance;

beforeEach(async function () {
lb = await LimitBalanceMock.new();
limitBalance = await LimitBalanceMock.new();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

});

let LIMIT = 1000;
const LIMIT = 1000;

it('should expose limit', async function () {
let limit = await lb.limit();
const limit = await limitBalance.limit();
assert.equal(limit, LIMIT);
});

it('should allow sending below limit', async function () {
let amount = 1;
await lb.limitedDeposit({ value: amount });
const amount = 1;
await limitBalance.limitedDeposit({ value: amount });

const balance = await ethGetBalance(lb.address);
const balance = await ethGetBalance(limitBalance.address);
assert.equal(balance, amount);
});

it('shouldnt allow sending above limit', async function () {
let amount = 1110;
await assertRevert(lb.limitedDeposit({ value: amount }));
const amount = 1110;
await assertRevert(limitBalance.limitedDeposit({ value: amount }));
});

it('should allow multiple sends below limit', async function () {
let amount = 500;
await lb.limitedDeposit({ value: amount });
const amount = 500;
await limitBalance.limitedDeposit({ value: amount });

const balance = await ethGetBalance(lb.address);
const balance = await ethGetBalance(limitBalance.address);
assert.equal(balance, amount);

await lb.limitedDeposit({ value: amount });
const updatedBalance = await ethGetBalance(lb.address);
await limitBalance.limitedDeposit({ value: amount });
const updatedBalance = await ethGetBalance(limitBalance.address);
assert.equal(updatedBalance, amount * 2);
});

it('shouldnt allow multiple sends above limit', async function () {
let amount = 500;
await lb.limitedDeposit({ value: amount });
const amount = 500;
await limitBalance.limitedDeposit({ value: amount });

const balance = await ethGetBalance(lb.address);
const balance = await ethGetBalance(limitBalance.address);
assert.equal(balance, amount);
await assertRevert(lb.limitedDeposit({ value: amount + 1 }));
await assertRevert(limitBalance.limitedDeposit({ value: amount + 1 }));
});
});
4 changes: 2 additions & 2 deletions test/ReentrancyGuard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ contract('ReentrancyGuard', function (accounts) {

beforeEach(async function () {
reentrancyMock = await ReentrancyMock.new();
let initialCounter = await reentrancyMock.counter();
const initialCounter = await reentrancyMock.counter();
assert.equal(initialCounter, 0);
});

it('should not allow remote callback', async function () {
let attacker = await ReentrancyAttack.new();
const attacker = await ReentrancyAttack.new();
await expectThrow(reentrancyMock.countAndCall(attacker.address));
});

Expand Down
6 changes: 3 additions & 3 deletions test/crowdsale/AllowanceCrowdsale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ contract('AllowanceCrowdsale', function ([_, investor, wallet, purchaser, tokenW

it('should assign tokens to sender', async function () {
await this.crowdsale.sendTransaction({ value: value, from: investor });
let balance = await this.token.balanceOf(investor);
const balance = await this.token.balanceOf(investor);
balance.should.be.bignumber.equal(expectedTokenAmount);
});

Expand All @@ -62,9 +62,9 @@ contract('AllowanceCrowdsale', function ([_, investor, wallet, purchaser, tokenW

describe('check remaining allowance', function () {
it('should report correct allowace left', async function () {
let remainingAllowance = tokenAllowance - expectedTokenAmount;
const remainingAllowance = tokenAllowance - expectedTokenAmount;
await this.crowdsale.buyTokens(investor, { value: value, from: purchaser });
let tokensRemaining = await this.crowdsale.remainingTokens();
const tokensRemaining = await this.crowdsale.remainingTokens();
tokensRemaining.should.be.bignumber.equal(remainingAllowance);
});
});
Expand Down
8 changes: 3 additions & 5 deletions test/crowdsale/CappedCrowdsale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,20 @@ contract('CappedCrowdsale', function ([_, wallet]) {

describe('ending', function () {
it('should not reach cap if sent under cap', async function () {
let capReached = await this.crowdsale.capReached();
capReached.should.equal(false);
await this.crowdsale.send(lessThanCap);
capReached = await this.crowdsale.capReached();
const capReached = await this.crowdsale.capReached();
capReached.should.equal(false);
});

it('should not reach cap if sent just under cap', async function () {
await this.crowdsale.send(cap.minus(1));
let capReached = await this.crowdsale.capReached();
const capReached = await this.crowdsale.capReached();
capReached.should.equal(false);
});

it('should reach cap if cap sent', async function () {
await this.crowdsale.send(cap);
let capReached = await this.crowdsale.capReached();
const capReached = await this.crowdsale.capReached();
capReached.should.equal(true);
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/crowdsale/Crowdsale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {

it('should assign tokens to sender', async function () {
await this.crowdsale.sendTransaction({ value: value, from: investor });
let balance = await this.token.balanceOf(investor);
const balance = await this.token.balanceOf(investor);
balance.should.be.bignumber.equal(expectedTokenAmount);
});

Expand Down
8 changes: 4 additions & 4 deletions test/crowdsale/IndividuallyCappedCrowdsale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ contract('IndividuallyCappedCrowdsale', function ([_, wallet, alice, bob, charli

describe('reporting state', function () {
it('should report correct cap', async function () {
let retrievedCap = await this.crowdsale.getUserCap(alice);
const retrievedCap = await this.crowdsale.getUserCap(alice);
retrievedCap.should.be.bignumber.equal(capAlice);
});

it('should report actual contribution', async function () {
await this.crowdsale.buyTokens(alice, { value: lessThanCapAlice });
let retrievedContribution = await this.crowdsale.getUserContribution(alice);
const retrievedContribution = await this.crowdsale.getUserContribution(alice);
retrievedContribution.should.be.bignumber.equal(lessThanCapAlice);
});
});
Expand Down Expand Up @@ -97,9 +97,9 @@ contract('IndividuallyCappedCrowdsale', function ([_, wallet, alice, bob, charli

describe('reporting state', function () {
it('should report correct cap', async function () {
let retrievedCapBob = await this.crowdsale.getUserCap(bob);
const retrievedCapBob = await this.crowdsale.getUserCap(bob);
retrievedCapBob.should.be.bignumber.equal(capBob);
let retrievedCapCharlie = await this.crowdsale.getUserCap(charlie);
const retrievedCapCharlie = await this.crowdsale.getUserCap(charlie);
retrievedCapCharlie.should.be.bignumber.equal(capBob);
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/crowdsale/MintedCrowdsale.behaviour.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function shouldBehaveLikeMintedCrowdsale ([_, investor, wallet, purchaser], rate

it('should assign tokens to sender', async function () {
await this.crowdsale.sendTransaction({ value: value, from: investor });
let balance = await this.token.balanceOf(investor);
const balance = await this.token.balanceOf(investor);
balance.should.be.bignumber.equal(expectedTokenAmount);
});

Expand Down
10 changes: 5 additions & 5 deletions test/crowdsale/WhitelistedCrowdsale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ contract('WhitelistedCrowdsale', function ([_, wallet, authorized, unauthorized,

describe('reporting whitelisted', function () {
it('should correctly report whitelisted addresses', async function () {
let isAuthorized = await this.crowdsale.whitelist(authorized);
const isAuthorized = await this.crowdsale.whitelist(authorized);
isAuthorized.should.equal(true);
let isntAuthorized = await this.crowdsale.whitelist(unauthorized);
const isntAuthorized = await this.crowdsale.whitelist(unauthorized);
isntAuthorized.should.equal(false);
});
});
Expand Down Expand Up @@ -82,11 +82,11 @@ contract('WhitelistedCrowdsale', function ([_, wallet, authorized, unauthorized,

describe('reporting whitelisted', function () {
it('should correctly report whitelisted addresses', async function () {
let isAuthorized = await this.crowdsale.whitelist(authorized);
const isAuthorized = await this.crowdsale.whitelist(authorized);
isAuthorized.should.equal(true);
let isAnotherAuthorized = await this.crowdsale.whitelist(anotherAuthorized);
const isAnotherAuthorized = await this.crowdsale.whitelist(anotherAuthorized);
isAnotherAuthorized.should.equal(true);
let isntAuthorized = await this.crowdsale.whitelist(unauthorized);
const isntAuthorized = await this.crowdsale.whitelist(unauthorized);
isntAuthorized.should.equal(false);
});
});
Expand Down
4 changes: 2 additions & 2 deletions test/helpers/increaseTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ function increaseTime (duration) {
* @param target time in seconds
*/
async function increaseTimeTo (target) {
let now = (await latestTime());
const now = (await latestTime());

if (target < now) throw Error(`Cannot increase current time(${now}) to a moment in the past(${target})`);
let diff = target - now;
const diff = target - now;
return increaseTime(diff);
}

Expand Down
Loading