5d5198f5d1
Second session. FUT core loop, the EASFC/POW online layer, a central account
backend, and a lot of corrections. Everything risky is behind an env flag with
the default set to whatever was live-proven.
WORKING END TO END (live-verified this session):
* match loop -- POST/PUT/POST/DELETE ut/%s/match, rewards via FutDestroyMatch
(0x180121b60). Play a match, get coins, W/D/L updates.
* packs -- buy, cards land in the club, session survives (FUT_PACK_AUTOCLUB=1)
* quick sell -- POST ut/delete/%s/item was UNMAPPED and paid NOTHING; six cards
were destroyed for 0 coins. Now credits discardValue.
* POW/EASFC online -- the "EA FC servers unreachable" banner is powdll's layer,
a THIRD http api on :8094 nobody had served. Redirect needs no root: powdll
FUN_18005a460 reads FIFA_POW_URL from the same client-config store as
ROSTERUPDATE_URL. FUT_POW=1.
* account backend -- fut_account.py replaces 7 hardcoded copies of the persona
across 5 files; club/persona/online-profile editable via CLI.
CORRECTIONS TO ENDPOINT_MAP (all re-extracted from the deserializers):
* FutStoreGetPackTypes: id/packType/isPremium/quantity/saleType/purchaseLimit/
purchaseCount are NOT skipped no-ops -- all are parsed. extPrice inner objects
take externalPriceId(0x11a), not amount/currency.
* FutMoveCard 0x180128600 has NO skip handler (FUN_180135ff0 appears zero times,
unique among FUT deserializers) and parses only itemData -> dreamSquads.
* class -> deserializer resolution: the name literal is preceded by a 4-BYTE
HEADER and the factory LEA points at the header, so look up name_addr - 4.
Six attempts failed on this; now ghidra_env.class_deser(). Unlocked 11 SBC/
Draft schemas.
* live-only endpoints the request table never lists: ut/%s/squad/list,
ut/%s/user/club, ut/%s/club/stats/*, ut/%s/clientdata/<key>. The template
table is a floor, not a ceiling -- the log is the only ground truth.
* 163 RS4 call names exist; we served 17. All now served.
FIXED: club/stats/* was answering with the entire 28-item club inventory on every
poll (it fell through to the generic /club route).
UNSOLVED: the pack reveal's "Send to Club" (PUT ut/%s/item) kills the FUT session
whatever we answer -- {} included -- while its sibling quick-sell endpoint accepts
a bare {}. Seven hypotheses eliminated by live test, documented in
REBUILD_RESEARCH.md S14c so none get re-walked. FUT_PACK_AUTOCLUB routes around it.
Also unfixed: store tiles render "unknown" (displayGroup is parsed RECURSIVELY by
the same element parser; sending it FROZE the store, so FUT_STORE_GROUPS=1 is
default off).
Tests: test_fut_contract.py 380 (live, read-only) + test_match_rewards.py 51 (pure).
Note: fut_store.py carries some pre-existing uncommitted changes from before this
session (pack catalogue ids, pending-pile behaviour) that could not be separated
from this session's additions in the same file.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VUT92pz6RWKih9dSr8ZpxW
112 lines
4.6 KiB
Python
112 lines
4.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Unit tests for the FUT match core loop — PURE, no server, no state, no profile.
|
|
|
|
Why separate from test_fut_contract.py: that suite is read-only by design (it hits
|
|
a live server and must never mutate the save), but the match loop credits coins and
|
|
bumps the W/D/L record. So the two pure pieces — result detection and the reward
|
|
body — are tested here instead of making the HTTP suite stateful.
|
|
|
|
Guards the two things that would silently break the loop:
|
|
* `_match_result()` mis-reading a scoreline (wrong result -> wrong payout)
|
|
* `destroy_match_body()` drifting from FutDestroyMatchServerResponse
|
|
(deser 0x180121b60): a non-scalar there is the freeze class at 0x1801c7f1a,
|
|
and a renamed key is silently SKIP'd, i.e. the reward vanishes with no error.
|
|
|
|
Run: python3 tools/test_match_rewards.py (exit 0 = pass)
|
|
"""
|
|
import os
|
|
import sys
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
os.environ.setdefault("FUT_PROFILE", "/tmp/openfut_unittest_profile.json")
|
|
|
|
import utas_server as U # noqa: E402
|
|
|
|
_fail = []
|
|
_pass = 0
|
|
|
|
|
|
def check(name, cond, detail=""):
|
|
global _pass
|
|
if cond:
|
|
_pass += 1
|
|
else:
|
|
_fail.append("%s: %s" % (name, detail))
|
|
|
|
|
|
# ---- _match_result: scoreline -> outcome ------------------------------------
|
|
def test_result_detection():
|
|
cases = [
|
|
({"goals": 3, "opponentGoals": 1}, "won"),
|
|
({"goals": 0, "opponentGoals": 2}, "loss"),
|
|
({"goals": 1, "opponentGoals": 1}, "draw"),
|
|
({"score": 2, "opponentScore": 0}, "won"),
|
|
({"homeGoals": 0, "awayGoals": 4}, "loss"),
|
|
({"match": {"goals": 5, "opponentGoals": 0}}, "won"), # nested
|
|
({"stats": {"score": 0, "opponentScore": 3}}, "loss"), # nested
|
|
({"result": "WIN"}, "won"),
|
|
({"outcome": "defeat"}, "loss"),
|
|
({"result": "tie"}, "draw"),
|
|
({}, "draw"), # unknown -> neutral fallback
|
|
(None, "draw"), # malformed body -> neutral fallback
|
|
({"goals": "2", "opponentGoals": 1}, "draw"), # non-int -> no guess
|
|
]
|
|
for body, expect in cases:
|
|
got, _ = U._match_result(body)
|
|
check("result %r -> %s" % (body, expect), got == expect, "got %s" % got)
|
|
|
|
# a 0-0 draw must not be mistaken for "no data"
|
|
r, s = U._match_result({"goals": 0, "opponentGoals": 0})
|
|
check("0-0 is a draw with a score", r == "draw" and s == (0, 0), "%s %s" % (r, s))
|
|
|
|
|
|
# ---- destroy_match_body: the reward record ----------------------------------
|
|
REQUIRED_INT = ("coins", "allCoins", "matchCoins", "seasonCoins", "tournamentCoins",
|
|
"boostConis", "participationAward", "qualifiedChampionEventId")
|
|
|
|
|
|
def test_reward_body():
|
|
b = U.destroy_match_body("won", 400, 13000)
|
|
for k in REQUIRED_INT:
|
|
check("reward.%s present" % k, k in b)
|
|
check("reward.%s is int (scalar, not nested)" % k,
|
|
isinstance(b.get(k), int) and not isinstance(b.get(k), bool), repr(b.get(k)))
|
|
check("reward.teamOfTournamentWinner is bool",
|
|
isinstance(b.get("teamOfTournamentWinner"), bool), repr(b.get("teamOfTournamentWinner")))
|
|
check("coins echoes the credited amount", b["coins"] == 400, repr(b["coins"]))
|
|
check("allCoins is the NEW balance", b["allCoins"] == 13000, repr(b["allCoins"]))
|
|
# EA's typo is load-bearing: the atom is 96 == "boostConis", not "boostCoins".
|
|
check("key is EA's misspelled boostConis", "boostConis" in b and "boostCoins" not in b,
|
|
repr(sorted(b)))
|
|
# nested members must stay OUT (all SKIP-safe; userData is a freeze-risk)
|
|
for k in ("userData", "gameModeAward", "matchCoinMultipliers"):
|
|
check("reward omits nested %s" % k, k not in b)
|
|
# nothing non-scalar may sneak in
|
|
for k, v in b.items():
|
|
check("reward.%s is scalar" % k, isinstance(v, (int, bool, str)), repr(v))
|
|
|
|
|
|
def test_payout_table():
|
|
for res in ("won", "draw", "loss"):
|
|
b = U.destroy_match_body(res, U.MATCH_COINS[res], 0)
|
|
check("matchCoins matches the %s payout" % res,
|
|
b["matchCoins"] == U.MATCH_COINS[res], repr(b["matchCoins"]))
|
|
check("win pays >= draw", U.MATCH_COINS["won"] >= U.MATCH_COINS["draw"])
|
|
check("draw pays >= loss", U.MATCH_COINS["draw"] >= U.MATCH_COINS["loss"])
|
|
|
|
|
|
def main():
|
|
for t in (test_result_detection, test_reward_body, test_payout_table):
|
|
try:
|
|
t()
|
|
except Exception as e:
|
|
_fail.append("%s raised %s: %s" % (t.__name__, type(e).__name__, e))
|
|
print("\n%d checks passed, %d failed" % (_pass, len(_fail)))
|
|
for f in _fail:
|
|
print(" FAIL:", f)
|
|
return 0 if not _fail else 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|