Skip to content

refactor: extract basis-points range validation into assert_valid_bps helper (#704) - #734

Merged
Kingsman-99 merged 2 commits into
Stellar-split:mainfrom
christy-dev4:fix/issue-704-assert-valid-bps
Aug 30, 2026
Merged

refactor: extract basis-points range validation into assert_valid_bps helper (#704)#734
Kingsman-99 merged 2 commits into
Stellar-split:mainfrom
christy-dev4:fix/issue-704-assert-valid-bps

Conversation

@christy-dev4

Copy link
Copy Markdown

Extract basis-points range validation into assert_valid_bps helper

Summary

Closes #704

Basis-point option fields (penalty_bps, tax_bps, insurance_premium_bps, …)
were validated inline at three call sites in lib.rs with
.expect("… must be ≤ 10000"). This PR extracts that check into a single shared
helper, assert_valid_bps, in contracts/split/src/validation.rs, matching the
existing assert_bps_sum / assert_bps_total guards, and routes all three call
sites through it.

This also fixes two pre-existing compile errors on main:

  • error[E0428]: the name 'validation' is defined multiple timeslib.rs
    declared mod validation; twice (lines 58 and 74). The duplicate declaration
    has been removed.
  • error[E0432]: unresolved import 'validation::assert_valid_bps' — the helper
    was referenced (line 77 and the three call sites) but never defined. It now
    exists.

What changed

  • validation.rs — added assert_valid_bps(bps: u32) -> Result<(), ContractError>
    that returns Err(ContractError::InvalidRatio) when bps > BASIS_POINTS_TOTAL
    (10_000). u32 is already non-negative, so only the upper bound is checked.
  • lib.rs — removed the duplicate mod validation; declaration. The three
    call sites already read assert_valid_bps(penalty_bps).expect(…) etc., so they
    now resolve correctly.

Behavior

No behavioral change for valid inputs. Out-of-range values still panic at the
call site via the existing .expect(...) (preserving the prior fail-fast
semantics); the validation logic is now centralized and reusable.

Verification

Resolves the E0428 (duplicate mod) and E0432 (assert_valid_bps unresolved)
errors. Note: cargo check on main still reports additional, unrelated
pre-existing errors from other unimplemented helpers/variants (e.g.
calc_platform_fee, TooFewRecipients, Map::has, Persistent::bump) that are
tracked by their own issues; this PR is scoped to #704 and does not attempt to
fix those.

closes #704

@drips-wave

drips-wave Bot commented Aug 29, 2026

Copy link
Copy Markdown

@christy-dev4 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Kingsman-99
Kingsman-99 merged commit 9402962 into Stellar-split:main Aug 30, 2026
1 of 4 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.

Extract basis-points range validation into assert_valid_bps helper

2 participants