Skip to content

Commit bc2c823

Browse files
committed
class test
1 parent 6c3997c commit bc2c823

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

src/Attack.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// SPDX-License-Identifier: UNLICENSED
22
pragma solidity ^0.8.13;
33

4+
import {SecureBank} from "./security.sol";
5+
46
contract AttackContract {
57
SecureBank public bank;
68

test/attack.t.sol

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {Test} from "forge-std/Test.sol";
55
import {SecureBank} from "../src/security.sol";
66
import {AttackContract} from "../src/Attack.sol";
77

8-
contract SecureBankTest is Test {
8+
contract AttackContractTest is Test {
99
SecureBank bank;
1010
AttackContract attack;
1111
address user1;
@@ -23,24 +23,14 @@ contract SecureBankTest is Test {
2323
bank.deposit{value: 10 ether}();
2424
}
2525

26-
function testDepositAndWithdraw() public {
27-
uint256 beforeBalance = user1.balance;
28-
vm.prank(user1);
29-
bank.withdraw(5 ether);
30-
uint256 afterBalance = user1.balance;
31-
32-
assertGt(afterBalance, beforeBalance);
33-
assertEq(bank.balances(user1), 5 ether);
34-
}
35-
36-
function testRevertsReentrancyGuard() public {
26+
function testAttackReverts() public {
3727
vm.deal(attacker, 1 ether);
3828
vm.prank(attacker);
39-
vm.expectRevert("No reentrancy");
29+
vm.expectRevert("Transfer failed");
4030
attack.attack{value: 1 ether}();
4131
}
4232

43-
function testFundsIntactAfterAttack() public {
33+
function testFundsSafe() public {
4434
vm.deal(attacker, 1 ether);
4535
vm.prank(attacker);
4636
try attack.attack{value: 1 ether}() {} catch {}
@@ -49,7 +39,7 @@ contract SecureBankTest is Test {
4939
assertGe(bankBalance, 10 ether);
5040
}
5141

52-
function testDepositAndWithdraw() public {
42+
function testWithdrawWorks() public {
5343
uint256 beforeBalance = user1.balance;
5444
vm.prank(user1);
5545
bank.withdraw(5 ether);
@@ -59,7 +49,7 @@ contract SecureBankTest is Test {
5949
assertEq(bank.balances(user1), 5 ether);
6050
}
6151

62-
function testRejectsWithdraw() public {
52+
function testOverdraftFails() public {
6353
vm.prank(user1);
6454
vm.expectRevert("Insufficient balance");
6555
bank.withdraw(999 ether);

0 commit comments

Comments
 (0)