Skip to content

Add edge-case coverage and harden pool TVL, fee APR, query defaults, and network accessors - #1271

Merged
Mimah97 merged 5 commits into
Vatix-Protocol:mainfrom
favourawaku:drips/1188-1189-1190-1191
Oct 16, 2026
Merged

Mimah97 merged 5 commits into
Vatix-Protocol:mainfrom
favourawaku:drips/1188-1189-1190-1191

Conversation

@favourawaku

Copy link
Copy Markdown
Contributor

Summary

Add edge-case coverage and harden pool TVL, fee APR, query defaults, and network accessors

What was solved

#1188 — apps/api: pool-tvl computation has no test for the zero-liquidity and missing-price branches

Extend apps/api/src/stats/pool-tvl.spec.ts with tests covering zero-liquidity pools, missing USD price on one token, missing USD price on both tokens, and a mixed valid/invalid aggregate; if pool-tvl.ts currently yields NaN/Infinity or throws on those inputs, make it return 0 (or skip the pool) and document the choice in the function JSDoc.

Addressed:

  • Changed: apps/api/src/stats/pool-tvl.ts, apps/api/src/stats/pool-tvl.spec.ts
  • Add spec cases for zero liquidity in apps/api/src/stats/pool-tvl.spec.ts
  • Add spec cases for missing USD price on one token and on both tokens
  • Assert aggregate TVL is a finite number when at least one pool is invalid

#1189 — apps/web: formatFeeApr accepts negative and non-finite inputs inconsistently

Add a vitest test file for apps/web/lib/fee-apr.ts covering NaN, Infinity, -Infinity, negative numbers, 0, valid numeric strings, and non-numeric strings, and fix formatFeeApr so empty/whitespace strings return 'N/A' instead of 0.00%.

Addressed:

  • Changed: apps/web/lib/fee-apr.ts, apps/web/lib/fee-apr.test.ts, apps/web/lib/fee-apr.ts, apps/web/lib/fee-apr.test.ts
  • Create apps/web/lib/fee-apr.test.ts using the existing vitest setup (apps/web/vitest.config.ts, apps/web/vitest.setup.ts)
  • Tests must cover NaN, Infinity, -Infinity, a negative number, 0, a valid numeric string, and a non-numeric string, asserting exact returned strings
  • Empty-string input must return 'N/A'; fix formatFeeApr in apps/web/lib/fee-apr.ts to explicitly reject empty/whitespace strings

#1190 — apps/web: Providers creates a QueryClient with no defaults, so failed queries retry forever

Update apps/web/app/providers.tsx to construct the QueryClient from an exported queryClientDefaults object with explicit query defaults: a retry function that returns false for 4xx errors (inspecting error.status or the shape from apps/web/lib/api-fetch.ts) and a bounded retry count otherwise, a sensible staleTime, and refetchOnWindowFocus disabled. Add a test under apps/web/tests/ asserting the retry behavior for 4xx vs other errors and that refetchOnWindowFocus is false.

Addressed:

  • Changed: apps/web/app/providers.tsx, apps/web/lib/api-fetch.ts, apps/web/app/providers.tsx, apps/web/tests/providers.test.tsx
  • Providers must create the QueryClient from an exported defaults object (e.g. export const queryClientDefaults) instead of new QueryClient() with no options.
  • Retry function must return false for 4xx errors and a bounded count (e.g. 2) for other errors, asserted by a test.
  • refetchOnWindowFocus must be false in the defaults and asserted by a test.

#1191 — packages/config: getNetworkPassphrase/getNetworkRpcUrl have no tests for unknown network input

Make the unknown-network contract explicit and consistent across the four config accessors (getNetworkPassphrase, getNetworkRpcUrl, getNetworkHorizonUrl, getExplorerTxUrl) by throwing a descriptive typed Error naming the offending value, keeping isStellarNetwork as the single narrowing source of truth, and extend the existing networks test file to assert behaviour for '', 'unknown', a wrong-cased known network ('TESTNET'), and a valid preset for each accessor. Public surface in packages/config/src/index.ts stays unchanged.

Addressed:

  • Changed: packages/config/src/networks.ts, packages/config/src/tests/networks.test.ts
  • All four accessors (getNetworkPassphrase, getNetworkRpcUrl, getNetworkHorizonUrl, getExplorerTxUrl) must share one documented behaviour for unknown network input — prefer throwing a descriptive Error naming the offending value over returning a wrong-network preset.
  • Tests must cover '', 'unknown', a wrong-cased known network (e.g. 'TESTNET'), and a valid preset for each of the four accessors, asserting either the thrown message or the returned value.
  • isStellarNetwork must return false for the invalid inputs used in the tests and remain the single source of truth for narrowing.

Changes

  • apps/web/lib/fee-apr.ts (modify)
  • apps/web/lib/api-fetch.ts (modify)
  • apps/api/src/stats/pool-tvl.ts (modify)
  • apps/web/lib/fee-apr.test.ts (modify)
  • apps/web/__tests__/providers.test.tsx (create)
  • apps/api/src/stats/pool-tvl.spec.ts (modify)
  • apps/web/app/providers.tsx (modify)
  • packages/config/src/networks.ts (modify)
  • packages/config/src/__tests__/networks.test.ts (modify)

Approach

  1. apps/api: pool-tvl computation has no test for the zero-liquidity and missing-price branches #1188 — apps/api: pool-tvl computation has no test for the zero-liquidity and missing-price branches (Changed: apps/api/src/stats/pool-tvl.ts, apps/api/src/stats/pool-tvl.spec.ts)
  2. apps/web: formatFeeApr accepts negative and non-finite inputs inconsistently #1189 — apps/web: formatFeeApr accepts negative and non-finite inputs inconsistently (Changed: apps/web/lib/fee-apr.ts, apps/web/lib/fee-apr.test.ts, apps/web/lib/fee-apr.ts, apps/web/lib/fee-apr.test.ts)
  3. apps/web: Providers creates a QueryClient with no defaults, so failed queries retry forever #1190 — apps/web: Providers creates a QueryClient with no defaults, so failed queries retry forever (Changed: apps/web/app/providers.tsx, apps/web/lib/api-fetch.ts, apps/web/app/providers.tsx, apps/web/tests/providers.test.tsx)
  4. packages/config: getNetworkPassphrase/getNetworkRpcUrl have no tests for unknown network input #1191 — packages/config: getNetworkPassphrase/getNetworkRpcUrl have no tests for unknown network input (Changed: packages/config/src/networks.ts, packages/config/src/tests/networks.test.ts)

Issues

Closes #1188
Closes #1189
Closes #1190
Closes #1191

@Mimah97
Mimah97 merged commit 8ca7b45 into Vatix-Protocol:main Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants