11// SPDX-License-Identifier: MIT
22pragma solidity >= 0.6.2 < 0.9.0 ;
33
4+ import {IERC721Metadata } from "../interfaces/IERC721.sol " ;
5+
46/// @notice This is a mock contract of the ERC721 standard for testing purposes only, it SHOULD NOT be used in production.
57/// @dev Forked from: https://github.com/transmissions11/solmate/blob/0384dbaaa4fcb5715738a9254a7c0a4cb62cf458/src/tokens/ERC721.sol
6- contract MockERC721 {
8+ contract MockERC721 is IERC721Metadata {
79 /*//////////////////////////////////////////////////////////////
8- EVENTS
10+ METADATA STORAGE/LOGIC
911 //////////////////////////////////////////////////////////////*/
1012
11- event Transfer (address indexed from , address indexed to , uint256 indexed id );
12-
13- event Approval (address indexed owner , address indexed spender , uint256 indexed id );
14-
15- event ApprovalForAll (address indexed owner , address indexed operator , bool approved );
13+ string internal _name;
1614
17- /*//////////////////////////////////////////////////////////////
18- METADATA STORAGE/LOGIC
19- //////////////////////////////////////////////////////////////*/
15+ string internal _symbol;
2016
21- string public name;
17+ function name () external view override returns (string memory ) {
18+ return _name;
19+ }
2220
23- string public symbol;
21+ function symbol () external view override returns (string memory ) {
22+ return _symbol;
23+ }
2424
25- function tokenURI (uint256 id ) public view virtual returns (string memory ) {}
25+ function tokenURI (uint256 id ) public view virtual override returns (string memory ) {}
2626
2727 /*//////////////////////////////////////////////////////////////
2828 ERC721 BALANCE/OWNER STORAGE
@@ -32,11 +32,11 @@ contract MockERC721 {
3232
3333 mapping (address => uint256 ) internal _balanceOf;
3434
35- function ownerOf (uint256 id ) public view virtual returns (address owner ) {
35+ function ownerOf (uint256 id ) public view virtual override returns (address owner ) {
3636 require ((owner = _ownerOf[id]) != address (0 ), "NOT_MINTED " );
3737 }
3838
39- function balanceOf (address owner ) public view virtual returns (uint256 ) {
39+ function balanceOf (address owner ) public view virtual override returns (uint256 ) {
4040 require (owner != address (0 ), "ZERO_ADDRESS " );
4141
4242 return _balanceOf[owner];
@@ -46,9 +46,17 @@ contract MockERC721 {
4646 ERC721 APPROVAL STORAGE
4747 //////////////////////////////////////////////////////////////*/
4848
49- mapping (uint256 => address ) public getApproved;
49+ mapping (uint256 => address ) internal _getApproved;
50+
51+ mapping (address => mapping (address => bool )) internal _isApprovedForAll;
5052
51- mapping (address => mapping (address => bool )) public isApprovedForAll;
53+ function getApproved (uint256 id ) public view virtual override returns (address ) {
54+ return _getApproved[id];
55+ }
56+
57+ function isApprovedForAll (address owner , address operator ) public view virtual override returns (bool ) {
58+ return _isApprovedForAll[owner][operator];
59+ }
5260
5361 /*//////////////////////////////////////////////////////////////
5462 INITIALIZE
@@ -59,11 +67,11 @@ contract MockERC721 {
5967
6068 /// @dev To hide constructor warnings across solc versions due to different constructor visibility requirements and
6169 /// syntaxes, we add an initialization function that can be called only once.
62- function initialize (string memory _name , string memory _symbol ) public {
70+ function initialize (string memory name_ , string memory symbol_ ) public {
6371 require (! initialized, "ALREADY_INITIALIZED " );
6472
65- name = _name ;
66- symbol = _symbol ;
73+ _name = name_ ;
74+ _symbol = symbol_ ;
6775
6876 initialized = true ;
6977 }
@@ -72,29 +80,30 @@ contract MockERC721 {
7280 ERC721 LOGIC
7381 //////////////////////////////////////////////////////////////*/
7482
75- function approve (address spender , uint256 id ) public virtual {
83+ function approve (address spender , uint256 id ) public payable virtual override {
7684 address owner = _ownerOf[id];
7785
78- require (msg .sender == owner || isApprovedForAll [owner][msg .sender ], "NOT_AUTHORIZED " );
86+ require (msg .sender == owner || _isApprovedForAll [owner][msg .sender ], "NOT_AUTHORIZED " );
7987
80- getApproved [id] = spender;
88+ _getApproved [id] = spender;
8189
8290 emit Approval (owner, spender, id);
8391 }
8492
85- function setApprovalForAll (address operator , bool approved ) public virtual {
86- isApprovedForAll [msg .sender ][operator] = approved;
93+ function setApprovalForAll (address operator , bool approved ) public virtual override {
94+ _isApprovedForAll [msg .sender ][operator] = approved;
8795
8896 emit ApprovalForAll (msg .sender , operator, approved);
8997 }
9098
91- function transferFrom (address from , address to , uint256 id ) public virtual {
99+ function transferFrom (address from , address to , uint256 id ) public payable virtual override {
92100 require (from == _ownerOf[id], "WRONG_FROM " );
93101
94102 require (to != address (0 ), "INVALID_RECIPIENT " );
95103
96104 require (
97- msg .sender == from || isApprovedForAll[from][msg .sender ] || msg .sender == getApproved[id], "NOT_AUTHORIZED "
105+ msg .sender == from || _isApprovedForAll[from][msg .sender ] || msg .sender == _getApproved[id],
106+ "NOT_AUTHORIZED "
98107 );
99108
100109 // Underflow of the sender's balance is impossible because we check for
@@ -105,12 +114,12 @@ contract MockERC721 {
105114
106115 _ownerOf[id] = to;
107116
108- delete getApproved [id];
117+ delete _getApproved [id];
109118
110119 emit Transfer (from, to, id);
111120 }
112121
113- function safeTransferFrom (address from , address to , uint256 id ) public virtual {
122+ function safeTransferFrom (address from , address to , uint256 id ) public payable virtual override {
114123 transferFrom (from, to, id);
115124
116125 require (
@@ -121,7 +130,12 @@ contract MockERC721 {
121130 );
122131 }
123132
124- function safeTransferFrom (address from , address to , uint256 id , bytes memory data ) public virtual {
133+ function safeTransferFrom (address from , address to , uint256 id , bytes memory data )
134+ public
135+ payable
136+ virtual
137+ override
138+ {
125139 transferFrom (from, to, id);
126140
127141 require (
@@ -136,7 +150,7 @@ contract MockERC721 {
136150 ERC165 LOGIC
137151 //////////////////////////////////////////////////////////////*/
138152
139- function supportsInterface (bytes4 interfaceId ) public pure virtual returns (bool ) {
153+ function supportsInterface (bytes4 interfaceId ) public view virtual override returns (bool ) {
140154 return interfaceId == 0x01ffc9a7 // ERC165 Interface ID for ERC165
141155 || interfaceId == 0x80ac58cd // ERC165 Interface ID for ERC721
142156 || interfaceId == 0x5b5e139f ; // ERC165 Interface ID for ERC721Metadata
@@ -169,7 +183,7 @@ contract MockERC721 {
169183
170184 delete _ownerOf[id];
171185
172- delete getApproved [id];
186+ delete _getApproved [id];
173187
174188 emit Transfer (owner, address (0 ), id);
175189 }
0 commit comments