run forge test --mc POCTest -vvvvv to test
Created
October 31, 2023 15:04
-
-
Save Falilah/c77222f98a8a7c656bfa974e508e7211 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.7.6; | |
pragma experimental ABIEncoderV2; | |
import {Test, console} from "forge-std/Test.sol"; | |
import {PuppyRaffle} from "../src/PuppyRaffle.sol"; | |
import {Attackpuppy} from "./attacker.sol"; | |
contract POCTest is Test { | |
PuppyRaffle puppyRaffle; | |
uint256 entranceFee = 1e18; | |
address playerOne = address(1); | |
address playerTwo = address(2); | |
address playerThree = address(3); | |
address playerFour = address(4); | |
address feeAddress = address(99); | |
uint256 duration = 1 days; | |
///// attacker | |
Attackpuppy attacker; | |
function setUp() public { | |
puppyRaffle = new PuppyRaffle(entranceFee, feeAddress, duration); | |
attacker = new Attackpuppy(address(puppyRaffle)); | |
} | |
////////////////////// | |
/// selectWinner /// | |
///////////////////// | |
modifier playersEntered() { | |
address[] memory players = new address[](4); | |
players[0] = playerOne; | |
players[1] = playerTwo; | |
players[2] = playerThree; | |
players[3] = playerFour; | |
puppyRaffle.enterRaffle{value: entranceFee * 4}(players); | |
_; | |
} | |
function testWithdrawFees() public playersEntered { | |
vm.warp(block.timestamp + duration + 1); | |
vm.roll(block.number + 1); | |
uint256 expectedPrizeAmount = ((entranceFee * 4) * 20) / 100; | |
puppyRaffle.changeFeeAddress(address(0)); | |
puppyRaffle.selectWinner(); | |
puppyRaffle.withdrawFees(); | |
assertEq(address(0).balance, expectedPrizeAmount); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment