@bgd-labs/aave-address-book 1.1.1

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.
Files changed (115) hide show
  1. package/.gitmodules +4 -0
  2. package/CHANGELOG.md +56 -0
  3. package/LICENSE +7 -0
  4. package/README.md +94 -0
  5. package/addressbook_logo.png +0 -0
  6. package/dist/AaveAddressBook.d.ts +17 -0
  7. package/dist/AaveAddressBook.js +20 -0
  8. package/dist/AaveV2Avalanche.d.ts +9 -0
  9. package/dist/AaveV2Avalanche.js +12 -0
  10. package/dist/AaveV2Ethereum.d.ts +9 -0
  11. package/dist/AaveV2Ethereum.js +12 -0
  12. package/dist/AaveV2EthereumAMM.d.ts +9 -0
  13. package/dist/AaveV2EthereumAMM.js +12 -0
  14. package/dist/AaveV2EthereumArc.d.ts +9 -0
  15. package/dist/AaveV2EthereumArc.js +12 -0
  16. package/dist/AaveV2Fuji.d.ts +9 -0
  17. package/dist/AaveV2Fuji.js +12 -0
  18. package/dist/AaveV2Mumbai.d.ts +9 -0
  19. package/dist/AaveV2Mumbai.js +12 -0
  20. package/dist/AaveV2Polygon.d.ts +9 -0
  21. package/dist/AaveV2Polygon.js +12 -0
  22. package/dist/AaveV3Arbitrum.d.ts +9 -0
  23. package/dist/AaveV3Arbitrum.js +12 -0
  24. package/dist/AaveV3Avalanche.d.ts +9 -0
  25. package/dist/AaveV3Avalanche.js +12 -0
  26. package/dist/AaveV3Fantom.d.ts +9 -0
  27. package/dist/AaveV3Fantom.js +12 -0
  28. package/dist/AaveV3FantomTestnet.d.ts +9 -0
  29. package/dist/AaveV3FantomTestnet.js +12 -0
  30. package/dist/AaveV3Fuji.d.ts +9 -0
  31. package/dist/AaveV3Fuji.js +12 -0
  32. package/dist/AaveV3Harmony.d.ts +9 -0
  33. package/dist/AaveV3Harmony.js +12 -0
  34. package/dist/AaveV3Mumbai.d.ts +9 -0
  35. package/dist/AaveV3Mumbai.js +12 -0
  36. package/dist/AaveV3Optimism.d.ts +9 -0
  37. package/dist/AaveV3Optimism.js +12 -0
  38. package/dist/AaveV3OptimismKovan.d.ts +9 -0
  39. package/dist/AaveV3OptimismKovan.js +12 -0
  40. package/dist/AaveV3Polygon.d.ts +9 -0
  41. package/dist/AaveV3Polygon.js +12 -0
  42. package/foundry.toml +8 -0
  43. package/lib/forge-std/.github/workflows/tests.yml +27 -0
  44. package/lib/forge-std/.gitmodules +3 -0
  45. package/lib/forge-std/LICENSE-APACHE +203 -0
  46. package/lib/forge-std/LICENSE-MIT +25 -0
  47. package/lib/forge-std/README.md +246 -0
  48. package/lib/forge-std/lib/ds-test/LICENSE +674 -0
  49. package/lib/forge-std/lib/ds-test/Makefile +14 -0
  50. package/lib/forge-std/lib/ds-test/default.nix +4 -0
  51. package/lib/forge-std/lib/ds-test/demo/demo.sol +222 -0
  52. package/lib/forge-std/lib/ds-test/src/test.sol +469 -0
  53. package/lib/forge-std/src/Script.sol +39 -0
  54. package/lib/forge-std/src/StdJson.sol +118 -0
  55. package/lib/forge-std/src/Test.sol +1134 -0
  56. package/lib/forge-std/src/Vm.sol +231 -0
  57. package/lib/forge-std/src/console.sol +1533 -0
  58. package/lib/forge-std/src/console2.sol +1538 -0
  59. package/lib/forge-std/src/test/Script.t.sol +12 -0
  60. package/lib/forge-std/src/test/StdAssertions.t.sol +591 -0
  61. package/lib/forge-std/src/test/StdCheats.t.sol +282 -0
  62. package/lib/forge-std/src/test/StdError.t.sol +124 -0
  63. package/lib/forge-std/src/test/StdMath.t.sol +200 -0
  64. package/lib/forge-std/src/test/StdStorage.t.sol +321 -0
  65. package/lib/forge-std/src/test/fixtures/broadcast.log.json +187 -0
  66. package/package.json +39 -0
  67. package/src/AaveAddressBook.sol +28 -0
  68. package/src/AaveAddressBookV2.sol +143 -0
  69. package/src/AaveAddressBookV2Testnet.sol +74 -0
  70. package/src/AaveAddressBookV3.sol +166 -0
  71. package/src/AaveAddressBookV3Testnet.sol +120 -0
  72. package/src/AaveGovernanceV2.sol +549 -0
  73. package/src/AaveV2.sol +931 -0
  74. package/src/AaveV2Avalanche.sol +35 -0
  75. package/src/AaveV2Ethereum.sol +36 -0
  76. package/src/AaveV2EthereumAMM.sol +36 -0
  77. package/src/AaveV2EthereumArc.sol +36 -0
  78. package/src/AaveV2Fuji.sol +35 -0
  79. package/src/AaveV2Mumbai.sol +35 -0
  80. package/src/AaveV2Polygon.sol +35 -0
  81. package/src/AaveV3.sol +2406 -0
  82. package/src/AaveV3Arbitrum.sol +34 -0
  83. package/src/AaveV3Avalanche.sol +34 -0
  84. package/src/AaveV3Fantom.sol +34 -0
  85. package/src/AaveV3FantomTestnet.sol +34 -0
  86. package/src/AaveV3Fuji.sol +34 -0
  87. package/src/AaveV3Harmony.sol +34 -0
  88. package/src/AaveV3HarmonyTestnet.sol +34 -0
  89. package/src/AaveV3Mumbai.sol +34 -0
  90. package/src/AaveV3Optimism.sol +34 -0
  91. package/src/AaveV3OptimismKovan.sol +34 -0
  92. package/src/AaveV3Polygon.sol +34 -0
  93. package/src/Common.sol +9 -0
  94. package/src/test/AaveV2Ethereum.t.sol +72 -0
  95. package/src/test/AaveV2Misfits.t.sol +33 -0
  96. package/src/test/AaveV3Avalanche.t.sol +65 -0
  97. package/src/ts/AaveAddressBook.ts +17 -0
  98. package/src/ts/AaveV2Avalanche.ts +11 -0
  99. package/src/ts/AaveV2Ethereum.ts +12 -0
  100. package/src/ts/AaveV2EthereumAMM.ts +12 -0
  101. package/src/ts/AaveV2EthereumArc.ts +12 -0
  102. package/src/ts/AaveV2Fuji.ts +11 -0
  103. package/src/ts/AaveV2Mumbai.ts +11 -0
  104. package/src/ts/AaveV2Polygon.ts +11 -0
  105. package/src/ts/AaveV3Arbitrum.ts +12 -0
  106. package/src/ts/AaveV3Avalanche.ts +12 -0
  107. package/src/ts/AaveV3Fantom.ts +12 -0
  108. package/src/ts/AaveV3FantomTestnet.ts +12 -0
  109. package/src/ts/AaveV3Fuji.ts +12 -0
  110. package/src/ts/AaveV3Harmony.ts +12 -0
  111. package/src/ts/AaveV3Mumbai.ts +12 -0
  112. package/src/ts/AaveV3Optimism.ts +12 -0
  113. package/src/ts/AaveV3OptimismKovan.ts +12 -0
  114. package/src/ts/AaveV3Polygon.ts +12 -0
  115. package/tsconfig.json +101 -0
