Skip to content

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

Closed
ayomidearegbeshola29-dev wants to merge 1 commit into
Stellar-split:mainfrom
ayomidearegbeshola29-dev:fix/issue-704-assert-valid-bps
Closed

refactor: extract basis-points range validation into assert_valid_bps (#704)#725
ayomidearegbeshola29-dev wants to merge 1 commit into
Stellar-split:mainfrom
ayomidearegbeshola29-dev:fix/issue-704-assert-valid-bps

Conversation

@ayomidearegbeshola29-dev

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

@ayomidearegbeshola29-dev

Copy link
Copy Markdown
Author

Re-homed: PR now opened from assignee account christy-dev4.

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

1 participant