1
0
forked from mico/idle_moloch

Player loses test

This commit is contained in:
mic0 2024-10-30 20:44:00 +01:00
parent 44f3e97de8
commit e282b499e9
Signed by: mico
GPG Key ID: A3F8023524CF1C8D
3 changed files with 43 additions and 6 deletions

View File

@ -12,7 +12,7 @@ contract RaidGeld is ERC20, Ownable, Constants {
uint256 public constant MANTISSA = 1e4; uint256 public constant MANTISSA = 1e4;
uint256 public constant BUY_IN_AMOUNT = 0.00005 ether; uint256 public constant BUY_IN_AMOUNT = 0.00005 ether;
uint256 public immutable BUY_IN_DAO_TOKEN_AMOUNT; 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 => Player) private players;
mapping(address => Army) private armies; mapping(address => Army) private armies;
mapping(address => Boss) private bosses; mapping(address => Boss) private bosses;

View File

@ -2,6 +2,7 @@
pragma solidity ^0.8.13; pragma solidity ^0.8.13;
import {Army} from "../src/RaidGeldStructs.sol"; import {Army} from "../src/RaidGeldStructs.sol";
import {console} from "forge-std/Test.sol";
library RaidGeldUtils { library RaidGeldUtils {
uint256 public constant PRECISION = 10000; 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, // Relative power as in, you can only put in 800 geld to defeat 900 geld boss,
// but you will get exponentially worse chances // but you will get exponentially worse chances
uint256 relativePower = ((geldBurnt ** 2) * 100) / bossPower ** 2; uint256 relativePower = ((geldBurnt ** 2) * 100) / bossPower ** 2;
uint256 roll = random_n * relativePower / 1e2; uint256 roll = 1e2 - (random_n * relativePower / 1e2);
return roll < bossRoll; return roll < bossRoll;
} }

View File

@ -264,6 +264,9 @@ contract raid_geldTest is Test, Constants {
registerPlayerWithDaoToken(); registerPlayerWithDaoToken();
raid_geld.addUnit(0, 1); 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); Boss memory boss = raid_geld.getBoss(player1);
// assert boss is initialized // assert boss is initialized
assertEq(boss.level, 0); 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 // Make a lot of time pass so user deffo has GELD to attack the boss
vm.warp(1200000); vm.warp(1200000);
bool[2] memory results = raid_geld.battle_with_boss(); bool[2] memory results = raid_geld.battle_with_boss();
console.log(results[0]);
console.log(results[1]);
// Should almost always defeat first boss // Should almost always defeat first boss
assertEq(results[0], true); assertEq(results[0], true);
// First boss doesnt grant a new prestige level (ascension) // First boss doesnt grant a new prestige level (ascension)
assertEq(results[1], false); 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);
} }
} }