import type { ProductId } from "@parity/truapi"; import type { Page, FrameLocator } from "@playwright/test"; import { type ChainStatus, type ChatMessageRecord, type MockHostConfig, type MockRuntimeConfig, type NotificationLogEntry, type PermissionLogEntry, type PermissionPolicy, type PermissionPolicyAlias, type SigningLogEntry, type StatementEntry } from "../web/create-mock-host.js"; import type { HostScan } from "../generated/host-callbacks.js"; import type { HostPaymentStatusSubscribeItem } from "@parity/truapi"; import type { StatementInput } from "../web/loopback-statements.js"; export type { StatementEntry } from "../web/create-mock-host.js"; export type { StatementInput } from "../web/loopback-statements.js"; export { productAccountAddress } from "./product-account.js"; export type { ProductAccountQuery } from "./product-account.js"; import { type NetworkConfig } from "./networks.js"; export { fromNetworks } from "./networks.js"; export type { LoopbackStatements, NetworkConfig } from "./networks.js"; import type { LoginRequestBehavior } from "./login-requests.js"; export { DEFAULT_CHAIN, DEV_ACCOUNTS, LIVE_CHAINS, PASEO_ASSET_HUB, liveChain, } from "./dev-accounts.js"; export { DEV_ACCOUNT_NAMES } from "./dev-accounts.js"; export type { DevAccount, DevAccountName } from "./dev-accounts.js"; export type { HexString } from "@parity/truapi"; export type { ChatMessageRecord as ChatMessageLogEntry, NotificationLogEntry, PermissionLogEntry, PermissionPolicy as PermissionBehavior, SigningLogEntry, } from "../web/create-mock-host.js"; export type { LoginBehavior } from "./host-page.js"; export type { LoginRequestBehavior } from "./login-requests.js"; /** Options for {@link createTestHostFixture}. */ export interface TestHostFixtureOptions { /** URL of the product under test. */ productUrl: string; /** * Base URL of a running host page server. * * Optional. Omit it and the fixture starts one itself, lazily, and shares it * across every test in the file -- bundling is not cached, so one server per * test would pay esbuild each time. Supply it to control the lifetime. */ hostUrl?: string; /** * Chains to serve, in `@parity/host-api-test-sdk`'s `NetworkConfig` shape. * * A convenience over spelling out `mock.chainProxies`, `mock.servedChains` * and `runtimeConfig.testStack` separately, which have to agree. The chain's * role is read from the `id` suffix (`-asset-hub`, `-people`, `-bulletin`, * else the relay) and the rest of the id is the network name. * * Explicit `mock` or `runtimeConfig` values win, so a suite can start here * and override one piece. */ networks?: NetworkConfig[]; /** * A single chain, as older `@parity/host-api-test-sdk` versions spell it. * * Exactly `networks: [chain]`, under the name that vintage uses. Passing * both is refused rather than merged, because guessing which one the author * meant is worse than saying so. */ chain?: NetworkConfig; /** * Accepted only to fail with an explanation. See the error text: TrUAPI * derives a product account from the session root, so it cannot be pinned. */ productAccounts?: Record; /** * dotNS identifier the host runs the product under. * * Must match the identifier the product signs with: the core rejects a * signing request whose account is scoped to a different product, so a * mismatch surfaces as `PermissionDenied` rather than as a config error. */ productId?: ProductId; /** Behaviour knobs forwarded to the mock host, including `chainProxies`. */ mock?: MockHostConfig; /** * Overrides merged into the host's runtime config. * * Proxying a real chain needs this: the core asks for a chain by the genesis * hash the config declares, so that hash has to be the real one rather than * a {@link MOCK_GENESIS} placeholder. */ runtimeConfig?: Partial; /** * Accounts the host can sign as. Defaults to `["alice"]`. * * Objects are accepted for `@parity/host-api-test-sdk` compatibility, but a * `uri` is rejected: a TrUAPI session activates from 32 bytes of entropy, * not a `//Alice`-style derivation path. */ accounts?: (string | { name: string; uri?: string; entropy?: Uint8Array; })[]; /** Whether the host starts signed in. Defaults to `"auto"`. */ loginBehavior?: "auto" | "manual"; /** * Where the core runs. Defaults to `"worker"`, the production topology. * * Switch to `"main-thread"` to debug: the core's log output then reaches the * page console, where `page.on("console")` can read it. Under `"worker"` it * goes to the worker console, which Playwright does not observe -- so a * failing call looks like a bare outcome with no reason attached. */ topology?: "worker" | "main-thread"; /** * How resource allocation is answered. Defaults to `"granted"`. * * `"granted"` answers every request as allocated without performing it, so a * suite exercises its product's allowance-dependent paths with no on-chain * personhood identity. Nothing is allocated, so a pass says the product * handles a grant, not that a host would have given one. * * `"chain"` runs the real allocation against the chains the host serves: * ring membership, slot selection, proof and extrinsic. It fails where a * real host would, which is the point of choosing it. */ allowances?: "granted" | "chain"; /** * Decisions applied before the product loads. * * `resourceAllocation` names resources the host refuses; anything unlisted * stays granted. A boot option rather than a call, because a product asks for * its resources on connect and a later call would land after that. * * A refusal here is answered as refused whatever {@link allowances} would * otherwise say, which is what makes a product's refusal path reachable: with * allocation granted there is nothing a suite could do to see one. */ behaviors?: { resourceAllocation?: Record; }; /** * Serve the statement store in-page instead of forwarding it to the chains * the host proxies. Defaults to on when `allowances` is `"granted"`, so the * two halves of a statement flow agree: a product that is handed an * unregistered allowance key can still submit with it. * * The store rides on the People chain's proxy, or on the single proxy of a * one-chain suite. Several chains with no People among them carry no store: * left to the default the fixture serves none, and `true` is refused, because * attaching it to a hub would answer reads a real hub refuses. * * Nothing submitted this way leaves the page, and a real store would refuse * it. Set `false` to send statements to the chain and see what it says. */ loopbackStatements?: boolean; /** * Core log level (`off`/`error`/`warn`/`info`/`debug`/`trace`). * * The core logs why a call failed before mapping it to a protocol answer, * so this is what turns an opaque outcome into its cause. Pair it with * `topology: "main-thread"` to read those lines from a test. */ logLevel?: string; /** * Product storage the host holds before the product loads, by the product's * own keys, stored as UTF-8. Use it for state a product reads once at * startup, which `seedProductStorage` can land too late for. A reload of * the host page and `reset()` both start from it again. */ productStorage?: Record; /** How long to wait for the host page to publish its control surface. */ readyTimeoutMs?: number; } /** The fixture a test receives. */ export interface TestHost { /** The Playwright page running the host. */ page: Page; /** Locator for the embedded product. */ productFrame(): FrameLocator; getNavigationLog(): Promise; clearNavigationLog(): Promise; getNotificationLog(): Promise; clearNotificationLog(): Promise; getSigningLog(): Promise; clearSigningLog(): Promise; getPermissionLog(): Promise; clearPermissionLog(): Promise; getGrantedPermissions(): Promise; grantPermission(permission: string): Promise; revokePermission(permission: string): Promise; setEnforcePermissions(enforce: boolean): Promise; setPermissionBehavior(behavior: PermissionPolicy | PermissionPolicyAlias): Promise; getChatRooms(): Promise; getChatBots(): Promise; getChatMessageLog(): Promise; clearChatState(): Promise; /** Product-scoped storage the core has written, keyed without the prefix. */ getProductStorage(): Promise>; getPreimages(): Promise; seedPreimage(value: Uint8Array): Promise; /** * Find the value the product stored under `key`. * * The core namespaces product storage keys before the host ever sees them, * so this reads the product's own key back out of that shape rather than * matching the internal string. Answers the bytes, where * {@link TestHost.getProductStorageValue} answers them decoded as UTF-8. */ findProductStorage(key: string): Promise; /** * Store `value` under the product's own `key`, where the core will read it, * as an entry persisted from an earlier session would be. It reaches a * product that subscribes to the key or reads it afterwards, not a read the * product already made at startup; boot-time state goes in `productStorage`. * A string is stored as UTF-8. */ seedProductStorage(key: string, value: Uint8Array | string, productId?: ProductId): Promise; /** * The SS58 address of a product account, at the prefix the core mandates. * * A product account is derived from the active session's root, so this * answers `undefined` while the host is signed out and a different address * after `switchAccount`. Read it here rather than out of the product's own * UI: a suite funding that account, or asserting on it, should not depend on * the product rendering it. * * Encoded at the prefix the core mandates, which is not necessarily the one * the product displays: a product rendering at another prefix shows a * different string for the same account. Compare against a product's own * rendering by decoding both, and pass this to a faucet or a transfer as it * stands. */ getProductAccountAddress(productId?: ProductId, index?: number): Promise; /** * The value the product stored under `key`, decoded as UTF-8. * * `@parity/host-api-test-sdk` spells this `getProductStorageValue` and * returns a string, so a migrating suite's storage assertions compile * unchanged. Use {@link findProductStorage} for a value that is not text. */ getProductStorageValue(key: string): Promise; clearPreimages(): Promise; getTheme(): Promise; setTheme(variant: string): Promise; /** Set the next scan's answer. Throws unless created with a `scanner` answer. */ setScanAnswer(answer: HostScan): Promise; /** * Open the product at `link`, a path with an optional query and hash such * as `/notes/1?view=raw#top`, as a link opened from outside the product * would. The host page loads again with the fixture's configuration, so the * host starts fresh: only state the configuration carries, such as * `productStorage`, is there again. */ openDeepLink(link: string): Promise; /** * Confirm or decline reviews, such as a signature, from now on. One test * can decline a signature without a fixture booted with * `confirmUserActions: false`. A permission the core has cached keeps its * answer. */ setConfirmUserActions(confirm: boolean): Promise; getIsAuthenticated(): Promise; getChainStatus(): Promise; getConnectionStatus(): Promise; /** * Raw JSON-RPC the core sent over the chain connection, in order. * * A chain-path failure is otherwise invisible from a suite: the product * shows a stalled UI and the fixture reports nothing about what the host * asked the chain. This is what tells you whether a request was made at * all, and what came back after it. */ getSentRpc(): Promise; /** Drop the recorded RPC, so one case does not read another's traffic. */ clearSentRpc(): Promise; simulateDisconnect(): Promise; simulateReconnect(): Promise; /** * Wait until the product has an open channel to the host. * * Resolves once the core has answered at least one product call, which is * the first observable evidence that frames are crossing the wire in both * directions. */ waitForConnection(timeoutMs?: number): Promise; /** Names the host can currently sign as. */ getAccounts(): Promise; /** The account the current session is activated from, if any. */ getActiveAccount(): Promise; /** Re-activate the session as `name`. */ switchAccount(name: string): Promise; /** Replace the roster, activating the first entry. */ setAccounts(names: string[]): Promise; /** Drop the session, leaving the host signed out. */ signOut(): Promise; /** Return the host to its constructed state between cases. */ reset(): Promise; /** * Statements the product submitted. * * Always throws. The statement store is core-owned and submission is * rejected inside the core before any RPC is emitted, so there is nothing * for the host to record -- not a host seam the mock declined to implement. */ /** * Statements the product submitted, decoded, read off the chain transport * rather than a host-side log. * * Empty for a product that asks the host to sign * (`createProofAuthorized`): that needs a statement allowance, and without * one no statement is ever built to submit. A product that signs its own * statements is observable here. */ getSubmittedStatements(): Promise; /** Every statement the store holds, submitted or injected, in order. */ getStatements(): Promise; /** * Deliver a statement to the product as a chain notification, answering the * entry the store retained. * * Takes the topics and payload as a structure, or the SCALE wire bytes the * chain would have sent. Retained either way, so a suite that injects before * its product subscribes has the statement replayed to it on subscribe * rather than losing it. */ injectStatement(statement: StatementInput | Uint8Array | string): Promise; /** Statements injected so far, in order. */ getInjectedStatements(): Promise; /** Forget the injected statements. */ clearStatements(): Promise; /** * Release the host. * * A no-op. Playwright owns the page's lifetime and closes it when the test * ends, so a suite has nothing to release. Declared because * `@parity/host-api-test-sdk`'s surface has it, so a teardown call written * against that surface is still valid here. */ dispose(): Promise; /** * Set the spendable balance. Always throws: this host cannot serve * payments, and answers every payment call `Unsupported`. */ setPaymentBalance(amount: bigint): Promise; /** Payment operations the product performed. Always throws; see above. */ getPaymentLog(): Promise; /** Drop the payment log. Always throws; see above. */ clearPaymentLog(): Promise; /** How top-ups resolve. Always throws; see above. */ setPaymentTopUpBehavior(behavior: unknown): Promise; /** * Force the status of the payment with this 32-byte id. Always throws; see * above. The string id and loose status are `@parity/host-api-test-sdk`'s * shapes, still accepted so a suite written against it type-checks. */ simulatePaymentStatus(id: Uint8Array | string, status: HostPaymentStatusSubscribeItem | { tag: string; value?: string; }): Promise; /** * Deliver a peer's activation of a chat action to the product. * * Always throws. `ChatPlatform` is create/register/post/subscribe-rooms only, * so a peer activating an action has no way into the core. `ChatAction` * exists as message *content* a product posts, not as an inbound event. */ /** * Deliver a host-authored Chat action to the product -- the path a posted * message or a tapped `Actions` button takes back to it. * * Takes the `HostChatActionSubscribeItem` the core publishes, not * `@parity/host-api-test-sdk`'s `{roomId, peer, payload}`: this goes through * the core's own action stream, so it carries the core's value. */ injectChatAction(action: unknown): Promise; /** * Answer a product's login request while the host is signed out, as a user * would on a real host. `"success"` signs in `account`, or the first account * when none is named, and the product gets `Success`. `"reject"` answers * `Rejected`. Unset, a signed-out host answers `Rejected`, and a signed-in * one answers `AlreadyConnected` either way, as does a second request made * while the first is signing in. A withdrawn request gets `Cancelled`. * `reset` unsets it. Whether the host starts signed in is the * `loginBehavior` fixture option. */ setLoginBehavior(behavior: LoginRequestBehavior, account?: string): Promise; } /** * The product-storage entry `key` names, or `undefined` when nothing holds it. * * Reads the product's own key out of each stored one with the parse * `getProductStorageValue` uses, so the byte reader and the string reader * cannot disagree about which entry a key names. Falls back to the whole key * for a value written straight through the host seam, which never passed * through the core's namespacing. */ export declare function productStorageEntry(stored: Record, key: string): Uint8Array | undefined; /** * Build the `testHost` fixture. * * ```ts * export const test = base.extend(createTestHostFixture({ * productUrl: "http://127.0.0.1:5173", * hostUrl: server.url, * })); * ``` */ export declare function createTestHostFixture(defaults: TestHostFixtureOptions): { testHost: ({ page }: { page: Page; }, use: (fixture: TestHost) => Promise) => Promise; };