run_presets.py raw
1 #!/usr/bin/env python3
2 """Show the baked indexer presets in the page, and the fail-closed shape of a fetch whose sources
3 have not seen the transactions (the dossier here is synthetic, so it must not pass)."""
4
5 import asyncio
6 import os
7
8 from playwright.async_api import async_playwright
9
10 HERE = os.path.dirname(os.path.abspath(__file__))
11 PROFILE = os.path.join(HERE, "chromium-profile")
12 PAGE = "http://127.0.0.1:8080/?chains=blake&network=xbt"
13
14
15 async def main():
16 dossier = open(os.path.join(HERE, "dossier.json")).read()
17
18 async with async_playwright() as p:
19 context = await p.chromium.launch_persistent_context(
20 PROFILE, viewport={"width": 1280, "height": 1700})
21 page = context.pages[0] if context.pages else await context.new_page()
22 page.on("console", lambda m: print("console:", m.text))
23
24 cdp = await context.new_cdp_session(page)
25 await cdp.send("Network.clearBrowserCache")
26
27 await page.goto(PAGE, wait_until="load", timeout=60000)
28
29 card = page.locator("#cards .card").first
30 await card.locator("input").nth(0).fill("wss://swaprelay.smesh.lol")
31 await page.get_by_role("button", name="Connect").click()
32 await page.wait_for_function(
33 "document.getElementById('connect-status').textContent.includes('connected')",
34 timeout=120000)
35
36 await page.wait_for_function(
37 "document.querySelectorAll('#indexers input').length > 0", timeout=60000)
38 presets = await page.locator("#indexers").inner_text()
39 print(presets[:600])
40 await page.screenshot(path=os.path.join(HERE, "02-presets.png"), full_page=True)
41
42 await page.locator("#dossier").fill(dossier)
43 await page.get_by_role("button", name="Fetch facts from the selected sources").click()
44 await page.wait_for_timeout(8000)
45 filled = await page.locator("#dossier").input_value()
46 print("sources after fetch:", [s["name"] for s in __import__("json").loads(filled)["sources"]])
47 print("checked:", await page.evaluate(
48 "Array.from(document.querySelectorAll('#indexers input')).filter(i => i.checked).length"))
49 await page.get_by_role("button", name="Verify").click()
50 await page.wait_for_function(
51 "document.getElementById('verify-report').textContent.length > 0", timeout=60000)
52
53 report = await page.locator("#verify-report").inner_text()
54 print("report:", " | ".join(report.splitlines()[:4]))
55 await page.screenshot(path=os.path.join(HERE, "03-fetch-fails-closed.png"), full_page=True)
56
57 await context.close()
58
59
60 asyncio.run(main())
61