Polkadot Apps
    Preparing search index...
    • Write a valid persisted session to storageDir, as if the user had completed QR pairing + attestation. A TerminalAdapter created with the same appId + storageDir will emit the synthesized session from adapter.sessions.sessions.

      • Signing does not round-trip. Sending a request via session.signRaw still goes out over the statement store and expects a real phone to respond. Use this helper for flows that test session discovery, persistence, and logout — not end-to-end signing.
      • Signing attempts surface NoAllowanceError. The synthesized local account was never registered on the People chain, so the first write to the statement store fails with NoAllowanceError. That's the same error path the CLI sees when a previously valid session's on-chain attestation has expired, so tests that assert "CLI handles an expired session" can be written against a synthesized session even though there's no expiresAt knob to turn.
      • No expiresAt. The on-disk codec has no expiry field; validity is tracked via on-chain attestation state. See above for how expiry-path tests still work in practice.
      • Corrupted-session cases don't need a helper — write garbage to <storageDir>/<appId>_SsoSessions.json with fs.writeFile directly.
      • Repeated calls replace the session list. Each call writes a fresh single-entry SsoSessions file, so calling twice on the same storageDir+appId leaves only the second session on disk. Use a fresh mkdtempSync per test to keep cases isolated.

      Parameters

      Returns Promise<TestSession>

      import { mkdtempSync } from "node:fs";
      import { tmpdir } from "node:os";
      import { join } from "node:path";
      import { createTestSession } from "@polkadot-apps/terminal/testing";
      import { createTerminalAdapter, waitForSessions } from "@polkadot-apps/terminal";

      const storageDir = mkdtempSync(join(tmpdir(), "e2e-"));
      const { sessionId } = await createTestSession({ appId: "dot-cli", storageDir });

      const adapter = createTerminalAdapter({ appId: "dot-cli", metadataUrl: "…", storageDir });
      const sessions = await waitForSessions(adapter);
      // sessions[0].id === sessionId