forked from retoor/devplacepy
pdate
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user