From ae8cf3781a638ad77835a54cfa221f813c8c0b81 Mon Sep 17 00:00:00 2001 From: Mitja Belak Date: Wed, 30 Oct 2024 22:19:13 +0100 Subject: [PATCH] Proves the game is winnable --- src/RaidGeld.sol | 3 ++- test/RaidGeld.t.sol | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/RaidGeld.sol b/src/RaidGeld.sol index 43a91be..426e45b 100644 --- a/src/RaidGeld.sol +++ b/src/RaidGeld.sol @@ -75,6 +75,7 @@ contract RaidGeld is ERC20, Ownable, Constants { reset_player(player); players[player].has_active_session = true; players[player].is_registered = true; + players[player].n_runs += 1; if (existing_player) { // TODO: Emit new run @@ -86,7 +87,7 @@ contract RaidGeld is ERC20, Ownable, Constants { function reset_player(address addr) private { Player memory player = players[addr]; - uint32 current_n_runs = player.n_runs + 1; + uint32 current_n_runs = player.n_runs; uint256 current_total_rewards = player.total_rewards; bool current_is_registered = player.is_registered; uint32 current_prestige_level = player.prestige_level; diff --git a/test/RaidGeld.t.sol b/test/RaidGeld.t.sol index 5f2fb1f..1d32a09 100644 --- a/test/RaidGeld.t.sol +++ b/test/RaidGeld.t.sol @@ -350,4 +350,49 @@ contract raid_geldTest is Test, Constants { uint256 balance3 = raid_geld.daoToken().balanceOf(address(raid_geld)); assertLt(balance2, balance3); } + + function test_09_player_can_gain_prestige(uint256 prevrandao) public { + vm.assume(prevrandao < type(uint256).max - 1e4); + vm.startPrank(player1); + stdstore.target(DAO_TOKEN).sig("balanceOf(address)").with_key(player1).checked_write(10000000 ether); + stdstore.target(DAO_TOKEN).sig("balanceOf(address)").with_key(address(raid_geld)).checked_write(10000000 ether); + bool success = false; + uint256 tries = 0; + uint256 streak = 0; + for (uint i = 0; i < 1000; i++) { + vm.prevrandao(prevrandao + i * 59); + bool[2] memory results; + bool alreadyLost = false; + uint256 newStreak = 0; + tries += 1; + console.log("NEW TRY, number: ", tries); + registerPlayerWithDaoToken(); + // Give bajillion GELD to player so player can battle boss after boss + stdstore.target(address(raid_geld)).sig("balanceOf(address)").with_key(player1).checked_write(10000000 ether); + for (uint j = 0; j < 6; j++) { + vm.prevrandao(prevrandao + j * 7 + i * 59); + newStreak += 1; + results = raid_geld.battle_with_boss(); + if (results[0] == false) { + alreadyLost = true; + break; + } + } + if (alreadyLost) { + if (newStreak > streak) { + streak = newStreak; + } + continue; + } + results = raid_geld.battle_with_boss(); + if (results[0] == true && results[1] == true) { + success = true; + Player memory player = raid_geld.getPlayer(player1); + vm.assertEq(player.prestige_level, 1); + vm.assertEq(player.n_runs, tries); + break; + } + } + require(success, "Player should eventually succeed"); + } }