|
| 1 | +// SPDX-License-Identifier: UNLICENSED |
| 2 | +pragma solidity ^0.8.13; |
| 3 | + |
| 4 | +import {Test, console} from "forge-std/Test.sol"; |
| 5 | +import {Assignment6} from "../src/Assignment6.sol"; |
| 6 | + |
| 7 | +contract Assignment6Test is Test { |
| 8 | + Assignment6 assignment; |
| 9 | + |
| 10 | + function setUp() public { |
| 11 | + assignment = new Assignment6(); |
| 12 | + } |
| 13 | + |
| 14 | + function testDeposit() public { |
| 15 | + vm.deal(address(this), 1 ether); |
| 16 | + vm.expectEmit(true, true, false, true); |
| 17 | + emit Assignment6.FundsDeposited(address(this), 1 ether); |
| 18 | + assignment.deposit{value: 1 ether}(); |
| 19 | + uint balance = assignment.balances(address(this)); |
| 20 | + assertEq(balance, 1 ether, "Balance should be 1 ether"); |
| 21 | + } |
| 22 | + |
| 23 | + function testWithdraw() public { |
| 24 | + vm.deal(address(this), 1 ether); |
| 25 | + assignment.deposit{value: 1 ether}(); |
| 26 | + vm.expectEmit(true, true, false, true); // Match receiver and amount |
| 27 | + emit Assignment6.FundsWithdrawn(address(this), 0.5 ether); |
| 28 | + assignment.withdraw(0.5 ether); |
| 29 | + uint balance = assignment.balances(address(this)); |
| 30 | + assertEq(balance, 0.5 ether, "Balance should be 0.5 ether"); |
| 31 | + } |
| 32 | + |
| 33 | + function testContractBalance() public { |
| 34 | + vm.deal(address(this), 1 ether); |
| 35 | + assignment.deposit{value: 1 ether}(); |
| 36 | + uint contractBalance = assignment.getContractBalance(); |
| 37 | + assertEq(contractBalance, 1 ether, "Contract balance should be 1 ether"); |
| 38 | + } |
| 39 | + |
| 40 | + receive() external payable {} |
| 41 | +} |
0 commit comments