@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.
- package/.gitmodules +4 -0
- package/CHANGELOG.md +56 -0
- package/LICENSE +7 -0
- package/README.md +94 -0
- package/addressbook_logo.png +0 -0
- package/dist/AaveAddressBook.d.ts +17 -0
- package/dist/AaveAddressBook.js +20 -0
- package/dist/AaveV2Avalanche.d.ts +9 -0
- package/dist/AaveV2Avalanche.js +12 -0
- package/dist/AaveV2Ethereum.d.ts +9 -0
- package/dist/AaveV2Ethereum.js +12 -0
- package/dist/AaveV2EthereumAMM.d.ts +9 -0
- package/dist/AaveV2EthereumAMM.js +12 -0
- package/dist/AaveV2EthereumArc.d.ts +9 -0
- package/dist/AaveV2EthereumArc.js +12 -0
- package/dist/AaveV2Fuji.d.ts +9 -0
- package/dist/AaveV2Fuji.js +12 -0
- package/dist/AaveV2Mumbai.d.ts +9 -0
- package/dist/AaveV2Mumbai.js +12 -0
- package/dist/AaveV2Polygon.d.ts +9 -0
- package/dist/AaveV2Polygon.js +12 -0
- package/dist/AaveV3Arbitrum.d.ts +9 -0
- package/dist/AaveV3Arbitrum.js +12 -0
- package/dist/AaveV3Avalanche.d.ts +9 -0
- package/dist/AaveV3Avalanche.js +12 -0
- package/dist/AaveV3Fantom.d.ts +9 -0
- package/dist/AaveV3Fantom.js +12 -0
- package/dist/AaveV3FantomTestnet.d.ts +9 -0
- package/dist/AaveV3FantomTestnet.js +12 -0
- package/dist/AaveV3Fuji.d.ts +9 -0
- package/dist/AaveV3Fuji.js +12 -0
- package/dist/AaveV3Harmony.d.ts +9 -0
- package/dist/AaveV3Harmony.js +12 -0
- package/dist/AaveV3Mumbai.d.ts +9 -0
- package/dist/AaveV3Mumbai.js +12 -0
- package/dist/AaveV3Optimism.d.ts +9 -0
- package/dist/AaveV3Optimism.js +12 -0
- package/dist/AaveV3OptimismKovan.d.ts +9 -0
- package/dist/AaveV3OptimismKovan.js +12 -0
- package/dist/AaveV3Polygon.d.ts +9 -0
- package/dist/AaveV3Polygon.js +12 -0
- package/foundry.toml +8 -0
- package/lib/forge-std/.github/workflows/tests.yml +27 -0
- package/lib/forge-std/.gitmodules +3 -0
- package/lib/forge-std/LICENSE-APACHE +203 -0
- package/lib/forge-std/LICENSE-MIT +25 -0
- package/lib/forge-std/README.md +246 -0
- package/lib/forge-std/lib/ds-test/LICENSE +674 -0
- package/lib/forge-std/lib/ds-test/Makefile +14 -0
- package/lib/forge-std/lib/ds-test/default.nix +4 -0
- package/lib/forge-std/lib/ds-test/demo/demo.sol +222 -0
- package/lib/forge-std/lib/ds-test/src/test.sol +469 -0
- package/lib/forge-std/src/Script.sol +39 -0
- package/lib/forge-std/src/StdJson.sol +118 -0
- package/lib/forge-std/src/Test.sol +1134 -0
- package/lib/forge-std/src/Vm.sol +231 -0
- package/lib/forge-std/src/console.sol +1533 -0
- package/lib/forge-std/src/console2.sol +1538 -0
- package/lib/forge-std/src/test/Script.t.sol +12 -0
- package/lib/forge-std/src/test/StdAssertions.t.sol +591 -0
- package/lib/forge-std/src/test/StdCheats.t.sol +282 -0
- package/lib/forge-std/src/test/StdError.t.sol +124 -0
- package/lib/forge-std/src/test/StdMath.t.sol +200 -0
- package/lib/forge-std/src/test/StdStorage.t.sol +321 -0
- package/lib/forge-std/src/test/fixtures/broadcast.log.json +187 -0
- package/package.json +39 -0
- package/src/AaveAddressBook.sol +28 -0
- package/src/AaveAddressBookV2.sol +143 -0
- package/src/AaveAddressBookV2Testnet.sol +74 -0
- package/src/AaveAddressBookV3.sol +166 -0
- package/src/AaveAddressBookV3Testnet.sol +120 -0
- package/src/AaveGovernanceV2.sol +549 -0
- package/src/AaveV2.sol +931 -0
- package/src/AaveV2Avalanche.sol +35 -0
- package/src/AaveV2Ethereum.sol +36 -0
- package/src/AaveV2EthereumAMM.sol +36 -0
- package/src/AaveV2EthereumArc.sol +36 -0
- package/src/AaveV2Fuji.sol +35 -0
- package/src/AaveV2Mumbai.sol +35 -0
- package/src/AaveV2Polygon.sol +35 -0
- package/src/AaveV3.sol +2406 -0
- package/src/AaveV3Arbitrum.sol +34 -0
- package/src/AaveV3Avalanche.sol +34 -0
- package/src/AaveV3Fantom.sol +34 -0
- package/src/AaveV3FantomTestnet.sol +34 -0
- package/src/AaveV3Fuji.sol +34 -0
- package/src/AaveV3Harmony.sol +34 -0
- package/src/AaveV3HarmonyTestnet.sol +34 -0
- package/src/AaveV3Mumbai.sol +34 -0
- package/src/AaveV3Optimism.sol +34 -0
- package/src/AaveV3OptimismKovan.sol +34 -0
- package/src/AaveV3Polygon.sol +34 -0
- package/src/Common.sol +9 -0
- package/src/test/AaveV2Ethereum.t.sol +72 -0
- package/src/test/AaveV2Misfits.t.sol +33 -0
- package/src/test/AaveV3Avalanche.t.sol +65 -0
- package/src/ts/AaveAddressBook.ts +17 -0
- package/src/ts/AaveV2Avalanche.ts +11 -0
- package/src/ts/AaveV2Ethereum.ts +12 -0
- package/src/ts/AaveV2EthereumAMM.ts +12 -0
- package/src/ts/AaveV2EthereumArc.ts +12 -0
- package/src/ts/AaveV2Fuji.ts +11 -0
- package/src/ts/AaveV2Mumbai.ts +11 -0
- package/src/ts/AaveV2Polygon.ts +11 -0
- package/src/ts/AaveV3Arbitrum.ts +12 -0
- package/src/ts/AaveV3Avalanche.ts +12 -0
- package/src/ts/AaveV3Fantom.ts +12 -0
- package/src/ts/AaveV3FantomTestnet.ts +12 -0
- package/src/ts/AaveV3Fuji.ts +12 -0
- package/src/ts/AaveV3Harmony.ts +12 -0
- package/src/ts/AaveV3Mumbai.ts +12 -0
- package/src/ts/AaveV3Optimism.ts +12 -0
- package/src/ts/AaveV3OptimismKovan.ts +12 -0
- package/src/ts/AaveV3Polygon.ts +12 -0
- package/tsconfig.json +101 -0
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity >=0.7.0 <0.9.0;
|
|
3
|
+
|
|
4
|
+
import "../Test.sol";
|
|
5
|
+
import "../StdJson.sol";
|
|
6
|
+
|
|
7
|
+
contract StdCheatsTest is Test {
|
|
8
|
+
Bar test;
|
|
9
|
+
|
|
10
|
+
using stdJson for string;
|
|
11
|
+
|
|
12
|
+
function setUp() public {
|
|
13
|
+
test = new Bar();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function testSkip() public {
|
|
17
|
+
vm.warp(100);
|
|
18
|
+
skip(25);
|
|
19
|
+
assertEq(block.timestamp, 125);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function testRewind() public {
|
|
23
|
+
vm.warp(100);
|
|
24
|
+
rewind(25);
|
|
25
|
+
assertEq(block.timestamp, 75);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function testHoax() public {
|
|
29
|
+
hoax(address(1337));
|
|
30
|
+
test.bar{value: 100}(address(1337));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function testHoaxOrigin() public {
|
|
34
|
+
hoax(address(1337), address(1337));
|
|
35
|
+
test.origin{value: 100}(address(1337));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function testHoaxDifferentAddresses() public {
|
|
39
|
+
hoax(address(1337), address(7331));
|
|
40
|
+
test.origin{value: 100}(address(1337), address(7331));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function testStartHoax() public {
|
|
44
|
+
startHoax(address(1337));
|
|
45
|
+
test.bar{value: 100}(address(1337));
|
|
46
|
+
test.bar{value: 100}(address(1337));
|
|
47
|
+
vm.stopPrank();
|
|
48
|
+
test.bar(address(this));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function testStartHoaxOrigin() public {
|
|
52
|
+
startHoax(address(1337), address(1337));
|
|
53
|
+
test.origin{value: 100}(address(1337));
|
|
54
|
+
test.origin{value: 100}(address(1337));
|
|
55
|
+
vm.stopPrank();
|
|
56
|
+
test.bar(address(this));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function testChangePrank() public {
|
|
60
|
+
vm.startPrank(address(1337));
|
|
61
|
+
test.bar(address(1337));
|
|
62
|
+
changePrank(address(0xdead));
|
|
63
|
+
test.bar(address(0xdead));
|
|
64
|
+
changePrank(address(1337));
|
|
65
|
+
test.bar(address(1337));
|
|
66
|
+
vm.stopPrank();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function testMakeAddrEquivalence() public {
|
|
70
|
+
(address addr, ) = makeAddrAndKey("1337");
|
|
71
|
+
assertEq(makeAddr("1337"), addr);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function testMakeAddrSigning() public {
|
|
75
|
+
(address addr, uint256 key) = makeAddrAndKey("1337");
|
|
76
|
+
bytes32 hash = keccak256("some_message");
|
|
77
|
+
|
|
78
|
+
(uint8 v, bytes32 r, bytes32 s) = vm.sign(key, hash);
|
|
79
|
+
assertEq(ecrecover(hash, v, r, s), addr);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function testDeal() public {
|
|
83
|
+
deal(address(this), 1 ether);
|
|
84
|
+
assertEq(address(this).balance, 1 ether);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function testDealToken() public {
|
|
88
|
+
Bar barToken = new Bar();
|
|
89
|
+
address bar = address(barToken);
|
|
90
|
+
deal(bar, address(this), 10000e18);
|
|
91
|
+
assertEq(barToken.balanceOf(address(this)), 10000e18);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function testDealTokenAdjustTS() public {
|
|
95
|
+
Bar barToken = new Bar();
|
|
96
|
+
address bar = address(barToken);
|
|
97
|
+
deal(bar, address(this), 10000e18, true);
|
|
98
|
+
assertEq(barToken.balanceOf(address(this)), 10000e18);
|
|
99
|
+
assertEq(barToken.totalSupply(), 20000e18);
|
|
100
|
+
deal(bar, address(this), 0, true);
|
|
101
|
+
assertEq(barToken.balanceOf(address(this)), 0);
|
|
102
|
+
assertEq(barToken.totalSupply(), 10000e18);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function testBound() public {
|
|
106
|
+
assertEq(bound(5, 0, 4), 0);
|
|
107
|
+
assertEq(bound(0, 69, 69), 69);
|
|
108
|
+
assertEq(bound(0, 68, 69), 68);
|
|
109
|
+
assertEq(bound(10, 150, 190), 160);
|
|
110
|
+
assertEq(bound(300, 2800, 3200), 3100);
|
|
111
|
+
assertEq(bound(9999, 1337, 6666), 6006);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function testCannotBoundMaxLessThanMin() public {
|
|
115
|
+
vm.expectRevert(bytes("Test bound(uint256,uint256,uint256): Max is less than min."));
|
|
116
|
+
bound(5, 100, 10);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function testBound(
|
|
120
|
+
uint256 num,
|
|
121
|
+
uint256 min,
|
|
122
|
+
uint256 max
|
|
123
|
+
) public {
|
|
124
|
+
if (min > max) (min, max) = (max, min);
|
|
125
|
+
|
|
126
|
+
uint256 bounded = bound(num, min, max);
|
|
127
|
+
|
|
128
|
+
assertGe(bounded, min);
|
|
129
|
+
assertLe(bounded, max);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function testBoundUint256Max() public {
|
|
133
|
+
assertEq(bound(0, type(uint256).max - 1, type(uint256).max), type(uint256).max - 1);
|
|
134
|
+
assertEq(bound(1, type(uint256).max - 1, type(uint256).max), type(uint256).max);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function testCannotBoundMaxLessThanMin(
|
|
138
|
+
uint256 num,
|
|
139
|
+
uint256 min,
|
|
140
|
+
uint256 max
|
|
141
|
+
) public {
|
|
142
|
+
vm.assume(min > max);
|
|
143
|
+
vm.expectRevert(bytes("Test bound(uint256,uint256,uint256): Max is less than min."));
|
|
144
|
+
bound(num, min, max);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function testDeployCode() public {
|
|
148
|
+
address deployed = deployCode("StdCheats.t.sol:StdCheatsTest", bytes(""));
|
|
149
|
+
assertEq(string(getCode(deployed)), string(getCode(address(this))));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function testDeployCodeNoArgs() public {
|
|
153
|
+
address deployed = deployCode("StdCheats.t.sol:StdCheatsTest");
|
|
154
|
+
assertEq(string(getCode(deployed)), string(getCode(address(this))));
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// We need that payable constructor in order to send ETH on construction
|
|
158
|
+
constructor() payable {}
|
|
159
|
+
|
|
160
|
+
function testDeployCodeVal() public {
|
|
161
|
+
address deployed = deployCode("StdCheats.t.sol:StdCheatsTest", bytes(""), 1 ether);
|
|
162
|
+
assertEq(string(getCode(deployed)), string(getCode(address(this))));
|
|
163
|
+
assertEq(deployed.balance, 1 ether);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function testDeployCodeValNoArgs() public {
|
|
167
|
+
address deployed = deployCode("StdCheats.t.sol:StdCheatsTest", 1 ether);
|
|
168
|
+
assertEq(string(getCode(deployed)), string(getCode(address(this))));
|
|
169
|
+
assertEq(deployed.balance, 1 ether);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// We need this so we can call "this.deployCode" rather than "deployCode" directly
|
|
173
|
+
function deployCodeHelper(string memory what) external {
|
|
174
|
+
deployCode(what);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function testDeployCodeFail() public {
|
|
178
|
+
vm.expectRevert(bytes("Test deployCode(string): Deployment failed."));
|
|
179
|
+
this.deployCodeHelper("StdCheats.t.sol:RevertingContract");
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function getCode(address who) internal view returns (bytes memory o_code) {
|
|
183
|
+
/// @solidity memory-safe-assembly
|
|
184
|
+
assembly {
|
|
185
|
+
// retrieve the size of the code, this needs assembly
|
|
186
|
+
let size := extcodesize(who)
|
|
187
|
+
// allocate output byte array - this could also be done without assembly
|
|
188
|
+
// by using o_code = new bytes(size)
|
|
189
|
+
o_code := mload(0x40)
|
|
190
|
+
// new "memory end" including padding
|
|
191
|
+
mstore(0x40, add(o_code, and(add(add(size, 0x20), 0x1f), not(0x1f))))
|
|
192
|
+
// store length in memory
|
|
193
|
+
mstore(o_code, size)
|
|
194
|
+
// actually retrieve the code, this needs assembly
|
|
195
|
+
extcodecopy(who, add(o_code, 0x20), 0, size)
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function testBytesToUint() public {
|
|
200
|
+
assertEq(3, bytesToUint(hex'03'));
|
|
201
|
+
assertEq(2, bytesToUint(hex'02'));
|
|
202
|
+
assertEq(255, bytesToUint(hex'ff'));
|
|
203
|
+
assertEq(29625, bytesToUint(hex'73b9'));
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function testParseJsonTxDetail() public {
|
|
207
|
+
string memory root = vm.projectRoot();
|
|
208
|
+
string memory path = string.concat(root, "/src/test/fixtures/broadcast.log.json");
|
|
209
|
+
string memory json = vm.readFile(path);
|
|
210
|
+
bytes memory transactionDetails = json.parseRaw(".transactions[0].tx");
|
|
211
|
+
RawTx1559Detail memory rawTxDetail = abi.decode(transactionDetails, (RawTx1559Detail));
|
|
212
|
+
Tx1559Detail memory txDetail = rawToConvertedEIP1559Detail(rawTxDetail);
|
|
213
|
+
assertEq(txDetail.from, 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266);
|
|
214
|
+
assertEq(txDetail.to, 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512);
|
|
215
|
+
assertEq(txDetail.data, hex'23e99187000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000013370000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000004');
|
|
216
|
+
assertEq(txDetail.nonce, 3);
|
|
217
|
+
assertEq(txDetail.txType, 2);
|
|
218
|
+
assertEq(txDetail.gas, 29625);
|
|
219
|
+
assertEq(txDetail.value, 0);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function testReadEIP1559Transaction() public {
|
|
223
|
+
string memory root = vm.projectRoot();
|
|
224
|
+
string memory path = string.concat(root, "/src/test/fixtures/broadcast.log.json");
|
|
225
|
+
uint256 index = 0;
|
|
226
|
+
Tx1559 memory transaction = readTx1559(path, index);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function testReadEIP1559Transactions() public {
|
|
230
|
+
string memory root = vm.projectRoot();
|
|
231
|
+
string memory path = string.concat(root, "/src/test/fixtures/broadcast.log.json");
|
|
232
|
+
Tx1559[] memory transactions = readTx1559s(path);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function testReadReceipt() public {
|
|
236
|
+
string memory root = vm.projectRoot();
|
|
237
|
+
string memory path = string.concat(root, "/src/test/fixtures/broadcast.log.json");
|
|
238
|
+
uint index = 5;
|
|
239
|
+
Receipt memory receipt = readReceipt(path, index);
|
|
240
|
+
assertEq(receipt.logsBloom,
|
|
241
|
+
hex"00000000000800000000000000000010000000000000000000000000000180000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100");
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function testReadReceipts() public {
|
|
245
|
+
string memory root = vm.projectRoot();
|
|
246
|
+
string memory path = string.concat(root, "/src/test/fixtures/broadcast.log.json");
|
|
247
|
+
Receipt[] memory receipts = readReceipts(path);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
contract Bar {
|
|
253
|
+
constructor() {
|
|
254
|
+
/// `DEAL` STDCHEAT
|
|
255
|
+
totalSupply = 10000e18;
|
|
256
|
+
balanceOf[address(this)] = totalSupply;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/// `HOAX` STDCHEATS
|
|
260
|
+
function bar(address expectedSender) public payable {
|
|
261
|
+
require(msg.sender == expectedSender, "!prank");
|
|
262
|
+
}
|
|
263
|
+
function origin(address expectedSender) public payable {
|
|
264
|
+
require(msg.sender == expectedSender, "!prank");
|
|
265
|
+
require(tx.origin == expectedSender, "!prank");
|
|
266
|
+
}
|
|
267
|
+
function origin(address expectedSender, address expectedOrigin) public payable {
|
|
268
|
+
require(msg.sender == expectedSender, "!prank");
|
|
269
|
+
require(tx.origin == expectedOrigin, "!prank");
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/// `DEAL` STDCHEAT
|
|
273
|
+
mapping (address => uint256) public balanceOf;
|
|
274
|
+
uint256 public totalSupply;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
contract RevertingContract {
|
|
278
|
+
constructor() {
|
|
279
|
+
revert();
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity >=0.8.10 <0.9.0;
|
|
3
|
+
|
|
4
|
+
import "../Test.sol";
|
|
5
|
+
|
|
6
|
+
contract StdErrorsTest is Test {
|
|
7
|
+
ErrorsTest test;
|
|
8
|
+
|
|
9
|
+
function setUp() public {
|
|
10
|
+
test = new ErrorsTest();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function testExpectAssertion() public {
|
|
14
|
+
vm.expectRevert(stdError.assertionError);
|
|
15
|
+
test.assertionError();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function testExpectArithmetic() public {
|
|
19
|
+
vm.expectRevert(stdError.arithmeticError);
|
|
20
|
+
test.arithmeticError(10);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function testExpectDiv() public {
|
|
24
|
+
vm.expectRevert(stdError.divisionError);
|
|
25
|
+
test.divError(0);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function testExpectMod() public {
|
|
29
|
+
vm.expectRevert(stdError.divisionError);
|
|
30
|
+
test.modError(0);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function testExpectEnum() public {
|
|
34
|
+
vm.expectRevert(stdError.enumConversionError);
|
|
35
|
+
test.enumConversion(1);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function testExpectEncodeStg() public {
|
|
39
|
+
vm.expectRevert(stdError.encodeStorageError);
|
|
40
|
+
test.encodeStgError();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function testExpectPop() public {
|
|
44
|
+
vm.expectRevert(stdError.popError);
|
|
45
|
+
test.pop();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function testExpectOOB() public {
|
|
49
|
+
vm.expectRevert(stdError.indexOOBError);
|
|
50
|
+
test.indexOOBError(1);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function testExpectMem() public {
|
|
54
|
+
vm.expectRevert(stdError.memOverflowError);
|
|
55
|
+
test.mem();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function testExpectIntern() public {
|
|
59
|
+
vm.expectRevert(stdError.zeroVarError);
|
|
60
|
+
test.intern();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function testExpectLowLvl() public {
|
|
64
|
+
vm.expectRevert(stdError.lowLevelError);
|
|
65
|
+
test.someArr(0);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
contract ErrorsTest {
|
|
70
|
+
enum T {
|
|
71
|
+
T1
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
uint256[] public someArr;
|
|
75
|
+
bytes someBytes;
|
|
76
|
+
|
|
77
|
+
function assertionError() public pure {
|
|
78
|
+
assert(false);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function arithmeticError(uint256 a) public pure {
|
|
82
|
+
a -= 100;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function divError(uint256 a) public pure {
|
|
86
|
+
100 / a;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function modError(uint256 a) public pure {
|
|
90
|
+
100 % a;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function enumConversion(uint256 a) public pure {
|
|
94
|
+
T(a);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function encodeStgError() public {
|
|
98
|
+
/// @solidity memory-safe-assembly
|
|
99
|
+
assembly {
|
|
100
|
+
sstore(someBytes.slot, 1)
|
|
101
|
+
}
|
|
102
|
+
keccak256(someBytes);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function pop() public {
|
|
106
|
+
someArr.pop();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function indexOOBError(uint256 a) public pure {
|
|
110
|
+
uint256[] memory t = new uint256[](0);
|
|
111
|
+
t[a];
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function mem() public pure {
|
|
115
|
+
uint256 l = 2**256 / 32;
|
|
116
|
+
new uint256[](l);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function intern() public returns (uint256) {
|
|
120
|
+
function(uint256) internal returns (uint256) x;
|
|
121
|
+
x(2);
|
|
122
|
+
return 7;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity >=0.8.0 <0.9.0;
|
|
3
|
+
|
|
4
|
+
import "../Test.sol";
|
|
5
|
+
|
|
6
|
+
contract StdMathTest is Test
|
|
7
|
+
{
|
|
8
|
+
function testGetAbs() external {
|
|
9
|
+
assertEq(stdMath.abs(-50), 50);
|
|
10
|
+
assertEq(stdMath.abs(50), 50);
|
|
11
|
+
assertEq(stdMath.abs(-1337), 1337);
|
|
12
|
+
assertEq(stdMath.abs(0), 0);
|
|
13
|
+
|
|
14
|
+
assertEq(stdMath.abs(type(int256).min), (type(uint256).max >> 1) + 1);
|
|
15
|
+
assertEq(stdMath.abs(type(int256).max), (type(uint256).max >> 1));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function testGetAbs_Fuzz(int256 a) external {
|
|
19
|
+
uint256 manualAbs = getAbs(a);
|
|
20
|
+
|
|
21
|
+
uint256 abs = stdMath.abs(a);
|
|
22
|
+
|
|
23
|
+
assertEq(abs, manualAbs);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function testGetDelta_Uint() external {
|
|
27
|
+
assertEq(stdMath.delta(uint256(0), uint256(0)), 0);
|
|
28
|
+
assertEq(stdMath.delta(uint256(0), uint256(1337)), 1337);
|
|
29
|
+
assertEq(stdMath.delta(uint256(0), type(uint64).max), type(uint64).max);
|
|
30
|
+
assertEq(stdMath.delta(uint256(0), type(uint128).max), type(uint128).max);
|
|
31
|
+
assertEq(stdMath.delta(uint256(0), type(uint256).max), type(uint256).max);
|
|
32
|
+
|
|
33
|
+
assertEq(stdMath.delta(0, uint256(0)), 0);
|
|
34
|
+
assertEq(stdMath.delta(1337, uint256(0)), 1337);
|
|
35
|
+
assertEq(stdMath.delta(type(uint64).max, uint256(0)), type(uint64).max);
|
|
36
|
+
assertEq(stdMath.delta(type(uint128).max, uint256(0)), type(uint128).max);
|
|
37
|
+
assertEq(stdMath.delta(type(uint256).max, uint256(0)), type(uint256).max);
|
|
38
|
+
|
|
39
|
+
assertEq(stdMath.delta(1337, uint256(1337)), 0);
|
|
40
|
+
assertEq(stdMath.delta(type(uint256).max, type(uint256).max), 0);
|
|
41
|
+
assertEq(stdMath.delta(5000, uint256(1250)), 3750);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function testGetDelta_Uint_Fuzz(uint256 a, uint256 b) external {
|
|
45
|
+
uint256 manualDelta;
|
|
46
|
+
if (a > b) {
|
|
47
|
+
manualDelta = a - b;
|
|
48
|
+
} else {
|
|
49
|
+
manualDelta = b - a;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
uint256 delta = stdMath.delta(a, b);
|
|
53
|
+
|
|
54
|
+
assertEq(delta, manualDelta);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function testGetDelta_Int() external {
|
|
58
|
+
assertEq(stdMath.delta(int256(0), int256(0)), 0);
|
|
59
|
+
assertEq(stdMath.delta(int256(0), int256(1337)), 1337);
|
|
60
|
+
assertEq(stdMath.delta(int256(0), type(int64).max), type(uint64).max >> 1);
|
|
61
|
+
assertEq(stdMath.delta(int256(0), type(int128).max), type(uint128).max >> 1);
|
|
62
|
+
assertEq(stdMath.delta(int256(0), type(int256).max), type(uint256).max >> 1);
|
|
63
|
+
|
|
64
|
+
assertEq(stdMath.delta(0, int256(0)), 0);
|
|
65
|
+
assertEq(stdMath.delta(1337, int256(0)), 1337);
|
|
66
|
+
assertEq(stdMath.delta(type(int64).max, int256(0)), type(uint64).max >> 1);
|
|
67
|
+
assertEq(stdMath.delta(type(int128).max, int256(0)), type(uint128).max >> 1);
|
|
68
|
+
assertEq(stdMath.delta(type(int256).max, int256(0)), type(uint256).max >> 1);
|
|
69
|
+
|
|
70
|
+
assertEq(stdMath.delta(-0, int256(0)), 0);
|
|
71
|
+
assertEq(stdMath.delta(-1337, int256(0)), 1337);
|
|
72
|
+
assertEq(stdMath.delta(type(int64).min, int256(0)), (type(uint64).max >> 1) + 1);
|
|
73
|
+
assertEq(stdMath.delta(type(int128).min, int256(0)), (type(uint128).max >> 1) + 1);
|
|
74
|
+
assertEq(stdMath.delta(type(int256).min, int256(0)), (type(uint256).max >> 1) + 1);
|
|
75
|
+
|
|
76
|
+
assertEq(stdMath.delta(int256(0), -0), 0);
|
|
77
|
+
assertEq(stdMath.delta(int256(0), -1337), 1337);
|
|
78
|
+
assertEq(stdMath.delta(int256(0), type(int64).min), (type(uint64).max >> 1) + 1);
|
|
79
|
+
assertEq(stdMath.delta(int256(0), type(int128).min), (type(uint128).max >> 1) + 1);
|
|
80
|
+
assertEq(stdMath.delta(int256(0), type(int256).min), (type(uint256).max >> 1) + 1);
|
|
81
|
+
|
|
82
|
+
assertEq(stdMath.delta(1337, int256(1337)), 0);
|
|
83
|
+
assertEq(stdMath.delta(type(int256).max, type(int256).max), 0);
|
|
84
|
+
assertEq(stdMath.delta(type(int256).min, type(int256).min), 0);
|
|
85
|
+
assertEq(stdMath.delta(type(int256).min, type(int256).max), type(uint256).max);
|
|
86
|
+
assertEq(stdMath.delta(5000, int256(1250)), 3750);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function testGetDelta_Int_Fuzz(int256 a, int256 b) external {
|
|
90
|
+
uint256 absA = getAbs(a);
|
|
91
|
+
uint256 absB = getAbs(b);
|
|
92
|
+
uint256 absDelta = absA > absB
|
|
93
|
+
? absA - absB
|
|
94
|
+
: absB - absA;
|
|
95
|
+
|
|
96
|
+
uint256 manualDelta;
|
|
97
|
+
if ((a >= 0 && b >= 0) || (a < 0 && b < 0)) {
|
|
98
|
+
manualDelta = absDelta;
|
|
99
|
+
}
|
|
100
|
+
// (a < 0 && b >= 0) || (a >= 0 && b < 0)
|
|
101
|
+
else {
|
|
102
|
+
manualDelta = absA + absB;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
uint256 delta = stdMath.delta(a, b);
|
|
106
|
+
|
|
107
|
+
assertEq(delta, manualDelta);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function testGetPercentDelta_Uint() external {
|
|
111
|
+
assertEq(stdMath.percentDelta(uint256(0), uint256(1337)), 1e18);
|
|
112
|
+
assertEq(stdMath.percentDelta(uint256(0), type(uint64).max), 1e18);
|
|
113
|
+
assertEq(stdMath.percentDelta(uint256(0), type(uint128).max), 1e18);
|
|
114
|
+
assertEq(stdMath.percentDelta(uint256(0), type(uint192).max), 1e18);
|
|
115
|
+
|
|
116
|
+
assertEq(stdMath.percentDelta(1337, uint256(1337)), 0);
|
|
117
|
+
assertEq(stdMath.percentDelta(type(uint192).max, type(uint192).max), 0);
|
|
118
|
+
assertEq(stdMath.percentDelta(0, uint256(2500)), 1e18);
|
|
119
|
+
assertEq(stdMath.percentDelta(2500, uint256(2500)), 0);
|
|
120
|
+
assertEq(stdMath.percentDelta(5000, uint256(2500)), 1e18);
|
|
121
|
+
assertEq(stdMath.percentDelta(7500, uint256(2500)), 2e18);
|
|
122
|
+
|
|
123
|
+
vm.expectRevert(stdError.divisionError);
|
|
124
|
+
stdMath.percentDelta(uint256(1), 0);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function testGetPercentDelta_Uint_Fuzz(uint192 a, uint192 b) external {
|
|
128
|
+
vm.assume(b != 0);
|
|
129
|
+
uint256 manualDelta;
|
|
130
|
+
if (a > b) {
|
|
131
|
+
manualDelta = a - b;
|
|
132
|
+
} else {
|
|
133
|
+
manualDelta = b - a;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
uint256 manualPercentDelta = manualDelta * 1e18 / b;
|
|
137
|
+
uint256 percentDelta = stdMath.percentDelta(a, b);
|
|
138
|
+
|
|
139
|
+
assertEq(percentDelta, manualPercentDelta);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function testGetPercentDelta_Int() external {
|
|
143
|
+
assertEq(stdMath.percentDelta(int256(0), int256(1337)), 1e18);
|
|
144
|
+
assertEq(stdMath.percentDelta(int256(0), -1337), 1e18);
|
|
145
|
+
assertEq(stdMath.percentDelta(int256(0), type(int64).min), 1e18);
|
|
146
|
+
assertEq(stdMath.percentDelta(int256(0), type(int128).min), 1e18);
|
|
147
|
+
assertEq(stdMath.percentDelta(int256(0), type(int192).min), 1e18);
|
|
148
|
+
assertEq(stdMath.percentDelta(int256(0), type(int64).max), 1e18);
|
|
149
|
+
assertEq(stdMath.percentDelta(int256(0), type(int128).max), 1e18);
|
|
150
|
+
assertEq(stdMath.percentDelta(int256(0), type(int192).max), 1e18);
|
|
151
|
+
|
|
152
|
+
assertEq(stdMath.percentDelta(1337, int256(1337)), 0);
|
|
153
|
+
assertEq(stdMath.percentDelta(type(int192).max, type(int192).max), 0);
|
|
154
|
+
assertEq(stdMath.percentDelta(type(int192).min, type(int192).min), 0);
|
|
155
|
+
|
|
156
|
+
assertEq(stdMath.percentDelta(type(int192).min, type(int192).max), 2e18); // rounds the 1 wei diff down
|
|
157
|
+
assertEq(stdMath.percentDelta(type(int192).max, type(int192).min), 2e18 - 1); // rounds the 1 wei diff down
|
|
158
|
+
assertEq(stdMath.percentDelta(0, int256(2500)), 1e18);
|
|
159
|
+
assertEq(stdMath.percentDelta(2500, int256(2500)), 0);
|
|
160
|
+
assertEq(stdMath.percentDelta(5000, int256(2500)), 1e18);
|
|
161
|
+
assertEq(stdMath.percentDelta(7500, int256(2500)), 2e18);
|
|
162
|
+
|
|
163
|
+
vm.expectRevert(stdError.divisionError);
|
|
164
|
+
stdMath.percentDelta(int256(1), 0);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function testGetPercentDelta_Int_Fuzz(int192 a, int192 b) external {
|
|
168
|
+
vm.assume(b != 0);
|
|
169
|
+
uint256 absA = getAbs(a);
|
|
170
|
+
uint256 absB = getAbs(b);
|
|
171
|
+
uint256 absDelta = absA > absB
|
|
172
|
+
? absA - absB
|
|
173
|
+
: absB - absA;
|
|
174
|
+
|
|
175
|
+
uint256 manualDelta;
|
|
176
|
+
if ((a >= 0 && b >= 0) || (a < 0 && b < 0)) {
|
|
177
|
+
manualDelta = absDelta;
|
|
178
|
+
}
|
|
179
|
+
// (a < 0 && b >= 0) || (a >= 0 && b < 0)
|
|
180
|
+
else {
|
|
181
|
+
manualDelta = absA + absB;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
uint256 manualPercentDelta = manualDelta * 1e18 / absB;
|
|
185
|
+
uint256 percentDelta = stdMath.percentDelta(a, b);
|
|
186
|
+
|
|
187
|
+
assertEq(percentDelta, manualPercentDelta);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/*//////////////////////////////////////////////////////////////////////////
|
|
191
|
+
HELPERS
|
|
192
|
+
//////////////////////////////////////////////////////////////////////////*/
|
|
193
|
+
|
|
194
|
+
function getAbs(int256 a) private pure returns (uint256) {
|
|
195
|
+
if (a < 0)
|
|
196
|
+
return a == type(int256).min ? uint256(type(int256).max) + 1 : uint256(-a);
|
|
197
|
+
|
|
198
|
+
return uint256(a);
|
|
199
|
+
}
|
|
200
|
+
}
|