aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/src/2.0.0/test
diff options
context:
space:
mode:
Diffstat (limited to 'packages/contracts/src/2.0.0/test')
-rw-r--r--packages/contracts/src/2.0.0/test/DummyERC20Token/DummyERC20Token.sol33
-rw-r--r--packages/contracts/src/2.0.0/test/DummyERC20Token/DummyNoReturnERC20Token.sol116
-rw-r--r--packages/contracts/src/2.0.0/test/DummyERC721Receiver/DummyERC721Receiver.sol68
-rw-r--r--packages/contracts/src/2.0.0/test/DummyERC721Receiver/InvalidERC721Receiver.sol66
-rw-r--r--packages/contracts/src/2.0.0/test/DummyERC721Token/DummyERC721Token.sol61
-rw-r--r--packages/contracts/src/2.0.0/test/Mintable/Mintable.sol43
6 files changed, 267 insertions, 120 deletions
diff --git a/packages/contracts/src/2.0.0/test/DummyERC20Token/DummyERC20Token.sol b/packages/contracts/src/2.0.0/test/DummyERC20Token/DummyERC20Token.sol
index 9272b18a8..412c5d1ad 100644
--- a/packages/contracts/src/2.0.0/test/DummyERC20Token/DummyERC20Token.sol
+++ b/packages/contracts/src/2.0.0/test/DummyERC20Token/DummyERC20Token.sol
@@ -18,17 +18,18 @@
pragma solidity 0.4.24;
-import "../Mintable/Mintable.sol";
import "../../utils/Ownable/Ownable.sol";
+import "../../tokens/ERC20Token/MintableERC20Token.sol";
contract DummyERC20Token is
- Mintable,
- Ownable
+ Ownable,
+ MintableERC20Token
{
string public name;
string public symbol;
uint256 public decimals;
+ uint256 public constant MAX_MINT_AMOUNT = 10000000000000000000000;
constructor (
string _name,
@@ -41,20 +42,36 @@ contract DummyERC20Token is
name = _name;
symbol = _symbol;
decimals = _decimals;
- totalSupply = _totalSupply;
+ _totalSupply = _totalSupply;
balances[msg.sender] = _totalSupply;
}
+ /// @dev Sets the balance of target address
+ /// @param _target Address or which balance will be updated
+ /// @param _value New balance of target address
function setBalance(address _target, uint256 _value)
- public
+ external
onlyOwner
{
- uint256 currBalance = balanceOf(_target);
+ uint256 currBalance = balances[_target];
if (_value < currBalance) {
- totalSupply = safeSub(totalSupply, safeSub(currBalance, _value));
+ _totalSupply = safeSub(_totalSupply, safeSub(currBalance, _value));
} else {
- totalSupply = safeAdd(totalSupply, safeSub(_value, currBalance));
+ _totalSupply = safeAdd(_totalSupply, safeSub(_value, currBalance));
}
balances[_target] = _value;
}
+
+ /// @dev Mints new tokens for sender
+ /// @param _value Amount of tokens to mint
+ function mint(uint256 _value)
+ external
+ {
+ require(
+ _value <= MAX_MINT_AMOUNT,
+ "VALUE_TOO_LARGE"
+ );
+
+ _mint(msg.sender, _value);
+ }
}
diff --git a/packages/contracts/src/2.0.0/test/DummyERC20Token/DummyNoReturnERC20Token.sol b/packages/contracts/src/2.0.0/test/DummyERC20Token/DummyNoReturnERC20Token.sol
new file mode 100644
index 000000000..79156d3dd
--- /dev/null
+++ b/packages/contracts/src/2.0.0/test/DummyERC20Token/DummyNoReturnERC20Token.sol
@@ -0,0 +1,116 @@
+/*
+
+ Copyright 2018 ZeroEx Intl.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+*/
+
+pragma solidity 0.4.24;
+
+import "./DummyERC20Token.sol";
+
+
+// solhint-disable no-empty-blocks
+contract DummyNoReturnERC20Token is
+ DummyERC20Token
+{
+
+ constructor (
+ string _name,
+ string _symbol,
+ uint256 _decimals,
+ uint256 _totalSupply
+ )
+ public
+ DummyERC20Token(
+ _name,
+ _symbol,
+ _decimals,
+ _totalSupply
+ )
+ {}
+
+ /// @dev send `value` token to `to` from `msg.sender`
+ /// @param _to The address of the recipient
+ /// @param _value The amount of token to be transferred
+ function transfer(address _to, uint256 _value)
+ external
+ returns (bool)
+ {
+ require(
+ balances[msg.sender] >= _value,
+ "ERC20_INSUFFICIENT_BALANCE"
+ );
+ require(
+ balances[_to] + _value >= balances[_to],
+ "UINT256_OVERFLOW"
+ );
+
+ balances[msg.sender] -= _value;
+ balances[_to] += _value;
+
+ emit Transfer(
+ msg.sender,
+ _to,
+ _value
+ );
+
+ // HACK: This contract will not compile if we remove `returns (bool)`, so we manually return no data
+ assembly {
+ return(0, 0)
+ }
+ }
+
+ /// @dev send `value` token to `to` from `from` on the condition it is approved by `from`
+ /// @param _from The address of the sender
+ /// @param _to The address of the recipient
+ /// @param _value The amount of token to be transferred
+ function transferFrom(
+ address _from,
+ address _to,
+ uint256 _value
+ )
+ external
+ returns (bool)
+ {
+ require(
+ balances[_from] >= _value,
+ "ERC20_INSUFFICIENT_BALANCE"
+ );
+ require(
+ allowed[_from][msg.sender] >= _value,
+ "ERC20_INSUFFICIENT_ALLOWANCE"
+ );
+ require(
+ balances[_to] + _value >= balances[_to],
+ "UINT256_OVERFLOW"
+ );
+
+ balances[_to] += _value;
+ balances[_from] -= _value;
+ allowed[_from][msg.sender] -= _value;
+
+ emit Transfer(
+ _from,
+ _to,
+ _value
+ );
+
+ // HACK: This contract will not compile if we remove `returns (bool)`, so we manually return no data
+ assembly {
+ return(0, 0)
+ }
+ }
+}
+
diff --git a/packages/contracts/src/2.0.0/test/DummyERC721Receiver/DummyERC721Receiver.sol b/packages/contracts/src/2.0.0/test/DummyERC721Receiver/DummyERC721Receiver.sol
index 5dce74a14..ac95e47bd 100644
--- a/packages/contracts/src/2.0.0/test/DummyERC721Receiver/DummyERC721Receiver.sol
+++ b/packages/contracts/src/2.0.0/test/DummyERC721Receiver/DummyERC721Receiver.sol
@@ -1,26 +1,19 @@
/*
-The MIT License (MIT)
-Copyright (c) 2016 Smart Contract Solutions, Inc.
+ Copyright 2018 ZeroEx Intl.
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
-The above copyright notice and this permission notice shall be included
-in all copies or substantial portions of the Software.
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
-CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
pragma solidity 0.4.24;
@@ -32,33 +25,44 @@ contract DummyERC721Receiver is
IERC721Receiver
{
+ // Function selector for ERC721Receiver.onERC721Received
+ // 0x150b7a02
+ bytes4 constant internal ERC721_RECEIVED = bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"));
+
event TokenReceived(
+ address operator,
address from,
uint256 tokenId,
bytes data
);
- /**
- * @notice Handle the receipt of an NFT
- * @dev The ERC721 smart contract calls this function on the recipient
- * after a `safetransfer`. This function MAY throw to revert and reject the
- * transfer. This function MUST use 50,000 gas or less. Return of other
- * than the magic value MUST result in the transaction being reverted.
- * Note: the contract address is always the message sender.
- * @param _from The sending address
- * @param _tokenId The NFT identifier which is being transfered
- * @param _data Additional data with no specified format
- * @return `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`
- */
+ /// @notice Handle the receipt of an NFT
+ /// @dev The ERC721 smart contract calls this function on the recipient
+ /// after a `transfer`. This function MAY throw to revert and reject the
+ /// transfer. Return of other than the magic value MUST result in the
+ /// transaction being reverted.
+ /// Note: the contract address is always the message sender.
+ /// @param _operator The address which called `safeTransferFrom` function
+ /// @param _from The address which previously owned the token
+ /// @param _tokenId The NFT identifier which is being transferred
+ /// @param _data Additional data with no specified format
+ /// @return `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`
+ /// unless throwing
function onERC721Received(
+ address _operator,
address _from,
uint256 _tokenId,
bytes _data
)
- public
+ external
returns (bytes4)
{
- emit TokenReceived(_from, _tokenId, _data);
+ emit TokenReceived(
+ _operator,
+ _from,
+ _tokenId,
+ _data
+ );
return ERC721_RECEIVED;
}
}
diff --git a/packages/contracts/src/2.0.0/test/DummyERC721Receiver/InvalidERC721Receiver.sol b/packages/contracts/src/2.0.0/test/DummyERC721Receiver/InvalidERC721Receiver.sol
new file mode 100644
index 000000000..309633bf5
--- /dev/null
+++ b/packages/contracts/src/2.0.0/test/DummyERC721Receiver/InvalidERC721Receiver.sol
@@ -0,0 +1,66 @@
+/*
+
+ Copyright 2018 ZeroEx Intl.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+*/
+
+pragma solidity 0.4.24;
+
+import "../../tokens/ERC721Token/IERC721Receiver.sol";
+
+
+contract InvalidERC721Receiver is
+ IERC721Receiver
+{
+ // Actual function signature is `onERC721Received(address,address,uint256,bytes)`
+ bytes4 constant internal INVALID_ERC721_RECEIVED = bytes4(keccak256("onERC721Received(address,uint256,bytes)"));
+
+ event TokenReceived(
+ address operator,
+ address from,
+ uint256 tokenId,
+ bytes data
+ );
+
+ /// @notice Handle the receipt of an NFT
+ /// @dev The ERC721 smart contract calls this function on the recipient
+ /// after a `transfer`. This function MAY throw to revert and reject the
+ /// transfer. Return of other than the magic value MUST result in the
+ /// transaction being reverted.
+ /// Note: the contract address is always the message sender.
+ /// @param _operator The address which called `safeTransferFrom` function
+ /// @param _from The address which previously owned the token
+ /// @param _tokenId The NFT identifier which is being transferred
+ /// @param _data Additional data with no specified format
+ /// @return `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`
+ /// unless throwing
+ function onERC721Received(
+ address _operator,
+ address _from,
+ uint256 _tokenId,
+ bytes _data
+ )
+ external
+ returns (bytes4)
+ {
+ emit TokenReceived(
+ _operator,
+ _from,
+ _tokenId,
+ _data
+ );
+ return INVALID_ERC721_RECEIVED;
+ }
+}
diff --git a/packages/contracts/src/2.0.0/test/DummyERC721Token/DummyERC721Token.sol b/packages/contracts/src/2.0.0/test/DummyERC721Token/DummyERC721Token.sol
index 627746a52..ac9068d1d 100644
--- a/packages/contracts/src/2.0.0/test/DummyERC721Token/DummyERC721Token.sol
+++ b/packages/contracts/src/2.0.0/test/DummyERC721Token/DummyERC721Token.sol
@@ -18,59 +18,46 @@
pragma solidity 0.4.24;
-import "../../tokens/ERC721Token/ERC721Token.sol";
+import "../../tokens/ERC721Token/MintableERC721Token.sol";
import "../../utils/Ownable/Ownable.sol";
// solhint-disable no-empty-blocks
contract DummyERC721Token is
Ownable,
- ERC721Token
+ MintableERC721Token
{
+ string public name;
+ string public symbol;
- /**
- * @dev Constructor passes its arguments to the base ERC721Token constructor
- * @param name of token
- * @param symbol of token
- */
constructor (
- string name,
- string symbol
+ string _name,
+ string _symbol
)
public
- ERC721Token(name, symbol)
- {}
+ {
+ name = _name;
+ symbol = _symbol;
+ }
- /**
- * @dev Function to mint a new token
- * @dev Reverts if the given token ID already exists
- * @param to address the beneficiary that will own the minted token
- * @param tokenId uint256 ID of the token to be minted by the msg.sender
- */
- function mint(address to, uint256 tokenId)
- public
- onlyOwner
+ /// @dev Function to mint a new token
+ /// Reverts if the given token ID already exists
+ /// @param _to Address of the beneficiary that will own the minted token
+ /// @param _tokenId ID of the token to be minted by the msg.sender
+ function mint(address _to, uint256 _tokenId)
+ external
{
- require(
- !exists(tokenId),
- "Token with tokenId already exists."
- );
- _mint(to, tokenId);
+ _mint(_to, _tokenId);
}
- /**
- * @dev Function to burn a token
- * @dev Reverts if the given token ID doesn't exist
- * @param tokenId uint256 ID of the token to be minted by the msg.sender
- */
- function burn(address owner, uint256 tokenId)
- public
+ /// @dev Function to burn a token
+ /// Reverts if the given token ID doesn't exist or not called by contract owner
+ /// @param _owner Owner of token with given token ID
+ /// @param _tokenId ID of the token to be burned by the msg.sender
+ function burn(address _owner, uint256 _tokenId)
+ external
onlyOwner
{
- require(
- exists(tokenId),
- "Token with tokenId does not exist."
- );
- _burn(owner, tokenId);
+ _burn(_owner, _tokenId);
}
}
diff --git a/packages/contracts/src/2.0.0/test/Mintable/Mintable.sol b/packages/contracts/src/2.0.0/test/Mintable/Mintable.sol
deleted file mode 100644
index 767cc8d25..000000000
--- a/packages/contracts/src/2.0.0/test/Mintable/Mintable.sol
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
-
- Copyright 2018 ZeroEx Intl.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
-*/
-
-pragma solidity 0.4.24;
-
-import "../../tokens/UnlimitedAllowanceToken/UnlimitedAllowanceToken.sol";
-import "../../utils/SafeMath/SafeMath.sol";
-
-
-/*
- * Mintable
- * Base contract that creates a mintable UnlimitedAllowanceToken
- */
-contract Mintable is
- UnlimitedAllowanceToken,
- SafeMath
-{
- function mint(uint256 _value)
- public
- {
- require(
- _value <= 100000000000000000000,
- "Minting more than 100000000000000000000 is not allowed."
- );
- balances[msg.sender] = safeAdd(_value, balances[msg.sender]);
- totalSupply = safeAdd(totalSupply, _value);
- }
-}