function testPrizeEmissionIncorrect() public {
address player = makeAddr("player");
vm.deal(player, 1 ether);
uint256 initialClaimFee = game.claimFee();
vm.prank(player);
game.claimThrone{value: initialClaimFee}();
uint256 actualPot = game.pot();
vm.warp(block.timestamp + game.gracePeriod() + 1);
uint256 gameRound = game.gameRound();
vm.expectEmit(true, true, true, true);
emit GameEnded(player, 0, block.timestamp, gameRound);
game.declareWinner();
assertNotEq(actualPot, 0, "Pot value is wrong");
}
forge test --mt testPrizeEmissionIncorrect -vvvv
[⠊] Compiling...
[⠒] Compiling 1 files with Solc 0.8.26
[⠑] Solc 0.8.26 finished in 488.01ms
Compiler run successful!
Ran 1 test for test/Game.t.sol:GameTest
[PASS] testPrizeEmissionIncorrect() (gas: 190824)
Traces:
[230624] GameTest::testPrizeEmissionIncorrect()
├─ [0] VM::addr(<pk>) [staticcall]
│ └─ ← [Return] player: [0x44E97aF4418b7a17AABD8090bEA0A471a366305C]
├─ [0] VM::label(player: [0x44E97aF4418b7a17AABD8090bEA0A471a366305C], "player")
│ └─ ← [Return]
├─ [0] VM::deal(player: [0x44E97aF4418b7a17AABD8090bEA0A471a366305C], 1000000000000000000 [1e18])
│ └─ ← [Return]
├─ [2514] Game::claimFee() [staticcall]
│ └─ ← [Return] 100000000000000000 [1e17]
├─ [0] VM::prank(player: [0x44E97aF4418b7a17AABD8090bEA0A471a366305C])
│ └─ ← [Return]
├─ [150601] Game::claimThrone{value: 100000000000000000}()
│ ├─ emit ThroneClaimed(newKing: player: [0x44E97aF4418b7a17AABD8090bEA0A471a366305C], claimAmount: 100000000000000000 [1e17], newClaimFee: 110000000000000000 [1.1e17], newPot: 95000000000000000 [9.5e16], timestamp: 1)
│ └─ ← [Stop]
├─ [515] Game::pot() [staticcall]
│ └─ ← [Return] 95000000000000000 [9.5e16]
├─ [2536] Game::gracePeriod() [staticcall]
│ └─ ← [Return] 86400 [8.64e4]
├─ [0] VM::warp(86402 [8.64e4])
│ └─ ← [Return]
├─ [2471] Game::gameRound() [staticcall]
│ └─ ← [Return] 1
├─ [0] VM::expectEmit(true, true, true, true)
│ └─ ← [Return]
├─ emit GameEnded(winner: player: [0x44E97aF4418b7a17AABD8090bEA0A471a366305C], prizeAmount: 0, timestamp: 86402 [8.64e4], round: 1)
├─ [46689] Game::declareWinner()
│ ├─ emit GameEnded(winner: player: [0x44E97aF4418b7a17AABD8090bEA0A471a366305C], prizeAmount: 0, timestamp: 86402 [8.64e4], round: 1)
│ └─ ← [Stop]
└─ ← [Stop]
Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 1.20ms (190.75µs CPU time)
Ran 1 test suite in 5.20ms (1.20ms CPU time): 1 tests passed, 0 failed, 0 skipped (1 total tests)
function declareWinner() external gameNotEnded {
require(currentKing != address(0));
require(block.timestamp > lastClaimTime + gracePeriod);
gameEnded = true;
+ uint256 prize = pot;
pendingWinnings[currentKing] += pot;
pot = 0;
- emit GameEnded(currentKing, pot, block.timestamp, gameRound);
+ emit GameEnded(currentKing, prize, block.timestamp, gameRound);
}