@paimaexample/evm-contracts 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/deno.json +28 -0
- package/docs/templates/contract.hbs +144 -0
- package/docs/templates/helpers.js +61 -0
- package/docs/templates/page.hbs +7 -0
- package/docs/templates/properties.js +76 -0
- package/hardhat.config.ts +11 -0
- package/index.js +1 -0
- package/mod.ts +0 -0
- package/package.json +13 -0
- package/remappings.txt +1 -0
- package/src/companions/ERC165Contract.json +21 -0
- package/src/companions/ERC165Contract.ts +21 -0
- package/src/companions/ERC20Contract.json +222 -0
- package/src/companions/ERC20Contract.ts +222 -0
- package/src/companions/ERC6551RegistryContract.json +128 -0
- package/src/companions/ERC6551RegistryContract.ts +128 -0
- package/src/companions/ERC721Contract.json +248 -0
- package/src/companions/ERC721Contract.ts +222 -0
- package/src/companions/IERC1155Contract.json +295 -0
- package/src/companions/IERC1155Contract.ts +295 -0
- package/src/companions/OldERC6551RegistryContract.json +133 -0
- package/src/companions/OldERC6551RegistryContract.ts +133 -0
- package/src/companions/PaimaERC721Contract.json +787 -0
- package/src/companions/PaimaERC721Contract.ts +787 -0
- package/src/companions/PaimaL2Contract.json +134 -0
- package/src/companions/PaimaL2Contract.ts +134 -0
- package/src/companions/README.md +5 -0
- package/src/contracts/AnnotatedMintNft.sol +171 -0
- package/src/contracts/BaseState.sol +16 -0
- package/src/contracts/ERC1967.sol +43 -0
- package/src/contracts/Erc20NftSale.sol +186 -0
- package/src/contracts/GenericPayment.sol +60 -0
- package/src/contracts/NativeNftSale.sol +97 -0
- package/src/contracts/PaimaL2Contract.sol +54 -0
- package/src/contracts/Proxy/Erc20NftSaleProxy.sol +79 -0
- package/src/contracts/Proxy/GenericPaymentProxy.sol +64 -0
- package/src/contracts/Proxy/NativeNftSaleProxy.sol +72 -0
- package/src/contracts/Proxy/OrderbookDexProxy.sol +27 -0
- package/src/contracts/README.md +72 -0
- package/src/contracts/State.sol +25 -0
- package/src/contracts/dev/ERC721Dev.sol +13 -0
- package/src/contracts/dev/Erc20Dev.sol +13 -0
- package/src/contracts/dev/NativeNftSaleUpgradeDev.sol +9 -0
- package/src/contracts/dev/NftSaleUpgradeDev.sol +12 -0
- package/src/contracts/dev/NftTypeMapper.sol +38 -0
- package/src/contracts/dev/Token.sol +15 -0
- package/src/contracts/dev/UpgradeDev.sol +10 -0
- package/src/contracts/orderbook/IOrderbookDex.sol +215 -0
- package/src/contracts/orderbook/OrderbookDex.sol +435 -0
- package/src/contracts/token/IERC4906Agnostic.sol +17 -0
- package/src/contracts/token/IInverseAppProjected1155.sol +40 -0
- package/src/contracts/token/IInverseAppProjectedNft.sol +38 -0
- package/src/contracts/token/IInverseBaseProjected1155.sol +25 -0
- package/src/contracts/token/IInverseBaseProjectedNft.sol +29 -0
- package/src/contracts/token/IInverseProjected1155.sol +38 -0
- package/src/contracts/token/IInverseProjectedNft.sol +41 -0
- package/src/contracts/token/ITokenUri.sol +10 -0
- package/src/contracts/token/IUri.sol +13 -0
- package/src/contracts/token/InverseAppProjected1155.sol +218 -0
- package/src/contracts/token/InverseAppProjectedNft.sol +192 -0
- package/src/contracts/token/InverseBaseProjected1155.sol +170 -0
- package/src/contracts/token/InverseBaseProjectedNft.sol +158 -0
- package/src/plugin/common.ts +35 -0
- package/src/plugin/deployment.ts +161 -0
- package/src/plugin/mod.ts +6 -0
- package/src/plugin/paimaL2.ts +202 -0
- package/src/recommendedHardhat.ts +86 -0
- package/test/lib/StdInvariant.sol +96 -0
- package/test/lib/cheatcodes.sol +89 -0
- package/test/lib/console.sol +1884 -0
- package/test/lib/ctest.sol +678 -0
- package/test/src/InverseAppProjected1155.t.sol +207 -0
- package/test/src/InverseAppProjectedNft.t.sol +164 -0
- package/test/src/InverseBaseProjected1155.t.sol +171 -0
- package/test/src/InverseBaseProjectedNft.t.sol +141 -0
- package/test/src/OrderbookDex.t.sol +710 -0
- package/test/src/OrderbookDexInvariant.t.sol +426 -0
- package/test/src/PaimaL2ContractTest.sol +115 -0
|
@@ -0,0 +1,678 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity >=0.5.0;
|
|
3
|
+
|
|
4
|
+
import {StdInvariant} from "./StdInvariant.sol";
|
|
5
|
+
|
|
6
|
+
contract CTest is StdInvariant {
|
|
7
|
+
event log(string);
|
|
8
|
+
event logs(bytes);
|
|
9
|
+
|
|
10
|
+
event log_address(address);
|
|
11
|
+
event log_bytes32(bytes32);
|
|
12
|
+
event log_int(int);
|
|
13
|
+
event log_uint(uint);
|
|
14
|
+
event log_bytes(bytes);
|
|
15
|
+
event log_string(string);
|
|
16
|
+
|
|
17
|
+
event log_named_address(string key, address val);
|
|
18
|
+
event log_named_bytes32(string key, bytes32 val);
|
|
19
|
+
event log_named_decimal_int(string key, int val, uint decimals);
|
|
20
|
+
event log_named_decimal_uint(string key, uint val, uint decimals);
|
|
21
|
+
event log_named_int(string key, int val);
|
|
22
|
+
event log_named_uint(string key, uint val);
|
|
23
|
+
event log_named_bytes(string key, bytes val);
|
|
24
|
+
event log_named_string(string key, string val);
|
|
25
|
+
|
|
26
|
+
bool public IS_TEST = true;
|
|
27
|
+
bool private _failed;
|
|
28
|
+
|
|
29
|
+
address constant HEVM_ADDRESS =
|
|
30
|
+
address(bytes20(uint160(uint256(keccak256("hevm cheat code")))));
|
|
31
|
+
address private constant CONSOLE2_ADDRESS = 0x000000000000000000636F6e736F6c652e6c6f67;
|
|
32
|
+
uint256 private constant INT256_MIN_ABS =
|
|
33
|
+
57896044618658097711785492504343953926634992332820282019728792003956564819968;
|
|
34
|
+
uint256 private constant UINT256_MAX =
|
|
35
|
+
115792089237316195423570985008687907853269984665640564039457584007913129639935;
|
|
36
|
+
|
|
37
|
+
modifier mayRevert() {
|
|
38
|
+
_;
|
|
39
|
+
}
|
|
40
|
+
modifier testopts(string memory) {
|
|
41
|
+
_;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function failed() public returns (bool) {
|
|
45
|
+
if (_failed) {
|
|
46
|
+
return _failed;
|
|
47
|
+
} else {
|
|
48
|
+
bool globalFailed = false;
|
|
49
|
+
if (hasHEVMContext()) {
|
|
50
|
+
(, bytes memory retdata) = HEVM_ADDRESS.call(
|
|
51
|
+
abi.encodePacked(
|
|
52
|
+
bytes4(keccak256("load(address,bytes32)")),
|
|
53
|
+
abi.encode(HEVM_ADDRESS, bytes32("failed"))
|
|
54
|
+
)
|
|
55
|
+
);
|
|
56
|
+
globalFailed = abi.decode(retdata, (bool));
|
|
57
|
+
}
|
|
58
|
+
return globalFailed;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function fail() internal virtual {
|
|
63
|
+
if (hasHEVMContext()) {
|
|
64
|
+
(bool status, ) = HEVM_ADDRESS.call(
|
|
65
|
+
abi.encodePacked(
|
|
66
|
+
bytes4(keccak256("store(address,bytes32,bytes32)")),
|
|
67
|
+
abi.encode(HEVM_ADDRESS, bytes32("failed"), bytes32(uint256(0x01)))
|
|
68
|
+
)
|
|
69
|
+
);
|
|
70
|
+
status; // Silence compiler warnings
|
|
71
|
+
}
|
|
72
|
+
_failed = true;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function hasHEVMContext() internal view returns (bool) {
|
|
76
|
+
uint256 hevmCodeSize = 0;
|
|
77
|
+
assembly {
|
|
78
|
+
hevmCodeSize := extcodesize(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D)
|
|
79
|
+
}
|
|
80
|
+
return hevmCodeSize > 0;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
modifier logs_gas() {
|
|
84
|
+
uint startGas = gasleft();
|
|
85
|
+
_;
|
|
86
|
+
uint endGas = gasleft();
|
|
87
|
+
emit log_named_uint("gas", startGas - endGas);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function assertTrue(bool condition) internal {
|
|
91
|
+
if (!condition) {
|
|
92
|
+
emit log("Error: Assertion Failed");
|
|
93
|
+
fail();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function assertTrue(bool condition, string memory err) internal {
|
|
98
|
+
if (!condition) {
|
|
99
|
+
emit log_named_string("Error", err);
|
|
100
|
+
assertTrue(condition);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function assertEq(address a, address b) internal {
|
|
105
|
+
if (a != b) {
|
|
106
|
+
emit log("Error: a == b not satisfied [address]");
|
|
107
|
+
emit log_named_address(" Left", a);
|
|
108
|
+
emit log_named_address(" Right", b);
|
|
109
|
+
fail();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function assertEq(address a, address b, string memory err) internal {
|
|
113
|
+
if (a != b) {
|
|
114
|
+
emit log_named_string("Error", err);
|
|
115
|
+
assertEq(a, b);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function assertEq(bytes32 a, bytes32 b) internal {
|
|
120
|
+
if (a != b) {
|
|
121
|
+
emit log("Error: a == b not satisfied [bytes32]");
|
|
122
|
+
emit log_named_bytes32(" Left", a);
|
|
123
|
+
emit log_named_bytes32(" Right", b);
|
|
124
|
+
fail();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function assertEq(bytes32 a, bytes32 b, string memory err) internal {
|
|
128
|
+
if (a != b) {
|
|
129
|
+
emit log_named_string("Error", err);
|
|
130
|
+
assertEq(a, b);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function assertEq32(bytes32 a, bytes32 b) internal {
|
|
134
|
+
assertEq(a, b);
|
|
135
|
+
}
|
|
136
|
+
function assertEq32(bytes32 a, bytes32 b, string memory err) internal {
|
|
137
|
+
assertEq(a, b, err);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function assertEq(int a, int b) internal {
|
|
141
|
+
if (a != b) {
|
|
142
|
+
emit log("Error: a == b not satisfied [int]");
|
|
143
|
+
emit log_named_int(" Left", a);
|
|
144
|
+
emit log_named_int(" Right", b);
|
|
145
|
+
fail();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function assertEq(int a, int b, string memory err) internal {
|
|
149
|
+
if (a != b) {
|
|
150
|
+
emit log_named_string("Error", err);
|
|
151
|
+
assertEq(a, b);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
function assertEq(uint a, uint b) internal {
|
|
155
|
+
if (a != b) {
|
|
156
|
+
emit log("Error: a == b not satisfied [uint]");
|
|
157
|
+
emit log_named_uint(" Left", a);
|
|
158
|
+
emit log_named_uint(" Right", b);
|
|
159
|
+
fail();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function assertEq(uint a, uint b, string memory err) internal {
|
|
163
|
+
if (a != b) {
|
|
164
|
+
emit log_named_string("Error", err);
|
|
165
|
+
assertEq(a, b);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function assertEqDecimal(int a, int b, uint decimals) internal {
|
|
169
|
+
if (a != b) {
|
|
170
|
+
emit log("Error: a == b not satisfied [decimal int]");
|
|
171
|
+
emit log_named_decimal_int(" Left", a, decimals);
|
|
172
|
+
emit log_named_decimal_int(" Right", b, decimals);
|
|
173
|
+
fail();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
function assertEqDecimal(int a, int b, uint decimals, string memory err) internal {
|
|
177
|
+
if (a != b) {
|
|
178
|
+
emit log_named_string("Error", err);
|
|
179
|
+
assertEqDecimal(a, b, decimals);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
function assertEqDecimal(uint a, uint b, uint decimals) internal {
|
|
183
|
+
if (a != b) {
|
|
184
|
+
emit log("Error: a == b not satisfied [decimal uint]");
|
|
185
|
+
emit log_named_decimal_uint(" Left", a, decimals);
|
|
186
|
+
emit log_named_decimal_uint(" Right", b, decimals);
|
|
187
|
+
fail();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
function assertEqDecimal(uint a, uint b, uint decimals, string memory err) internal {
|
|
191
|
+
if (a != b) {
|
|
192
|
+
emit log_named_string("Error", err);
|
|
193
|
+
assertEqDecimal(a, b, decimals);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function assertNotEq(address a, address b) internal {
|
|
198
|
+
if (a == b) {
|
|
199
|
+
emit log("Error: a != b not satisfied [address]");
|
|
200
|
+
emit log_named_address(" Left", a);
|
|
201
|
+
emit log_named_address(" Right", b);
|
|
202
|
+
fail();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
function assertNotEq(address a, address b, string memory err) internal {
|
|
206
|
+
if (a == b) {
|
|
207
|
+
emit log_named_string("Error", err);
|
|
208
|
+
assertNotEq(a, b);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function assertNotEq(bytes32 a, bytes32 b) internal {
|
|
213
|
+
if (a == b) {
|
|
214
|
+
emit log("Error: a != b not satisfied [bytes32]");
|
|
215
|
+
emit log_named_bytes32(" Left", a);
|
|
216
|
+
emit log_named_bytes32(" Right", b);
|
|
217
|
+
fail();
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
function assertNotEq(bytes32 a, bytes32 b, string memory err) internal {
|
|
221
|
+
if (a == b) {
|
|
222
|
+
emit log_named_string("Error", err);
|
|
223
|
+
assertNotEq(a, b);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function assertNotEq32(bytes32 a, bytes32 b) internal {
|
|
227
|
+
assertNotEq(a, b);
|
|
228
|
+
}
|
|
229
|
+
function assertNotEq32(bytes32 a, bytes32 b, string memory err) internal {
|
|
230
|
+
assertNotEq(a, b, err);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function assertNotEq(int a, int b) internal {
|
|
234
|
+
if (a == b) {
|
|
235
|
+
emit log("Error: a != b not satisfied [int]");
|
|
236
|
+
emit log_named_int(" Left", a);
|
|
237
|
+
emit log_named_int(" Right", b);
|
|
238
|
+
fail();
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
function assertNotEq(int a, int b, string memory err) internal {
|
|
242
|
+
if (a == b) {
|
|
243
|
+
emit log_named_string("Error", err);
|
|
244
|
+
assertNotEq(a, b);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
function assertNotEq(uint a, uint b) internal {
|
|
248
|
+
if (a == b) {
|
|
249
|
+
emit log("Error: a != b not satisfied [uint]");
|
|
250
|
+
emit log_named_uint(" Left", a);
|
|
251
|
+
emit log_named_uint(" Right", b);
|
|
252
|
+
fail();
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
function assertNotEq(uint a, uint b, string memory err) internal {
|
|
256
|
+
if (a == b) {
|
|
257
|
+
emit log_named_string("Error", err);
|
|
258
|
+
assertNotEq(a, b);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
function assertNotEqDecimal(int a, int b, uint decimals) internal {
|
|
262
|
+
if (a == b) {
|
|
263
|
+
emit log("Error: a != b not satisfied [decimal int]");
|
|
264
|
+
emit log_named_decimal_int(" Left", a, decimals);
|
|
265
|
+
emit log_named_decimal_int(" Right", b, decimals);
|
|
266
|
+
fail();
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
function assertNotEqDecimal(int a, int b, uint decimals, string memory err) internal {
|
|
270
|
+
if (a == b) {
|
|
271
|
+
emit log_named_string("Error", err);
|
|
272
|
+
assertNotEqDecimal(a, b, decimals);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
function assertNotEqDecimal(uint a, uint b, uint decimals) internal {
|
|
276
|
+
if (a == b) {
|
|
277
|
+
emit log("Error: a != b not satisfied [decimal uint]");
|
|
278
|
+
emit log_named_decimal_uint(" Left", a, decimals);
|
|
279
|
+
emit log_named_decimal_uint(" Right", b, decimals);
|
|
280
|
+
fail();
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
function assertNotEqDecimal(uint a, uint b, uint decimals, string memory err) internal {
|
|
284
|
+
if (a == b) {
|
|
285
|
+
emit log_named_string("Error", err);
|
|
286
|
+
assertNotEqDecimal(a, b, decimals);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function assertGt(uint a, uint b) internal {
|
|
291
|
+
if (a <= b) {
|
|
292
|
+
emit log("Error: a > b not satisfied [uint]");
|
|
293
|
+
emit log_named_uint(" Value a", a);
|
|
294
|
+
emit log_named_uint(" Value b", b);
|
|
295
|
+
fail();
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
function assertGt(uint a, uint b, string memory err) internal {
|
|
299
|
+
if (a <= b) {
|
|
300
|
+
emit log_named_string("Error", err);
|
|
301
|
+
assertGt(a, b);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
function assertGt(int a, int b) internal {
|
|
305
|
+
if (a <= b) {
|
|
306
|
+
emit log("Error: a > b not satisfied [int]");
|
|
307
|
+
emit log_named_int(" Value a", a);
|
|
308
|
+
emit log_named_int(" Value b", b);
|
|
309
|
+
fail();
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
function assertGt(int a, int b, string memory err) internal {
|
|
313
|
+
if (a <= b) {
|
|
314
|
+
emit log_named_string("Error", err);
|
|
315
|
+
assertGt(a, b);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
function assertGtDecimal(int a, int b, uint decimals) internal {
|
|
319
|
+
if (a <= b) {
|
|
320
|
+
emit log("Error: a > b not satisfied [decimal int]");
|
|
321
|
+
emit log_named_decimal_int(" Value a", a, decimals);
|
|
322
|
+
emit log_named_decimal_int(" Value b", b, decimals);
|
|
323
|
+
fail();
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
function assertGtDecimal(int a, int b, uint decimals, string memory err) internal {
|
|
327
|
+
if (a <= b) {
|
|
328
|
+
emit log_named_string("Error", err);
|
|
329
|
+
assertGtDecimal(a, b, decimals);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
function assertGtDecimal(uint a, uint b, uint decimals) internal {
|
|
333
|
+
if (a <= b) {
|
|
334
|
+
emit log("Error: a > b not satisfied [decimal uint]");
|
|
335
|
+
emit log_named_decimal_uint(" Value a", a, decimals);
|
|
336
|
+
emit log_named_decimal_uint(" Value b", b, decimals);
|
|
337
|
+
fail();
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
function assertGtDecimal(uint a, uint b, uint decimals, string memory err) internal {
|
|
341
|
+
if (a <= b) {
|
|
342
|
+
emit log_named_string("Error", err);
|
|
343
|
+
assertGtDecimal(a, b, decimals);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function assertGe(uint a, uint b) internal {
|
|
348
|
+
if (a < b) {
|
|
349
|
+
emit log("Error: a >= b not satisfied [uint]");
|
|
350
|
+
emit log_named_uint(" Value a", a);
|
|
351
|
+
emit log_named_uint(" Value b", b);
|
|
352
|
+
fail();
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
function assertGe(uint a, uint b, string memory err) internal {
|
|
356
|
+
if (a < b) {
|
|
357
|
+
emit log_named_string("Error", err);
|
|
358
|
+
assertGe(a, b);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
function assertGe(int a, int b) internal {
|
|
362
|
+
if (a < b) {
|
|
363
|
+
emit log("Error: a >= b not satisfied [int]");
|
|
364
|
+
emit log_named_int(" Value a", a);
|
|
365
|
+
emit log_named_int(" Value b", b);
|
|
366
|
+
fail();
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
function assertGe(int a, int b, string memory err) internal {
|
|
370
|
+
if (a < b) {
|
|
371
|
+
emit log_named_string("Error", err);
|
|
372
|
+
assertGe(a, b);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
function assertGeDecimal(int a, int b, uint decimals) internal {
|
|
376
|
+
if (a < b) {
|
|
377
|
+
emit log("Error: a >= b not satisfied [decimal int]");
|
|
378
|
+
emit log_named_decimal_int(" Value a", a, decimals);
|
|
379
|
+
emit log_named_decimal_int(" Value b", b, decimals);
|
|
380
|
+
fail();
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
function assertGeDecimal(int a, int b, uint decimals, string memory err) internal {
|
|
384
|
+
if (a < b) {
|
|
385
|
+
emit log_named_string("Error", err);
|
|
386
|
+
assertGeDecimal(a, b, decimals);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
function assertGeDecimal(uint a, uint b, uint decimals) internal {
|
|
390
|
+
if (a < b) {
|
|
391
|
+
emit log("Error: a >= b not satisfied [decimal uint]");
|
|
392
|
+
emit log_named_decimal_uint(" Value a", a, decimals);
|
|
393
|
+
emit log_named_decimal_uint(" Value b", b, decimals);
|
|
394
|
+
fail();
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
function assertGeDecimal(uint a, uint b, uint decimals, string memory err) internal {
|
|
398
|
+
if (a < b) {
|
|
399
|
+
emit log_named_string("Error", err);
|
|
400
|
+
assertGeDecimal(a, b, decimals);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
function assertLt(uint a, uint b) internal {
|
|
405
|
+
if (a >= b) {
|
|
406
|
+
emit log("Error: a < b not satisfied [uint]");
|
|
407
|
+
emit log_named_uint(" Value a", a);
|
|
408
|
+
emit log_named_uint(" Value b", b);
|
|
409
|
+
fail();
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
function assertLt(uint a, uint b, string memory err) internal {
|
|
413
|
+
if (a >= b) {
|
|
414
|
+
emit log_named_string("Error", err);
|
|
415
|
+
assertLt(a, b);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
function assertLt(int a, int b) internal {
|
|
419
|
+
if (a >= b) {
|
|
420
|
+
emit log("Error: a < b not satisfied [int]");
|
|
421
|
+
emit log_named_int(" Value a", a);
|
|
422
|
+
emit log_named_int(" Value b", b);
|
|
423
|
+
fail();
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
function assertLt(int a, int b, string memory err) internal {
|
|
427
|
+
if (a >= b) {
|
|
428
|
+
emit log_named_string("Error", err);
|
|
429
|
+
assertLt(a, b);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
function assertLtDecimal(int a, int b, uint decimals) internal {
|
|
433
|
+
if (a >= b) {
|
|
434
|
+
emit log("Error: a < b not satisfied [decimal int]");
|
|
435
|
+
emit log_named_decimal_int(" Value a", a, decimals);
|
|
436
|
+
emit log_named_decimal_int(" Value b", b, decimals);
|
|
437
|
+
fail();
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
function assertLtDecimal(int a, int b, uint decimals, string memory err) internal {
|
|
441
|
+
if (a >= b) {
|
|
442
|
+
emit log_named_string("Error", err);
|
|
443
|
+
assertLtDecimal(a, b, decimals);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
function assertLtDecimal(uint a, uint b, uint decimals) internal {
|
|
447
|
+
if (a >= b) {
|
|
448
|
+
emit log("Error: a < b not satisfied [decimal uint]");
|
|
449
|
+
emit log_named_decimal_uint(" Value a", a, decimals);
|
|
450
|
+
emit log_named_decimal_uint(" Value b", b, decimals);
|
|
451
|
+
fail();
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
function assertLtDecimal(uint a, uint b, uint decimals, string memory err) internal {
|
|
455
|
+
if (a >= b) {
|
|
456
|
+
emit log_named_string("Error", err);
|
|
457
|
+
assertLtDecimal(a, b, decimals);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
function assertLe(uint a, uint b) internal {
|
|
462
|
+
if (a > b) {
|
|
463
|
+
emit log("Error: a <= b not satisfied [uint]");
|
|
464
|
+
emit log_named_uint(" Value a", a);
|
|
465
|
+
emit log_named_uint(" Value b", b);
|
|
466
|
+
fail();
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
function assertLe(uint a, uint b, string memory err) internal {
|
|
470
|
+
if (a > b) {
|
|
471
|
+
emit log_named_string("Error", err);
|
|
472
|
+
assertLe(a, b);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
function assertLe(int a, int b) internal {
|
|
476
|
+
if (a > b) {
|
|
477
|
+
emit log("Error: a <= b not satisfied [int]");
|
|
478
|
+
emit log_named_int(" Value a", a);
|
|
479
|
+
emit log_named_int(" Value b", b);
|
|
480
|
+
fail();
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
function assertLe(int a, int b, string memory err) internal {
|
|
484
|
+
if (a > b) {
|
|
485
|
+
emit log_named_string("Error", err);
|
|
486
|
+
assertLe(a, b);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
function assertLeDecimal(int a, int b, uint decimals) internal {
|
|
490
|
+
if (a > b) {
|
|
491
|
+
emit log("Error: a <= b not satisfied [decimal int]");
|
|
492
|
+
emit log_named_decimal_int(" Value a", a, decimals);
|
|
493
|
+
emit log_named_decimal_int(" Value b", b, decimals);
|
|
494
|
+
fail();
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
function assertLeDecimal(int a, int b, uint decimals, string memory err) internal {
|
|
498
|
+
if (a > b) {
|
|
499
|
+
emit log_named_string("Error", err);
|
|
500
|
+
assertLeDecimal(a, b, decimals);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
function assertLeDecimal(uint a, uint b, uint decimals) internal {
|
|
504
|
+
if (a > b) {
|
|
505
|
+
emit log("Error: a <= b not satisfied [decimal uint]");
|
|
506
|
+
emit log_named_decimal_uint(" Value a", a, decimals);
|
|
507
|
+
emit log_named_decimal_uint(" Value b", b, decimals);
|
|
508
|
+
fail();
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
function assertLeDecimal(uint a, uint b, uint decimals, string memory err) internal {
|
|
512
|
+
if (a > b) {
|
|
513
|
+
emit log_named_string("Error", err);
|
|
514
|
+
assertLeDecimal(a, b, decimals);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
function assertEq(string memory a, string memory b) internal {
|
|
519
|
+
if (keccak256(abi.encodePacked(a)) != keccak256(abi.encodePacked(b))) {
|
|
520
|
+
emit log("Error: a == b not satisfied [string]");
|
|
521
|
+
emit log_named_string(" Left", a);
|
|
522
|
+
emit log_named_string(" Right", b);
|
|
523
|
+
fail();
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
function assertEq(string memory a, string memory b, string memory err) internal {
|
|
527
|
+
if (keccak256(abi.encodePacked(a)) != keccak256(abi.encodePacked(b))) {
|
|
528
|
+
emit log_named_string("Error", err);
|
|
529
|
+
assertEq(a, b);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
function assertNotEq(string memory a, string memory b) internal {
|
|
534
|
+
if (keccak256(abi.encodePacked(a)) == keccak256(abi.encodePacked(b))) {
|
|
535
|
+
emit log("Error: a != b not satisfied [string]");
|
|
536
|
+
emit log_named_string(" Left", a);
|
|
537
|
+
emit log_named_string(" Right", b);
|
|
538
|
+
fail();
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
function assertNotEq(string memory a, string memory b, string memory err) internal {
|
|
542
|
+
if (keccak256(abi.encodePacked(a)) == keccak256(abi.encodePacked(b))) {
|
|
543
|
+
emit log_named_string("Error", err);
|
|
544
|
+
assertNotEq(a, b);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
function checkEq0(bytes memory a, bytes memory b) internal pure returns (bool ok) {
|
|
549
|
+
ok = true;
|
|
550
|
+
if (a.length == b.length) {
|
|
551
|
+
for (uint i = 0; i < a.length; i++) {
|
|
552
|
+
if (a[i] != b[i]) {
|
|
553
|
+
ok = false;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
} else {
|
|
557
|
+
ok = false;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
function assertEq0(bytes memory a, bytes memory b) internal {
|
|
561
|
+
if (!checkEq0(a, b)) {
|
|
562
|
+
emit log("Error: a == b not satisfied [bytes]");
|
|
563
|
+
emit log_named_bytes(" Left", a);
|
|
564
|
+
emit log_named_bytes(" Right", b);
|
|
565
|
+
fail();
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
function assertEq0(bytes memory a, bytes memory b, string memory err) internal {
|
|
569
|
+
if (!checkEq0(a, b)) {
|
|
570
|
+
emit log_named_string("Error", err);
|
|
571
|
+
assertEq0(a, b);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
function assertNotEq0(bytes memory a, bytes memory b) internal {
|
|
576
|
+
if (checkEq0(a, b)) {
|
|
577
|
+
emit log("Error: a != b not satisfied [bytes]");
|
|
578
|
+
emit log_named_bytes(" Left", a);
|
|
579
|
+
emit log_named_bytes(" Right", b);
|
|
580
|
+
fail();
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
function assertNotEq0(bytes memory a, bytes memory b, string memory err) internal {
|
|
584
|
+
if (checkEq0(a, b)) {
|
|
585
|
+
emit log_named_string("Error", err);
|
|
586
|
+
assertNotEq0(a, b);
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
function console2_log(string memory p0, uint256 p1) private view {
|
|
591
|
+
(bool status, ) = address(CONSOLE2_ADDRESS).staticcall(
|
|
592
|
+
abi.encodeWithSignature("log(string,uint256)", p0, p1)
|
|
593
|
+
);
|
|
594
|
+
status;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
function console2_log(string memory p0, string memory p1) private view {
|
|
598
|
+
(bool status, ) = address(CONSOLE2_ADDRESS).staticcall(
|
|
599
|
+
abi.encodeWithSignature("log(string,string)", p0, p1)
|
|
600
|
+
);
|
|
601
|
+
status;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
function _bound(
|
|
605
|
+
uint256 x,
|
|
606
|
+
uint256 min,
|
|
607
|
+
uint256 max
|
|
608
|
+
) internal pure virtual returns (uint256 result) {
|
|
609
|
+
require(min <= max, "StdUtils bound(uint256,uint256,uint256): Max is less than min.");
|
|
610
|
+
// If x is between min and max, return x directly. This is to ensure that dictionary values
|
|
611
|
+
// do not get shifted if the min is nonzero. More info: https://github.com/foundry-rs/forge-std/issues/188
|
|
612
|
+
if (x >= min && x <= max) return x;
|
|
613
|
+
|
|
614
|
+
uint256 size = max - min + 1;
|
|
615
|
+
|
|
616
|
+
// If the value is 0, 1, 2, 3, wrap that to min, min+1, min+2, min+3. Similarly for the UINT256_MAX side.
|
|
617
|
+
// This helps ensure coverage of the min/max values.
|
|
618
|
+
if (x <= 3 && size > x) return min + x;
|
|
619
|
+
if (x >= UINT256_MAX - 3 && size > UINT256_MAX - x) return max - (UINT256_MAX - x);
|
|
620
|
+
|
|
621
|
+
// Otherwise, wrap x into the range [min, max], i.e. the range is inclusive.
|
|
622
|
+
if (x > max) {
|
|
623
|
+
uint256 diff = x - max;
|
|
624
|
+
uint256 rem = diff % size;
|
|
625
|
+
if (rem == 0) return max;
|
|
626
|
+
result = min + rem - 1;
|
|
627
|
+
} else if (x < min) {
|
|
628
|
+
uint256 diff = min - x;
|
|
629
|
+
uint256 rem = diff % size;
|
|
630
|
+
if (rem == 0) return min;
|
|
631
|
+
result = max - rem + 1;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
function bound(
|
|
636
|
+
uint256 x,
|
|
637
|
+
uint256 min,
|
|
638
|
+
uint256 max
|
|
639
|
+
) internal view virtual returns (uint256 result) {
|
|
640
|
+
result = _bound(x, min, max);
|
|
641
|
+
// console2_log("Bound Result", result);
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
function _bound(
|
|
645
|
+
int256 x,
|
|
646
|
+
int256 min,
|
|
647
|
+
int256 max
|
|
648
|
+
) internal pure virtual returns (int256 result) {
|
|
649
|
+
require(min <= max, "StdUtils bound(int256,int256,int256): Max is less than min.");
|
|
650
|
+
|
|
651
|
+
// Shifting all int256 values to uint256 to use _bound function. The range of two types are:
|
|
652
|
+
// int256 : -(2**255) ~ (2**255 - 1)
|
|
653
|
+
// uint256: 0 ~ (2**256 - 1)
|
|
654
|
+
// So, add 2**255, INT256_MIN_ABS to the integer values.
|
|
655
|
+
//
|
|
656
|
+
// If the given integer value is -2**255, we cannot use `-uint256(-x)` because of the overflow.
|
|
657
|
+
// So, use `~uint256(x) + 1` instead.
|
|
658
|
+
uint256 _x = x < 0 ? (INT256_MIN_ABS - ~uint256(x) - 1) : (uint256(x) + INT256_MIN_ABS);
|
|
659
|
+
uint256 _min = min < 0
|
|
660
|
+
? (INT256_MIN_ABS - ~uint256(min) - 1)
|
|
661
|
+
: (uint256(min) + INT256_MIN_ABS);
|
|
662
|
+
uint256 _max = max < 0
|
|
663
|
+
? (INT256_MIN_ABS - ~uint256(max) - 1)
|
|
664
|
+
: (uint256(max) + INT256_MIN_ABS);
|
|
665
|
+
|
|
666
|
+
uint256 y = _bound(_x, _min, _max);
|
|
667
|
+
|
|
668
|
+
// To move it back to int256 value, subtract INT256_MIN_ABS at here.
|
|
669
|
+
result = y < INT256_MIN_ABS
|
|
670
|
+
? int256(~(INT256_MIN_ABS - y) + 1)
|
|
671
|
+
: int256(y - INT256_MIN_ABS);
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
function bound(int256 x, int256 min, int256 max) internal view virtual returns (int256 result) {
|
|
675
|
+
result = _bound(x, min, max);
|
|
676
|
+
// console2_log("Bound result", vm.toString(result));
|
|
677
|
+
}
|
|
678
|
+
}
|