Test/max invoices per business#520
Merged
Baskarayelu merged 6 commits intoQuickLendX:mainfrom Mar 9, 2026
Merged
Conversation
- Add max_invoices_per_business field to ProtocolLimits - Add MaxInvoicesPerBusinessExceeded error (code 1407) - Implement count_active_business_invoices() helper - Add enforcement logic in upload_invoice() - Add update_protocol_limits_with_max_invoices() admin function - Create comprehensive test suite with 10 tests achieving >95% coverage Tests cover: - Creating invoices up to limit - Clear error when limit exceeded - Cancelled invoices freeing slots - Paid invoices freeing slots - Dynamic config updates - Unlimited mode (limit=0) - Per-business independence - Active invoice counting - All invoice statuses - Edge cases (limit=1)
Renamed update_protocol_limits_with_max_invoices (40 chars) to update_limits_max_invoices (26 chars) to comply with Soroban's 32-character limit for contract function names. Updated all references in: - src/lib.rs - src/test_max_invoices_per_business.rs - Documentation files
Removed unused imports: - emit_dispute_created - emit_dispute_resolved - emit_dispute_under_review These were causing compilation warnings in CI.
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.
Max Invoices Per Business Enforcement
Description
Adds enforcement and tests for a maximum number of active invoices per business.
Protocol admins can configure this limit to prevent abuse and ensure fair resource usage.
Type of Change
Key Changes
Protocol Limits
max_invoices_per_business: u32toProtocolLimits0disables the limit (unlimited invoices)Error Handling
MaxInvoicesPerBusinessExceededInvoice Counting
Added helper:
count_active_business_invoices()Invoices counted as active:
Invoices not counted:
Enforcement
upload_invoice()Admin Configuration
New admin function:
update_protocol_limits_with_max_invoices()Allows updating limits dynamically.
Files Modified
quicklendx-contracts/src/protocol_limits.rsquicklendx-contracts/src/errors.rsquicklendx-contracts/src/invoice.rsquicklendx-contracts/src/lib.rscargo fmtFiles Added
test_max_invoices_per_business.rsMAX_INVOICES_PER_BUSINESS_TESTS.mdTEST_MAX_INVOICES_IMPLEMENTATION_SUMMARY.mdQUICK_TEST_GUIDE_MAX_INVOICES.mdTesting
10 tests covering:
limit = 0)limit = 1)Test coverage: >95%
Run tests:
cargo test test_max_invoices --lib
Contract Checks
Breaking Changes
None.
This feature is backward compatible.
Design Decisions
limit = 0enables unlimited invoicesclose #490