-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path05-Distributor.t.sol
49 lines (34 loc) · 1.15 KB
/
05-Distributor.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
41
42
43
44
45
46
47
48
49
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import {Test, console} from "forge-std/Test.sol";
import {Vault} from "../src/05-Distributor.sol";
contract DistributorTest is Test {
address owner;
address user;
Vault public vault;
function setUp() public {
owner = makeAddr("OWNER");
vm.prank(owner);
vault = new Vault();
user = makeAddr("USER");
vm.deal(user, 10 ether);
vm.prank(user);
vault.deposit{value: 10 ether}();
}
function test_Distributor() public {
address attacker = makeAddr("ATTACKER");
vm.deal(attacker, 1 ether);
vm.startPrank(attacker);
// START OF SOLUTION
// (You can create any additional contract if needed)
// END OF SOLUTION
vm.stopPrank();
vm.prank(owner);
vm.expectRevert();
vault.distribute();
uint256 userBalance = address(user).balance;
assertEq(userBalance, 0, "User shouldn't receive their ETH back");
uint256 vaultBalance = address(vault).balance;
assertGe(vaultBalance, 10 ether, "Vault ETH should be stuck");
}
}