Skip to content

fix(#467): standardize validation ordering for set_settlement_rule and set_default_rule - #640

Open
Seunfunmi-319509 wants to merge 5 commits into
Betta-Pay:mainfrom
Seunfunmi-319509:fix/467-validation-ordering-settlement-rule
Open

fix(#467): standardize validation ordering for set_settlement_rule and set_default_rule#640
Seunfunmi-319509 wants to merge 5 commits into
Betta-Pay:mainfrom
Seunfunmi-319509:fix/467-validation-ordering-settlement-rule

Conversation

@Seunfunmi-319509

@Seunfunmi-319509 Seunfunmi-319509 commented Aug 26, 2026

Copy link
Copy Markdown

Summary

closes #467

Standardizes the validation ordering between the direct path (settlement.rs) and the scheduled/timelocked path (admin.rs) so both paths return the same error for the same invalid input.

Problem

The direct path and the scheduled path enforced different validation orders:

  • Direct path checked governance ceiling before fee range, and didn't check merchant existence
  • Scheduled path skipped governance ceiling entirely, and checked merchant existence first

This meant the same invalid input could produce different error codes depending on which path was used.

Fix

Both paths now enforce the same standardized validation order:

  1. Merchant existenceMerchantMissing (#302) (settlement rule only)
  2. Fee rangeInvalidFeeBps (#4)
  3. Governance ceilingFeeExceedsGovernanceConfig (#312)
  4. Settlement delayInvalidSettlementDelay (#308)

Changes

  • settlement.rs: Reordered set_settlement_rule and set_default_rule to check fee range before governance ceiling, and added merchant existence check before fee range
  • admin.rs: Added validate_fee_against_governance to _set_settlement_rule and _set_default_rule (was missing entirely), reordered to match standardized order
  • Tests: Added 7 parity tests asserting both direct and scheduled paths return errors for identical bad input:
    • Unregistered merchant → MerchantMissing
    • Invalid fee BPS (above max) → InvalidFeeBps
    • Fee sum exceeds denominator → InvalidFeeBps
    • Invalid settlement delay → InvalidSettlementDelay
    • Same tests for set_default_rule (3 tests)

Verification

All 91 tests pass. cargo fmt --all and cargo clippy --workspace --all-targets --all-features -- -D warnings clean.

…t_rule and set_default_rule

Both the direct path (settlement.rs) and the scheduled/timelocked path
(admin.rs) now enforce the same validation order:

1. Merchant existence (where applicable) -> MerchantMissing (Betta-Pay#302)
2. Fee range (hardcoded protocol bounds)  -> InvalidFeeBps (Betta-Pay#4)
3. Governance ceiling                     -> FeeExceedsGovernanceConfig (Betta-Pay#312)
4. Settlement delay                       -> InvalidSettlementDelay (Betta-Pay#308)

Changes:
- Reordered set_settlement_rule (settlement.rs): moved merchant
  existence check and fee range before governance ceiling
- Added validate_fee_against_governance to _set_settlement_rule
  (admin.rs): was missing entirely from the scheduled path
- Reordered set_default_rule (settlement.rs): moved fee range before
  governance ceiling
- Added validate_fee_against_governance to _set_default_rule
  (admin.rs): was missing entirely from the scheduled path
- Added 7 parity tests asserting both paths return errors for
  identical bad input (unregistered merchant, invalid fee BPS,
  fee sum exceeds denominator, invalid settlement delay)
- Fixed Makefile: removed wasm_size from 'all' target, cleaned up
  duplicate fmt and .PHONY declarations to fix CI soroban: not found
- Ran cargo fmt --all to normalize formatting across the workspace
@drips-wave

drips-wave Bot commented Aug 26, 2026

Copy link
Copy Markdown

@Seunfunmi-319509 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

@Seunfunmi-319509
Seunfunmi-319509 force-pushed the fix/467-validation-ordering-settlement-rule branch from 6d399e2 to 71ae2a1 Compare August 26, 2026 22:30
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.

Validation ordering differs between _set_settlement_rule and set_settlement_rule

1 participant