Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmaxbu committed Feb 13, 2025
1 parent 472db3e commit fd341fb
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/Faucet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@ contract Faucet {
emit Withdrawal(msg.sender, withdraw_amount);
}

/**
* @notice Receive ether, people can send ether that they are not gonna use to this contract
*/
receive() external payable {}
}
37 changes: 34 additions & 3 deletions test/Faucet.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,43 @@ pragma solidity ^0.8.24;

import {Test} from "forge-std/Test.sol";
import {Faucet} from "src/Faucet.sol";
import {Deploy} from "script/Deploy.s.sol";

contract FaucetTest is Test {
Faucet faucet;

function test_withdraw() public {
Faucet faucet = new Faucet();
faucet.deposit{value: 1 ether}();
address testUser = makeAddr("testUser");

function setup() public {
Deploy deploy = new Deploy();
faucet = deploy.run();

//transfer some funds to the faucet
//put it here, so for the production, we can fund the faucet manually, for security reasons.
vm.startBroadcast();
vm.deal(address(faucet), 100 ether);
vm.stopBroadcast();
}


function test_withdrawTooLarge() public {
vm.prank(testUser);
vm.expectRevert(Faucet.Faucet__amountTooLarge);
faucet.withdraw(10 ether);
}

function test_withdraw(uint amount) public {
vm.prank(testUser);
uint _amount = amount % 0.1 ether;
faucet.withdraw(_amount);
assertEq(address(testUser).balance, _amount);
}

function test_rateLimit() public {
vm.prank(testUser);
faucet.withdraw(0.01 ether);
vm.expectRevert(Faucet.Faucet__rateLimt);
faucet.withdraw(0.01 ether);
}

}

0 comments on commit fd341fb

Please sign in to comment.