Skip to content

#123 [High] Add null-handling and ingestion tests for Token.priceUsd across the tokens module #332

Description

@james2177

Description: prisma/schema.prisma's Token model defines priceUsd Float? as explicitly nullable ("Latest known USD price (nullable – updated by a price-feed worker)"), and issue #55 backs the Token model with a real repository/service, but neither src/tokens/tokens.service.ts nor src/tokens/tokens.controller.ts currently has verified, tested behavior for the null case — before a price-feed worker (issue #8's pluggable price-feed provider) has ever populated a token's price.

Problem Statement & Context: Between issue #55 (real Token repository) and issue #8 (pluggable price-feed provider) landing, there's a real window — and likely a permanent steady-state for newly-listed tokens — where priceUsd is null. Any consumer (quote calculation, RoutingService, API responses) that assumes a numeric price without checking will produce NaN/crash rather than a clear "price unavailable" signal.

Scope & Acceptance Criteria:

  • Audit every read site of Token.priceUsd (via src/tokens/tokens.service.ts and any downstream consumer such as quote-calculation logic) and ensure each handles null explicitly (typed as number | null throughout, never silently coerced).
  • Add a documented, explicit behavior for API consumers when priceUsd is null (e.g. the field is omitted vs. returned as null in the response — pick one and make it consistent, then document it in Swagger per the pattern in issue Add an audit trail for cancelled and expired intents #62).
  • Out of scope: implementing the price-feed worker itself (issue feat: port /api/v1/intents routes to Nest #8) — this issue only hardens the null-handling path that exists regardless of when/whether a price feed is populating data.
  • Out of scope: TokensService.getByChain()'s separately-tracked return-shape bug (issue feat: port /api/v1/stats endpoint to Nest #9).

Implementation Guidelines:

  1. Key files: prisma/schema.prisma (Token.priceUsd), src/tokens/tokens.service.ts, src/tokens/tokens.controller.ts, src/tokens/tokens.data.ts (current static data source, useful for comparing pre/post issue Replace SolversService's in-memory Map with persistent storage #55 shapes).
  2. Trace any arithmetic performed on priceUsd (e.g. USD-value calculations feeding stats/quote logic) and guard each with an explicit null check rather than relying on TypeScript's optional-chaining alone to prevent a runtime NaN.
  3. Coordinate the null-vs-omitted API contract decision with whatever Swagger documentation issue Add an audit trail for cancelled and expired intents #62 adds for TokensController, so the two stay consistent.
  4. Testing: minimum 90% branch coverage on the null-handling paths specifically; add test cases for a token with priceUsd: null at every read site identified in the audit, plus a regression test confirming no NaN/unhandled-exception path exists.

Definition of Done:

  • Null-handling audited and hardened across all identified read sites, tested, documented.
  • Acceptance criteria met.
  • PR passes CI with test output.
  • Reviewed and approved.

Resources: prisma/schema.prisma, src/tokens/tokens.service.ts, src/tokens/tokens.controller.ts, src/tokens/tokens.data.ts

Complexity: High (200 points)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions