Browse Source

Improve eslint config, and some linting

maurelian 6 years ago
parent
commit
ef4f7d2594

+ 21 - 0
.eslintrc.json

@@ -0,0 +1,21 @@
+{
+  "extends": "airbnb",
+  "env": {
+    "node": true,
+    "mocha": true,
+    "es6": true
+  },
+  "parserOptions": {
+    "ecmaVersion": 8,
+    "sourceType": "module"
+  },
+  "globals": {
+    "assert": true,
+    "it": true,
+    "bef: true,ore": true,
+    "beforeE: true,ach": true,
+    "artifacts": true,
+    "contract": true,
+    "web3": true
+  }
+}

+ 3 - 3
migrations/1_initial_migration.js

@@ -1,5 +1,5 @@
-const Migrations = artifacts.require(`./Migrations.sol`)
+const Migrations = artifacts.require('./Migrations.sol');
 
 module.exports = (deployer) => {
-  deployer.deploy(Migrations)
-}
+  deployer.deploy(Migrations);
+};

+ 3 - 3
migrations/2_deploy_tokens.js

@@ -1,5 +1,5 @@
-const EIP20 = artifacts.require(`./EIP20.sol`)
+const EIP20 = artifacts.require('./EIP20.sol');
 
 module.exports = (deployer) => {
-  deployer.deploy(EIP20)
-}
+  deployer.deploy(EIP20);
+};

+ 3 - 3
migrations/3_deploy_factory.js

@@ -1,6 +1,6 @@
 const EIP20Factory =
-  artifacts.require(`./EIP20Factory.sol`)
+  artifacts.require('./EIP20Factory.sol');
 
 module.exports = (deployer) => {
-  deployer.deploy(EIP20Factory)
-}
+  deployer.deploy(EIP20Factory);
+};

File diff suppressed because it is too large
+ 885 - 564
package-lock.json


+ 13 - 19
package.json

@@ -8,9 +8,12 @@
   },
   "scripts": {
     "compile": "truffle compile",
-    "test": "standard && truffle test",
-    "lint": "standard --fix && solhint contracts/*.sol contracts/*/*.sol",
-    "publish": "truffle publish"
+    "lint:js": "eslint --fix test/**/*.js migrations/**/*.js",
+    "lint:sol": "solhint contracts/*.sol contracts/*/*.sol test/*.sol test/*/*.sol",
+    "lint": "npm run lint:js && npm run lint:sol",
+    "publish": "truffle publish",
+    "test": "truffle test",
+    "posttest": "npm run lint"
   },
   "repository": {
     "type": "git",
@@ -33,22 +36,13 @@
     "truffle-hdwallet-provider": "0.0.3"
   },
   "devDependencies": {
-    "eslint-plugin-import": "2.7.0",
+    "eslint": "4.13.1",
+    "eslint-config-airbnb": "16.1.0",
+    "eslint-plugin-import": "2.8.0",
+    "eslint-plugin-jsx-a11y": "6.0.3",
+    "eslint-plugin-mocha": "4.11.0",
     "eslint-plugin-node": "5.1.0",
-    "eslint-plugin-react": "7.1.0",
-    "eslint-plugin-standard": "3.0.1",
-    "solhint": "^1.1.9",
-    "standard": "10.0.2"
-  },
-  "standard": {
-    "globals": [
-      "assert",
-      "it",
-      "before",
-      "beforeEach",
-      "artifacts",
-      "contract",
-      "web3"
-    ]
+    "eslint-plugin-react": "7.5.1",
+    "solhint": "1.1.9"
   }
 }

+ 133 - 135
test/eip20/eip20.js

@@ -1,208 +1,206 @@
-const expectThrow = require('../utils').expectThrow
-const EIP20Abstraction = artifacts.require('EIP20')
-let HST
+const { expectThrow } = require('../utils');
 
