Skip to content

[16] Add unit tests for SponsorsService #8

Description

@EmeditWeb

Problem

src/modules/sponsors/sponsors.service.ts has no unit tests. Pool stats aggregation, deposit XDR construction, and withdrawal validation are all unverified.

Context

Sponsors are the funding side of the protocol — any silent miscalculation in pool stats undermines trust. Tests are essential before sponsors put real funds in.

Before Starting

Read these context files first:

  • context/architecture-context.md
  • context/code-standards.md
  • context/progress-tracker.md
  • src/modules/sponsors/sponsors.service.ts

What To Build

  1. Create test/unit/sponsors.service.spec.ts.
  2. Test getPool(): returns aggregated { totalDeposited, totalShares, utilizationBps, apyBps }; mocks repo + contract client.
  3. Test buildDepositXdr(wallet, amount): calls the liquidity client with correct args; returns the XDR; rejects amount ≤ 0.
  4. Test buildWithdrawXdr(wallet, shares): rejects shares below MIN_WITHDRAWAL_SHARES; otherwise returns valid XDR.
  5. Test that pool utilization is computed as (borrowed / totalDeposited) * 10_000 rounded to bps.
  6. Achieve ≥ 85% coverage.

Files To Touch

  • test/unit/sponsors.service.spec.ts

Acceptance Criteria

  • All 3 service methods covered
  • Minimum-withdrawal validation tested
  • Pool math verified against a known fixture
  • npm test -- sponsors.service passes
  • Coverage ≥ 85%
  • No any types

Mandatory Checks Before PR

  • npm run build passes with zero TypeScript errors
  • No new any types introduced anywhere
  • Full Swagger @apioperation + @apiresponse decorators on any new endpoints
  • New migration file created for any schema changes
  • context/progress-tracker.md updated

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions