Skip to content
This repository has been archived by the owner on Jul 19, 2019. It is now read-only.

tests: add and follow most of the eslint rules #52

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
51 changes: 51 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"extends" : [
"standard",
"plugin:promise/recommended",
],
"plugins": [
"promise"
],
"env": {
"browser" : true,
"node" : true,
"mocha" : true,
"jest" : true
},
"globals" : {
"artifacts": false,
"contract": false,
"assert": false,
"web3": false
},
"rules": {

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

// Code style
"indent": [2, 2],
"quotes": [2, "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
}
}
1 change: 1 addition & 0 deletions .soliumignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
15 changes: 15 additions & 0 deletions .soliumrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "solium:all",
"plugins": ["security"],
"rules": {
"quotes": ["error", "double"],
"no-empty-blocks": "off",
"indentation": ["error", 2],
"max-len": ["error", 79],
"no-constant": ["error"],
"security/enforce-explicit-visibility": ["error"],
"security/no-block-members": ["warning"],
"security/no-inline-assembly": ["warning"],
"arg-overflow": ["off"]
}
}
28 changes: 21 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
language: node_js

node_js:
- '8'

cache:
directories:
- node_modules
env:
-
- SOLIDITY_COVERAGE=true
matrix:

jobs:
# XXX fast_finish doesn't work with stages yet. See
# https://github.com/travis-ci/travis-ci/issues/8425
# --elopio - 20180531
fast_finish: true
allow_failures:
- env: SOLIDITY_COVERAGE=true
script:
- npm test
- env: SOLIDITY_COVERAGE=true
include:
# Run the unit test suite three times in parallel.
# The first one gets results faster and is the only one required to pass.
# The second one generates the coverage report.
- stage: unit
script: npm test
- stage: unit
script: npm run test
env: SOLIDITY_COVERAGE=true
# solidity style tests.
- stage: static
script: npm run lint:sol

notifications:
slack:
rooms:
Expand Down
46 changes: 40 additions & 6 deletions contracts/Kernel.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "zeppelin-solidity/contracts/math/SafeMath.sol";
import "zos-lib/contracts/migrations/Migratable.sol";
import "zos-lib/contracts/upgradeability/UpgradeabilityProxyFactory.sol";


