forked from OpenZeppelin/openzeppelin-contracts
/
EnumerableMapMock.sol
219 lines (162 loc) · 5.73 KB
/
EnumerableMapMock.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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../utils/structs/EnumerableMap.sol";
// UintToAddressMap
contract UintToAddressMapMock {
using EnumerableMap for EnumerableMap.UintToAddressMap;
event OperationResult(bool result);
EnumerableMap.UintToAddressMap private _map;
function contains(uint256 key) public view returns (bool) {
return _map.contains(key);
}
function set(uint256 key, address value) public {
bool result = _map.set(key, value);
emit OperationResult(result);
}
function remove(uint256 key) public {
bool result = _map.remove(key);
emit OperationResult(result);
}
function length() public view returns (uint256) {
return _map.length();
}
function at(uint256 index) public view returns (uint256 key, address value) {
return _map.at(index);
}
function tryGet(uint256 key) public view returns (bool, address) {
return _map.tryGet(key);
}
function get(uint256 key) public view returns (address) {
return _map.get(key);
}
function getWithMessage(uint256 key, string calldata errorMessage) public view returns (address) {
return _map.get(key, errorMessage);
}
}
// AddressToUintMap
contract AddressToUintMapMock {
using EnumerableMap for EnumerableMap.AddressToUintMap;
event OperationResult(bool result);
EnumerableMap.AddressToUintMap private _map;
function contains(address key) public view returns (bool) {
return _map.contains(key);
}
function set(address key, uint256 value) public {
bool result = _map.set(key, value);
emit OperationResult(result);
}
function remove(address key) public {
bool result = _map.remove(key);
emit OperationResult(result);
}
function length() public view returns (uint256) {
return _map.length();
}
function at(uint256 index) public view returns (address key, uint256 value) {
return _map.at(index);
}
function tryGet(address key) public view returns (bool, uint256) {
return _map.tryGet(key);
}
function get(address key) public view returns (uint256) {
return _map.get(key);
}
function getWithMessage(address key, string calldata errorMessage) public view returns (uint256) {
return _map.get(key, errorMessage);
}
}
contract Bytes32ToBytes32MapMock {
using EnumerableMap for EnumerableMap.Bytes32ToBytes32Map;
event OperationResult(bool result);
EnumerableMap.Bytes32ToBytes32Map private _map;
function contains(bytes32 key) public view returns (bool) {
return _map.contains(key);
}
function set(bytes32 key, bytes32 value) public {
bool result = _map.set(key, value);
emit OperationResult(result);
}
function remove(bytes32 key) public {
bool result = _map.remove(key);
emit OperationResult(result);
}
function length() public view returns (uint256) {
return _map.length();
}
function at(uint256 index) public view returns (bytes32 key, bytes32 value) {
return _map.at(index);
}
function tryGet(bytes32 key) public view returns (bool, bytes32) {
return _map.tryGet(key);
}
function get(bytes32 key) public view returns (bytes32) {
return _map.get(key);
}
function getWithMessage(bytes32 key, string calldata errorMessage) public view returns (bytes32) {
return _map.get(key, errorMessage);
}
}
// UintToUintMap
contract UintToUintMapMock {
using EnumerableMap for EnumerableMap.UintToUintMap;
event OperationResult(bool result);
EnumerableMap.UintToUintMap private _map;
function contains(uint256 key) public view returns (bool) {
return _map.contains(key);
}
function set(uint256 key, uint256 value) public {
bool result = _map.set(key, value);
emit OperationResult(result);
}
function remove(uint256 key) public {
bool result = _map.remove(key);
emit OperationResult(result);
}
function length() public view returns (uint256) {
return _map.length();
}
function at(uint256 index) public view returns (uint256 key, uint256 value) {
return _map.at(index);
}
function tryGet(uint256 key) public view returns (bool, uint256) {
return _map.tryGet(key);
}
function get(uint256 key) public view returns (uint256) {
return _map.get(key);
}
function getWithMessage(uint256 key, string calldata errorMessage) public view returns (uint256) {
return _map.get(key, errorMessage);
}
}
// Bytes32ToUintMap
contract Bytes32ToUintMapMock {
using EnumerableMap for EnumerableMap.Bytes32ToUintMap;
event OperationResult(bool result);
EnumerableMap.Bytes32ToUintMap private _map;
function contains(bytes32 key) public view returns (bool) {
return _map.contains(key);
}
function set(bytes32 key, uint256 value) public {
bool result = _map.set(key, value);
emit OperationResult(result);
}
function remove(bytes32 key) public {
bool result = _map.remove(key);
emit OperationResult(result);
}
function length() public view returns (uint256) {
return _map.length();
}
function at(uint256 index) public view returns (bytes32 key, uint256 value) {
return _map.at(index);
}
function tryGet(bytes32 key) public view returns (bool, uint256) {
return _map.tryGet(key);
}
function get(bytes32 key) public view returns (uint256) {
return _map.get(key);
}
function getWithMessage(bytes32 key, string calldata errorMessage) public view returns (uint256) {
return _map.get(key, errorMessage);
}
}