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

Commit 91e0213

Browse files
committed
tests: add and follow solium rules
1 parent 47edcb5 commit 91e0213

24 files changed

+1962
-1483
lines changed

.soliumrc.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"extends": "solium:all",
3+
"plugins": ["security"],
4+
"rules": {
5+
"quotes": ["error", "double"],
6+
"no-empty-blocks": "off",
7+
"indentation": ["error", 2],
8+
"max-len": ["error", 79],
9+
"no-constant": ["error"],
10+
"security/enforce-explicit-visibility": ["error"],
11+
"security/no-block-members": ["warning"],
12+
"security/no-inline-assembly": ["warning"],
13+
"arg-overflow": ["off"]
14+
}
15+
}

.travis.yml

+19-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
11
language: node_js
22
node_js:
33
- '8'
4+
45
cache:
56
directories:
67
- node_modules
7-
env:
8-
-
9-
- SOLIDITY_COVERAGE=true
10-
matrix:
8+
9+
jobs:
10+
# XXX fast_finish doesn't work with stages yet. See
11+
# https://github.com/travis-ci/travis-ci/issues/8425
12+
# --elopio - 20180531
1113
fast_finish: true
1214
allow_failures:
1315
- env: SOLIDITY_COVERAGE=true
14-
script:
15-
- npm test
16+
include:
17+
# Run the unit test suite three times in parallel.
18+
# The first one gets results faster and is the only one required to pass.
19+
# The second one generates the coverage report.
20+
- stage: unit
21+
script: npm test
22+
- stage: unit
23+
script: npm run test
24+
env: SOLIDITY_COVERAGE=true
25+
# solidity and javascript style tests.
26+
- stage: static
27+
script: npm run lint:sol
28+
1629
notifications:
1730
slack:
1831
rooms:

contracts/application/AppDirectory.sol

+8-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import "./versioning/ImplementationProvider.sol";
44
import "./versioning/ImplementationDirectory.sol";
55
import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
66