-contract('EIP20', function (accounts) {
+const EIP20Abstraction = artifacts.require('EIP20');
+let HST;
+
+contract('EIP20', (accounts) => {
   beforeEach(async () => {
-    HST = await EIP20Abstraction.new(10000, 'Simon Bucks', 1, 'SBX', {from: accounts[0]})
-  })
+    HST = await EIP20Abstraction.new(10000, 'Simon Bucks', 1, 'SBX', { from: accounts[0] });
+  });
 
   it('creation: should create an initial balance of 10000 for the creator', async () => {
-    const balance = await HST.balanceOf.call(accounts[0])
-    assert.strictEqual(balance.toNumber(), 10000)
-  })
+    const balance = await HST.balanceOf.call(accounts[0]);
+    assert.strictEqual(balance.toNumber(), 10000);
+  });
 
   it('creation: test correct setting of vanity information', async () => {
-    const name = await HST.name.call()
-    assert.strictEqual(name, 'Simon Bucks')
+    const name = await HST.name.call();
+    assert.strictEqual(name, 'Simon Bucks');
 
-    const decimals = await HST.decimals.call()
-    assert.strictEqual(decimals.toNumber(), 1)
+    const decimals = await HST.decimals.call();
+    assert.strictEqual(decimals.toNumber(), 1);
 
-    const symbol = await HST.symbol.call()
-    assert.strictEqual(symbol, 'SBX')
-  })
+    const symbol = await HST.symbol.call();
+    assert.strictEqual(symbol, 'SBX');
+  });
 
   it('creation: should succeed in creating over 2^256 - 1 (max) tokens', async () => {
     // 2^256 - 1
-    let HST2 = await EIP20Abstraction.new('115792089237316195423570985008687907853269984665640564039457584007913129639935', 'Simon Bucks', 1, 'SBX', {from: accounts[0]})
-    const totalSupply = await HST2.totalSupply()
-    const match = totalSupply.equals('1.15792089237316195423570985008687907853269984665640564039457584007913129639935e+77')
-    assert(match, 'result is not correct')
-  })
+    const HST2 = await EIP20Abstraction.new('115792089237316195423570985008687907853269984665640564039457584007913129639935', 'Simon Bucks', 1, 'SBX', { from: accounts[0] });
+    const totalSupply = await HST2.totalSupply();
+    const match = totalSupply.equals('1.15792089237316195423570985008687907853269984665640564039457584007913129639935e+77');
+    assert(match, 'result is not correct');
+  });
 
   // TRANSERS
   // normal transfers without approvals
   it('transfers: ether transfer should be reversed.', async () => {
-    const balanceBefore = await HST.balanceOf.call(accounts[0])
-    assert.strictEqual(balanceBefore.toNumber(), 10000)
+    const balanceBefore = await HST.balanceOf.call(accounts[0]);
+    assert.strictEqual(balanceBefore.toNumber(), 10000);
 
-    web3.eth.sendTransaction({from: accounts[0], to: HST.address, value: web3.toWei('10', 'Ether')}, async (err, res) => {
+    web3.eth.sendTransaction({ from: accounts[0], to: HST.address, value: web3.toWei('10', 'Ether') }, async (err, res) => {
       expectThrow(new Promise((resolve, reject) => {
-        if (err) reject(err)
-        resolve(res)
-      }))
+        if (err) reject(err);
+        resolve(res);
+      }));
 
-      const balanceAfter = await HST.balanceOf.call(accounts[0])
-      assert.strictEqual(balanceAfter.toNumber(), 10000)
-    })
-  })
+      const balanceAfter = await HST.balanceOf.call(accounts[0]);
+      assert.strictEqual(balanceAfter.toNumber(), 10000);
+    });
+  });
 
   it('transfers: should transfer 10000 to accounts[1] with accounts[0] having 10000', async () => {
-    await HST.transfer(accounts[1], 10000, {from: accounts[0]})
-    const balance = await HST.balanceOf.call(accounts[1])
-    assert.strictEqual(balance.toNumber(), 10000)
-  })
+    await HST.transfer(accounts[1], 10000, { from: accounts[0] });
+    const balance = await HST.balanceOf.call(accounts[1]);
+    assert.strictEqual(balance.toNumber(), 10000);
+  });
 
