test: add tests for lib/wallet.ts - #435
Open
ugoocreates-pixel wants to merge 1 commit into
Open
Conversation
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`
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.
Closes #427
Coverage Inventory
wallet.tsexports:saveAccount,loadAccount,clearAccount,truncateAddress,mockAddress,STORAGE_KEY.useWallet.test.ts: Covers none of the above. It only tests theuseWallethook to ensure it throws when used outside aWalletProvider.The Defect (Mocking Strategy & Incorrect Assumptions)
The issue description assumed that
wallet.tsimplements a real wallet integration with error paths like "Provider absent", "User rejection", and "Chain mismatch". However, as documented inwallet.ts, this module is purely a mock / stand-in that stores a deterministic fake address inlocalStorage.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:
localStorageloadAccounterror paths (invalid JSON, missing address, regex validation failure)mockAddress