From e282b499e91082d1c1de35e81a60cfd3b9c3e13f Mon Sep 17 00:00:00 2001 From: Mitja Belak Date: Wed, 30 Oct 2024 20:44:00 +0100 Subject: [PATCH] Player loses test --- src/RaidGeld.sol | 2 +- src/RaidGeldUtils.sol | 3 ++- test/RaidGeld.t.sol | 44 +++++++++++++++++++++++++++++++++++++++---- 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/RaidGeld.sol b/src/RaidGeld.sol index 8c95e8c..0852cb6 100644 --- a/src/RaidGeld.sol +++ b/src/RaidGeld.sol @@ -12,7 +12,7 @@ contract RaidGeld is ERC20, Ownable, Constants { uint256 public constant MANTISSA = 1e4; uint256 public constant BUY_IN_AMOUNT = 0.00005 ether; uint256 public immutable BUY_IN_DAO_TOKEN_AMOUNT; - uint256 public constant INITIAL_GELD = 500 * MANTISSA; + uint256 public constant INITIAL_GELD = 50 * MANTISSA; mapping(address => Player) private players; mapping(address => Army) private armies; mapping(address => Boss) private bosses; diff --git a/src/RaidGeldUtils.sol b/src/RaidGeldUtils.sol index 5f42d1f..0296489 100644 --- a/src/RaidGeldUtils.sol +++ b/src/RaidGeldUtils.sol @@ -2,6 +2,7 @@ pragma solidity ^0.8.13; import {Army} from "../src/RaidGeldStructs.sol"; +import {console} from "forge-std/Test.sol"; library RaidGeldUtils { uint256 public constant PRECISION = 10000; @@ -109,7 +110,7 @@ library RaidGeldUtils { // Relative power as in, you can only put in 800 geld to defeat 900 geld boss, // but you will get exponentially worse chances uint256 relativePower = ((geldBurnt ** 2) * 100) / bossPower ** 2; - uint256 roll = random_n * relativePower / 1e2; + uint256 roll = 1e2 - (random_n * relativePower / 1e2); return roll < bossRoll; } diff --git a/test/RaidGeld.t.sol b/test/RaidGeld.t.sol index 62ff7e6..ba9b97a 100644 --- a/test/RaidGeld.t.sol +++ b/test/RaidGeld.t.sol @@ -264,6 +264,9 @@ contract raid_geldTest is Test, Constants { registerPlayerWithDaoToken(); raid_geld.addUnit(0, 1); + uint256 initialDaoBalance = raid_geld.daoToken().balanceOf(player1); + uint256 initialContractBalance = raid_geld.daoToken().balanceOf(address(raid_geld)); + Boss memory boss = raid_geld.getBoss(player1); // assert boss is initialized assertEq(boss.level, 0); @@ -272,14 +275,47 @@ contract raid_geldTest is Test, Constants { // Make a lot of time pass so user deffo has GELD to attack the boss vm.warp(1200000); - bool[2] memory results = raid_geld.battle_with_boss(); - console.log(results[0]); - console.log(results[1]); - // Should almost always defeat first boss assertEq(results[0], true); // First boss doesnt grant a new prestige level (ascension) assertEq(results[1], false); + + uint256 afterBossDaoBalance = raid_geld.daoToken().balanceOf(player1); + uint256 afterBossContractBalance = raid_geld.daoToken().balanceOf(address(raid_geld)); + + // User should receive funs, contract should lose them + assertLt(initialDaoBalance, afterBossDaoBalance); + assertGt(initialContractBalance, afterBossContractBalance); + + Player memory player = raid_geld.getPlayer(player1); + // Players total rewards should increase + assertGt(player.total_rewards, 0); + } + + function test_07_attack_boss_fail() public { + // Let some time pass so we dont start at block timestamp 0 + vm.warp(120); + + // Register player 1 + vm.startPrank(player1); + registerPlayerWithDaoToken(); + raid_geld.addUnit(0, 1); + + bool[2] memory results = raid_geld.battle_with_boss(); + // Should lose with just starting GELD + assertEq(results[0], false); + // First boss doesnt grant a new prestige level (ascension) + assertEq(results[1], false); + + Player memory player = raid_geld.getPlayer(player1); + Army memory army = raid_geld.getArmy(player1); + + // player sessions should end + assertEq(player.has_active_session, false); + // player should lose all geld + assertEq(raid_geld.balanceOf(player1), 0); + // Units should reset + assertEq(army.moloch_denier.level, 0); } }