Skip to content

fix(coin): align fromString denom regex with Cosmos denom spec#169

Merged
Vritra4 merged 1 commit into
v2from
fix/v2-denom
May 28, 2026
Merged

fix(coin): align fromString denom regex with Cosmos denom spec#169
Vritra4 merged 1 commit into
v2from
fix/v2-denom

Conversation

@Vritra4
Copy link
Copy Markdown
Contributor

@Vritra4 Vritra4 commented May 28, 2026

same with #168

Summary by CodeRabbit

  • New Features

    • Enhanced denom validation now accepts additional special characters (colons, slashes, dots, underscores, hyphens).
    • Stricter denom length constraints enforced for better compliance.
    • Improved decimal coin parsing with support for negative amounts.
  • Tests

    • Extended test coverage validating denom characters and length bounds.
    • Added comprehensive test scenarios for decimal coin parsing.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 36da4b37-017f-43b9-80b7-8919071b27f9

📥 Commits

Reviewing files that changed from the base of the PR and between 62f6e47 and 5e2169a.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • src/core/coin.ts
  • test/unit/core/coin.spec.ts

Walkthrough

This PR centralizes coin and denom string validation into shared regex constants, updates parseCoin and parseDecCoin to use those patterns instead of inline regexes, refactors the DecCoin constructor's amount-type handling, and adds comprehensive test coverage for denom character support and length constraints.

Changes

Coin validation module update

Layer / File(s) Summary
Denom and coin string validation regex constants
src/core/coin.ts
Introduces DENOM_REGEX_FRAGMENT, COIN_STRING_REGEX, and DEC_COIN_STRING_REGEX constants that define expanded denom character support (:, /, ., _, -) and enforce Cosmos denom length constraints.
Update parseCoin and parseDecCoin validation
src/core/coin.ts
parseCoin and parseDecCoin now validate input against centralized regex patterns, replacing inline regex definitions with the shared constants.
DecCoin constructor input normalization refactoring
src/core/coin.ts
Refactors the amount parameter handling from inline case statements into a structured switch statement with multi-line assignments.
Coin validation and parsing test coverage
test/unit/core/coin.spec.ts
Extends parseCoin tests to verify denom character support and Cosmos denom length bounds; adds new parseDecCoin test suite covering denom validation, negative amounts, and length constraints.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A coin's true form now clearly defined,
With patterns shared across the line,
Denoms dance with characters new,
Length bounds enforced, validation true,
Tests ensure the parsing's right!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: aligning the denom regex patterns in coin parsing functions with Cosmos specification, which is the central focus of the file modifications.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/v2-denom

Comment @coderabbitai help to get the list of available commands and usage tips.

@Vritra4 Vritra4 merged commit a60dc6b into v2 May 28, 2026
1 check passed
@Vritra4 Vritra4 deleted the fix/v2-denom branch May 28, 2026 05:43
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.

1 participant