This repository has been archived by the owner on May 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Linter integration #44
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
- repo: https://github.com/keep-network/pre-commit-hooks.git | ||
rev: v1.3.0 | ||
hooks: | ||
- id: check-added-large-files | ||
- repo: local | ||
hooks: | ||
- id: lint-js | ||
name: 'lint js' | ||
entry: /usr/bin/env bash -c "cd solidity && npm run js:lint" | ||
files: '\.js$' | ||
language: script | ||
description: "Checks JS code according to the package's linter configuration" | ||
- id: lint-sol | ||
name: 'lint solidity' | ||
entry: /usr/bin/env bash -c "cd solidity && npm run sol:lint" | ||
files: '\.sol$' | ||
language: script | ||
description: "Checks Solidity code according to the package's linter configuration" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"extends": "eslint-config-keep", | ||
"parserOptions": { | ||
"ecmaVersion": 2017, | ||
"sourceType": "module" | ||
}, | ||
"env": { | ||
"es6": true, | ||
"mocha": true | ||
}, | ||
"rules": { | ||
"semi": [2, "never"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "keep", | ||
"plugins": [ | ||
"security" | ||
], | ||
"rules": { | ||
"security/no-block-members": "off" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
pragma solidity >=0.4.21 <0.6.0; | ||
|
||
contract Migrations { | ||
address public owner; | ||
uint public last_completed_migration; | ||
address public owner; | ||
uint public last_completed_migration; | ||
|
||
constructor() public { | ||
owner = msg.sender; | ||
} | ||
constructor() public { | ||
owner = msg.sender; | ||
} | ||
|
||
modifier restricted() { | ||
if (msg.sender == owner) _; | ||
} | ||
modifier restricted() { | ||
if (msg.sender == owner) _; | ||
} | ||
|
||
function setCompleted(uint completed) public restricted { | ||
last_completed_migration = completed; | ||
} | ||
function setCompleted(uint completed) public restricted { | ||
last_completed_migration = completed; | ||
} | ||
|
||
function upgrade(address new_address) public restricted { | ||
Migrations upgraded = Migrations(new_address); | ||
upgraded.setCompleted(last_completed_migration); | ||
} | ||
function upgrade(address new_address) public restricted { | ||
Migrations upgraded = Migrations(new_address); | ||
upgraded.setCompleted(last_completed_migration); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
const Migrations = artifacts.require("Migrations"); | ||
const Migrations = artifacts.require('Migrations') | ||
|
||
module.exports = function(deployer) { | ||
deployer.deploy(Migrations); | ||
}; | ||
deployer.deploy(Migrations) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
const ECDSAKeepFactory = artifacts.require("./ECDSAKeepFactory.sol"); | ||
const KeepRegistry = artifacts.require("./KeepRegistry.sol"); | ||
const ECDSAKeepFactory = artifacts.require('./ECDSAKeepFactory.sol') | ||
const KeepRegistry = artifacts.require('./KeepRegistry.sol') | ||
|
||
module.exports = async function (deployer) { | ||
await deployer.deploy(ECDSAKeepFactory); | ||
await deployer.deploy(KeepRegistry, ECDSAKeepFactory.address); | ||
}; | ||
module.exports = async function(deployer) { | ||
await deployer.deploy(ECDSAKeepFactory) | ||
await deployer.deploy(KeepRegistry, ECDSAKeepFactory.address) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,14 @@ | |
"scripts": { | ||
"truffle": "truffle", | ||
"build": "truffle compile", | ||
"test": "truffle test" | ||
"test": "truffle test", | ||
"js:lint": "eslint ${npm_package_config_eslintPaths}", | ||
"js:lint:fix": "eslint --fix ${npm_package_config_eslintPaths}", | ||
"sol:lint": "solium -d contracts/", | ||
"sol:lint:fix": "solium -d contracts/ --fix" | ||
Shadowfiend marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
"config": { | ||
"eslintPaths": "test/ migrations/" | ||
}, | ||
"author": "Jakub Nowakowski <jakub.nowakowski@keep.network>", | ||
"license": "MIT", | ||
|
@@ -18,7 +25,9 @@ | |
}, | ||
"homepage": "https://github.com/keep-network/keep-tecdsa", | ||
"dependencies": { | ||
"openzeppelin-solidity": "^2.2.0" | ||
"eslint-config-keep": "git+https://github.com/keep-network/eslint-config-keep.git#0.1.2", | ||
"openzeppelin-solidity": "^2.2.0", | ||
"solium-config-keep": "git+https://github.com/keep-network/solium-config-keep.git#0.1.1" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are the configs not dev dependencies? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh woops! Nice catch |
||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.4.4", | ||
|
@@ -28,6 +37,8 @@ | |
"babel-polyfill": "^6.26.0", | ||
"babel-register": "^6.26.0", | ||
"chai": "^4.2.0", | ||
"eslint": "^6.0.1", | ||
"ethlint": "^1.2.4", | ||
"solc": "^0.5.8", | ||
"truffle": "^5.0.18", | ||
"truffle-assertions": "^0.9.1" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,43 @@ | ||
var ECDSAKeepFactory = artifacts.require('ECDSAKeepFactory'); | ||
|
||
contract("ECDSAKeepFactory", async accounts => { | ||
|
||
it("emits ECDSAKeepCreated event upon keep creation", async () => { | ||
let blockNumber = await web3.eth.getBlockNumber() | ||
|
||
let keepFactory = await ECDSAKeepFactory.deployed(); | ||
|
||
let keepAddress = await keepFactory.createNewKeep.call( | ||
10, // _groupSize, | ||
5, // _honestThreshold, | ||
"0xbc4862697a1099074168d54A555c4A60169c18BD" // _owner | ||
).catch((err) => { | ||
assert.fail(`ecdsa keep creation failed: ${err}`); | ||
}); | ||
|
||
await keepFactory.createNewKeep( | ||
10, // _groupSize, | ||
5, // _honestThreshold, | ||
"0xbc4862697a1099074168d54A555c4A60169c18BD" // _owner | ||
).catch((err) => { | ||
assert.fail(`ecdsa keep creation failed: ${err}`); | ||
}); | ||
|
||
let eventList = await keepFactory.getPastEvents('ECDSAKeepCreated', { | ||
fromBlock: blockNumber, | ||
toBlock: 'latest' | ||
}) | ||
|
||
assert.isTrue( | ||
web3.utils.isAddress(keepAddress), | ||
`keep address ${keepAddress} is not a valid address`, | ||
); | ||
|
||
assert.equal(eventList.length, 1, "incorrect number of emitted events") | ||
|
||
assert.equal( | ||
eventList[0].returnValues.keepAddress, | ||
keepAddress, | ||
"incorrect keep address in emitted event", | ||
) | ||
}); | ||
}); | ||
const ECDSAKeepFactory = artifacts.require('ECDSAKeepFactory') | ||
|
||
contract('ECDSAKeepFactory', async (accounts) => { | ||
it('emits ECDSAKeepCreated event upon keep creation', async () => { | ||
const blockNumber = await web3.eth.getBlockNumber() | ||
|
||
const keepFactory = await ECDSAKeepFactory.deployed() | ||
|
||
const keepAddress = await keepFactory.createNewKeep.call( | ||
10, // _groupSize, | ||
5, // _honestThreshold, | ||
'0xbc4862697a1099074168d54A555c4A60169c18BD' // _owner | ||
).catch((err) => { | ||
assert.fail(`ecdsa keep creation failed: ${err}`) | ||
}) | ||
|
||
await keepFactory.createNewKeep( | ||
10, // _groupSize, | ||
5, // _honestThreshold, | ||
'0xbc4862697a1099074168d54A555c4A60169c18BD' // _owner | ||
).catch((err) => { | ||
assert.fail(`ecdsa keep creation failed: ${err}`) | ||
}) | ||
|
||
const eventList = await keepFactory.getPastEvents('ECDSAKeepCreated', { | ||
fromBlock: blockNumber, | ||
toBlock: 'latest', | ||
}) | ||
|
||
assert.isTrue( | ||
web3.utils.isAddress(keepAddress), | ||
`keep address ${keepAddress} is not a valid address`, | ||
) | ||
|
||
assert.equal(eventList.length, 1, 'incorrect number of emitted events') | ||
|
||
assert.equal( | ||
eventList[0].returnValues.keepAddress, | ||
keepAddress, | ||
'incorrect keep address in emitted event', | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,79 @@ | ||
const ECDSAKeepFactory = artifacts.require('./ECDSAKeepFactory.sol'); | ||
const ECDSAKeep = artifacts.require('./ECDSAKeep.sol'); | ||
const ECDSAKeep = artifacts.require('./ECDSAKeep.sol') | ||
|
||
const truffleAssert = require('truffle-assertions'); | ||
const truffleAssert = require('truffle-assertions') | ||
|
||
contract('ECDSAKeep', function(accounts) { | ||
describe("#constructor", async function() { | ||
describe('#constructor', async function() { | ||
it('succeeds', async () => { | ||
let owner = accounts[0] | ||
let members = [ owner ]; | ||
let threshold = 1; | ||
const owner = accounts[0] | ||
const members = [owner] | ||
const threshold = 1 | ||
|
||
let instance = await ECDSAKeep.new( | ||
owner, | ||
members, | ||
threshold | ||
); | ||
const instance = await ECDSAKeep.new( | ||
owner, | ||
members, | ||
threshold | ||
) | ||
|
||
expect(instance.address).to.be.not.empty; | ||
expect(instance.address).to.be.not.empty | ||
}) | ||
}); | ||
}) | ||
|
||
describe('#sign', async function () { | ||
let instance; | ||
describe('#sign', async function() { | ||
let instance | ||
|
||
before(async () => { | ||
let owner = accounts[0] | ||
let members = [ owner ]; | ||
let threshold = 1; | ||
|
||
instance = await ECDSAKeep.new( | ||
owner, | ||
members, | ||
threshold | ||
); | ||
}); | ||
const owner = accounts[0] | ||
const members = [owner] | ||
const threshold = 1 | ||
|
||
instance = await ECDSAKeep.new( | ||
owner, | ||
members, | ||
threshold | ||
) | ||
}) | ||
|
||
it('emits event', async () => { | ||
let res = await instance.sign('0x00') | ||
truffleAssert.eventEmitted(res, 'SignatureRequested', (ev) => { | ||
return ev.digest == '0x00' | ||
}); | ||
const res = await instance.sign('0x00') | ||
truffleAssert.eventEmitted(res, 'SignatureRequested', (ev) => { | ||
return ev.digest == '0x00' | ||
}) | ||
}) | ||
}) | ||
|
||
describe("public key", () => { | ||
let expectedPublicKey = web3.utils.hexToBytes("0x67656e657261746564207075626c6963206b6579") | ||
let owner = "0xbc4862697a1099074168d54A555c4A60169c18BD"; | ||
let members = ["0x774700a36A96037936B8666dCFdd3Fb6687b08cb"]; | ||
let honestThreshold = 5; | ||
describe('public key', () => { | ||
const expectedPublicKey = web3.utils.hexToBytes('0x67656e657261746564207075626c6963206b6579') | ||
const owner = '0xbc4862697a1099074168d54A555c4A60169c18BD' | ||
const members = ['0x774700a36A96037936B8666dCFdd3Fb6687b08cb'] | ||
const honestThreshold = 5 | ||
|
||
it("get public key before it is set", async () => { | ||
let keep = await ECDSAKeep.new(owner, members, honestThreshold); | ||
it('get public key before it is set', async () => { | ||
const keep = await ECDSAKeep.new(owner, members, honestThreshold) | ||
|
||
let publicKey = await keep.getPublicKey.call().catch((err) => { | ||
assert.fail(`ecdsa keep creation failed: ${err}`); | ||
}); | ||
const publicKey = await keep.getPublicKey.call().catch((err) => { | ||
assert.fail(`ecdsa keep creation failed: ${err}`) | ||
}) | ||
|
||
assert.equal(publicKey, undefined, "incorrect public key") | ||
}); | ||
assert.equal(publicKey, undefined, 'incorrect public key') | ||
}) | ||
|
||
it("set public key and get it", async () => { | ||
let keep = await ECDSAKeep.new(owner, members, honestThreshold); | ||
it('set public key and get it', async () => { | ||
const keep = await ECDSAKeep.new(owner, members, honestThreshold) | ||
|
||
await keep.setPublicKey(expectedPublicKey).catch((err) => { | ||
assert.fail(`ecdsa keep creation failed: ${err}`); | ||
}); | ||
await keep.setPublicKey(expectedPublicKey).catch((err) => { | ||
assert.fail(`ecdsa keep creation failed: ${err}`) | ||
}) | ||
|
||
let publicKey = await keep.getPublicKey.call().catch((err) => { | ||
assert.fail(`cannot get public key: ${err}`); | ||
}); | ||
const publicKey = await keep.getPublicKey.call().catch((err) => { | ||
assert.fail(`cannot get public key: ${err}`) | ||
}) | ||
|
||
assert.equal( | ||
publicKey, | ||
web3.utils.bytesToHex(expectedPublicKey), | ||
"incorrect public key" | ||
) | ||
}); | ||
assert.equal( | ||
publicKey, | ||
web3.utils.bytesToHex(expectedPublicKey), | ||
'incorrect public key' | ||
) | ||
}) | ||
}) | ||
|
||
}); | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I alllso don't love this, but don't have an immediate fix in mind. Though worth noting, it's usually safer to use
sh
instead of having to/usr/bin/env bash
unless you're relying on bash-specific behavior.