Skip to content

Commit

Permalink
tests: fix most of the static warnings (#844)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo Arias authored and frangio committed Mar 28, 2018
1 parent 42787e2 commit 82ce197
Show file tree
Hide file tree
Showing 30 changed files with 173 additions and 70 deletions.
15 changes: 11 additions & 4 deletions contracts/AddressUtils.sol
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
pragma solidity ^0.4.18;


/**
* Utility library of inline functions on addresses
*/
library AddressUtils {

/**
* Returns whether there is code in the target address
* Returns whether the target address is a contract
* @dev This function will return false if invoked during the constructor of a contract,
* as the code is not actually created until after the constructor finishes.
* @param addr address address to check
* @return whether there is code in the target address
* @param addr address to check
* @return whether the target address is a contract
*/
function isContract(address addr) internal view returns (bool) {
uint256 size;
assembly { size := extcodesize(addr) }
// XXX Currently there is no better way to check if there is a contract in an address
// than to check the size of the code at that address.
// See https://ethereum.stackexchange.com/a/14016/36603
// for more details about how this works.
// TODO Check this again before the Serenity release, because all addresses will be
// contracts then.
assembly { size := extcodesize(addr) } // solium-disable-line security/no-inline-assembly
return size > 0;
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/DayLimit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ contract DayLimit {
* @return uint256 of today's index.
*/
function today() private view returns (uint256) {
return now / 1 days;
return block.timestamp / 1 days;
}

/**
Expand Down
7 changes: 7 additions & 0 deletions contracts/ECRecovery.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ pragma solidity ^0.4.18;
* @title Eliptic curve signature operations
*
* @dev Based on https://gist.github.com/axic/5b33912c6f61ae6fd96d6c4a47afde6d
*
* TODO Remove this library once solidity supports passing a signature to ecrecover.
* See https://github.com/ethereum/solidity/issues/864
*
*/

library ECRecovery {
Expand All @@ -25,6 +29,9 @@ library ECRecovery {
}

// Divide the signature in r, s and v variables
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
// solium-disable-next-line security/no-inline-assembly
assembly {
r := mload(add(sig, 32))
s := mload(add(sig, 64))
Expand Down
1 change: 1 addition & 0 deletions contracts/MerkleProof.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ library MerkleProof {
bytes32 computedHash = _leaf;

for (uint256 i = 32; i <= _proof.length; i += 32) {
// solium-disable-next-line security/no-inline-assembly
assembly {
// Load the current element of the proof
proofElement := mload(add(_proof, i))
Expand Down
4 changes: 2 additions & 2 deletions contracts/crowdsale/Crowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity ^0.4.18;
import "../token/ERC20/ERC20.sol";
import "../math/SafeMath.sol";


/**
* @title Crowdsale
* @dev Crowdsale is a base contract for managing a token crowdsale,
Expand All @@ -11,11 +12,10 @@ import "../math/SafeMath.sol";
* functionality and/or custom behavior.
* The external interface represents the basic interface for purchasing tokens, and conform
* the base architecture for crowdsales. They are *not* intended to be modified / overriden.
* The internal interface conforms the extensible and modifiable surface of crowdsales. Override
* The internal interface conforms the extensible and modifiable surface of crowdsales. Override
* the methods to add functionality. Consider using 'super' where appropiate to concatenate
* behavior.
*/

contract Crowdsale {
using SafeMath for uint256;

Expand Down
2 changes: 2 additions & 0 deletions contracts/crowdsale/distribution/FinalizableCrowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "../../math/SafeMath.sol";
import "../../ownership/Ownable.sol";
import "../validation/TimedCrowdsale.sol";


/**
* @title FinalizableCrowdsale
* @dev Extension of Crowdsale where an owner can do extra work
Expand Down Expand Up @@ -37,4 +38,5 @@ contract FinalizableCrowdsale is TimedCrowdsale, Ownable {
*/
function finalization() internal {
}

}
20 changes: 11 additions & 9 deletions contracts/crowdsale/distribution/PostDeliveryCrowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "../validation/TimedCrowdsale.sol";
import "../../token/ERC20/ERC20.sol";
import "../../math/SafeMath.sol";


/**
* @title PostDeliveryCrowdsale
* @dev Crowdsale that locks tokens from withdrawal until it ends.
Expand All @@ -13,15 +14,6 @@ contract PostDeliveryCrowdsale is TimedCrowdsale {

mapping(address => uint256) public balances;

/**
* @dev Overrides parent by storing balances instead of issuing tokens right away.
* @param _beneficiary Token purchaser
* @param _tokenAmount Amount of tokens purchased
*/
function _processPurchase(address _beneficiary, uint256 _tokenAmount) internal {
balances[_beneficiary] = balances[_beneficiary].add(_tokenAmount);
}

/**
* @dev Withdraw tokens only after crowdsale ends.
*/
Expand All @@ -32,4 +24,14 @@ contract PostDeliveryCrowdsale is TimedCrowdsale {
balances[msg.sender] = 0;
_deliverTokens(msg.sender, amount);
}

/**
* @dev Overrides parent by storing balances instead of issuing tokens right away.
* @param _beneficiary Token purchaser
* @param _tokenAmount Amount of tokens purchased
*/
function _processPurchase(address _beneficiary, uint256 _tokenAmount) internal {
balances[_beneficiary] = balances[_beneficiary].add(_tokenAmount);
}

}
9 changes: 5 additions & 4 deletions contracts/crowdsale/price/IncreasingPriceCrowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ pragma solidity ^0.4.18;
import "../validation/TimedCrowdsale.sol";
import "../../math/SafeMath.sol";


/**
* @title IncreasingPriceCrowdsale
* @dev Extension of Crowdsale contract that increases the price of tokens linearly in time.
* @dev Extension of Crowdsale contract that increases the price of tokens linearly in time.
* Note that what should be provided to the constructor is the initial and final _rates_, that is,
* the amount of tokens per wei contributed. Thus, the initial rate must be greater than the final rate.
*/
Expand All @@ -28,12 +29,12 @@ contract IncreasingPriceCrowdsale is TimedCrowdsale {
}

/**
* @dev Returns the rate of tokens per wei at the present time.
* Note that, as price _increases_ with time, the rate _decreases_.
* @dev Returns the rate of tokens per wei at the present time.
* Note that, as price _increases_ with time, the rate _decreases_.
* @return The number of tokens a buyer gets per wei at a given time
*/
function getCurrentRate() public view returns (uint256) {
uint256 elapsedTime = now.sub(openingTime);
uint256 elapsedTime = block.timestamp.sub(openingTime);
uint256 timeRange = closingTime.sub(openingTime);
uint256 rateRange = initialRate.sub(finalRate);
return initialRate.sub(elapsedTime.mul(rateRange).div(timeRange));
Expand Down
10 changes: 5 additions & 5 deletions contracts/crowdsale/validation/TimedCrowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ contract TimedCrowdsale is Crowdsale {
uint256 public closingTime;

/**
* @dev Reverts if not in crowdsale time range.
* @dev Reverts if not in crowdsale time range.
*/
modifier onlyWhileOpen {
require(now >= openingTime && now <= closingTime);
require(block.timestamp >= openingTime && block.timestamp <= closingTime);
_;
}

Expand All @@ -28,7 +28,7 @@ contract TimedCrowdsale is Crowdsale {
* @param _closingTime Crowdsale closing time
*/
function TimedCrowdsale(uint256 _openingTime, uint256 _closingTime) public {
require(_openingTime >= now);
require(_openingTime >= block.timestamp);
require(_closingTime >= _openingTime);

openingTime = _openingTime;
Expand All @@ -40,9 +40,9 @@ contract TimedCrowdsale is Crowdsale {
* @return Whether crowdsale period has elapsed
*/
function hasClosed() public view returns (bool) {
return now > closingTime;
return block.timestamp > closingTime;
}

/**
* @dev Extend parent behavior requiring to be within contributing period
* @param _beneficiary Token purchaser
Expand Down
11 changes: 10 additions & 1 deletion contracts/examples/SampleCrowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,16 @@ contract SampleCrowdsaleToken is MintableToken {
*/
contract SampleCrowdsale is CappedCrowdsale, RefundableCrowdsale, MintedCrowdsale {

function SampleCrowdsale(uint256 _openingTime, uint256 _closingTime, uint256 _rate, address _wallet, uint256 _cap, MintableToken _token, uint256 _goal) public
function SampleCrowdsale(
uint256 _openingTime,
uint256 _closingTime,
uint256 _rate,
address _wallet,
uint256 _cap,
MintableToken _token,
uint256 _goal
)
public
Crowdsale(_rate, _wallet, _token)
CappedCrowdsale(_cap)
TimedCrowdsale(_openingTime, _closingTime)
Expand Down
8 changes: 5 additions & 3 deletions contracts/mocks/ERC223TokenMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ pragma solidity ^0.4.18;

import "../token/ERC20/BasicToken.sol";


contract ERC223ContractInterface {
function tokenFallback(address _from, uint256 _value, bytes _data) external;
}


contract ERC223TokenMock is BasicToken {

function ERC223TokenMock(address initialAccount, uint256 initialBalance) public {
Expand All @@ -18,11 +20,11 @@ contract ERC223TokenMock is BasicToken {
returns (bool success)
{
transfer(_to, _value);
bool is_contract = false;
bool isContract = false;
assembly {
is_contract := not(iszero(extcodesize(_to)))
isContract := not(iszero(extcodesize(_to)))
}
if (is_contract) {
if (isContract) {
ERC223ContractInterface receiver = ERC223ContractInterface(_to);
receiver.tokenFallback(msg.sender, _value, _data);
}
Expand Down
1 change: 1 addition & 0 deletions contracts/mocks/ERC721BasicTokenMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pragma solidity ^0.4.18;

import "../token/ERC721/ERC721BasicToken.sol";


/**
* @title ERC721BasicTokenMock
* This mock just provides a public mint and burn functions for testing purposes
Expand Down
3 changes: 2 additions & 1 deletion contracts/mocks/ERC721ReceiverMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ pragma solidity ^0.4.18;

import "../token/ERC721/ERC721Receiver.sol";


contract ERC721ReceiverMock is ERC721Receiver {
bytes4 retval;
bool reverts;

event Received(address _address, uint256 _tokenId, bytes _data, uint256 _gas);

function ERC721ReceiverMock(bytes4 _retval, bool _reverts) public {
Expand Down
3 changes: 2 additions & 1 deletion contracts/mocks/ERC721TokenMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pragma solidity ^0.4.18;

import "../token/ERC721/ERC721Token.sol";


/**
* @title ERC721TokenMock
* This mock just provides a public mint and burn functions for testing purposes,
Expand All @@ -23,4 +24,4 @@ contract ERC721TokenMock is ERC721Token {
function setTokenURI(uint256 _tokenId, string _uri) public {
super._setTokenURI(_tokenId, _uri);
}
}
}
1 change: 1 addition & 0 deletions contracts/mocks/MessageHelper.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pragma solidity ^0.4.11;


contract MessageHelper {

event Show(bytes32 b32, uint256 number, string text);
Expand Down
3 changes: 2 additions & 1 deletion contracts/mocks/RefundableCrowdsaleImpl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity ^0.4.18;
import "../token/ERC20/MintableToken.sol";
import "../crowdsale/distribution/RefundableCrowdsale.sol";


contract RefundableCrowdsaleImpl is RefundableCrowdsale {

function RefundableCrowdsaleImpl (
Expand All @@ -12,7 +13,7 @@ contract RefundableCrowdsaleImpl is RefundableCrowdsale {
address _wallet,
MintableToken _token,
uint256 _goal
)
)
public
Crowdsale(_rate, _wallet, _token)
TimedCrowdsale(_openingTime, _closingTime)
Expand Down
1 change: 1 addition & 0 deletions contracts/mocks/StandardTokenMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pragma solidity ^0.4.18;

import "../token/ERC20/StandardToken.sol";


// mock class using StandardToken
contract StandardTokenMock is StandardToken {

Expand Down
3 changes: 2 additions & 1 deletion contracts/mocks/TimedCrowdsaleImpl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity ^0.4.18;
import "../token/ERC20/ERC20.sol";
import "../crowdsale/validation/TimedCrowdsale.sol";


contract TimedCrowdsaleImpl is TimedCrowdsale {

function TimedCrowdsaleImpl (
Expand All @@ -11,7 +12,7 @@ contract TimedCrowdsaleImpl is TimedCrowdsale {
uint256 _rate,
address _wallet,
ERC20 _token
)
)
public
Crowdsale(_rate, _wallet, _token)
TimedCrowdsale(_openingTime, _closingTime)
Expand Down
9 changes: 8 additions & 1 deletion contracts/token/ERC20/SafeERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ library SafeERC20 {
assert(token.transfer(to, value));
}

function safeTransferFrom(ERC20 token, address from, address to, uint256 value) internal {
function safeTransferFrom(
ERC20 token,
address from,
address to,
uint256 value
)
internal
{
assert(token.transferFrom(from, to, value));
}

Expand Down
4 changes: 2 additions & 2 deletions contracts/token/ERC20/TokenTimelock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contract TokenTimelock {
uint256 public releaseTime;

function TokenTimelock(ERC20Basic _token, address _beneficiary, uint256 _releaseTime) public {
require(_releaseTime > now);
require(_releaseTime > block.timestamp);
token = _token;
beneficiary = _beneficiary;
releaseTime = _releaseTime;
Expand All @@ -31,7 +31,7 @@ contract TokenTimelock {
* @notice Transfers tokens held by timelock to beneficiary.
*/
function release() public {
require(now >= releaseTime);
require(block.timestamp >= releaseTime);

uint256 amount = token.balanceOf(this);
require(amount > 0);
Expand Down
Loading

0 comments on commit 82ce197

Please sign in to comment.