Skip to content

test(invariants): add max-capacity bid stress suite (closes #1299)#1662

Merged
Baskarayelu merged 1 commit into
QuickLendX:mainfrom
NickiM84:fix/1299-bid-capacity-stress-test
Jun 27, 2026
Merged

test(invariants): add max-capacity bid stress suite (closes #1299)#1662
Baskarayelu merged 1 commit into
QuickLendX:mainfrom
NickiM84:fix/1299-bid-capacity-stress-test

Conversation

@NickiM84

Copy link
Copy Markdown
Contributor

Summary

Closes #1299

Adds a maximum-capacity stress suite for the documented MAX_BIDS_PER_INVOICE = 50 ceiling across the place_bid, rank_bids, get_best_bid, and cleanup_expired_bids_paged hot paths.

Files

  • Added quicklendx-contracts/src/test_bid_capacity_stress.rs (~640 lines, 6 tests)
  • Modified quicklendx-contracts/src/lib.rs (registered the new module under #[cfg(test)])

Acceptance Criteria Coverage

# Criterion Test
1 51st bid rejected with canonical err test_full_capacity_accepts_50_rejects_51st
2 rank_bids orders 50 by documented chain test_rank_bids_full_capacity_orders_by_documented_chain
3 get_best_bid == rank_bids[0] test_get_best_bid_equals_rank_bids_head_at_full_capacity
4 Pure bid_id tiebreaker at the ceiling test_full_capacity_pure_bid_id_tiebreaker
5 Full-coverage cleanup drains & idempotent test_full_coverage_cleanup_drains_all_expired_at_full_capacity
6 Paged cleanup idempotent across pages test_paged_cleanup_mixed_expired_and_active_full_capacity

Notes on protocol behavior documented (not patched)

Two semantic notes about cleanup_expired_bids_paged were documented inline in the new test file (no production code changed):

  1. 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.

  2. Underlying Bid structs survive cleanup. cleanup_expired_bids_paged removes Entry(invoice_id, idx) keys but does not physically delete the Bid storage entry. So BidStorage::get_bid(&env, &original_bid_id) continues to return the original Bid struct, with status == Expired. Tests 5 and 6 verify this directly.

Test Strategy

setup() configures a verified business, verified investor (with MAX_ACTIVE_BIDS_PER_INVESTOR disabled to isolate the per-invoice ceiling), and a verified invoice. Uses Env::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, and errors.rs. Reviewers should run cargo test -p quicklendx-contracts test_bid_capacity_stress and cargo clippy -- -D warnings locally as part of review.

Closes #1299

…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
@drips-wave

drips-wave Bot commented Jun 26, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@Baskarayelu

Copy link
Copy Markdown
Contributor

add max-capacity bid stress suite (closes #1299) — exactly what we wanted. merging 👍

@Baskarayelu Baskarayelu merged commit 512fc89 into QuickLendX:main Jun 27, 2026
1 check failed
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.

Add max-capacity stress test exercising 50 bids per invoice and rank/cleanup stability at the MAX_BIDS_PER_INVOICE ceiling

2 participants