function resetGame() external onlyOwner gameEndedOnly {
currentKing = address(0);
lastClaimTime = block.timestamp;
pot = 0;
claimFee = initialClaimFee;
gracePeriod = initialGracePeriod;
gameEnded = false;
gameRound = gameRound + 1;
}
pragma solidity ^0.8.20;
import {Test} from "forge-std/Test.sol";
import {Game} from "../src/Game.sol";
contract GameLastClaimTimeTest is Test {
Game public game;
address public deployer;
address public player1;
uint256 public constant INITIAL_CLAIM_FEE = 0.1 ether;
uint256 public constant GRACE_PERIOD = 1 days;
uint256 public constant FEE_INCREASE_PERCENTAGE = 10;
uint256 public constant PLATFORM_FEE_PERCENTAGE = 5;
function setUp() public {
deployer = makeAddr("deployer");
player1 = makeAddr("player1");
vm.deal(deployer, 10 ether);
vm.deal(player1, 10 ether);
vm.startPrank(deployer);
game = new Game(
INITIAL_CLAIM_FEE,
GRACE_PERIOD,
FEE_INCREASE_PERCENTAGE,
PLATFORM_FEE_PERCENTAGE
);
vm.stopPrank();
}
function testResetGameSetsIncorrectLastClaimTime() public {
vm.startPrank(player1);
game.claimThrone{value: INITIAL_CLAIM_FEE}();
vm.stopPrank();
vm.warp(block.timestamp + GRACE_PERIOD + 1);
game.declareWinner();
uint256 resetTimestamp = block.timestamp;
vm.startPrank(deployer);
game.resetGame();
vm.stopPrank();
assertEq(game.currentKing(), address(0), "No king should exist after reset");
assertEq(game.lastClaimTime(), resetTimestamp, "lastClaimTime incorrectly set to reset time");
}
function testGetRemainingTimeWithoutKing() public {
vm.startPrank(player1);
game.claimThrone{value: INITIAL_CLAIM_FEE}();
vm.stopPrank();
vm.warp(block.timestamp + GRACE_PERIOD + 1);
game.declareWinner();
vm.startPrank(deployer);
game.resetGame();
vm.stopPrank();
uint256 remainingTime = game.getRemainingTime();
assertTrue(remainingTime > 0, "getRemainingTime should be 0 when no king exists");
}
function testGracePeriodRunsWithoutKing() public {
vm.startPrank(player1);
game.claimThrone{value: INITIAL_CLAIM_FEE}();
vm.stopPrank();
vm.warp(block.timestamp + GRACE_PERIOD + 1);
game.declareWinner();
vm.startPrank(deployer);
game.resetGame();
vm.stopPrank();
vm.warp(block.timestamp + GRACE_PERIOD + 1);
vm.expectRevert("Game: No one has claimed the throne yet.");
game.declareWinner();
}
}
function resetGame() external onlyOwner gameEndedOnly {
currentKing = address(0);
- lastClaimTime = block.timestamp;
+ lastClaimTime = 0;
pot = 0;
claimFee = initialClaimFee;
gracePeriod = initialGracePeriod;
gameEnded = false;
gameRound = gameRound + 1;
}