pdate
DevPlace CI / test (push) Has been cancelled

This commit is contained in:
2026-07-23 01:14:10 +02:00
parent 64c3983c9f
commit 582e37d176
24 changed files with 549 additions and 36 deletions
+64
View File
@@ -399,3 +399,67 @@ def test_weekly_contract_deterministic():
assert first == second
assert first["kind"] in economy.QUEST_DEFS
assert first["reward_stars"] > 0
# --- refactor fee, carry-over, and grants -------------------------------------------
def test_refactor_cost_monotonic_in_prestige():
previous = 0
for prestige in range(0, 200):
cost = economy.refactor_cost(prestige, 0)
assert cost > previous
previous = cost
def test_refactor_cost_monotonic_in_wealth():
previous = -1
for coins in range(0, 2_000_000, 10_000):
cost = economy.refactor_cost(0, coins)
assert cost >= previous
previous = cost
def test_refactor_cost_floor_is_base():
assert economy.refactor_cost(0, 0) == economy.REFACTOR_BASE_COST
assert economy.refactor_cost(-5, -100) == economy.REFACTOR_BASE_COST
def test_refactor_cost_includes_wealth_tax():
coins = 100_000
expected = round(
economy.REFACTOR_BASE_COST + economy.REFACTOR_WEALTH_PCT * coins
)
assert economy.refactor_cost(0, coins) == expected
def test_refactor_carryover_fraction_bounds():
for level in range(0, 50):
fraction = economy.refactor_carryover_fraction(level)
assert economy.REFACTOR_CARRYOVER_BASE <= fraction <= economy.REFACTOR_CARRYOVER_MAX
def test_refactor_carryover_never_exceeds_remainder():
for coins in range(0, 500_000, 7_777):
for level in (0, 3, 5):
fee = economy.refactor_cost(0, coins)
carried = economy.refactor_carryover(coins, fee, level)
assert 0 <= carried <= max(0, coins - fee)
def test_refactor_carryover_zero_when_unaffordable():
assert economy.refactor_carryover(100, 20_000, 5) == 0
def test_grant_amount_capped_and_bounded():
assert economy.grant_amount(0) == 0
assert economy.grant_amount(-10) == 0
assert economy.grant_amount(100) == 100
assert economy.grant_amount(10**9) == economy.GRANT_CAP
def test_legacy_carryover_upgrade_registered():
upgrade = economy.legacy_for("carryover")
assert upgrade is not None
assert upgrade.max_level == 5
assert "carry-over" in economy.legacy_value_text(upgrade, 2)
+132 -2
View File
@@ -45,6 +45,7 @@ def _reset(username, coins=100000):
get_table("game_steals").delete(owner_uid=user["uid"])
get_table("game_cosmetics").delete(user_uid=user["uid"])
get_table("game_market_ticks").delete()
get_table("game_treasury").delete()
_clear_game_caches()
farm = store.ensure_farm(user["uid"])
get_table("game_farms").update({"uid": farm["uid"], "coins": coins}, ["uid"])
@@ -493,10 +494,15 @@ def test_prestige_resets_farm_and_increments(local_db):
ci_tier=3,
)
store.buy_plot(user)
coins_before = _coins(user)
fee = economy.refactor_cost(0, coins_before)
carried = economy.refactor_carryover(coins_before, fee, 0)
result = store.prestige(user)
assert result["prestige"] == 1
assert result["fee"] == fee
assert result["carried"] == carried
farm = store.get_farm(user["uid"])
assert farm["coins"] == economy.STARTING_COINS
assert farm["coins"] == economy.STARTING_COINS + carried
assert farm["xp"] == 0
assert farm["ci_tier"] == 1
assert farm["perk_growth"] == 0
@@ -504,6 +510,45 @@ def test_prestige_resets_farm_and_increments(local_db):
assert len(store.get_plots(farm["uid"])) == economy.STARTING_PLOTS
def test_prestige_insufficient_coins_blocked(local_db):
user = _reset("unit_a", coins=100)
_set(user, xp=economy.xp_threshold(economy.PRESTIGE_MIN_LEVEL))
with pytest.raises(GameError):
store.prestige(user)
farm = store.get_farm(user["uid"])
assert int(farm["prestige"] or 0) == 0
assert int(farm["coins"]) == 100
def test_prestige_fee_funds_treasury(local_db):
user = _reset("unit_a")
_set(user, xp=economy.xp_threshold(economy.PRESTIGE_MIN_LEVEL))
fee = economy.refactor_cost(0, _coins(user))
store.prestige(user)
assert store.treasury_balance() == fee
def test_prestige_carryover_scales_with_legacy(local_db):
user = _reset("unit_a")
_set(
user,
xp=economy.xp_threshold(economy.PRESTIGE_MIN_LEVEL),
legacy_carryover=5,
)
coins_before = _coins(user)
fee = economy.refactor_cost(0, coins_before)
carried = economy.refactor_carryover(coins_before, fee, 5)
assert carried > economy.refactor_carryover(coins_before, fee, 0)
store.prestige(user)
farm = store.get_farm(user["uid"])
assert farm["coins"] == economy.STARTING_COINS + carried
def test_prestige_fee_rises_with_prestige_and_wealth(local_db):
assert economy.refactor_cost(1, 0) > economy.refactor_cost(0, 0)
assert economy.refactor_cost(0, 1_000_000) > economy.refactor_cost(0, 0)
# --- legacy upgrades ---------------------------------------------------------
@@ -851,7 +896,8 @@ def test_farm_analytics_tracks_lifetime_totals_once_unlocked(local_db):
def test_prestige_awards_mastery_at_threshold(local_db):
user = _reset("unit_a")
_set(user, xp=economy.xp_threshold(economy.PRESTIGE_MIN_LEVEL), prestige=49)
coins = economy.refactor_cost(49, 0) * 2
_set(user, xp=economy.xp_threshold(economy.PRESTIGE_MIN_LEVEL), prestige=49, coins=coins)
result = store.prestige(user)
assert result["mastery_awarded"] == 1
farm = store.get_farm(user["uid"])
@@ -946,3 +992,87 @@ def test_weekly_contract_claim_pays_stars_and_boost(local_db):
farm = store.get_farm(user["uid"])
assert int(farm["stars"]) == result["reward_stars"]
assert farm.get("contract_boost_until")
# --- treasury and community grant --------------------------------------------
def _seed_treasury(amount):
store.ensure_treasury()
get_table("game_treasury").update(
{"uid": "treasury-main", "balance": amount}, ["uid"]
)
def _make_grant_eligible(user):
_set(
user,
coins=100,
harvests_week=economy.GRANT_MIN_WEEK_HARVESTS,
harvests_week_start=store._iso_week(store._now()),
)
def test_claim_grant_pays_from_treasury(local_db):
user = _reset("unit_a")
_seed_treasury(100_000)
_make_grant_eligible(user)
result = store.claim_grant(user)
assert result["amount"] == economy.GRANT_CAP
assert _coins(user) == 100 + economy.GRANT_CAP
assert store.treasury_balance() == 100_000 - economy.GRANT_CAP
def test_claim_grant_once_per_week(local_db):
user = _reset("unit_a")
_seed_treasury(100_000)
_make_grant_eligible(user)
store.claim_grant(user)
_set(user, coins=100)
with pytest.raises(GameError):
store.claim_grant(user)
def test_claim_grant_requires_activity(local_db):
user = _reset("unit_a")
_seed_treasury(100_000)
_set(user, coins=100, harvests_week=economy.GRANT_MIN_WEEK_HARVESTS - 1)
with pytest.raises(GameError):
store.claim_grant(user)
def test_claim_grant_wealth_ceiling(local_db):
user = _reset("unit_a")
_seed_treasury(100_000)
_set(
user,
coins=economy.GRANT_WEALTH_CEILING,
harvests_week=economy.GRANT_MIN_WEEK_HARVESTS,
)
with pytest.raises(GameError):
store.claim_grant(user)
def test_claim_grant_prestige_cap(local_db):
user = _reset("unit_a")
_seed_treasury(100_000)
_make_grant_eligible(user)
_set(user, prestige=economy.GRANT_MAX_PRESTIGE + 1)
with pytest.raises(GameError):
store.claim_grant(user)
def test_claim_grant_empty_treasury(local_db):
user = _reset("unit_a")
_make_grant_eligible(user)
with pytest.raises(GameError):
store.claim_grant(user)
def test_claim_grant_partial_treasury(local_db):
user = _reset("unit_a")
_seed_treasury(300)
_make_grant_eligible(user)
result = store.claim_grant(user)
assert result["amount"] == 300
assert store.treasury_balance() == 0