Test wallet package
The @solana/test-wallet package is a private, scriptable Wallet Standard wallet for browser and agent-driven tests. It gives wallet-adapter integrations a real signing identity with controlled approvals, so tests can cover wallet use without a user wallet extension. See Test wallet interactions and approvals for the detailed request and approval model.
Test wallet purpose
The test wallet models the boundary between a dApp and an installed wallet. It can expose selected Wallet Standard features, connect accounts, sign messages and transactions, and submit signed transactions to a configured Solana RPC endpoint. Its signatures use real key pairs, so tests can verify results on a validator rather than use placeholder data.
The package supports two related test settings:
- Browser sessions: A generated script registers the wallet in the page's Wallet Standard registry.
- In-process tests:
createTestWalletreturns a wallet and its controls for direct registration in a test.
References: packages/…/README.md• L1-5 packages/…/index.ts• L1-12
Browser wallet setup
The browser setup turns a key pair and run settings into a self-registering script. The script creates the wallet, exposes test controls on window.__testWallet, and registers the wallet before the dApp discovers wallets.
The setup flow connects a funded test identity to a browser dApp:
flowchart LR
A[Init script options] --> B[Bundled browser script]
B --> C[Create signer and test wallet]
C --> D[Register with Wallet Standard]
D --> E[Wallet adapter discovers Test Wallet]
E --> F[Connect, sign, or send]
F --> G[Configured Solana RPC]
The script accepts a fresh key pair or a Solana CLI key pair. It also fixes the wallet name, advertised chains, RPC endpoint, signing mode, and optional approval delay for that browser run. Because the script contains the secret key, it is only suitable for throwaway keys on a local validator or devnet.
References: packages/…/browser.ts• L7-15 packages/…/browser.ts• L22-45 packages/…/init-script.mjs• L14-22 packages/…/init-script.mjs• L60-126 packages/…/README.md• L7-22
In-process wallet setup
createTestWallet provides the same wallet behavior without a browser bundle. A test selects the wallet features, accounts or signers, chains, transaction versions, RPC endpoint, and approval mode. The returned wallet can then be registered with Wallet Standard in the test environment.
The package defaults to one generated account and a small set of connection, event, message-signing, and transaction-signing features. The full browser wallet enables the broader feature set needed for end-to-end flows, including sign-in, off-chain message signing, and transaction submission.
References: packages/…/wallet.ts• L17-44 packages/…/wallet.ts• L90-113 packages/…/README.md• L49-60
Wallet behavior
The wallet keeps accounts hidden until a normal connection is approved. A silent connection can return accounts that were already approved, which lets tests model autoconnect without bypassing a first-time user decision. Disconnect clears the exposed accounts, while standard events let the dApp observe wallet changes.
References: packages/…/wallet.ts• L143-145 packages/…/wallet.ts• L361-399 packages/…/wallet-test.ts• L62-96
Every enabled signing feature passes through the same approval boundary before it signs. The wallet gives the approver a safe summary of message or transaction inputs, then signs with the selected test account. Transaction submission adds the final RPC step after signing, so the test can cover both wallet authorization and validator acceptance.
References: packages/…/wallet.ts• L134-171 packages/…/wallet.ts• L172-203 packages/…/wallet.ts• L263-360
Approval control
Approval control is the shared seam between wallet requests and the test driver. In auto mode requests resolve at once or after a configured delay. In manual mode requests remain pending until the driver approves or rejects their request ID, which allows tests to exercise loading, acceptance, and user-rejection paths.
Browser drivers use window.__testWallet to inspect pending requests and change decisions during a live session. In-process tests use the returned approval queue directly. The queue reports request methods and compact inputs rather than raw transaction bytes, so a test can decide based on the account, message, fee payer, instruction count, and invoked programs.
References: packages/…/approvals.ts• L6-26 packages/…/approvals.ts• L28-71 packages/…/browser.ts• L32-44 packages/…/wallet.ts• L63-81 packages/…/README.md• L34-47
Test setup
The package keeps unit tests beside the source and runs them with Vitest through the package's test:unit script. The test scope covers both the approval queue contract and the wallet contract. The wallet tests check connection visibility, silent connection behavior, message and transaction summaries, real signing output, and support for lookup-table transactions. The approval tests check timing, manual decisions, rejection errors, invalid IDs, and mode changes.
The package also checks types without emitting build output. Separate lint and format checks cover the source and bundling script. The browser artifact is built with the package's bundle command, which embeds the chosen browser configuration into a single script.
References: packages/…/package.json• L14-22 packages/…/vitest.config.ts• L1-7 packages/…/tsconfig.json• L1-8
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the browser configuration,
window.__testWalletcontrols, andcreateTestWalletoptions aligned so browser and in-process tests exercise the same wallet contract. - Keep advertised Wallet Standard feature names consistent with the feature implementations and the wallet-adapter capabilities that consume them.
- Keep the transaction summary stable when transaction formats or address-lookup handling change because manual approval drivers use it as their decision input.
- Keep the RPC submission contract aligned with the configured validator and the advertised transaction versions.
- Treat generated browser scripts as secret-bearing test artifacts and use only throwaway key pairs.
- Keep the package's unit, type, lint, format, and browser-bundle commands aligned with its Node.js runtime and package entry point.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| The browser script uses a key with real funds | The script exposes the private key to the page and generated artifact | Use throwaway keys on localnet or devnet only. |
signAndSendTransaction is enabled without an RPC URL | The wallet can sign the request but cannot submit it | Configure rpcUrl or omit the feature. |
| A manual request is not approved or rejected | The dApp operation remains pending | Inspect the pending queue and decide each request ID. |
| A silent connect runs before a manual normal connect | No account is exposed and autoconnect does not prompt | Approve a normal connect before relying on silent reconnect. |
| The test requests an account that is not owned by the wallet | The request fails with an unknown-account error | Use an address from the wallet's configured signers. |
Key files
| File | Why to read it |
|---|---|
| packages/…/README.md | Shows the package purpose, browser workflow, safety limits, manual controls, and in-process example. |
| packages/…/index.ts | Defines the public package surface for wallet creation and approval control. |
| packages/…/wallet.ts | Defines the wallet contract, account visibility, signing features, transaction submission, and returned test controls. |
| packages/…/browser.ts | Connects the bundled browser configuration to the page-level test controls and Wallet Standard registration. |
| packages/…/approvals.ts | Defines the shared auto and manual approval behavior. |
| packages/…/init-script.mjs | Builds the self-registering browser script from command-line test settings. |
| packages/…/wallet-test.ts | Demonstrates the wallet behavior and the guarantees around request summaries and signatures. |
| packages/…/approvals-test.ts | Demonstrates the approval queue timing, decisions, errors, and mode changes. |
| packages/…/package.json | Defines the package entry point and the unit, type, lint, format, and browser-bundle checks. |