From b79e9c7eb03bc0c91944bd1c332f9c4f0558016b Mon Sep 17 00:00:00 2001 From: Mitja Belak Date: Wed, 30 Oct 2024 21:10:01 +0100 Subject: [PATCH] Player can reenter the game test --- src/RaidGeld.sol | 1 + test/RaidGeld.t.sol | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/RaidGeld.sol b/src/RaidGeld.sol index 0852cb6..43a91be 100644 --- a/src/RaidGeld.sol +++ b/src/RaidGeld.sol @@ -74,6 +74,7 @@ contract RaidGeld is ERC20, Ownable, Constants { // Reset or set player reset_player(player); players[player].has_active_session = true; + players[player].is_registered = true; if (existing_player) { // TODO: Emit new run diff --git a/test/RaidGeld.t.sol b/test/RaidGeld.t.sol index ba9b97a..5f2fb1f 100644 --- a/test/RaidGeld.t.sol +++ b/test/RaidGeld.t.sol @@ -288,6 +288,10 @@ contract raid_geldTest is Test, Constants { assertLt(initialDaoBalance, afterBossDaoBalance); assertGt(initialContractBalance, afterBossContractBalance); + // Boss should level up + boss = raid_geld.getBoss(player1); + assertEq(boss.level, 1); + Player memory player = raid_geld.getPlayer(player1); // Players total rewards should increase assertGt(player.total_rewards, 0); @@ -318,4 +322,32 @@ contract raid_geldTest is Test, Constants { // Units should reset assertEq(army.moloch_denier.level, 0); } + + function test_08_player_who_lost_can_restart() public { + // Let some time pass so we dont start at block timestamp 0 + vm.warp(120); + uint256 balance1 = raid_geld.daoToken().balanceOf(address(raid_geld)); + + // Register player 1 + vm.startPrank(player1); + registerPlayerWithDaoToken(); + raid_geld.addUnit(0, 1); + uint256 balance2 = raid_geld.daoToken().balanceOf(address(raid_geld)); + // Contract gets DAO Tokens with first register + assertLt(balance1, balance2); + + bool[2] memory results = raid_geld.battle_with_boss(); + // Should lose with just starting GELD + assertEq(results[0], false); + Player memory player = raid_geld.getPlayer(player1); + // player sessions should end + assertEq(player.has_active_session, false); + assertEq(player.is_registered, true); + + registerPlayerWithDaoToken(); + player = raid_geld.getPlayer(player1); + assertEq(player.has_active_session, true); + uint256 balance3 = raid_geld.daoToken().balanceOf(address(raid_geld)); + assertLt(balance2, balance3); + } }