213 lines
9.2 KiB
Lua
213 lines
9.2 KiB
Lua
-- Exercise the installed SuperDistrict Lua against the engine's Glue save
|
|
-- contract. No live account, server, or client is opened by this fixture.
|
|
local path = assert(arg[1], "SuperDistrict candidate required");
|
|
local tocPath = assert(arg[2], "Glue SavedVariables TOC candidate required");
|
|
local tocFile = assert(io.open(tocPath, "rb"));
|
|
local toc = tocFile:read("*a"); tocFile:close();
|
|
local declaration = "## SavedVariablesMachine: g_collapsedServerAlert, " ..
|
|
"g_characterSelectToolTrayCollapsed, g_newGameModeAvailableAcknowledged, " ..
|
|
"g_octoLastRealmIdentity";
|
|
assert(toc:find(declaration, 1, true), "Glue machine variable not registered");
|
|
assert(toc:find("## AllowLoad: Glue",1,true), "TOC must load in Glue");
|
|
assert(toc:find("## LoadOnDemand: 0",1,true), "TOC must load automatically");
|
|
|
|
local function widget()
|
|
local value = {enabled=true};
|
|
function value:SetText(text) self.value=text; end
|
|
function value:GetText() return self.value; end
|
|
function value:SetEnabled(enabled) self.enabled=enabled; end
|
|
function value:SetDisabledTooltip() end
|
|
function value:SetShown() end
|
|
function value:SetChecked() end
|
|
function value:Hide() end
|
|
function value:Show() end
|
|
function value:Layout() end
|
|
function value:SetupMenu() end
|
|
function value:SetWidth() end
|
|
return value;
|
|
end
|
|
|
|
local firstRow = {name="Octo PvE", address="play.octowow.st:8085", type=0,
|
|
flags=0, characters=1, category=1, wire_id=5, population_text="0.5"};
|
|
local movedRow = {name="Octo PvE", address="192.0.2.25:8085", type=0,
|
|
flags=0, characters=1, category=1, wire_id=5, population_text="0.5"};
|
|
local secondRow = {name="Octo PvP", address="play.octowow.st:8086", type=1,
|
|
flags=0, characters=0, category=1, wire_id=6, population_text="0.7"};
|
|
local snapshot = {abi=1, size=64, generation=51, endpoint_kind=0, state=5,
|
|
error=0, auth_result=0, discovery_result=0, server_proof_verified=1,
|
|
realm_count=2, selected_index=-1, transport_prepared=0, cancel=0,
|
|
genuine_discovery=1, auth_port=3724, copied_realms=2,
|
|
r0=firstRow, r1=secondRow};
|
|
local requests = {};
|
|
C_Login = {
|
|
GetTurtleRealmSnapshot=function() return snapshot; end,
|
|
RequestTurtleRealm=function(index,generation)
|
|
requests[#requests+1]={index=index,generation=generation}; return 0;
|
|
end,
|
|
GetSubRegions=function() return {}; end,
|
|
GetCurrentSubRegion=function() end,
|
|
SetCurrentSubRegion=function() end,
|
|
};
|
|
C_DistrictUtils={GetAvailableSuperDistricts=function() return {}; end};
|
|
EventRegistry={RegisterCallback=function() end,TriggerEvent=function() end};
|
|
function SetLoginScreenModel() end
|
|
function CreateFromMixins(...)
|
|
local value={};
|
|
for _, mixin in ipairs({...}) do
|
|
for key, member in pairs(mixin) do value[key]=member; end
|
|
end
|
|
return value;
|
|
end
|
|
SelectableButtonMixin,DisabledTooltipButtonMixin={},{};
|
|
function StaticPopup_Show() error("unexpected popup"); end
|
|
NarrationUtil={RegionToNarrationInfo=function() end};
|
|
SOUNDKIT={}; function PlaySound() end
|
|
function CreateFramePoolCollection()
|
|
return {CreatePool=function() end, ReleaseAll=function() end,
|
|
Acquire=function()
|
|
local button=CreateFromMixins(SuperDistrictButtonMixin,widget());
|
|
button.Title,button.Description=widget(),widget();
|
|
button.Icon={SetTexture=function() end,GetTexture=function() end,
|
|
SetDesaturated=function() end};
|
|
button.Background={SetDesaturated=function() end};
|
|
button.Circle={SetDesaturated=function() end};
|
|
function button:SetAlpha() end
|
|
function button:SetMotionScriptsWhileDisabled() end
|
|
function button:SetScript() end
|
|
return button;
|
|
end};
|
|
end
|
|
|
|
local function newFrame()
|
|
local frame=CreateFromMixins(SuperDistrictMixin);
|
|
frame.Title,frame.Description=widget(),widget();
|
|
frame.SelectButton,frame.SubRegionDropdown,frame.ButtonLayout=widget(),widget(),widget();
|
|
frame.Title:SetText("old title"); frame.Description:SetText("old description");
|
|
frame.SelectButton:SetText("old select");
|
|
function frame:RegisterEvent() end
|
|
function frame:HookScript(name,callback)
|
|
assert(name=="OnUpdate"); self.onUpdate=callback;
|
|
end
|
|
frame:OnLoad();
|
|
return frame;
|
|
end
|
|
|
|
C_Login.GetState = function() return {connectedToWoW=false}; end;
|
|
C_Login.DisconnectFromServer = function() end;
|
|
-- These match the native SHA-256 test vectors for the synthetic game accounts.
|
|
local a = "55bcd3a1fabf2e35d04e0cecb302defe529ebbbd6b1166d437da256fab6c5d77";
|
|
local b = "120e60e450bfe6245ed4143816979c138b747c4a5723d673381bccfe7e680111";
|
|
local headerFields = {"abi", "size", "generation", "endpoint_kind", "state", "error",
|
|
"auth_result", "discovery_result", "server_proof_verified", "realm_count",
|
|
"selected_index", "transport_prepared", "cancel", "auth_port", "copied_realms",
|
|
"genuine_discovery", "source_login_readiness"};
|
|
local generationReads, tornGeneration = 0, false;
|
|
function C_Login.GetTurtleRealmSnapshot(query, index, field)
|
|
if query == 4 then return 0; end
|
|
if query == 0 then
|
|
if index == 0 then generationReads = 0; return 0; end
|
|
if index == 3 then
|
|
generationReads = generationReads + 1;
|
|
if tornGeneration and generationReads > 1 then return snapshot.generation + 1; end
|
|
end
|
|
if index <= #headerFields then return snapshot[headerFields[index]] or 0; end
|
|
local digest = snapshot.account_preference_key;
|
|
if index > 33 or type(digest) ~= "string" or #digest ~= 64 then return -4006; end
|
|
local start = 1 + (index - 18) * 4;
|
|
return tonumber(digest:sub(start, start + 3), 16) or -4006;
|
|
end
|
|
local row = snapshot["r" .. index];
|
|
if query == 1 then
|
|
return ({row.type, row.flags, row.characters, row.category, row.wire_id, 0x3f000000})[field + 1];
|
|
end
|
|
local value = query == 2 and row.name or row.address;
|
|
return (value:byte(1 + field * 3) or 0) + (value:byte(2 + field * 3) or 0) * 256
|
|
+ (value:byte(3 + field * 3) or 0) * 65536;
|
|
end
|
|
local function enterAccount(key)
|
|
snapshot.generation = snapshot.generation + 1;
|
|
snapshot.state, snapshot.selected_index, snapshot.transport_prepared = 5,-1,0;
|
|
snapshot.account_preference_key = key;
|
|
snapshot.r0, snapshot.r1 = firstRow, secondRow;
|
|
snapshot.copied_realms, snapshot.realm_count = 2,2;
|
|
requests = {};
|
|
assert(loadfile(path))();
|
|
return newFrame();
|
|
end
|
|
local function choose(frame,index)
|
|
frame:UpdateSelection(frame.districtButtons[index+1].superDistrictID);
|
|
frame:ConfirmSuperDistrict();
|
|
assert(#requests==1 and requests[1].index==index);
|
|
end
|
|
local function roster(frame,index)
|
|
snapshot.state,snapshot.selected_index,snapshot.transport_prepared = 2,index,1;
|
|
frame:OnEvent("CHARACTER_LIST_UPDATE");
|
|
end
|
|
|
|
-- The older numeric provider does not expose digest words. A legacy scalar has no owner.
|
|
local legacy = "v2|Octo%20PvE|5";
|
|
g_octoLastRealmIdentity = legacy;
|
|
local frame = enterAccount(nil);
|
|
assert(#requests==0);
|
|
choose(frame,1);
|
|
roster(frame,1);
|
|
assert(g_octoLastRealmIdentity == legacy);
|
|
|
|
-- When a snapshot contains an application-supplied, generation-bound key,
|
|
-- an explicit choice commits only after the server supplies its character list.
|
|
frame=enterAccount(a);
|
|
assert(#requests==0);
|
|
choose(frame,0);
|
|
assert(g_octoLastRealmIdentity==legacy);
|
|
frame:OnEvent("CHARACTER_LIST_UPDATE"); -- wrong state, cannot commit
|
|
assert(g_octoLastRealmIdentity==legacy);
|
|
frame=enterAccount(a);
|
|
choose(frame,0);
|
|
roster(frame,0);
|
|
assert(g_octoLastRealmIdentity[a]==legacy);
|
|
|
|
-- A distinct account with the same realm rows must choose independently.
|
|
frame=enterAccount(b);
|
|
assert(#requests==0);
|
|
choose(frame,1);
|
|
roster(frame,1);
|
|
assert(g_octoLastRealmIdentity[b]=="v2|Octo%20PvP|6" and g_octoLastRealmIdentity[a]==legacy);
|
|
frame=enterAccount(a);
|
|
assert(#requests==1 and requests[1].index==0);
|
|
frame=enterAccount(b);
|
|
assert(#requests==1 and requests[1].index==1);
|
|
frame=enterAccount(string.rep("32ab",15) .. "xx11");
|
|
assert(#requests==0);
|
|
|
|
tornGeneration=true;
|
|
frame=enterAccount(a);
|
|
assert(#requests==0, "generation changed while reading digest");
|
|
tornGeneration=false;
|
|
-- A stale roster, cancellation, or a failed or discarded account scope never writes.
|
|
for _,kind in ipairs({"generation","account","cancel","auth-error","wrong-realm"}) do
|
|
local c=string.rep("c",64);
|
|
frame=enterAccount(c);
|
|
choose(frame,1);
|
|
if kind=="generation" then snapshot.generation=snapshot.generation+1;
|
|
elseif kind=="account" then snapshot.account_preference_key=a;
|
|
elseif kind=="cancel" then frame:OnCancel();
|
|
elseif kind=="auth-error" then snapshot.error=1;
|
|
end
|
|
roster(frame,kind=="wrong-realm" and 0 or 1);
|
|
assert(g_octoLastRealmIdentity[c]==nil,kind);
|
|
snapshot.error=0;
|
|
end
|
|
|
|
-- A saved realm can appear in a later snapshot for the same generation.
|
|
g_octoLastRealmIdentity[a]="v2|Octo%20PvE|5";
|
|
frame=enterAccount(nil); requests={};
|
|
snapshot.account_preference_key=a;
|
|
snapshot.r0=secondRow; snapshot.r1=nil; snapshot.copied_realms,snapshot.realm_count=1,1;
|
|
frame:onUpdate(0.5);
|
|
assert(#requests==0);
|
|
snapshot.r1=firstRow; snapshot.copied_realms,snapshot.realm_count=2,2;
|
|
frame:onUpdate(0.5);
|
|
assert(#requests==1 and requests[1].index==1);
|
|
frame:onUpdate(0.5); assert(#requests==1);
|
|
print("PASS numeric account isolation, manual unknown-account fallback, confirmed roster persistence, late-list resolution");
|