Skip to content

[TESTING] Add unit tests for stroopsToXlm and xlmToStroops unit conversion helpersΒ #175

Description

@chizzy192

Metadata

Field Value
Domain Testing
Difficulty Easy (1–2 Days)
Effort Estimate effort: 2h
Priority P2-Medium
Labels good first issue, easy, Stellar Wave
Target Branch dev
Depends On None

🎯 Context & Goal

Converting between Stellar stroops (1 XLM = 10,000,000 stroops) and human-readable decimal XLM/USDC amounts must be accurate down to the single stroop. Floating point math can introduce precision errors when handling financial balances.

This issue creates unit tests in tests/unit/utils/unit-conversion.test.ts testing stroopsToXlm() and xlmToStroops() across boundary values (0, 1 stroop, fractional stroops, 100,000 XLM).

πŸ“‚ Target Files

  • tests/unit/utils/unit-conversion.test.ts -> Unit conversion test suite
  • src/utils/unit-conversion.utils.ts -> Conversion utility functions

πŸ“‹ Implementation Tasks

  • Implement stroopsToXlm(stroops: bigint | string): string using Decimal.js
  • Implement xlmToStroops(xlm: string | number): bigint using Decimal.js
  • Write unit tests verifying boundary values and preventing floating-point precision loss

πŸ› οΈ Technical Guidance

import Decimal from 'decimal.js';

export function stroopsToXlm(stroops: bigint | string): string {
  return new Decimal(stroops.toString()).dividedBy(10000000).toFixed(7);
}
export function xlmToStroops(xlm: string | number): bigint {
  return BigInt(new Decimal(xlm).times(10000000).toFixed(0));
}

πŸ”— References & Related

  • Stellar Precision Docs

⏳ Delivery Window

This issue should be completed within 1 day(s) of assignment.

Contribution Workflow

  1. Branch off dev: git checkout -b feature/descriptive-name dev
  2. Implement all tasks in the checklist above.
  3. Run all CI checks locally (see DEVELOPMENT.md).
  4. Open a Pull Request targeting dev.
  5. Link this issue in your PR description: Closes #XX.

βœ… Acceptance Criteria

  • All implementation tasks above are completed.
  • Code compiles/builds without errors.
  • All existing tests continue to pass.
  • New tests are added with >80% coverage of new code.
  • Code follows project style guidelines (formatting, linting).
  • PR targets dev branch (NOT main).
  • PR description references this issue.
  • Documentation is updated if public API changed.

Metadata

Metadata

Labels

Stellar WaveIssues in the Stellar wave programeasySmall scope / straightforwardgood first issueGood for newcomers

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions