refactor: extract basis-points range validation into assert_valid_bps helper (#704) - #734
Merged
Kingsman-99 merged 2 commits intoAug 30, 2026
Conversation
|
@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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Extract basis-points range validation into
assert_valid_bpshelperSummary
Closes #704
Basis-point option fields (
penalty_bps,tax_bps,insurance_premium_bps, …)were validated inline at three call sites in
lib.rswith.expect("… must be ≤ 10000"). This PR extracts that check into a single sharedhelper,
assert_valid_bps, incontracts/split/src/validation.rs, matching theexisting
assert_bps_sum/assert_bps_totalguards, and routes all three callsites through it.
This also fixes two pre-existing compile errors on
main:error[E0428]: the name 'validation' is defined multiple times—lib.rsdeclared
mod validation;twice (lines 58 and 74). The duplicate declarationhas been removed.
error[E0432]: unresolved import 'validation::assert_valid_bps'— the helperwas referenced (line 77 and the three call sites) but never defined. It now
exists.
What changed
validation.rs— addedassert_valid_bps(bps: u32) -> Result<(), ContractError>that returns
Err(ContractError::InvalidRatio)whenbps > BASIS_POINTS_TOTAL(10_000).
u32is already non-negative, so only the upper bound is checked.lib.rs— removed the duplicatemod validation;declaration. The threecall sites already read
assert_valid_bps(penalty_bps).expect(…)etc., so theynow 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-fastsemantics); the validation logic is now centralized and reusable.
Verification
Resolves the
E0428(duplicatemod) andE0432(assert_valid_bpsunresolved)errors. Note:
cargo checkonmainstill reports additional, unrelatedpre-existing errors from other unimplemented helpers/variants (e.g.
calc_platform_fee,TooFewRecipients,Map::has,Persistent::bump) that aretracked by their own issues; this PR is scoped to #704 and does not attempt to
fix those.
closes #704