diff options
author | chriseth <chris@ethereum.org> | 2018-10-24 20:51:37 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2018-10-24 20:52:55 +0800 |
commit | eded236e67d714802e62365381c6aa2588a091c5 (patch) | |
tree | 8213d65d048e33743eaefef7ad1435f5071a6146 /test/compilationTests/zeppelin/token | |
parent | f5f977eaf5b57c5fbed99692eed1b6e3b0f5527f (diff) | |
download | dexon-solidity-eded236e67d714802e62365381c6aa2588a091c5.tar dexon-solidity-eded236e67d714802e62365381c6aa2588a091c5.tar.gz dexon-solidity-eded236e67d714802e62365381c6aa2588a091c5.tar.bz2 dexon-solidity-eded236e67d714802e62365381c6aa2588a091c5.tar.lz dexon-solidity-eded236e67d714802e62365381c6aa2588a091c5.tar.xz dexon-solidity-eded236e67d714802e62365381c6aa2588a091c5.tar.zst dexon-solidity-eded236e67d714802e62365381c6aa2588a091c5.zip |
Only run zeppelin as external tests.
Diffstat (limited to 'test/compilationTests/zeppelin/token')
10 files changed, 0 insertions, 577 deletions
diff --git a/test/compilationTests/zeppelin/token/BasicToken.sol b/test/compilationTests/zeppelin/token/BasicToken.sol deleted file mode 100644 index 3d5646a4..00000000 --- a/test/compilationTests/zeppelin/token/BasicToken.sol +++ /dev/null @@ -1,37 +0,0 @@ -pragma solidity ^0.4.11; - - -import './ERC20Basic.sol'; -import '../math/SafeMath.sol'; - - -/** - * @title Basic token - * @dev Basic version of StandardToken, with no allowances. - */ -contract BasicToken is ERC20Basic { - using SafeMath for uint256; - - mapping(address => uint256) balances; - - /** - * @dev transfer token for a specified address - * @param _to The address to transfer to. - * @param _value The amount to be transferred. - */ - function transfer(address _to, uint256 _value) public { - balances[msg.sender] = balances[msg.sender].sub(_value); - balances[_to] = balances[_to].add(_value); - emit Transfer(msg.sender, _to, _value); - } - - /** - * @dev Gets the balance of the specified address. - * @param _owner The address to query the the balance of. - * @return An uint256 representing the amount owned by the passed address. - */ - function balanceOf(address _owner) public view returns (uint256 balance) { - return balances[_owner]; - } - -} diff --git a/test/compilationTests/zeppelin/token/ERC20.sol b/test/compilationTests/zeppelin/token/ERC20.sol deleted file mode 100644 index 5b5dc748..00000000 --- a/test/compilationTests/zeppelin/token/ERC20.sol +++ /dev/null @@ -1,16 +0,0 @@ -pragma solidity ^0.4.11; - - -import './ERC20Basic.sol'; - - -/** - * @title ERC20 interface - * @dev see https://github.com/ethereum/EIPs/issues/20 - */ -contract ERC20 is ERC20Basic { - function allowance(address owner, address spender) public view returns (uint256); - function transferFrom(address from, address to, uint256 value) public; - function approve(address spender, uint256 value) public; - event Approval(address indexed owner, address indexed spender, uint256 value); -} diff --git a/test/compilationTests/zeppelin/token/ERC20Basic.sol b/test/compilationTests/zeppelin/token/ERC20Basic.sol deleted file mode 100644 index fbe33134..00000000 --- a/test/compilationTests/zeppelin/token/ERC20Basic.sol +++ /dev/null @@ -1,14 +0,0 @@ -pragma solidity ^0.4.11; - - -/** - * @title ERC20Basic - * @dev Simpler version of ERC20 interface - * @dev see https://github.com/ethereum/EIPs/issues/20 - */ -contract ERC20Basic { - uint256 public totalSupply; - function balanceOf(address who) public view returns (uint256); - function transfer(address to, uint256 value) public; - event Transfer(address indexed from, address indexed to, uint256 value); -} diff --git a/test/compilationTests/zeppelin/token/LimitedTransferToken.sol b/test/compilationTests/zeppelin/token/LimitedTransferToken.sol deleted file mode 100644 index d668b86f..00000000 --- a/test/compilationTests/zeppelin/token/LimitedTransferToken.sol +++ /dev/null @@ -1,57 +0,0 @@ -pragma solidity ^0.4.11; - -import "./ERC20.sol"; - -/** - * @title LimitedTransferToken - * @dev LimitedTransferToken defines the generic interface and the implementation to limit token - * transferability for different events. It is intended to be used as a base class for other token - * contracts. - * LimitedTransferToken has been designed to allow for different limiting factors, - * this can be achieved by recursively calling super.transferableTokens() until the base class is - * hit. For example: - * function transferableTokens(address holder, uint64 time) view public returns (uint256) { - * return min256(unlockedTokens, super.transferableTokens(holder, time)); - * } - * A working example is VestedToken.sol: - * https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/token/VestedToken.sol - */ - -contract LimitedTransferToken is ERC20 { - - /** - * @dev Checks whether it can transfer or otherwise throws. - */ - modifier canTransfer(address _sender, uint256 _value) { - if (_value > transferableTokens(_sender, uint64(now))) revert(); - _; - } - - /** - * @dev Checks modifier and allows transfer if tokens are not locked. - * @param _to The address that will receive the tokens. - * @param _value The amount of tokens to be transferred. - */ - function transfer(address _to, uint256 _value) canTransfer(msg.sender, _value) public { - super.transfer(_to, _value); - } - - /** - * @dev Checks modifier and allows transfer if tokens are not locked. - * @param _from The address that will send the tokens. - * @param _to The address that will receive the tokens. - * @param _value The amount of tokens to be transferred. - */ - function transferFrom(address _from, address _to, uint256 _value) public canTransfer(_from, _value) { - super.transferFrom(_from, _to, _value); - } - - /** - * @dev Default transferable tokens function returns all tokens for a holder (no limit). - * @dev Overwriting transferableTokens(address holder, uint64 time) is the way to provide the - * specific logic for limiting token transferability for a holder over time. - */ - function transferableTokens(address holder, uint64 time) view public returns (uint256) { - return balanceOf(holder); - } -} diff --git a/test/compilationTests/zeppelin/token/MintableToken.sol b/test/compilationTests/zeppelin/token/MintableToken.sol deleted file mode 100644 index 24b8c807..00000000 --- a/test/compilationTests/zeppelin/token/MintableToken.sol +++ /dev/null @@ -1,50 +0,0 @@ -pragma solidity ^0.4.11; - - -import './StandardToken.sol'; -import '../ownership/Ownable.sol'; - - - -/** - * @title Mintable token - * @dev Simple ERC20 Token example, with mintable token creation - * @dev Issue: * https://github.com/OpenZeppelin/zeppelin-solidity/issues/120 - * Based on code by TokenMarketNet: https://github.com/TokenMarketNet/ico/blob/master/contracts/MintableToken.sol - */ - -contract MintableToken is StandardToken, Ownable { - event Mint(address indexed to, uint256 amount); - event MintFinished(); - - bool public mintingFinished = false; - - - modifier canMint() { - if(mintingFinished) revert(); - _; - } - - /** - * @dev Function to mint tokens - * @param _to The address that will receive the minted tokens. - * @param _amount The amount of tokens to mint. - * @return A boolean that indicates if the operation was successful. - */ - function mint(address _to, uint256 _amount) public onlyOwner canMint returns (bool) { - totalSupply = totalSupply.add(_amount); - balances[_to] = balances[_to].add(_amount); - emit Mint(_to, _amount); - return true; - } - - /** - * @dev Function to stop minting new tokens. - * @return True if the operation was successful. - */ - function finishMinting() public onlyOwner returns (bool) { - mintingFinished = true; - emit MintFinished(); - return true; - } -} diff --git a/test/compilationTests/zeppelin/token/PausableToken.sol b/test/compilationTests/zeppelin/token/PausableToken.sol deleted file mode 100644 index 66f80b80..00000000 --- a/test/compilationTests/zeppelin/token/PausableToken.sol +++ /dev/null @@ -1,21 +0,0 @@ -pragma solidity ^0.4.11; - -import './StandardToken.sol'; -import '../lifecycle/Pausable.sol'; - -/** - * Pausable token - * - * Simple ERC20 Token example, with pausable token creation - **/ - -contract PausableToken is StandardToken, Pausable { - - function transfer(address _to, uint _value) public whenNotPaused { - super.transfer(_to, _value); - } - - function transferFrom(address _from, address _to, uint _value) public whenNotPaused { - super.transferFrom(_from, _to, _value); - } -} diff --git a/test/compilationTests/zeppelin/token/SimpleToken.sol b/test/compilationTests/zeppelin/token/SimpleToken.sol deleted file mode 100644 index d8717562..00000000 --- a/test/compilationTests/zeppelin/token/SimpleToken.sol +++ /dev/null @@ -1,28 +0,0 @@ -pragma solidity ^0.4.11; - - -import "./StandardToken.sol"; - - -/** - * @title SimpleToken - * @dev Very simple ERC20 Token example, where all tokens are pre-assigned to the creator. - * Note they can later distribute these tokens as they wish using `transfer` and other - * `StandardToken` functions. - */ -contract SimpleToken is StandardToken { - - string public name = "SimpleToken"; - string public symbol = "SIM"; - uint256 public decimals = 18; - uint256 public INITIAL_SUPPLY = 10000; - - /** - * @dev Constructor that gives msg.sender all of existing tokens. - */ - constructor() public { - totalSupply = INITIAL_SUPPLY; - balances[msg.sender] = INITIAL_SUPPLY; - } - -} diff --git a/test/compilationTests/zeppelin/token/StandardToken.sol b/test/compilationTests/zeppelin/token/StandardToken.sol deleted file mode 100644 index 56f4a5f3..00000000 --- a/test/compilationTests/zeppelin/token/StandardToken.sol +++ /dev/null @@ -1,65 +0,0 @@ -pragma solidity ^0.4.11; - - -import './BasicToken.sol'; -import './ERC20.sol'; - - -/** - * @title Standard ERC20 token - * - * @dev Implementation of the basic standard token. - * @dev https://github.com/ethereum/EIPs/issues/20 - * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol - */ -contract StandardToken is ERC20, BasicToken { - - mapping (address => mapping (address => uint256)) allowed; - - - /** - * @dev Transfer tokens from one address to another - * @param _from address The address which you want to send tokens from - * @param _to address The address which you want to transfer to - * @param _value uint256 the amount of tokens to be transferred - */ - function transferFrom(address _from, address _to, uint256 _value) public { - uint256 _allowance = allowed[_from][msg.sender]; - - // Check is not needed because sub(_allowance, _value) will already throw if this condition is not met - // if (_value > _allowance) revert(); - - balances[_to] = balances[_to].add(_value); - balances[_from] = balances[_from].sub(_value); - allowed[_from][msg.sender] = _allowance.sub(_value); - emit Transfer(_from, _to, _value); - } - - /** - * @dev Aprove the passed address to spend the specified amount of tokens on behalf of msg.sender. - * @param _spender The address which will spend the funds. - * @param _value The amount of tokens to be spent. - */ - function approve(address _spender, uint256 _value) public { - - // To change the approve amount you first have to reduce the addresses` - // allowance to zero by calling `approve(_spender, 0)` if it is not - // already 0 to mitigate the race condition described here: - // https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 - if ((_value != 0) && (allowed[msg.sender][_spender] != 0)) revert(); - - allowed[msg.sender][_spender] = _value; - emit Approval(msg.sender, _spender, _value); - } - - /** - * @dev Function to check the amount of tokens that an owner allowed to a spender. - * @param _owner address The address which owns the funds. - * @param _spender address The address which will spend the funds. - * @return A uint256 specifying the amount of tokens still available for the spender. - */ - function allowance(address _owner, address _spender) public view returns (uint256 remaining) { - return allowed[_owner][_spender]; - } - -} diff --git a/test/compilationTests/zeppelin/token/TokenTimelock.sol b/test/compilationTests/zeppelin/token/TokenTimelock.sol deleted file mode 100644 index 4847b648..00000000 --- a/test/compilationTests/zeppelin/token/TokenTimelock.sol +++ /dev/null @@ -1,41 +0,0 @@ -pragma solidity ^0.4.11; - - -import './ERC20Basic.sol'; - -/** - * @title TokenTimelock - * @dev TokenTimelock is a token holder contract that will allow a - * beneficiary to extract the tokens after a given release time - */ -contract TokenTimelock { - - // ERC20 basic token contract being held - ERC20Basic token; - - // beneficiary of tokens after they are released - address beneficiary; - - // timestamp when token release is enabled - uint releaseTime; - - constructor(ERC20Basic _token, address _beneficiary, uint _releaseTime) public { - require(_releaseTime > now); - token = _token; - beneficiary = _beneficiary; - releaseTime = _releaseTime; - } - - /** - * @dev beneficiary claims tokens held by time lock - */ - function claim() public { - require(msg.sender == beneficiary); - require(now >= releaseTime); - - uint amount = token.balanceOf(address(this)); - require(amount > 0); - - token.transfer(beneficiary, amount); - } -} diff --git a/test/compilationTests/zeppelin/token/VestedToken.sol b/test/compilationTests/zeppelin/token/VestedToken.sol deleted file mode 100644 index c9469f16..00000000 --- a/test/compilationTests/zeppelin/token/VestedToken.sol +++ /dev/null @@ -1,248 +0,0 @@ -pragma solidity ^0.4.11; - -import "../math/Math.sol"; -import "./StandardToken.sol"; -import "./LimitedTransferToken.sol"; - -/** - * @title Vested token - * @dev Tokens that can be vested for a group of addresses. - */ -contract VestedToken is StandardToken, LimitedTransferToken { - - uint256 MAX_GRANTS_PER_ADDRESS = 20; - - struct TokenGrant { - address granter; // 20 bytes - uint256 value; // 32 bytes - uint64 cliff; - uint64 vesting; - uint64 start; // 3 * 8 = 24 bytes - bool revokable; - bool burnsOnRevoke; // 2 * 1 = 2 bits? or 2 bytes? - } // total 78 bytes = 3 sstore per operation (32 per sstore) - - mapping (address => TokenGrant[]) public grants; - - event NewTokenGrant(address indexed from, address indexed to, uint256 value, uint256 grantId); - - /** - * @dev Grant tokens to a specified address - * @param _to address The address which the tokens will be granted to. - * @param _value uint256 The amount of tokens to be granted. - * @param _start uint64 Time of the beginning of the grant. - * @param _cliff uint64 Time of the cliff period. - * @param _vesting uint64 The vesting period. - */ - function grantVestedTokens( - address _to, - uint256 _value, - uint64 _start, - uint64 _cliff, - uint64 _vesting, - bool _revokable, - bool _burnsOnRevoke - ) public { - - // Check for date inconsistencies that may cause unexpected behavior - if (_cliff < _start || _vesting < _cliff) { - revert(); - } - - if (tokenGrantsCount(_to) > MAX_GRANTS_PER_ADDRESS) revert(); // To prevent a user being spammed and have his balance locked (out of gas attack when calculating vesting). - - uint256 count = grants[_to].push( - TokenGrant( - _revokable ? msg.sender : 0x0000000000000000000000000000000000000000, // avoid storing an extra 20 bytes when it is non-revokable - _value, - _cliff, - _vesting, - _start, - _revokable, - _burnsOnRevoke - ) - ); - - transfer(_to, _value); - - emit NewTokenGrant(msg.sender, _to, _value, count - 1); - } - - /** - * @dev Revoke the grant of tokens of a specified address. - * @param _holder The address which will have its tokens revoked. - * @param _grantId The id of the token grant. - */ - function revokeTokenGrant(address _holder, uint256 _grantId) public { - TokenGrant storage grant = grants[_holder][_grantId]; - - if (!grant.revokable) { // Check if grant was revokable - revert(); - } - - if (grant.granter != msg.sender) { // Only granter can revoke it - revert(); - } - - address receiver = grant.burnsOnRevoke ? 0x000000000000000000000000000000000000dEaD : msg.sender; - - uint256 nonVested = nonVestedTokens(grant, uint64(now)); - - // remove grant from array - delete grants[_holder][_grantId]; - grants[_holder][_grantId] = grants[_holder][grants[_holder].length.sub(1)]; - grants[_holder].length -= 1; - - balances[receiver] = balances[receiver].add(nonVested); - balances[_holder] = balances[_holder].sub(nonVested); - - emit Transfer(_holder, receiver, nonVested); - } - - - /** - * @dev Calculate the total amount of transferable tokens of a holder at a given time - * @param holder address The address of the holder - * @param time uint64 The specific time. - * @return An uint256 representing a holder's total amount of transferable tokens. - */ - function transferableTokens(address holder, uint64 time) view public returns (uint256) { - uint256 grantIndex = tokenGrantsCount(holder); - - if (grantIndex == 0) return balanceOf(holder); // shortcut for holder without grants - - // Iterate through all the grants the holder has, and add all non-vested tokens - uint256 nonVested = 0; - for (uint256 i = 0; i < grantIndex; i++) { - nonVested = SafeMath.add(nonVested, nonVestedTokens(grants[holder][i], time)); - } - - // Balance - totalNonVested is the amount of tokens a holder can transfer at any given time - uint256 vestedTransferable = SafeMath.sub(balanceOf(holder), nonVested); - - // Return the minimum of how many vested can transfer and other value - // in case there are other limiting transferability factors (default is balanceOf) - return Math.min256(vestedTransferable, super.transferableTokens(holder, time)); - } - - /** - * @dev Check the amount of grants that an address has. - * @param _holder The holder of the grants. - * @return A uint256 representing the total amount of grants. - */ - function tokenGrantsCount(address _holder) public view returns (uint256 index) { - return grants[_holder].length; - } - - /** - * @dev Calculate amount of vested tokens at a specific time. - * @param tokens uint256 The amount of tokens granted. - * @param time uint64 The time to be checked - * @param start uint64 A time representing the beginning of the grant - * @param cliff uint64 The cliff period. - * @param vesting uint64 The vesting period. - * @return An uint256 representing the amount of vested tokens of a specific grant. - * transferableTokens - * | _/-------- vestedTokens rect - * | _/ - * | _/ - * | _/ - * | _/ - * | / - * | .| - * | . | - * | . | - * | . | - * | . | - * | . | - * +===+===========+---------+----------> time - * Start Clift Vesting - */ - function calculateVestedTokens( - uint256 tokens, - uint256 time, - uint256 start, - uint256 cliff, - uint256 vesting) public view returns (uint256) - { - // Shortcuts for before cliff and after vesting cases. - if (time < cliff) return 0; - if (time >= vesting) return tokens; - - // Interpolate all vested tokens. - // As before cliff the shortcut returns 0, we can use just calculate a value - // in the vesting rect (as shown in above's figure) - - // vestedTokens = tokens * (time - start) / (vesting - start) - uint256 vestedTokens = SafeMath.div( - SafeMath.mul( - tokens, - SafeMath.sub(time, start) - ), - SafeMath.sub(vesting, start) - ); - - return vestedTokens; - } - - /** - * @dev Get all information about a specific grant. - * @param _holder The address which will have its tokens revoked. - * @param _grantId The id of the token grant. - * @return Returns all the values that represent a TokenGrant(address, value, start, cliff, - * revokability, burnsOnRevoke, and vesting) plus the vested value at the current time. - */ - function tokenGrant(address _holder, uint256 _grantId) public view returns (address granter, uint256 value, uint256 vested, uint64 start, uint64 cliff, uint64 vesting, bool revokable, bool burnsOnRevoke) { - TokenGrant storage grant = grants[_holder][_grantId]; - - granter = grant.granter; - value = grant.value; - start = grant.start; - cliff = grant.cliff; - vesting = grant.vesting; - revokable = grant.revokable; - burnsOnRevoke = grant.burnsOnRevoke; - - vested = vestedTokens(grant, uint64(now)); - } - - /** - * @dev Get the amount of vested tokens at a specific time. - * @param grant TokenGrant The grant to be checked. - * @param time The time to be checked - * @return An uint256 representing the amount of vested tokens of a specific grant at a specific time. - */ - function vestedTokens(TokenGrant memory grant, uint64 time) private view returns (uint256) { - return calculateVestedTokens( - grant.value, - uint256(time), - uint256(grant.start), - uint256(grant.cliff), - uint256(grant.vesting) - ); - } - - /** - * @dev Calculate the amount of non vested tokens at a specific time. - * @param grant TokenGrant The grant to be checked. - * @param time uint64 The time to be checked - * @return An uint256 representing the amount of non vested tokens of a specific grant on the - * passed time frame. - */ - function nonVestedTokens(TokenGrant memory grant, uint64 time) private view returns (uint256) { - return grant.value.sub(vestedTokens(grant, time)); - } - - /** - * @dev Calculate the date when the holder can transfer all its tokens - * @param holder address The address of the holder - * @return An uint256 representing the date of the last transferable tokens. - */ - function lastTokenIsTransferableDate(address holder) view public returns (uint64 date) { - date = uint64(now); - uint256 grantIndex = grants[holder].length; - for (uint256 i = 0; i < grantIndex; i++) { - date = Math.max64(grants[holder][i].vesting, date); - } - } -} |