Skip to content

test: Split Loan_test.cpp into topical suites - #7864

Open
Tapanito wants to merge 3 commits into
tapanito/lending-cash-basisfrom
tapanito/loan-test-split
Open

test: Split Loan_test.cpp into topical suites#7864
Tapanito wants to merge 3 commits into
tapanito/lending-cash-basisfrom
tapanito/loan-test-split

Conversation

@Tapanito

Copy link
Copy Markdown
Contributor

Summary

  • Loan_test.cpp had grown to ~9700 lines covering core transactor tests, fuzzer/invariant regressions, RIPD/bug repros, and cash-basis accounting all in one Suite. Split into four topical suites — Loan, LoanInvariant, LoanRegression, LoanCashBasis — following the existing precedent for large domains in this codebase (e.g. AMM_test/AMMCalc_test/AMMClawback_test).
  • Shared fixtures and helpers (BrokerInfo, createVaultAndBroker, createFundedIouAsset, nextLoanKeylet, makeLoanPayments, etc.) move into a new LoanTestBase, which every split suite — including the existing LoanBatch_test/LoanArbitrary_test manual fuzz suites — inherits from instead of Loan_test.
  • Also includes minor dedup done ahead of the split: a few repeated setup blocks across FIND-derived regression tests were factored into helpers (createFundedIouAsset, nextLoanKeylet, createFundedRippleIouAsset, brokerPseudoAccount), and four near-identical fuzzer-derived invariant tests were merged into one (testLoanPayComputePeriodicPaymentInvariants), each finding kept as its own testcase().
  • Pure reorganization — no test logic, assertions, or magic numbers changed.

Based on tapanito/lending-cash-basis (#7817) rather than develop, since this only reorganizes tests already on that branch.

Test plan

  • Clean rebuild (rw make) compiles all 5 changed/new files with no new warnings.
  • ./xrpld -u Loan,LoanInvariant,LoanRegression,LoanCashBasis reports 1070 cases, 116951 assertions, 0 failures — an exact match to the pre-split monolithic suite's totals.
  • Manual fuzz suites (LoanBatch, LoanArbitrary) still compile and run; confirmed their underlying logic (runLoan/createLoan/makeLoanPayments/testRandomLoan, deterministic RNG seed) is byte-identical to the pre-split code, so their behavior (including LoanBatch's pre-existing, seed-dependent failures on some random draws) is unchanged by this move.

Loan_test.cpp had grown to ~9700 lines covering lifecycle, invariant
regressions, RIPD/bug repros, and cash-basis accounting in one class.
Split into Loan (core transactor tests), LoanInvariant (fuzzer/invariant
repros), LoanRegression (RIPD-*/bug:/edge: repros), and LoanCashBasis
(cash-basis accounting), sharing fixtures and helpers via a new
LoanTestBase. LoanBatch_test/LoanArbitrary_test are rebased onto
LoanTestBase instead of Loan_test for the same reason.

Pure reorganization: combined case/assertion counts across the four
new suites match the pre-split totals exactly (1070 cases, 116951
assertions, 0 failures).
@Tapanito
Tapanito requested review from a1q123456 and gregtatcam July 24, 2026 14:54

@xrplf-ai-reviewer xrplf-ai-reviewer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean reorganization with comprehensive test validation — everything checks out.

@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Supersedes the previous 4-file split (Loan/LoanInvariant/
LoanRegression/LoanCashBasis) with a more granular, 10-suite layout:

- Loan: core LoanSet lifecycle
- LoanLifecycle: full lifecycle, self-loan, issuer/broker-as-borrower
- LoanValidation: disabled-amendment and invalid-transaction checks
- LoanPay: payment-mechanics regressions (fees, near-zero rate, overflow)
- LoanInvariants: fuzzer-derived invariant regressions
- LoanRounding: precision/scale/dust rounding regressions
- LoanCoverFreezeAuth: first-loss-cover, freeze, and MPT auth permissions
- LoanSecurity: PoC and RIPD-numbered regressions
- LoanCashBasis: unchanged, LendingProtocolV1_1 cash-basis coverage
- LoanMisc: RPC signing flow, plus the LoanBatch/LoanArbitrary manual
  fuzz suites relocated here

Shared fixtures/helpers remain in LoanTestBase.h; testCaseWrapper moves
there too since it's used by both LoanSet (Loan) and testLifecycle
(LoanLifecycle), not just the former.

Pure reorganization: every function body is byte-identical to the
prior split, and independent/sensitive call-site wiring matches
exactly (verified via diff). The combined suite total is 1071 cases
(vs. 1070 previously) with an identical 116951 assertions and 0
failures. The extra case is a benign case-boundary bookkeeping
artifact: testLoanSet's (unchanged) setup code performs real
transaction-application work before its own first testcase() call,
and now that it's the sole/first function in its own suite, that
pre-existing activity surfaces as a new blank case instead of
attaching to a predecessor's case as it did when other functions ran
before it in the old grouping. No assertions were gained, lost, or
duplicated.

@xrplf-ai-reviewer xrplf-ai-reviewer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All test cases passing with comprehensive coverage maintained. Ready to merge.

Run clang-tidy (misc-include-cleaner) scoped to the files touched by
the Loan test split. Trims LoanTestBase.h down to only the includes
its shared helpers actually need now that most test bodies moved out,
and adds direct includes to each split file for symbols they use.

Restores two includes the automated fixer incorrectly dropped
(test/jtx/jtx_json.h for Json(...), test/jtx/sponsor.h for
sponsor::As) which broke the build; clang-tidy's usage tracking
doesn't reliably see through these. Verified with a full clean
rebuild and test run: 1071 cases, 116951 assertions, 0 failures,
unchanged from before this cleanup.

@gregtatcam gregtatcam left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

One thought. Does it make sense adding a brief comment to each module describing what tests it covers so it's easier to figure out where the future tests should go to? Some file names are obvious but some are too general.

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.

3 participants