/**
* @title Kernel
* @dev Controls the standard library releases for ZeppelinOS
Expand Down Expand Up @@ -55,7 +56,10 @@ contract Kernel is Migratable {
uint256 _developerFraction,
ZepToken _token,
Vouching _vouches
) public isInitializer("Kernel", "0") {
)
public
isInitializer("Kernel", "0")
{
vouches = _vouches;
token = _token;
developerFraction = _developerFraction;
Expand All @@ -71,7 +75,7 @@ contract Kernel is Migratable {
require(release.frozen());
releases[release] = true;
emit ReleaseRegistered(release);

require(token.transferFrom(msg.sender, this, newVersionCost));
token.burn(newVersionCost);
}
Expand All @@ -90,7 +94,14 @@ contract Kernel is Migratable {
* @param amount the amount being vouched
* @param data additional information for complex vouching models
*/
function vouch(Release release, uint256 amount, bytes data) public whenRegistered(release) {
function vouch(
Release release,
uint256 amount,
bytes data
)
public
whenRegistered(release)
{
require(token.transferFrom(msg.sender, this, amount));
_payoutAndVouch(msg.sender, release, amount, data);
}
Expand All @@ -101,7 +112,14 @@ contract Kernel is Migratable {
* @param amount the amount being unvouched
* @param data additional information for complex vouching models
*/
function unvouch(Release release, uint256 amount, bytes data) public whenRegistered(release) {
function unvouch(
Release release,
uint256 amount,
bytes data
)
public
whenRegistered(release)
{
vouches.unvouch(msg.sender, release, amount, data);
require(token.transfer(msg.sender, amount));
}
Expand All @@ -113,7 +131,16 @@ contract Kernel is Migratable {
* @param amount the amount of vouches being transferred
* @param data additional information for complex vouching models
*/
function transferVouch(Release from, Release to, uint256 amount, bytes data) public whenRegistered(from) whenRegistered(to) {
function transferVouch(
Release from,
Release to,
uint256 amount,
bytes data
)
public
whenRegistered(from)
whenRegistered(to)
{
vouches.unvouch(msg.sender, from, amount, data);
_payoutAndVouch(msg.sender, to, amount, data);
}
Expand All @@ -125,7 +152,14 @@ contract Kernel is Migratable {
* @param amount the amount being vouched
* @param data additional information for complex vouching models
*/
function _payoutAndVouch(address voucher, Release release, uint256 amount, bytes data) internal {
function _payoutAndVouch(
address voucher,
Release release,
uint256 amount,
bytes data
)
internal
{
uint256 developerPayout = amount.div(developerFraction);
require(developerPayout > 0);

Expand Down
14 changes: 8 additions & 6 deletions contracts/Migrations.sol
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
pragma solidity ^0.4.21;


contract Migrations {
address public owner;
uint public last_completed_migration;
uint public lastCompletedMigration;

modifier restricted() {
if (msg.sender == owner) _;
if (msg.sender == owner)
_;
}

function Migrations() public {
owner = msg.sender;
}

function setCompleted(uint completed) public restricted {
last_completed_migration = completed;
lastCompletedMigration = completed;
}

function upgrade(address new_address) public restricted {
Migrations upgraded = Migrations(new_address);
upgraded.setCompleted(last_completed_migration);
function upgrade(address newAddress) public restricted {
Migrations upgraded = Migrations(newAddress);
upgraded.setCompleted(lastCompletedMigration);
}
}
5 changes: 3 additions & 2 deletions contracts/Release.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
pragma solidity ^0.4.21;

// solium-disable-next-line max-len
import "zos-lib/contracts/application/versioning/FreezableContractDirectory.sol";


/**
* @title Release
* @dev This contract represents a particular stdlib version from a developer
Expand All @@ -11,7 +12,7 @@ contract Release is FreezableContractDirectory {

// Developer address to which staking payouts will be sent, owner of the contract directory
address public developer;

/**
* @dev Constructor function that sets the developer of this release
*/
Expand Down
40 changes: 35 additions & 5 deletions contracts/Vouching.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ contract Vouching is Migratable, Ownable {
* @param total the new total amount vouched
* @param data additional information for complex vouching models
*/
event Vouched(address indexed voucher, address release, uint256 amount, uint256 total, bytes data);
event Vouched(
address indexed voucher,
address release,
uint256 amount,
uint256 total,
bytes data
);

/**
* @dev Event signaling an unvouching
Expand All @@ -30,7 +36,13 @@ contract Vouching is Migratable, Ownable {
* @param total the new total amount vouched
* @param data additional information for complex vouching models
*/
event Unvouched(address indexed voucher, address release, uint256 amount, uint256 total, bytes data);
event Unvouched(
address indexed voucher,
address release,
uint256 amount,
uint256 total,
bytes data
);

// Total amount of vouched tokens
uint256 private _totalVouched;
Expand Down Expand Up @@ -72,7 +84,9 @@ contract Vouching is Migratable, Ownable {
* @param release the stdlib release
* @return the total vouched amount by the voucher for the given release
*/
function vouchedFor(address voucher, address release) public view returns (uint256) {
function vouchedFor(address voucher, address release)
public view returns (uint256)
{
return _vouches[voucher][release];
}

Expand All @@ -83,7 +97,15 @@ contract Vouching is Migratable, Ownable {
* @param amount the amount being vouched
* @param data additional information for complex vouching models
*/
function vouch(address voucher, address release, uint256 amount, bytes data) public onlyOwner {
function vouch(
address voucher,
address release,
uint256 amount,
bytes data
)
public
onlyOwner
{
_totalVouched = _totalVouched.add(amount);
_releaseVouches[release] = _releaseVouches[release].add(amount);
_vouches[voucher][release] = _vouches[voucher][release].add(amount);
Expand All @@ -98,7 +120,15 @@ contract Vouching is Migratable, Ownable {
* @param amount the amount being unvouched
* @param data additional information for complex vouching models
*/
function unvouch(address voucher, address release, uint256 amount, bytes data) public onlyOwner {
function unvouch(
address voucher,
address release,
uint256 amount,
bytes data
)
public
onlyOwner
{
uint256 currentVouch = _vouches[voucher][release];
require(currentVouch >= amount);

Expand Down
19 changes: 14 additions & 5 deletions contracts/ZepToken.sol
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
pragma solidity ^0.4.21;

import 'zos-lib/contracts/migrations/Migratable.sol';
import 'zeppelin-solidity/contracts/token/ERC20/PausableToken.sol';
import 'zeppelin-solidity/contracts/token/ERC20/MintableToken.sol';
import 'zeppelin-solidity/contracts/token/ERC20/BurnableToken.sol';
import 'zeppelin-solidity/contracts/token/ERC20/StandardToken.sol';
import "zos-lib/contracts/migrations/Migratable.sol";
import "zeppelin-solidity/contracts/token/ERC20/PausableToken.sol";
import "zeppelin-solidity/contracts/token/ERC20/MintableToken.sol";
import "zeppelin-solidity/contracts/token/ERC20/BurnableToken.sol";
import "zeppelin-solidity/contracts/token/ERC20/StandardToken.sol";


/**
* @title ZepToken
* @dev ZEP token contract including mintable, pausable and burnable functionalities
*/
// XXX There doesn't seem to be a way to split this line that keeps solium
// happy. See:
// https://github.com/duaraghav8/Solium/issues/205
// --elopio - 2018-05-31
// solium-disable-next-line max-len
contract ZepToken is Migratable, StandardToken, MintableToken, PausableToken, BurnableToken {

// solium-disable-next-line uppercase
string public constant name = "Zep Token";
// solium-disable-next-line uppercase
string public constant symbol = "ZEP";
// solium-disable-next-line uppercase
uint8 public constant decimals = 18;

/**
Expand Down
14 changes: 11 additions & 3 deletions contracts/test/MockKernelV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,25 @@ pragma solidity ^0.4.18;

import "../Kernel.sol";


contract MockKernelV2 is Kernel {

function testV2() public pure returns (string) {
return "v2";
}

// Duplicate developer payout, because reasons
function _payoutAndVouch(address voucher, Release release, uint256 amount, bytes data) internal {
function _payoutAndVouch(
address voucher,
Release release,
uint256 amount,
bytes data
)
internal
{
uint256 developerPayout = amount.mul(2).div(developerFraction);
require(developerPayout > 0);

uint256 vouchedAmount = amount.sub(developerPayout);
vouches.vouch(voucher, release, vouchedAmount, data);
require(token.transfer(release.developer(), developerPayout));
Expand Down
Loading