-  it('transfers: should fail when trying to transfer 10001 to accounts[1] with accounts[0] having 10000', () => {
-    return expectThrow(HST.transfer.call(accounts[1], 10001, {from: accounts[0]}))
-  })
+  it('transfers: should fail when trying to transfer 10001 to accounts[1] with accounts[0] having 10000', () => expectThrow(HST.transfer.call(accounts[1], 10001, { from: accounts[0] })));
 
   it('transfers: should handle zero-transfers normally', async () => {
-    assert(await HST.transfer.call(accounts[1], 0, {from: accounts[0]}), 'zero-transfer has failed')
-  })
+    assert(await HST.transfer.call(accounts[1], 0, { from: accounts[0] }), 'zero-transfer has failed');
+  });
 
-  // NOTE: testing uint256 wrapping is impossible in this standard token since you can't supply > 2^256 -1
+  // NOTE: testing uint256 wrapping is impossible since you can't supply > 2^256 -1
   // todo: transfer max amounts
 
   // APPROVALS
   it('approvals: msg.sender should approve 100 to accounts[1]', async () => {
-    await HST.approve(accounts[1], 100, {from: accounts[0]})
-    const allowance = await HST.allowance.call(accounts[0], accounts[1])
-    assert.strictEqual(allowance.toNumber(), 100)
-  })
+    await HST.approve(accounts[1], 100, { from: accounts[0] });
+    const allowance = await HST.allowance.call(accounts[0], accounts[1]);
+    assert.strictEqual(allowance.toNumber(), 100);
+  });
 
   // bit overkill. But is for testing a bug
   it('approvals: msg.sender approves accounts[1] of 100 & withdraws 20 once.', async () => {
-    const balance0 = await HST.balanceOf.call(accounts[0])
-    assert.strictEqual(balance0.toNumber(), 10000)
+    const balance0 = await HST.balanceOf.call(accounts[0]);
+    assert.strictEqual(balance0.toNumber(), 10000);
 
-    await HST.approve(accounts[1], 100, {from: accounts[0]}) // 100
-    const balance2 = await HST.balanceOf.call(accounts[2])
-    assert.strictEqual(balance2.toNumber(), 0, 'balance2 not correct')
+    await HST.approve(accounts[1], 100, { from: accounts[0] }); // 100
+    const balance2 = await HST.balanceOf.call(accounts[2]);
+    assert.strictEqual(balance2.toNumber(), 0, 'balance2 not correct');
 
-    await HST.transferFrom.call(accounts[0], accounts[2], 20, {from: accounts[1]})
-    await HST.allowance.call(accounts[0], accounts[1])
-    await HST.transferFrom(accounts[0], accounts[2], 20, {from: accounts[1]}) // -20
-    const allowance01 = await HST.allowance.call(accounts[0], accounts[1])
-    assert.strictEqual(allowance01.toNumber(), 80) // =80
+    await HST.transferFrom.call(accounts[0], accounts[2], 20, { from: accounts[1] });
+    await HST.allowance.call(accounts[0], accounts[1]);
+    await HST.transferFrom(accounts[0], accounts[2], 20, { from: accounts[1] }); // -20
+    const allowance01 = await HST.allowance.call(accounts[0], accounts[1]);
+    assert.strictEqual(allowance01.toNumber(), 80); // =80
 
-    const balance22 = await HST.balanceOf.call(accounts[2])
-    assert.strictEqual(balance22.toNumber(), 20)
+    const balance22 = await HST.balanceOf.call(accounts[2]);
+    assert.strictEqual(balance22.toNumber(), 20);
 
-    const balance02 = await HST.balanceOf.call(accounts[0])
-    assert.strictEqual(balance02.toNumber(), 9980)
-  })
+    const balance02 = await HST.balanceOf.call(accounts[0]);
+    assert.strictEqual(balance02.toNumber(), 9980);
+  });
 
   // should approve 100 of msg.sender & withdraw 50, twice. (should succeed)
   it('approvals: msg.sender approves accounts[1] of 100 & withdraws 20 twice.', async () => {
-    await HST.approve(accounts[1], 100, {from: accounts[0]})
-    const allowance01 = await HST.allowance.call(accounts[0], accounts[1])
-    assert.strictEqual(allowance01.toNumber(), 100)
+    await HST.approve(accounts[1], 100, { from: accounts[0] });
+    const allowance01 = await HST.allowance.call(accounts[0], accounts[1]);
+    assert.strictEqual(allowance01.toNumber(), 100);
 
-    await HST.transferFrom(accounts[0], accounts[2], 20, {from: accounts[1]})
-    const allowance012 = await HST.allowance.call(accounts[0], accounts[1])
-    assert.strictEqual(allowance012.toNumber(), 80)
+    await HST.transferFrom(accounts[0], accounts[2], 20, { from: accounts[1] });
+    const allowance012 = await HST.allowance.call(accounts[0], accounts[1]);
+    assert.strictEqual(allowance012.toNumber(), 80);
 
-    const balance2 = await HST.balanceOf.call(accounts[2])
-    assert.strictEqual(balance2.toNumber(), 20)
+    const balance2 = await HST.balanceOf.call(accounts[2]);
+    assert.strictEqual(balance2.toNumber(), 20);
 
-    const balance0 = await HST.balanceOf.call(accounts[0])
-    assert.strictEqual(balance0.toNumber(), 9980)
+    const balance0 = await HST.balanceOf.call(accounts[0]);
+    assert.strictEqual(balance0.toNumber(), 9980);
 
     // FIRST tx done.
     // onto next.
-    await HST.transferFrom(accounts[0], accounts[2], 20, {from: accounts[1]})
-    const allowance013 = await HST.allowance.call(accounts[0], accounts[1])
-    assert.strictEqual(allowance013.toNumber(), 60)
+    await HST.transferFrom(accounts[0], accounts[2], 20, { from: accounts[1] });
+    const allowance013 = await HST.allowance.call(accounts[0], accounts[1]);
+    assert.strictEqual(allowance013.toNumber(), 60);
 
-    const balance22 = await HST.balanceOf.call(accounts[2])
-    assert.strictEqual(balance22.toNumber(), 40)
+    const balance22 = await HST.balanceOf.call(accounts[2]);
+    assert.strictEqual(balance22.toNumber(), 40);
 
-    const balance02 = await HST.balanceOf.call(accounts[0])
-    assert.strictEqual(balance02.toNumber(), 9960)
-  })
+    const balance02 = await HST.balanceOf.call(accounts[0]);
+    assert.strictEqual(balance02.toNumber(), 9960);
+  });
 
   // should approve 100 of msg.sender & withdraw 50 & 60 (should fail).
   it('approvals: msg.sender approves accounts[1] of 100 & withdraws 50 & 60 (2nd tx should fail)', async () => {
-    await HST.approve(accounts[1], 100, {from: accounts[0]})
-    const allowance01 = await HST.allowance.call(accounts[0], accounts[1])
-    assert.strictEqual(allowance01.toNumber(), 100)
+    await HST.approve(accounts[1], 100, { from: accounts[0] });
+    const allowance01 = await HST.allowance.call(accounts[0], accounts[1]);
+    assert.strictEqual(allowance01.toNumber(), 100);
 
-    await HST.transferFrom(accounts[0], accounts[2], 50, {from: accounts[1]})
-    const allowance012 = await HST.allowance.call(accounts[0], accounts[1])
-    assert.strictEqual(allowance012.toNumber(), 50)
+    await HST.transferFrom(accounts[0], accounts[2], 50, { from: accounts[1] });
+    const allowance012 = await HST.allowance.call(accounts[0], accounts[1]);
+    assert.strictEqual(allowance012.toNumber(), 50);
 
-    const balance2 = await HST.balanceOf.call(accounts[2])
-    assert.strictEqual(balance2.toNumber(), 50)
+    const balance2 = await HST.balanceOf.call(accounts[2]);
+    assert.strictEqual(balance2.toNumber(), 50);
 
-    const balance0 = await HST.balanceOf.call(accounts[0])
-    assert.strictEqual(balance0.toNumber(), 9950)
+    const balance0 = await HST.balanceOf.call(accounts[0]);
+    assert.strictEqual(balance0.toNumber(), 9950);
 
     // FIRST tx done.
     // onto next.
-    expectThrow(HST.transferFrom.call(accounts[0], accounts[2], 60, {from: accounts[1]}))
-  })
+    expectThrow(HST.transferFrom.call(accounts[0], accounts[2], 60, { from: accounts[1] }));
+  });
 
