-
Notifications
You must be signed in to change notification settings - Fork 12.4k
Expand file tree
/
Copy pathERC721ReceiverMock.sol
More file actions
47 lines (39 loc) · 1.29 KB
/
ERC721ReceiverMock.sol
File metadata and controls
47 lines (39 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {IERC721Receiver} from "../../token/ERC721/IERC721Receiver.sol";
contract ERC721ReceiverMock is IERC721Receiver {
enum RevertType {
None,
RevertWithoutMessage,
RevertWithMessage,
RevertWithCustomError,
Panic
}
bytes4 private immutable _retval;
RevertType private immutable _error;
event Received(address operator, address from, uint256 tokenId, bytes data, uint256 gas);
error CustomError(bytes4);
constructor(bytes4 retval, RevertType err) {
_retval = retval;
_error = err;
}
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes memory data
) public returns (bytes4) {
if (_error == RevertType.RevertWithoutMessage) {
revert();
} else if (_error == RevertType.RevertWithMessage) {
revert("ERC721ReceiverMock: reverting");
} else if (_error == RevertType.RevertWithCustomError) {
revert CustomError(_retval);
} else if (_error == RevertType.Panic) {
uint256 a = uint256(0) / uint256(0);
a;
}
emit Received(operator, from, tokenId, data, gasleft());
return _retval;
}
}