test(invariants): add max-capacity bid stress suite (closes #1299)#1662
Merged
Baskarayelu merged 1 commit intoJun 27, 2026
Merged
Conversation
…ndX#1299 Adds quicklendx-contracts/src/test_bid_capacity_stress.rs exercising the documented MAX_BIDS_PER_INVOICE = 50 ceiling across place_bid, rank_bids, get_best_bid, and cleanup_expired_bids_paged hot paths. Closes QuickLendX#1299 - full-capacity placement asserts 51st bid is rejected with MaxBidsPerInvoiceExceeded - rank_bids full-chain ordering at the ceiling (profit, expected_return, bid_amount, timestamp, bid_id) - get_best_bid == rank_bids[0] invariant after a cancel at full capacity - pure bid_id tiebreaker at the ceiling (identical timestamp/profit) - full-coverage cleanup drains all 50 expired and is fully idempotent on re-run - paged cleanup docs the partial-coverage storage-ghost behavior and proves idempotency at full capacity across pages
|
@NickiM84 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! 🚀 |
Contributor
|
add max-capacity bid stress suite (closes #1299) — exactly what we wanted. merging 👍 |
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.
Summary
Closes #1299
Adds a maximum-capacity stress suite for the documented
MAX_BIDS_PER_INVOICE= 50 ceiling across theplace_bid,rank_bids,get_best_bid, andcleanup_expired_bids_pagedhot paths.Files
quicklendx-contracts/src/test_bid_capacity_stress.rs(~640 lines, 6 tests)quicklendx-contracts/src/lib.rs(registered the new module under#[cfg(test)])Acceptance Criteria Coverage
test_full_capacity_accepts_50_rejects_51strank_bidsorders 50 by documented chaintest_rank_bids_full_capacity_orders_by_documented_chainget_best_bid==rank_bids[0]test_get_best_bid_equals_rank_bids_head_at_full_capacitybid_idtiebreaker at the ceilingtest_full_capacity_pure_bid_id_tiebreakertest_full_coverage_cleanup_drains_all_expired_at_full_capacitytest_paged_cleanup_mixed_expired_and_active_full_capacityNotes on protocol behavior documented (not patched)
Two semantic notes about
cleanup_expired_bids_pagedwere documented inline in the new test file (no production code changed):Partial-coverage index ghosts. The paged path compacts the per-invoice index within the processed window
[offset, end_idx)but intentionally does not update the storage count. A subsequent full-coverage pass at the same ledger timestamp (offset = 0,end_idx = old_count) detects these as stale, drains them, and settles the storage counter. Test 6 demonstrates this end-to-end.Underlying
Bidstructs survive cleanup.cleanup_expired_bids_pagedremovesEntry(invoice_id, idx)keys but does not physically delete theBidstorage entry. SoBidStorage::get_bid(&env, &original_bid_id)continues to return the originalBidstruct, withstatus == Expired. Tests 5 and 6 verify this directly.Test Strategy
setup()configures a verified business, verified investor (withMAX_ACTIVE_BIDS_PER_INVESTORdisabled to isolate the per-invoice ceiling), and a verified invoice. UsesEnv::default(),Address::generate(),mock_all_auths(), and SAC v2 mint+approval for future funded-path deltas.Testing Performed
Cross-referenced the suite against
bid.rs,lib.rs,types.rs, anderrors.rs. Reviewers should runcargo test -p quicklendx-contracts test_bid_capacity_stressandcargo clippy -- -D warningslocally as part of review.Closes #1299