-  it('approvals: attempt withdrawal from account with no allowance (should fail)', () => {
-    return expectThrow(HST.transferFrom.call(accounts[0], accounts[2], 60, {from: accounts[1]}))
-  })
+  it('approvals: attempt withdrawal from account with no allowance (should fail)', () => expectThrow(HST.transferFrom.call(accounts[0], accounts[2], 60, { from: accounts[1] })));
 
   it('approvals: allow accounts[1] 100 to withdraw from accounts[0]. Withdraw 60 and then approve 0 & attempt transfer.', async () => {
-    await HST.approve(accounts[1], 100, {from: accounts[0]})
-    await HST.transferFrom(accounts[0], accounts[2], 60, {from: accounts[1]})
-    await HST.approve(accounts[1], 0, {from: accounts[0]})
-    expectThrow(HST.transferFrom.call(accounts[0], accounts[2], 10, {from: accounts[1]}))
-  })
+    await HST.approve(accounts[1], 100, { from: accounts[0] });
+    await HST.transferFrom(accounts[0], accounts[2], 60, { from: accounts[1] });
+    await HST.approve(accounts[1], 0, { from: accounts[0] });
+    expectThrow(HST.transferFrom.call(accounts[0], accounts[2], 10, { from: accounts[1] }));
+  });
 
   it('approvals: approve max (2^256 - 1)', async () => {
-    await HST.approve(accounts[1], '115792089237316195423570985008687907853269984665640564039457584007913129639935', {from: accounts[0]})
-    const allowance = await HST.allowance(accounts[0], accounts[1])
-    assert(allowance.equals('1.15792089237316195423570985008687907853269984665640564039457584007913129639935e+77'))
-  })
+    await HST.approve(accounts[1], '115792089237316195423570985008687907853269984665640564039457584007913129639935', { from: accounts[0] });
+    const allowance = await HST.allowance(accounts[0], accounts[1]);
+    assert(allowance.equals('1.15792089237316195423570985008687907853269984665640564039457584007913129639935e+77'));
+  });
 
   // should approve max of msg.sender & withdraw 20 without changing allowance (should succeed).
   it('approvals: msg.sender approves accounts[1] of max (2^256 - 1) & withdraws 20', async () => {
-    const balance0 = await HST.balanceOf.call(accounts[0])
-    assert.strictEqual(balance0.toNumber(), 10000)
+    const balance0 = await HST.balanceOf.call(accounts[0]);
+    assert.strictEqual(balance0.toNumber(), 10000);
 
-    const max = '1.15792089237316195423570985008687907853269984665640564039457584007913129639935e+77'
-    await HST.approve(accounts[1], max, {from: accounts[0]})
-    const balance2 = await HST.balanceOf.call(accounts[2])
-    assert.strictEqual(balance2.toNumber(), 0, 'balance2 not correct')
+    const max = '1.15792089237316195423570985008687907853269984665640564039457584007913129639935e+77';
+    await HST.approve(accounts[1], max, { from: accounts[0] });
+    const balance2 = await HST.balanceOf.call(accounts[2]);
+    assert.strictEqual(balance2.toNumber(), 0, 'balance2 not correct');
 
-    await HST.transferFrom(accounts[0], accounts[2], 20, {from: accounts[1]})
-    const allowance01 = await HST.allowance.call(accounts[0], accounts[1])
-    assert(allowance01.equals(max))
+    await HST.transferFrom(accounts[0], accounts[2], 20, { from: accounts[1] });
+    const allowance01 = await HST.allowance.call(accounts[0], accounts[1]);
+    assert(allowance01.equals(max));
 
-    const balance22 = await HST.balanceOf.call(accounts[2])
-    assert.strictEqual(balance22.toNumber(), 20)
+    const balance22 = await HST.balanceOf.call(accounts[2]);
+    assert.strictEqual(balance22.toNumber(), 20);
 
-    const balance02 = await HST.balanceOf.call(accounts[0])
-    assert.strictEqual(balance02.toNumber(), 9980)
-  })
+    const balance02 = await HST.balanceOf.call(accounts[0]);
+    assert.strictEqual(balance02.toNumber(), 9980);
+  });
 
