Skip to content

test: add tests for lib/wallet.ts - #435

Open
ugoocreates-pixel wants to merge 1 commit into
AnchorNet-Org:mainfrom
ugoocreates-pixel:fix/wallet-tests
Open

test: add tests for lib/wallet.ts#435
ugoocreates-pixel wants to merge 1 commit into
AnchorNet-Org:mainfrom
ugoocreates-pixel:fix/wallet-tests

Conversation

@ugoocreates-pixel

Copy link
Copy Markdown

Closes #427

Coverage Inventory

  • wallet.ts exports: saveAccount, loadAccount, clearAccount, truncateAddress, mockAddress, STORAGE_KEY.
  • useWallet.test.ts: Covers none of the above. It only tests the useWallet hook to ensure it throws when used outside a WalletProvider.

The Defect (Mocking Strategy & Incorrect Assumptions)

The issue description assumed that wallet.ts implements a real wallet integration with error paths like "Provider absent", "User rejection", and "Chain mismatch". However, as documented in wallet.ts, this module is purely a mock / stand-in that stores a deterministic fake address in localStorage.

Since the module does not integrate with any real wallet provider (like Freighter), these assumed error paths and listeners do not exist in wallet.ts. I have reported these "untested paths" as .todo() in the test suite to formally acknowledge them as defects (i.e. the promised feature doesn't exist).

I have written tests for the actual exposed methods, verifying:

  • Successful saving, loading, and clearing of accounts from localStorage
  • The loadAccount error paths (invalid JSON, missing address, regex validation failure)
  • Address truncation formatting
  • Deterministic seed generation in mockAddress

Closes #<n>.

### Coverage Inventory
* **wallet.ts exports**: `saveAccount`, `loadAccount`, `clearAccount`, `truncateAddress`, `mockAddress`, `STORAGE_KEY`.
* **useWallet.test.ts**: Covers *none* of the above. It only tests the `useWallet` hook to ensure it throws when used outside a `WalletProvider`.

### The Defect (Mocking Strategy & Incorrect Assumptions)
The issue description assumed that `wallet.ts` implements a real wallet integration with error paths like "Provider absent", "User rejection", and "Chain mismatch". However, as documented in `wallet.ts`, this module is purely a mock / stand-in that stores a deterministic fake address in `localStorage`.

Since the module does not integrate with any real wallet provider (like Freighter), these assumed error paths and listeners **do not exist** in `wallet.ts`. I have reported these "untested paths" as `.todo()` in the test suite to formally acknowledge them as defects (i.e. the promised feature doesn't exist).

I have written tests for the actual exposed methods, verifying:
- Successful saving, loading, and clearing of accounts from `localStorage`
- The `loadAccount` error paths (invalid JSON, missing address, regex validation failure)
- Address truncation formatting
- Deterministic seed generation in `mockAddress`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

src/lib/wallet.ts is the only module in src/lib/ with no test file

1 participant