Skip to content
This repository has been archived by the owner on May 22, 2023. It is now read-only.

Linter integration #44

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
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"
Copy link
Contributor

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.

files: '\.sol$'
language: script
description: "Checks Solidity code according to the package's linter configuration"
14 changes: 14 additions & 0 deletions solidity/.eslintrc
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"]
}
}
9 changes: 9 additions & 0 deletions solidity/.soliumrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "keep",
"plugins": [
"security"
],
"rules": {
"security/no-block-members": "off"
}
}
2 changes: 1 addition & 1 deletion solidity/contracts/ECDSAKeep.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ contract ECDSAKeep {
/// @notice Returns the keep signer's public key.
/// @return Signer's public key.
function getPublicKey() public view returns (bytes memory) {
return publicKey;
return publicKey;
}

/// @notice Calculates a signature over provided digest by the keep.
Expand Down
30 changes: 15 additions & 15 deletions solidity/contracts/Migrations.sol
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);
}
}
6 changes: 3 additions & 3 deletions solidity/migrations/1_initial_migration.js
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)
}
12 changes: 6 additions & 6 deletions solidity/migrations/2_deploy_contracts.js
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)
}
15 changes: 13 additions & 2 deletions solidity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Copy link
Contributor

Choose a reason for hiding this comment

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

Are the configs not dev dependencies?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh woops! Nice catch

},
"devDependencies": {
"@babel/cli": "^7.4.4",
Expand All @@ -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"
Expand Down
87 changes: 43 additions & 44 deletions solidity/test/ECDSAKeepFactoryTest.js
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',
)
})
})
114 changes: 56 additions & 58 deletions solidity/test/ECDSAKeepTest.js
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'
)
})
})

});
})