Skip to content

Commit

Permalink
document test contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
mmv08 committed Feb 23, 2023
1 parent 8b9023d commit 5698d13
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 18 deletions.
50 changes: 33 additions & 17 deletions contracts/test/ERC1155Token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ pragma solidity >=0.7.0 <0.9.0;
import "../interfaces/ERC1155TokenReceiver.sol";
import "../external/SafeMath.sol";

/**
* @title ERC1155Token - A test ERC1155 token contract
*/
contract ERC1155Token {
using SafeMath for uint256;

Expand All @@ -14,26 +17,26 @@ contract ERC1155Token {
mapping(address => mapping(address => bool)) private _operatorApprovals;

/**
@dev Get the specified address' balance for token with specified ID.
@param owner The address of the token holder
@param id ID of the token
@return The owner's balance of the token type requested
* @dev Get the specified address' balance for token with specified ID.
* @param owner The address of the token holder
* @param id ID of the token
* @return The owner's balance of the token type requested
*/
function balanceOf(address owner, uint256 id) public view returns (uint256) {
require(owner != address(0), "ERC1155: balance query for the zero address");
return _balances[id][owner];
}

/**
@dev Transfers `value` amount of an `id` from the `from` address to the `to` address specified.
Caller must be approved to manage the tokens being transferred out of the `from` account.
If `to` is a smart contract, will call `onERC1155Received` on `to` and act appropriately.
@param from Source address
@param to Target address
@param id ID of the token type
@param value Transfer amount
@param data Data forwarded to `onERC1155Received` if `to` is a contract receiver
*/
* @notice Transfers `value` amount of an `id` from the `from` address to the `to` address specified.
* Caller must be approved to manage the tokens being transferred out of the `from` account.
* If `to` is a smart contract, will call `onERC1155Received` on `to` and act appropriately.
* @param from Source address
* @param to Target address
* @param id ID of the token type
* @param value Transfer amount
* @param data Data forwarded to `onERC1155Received` if `to` is a contract receiver
*/
function safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes calldata data) external {
require(to != address(0), "ERC1155: target address must be non-zero");
require(
Expand Down Expand Up @@ -62,11 +65,14 @@ contract ERC1155Token {
_doSafeTransferAcceptanceCheck(msg.sender, address(0), to, id, value, data);
}

/**
* @notice Returns true if `account` 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 account The address being queried
* @return True if `account` is a contract
*/
function isContract(address account) internal view returns (bool) {
// This method relies in extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.

uint256 size;
// solhint-disable-next-line no-inline-assembly
assembly {
Expand All @@ -75,6 +81,16 @@ contract ERC1155Token {
return size > 0;
}

/**
* @dev Internal function to invoke `onERC1155Received` on a target address
* The call is not executed if the target address is not a contract
* @param operator The address which initiated the transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param to The address which will now own the token
* @param id The id of the token being transferred
* @param value The amount of tokens being transferred
* @param data Additional data with no specified format
*/
function _doSafeTransferAcceptanceCheck(
address operator,
address from,
Expand Down
7 changes: 7 additions & 0 deletions contracts/test/ERC20Token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ pragma solidity >=0.6.0 <0.8.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

/**
* @title ERC20Token
* @dev This contract is an ERC20 token contract that extends the OpenZeppelin ERC20 contract.
*/
contract ERC20Token is ERC20 {
/**
* @dev Constructor that sets the name and symbol of the token and mints an initial supply to the contract deployer.
*/
constructor() public ERC20("TestToken", "TT") {
_mint(msg.sender, 1000000000000000);
}
Expand Down
8 changes: 8 additions & 0 deletions contracts/test/TestHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@ pragma solidity >=0.7.0 <0.9.0;

import "../handler/HandlerContext.sol";

/**
* @title TestHandler - A test FallbackHandler contract
*/
contract TestHandler is HandlerContext {
/**
* @notice Returns the sender and manager address provided by the HandlerContext
* @return sender The sender address
* @return manager The manager address
*/
function dudududu() external view returns (address sender, address manager) {
return (_msgSender(), _manager());
}
Expand Down
1 change: 0 additions & 1 deletion contracts/test/Token.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.6.0 <0.7.0;
import "@gnosis.pm/mock-contract/contracts/MockContract.sol";

interface Token {
function transfer(address _to, uint256 value) external returns (bool);
Expand Down

0 comments on commit 5698d13

Please sign in to comment.