+  /* eslint-disable no-underscore-dangle */
   it('events: should fire Transfer event properly', async () => {
-    const res = await HST.transfer(accounts[1], '2666', {from: accounts[0]})
-    const transferLog = res.logs.find(element => element.event.match('Transfer'))
-    assert.strictEqual(transferLog.args._from, accounts[0])
-    assert.strictEqual(transferLog.args._to, accounts[1])
-    assert.strictEqual(transferLog.args._value.toString(), '2666')
-  })
+    const res = await HST.transfer(accounts[1], '2666', { from: accounts[0] });
+    const transferLog = res.logs.find(element => element.event.match('Transfer'));
+    assert.strictEqual(transferLog.args._from, accounts[0]);
+    assert.strictEqual(transferLog.args._to, accounts[1]);
+    assert.strictEqual(transferLog.args._value.toString(), '2666');
+  });
 
   it('events: should fire Transfer event normally on a zero transfer', async () => {
-    const res = await HST.transfer(accounts[1], '0', {from: accounts[0]})
-    const transferLog = res.logs.find(element => element.event.match('Transfer'))
-    assert.strictEqual(transferLog.args._from, accounts[0])
-    assert.strictEqual(transferLog.args._to, accounts[1])
-    assert.strictEqual(transferLog.args._value.toString(), '0')
-  })
+    const res = await HST.transfer(accounts[1], '0', { from: accounts[0] });
+    const transferLog = res.logs.find(element => element.event.match('Transfer'));
+    assert.strictEqual(transferLog.args._from, accounts[0]);
+    assert.strictEqual(transferLog.args._to, accounts[1]);
+    assert.strictEqual(transferLog.args._value.toString(), '0');
+  });
 
   it('events: should fire Approval event properly', async () => {
-    const res = await HST.approve(accounts[1], '2666', {from: accounts[0]})
-    const approvalLog = res.logs.find(element => element.event.match('Approval'))
-    assert.strictEqual(approvalLog.args._owner, accounts[0])
-    assert.strictEqual(approvalLog.args._spender, accounts[1])
-    assert.strictEqual(approvalLog.args._value.toString(), '2666')
-  })
-})
+    const res = await HST.approve(accounts[1], '2666', { from: accounts[0] });
+    const approvalLog = res.logs.find(element => element.event.match('Approval'));
+    assert.strictEqual(approvalLog.args._owner, accounts[0]);
+    assert.strictEqual(approvalLog.args._spender, accounts[1]);
+    assert.strictEqual(approvalLog.args._value.toString(), '2666');
+  });
+});

