Description
The wallet layer is entirely untested: context/WalletContext.tsx persists {address, name, connected} to localStorage under predictify_wallet_state and reconnects on mount, and hooks/useWallet.hook.ts wraps @creit.tech/stellar-wallets-kit for connectWallet, disconnectWallet, and signTransaction, yet a repo-wide search finds no tests for either. Given wallet state is the core of the app's identity, this issue adds unit tests with the kit mocked.
Requirements and context
- Add
context/__tests__/WalletContext.test.tsx covering: hydration from localStorage on mount, persistence on connect, key removal on disconnect, and that useWalletContext throws outside a provider.
- Add
hooks/__tests__/useWallet.test.tsx mocking getKit() from constants/wallet-kits.constant.ts to cover connectWallet success/failure, disconnectWallet, signTransaction success and the "No wallet connected" guard, and the isConnecting/error state.
- Non-functional: tests must mock
localStorage and the kit (no real wallet); assert the returned discriminated {success, ...} shapes; deterministic with no real async wallet calls.
- Follow the existing Jest + React Testing Library conventions and
jest.setup.js.
Acceptance criteria
Suggested execution
1. Fork the repo and create a branch — git checkout -b feature/wallet-tests.
2. Implement changes — add context/__tests__/WalletContext.test.tsx and hooks/__tests__/useWallet.test.tsx; mock constants/wallet-kits.constant.ts.
3. Write/extend tests — Jest + React Testing Library + renderHook from @testing-library/react with pnpm; mock localStorage and getKit. Mirror the style of lib/__tests__/scroll-position-store.test.ts.
4. Test and commit —
pnpm install
pnpm test
pnpm test:coverage
pnpm lint
Example commit message
test(wallet): cover WalletContext persistence and useWallet connect/disconnect/sign
Guidelines
- Raise wallet coverage from 0% to >=90% line coverage for the two files.
- Note that
collectCoverageFrom in jest.config.js currently omits context/ and hooks/; mention extending it so wallet coverage is reported.
- Timeframe: 96 hours.
Description
The wallet layer is entirely untested:
context/WalletContext.tsxpersists{address, name, connected}tolocalStorageunderpredictify_wallet_stateand reconnects on mount, andhooks/useWallet.hook.tswraps@creit.tech/stellar-wallets-kitforconnectWallet,disconnectWallet, andsignTransaction, yet a repo-wide search finds no tests for either. Given wallet state is the core of the app's identity, this issue adds unit tests with the kit mocked.Requirements and context
context/__tests__/WalletContext.test.tsxcovering: hydration fromlocalStorageon mount, persistence onconnect, key removal ondisconnect, and thatuseWalletContextthrows outside a provider.hooks/__tests__/useWallet.test.tsxmockinggetKit()fromconstants/wallet-kits.constant.tsto coverconnectWalletsuccess/failure,disconnectWallet,signTransactionsuccess and the "No wallet connected" guard, and theisConnecting/errorstate.localStorageand the kit (no real wallet); assert the returned discriminated{success, ...}shapes; deterministic with no real async wallet calls.jest.setup.js.Acceptance criteria
context/__tests__/WalletContext.test.tsxverifies hydrate/persist/clear and the provider guard.hooks/__tests__/useWallet.test.tsxcovers connect success/failure, disconnect, and sign success/guard.{success, address|signedTxXdr|error}shapes are asserted.errorandisConnectingstate transitions are asserted.WalletContext.tsxanduseWallet.hook.tsreaches >=90% lines.Suggested execution
1. Fork the repo and create a branch —
git checkout -b feature/wallet-tests.2. Implement changes — add
context/__tests__/WalletContext.test.tsxandhooks/__tests__/useWallet.test.tsx; mockconstants/wallet-kits.constant.ts.3. Write/extend tests — Jest + React Testing Library +
renderHookfrom@testing-library/reactwith pnpm; mocklocalStorageandgetKit. Mirror the style oflib/__tests__/scroll-position-store.test.ts.4. Test and commit —
pnpm install pnpm test pnpm test:coverage pnpm lintExample commit message
Guidelines
collectCoverageFrominjest.config.jscurrently omitscontext/andhooks/; mention extending it so wallet coverage is reported.