summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErsikan <julien.philippon@epitech.eu>2021-03-29 14:50:28 +0200
committerDavid Peter <sharkdp@users.noreply.github.com>2021-05-12 11:42:17 +0200
commitc933be926dfed57f9601c31cef918a3eff86a843 (patch)
treeb0a87350123859b81ad06625f828ff7e1c90dfc8
parentfc88040b31635631327432da9babcf73b0c1278f (diff)
Add syntax tests for Solidity language.
-rw-r--r--tests/syntax-tests/highlighted/Solidity/ERC721.sol376
-rw-r--r--tests/syntax-tests/source/Solidity/ERC721.sol376
-rw-r--r--tests/syntax-tests/source/Solidity/LICENSE.md27
3 files changed, 779 insertions, 0 deletions
diff --git a/tests/syntax-tests/highlighted/Solidity/ERC721.sol b/tests/syntax-tests/highlighted/Solidity/ERC721.sol
new file mode 100644
index 00000000..a04bea91
--- /dev/null
+++ b/tests/syntax-tests/highlighted/Solidity/ERC721.sol
@@ -0,0 +1,376 @@
+// SPDX-License-Identifier: MIT
+
+pragma solidity ^0.8.0;
+
+import "./IERC721.sol";
+import "./IERC721Receiver.sol";
+import "./extensions/IERC721Metadata.sol";
+import "../../utils/Address.sol";
+import "../../utils/Context.sol";
+import "../../utils/Strings.sol";
+import "../../utils/introspection/ERC165.sol";
+
+/**
+ * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
+ * the Metadata extension, but not including the Enumerable extension, which is available separately as
+ * {ERC721Enumerable}.
+ */
+contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
+ using Address for address;
+ using Strings for uint256;
+
+ // Token name
+ string private _name;
+
+ // Token symbol
+ string private _symbol;
+
+ // Mapping from token ID to owner address
+ mapping (uint256 => address) private _owners;
+
+ // Mapping owner address to token count
+ mapping (address => uint256) private _balances;
+
+ // Mapping from token ID to approved address
+ mapping (uint256 => address) private _tokenApprovals;
+
+ // Mapping from owner to operator approvals
+ mapping (address => mapping (address => bool)) private _operatorApprovals;
+
+ /**
+ * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
+ */
+ constructor (string memory name_, string memory symbol_) {
+ _name = name_;
+ _symbol = symbol_;
+ }
+
+ /**
+ * @dev See {IERC165-supportsInterface}.
+ */
+ function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
+ return interfaceId == type(IERC721).interfaceId
+ || interfaceId == type(IERC721Metadata).interfaceId
+ || super.supportsInterface(interfaceId);
+ }
+
+ /**
+ * @dev See {IERC721-balanceOf}.
+ */
+ function balanceOf(address owner) public view virtual override returns (uint256) {
+ require(owner != address(0), "ERC721: balance query for the zero address");
+ return _balances[owner];
+ }
+
+ /**
+ * @dev See {IERC721-ownerOf}.
+ */
+ function ownerOf(uint256 tokenId) public view virtual override returns (address) {
+ address owner = _owners[tokenId];
+ require(owner != address(0), "ERC721: owner query for nonexistent token");
+ return owner;
+ }
+
+ /**
+ * @dev See {IERC721Metadata-name}.
+ */
+ function name() public view virtual override returns (string memory) {
+ return _name;
+ }
+
+ /**
+ * @dev See {IERC721Metadata-symbol}.
+ */
+ function symbol() public view virtual override returns (string memory) {
+ return _symbol;
+ }
+
+ /**
+ * @dev See {IERC721Metadata-tokenURI}.
+ */
+ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
+ require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
+
+ string memory baseURI = _baseURI();
+ return bytes(baseURI).length > 0
+ ? string(abi.encodePacked(baseURI, tokenId.toString()))
+ : '';
+ }
+
+ /**
+ * @dev Base URI for computing {tokenURI}. Empty by default, can be overriden
+ * in child contracts.
+ */
+ function _baseURI() internal view virtual returns (string memory) {
+ return "";
+ }
+
+ /**
+ * @dev See {IERC721-approve}.
+ */
+ function approve(address to, uint256 tokenId) public virtual override {
+ address owner = ERC721.ownerOf(tokenId);
+ require(to != owner, "ERC721: approval to current owner");
+
+ require(_msgSender() == owner || isApprovedForAll(owner, _msgSender()),
+ "ERC721: approve caller is not owner nor approved for all"
+ );
+
+ _approve(to, tokenId);
+ }
+
+ /**
+ * @dev See {IERC721-getApproved}.
+ */
+ function getApproved(uint256 tokenId) public view virtual override returns (address) {
+ require(_exists(tokenId), "ERC721: approved query for nonexistent token");
+
+ return _tokenApprovals[tokenId];
+ }
+
+ /**
+ * @dev See {IERC721-setApprovalForAll}.
+ */
+ function setApprovalForAll(address operator, bool approved) public virtual override {
+ require(operator != _msgSender(), "ERC721: approve to caller");
+
+ _operatorApprovals[_msgSender()][operator] = approved;
+ emit ApprovalForAll(_msgSender(), operator, approved);
+ }
+
+ /**
+ * @dev See {IERC721-isApprovedForAll}.
+ */
+ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
+ return _operatorApprovals[owner][operator];
+ }
+
+ /**
+ * @dev See {IERC721-transferFrom}.
+ */
+ function transferFrom(address from, address to, uint256 tokenId) public virtual override {
+ //solhint-disable-next-line max-line-length
+ require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
+
+ _transfer(from, to, tokenId);
+ }
+
+ /**
+ * @dev See {IERC721-safeTransferFrom}.
+ */
+ function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override {
+ safeTransferFrom(from, to, tokenId, "");
+ }
+
+ /**
+ * @dev See {IERC721-safeTransferFrom}.
+ */
+ function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) public virtual override {
+ require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
+ _safeTransfer(from, to, tokenId, _data);
+ }
+
+ /**
+ * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
+ * are aware of the ERC721 protocol to prevent tokens from being forever locked.
+ *
+ * `_data` is additional data, it has no specified format and it is sent in call to `to`.
+ *
+ * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
+ * implement alternative mechanisms to perform token transfer, such as signature-based.
+ *
+ * Requirements:
+ *
+ * - `from` cannot be the zero address.
+ * - `to` cannot be the zero address.
+ * - `tokenId` token must exist and be owned by `from`.
+ * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
+ *
+ * Emits a {Transfer} event.
+ */
+ function _safeTransfer(address from, address to, uint256 tokenId, bytes[38;2