7+
78
/**
89
* @title AppDirectory
910
* @dev Implementation directory with a standard library as a fallback provider.
@@ -38,10 +39,14 @@ contract AppDirectory is ImplementationDirectory {
3839
* @return Address where the contract is implemented, or 0 if it is not
3940
* found.
4041
*/
41-
function getImplementation(string contractName) public view returns (address) {
42+
function getImplementation(string contractName)
43+
public view returns (address)
44+
{
4245
address implementation = super.getImplementation(contractName);
43-
if(implementation != address(0)) return implementation;
44-
if(stdlib != address(0)) return stdlib.getImplementation(contractName);
46+
if (implementation != address(0))
47+
return implementation;
48+
if (stdlib != address(0))
49+
return stdlib.getImplementation(contractName);
4550
return address(0);
4651
}
4752

contracts/application/BaseApp.sol

+47-14
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import "../upgradeability/AdminUpgradeabilityProxy.sol";
55
import "../upgradeability/UpgradeabilityProxyFactory.sol";
66
import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
77

8+
89
/**
910
* @title BaseApp
1011
* @dev Abstract base contract for upgradeable applications.
@@ -23,18 +24,14 @@ contract BaseApp is Ownable {
2324
factory = _factory;
2425
}
2526

26-
/**
27-
* @dev Abstract function to return the implementation provider.
28-
* @return The implementation provider.
29-
*/
30-
function getProvider() internal view returns (ImplementationProvider);
31-
3227
/**
3328
* @dev Returns the implementation address for a given contract name, provided by the `ImplementationProvider`.
3429
* @param contractName Name of the contract.
3530
* @return Address where the contract is implemented.
3631
*/
37-
function getImplementation(string contractName) public view returns (address) {
32+
function getImplementation(string contractName)
33+
public view returns (address)
34+
{
3835
return getProvider().getImplementation(contractName);
3936
}
4037

@@ -43,7 +40,10 @@ contract BaseApp is Ownable {
4340
* @param contractName Name of the contract.
4441
* @return Address of the new proxy.
4542
*/
46-
function create(string contractName) public returns (AdminUpgradeabilityProxy) {
43+
function create(string contractName)
44+
public
45+
returns (AdminUpgradeabilityProxy)
46+
{
4747
address implementation = getImplementation(contractName);
4848
return factory.createProxy(this, implementation);
4949
}
@@ -58,17 +58,31 @@ contract BaseApp is Ownable {
5858
* https://solidity.readthedocs.io/en/develop/abi-spec.html#function-selector-and-argument-encoding.
5959
* @return Address of the new proxy.
6060
*/
61-
function createAndCall(string contractName, bytes data) payable public returns (AdminUpgradeabilityProxy) {
61+
function createAndCall(
62+
string contractName,
63+
bytes data
64+
)
65+
payable
66+
public
67+
returns (AdminUpgradeabilityProxy)
68+
{
6269
address implementation = getImplementation(contractName);
63-
return factory.createProxyAndCall.value(msg.value)(this, implementation, data);
70+
return factory.createProxyAndCall.value(
71+
msg.value)(this, implementation, data);
6472
}
6573

6674
/**
6775
* @dev Upgrades a proxy to the newest implementation of a contract.
6876
* @param proxy Proxy to be upgraded.
6977
* @param contractName Name of the contract.
7078
*/
71-
function upgrade(AdminUpgradeabilityProxy proxy, string contractName) public onlyOwner {
79+
function upgrade(
80+
AdminUpgradeabilityProxy proxy,
81+
string contractName
82+
)
83+
public
84+
onlyOwner
85+
{
7286
address implementation = getImplementation(contractName);
7387
proxy.upgradeTo(implementation);
7488
}
@@ -83,7 +97,15 @@ contract BaseApp is Ownable {
8397
* called, as described in
8498
* https://solidity.readthedocs.io/en/develop/abi-spec.html#function-selector-and-argument-encoding.
8599
*/
86-
function upgradeAndCall(AdminUpgradeabilityProxy proxy, string contractName, bytes data) payable public onlyOwner {
100+
function upgradeAndCall(
101+
AdminUpgradeabilityProxy proxy,
102+
string contractName,
103+
bytes data
104+
)
105+
payable
106+
public
107+
onlyOwner
108+
{
87109
address implementation = getImplementation(contractName);
88110
proxy.upgradeToAndCall.value(msg.value)(implementation, data);
89111
}
@@ -93,7 +115,9 @@ contract BaseApp is Ownable {
93115
* This is needed because only the proxy admin can query it.
94116
* @return The address of the current implementation of the proxy.
95117
*/
96-
function getProxyImplementation(AdminUpgradeabilityProxy proxy) public view returns (address) {
118+
function getProxyImplementation(AdminUpgradeabilityProxy proxy)
119+
public view returns (address)
120+
{
97121
return proxy.implementation();
98122
}
99123

@@ -102,7 +126,16 @@ contract BaseApp is Ownable {
102126
* Only the admin can query it.
103127
* @return The address of the current admin of the proxy.
104128
*/
105-
function getProxyAdmin(AdminUpgradeabilityProxy proxy) public view returns (address) {
129+
function getProxyAdmin(AdminUpgradeabilityProxy proxy)
130+
public view returns (address)
131+
{
106132
return proxy.admin();
107133
}
134+
135+
/**
136+
* @dev Abstract function to return the implementation provider.
137+
* @return The implementation provider.
138+
*/
139+
function getProvider() internal view returns (ImplementationProvider);
140+
108141
}

contracts/application/PackagedApp.sol

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import "./BaseApp.sol";
44
import "./versioning/Package.sol";
55
import "../upgradeability/UpgradeabilityProxyFactory.sol";
66

7+
78
/**
89
* @title PackagedApp
910
* @dev App for an upgradeable project that can use different versions.
@@ -21,7 +22,11 @@ contract PackagedApp is BaseApp {
2122
* @param _version Initial version of the app.
2223
* @param _factory Proxy factory.
2324
*/
24-
function PackagedApp(Package _package, string _version, UpgradeabilityProxyFactory _factory)
25+
function PackagedApp(
26+
Package _package,
27+
string _version,
28+
UpgradeabilityProxyFactory _factory
29+
)
2530
BaseApp(_factory)
2631
public
2732
{

contracts/application/UnversionedApp.sol

+14-9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import "./BaseApp.sol";
44
import "./versioning/ImplementationProvider.sol";
55
import "../upgradeability/UpgradeabilityProxyFactory.sol";
66

7+
78
/**
89
* @title UnversionedApp
910
* @dev Basic implementation of an upgradable app with no versioning.
@@ -19,21 +20,16 @@ contract UnversionedApp is BaseApp {
1920
* @param _provider Implementation provider.
2021
* @param _factory Proxy factory.
2122
*/
22-
function UnversionedApp(ImplementationProvider _provider, UpgradeabilityProxyFactory _factory)
23+
function UnversionedApp(
24+
ImplementationProvider _provider,
25+
UpgradeabilityProxyFactory _factory
26+
)
2327
BaseApp(_factory)
2428
public
2529
{
2630
setProvider(_provider);
2731
}
2832

29-
/**
30-
* @dev Returns the provider used by the app.
31-
* @return The provider.
32-
*/
33-
function getProvider() internal view returns (ImplementationProvider) {
34-
return provider;
35-
}
36-
3733
/**
3834
* @dev Sets a new implementation provider.
3935
* @param _provider New implementation provider
@@ -42,4 +38,13 @@ contract UnversionedApp is BaseApp {
4238
require(address(_provider) != address(0));
4339
provider = _provider;
4440
}
41+
42+
/**
43+
* @dev Returns the provider used by the app.
44+
* @return The provider.
45+
*/
46+
function getProvider() internal view returns (ImplementationProvider) {
47+
return provider;
48+
}
49+
4550
}

contracts/application/versioning/FreezableImplementationDirectory.sol

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ pragma solidity ^0.4.21;
22

33
import "./ImplementationDirectory.sol";
44

5+
56
/**
67
* @title FreezableImplementationDirectory
78
* @dev Implementation directory which can be made irreversibly immutable by the owner.
89
*/
9-
contract FreezableImplementationDirectory is ImplementationDirectory {
10+
contract FreezableImplementationDirectory is ImplementationDirectory {
1011
/// @dev Mutability state of the directory.
1112
bool public frozen;
1213

@@ -32,7 +33,12 @@ import "./ImplementationDirectory.sol";
3233
* @param contractName Name of the contract.
3334
* @param implementation Address where the contract is implemented.
3435
*/
35-
function setImplementation(string contractName, address implementation) public whenNotFrozen {
36+
function setImplementation(
37+
string contractName,
38+
address implementation
39+
)
40+
public whenNotFrozen
41+
{
3642
super.setImplementation(contractName, implementation);
3743
}
3844
}

contracts/application/versioning/ImplementationDirectory.sol

+12-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ pragma solidity ^0.4.21;
22

33
import "./ImplementationProvider.sol";
44
import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
5-
import 'openzeppelin-solidity/contracts/AddressUtils.sol';
5+
import "openzeppelin-solidity/contracts/AddressUtils.sol";
6+
67

78
/**
89
* @title ImplementationDirectory
@@ -24,7 +25,9 @@ contract ImplementationDirectory is ImplementationProvider, Ownable {
2425
* @param contractName Name of the contract.
2526
* @return Address of the implementation.
2627
*/
27-
function getImplementation(string contractName) public view returns (address) {
28+
function getImplementation(string contractName)
29+
public view returns (address)
30+
{
2831
return implementations[contractName];
2932
}
3033

@@ -33,7 +36,13 @@ contract ImplementationDirectory is ImplementationProvider, Ownable {
3336
* @param contractName Name of the contract.
3437
* @param implementation Address of the implementation.
3538
*/
36-
function setImplementation(string contractName, address implementation) public onlyOwner {
39+
function setImplementation(
40+
string contractName,
41+
address implementation
42+
)
43+
public
44+
onlyOwner
45+
{
3746
require(AddressUtils.isContract(implementation));
3847
implementations[contractName] = implementation;
3948
emit ImplementationChanged(contractName, implementation);

contracts/application/versioning/ImplementationProvider.sol

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ interface ImplementationProvider {
1010
* @param contractName Name of the contract.
1111
* @return Implementation address of the contract.
1212
*/
13-
function getImplementation(string contractName) public view returns (address);
13+
function getImplementation(string contractName)
14+
public view returns (address);
1415
}

contracts/application/versioning/Package.sol

+14-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pragma solidity ^0.4.21;
33
import "./ImplementationProvider.sol";
44
import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
55

6+
67
/**
78
* @title Package
89
* @dev Collection of contracts grouped into versions.
@@ -27,7 +28,9 @@ contract Package is Ownable {
2728
* @param version Name of the version.
2829
* @return The implementation provider of the version.
2930
*/
30-
function getVersion(string version) public view returns (ImplementationProvider) {
31+
function getVersion(string version)
32+
public view returns (ImplementationProvider)
33+
{
3134
ImplementationProvider provider = versions[version];
3235
return provider;
3336
}
@@ -37,7 +40,13 @@ contract Package is Ownable {
3740
* @param version Name of the version.
3841
* @param provider ImplementationProvider associated with the version.
3942
*/
40-
function addVersion(string version, ImplementationProvider provider) public onlyOwner {
43+
function addVersion(
44+
string version,
45+
ImplementationProvider provider
46+
)
47+
public
48+
onlyOwner
49+
{
4150
require(!hasVersion(version));
4251
versions[version] = provider;
4352
emit VersionAdded(version, provider);
@@ -58,7 +67,9 @@ contract Package is Ownable {
5867
* @param contractName Name of the contract.
5968
* @return Address where the contract is implemented.
6069
*/
61-
function getImplementation(string version, string contractName) public view returns (address) {
70+
function getImplementation(string version, string contractName)
71+
public view returns (address)
72+
{
6273
ImplementationProvider provider = getVersion(version);
6374
return provider.getImplementation(contractName);
6475
}

contracts/application/versioning/Release.sol

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ pragma solidity ^0.4.21;
22

33
import "./FreezableImplementationDirectory.sol";
44

5+
56
/**
67
* @title Release
78
* @dev This contract represents a particular standard library version from a developer.

0 commit comments

Comments
 (0)