forked from OpenZeppelin/openzeppelin-contracts
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCallReceiverMock.sol
More file actions
107 lines (84 loc) · 2.9 KB
/
CallReceiverMock.sol
File metadata and controls
107 lines (84 loc) · 2.9 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract CallReceiverMock {
event MockFunctionCalled();
event MockFunctionCalledWithArgs(uint256 a, uint256 b);
event MockFunctionCalledExtra(address caller, uint256 value);
uint256[] private _array;
function mockFunction() public payable returns (string memory) {
emit MockFunctionCalled();
return "0x1234";
}
function mockFunctionWritesStorage(bytes32 slot, bytes32 value) public returns (string memory) {
assembly ("memory-safe") {
sstore(slot, value)
}
return "0x1234";
}
function mockFunctionEmptyReturn() public payable {
emit MockFunctionCalled();
}
function mockFunctionEmptyReturnWritesStorage(bytes32 slot, bytes32 value) public payable {
assembly ("memory-safe") {
sstore(slot, value)
}
emit MockFunctionCalled();
}
function mockFunctionWithArgs(uint256 a, uint256 b) public payable returns (string memory) {
emit MockFunctionCalledWithArgs(a, b);
return "0x1234";
}
function mockFunctionWithArgsReturn(uint256 a, uint256 b) public payable returns (uint256, uint256) {
emit MockFunctionCalledWithArgs(a, b);
return (a, b);
}
function mockFunctionWithArgsReturnWritesStorage(
bytes32 slot,
bytes32 value,
uint256 a,
uint256 b
) public payable returns (uint256, uint256) {
assembly ("memory-safe") {
sstore(slot, value)
}
emit MockFunctionCalledWithArgs(a, b);
return (a, b);
}
function mockFunctionNonPayable() public returns (string memory) {
emit MockFunctionCalled();
return "0x1234";
}
function mockStaticFunction() public pure returns (string memory) {
return "0x1234";
}
function mockStaticFunctionWithArgsReturn(uint256 a, uint256 b) public pure returns (uint256, uint256) {
return (a, b);
}
function mockFunctionRevertsNoReason() public payable {
revert();
}
function mockFunctionRevertsReason() public payable {
revert("CallReceiverMock: reverting");
}
function mockFunctionThrows() public payable {
assert(false);
}
function mockFunctionOutOfGas() public payable {
for (uint256 i = 0; ; ++i) {
_array.push(i);
}
}
function mockFunctionExtra() public payable returns (address, uint256) {
emit MockFunctionCalledExtra(msg.sender, msg.value);
return (msg.sender, msg.value);
}
}
contract CallReceiverMockTrustingForwarder is CallReceiverMock {
address private _trustedForwarder;
constructor(address trustedForwarder_) {
_trustedForwarder = trustedForwarder_;
}
function isTrustedForwarder(address forwarder) public view virtual returns (bool) {
return forwarder == _trustedForwarder;
}
}