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

tests: add and follow solium rules #154

Open
wants to merge 9 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
3 changes: 3 additions & 0 deletions .soliumignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
examples/simple/node_modules
examples/complex/node_modules
25 changes: 25 additions & 0 deletions .soliumrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"extends": "solium:all",
"plugins": ["security"],
"rules": {
"imports-on-top": "warning",
"variable-declarations": "warning",
"array-declarations": "warning",
"operator-whitespace": "warning",
"lbrace": "warning",
"function-whitespace": "warning",
"semicolon-whitespace": "warning",
"comma-whitespace": "warning",
"conditionals-whitespace": "warning",
"quotes": ["warning", "double"],
"no-empty-blocks": "off",
"indentation": ["warning", 2],
"max-len": ["warning", 120],
"arg-overflow": ["warning", 3],
"no-constant": "error",
"security/enforce-explicit-visibility": "error",
"security/no-block-members": "warning",
"security/no-inline-assembly": "warning",
"arg-overflow": ["off"]
}
}
25 changes: 19 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
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
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 and javascript style tests.
- stage: static
script: npm run lint:sol

notifications:
slack:
rooms:
Expand Down
7 changes: 5 additions & 2 deletions contracts/application/AppDirectory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "./versioning/ImplementationProvider.sol";
import "./versioning/ImplementationDirectory.sol";
import "openzeppelin-solidity/contracts/ownership/Ownable.sol";


/**
* @title AppDirectory
* @dev Implementation directory with a standard library as a fallback provider.
Expand Down Expand Up @@ -40,8 +41,10 @@ contract AppDirectory is ImplementationDirectory {
*/
function getImplementation(string contractName) public view returns (address) {
address implementation = super.getImplementation(contractName);
if(implementation != address(0)) return implementation;
if(stdlib != address(0)) return stdlib.getImplementation(contractName);
if (implementation != address(0))
return implementation;
if (stdlib != address(0))
return stdlib.getImplementation(contractName);
return address(0);
}

Expand Down
16 changes: 9 additions & 7 deletions contracts/application/BaseApp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "../upgradeability/AdminUpgradeabilityProxy.sol";
import "../upgradeability/UpgradeabilityProxyFactory.sol";
import "openzeppelin-solidity/contracts/ownership/Ownable.sol";


/**
* @title BaseApp
* @dev Abstract base contract for upgradeable applications.
Expand All @@ -23,12 +24,6 @@ contract BaseApp is Ownable {
factory = _factory;
}

/**
* @dev Abstract function to return the implementation provider.
* @return The implementation provider.
*/
function getProvider() internal view returns (ImplementationProvider);

/**
* @dev Returns the implementation address for a given contract name, provided by the `ImplementationProvider`.
* @param contractName Name of the contract.
Expand Down Expand Up @@ -58,7 +53,7 @@ contract BaseApp is Ownable {
* https://solidity.readthedocs.io/en/develop/abi-spec.html#function-selector-and-argument-encoding.
* @return Address of the new proxy.
*/
function createAndCall(string contractName, bytes data) payable public returns (AdminUpgradeabilityProxy) {
function createAndCall(string contractName, bytes data) payable public returns (AdminUpgradeabilityProxy) {
address implementation = getImplementation(contractName);
return factory.createProxyAndCall.value(msg.value)(this, implementation, data);
}
Expand Down Expand Up @@ -105,4 +100,11 @@ contract BaseApp is Ownable {
function getProxyAdmin(AdminUpgradeabilityProxy proxy) public view returns (address) {
return proxy.admin();
}

/**
* @dev Abstract function to return the implementation provider.
* @return The implementation provider.
*/
function getProvider() internal view returns (ImplementationProvider);

}
1 change: 1 addition & 0 deletions contracts/application/PackagedApp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "./BaseApp.sol";
import "./versioning/Package.sol";
import "../upgradeability/UpgradeabilityProxyFactory.sol";


/**
* @title PackagedApp
* @dev App for an upgradeable project that can use different versions.
Expand Down
18 changes: 10 additions & 8 deletions contracts/application/UnversionedApp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "./BaseApp.sol";
import "./versioning/ImplementationProvider.sol";
import "../upgradeability/UpgradeabilityProxyFactory.sol";


/**
* @title UnversionedApp
* @dev Basic implementation of an upgradable app with no versioning.
Expand All @@ -26,14 +27,6 @@ contract UnversionedApp is BaseApp {
setProvider(_provider);
}

/**
* @dev Returns the provider used by the app.
* @return The provider.
*/
function getProvider() internal view returns (ImplementationProvider) {
return provider;
}

/**
* @dev Sets a new implementation provider.
* @param _provider New implementation provider
Expand All @@ -42,4 +35,13 @@ contract UnversionedApp is BaseApp {
require(address(_provider) != address(0));
provider = _provider;
}

/**
* @dev Returns the provider used by the app.
* @return The provider.
*/
function getProvider() internal view returns (ImplementationProvider) {
return provider;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ pragma solidity ^0.4.21;

import "./ImplementationDirectory.sol";


/**
* @title FreezableImplementationDirectory
* @dev Implementation directory which can be made irreversibly immutable by the owner.
*/
contract FreezableImplementationDirectory is ImplementationDirectory {
contract FreezableImplementationDirectory is ImplementationDirectory {
/// @dev Mutability state of the directory.
bool public frozen;

Expand Down
3 changes: 2 additions & 1 deletion contracts/application/versioning/ImplementationDirectory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ pragma solidity ^0.4.21;

import "./ImplementationProvider.sol";
import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
import 'openzeppelin-solidity/contracts/AddressUtils.sol';
import "openzeppelin-solidity/contracts/AddressUtils.sol";


/**
* @title ImplementationDirectory
Expand Down
1 change: 1 addition & 0 deletions contracts/application/versioning/Package.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity ^0.4.21;
import "./ImplementationProvider.sol";
import "openzeppelin-solidity/contracts/ownership/Ownable.sol";


/**
* @title Package
* @dev Collection of contracts grouped into versions.
Expand Down
1 change: 1 addition & 0 deletions contracts/application/versioning/Release.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pragma solidity ^0.4.21;

import "./FreezableImplementationDirectory.sol";


/**
* @title Release
* @dev This contract represents a particular standard library version from a developer.
Expand Down
14 changes: 8 additions & 6 deletions contracts/lifecycle/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: 4 additions & 1 deletion contracts/mocks/DummyImplementation.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
pragma solidity ^0.4.21;


contract Impl {
function version() public pure returns (string);
function version() public pure returns (string);
}


contract DummyImplementation {
uint256 public value;
string public text;
Expand All @@ -28,6 +30,7 @@ contract DummyImplementation {
}
}


contract DummyImplementationV2 is DummyImplementation {
function migrate(uint256 newVal) public {
value = newVal;
Expand Down
1 change: 1 addition & 0 deletions contracts/mocks/InitializableMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pragma solidity ^0.4.21;

import "../migrations/Initializable.sol";


/**
* @title InitializableMock
* @dev This contract is a mock to test initializable functionality
Expand Down
1 change: 1 addition & 0 deletions contracts/mocks/MigratableMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pragma solidity ^0.4.21;

import "../migrations/Migratable.sol";


/**
* @title MigratableMock
* @dev This contract is a mock to test upgradeability functionality
Expand Down
Loading