[TEST] Add Vitest unit tests for lib/walletAdapter.ts#414
Merged
Samuel1-ona merged 1 commit intoJun 1, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds comprehensive Vitest unit tests for lib/walletAdapter.ts, which is a critical integration point between the UI and the Freighter wallet. This file previously had no unit test coverage, meaning bugs could silently break all wallet interactions.
Changes
Created lib/tests/walletAdapter.test.ts with 289 lines of tests covering:
Test Cases Covered
getPublicKey() returns correct address format
Tests successful public key retrieval from Freighter
Validates Stellar address format (G-prefixed, 56 characters)
signTransaction() rejects when wallet is locked
Tests rejection when Freighter returns error (e.g., user rejected, wallet locked)
Tests rejection when no signed XDR is returned
isConnected() returns false when Freighter is not installed
Tests error handling when Freighter extension is not available
Tests browser environment validation
Error cases mapped to user-friendly messages
Verifies all error scenarios return clear, actionable error messages
Tests mapping of technical errors to user-friendly text
Additional Test Coverage
Session Management: getStoredWalletSession(), setStoredWalletSession(), clearStoredWalletSession()
Active Adapter: getActiveWalletAdapter() with Freighter provider
Connection Flow: connectWalletProvider() with Freighter
Edge Cases: Window undefined scenarios, localStorage parsing errors, invalid session data
Implementation Details
Uses vi.mock for @stellar/freighter-api module mocking as specified in the issue
Follows existing test patterns from walletAdapterXBull.test.ts
Uses Vitest with jsdom environment
Mocks localStorage and window objects appropriately
closes #339