Skip to content

fix(types): validate individual ratio legs in validateSplitRatioSum - #1015

Closed
neverm1ndthat wants to merge 1 commit into
Stellar-split:mainfrom
neverm1ndthat:fix/1012-validate-ratio-legs
Closed

neverm1ndthat wants to merge 1 commit into
Stellar-split:mainfrom
neverm1ndthat:fix/1012-validate-ratio-legs

Conversation

@neverm1ndthat

Copy link
Copy Markdown

Fixes #1012

Summary

validateSplitRatioSum() in splitExecutor.ts now validates each recipient ratio individually before checking their aggregate sum.

The Bug

validateSplitRatioSum() only verified that |sum - 1| < tolerance. This allowed invalid inputs to pass:

  • [-1, 2] - sums to 1 but contains a negative ratio and a ratio > 1
  • NaN / Infinity legs - Math.abs(NaN - 1) > tolerance always evaluates to false, so NaN sums silently pass

The Fix

  1. Iterate each recipient with a declared ratio and reject any that is not finite or outside [0, 1]
  2. Also guard the aggregate sum with Number.isFinite before the tolerance check
  3. Adds a new SplitRatioLegError that surfaces which recipient has the bad ratio and why

Testing

  • All 10 existing tests in test/splitExecutorRatio.test.ts continue to pass
  • New SplitRatioLegError class properly extends StellarSplitError with code SPLIT_RATIO_LEG_INVALID

Issue Stellar-split#1012 - reject recipient ratios that are not finite or outside [0, 1]
before checking their aggregate sum. This catches invalid inputs like [-1, 2]
(sum=1 but semantically wrong), NaN, and Infinity which previously evaded
the tolerance check because NaN comparisons always return false.

Adds SplitRatioLegError to surface which recipient has the bad ratio and why.
@neverm1ndthat

Copy link
Copy Markdown
Author

Hi @Kingsman-99! This PR addresses Issue #1012 - validateSplitRatioSum now rejects individual ratio legs that are not finite or outside [0,1], not just the aggregate sum. This catches cases like [-1, 2] that sum to 1 but are semantically invalid. PTAL!

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.

Bug: invalid recipient ratio legs pass split preflight validation

2 participants