@@ -0,0 +1,12 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity >=0.7.0 <0.9.0;
3
+
4
+ import "../Test.sol";
5
+
6
+ contract ScriptTest is Test
7
+ {
8
+ function testGenerateCorrectAddress() external {
9
+ address creation = computeCreateAddress(0x6C9FC64A53c1b71FB3f9Af64d1ae3A4931A5f4E9, 14);
10
+ assertEq(creation, 0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45);
11
+ }
12
+ }
@@ -0,0 +1,591 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity >=0.7.0 <0.9.0;
3
+
4
+ import "../Test.sol";
5
+
6
+ contract StdAssertionsTest is Test
7
+ {
8
+ string constant CUSTOM_ERROR = "guh!";
9
+
10
+ bool constant EXPECT_PASS = false;
11
+ bool constant EXPECT_FAIL = true;
12
+
13
+ TestTest t = new TestTest();
14
+
15
+ /*//////////////////////////////////////////////////////////////////////////
16
+ FAIL(STRING)
17
+ //////////////////////////////////////////////////////////////////////////*/
18
+
19
+ function testShouldFail() external {
20
+ vm.expectEmit(false, false, false, true);
21
+ emit log_named_string("Error", CUSTOM_ERROR);
22
+ t._fail(CUSTOM_ERROR);
23
+ }
24
+
25
+ /*//////////////////////////////////////////////////////////////////////////
26
+ ASSERT_FALSE
27
+ //////////////////////////////////////////////////////////////////////////*/
28
+
29
+ function testAssertFalse_Pass() external {
30
+ t._assertFalse(false, EXPECT_PASS);
31
+ }
32
+
33
+ function testAssertFalse_Fail() external {
34
+ vm.expectEmit(false, false, false, true);
35
+ emit log("Error: Assertion Failed");
36
+ t._assertFalse(true, EXPECT_FAIL);
37
+ }
38
+
39
+ function testAssertFalse_Err_Pass() external {
40
+ t._assertFalse(false, CUSTOM_ERROR, EXPECT_PASS);
41
+ }
42
+
43
+ function testAssertFalse_Err_Fail() external {
44
+ vm.expectEmit(false, false, false, true);
45
+ emit log_named_string("Error", CUSTOM_ERROR);
46
+ t._assertFalse(true, CUSTOM_ERROR, EXPECT_FAIL);
47
+ }
48
+
49
+ /*//////////////////////////////////////////////////////////////////////////
50
+ ASSERT_EQ(BOOL)
51
+ //////////////////////////////////////////////////////////////////////////*/
52
+
53
+ function testAssertEq_Bool_Pass(bool a) external {
54
+ t._assertEq(a, a, EXPECT_PASS);
55
+ }
56
+
57
+ function testAssertEq_Bool_Fail(bool a, bool b) external {
58
+ vm.assume(a != b);
59
+
60
+ vm.expectEmit(false, false, false, true);
61
+ emit log("Error: a == b not satisfied [bool]");
62
+ t._assertEq(a, b, EXPECT_FAIL);
63
+ }
64
+
65
+ function testAssertEq_BoolErr_Pass(bool a) external {
66
+ t._assertEq(a, a, CUSTOM_ERROR, EXPECT_PASS);
67
+ }
68
+
69
+ function testAssertEq_BoolErr_Fail(bool a, bool b) external {
70
+ vm.assume(a != b);
71
+
72
+ vm.expectEmit(false, false, false, true);
73
+ emit log_named_string("Error", CUSTOM_ERROR);
74
+ t._assertEq(a, b, CUSTOM_ERROR, EXPECT_FAIL);
75
+ }
76
+
77
+ /*//////////////////////////////////////////////////////////////////////////
78
+ ASSERT_EQ(BYTES)
79
+ //////////////////////////////////////////////////////////////////////////*/
80
+
81
+ function testAssertEq_Bytes_Pass(bytes calldata a) external {
82
+ t._assertEq(a, a, EXPECT_PASS);
83
+ }
84
+
85
+ function testAssertEq_Bytes_Fail(bytes calldata a, bytes calldata b) external {
86
+ vm.assume(keccak256(a) != keccak256(b));
87
+
88
+ vm.expectEmit(false, false, false, true);
89
+ emit log("Error: a == b not satisfied [bytes]");
90
+ t._assertEq(a, b, EXPECT_FAIL);
91
+ }
92
+
93
+ function testAssertEq_BytesErr_Pass(bytes calldata a) external {
94
+ t._assertEq(a, a, CUSTOM_ERROR, EXPECT_PASS);
95
+ }
96
+
97
+ function testAssertEq_BytesErr_Fail(bytes calldata a, bytes calldata b) external {
98
+ vm.assume(keccak256(a) != keccak256(b));
99
+
100
+ vm.expectEmit(false, false, false, true);
101
+ emit log_named_string("Error", CUSTOM_ERROR);
102
+ t._assertEq(a, b, CUSTOM_ERROR, EXPECT_FAIL);
103
+ }
104
+
105
+ /*//////////////////////////////////////////////////////////////////////////
106
+ ASSERT_EQ(ARRAY)
107
+ //////////////////////////////////////////////////////////////////////////*/
108
+
109
+ function testAssertEq_UintArr_Pass(uint256 e0, uint256 e1, uint256 e2) public {
110
+ uint256[] memory a = new uint256[](3);
111
+ a[0] = e0;
112
+ a[1] = e1;
113
+ a[2] = e2;
114
+ uint256[] memory b = new uint256[](3);
115
+ b[0] = e0;
116
+ b[1] = e1;
117
+ b[2] = e2;
118
+
119
+ t._assertEq(a, b, EXPECT_PASS);
120
+ }
121
+
122
+ function testAssertEq_IntArr_Pass(int256 e0, int256 e1, int256 e2) public {
123
+ int256[] memory a = new int256[](3);
124
+ a[0] = e0;
125
+ a[1] = e1;
126
+ a[2] = e2;
127
+ int256[] memory b = new int256[](3);
128
+ b[0] = e0;
129
+ b[1] = e1;
130
+ b[2] = e2;
131
+
132
+ t._assertEq(a, b, EXPECT_PASS);
133
+ }
134
+
135
+ function testAssertEq_AddressArr_Pass(address e0, address e1, address e2) public {
136
+ address[] memory a = new address[](3);
137
+ a[0] = e0;
138
+ a[1] = e1;
139
+ a[2] = e2;
140
+ address[] memory b = new address[](3);
141
+ b[0] = e0;
142
+ b[1] = e1;
143
+ b[2] = e2;
144
+
145
+ t._assertEq(a, b, EXPECT_PASS);
146
+ }
147
+
148
+ function testAssertEq_UintArr_FailEl(uint256 e1) public {
149
+ vm.assume(e1 != 0);
150
+ uint256[] memory a = new uint256[](3);
151
+ uint256[] memory b = new uint256[](3);
152
+ b[1] = e1;
153
+
154
+ vm.expectEmit(false, false, false, true);
155
+ emit log("Error: a == b not satisfied [uint[]]");
156
+ t._assertEq(a, b, EXPECT_FAIL);
157
+ }
158
+
159
+ function testAssertEq_IntArr_FailEl(int256 e1) public {
160
+ vm.assume(e1 != 0);
161
+ int256[] memory a = new int256[](3);
162
+ int256[] memory b = new int256[](3);
163
+ b[1] = e1;
164
+
165
+ vm.expectEmit(false, false, false, true);
166
+ emit log("Error: a == b not satisfied [int[]]");
167
+ t._assertEq(a, b, EXPECT_FAIL);
168
+ }
169
+
170
+
171
+ function testAssertEq_AddressArr_FailEl(address e1) public {
172
+ vm.assume(e1 != address(0));
173
+ address[] memory a = new address[](3);
174
+ address[] memory b = new address[](3);
175
+ b[1] = e1;
176
+
177
+ vm.expectEmit(false, false, false, true);
178
+ emit log("Error: a == b not satisfied [address[]]");
179
+ t._assertEq(a, b, EXPECT_FAIL);
180
+ }
181
+
182
+ function testAssertEq_UintArrErr_FailEl(uint256 e1) public {
183
+ vm.assume(e1 != 0);
184
+ uint256[] memory a = new uint256[](3);
185
+ uint256[] memory b = new uint256[](3);
186
+ b[1] = e1;
187
+
188
+ vm.expectEmit(false, false, false, true);
189
+ emit log_named_string("Error", CUSTOM_ERROR);
190
+ vm.expectEmit(false, false, false, true);
191
+ emit log("Error: a == b not satisfied [uint[]]");
192
+ t._assertEq(a, b, CUSTOM_ERROR, EXPECT_FAIL);
193
+ }
194
+
195
+ function testAssertEq_IntArrErr_FailEl(int256 e1) public {
196
+ vm.assume(e1 != 0);
197
+ int256[] memory a = new int256[](3);
198
+ int256[] memory b = new int256[](3);
199
+ b[1] = e1;
200
+
201
+ vm.expectEmit(false, false, false, true);
202
+ emit log_named_string("Error", CUSTOM_ERROR);
203
+ vm.expectEmit(false, false, false, true);
204
+ emit log("Error: a == b not satisfied [int[]]");
205
+ t._assertEq(a, b, CUSTOM_ERROR, EXPECT_FAIL);
206
+ }
207
+
208
+
209
+ function testAssertEq_AddressArrErr_FailEl(address e1) public {
210
+ vm.assume(e1 != address(0));
211
+ address[] memory a = new address[](3);
212
+ address[] memory b = new address[](3);
213
+ b[1] = e1;
214
+
215
+ vm.expectEmit(false, false, false, true);
216
+ emit log_named_string("Error", CUSTOM_ERROR);
217
+ vm.expectEmit(false, false, false, true);
218
+ emit log("Error: a == b not satisfied [address[]]");
219
+ t._assertEq(a, b, CUSTOM_ERROR, EXPECT_FAIL);
220
+ }
221
+
222
+ function testAssertEq_UintArr_FailLen(uint256 lenA, uint256 lenB) public {
223
+ vm.assume(lenA != lenB);
224
+ vm.assume(lenA <= 10000);
225
+ vm.assume(lenB <= 10000);
226
+ uint256[] memory a = new uint256[](lenA);
227
+ uint256[] memory b = new uint256[](lenB);
228
+
229
+ vm.expectEmit(false, false, false, true);
230
+ emit log("Error: a == b not satisfied [uint[]]");
231
+ t._assertEq(a, b, EXPECT_FAIL);
232
+ }
233
+
234
+ function testAssertEq_IntArr_FailLen(uint256 lenA, uint256 lenB) public {
235
+ vm.assume(lenA != lenB);
236
+ vm.assume(lenA <= 10000);
237
+ vm.assume(lenB <= 10000);
238
+ int256[] memory a = new int256[](lenA);
239
+ int256[] memory b = new int256[](lenB);
240
+
241
+ vm.expectEmit(false, false, false, true);
242
+ emit log("Error: a == b not satisfied [int[]]");
243
+ t._assertEq(a, b, EXPECT_FAIL);
244
+ }
245
+
246
+ function testAssertEq_AddressArr_FailLen(uint256 lenA, uint256 lenB) public {
247
+ vm.assume(lenA != lenB);
248
+ vm.assume(lenA <= 10000);
249
+ vm.assume(lenB <= 10000);
250
+ address[] memory a = new address[](lenA);
251
+ address[] memory b = new address[](lenB);
252
+
253
+ vm.expectEmit(false, false, false, true);
254
+ emit log("Error: a == b not satisfied [address[]]");
255
+ t._assertEq(a, b, EXPECT_FAIL);
256
+ }
257
+
258
+ function testAssertEq_UintArrErr_FailLen(uint256 lenA, uint256 lenB) public {
259
+ vm.assume(lenA != lenB);
260
+ vm.assume(lenA <= 10000);
261
+ vm.assume(lenB <= 10000);
262
+ uint256[] memory a = new uint256[](lenA);
263
+ uint256[] memory b = new uint256[](lenB);
264
+
265
+ vm.expectEmit(false, false, false, true);
266
+ emit log_named_string("Error", CUSTOM_ERROR);
267
+ vm.expectEmit(false, false, false, true);
268
+ emit log("Error: a == b not satisfied [uint[]]");
269
+ t._assertEq(a, b, CUSTOM_ERROR, EXPECT_FAIL);
270
+ }
271
+
272
+ function testAssertEq_IntArrErr_FailLen(uint256 lenA, uint256 lenB) public {
273
+ vm.assume(lenA != lenB);
274
+ vm.assume(lenA <= 10000);
275
+ vm.assume(lenB <= 10000);
276
+ int256[] memory a = new int256[](lenA);
277
+ int256[] memory b = new int256[](lenB);
278
+
279
+ vm.expectEmit(false, false, false, true);
280
+ emit log_named_string("Error", CUSTOM_ERROR);
281
+ vm.expectEmit(false, false, false, true);
282
+ emit log("Error: a == b not satisfied [int[]]");
283
+ t._assertEq(a, b, CUSTOM_ERROR, EXPECT_FAIL);
284
+ }
285
+
286
+ function testAssertEq_AddressArrErr_FailLen(uint256 lenA, uint256 lenB) public {
287
+ vm.assume(lenA != lenB);
288
+ vm.assume(lenA <= 10000);
289
+ vm.assume(lenB <= 10000);
290
+ address[] memory a = new address[](lenA);
291
+ address[] memory b = new address[](lenB);
292
+
293
+ vm.expectEmit(false, false, false, true);
294
+ emit log_named_string("Error", CUSTOM_ERROR);
295
+ vm.expectEmit(false, false, false, true);
296
+ emit log("Error: a == b not satisfied [address[]]");
297
+ t._assertEq(a, b, CUSTOM_ERROR, EXPECT_FAIL);
298
+ }
299
+
300
+ /*//////////////////////////////////////////////////////////////////////////
301
+ APPROX_EQ_ABS(UINT)
302
+ //////////////////////////////////////////////////////////////////////////*/
303
+
304
+ function testAssertApproxEqAbs_Uint_Pass(uint256 a, uint256 b, uint256 maxDelta) external {
305
+ vm.assume(stdMath.delta(a, b) <= maxDelta);
306
+
307
+ t._assertApproxEqAbs(a, b, maxDelta, EXPECT_PASS);
308
+ }
309
+
310
+ function testAssertApproxEqAbs_Uint_Fail(uint256 a, uint256 b, uint256 maxDelta) external {
311
+ vm.assume(stdMath.delta(a, b) > maxDelta);
312
+
313
+ vm.expectEmit(false, false, false, true);
314
+ emit log("Error: a ~= b not satisfied [uint]");
315
+ t._assertApproxEqAbs(a, b, maxDelta, EXPECT_FAIL);
316
+ }
317
+
318
+ function testAssertApproxEqAbs_UintErr_Pass(uint256 a, uint256 b, uint256 maxDelta) external {
319
+ vm.assume(stdMath.delta(a, b) <= maxDelta);
320
+
321
+ t._assertApproxEqAbs(a, b, maxDelta, CUSTOM_ERROR, EXPECT_PASS);
322
+ }
323
+
324
+ function testAssertApproxEqAbs_UintErr_Fail(uint256 a, uint256 b, uint256 maxDelta) external {
325
+ vm.assume(stdMath.delta(a, b) > maxDelta);
326
+
327
+ vm.expectEmit(false, false, false, true);
328
+ emit log_named_string("Error", CUSTOM_ERROR);
329
+ t._assertApproxEqAbs(a, b, maxDelta, CUSTOM_ERROR, EXPECT_FAIL);
330
+ }
331
+
332
+ /*//////////////////////////////////////////////////////////////////////////
333
+ APPROX_EQ_ABS(INT)
334
+ //////////////////////////////////////////////////////////////////////////*/
335
+
336
+ function testAssertApproxEqAbs_Int_Pass(int256 a, int256 b, uint256 maxDelta) external {
337
+ vm.assume(stdMath.delta(a, b) <= maxDelta);
338
+
339
+ t._assertApproxEqAbs(a, b, maxDelta, EXPECT_PASS);
340
+ }
341
+
342
+ function testAssertApproxEqAbs_Int_Fail(int256 a, int256 b, uint256 maxDelta) external {
343
+ vm.assume(stdMath.delta(a, b) > maxDelta);
344
+
345
+ vm.expectEmit(false, false, false, true);
346
+ emit log("Error: a ~= b not satisfied [int]");
347
+ t._assertApproxEqAbs(a, b, maxDelta, EXPECT_FAIL);
348
+ }
349
+
350
+ function testAssertApproxEqAbs_IntErr_Pass(int256 a, int256 b, uint256 maxDelta) external {
351
+ vm.assume(stdMath.delta(a, b) <= maxDelta);
352
+
353
+ t._assertApproxEqAbs(a, b, maxDelta, CUSTOM_ERROR, EXPECT_PASS);
354
+ }
355
+
356
+ function testAssertApproxEqAbs_IntErr_Fail(int256 a, int256 b, uint256 maxDelta) external {
357
+ vm.assume(stdMath.delta(a, b) > maxDelta);
358
+
359
+ vm.expectEmit(false, false, false, true);
360
+ emit log_named_string("Error", CUSTOM_ERROR);
361
+ t._assertApproxEqAbs(a, b, maxDelta, CUSTOM_ERROR, EXPECT_FAIL);
362
+ }
363
+
364
+ /*//////////////////////////////////////////////////////////////////////////
365
+ APPROX_EQ_REL(UINT)
366
+ //////////////////////////////////////////////////////////////////////////*/
367
+
368
+ function testAssertApproxEqRel_Uint_Pass(uint256 a, uint256 b, uint256 maxPercentDelta) external {
369
+ vm.assume(a < type(uint128).max && b < type(uint128).max && b != 0);
370
+ vm.assume(stdMath.percentDelta(a, b) <= maxPercentDelta);
371
+
372
+ t._assertApproxEqRel(a, b, maxPercentDelta, EXPECT_PASS);
373
+ }
374
+
375
+ function testAssertApproxEqRel_Uint_Fail(uint256 a, uint256 b, uint256 maxPercentDelta) external {
376
+ vm.assume(a < type(uint128).max && b < type(uint128).max && b != 0);
377
+ vm.assume(stdMath.percentDelta(a, b) > maxPercentDelta);
378
+
379
+ vm.expectEmit(false, false, false, true);
380
+ emit log("Error: a ~= b not satisfied [uint]");
381
+ t._assertApproxEqRel(a, b, maxPercentDelta, EXPECT_FAIL);
382
+ }
383
+
384
+ function testAssertApproxEqRel_UintErr_Pass(uint256 a, uint256 b, uint256 maxPercentDelta) external {
385
+ vm.assume(a < type(uint128).max && b < type(uint128).max && b != 0);
386
+ vm.assume(stdMath.percentDelta(a, b) <= maxPercentDelta);
387
+
388
+ t._assertApproxEqRel(a, b, maxPercentDelta, CUSTOM_ERROR, EXPECT_PASS);
389
+ }
390
+
391
+ function testAssertApproxEqRel_UintErr_Fail(uint256 a, uint256 b, uint256 maxPercentDelta) external {
392
+ vm.assume(a < type(uint128).max && b < type(uint128).max && b != 0);
393
+ vm.assume(stdMath.percentDelta(a, b) > maxPercentDelta);
394
+
395
+ vm.expectEmit(false, false, false, true);
396
+ emit log_named_string("Error", CUSTOM_ERROR);
397
+ t._assertApproxEqRel(a, b, maxPercentDelta, CUSTOM_ERROR, EXPECT_FAIL);
398
+ }
399
+
400
+ /*//////////////////////////////////////////////////////////////////////////
401
+ APPROX_EQ_REL(INT)
402
+ //////////////////////////////////////////////////////////////////////////*/
403
+
404
+ function testAssertApproxEqRel_Int_Pass(int128 a, int128 b, uint128 maxPercentDelta) external {
405
+ vm.assume(b != 0);
406
+ vm.assume(stdMath.percentDelta(a, b) <= maxPercentDelta);
407
+
408
+ t._assertApproxEqRel(a, b, maxPercentDelta, EXPECT_PASS);
409
+ }
410
+
411
+ function testAssertApproxEqRel_Int_Fail(int128 a, int128 b, uint128 maxPercentDelta) external {
412
+ vm.assume(b != 0);
413
+ vm.assume(stdMath.percentDelta(a, b) > maxPercentDelta);
414
+
415
+ vm.expectEmit(false, false, false, true);
416
+ emit log("Error: a ~= b not satisfied [int]");
417
+ t._assertApproxEqRel(a, b, maxPercentDelta, EXPECT_FAIL);
418
+ }
419
+
420
+ function testAssertApproxEqRel_IntErr_Pass(int128 a, int128 b, uint128 maxPercentDelta) external {
421
+ vm.assume(b != 0);
422
+ vm.assume(stdMath.percentDelta(a, b) <= maxPercentDelta);
423
+
424
+ t._assertApproxEqRel(a, b, maxPercentDelta, CUSTOM_ERROR, EXPECT_PASS);
425
+ }
426
+
427
+ function testAssertApproxEqRel_IntErr_Fail(int128 a, int128 b, uint128 maxPercentDelta) external {
428
+ vm.assume(b != 0);
429
+ vm.assume(stdMath.percentDelta(a, b) > maxPercentDelta);
430
+
431
+ vm.expectEmit(false, false, false, true);
432
+ emit log_named_string("Error", CUSTOM_ERROR);
433
+ t._assertApproxEqRel(a, b, maxPercentDelta, CUSTOM_ERROR, EXPECT_FAIL);
434
+ }
435
+ }
436
+
437
+
438
+ contract TestTest is Test
439
+ {
440
+ modifier expectFailure(bool expectFail) {
441
+ bool preState = vm.load(HEVM_ADDRESS, bytes32("failed")) != bytes32(0x00);
442
+ _;
443
+ bool postState = vm.load(HEVM_ADDRESS, bytes32("failed")) != bytes32(0x00);
444
+
445
+ if (preState == true) {
446
+ return;
447
+ }
448
+
449
+ if (expectFail) {
450
+ require(postState == true, "expected failure not triggered");
451
+
452
+ // unwind the expected failure
453
+ vm.store(HEVM_ADDRESS, bytes32("failed"), bytes32(uint256(0x00)));
454
+ } else {
455
+ require(postState == false, "unexpected failure was triggered");
456
+ }
457
+ }
458
+
459
+ function _fail(string memory err) external expectFailure(true) {
460
+ fail(err);
461
+ }
462
+
463
+ function _assertFalse(bool data, bool expectFail) external expectFailure(expectFail) {
464
+ assertFalse(data);
465
+ }
466
+
467
+ function _assertFalse(bool data, string memory err, bool expectFail) external expectFailure(expectFail) {
468
+ assertFalse(data, err);
469
+ }
470
+
471
+ function _assertEq(bool a, bool b, bool expectFail) external expectFailure(expectFail) {
472
+ assertEq(a, b);
473
+ }
474
+
475
+ function _assertEq(bool a, bool b, string memory err, bool expectFail) external expectFailure(expectFail) {
476
+ assertEq(a, b, err);
477
+ }
478
+
479
+ function _assertEq(bytes memory a, bytes memory b, bool expectFail) external expectFailure(expectFail) {
480
+ assertEq(a, b);
481
+ }
482
+
483
+ function _assertEq(bytes memory a,
484
+ bytes memory b,
485
+ string memory err,
486
+ bool expectFail
487
+ ) external expectFailure(expectFail) {
488
+ assertEq(a, b, err);
489
+ }
490
+
491
+ function _assertEq(uint256[] memory a, uint256[] memory b, bool expectFail) external expectFailure(expectFail) {
492
+ assertEq(a, b);
493
+ }
494
+
495
+ function _assertEq(int256[] memory a, int256[] memory b, bool expectFail) external expectFailure(expectFail) {
496
+ assertEq(a, b);
497
+ }
498
+
499
+ function _assertEq(address[] memory a, address[] memory b, bool expectFail) external expectFailure(expectFail) {
500
+ assertEq(a, b);
501
+ }
502
+
503
+ function _assertEq(uint256[] memory a, uint256[] memory b, string memory err, bool expectFail) external expectFailure(expectFail) {
504
+ assertEq(a, b, err);
505
+ }
506
+
507
+ function _assertEq(int256[] memory a, int256[] memory b, string memory err, bool expectFail) external expectFailure(expectFail) {
508
+ assertEq(a, b, err);
509
+ }
510
+
511
+ function _assertEq(address[] memory a, address[] memory b, string memory err, bool expectFail) external expectFailure(expectFail) {
512
+ assertEq(a, b, err);
513
+ }
514
+
515
+
516
+ function _assertApproxEqAbs(
517
+ uint256 a,
518
+ uint256 b,
519
+ uint256 maxDelta,
520
+ bool expectFail
521
+ ) external expectFailure(expectFail) {
522
+ assertApproxEqAbs(a, b, maxDelta);
523
+ }
524
+
525
+ function _assertApproxEqAbs(
526
+ uint256 a,
527
+ uint256 b,
528
+ uint256 maxDelta,
529
+ string memory err,
530
+ bool expectFail
531
+ ) external expectFailure(expectFail) {
532
+ assertApproxEqAbs(a, b, maxDelta, err);
533
+ }
534
+
535
+ function _assertApproxEqAbs(
536
+ int256 a,
537
+ int256 b,
538
+ uint256 maxDelta,
539
+ bool expectFail
540
+ ) external expectFailure(expectFail) {
541
+ assertApproxEqAbs(a, b, maxDelta);
542
+ }
543
+
544
+ function _assertApproxEqAbs(
545
+ int256 a,
546
+ int256 b,
547
+ uint256 maxDelta,
548
+ string memory err,
549
+ bool expectFail
550
+ ) external expectFailure(expectFail) {
551
+ assertApproxEqAbs(a, b, maxDelta, err);
552
+ }
553
+
554
+ function _assertApproxEqRel(
555
+ uint256 a,
556
+ uint256 b,
557
+ uint256 maxPercentDelta,
558
+ bool expectFail
559
+ ) external expectFailure(expectFail) {
560
+ assertApproxEqRel(a, b, maxPercentDelta);
561
+ }
562
+
563
+ function _assertApproxEqRel(
564
+ uint256 a,
565
+ uint256 b,
566
+ uint256 maxPercentDelta,
567
+ string memory err,
568
+ bool expectFail
569
+ ) external expectFailure(expectFail) {
570
+ assertApproxEqRel(a, b, maxPercentDelta, err);
571
+ }
572
+
573
+ function _assertApproxEqRel(
574
+ int256 a,
575
+ int256 b,
576
+ uint256 maxPercentDelta,
577
+ bool expectFail
578
+ ) external expectFailure(expectFail) {
579
+ assertApproxEqRel(a, b, maxPercentDelta);
580
+ }
581
+
582
+ function _assertApproxEqRel(
583
+ int256 a,
584
+ int256 b,
585
+ uint256 maxPercentDelta,
586
+ string memory err,
587
+ bool expectFail
588
+ ) external expectFailure(expectFail) {
589
+ assertApproxEqRel(a, b, maxPercentDelta, err);
590
+ }
591
+ }