+ 9 - 9
test/eip20/eip20Factory.js

@@ -1,11 +1,11 @@
-const EIP20Factory = artifacts.require('EIP20Factory')
+const EIP20Factory = artifacts.require('EIP20Factory');
 
-contract('EIP20Factory', function (accounts) {
+contract('EIP20Factory', (accounts) => {
   it('Verify a Human Standard Token once deployed using both verification functions.', async () => {
-    const factory = await EIP20Factory.new()
-    const newTokenAddr = await factory.createEIP20.call(100000, 'Simon Bucks', 2, 'SBX', {from: accounts[0]})
-    await factory.createEIP20(100000, 'Simon Bucks', 2, 'SBX', {from: accounts[0]})
-    const res = await factory.verifyEIP20.call(newTokenAddr, {from: accounts[0]})
-    assert(res, 'Could not verify the token.')
-  })
-})
+    const factory = await EIP20Factory.new();
+    const newTokenAddr = await factory.createEIP20.call(100000, 'Simon Bucks', 2, 'SBX', { from: accounts[0] });
+    await factory.createEIP20(100000, 'Simon Bucks', 2, 'SBX', { from: accounts[0] });
+    const res = await factory.verifyEIP20.call(newTokenAddr, { from: accounts[0] });
+    assert(res, 'Could not verify the token.');
+  });
+});

+ 8 - 8
test/utils.js

@@ -1,12 +1,12 @@
 module.exports = {
-  expectThrow: async promise => {
-    const errMsg = 'Expected throw not received'
+  expectThrow: async (promise) => {
+    const errMsg = 'Expected throw not received';
     try {
-      await promise
+      await promise;
     } catch (err) {
-      assert(err.toString().includes('invalid opcode'), errMsg)
-      return
+      assert(err.toString().includes('invalid opcode'), errMsg);
+      return;
     }
-    assert.fail(errMsg)
-  }
-}
+    assert.fail(errMsg);
+  },
+};