|
2 | 2 | pragma solidity ^0.8.0; |
3 | 3 |
|
4 | 4 | import "contracts/drop/DropERC721.sol"; |
| 5 | +import "@openzeppelin/contracts/utils/Strings.sol"; |
5 | 6 |
|
6 | 7 | // Test imports |
7 | 8 | import "../utils/BaseTest.sol"; |
8 | 9 |
|
9 | 10 | contract SubExploitContract is ERC721Holder, ERC1155Holder { |
10 | 11 | DropERC721 internal drop; |
11 | 12 | address payable internal master; |
| 13 | + // using Strings for uint256; |
12 | 14 |
|
13 | 15 | constructor(address _drop) { |
14 | 16 | drop = DropERC721(_drop); |
@@ -223,4 +225,123 @@ contract DropERC721Test is BaseTest { |
223 | 225 | 0 |
224 | 226 | ); |
225 | 227 | } |
| 228 | + |
| 229 | + /*/////////////////////////////////////////////////////////////// |
| 230 | + Miscellaneous |
| 231 | + //////////////////////////////////////////////////////////////*/ |
| 232 | + |
| 233 | + function test_revert_claim_claimQty(uint256 x) public { |
| 234 | + vm.assume(x != 0); |
| 235 | + vm.warp(1); |
| 236 | + |
| 237 | + address receiver = getActor(0); |
| 238 | + bytes32[] memory proofs = new bytes32[](0); |
| 239 | + |
| 240 | + DropERC721.ClaimCondition[] memory conditions = new DropERC721.ClaimCondition[](1); |
| 241 | + conditions[0].maxClaimableSupply = 500; |
| 242 | + conditions[0].quantityLimitPerTransaction = 100; |
| 243 | + conditions[0].waitTimeInSecondsBetweenClaims = type(uint256).max; |
| 244 | + |
| 245 | + vm.prank(deployer); |
| 246 | + drop.lazyMint(500, "ipfs://", bytes("")); |
| 247 | + |
| 248 | + vm.prank(deployer); |
| 249 | + drop.setClaimConditions(conditions, false); |
| 250 | + |
| 251 | + vm.prank(getActor(5), getActor(5)); |
| 252 | + vm.expectRevert("invalid quantity."); |
| 253 | + drop.claim(receiver, 200, address(0), 0, proofs, x); |
| 254 | + |
| 255 | + vm.prank(deployer); |
| 256 | + drop.setClaimConditions(conditions, true); |
| 257 | + |
| 258 | + vm.prank(getActor(5), getActor(5)); |
| 259 | + vm.expectRevert("invalid quantity."); |
| 260 | + drop.claim(receiver, 200, address(0), 0, proofs, x); |
| 261 | + } |
| 262 | + |
| 263 | + function test_claimCondition_merkleProof(uint256 x) public { |
| 264 | + vm.assume(x != 0 && x < 500); |
| 265 | + string[] memory inputs = new string[](3); |
| 266 | + |
| 267 | + inputs[0] = "node"; |
| 268 | + inputs[1] = "src/test/scripts/generateRoot.ts"; |
| 269 | + inputs[2] = Strings.toString(x); |
| 270 | + |
| 271 | + bytes memory result = vm.ffi(inputs); |
| 272 | + // revert(); |
| 273 | + bytes32 root = abi.decode(result, (bytes32)); |
| 274 | + |
| 275 | + inputs[1] = "src/test/scripts/getProof.ts"; |
| 276 | + result = vm.ffi(inputs); |
| 277 | + bytes32[] memory proofs = abi.decode(result, (bytes32[])); |
| 278 | + |
| 279 | + vm.warp(1); |
| 280 | + |
| 281 | + address receiver = address(0x92Bb439374a091c7507bE100183d8D1Ed2c9dAD3); |
| 282 | + |
| 283 | + // bytes32[] memory proofs = new bytes32[](0); |
| 284 | + |
| 285 | + DropERC721.ClaimCondition[] memory conditions = new DropERC721.ClaimCondition[](1); |
| 286 | + conditions[0].maxClaimableSupply = x; |
| 287 | + conditions[0].quantityLimitPerTransaction = 100; |
| 288 | + conditions[0].waitTimeInSecondsBetweenClaims = type(uint256).max; |
| 289 | + conditions[0].merkleRoot = root; |
| 290 | + |
| 291 | + vm.prank(deployer); |
| 292 | + drop.lazyMint(x, "ipfs://", ""); |
| 293 | + vm.prank(deployer); |
| 294 | + drop.setClaimConditions(conditions, false); |
| 295 | + |
| 296 | + // vm.prank(getActor(5), getActor(5)); |
| 297 | + vm.prank(receiver, receiver); |
| 298 | + drop.claim(receiver, x, address(0), 0, proofs, x); |
| 299 | + |
| 300 | + vm.prank(address(4), address(4)); |
| 301 | + vm.expectRevert("not in whitelist."); |
| 302 | + drop.claim(receiver, x, address(0), 0, proofs, x); |
| 303 | + } |
| 304 | + |
| 305 | + function testFail_claimCondition_merkleProof(uint256 x, uint256 y) public { |
| 306 | + vm.assume(x != 0 && x < 500); |
| 307 | + vm.assume(x != y); |
| 308 | + string[] memory inputs = new string[](3); |
| 309 | + |
| 310 | + inputs[0] = "node"; |
| 311 | + inputs[1] = "src/test/scripts/generateRoot.ts"; |
| 312 | + inputs[2] = Strings.toString(x); |
| 313 | + |
| 314 | + bytes memory result = vm.ffi(inputs); |
| 315 | + // revert(); |
| 316 | + bytes32 root = abi.decode(result, (bytes32)); |
| 317 | + |
| 318 | + inputs[1] = "src/test/scripts/getProof.ts"; |
| 319 | + result = vm.ffi(inputs); |
| 320 | + bytes32[] memory proofs = abi.decode(result, (bytes32[])); |
| 321 | + |
| 322 | + vm.warp(1); |
| 323 | + |
| 324 | + address receiver = address(0x92Bb439374a091c7507bE100183d8D1Ed2c9dAD3); |
| 325 | + |
| 326 | + // bytes32[] memory proofs = new bytes32[](0); |
| 327 | + |
| 328 | + DropERC721.ClaimCondition[] memory conditions = new DropERC721.ClaimCondition[](1); |
| 329 | + conditions[0].maxClaimableSupply = x; |
| 330 | + conditions[0].quantityLimitPerTransaction = 100; |
| 331 | + conditions[0].waitTimeInSecondsBetweenClaims = type(uint256).max; |
| 332 | + conditions[0].merkleRoot = root; |
| 333 | + |
| 334 | + vm.prank(deployer); |
| 335 | + drop.lazyMint(x, "ipfs://", ""); |
| 336 | + vm.prank(deployer); |
| 337 | + drop.setClaimConditions(conditions, false); |
| 338 | + |
| 339 | + // vm.prank(getActor(5), getActor(5)); |
| 340 | + vm.prank(receiver, receiver); |
| 341 | + drop.claim(receiver, x, address(0), 0, proofs, y); |
| 342 | + |
| 343 | + vm.prank(address(4), address(4)); |
| 344 | + vm.expectRevert("not in whitelist."); |
| 345 | + drop.claim(receiver, x, address(0), 0, proofs, y); |
| 346 | + } |
226 | 347 | } |
0 commit comments