The following tests demonstrate the issue. Stats persist and accumulate across multiple rounds and are never reset:
pragma solidity ^0.8.20;
import {Test, console2} from "forge-std/Test.sol";
import {Game} from "../src/Game.sol";
contract GameStatsOverflowTest 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, 100 ether);
vm.deal(player1, 100 ether);
vm.startPrank(deployer);
game = new Game(
INITIAL_CLAIM_FEE,
GRACE_PERIOD,
FEE_INCREASE_PERCENTAGE,
PLATFORM_FEE_PERCENTAGE
);
vm.stopPrank();
}
function testStatsNeverReset() public {
vm.startPrank(player1);
game.claimThrone{value: INITIAL_CLAIM_FEE}();
vm.stopPrank();
uint256 initialTotalClaims = game.totalClaims();
uint256 initialPlayerClaims = game.playerClaimCount(player1);
assertEq(initialTotalClaims, 1, "Should have 1 total claim");
assertEq(initialPlayerClaims, 1, "Player should have 1 claim");
vm.warp(block.timestamp + GRACE_PERIOD + 1);
game.declareWinner();
vm.startPrank(deployer);
game.resetGame();
vm.stopPrank();
assertEq(game.totalClaims(), initialTotalClaims, "Total claims should persist after reset");
assertEq(game.playerClaimCount(player1), initialPlayerClaims, "Player claims should persist after reset");
vm.startPrank(player1);
game.claimThrone{value: INITIAL_CLAIM_FEE}();
vm.stopPrank();
assertEq(game.totalClaims(), 2, "Total claims should accumulate");
assertEq(game.playerClaimCount(player1), 2, "Player claims should accumulate");
}
function testCountersUseUint256() public view {
uint256 maxValue = type(uint256).max;
console2.log("uint256 max value:", maxValue);
uint64 maxUint64 = type(uint64).max;
console2.log("uint64 max value:", maxUint64);
}
function testStatsPersistenceAcrossMultipleRounds() public {
uint256 rounds = 3;
for (uint256 i = 0; i < rounds; i++) {
vm.startPrank(player1);
game.claimThrone{value: INITIAL_CLAIM_FEE}();
vm.stopPrank();
vm.warp(block.timestamp + GRACE_PERIOD + 1);
game.declareWinner();
if (i < rounds - 1) {
vm.startPrank(deployer);
game.resetGame();
vm.stopPrank();
}
}
assertEq(game.totalClaims(), rounds, "Total claims should accumulate across all rounds");
assertEq(game.playerClaimCount(player1), rounds, "Player claims should accumulate across all rounds");
}
}