Skip to content

test(utils): add unit conversion helpers and comprehensive unit tests - #187

Merged
chizzy192 merged 1 commit into
StellarState:devfrom
namdamdoi68-oss:feature/unit-conversion-helpers
Jul 30, 2026
Merged

test(utils): add unit conversion helpers and comprehensive unit tests#187
chizzy192 merged 1 commit into
StellarState:devfrom
namdamdoi68-oss:feature/unit-conversion-helpers

Conversation

@namdamdoi68-oss

Copy link
Copy Markdown
Contributor

Closes #175

Summary

  • Implemented stroopsToXlm and xlmToStroops in src/utils/unit-conversion.utils.ts using decimal.js to ensure arbitrary-precision safety when converting between Stellar stroops and 7-decimal XLM strings.
  • Added unit test suite in tests/unit/utils/unit-conversion.test.ts covering boundary values (0, 1 stroop, fractional decimals, 100,000 XLM, invalid inputs).

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@chizzy192 chizzy192 closed this Jul 29, 2026
@chizzy192 chizzy192 reopened this Jul 29, 2026
@chizzy192 chizzy192 closed this Jul 29, 2026
@chizzy192 chizzy192 reopened this Jul 29, 2026
@chizzy192
chizzy192 self-requested a review July 29, 2026 17:26
@chizzy192 chizzy192 closed this Jul 29, 2026
@chizzy192 chizzy192 reopened this Jul 29, 2026
@chizzy192

Copy link
Copy Markdown
Contributor

Hi @namdamdoi68-oss! 👋

Thank you for your contribution!

Problem Identified:
Your branch currently has merge conflicts against the latest dev branch.

Recommended Fix:
Please fetch the latest dev branch, rebase your feature branch, resolve the conflicts, and force-push:

git fetch origin dev
git checkout feature/unit-conversion-helpers
git rebase origin/dev
# Resolve any conflicts, then:
git add <resolved-files>
git rebase --continue
npm test
git push --force-with-lease origin feature/unit-conversion-helpers

Once rebased, all GitHub Actions CI checks will execute automatically. Thanks! 🚀

@chizzy192

Copy link
Copy Markdown
Contributor

Hi @namdamdoi68-oss! 👋

Specific Conflict Analysis for PR #187:

The file src/utils/unit-conversion.utils.ts was recently merged into dev (via PR #188), which creates a duplicate file conflict with your branch:

  • Conflicting File: src/utils/unit-conversion.utils.ts
  • Conflict Reason: Both dev and your branch define stroopsToXlm and xlmToStroops.
    • dev uses:
      const STROOP_DIVISOR = new Decimal(10).pow(7);
      export function stroopsToXlm(stroops: bigint | string): string { ... }
    • Your PR adds NaN type validation:
      if (dec.isNaN()) throw new TypeError(`Invalid stroops amount: ${stroops}`);

Step-by-Step Fix:

  1. Fetch latest dev and rebase your branch:
    git fetch origin dev
    git checkout feature/unit-conversion-helpers
    git rebase origin/dev
  2. Open src/utils/unit-conversion.utils.ts and reconcile the implementation by combining your NaN validation with the existing dev function exports.
  3. Mark resolved and continue:
    git add src/utils/unit-conversion.utils.ts
    git rebase --continue
    npm test
    git push --force-with-lease origin feature/unit-conversion-helpers

Once rebased, all CI checks will run automatically. Thanks! 🚀

Signed-off-by: namdamdoi68-oss <namdamdoi68@gmail.com>
@namdamdoi68-oss
namdamdoi68-oss force-pushed the feature/unit-conversion-helpers branch from 70fc3e5 to 8427666 Compare July 29, 2026 18:19
@namdamdoi68-oss

Copy link
Copy Markdown
Contributor Author

Rebased on latest dev and reconciled unit-conversion.utils.ts — kept STROOPS_PER_XLM constant and @example docs from #188, added NaN type validation on top. All 15 tests pass.

@chizzy192
chizzy192 merged commit 4af3f22 into StellarState:dev Jul 30, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants