-
Notifications
You must be signed in to change notification settings - Fork 11.8k
/
ERC1363Mock.sol
60 lines (52 loc) · 1.8 KB
/
ERC1363Mock.sol
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
48
49
50
51
52
53
54
55
56
57
58
59
60
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../token/ERC20/extensions/ERC1363.sol";
contract ERC1363Mock is ERC1363 {
constructor(
string memory name,
string memory symbol,
address initialAccount,
uint256 initialBalance
) payable ERC20(name, symbol) {
_mint(initialAccount, initialBalance);
}
function mint(address account, uint256 amount) public {
_mint(account, amount);
}
function burn(address account, uint256 amount) public {
_burn(account, amount);
}
}
contract ERC1363ReceiverMock is IERC1363Receiver, IERC1363Spender {
event TransferReceived(address operator, address from, uint256 value, bytes data);
event ApprovalReceived(address owner, uint256 value, bytes data);
function onTransferReceived(
address operator,
address from,
uint256 value,
bytes memory data
) external override returns (bytes4) {
if (data.length == 1) {
if (data[0] == 0x00) return bytes4(0);
if (data[0] == 0x01) revert("onTransferReceived revert");
if (data[0] == 0x02) revert();
if (data[0] == 0x03) assert(false);
}
emit TransferReceived(operator, from, value, data);
return this.onTransferReceived.selector;
}
function onApprovalReceived(
address owner,
uint256 value,
bytes memory data
) external override returns (bytes4) {
if (data.length == 1) {
if (data[0] == 0x00) return bytes4(0);
if (data[0] == 0x01) revert("onApprovalReceived revert");
if (data[0] == 0x02) revert();
if (data[0] == 0x03) assert(false);
}
emit ApprovalReceived(owner, value, data);
return this.onApprovalReceived.selector;
}
}