You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.3 KiB
47 lines
1.3 KiB
// 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 error) {
|
|
_retval = retval;
|
|
_error = error;
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|