idle_moloch/test/RaidGeldUtils.t.sol
Mitja Belak cb12c772ae
Some checks are pending
CI / Foundry project (push) Waiting to run
Made tests pure where applicable
2024-10-24 14:35:55 +02:00

53 lines
2.0 KiB
Solidity

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import {Test, console} from "forge-std/Test.sol";
import {Army, Raider} from "../src/RaidGeld.sol";
import "../src/RaidGeldUtils.sol";
contract raid_geldTest is Test {
function test_0_unit_price() pure public {
// buying 1 unit of moloch_denier
uint256 basePriceMolochDenier = RaidGeldUtils.calculateUnitPrice(0, 0, 1);
assertEq(basePriceMolochDenier, 38);
// buying 3 units
// has to be a bit more than 3 * 38 = 114
uint256 price = RaidGeldUtils.calculateUnitPrice(0, 0, 3);
assertGt(price, 3 * basePriceMolochDenier);
uint256 basePriceChamp = RaidGeldUtils.calculateUnitPrice(0, 0, 3);
// buying 3 units of champions
// has to be a bit more than 4 * 38 * 3 = 114
price = RaidGeldUtils.calculateUnitPrice(3, 0, 3);
assertGt(price, 3 * basePriceChamp);
// buying 12 units of champions when u already have 10
price = RaidGeldUtils.calculateUnitPrice(3, 10, 12);
// price should scale up
assertGt(price, basePriceChamp * 12);
}
function test_1_profits_per_second() pure public {
Army memory army = Army({
moloch_denier: Raider({ level: 1}),
apprentice: Raider({ level: 0}),
anointed: Raider({ level: 0}),
champion: Raider({ level: 0}),
profit_per_second: 0 // irrelevant for this test
});
uint256 profits_per_second = RaidGeldUtils.calculateProfitsPerSecond(army);
assertEq(profits_per_second, 1);
army = Army({
moloch_denier: Raider({ level: 2}),
apprentice: Raider({ level: 0}),
anointed: Raider({ level: 10}),
champion: Raider({ level: 1}),
profit_per_second: 0 // irrelevant for this test
});
profits_per_second = RaidGeldUtils.calculateProfitsPerSecond(army);
assertEq(profits_per_second, 640);
}
}