Introducing a new way to review your PRs.

Read the announcement

solana-foundation / solana-web3.js

Solana JavaScript SDK

View on GitHub

23 documents · Updated Nov 16, 2026

docs / test-wallet-interactions-and-approvals

Test wallet interactions and approvals

The test wallet is a scriptable Wallet Standard wallet for browser and end-to-end tests. It lets a dApp discover a wallet, connect an account, sign messages or transactions, and submit real transactions to a Solana endpoint. Its approval queue makes each user decision either immediate or controlled by the test.

Browser integration

The browser form registers the test wallet before the dApp starts. This makes the wallet appear through the normal Wallet Standard discovery path instead of through a test-only adapter.

Init script

The fully qualified path packages/…/init-script.mjs builds a self-registering browser script from a keypair, RPC URL, chain list, wallet name, and approval mode. The script is loaded before the page so wallet discovery can find the registered wallet during page setup. The generated script contains the secret key, so it is only suitable for throwaway keys on a local validator or test network.

References: packages/…/init-script.mjs• L14-22 packages/…/init-script.mjs• L86-117 packages/…/browser.ts• L22-45

Browser controls

The browser wallet exposes a small control surface at window.__testWallet. A browser driver can read the wallet address and current mode, inspect pending requests, approve or reject a request by ID, and change the mode while the page is running. These controls let an end-to-end test reproduce both an accepted wallet prompt and a user rejection.

References: packages/…/browser.ts• L32-43 packages/…/approvals.ts• L40-70 packages/…/README.md• L34-47

Wallet behavior

The wallet follows Wallet Standard contracts while using real Solana keypair signers. It advertises only the features selected by the test, which lets wallet-adapter flows test both complete wallets and wallets with limited capabilities.

Connection lifecycle

The wallet starts with no visible accounts. A normal connect request must pass approval before the account becomes available. A silent connect does not prompt in manual mode; it returns only accounts that were already approved. Disconnect removes the visible accounts, and the wallet can notify registered listeners when a dApp watches wallet events.

References: packages/…/wallet.ts• L143-145 packages/…/wallet.ts• L361-385 packages/…/wallet-test.ts• L62-96

Signing and submission

The wallet can sign plain messages, off-chain messages, sign-in messages, and serialized transactions. It preserves the approved input before signing, so the result represents the request that the test inspected. Transaction signing returns signed bytes, while sign-and-send signing submits those bytes to the configured RPC endpoint and returns the validator signature.

The wallet reports transaction facts in an approval summary rather than exposing the full transaction to the approval control. The summary identifies the account, fee payer, instruction count, invoked programs, and transaction version. This gives a test enough data to verify what the user approved while keeping the browser control simple.

References: packages/…/wallet.ts• L63-81 packages/…/wallet.ts• L172-359 packages/…/wallet-test.ts• L98-204

Feature and network compatibility

The wallet advertises its supported chains, message features, and transaction versions. wallet-adapter uses those declarations to expose or disable matching actions. End-to-end coverage therefore checks both successful actions and the absence of actions that the selected wallet cannot perform.

References: packages/…/wallet.ts• L17-44 packages/…/wallet.ts• L90-123 packages/…/example-page-live-test.tsx• L176-192

Approval mechanisms

The approval queue stands in for the prompt that a real wallet shows to a user. Every connect or signing request passes through the queue before the wallet creates a signature or submits a transaction.

Automatic approval

Automatic mode resolves each request without external control. An optional delay adds a predictable pause before approval, which allows tests to observe loading states without changing the wallet result. This is the normal mode for browser flows that need real signatures with no prompt-handling step.

References: packages/…/approvals.ts• L22-31 packages/…/approvals.ts• L55-67 packages/…/approvals-test.ts• L9-32

Manual approval

Manual mode holds each request in a pending set and assigns it an ID. The test reads the method and one safe summary for each input, then calls approve(id) or reject(id). Approval allows the wallet action to continue. Rejection returns the standard Wallet Standard user-rejected error to the dApp.

References: packages/…/approvals.ts• L8-14 packages/…/approvals.ts• L34-70 packages/…/approvals-test.ts• L34-61

Mode changes

The mode can change while the wallet runs. New requests use the new mode, which lets a test begin with controlled prompts and then switch to automatic behavior for later actions. A mode change does not itself resolve requests that are already waiting for a manual decision.

References: packages/…/approvals.ts• L40-70 packages/…/approvals-test.ts• L63-70

End-to-end wallet flow

The browser and in-process forms drive the same product behavior. Browser tests load the init script before the dApp, while in-process tests register the wallet directly with the Wallet Standard registry. Both paths then exercise connection, capability checks, approval, signing, and optional submission.

This diagram shows how a dApp request moves through discovery and approval to a result.

flowchart LR
    A[DApp discovers wallet] --> B[Wallet Standard request]
    B --> C{Approval mode}
    C -->|auto| D[Approve now or after delay]
    C -->|manual| E[Pending request]
    E --> F{Test decision}
    F -->|approve| D
    F -->|reject| G[User-rejected error]
    D --> H[Sign with test keypair]
    H --> I{Transaction request?}
    I -->|no| J[Return signature or signed data]
    I -->|yes, sign only| J
    I -->|yes, sign and send| K[Submit to configured RPC]
    K --> L[Return transaction signature]

Live wallet-adapter tests register wallets with different chains, features, and transaction versions. They use a local Surfnet validator to verify message signatures and transaction effects, so the tests cover both adapter behavior and the result seen on the network.

References: packages/…/app-live-test.tsx• L49-110 packages/…/example-page-live-test.tsx• L21-60 packages/…/README.md• L10-22

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the browser control names and request IDs aligned with the init-script examples and browser drivers.
  • Keep advertised feature names and transaction-version support aligned with wallet-adapter capability checks.
  • Keep approval summaries stable when tests use them to inspect the account, fee payer, programs, or message text.
  • Keep the RPC submission contract aligned with the endpoint used by browser and live-validator tests.
  • Treat generated init scripts as test credentials. Do not use a real funded wallet key.

Important failure modes

TriggerConsequenceGuard
Manual mode receives no approve or reject callThe dApp request stays pending and the browser flow does not finishInspect window.__testWallet.pending() and decide each request
A silent connect runs before a manual normal connect is approvedThe dApp sees no account and autoconnect does not establish a sessionApprove a normal connect before relying on silent connect
signAndSendTransaction has no RPC URLThe wallet cannot submit the signed transactionConfigure the RPC endpoint when creating or bundling the wallet
The wallet does not advertise a requested feature or transaction versionwallet-adapter disables the matching action or rejects the flowSelect the required feature and supported version for the scenario
The init script uses a real or valuable secret keyThe key is exposed in browser script textUse a throwaway key on a local validator or test network

Key files

FileWhy to read it
packages/…/wallet.tsDefines the Wallet Standard surface, account lifecycle, signing behavior, and RPC submission path
packages/…/approvals.tsDefines automatic and manual approval behavior and the user-rejection contract
packages/…/browser.tsConnects the wallet to the browser registry and exposes test controls
packages/…/init-script.mjsDefines how browser-ready wallet scripts are configured and built
packages/…/wallet-test.tsShows the expected connection, message, off-chain message, and transaction behavior
packages/…/approvals-test.tsShows the guarantees for delay, pending requests, rejection, and mode changes
packages/…/example-page-live-test.tsxShows live adapter flows across wallet features, transaction versions, networks, and UI actions
packages/…/app-live-test.tsxShows wallet registration, capability filtering, signature checks, and real transaction effects
docs/test-wallet.mdParent page for the wider test-wallet system overview