Skip to content

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

Merged
mathbunnyru merged 24 commits into
developfrom
tapanito/loan-test-split
Aug 4, 2026
Merged

test: Split Loan_test.cpp into topical suites#7864
mathbunnyru merged 24 commits into
developfrom
tapanito/loan-test-split

Conversation

@Tapanito

@Tapanito Tapanito commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Loan_test.cpp had grown to ~9700 lines covering core transactor tests, invariant/fuzzer regressions, RIPD/bug repros, and cash-basis accounting all in one Suite. Split into a new src/test/app/lending/ directory containing 12 topical suites, grouped by concern rather than by history: LendingHelpers, LoanBroker, LoanCashBasis, LoanCoverFreezeAuth, LoanInvariants, LoanLifecycle, LoanMisc, LoanPay, LoanRounding, LoanSecurity, LoanSet, LoanValidation.
  • The two other pre-existing lending test files, LendingHelpers_test.cpp and LoanBroker_test.cpp, moved into src/test/app/lending/ alongside the new suites so all lending tests live in one place.
  • Shared fixtures and helpers (BrokerInfo, createVaultAndBroker, createFundedIouAsset, nextLoanKeylet, makeLoanPayments, etc.) live in a new LoanTestBase.h, which every split suite — including the pre-existing manual fuzz suites LoanBatch_test/LoanArbitrary_test (now in LoanMisc_test.cpp) — inherits from.
  • Added a manual aggregator suite, src/test/app/lending/Loan_test.cpp, that reruns all 12 topical suites under the historical Loan name so existing tooling/muscle memory that invokes -u Loan keeps working. This needed a small addition to beast::unit_test::Suite (a protected runner() accessor) so the aggregator can dispatch into its member suites via the global suite registry.
  • Retargeted the UBSan suppression entry for the old test/app/Loan_test.cpp path to its new home, test/app/lending/LoanSecurity_test.cpp (the file that still contains the intentional unsigned-underflow PoC), and picked up a handful of reviewer/AI-flagged fixes along the way (a couple of unguarded SLE dereferences, an ambiguous Balance reference from unity-build batching, stale comments).
  • Pure reorganization — no test logic, assertions, or magic numbers changed relative to the pre-split monolith.

Based on develop (the cash-basis accounting work this originally depended on, #7817, has since merged into develop). Kept in sync with develop via several merges; the most recent one conflicted on the now-deleted monolithic Loan_test.cpp against an unrelated develop commit that renamed loanBroker/Lending/Accrual/CashBasis namespaces to snake_case — that rename was reapplied by hand to the split files.

Test plan

  • Clean rebuild (rw make) compiles all changed/new files with no new warnings.
  • ./xrpld -u Loan (the aggregator, rerunning all 12 topical suites) reports 1188 cases, 122054 tests, 0 failures.
  • Each of the 12 topical suites also verified individually (./xrpld -u <Suite>) with 0 failures.
  • Manual fuzz suites (LoanBatch, LoanArbitrary) still compile and run; their underlying logic is unchanged by this move.

Tapanito added 11 commits July 16, 2026 18:12
Gate Vault AssetsTotal and LoanBroker DebtTotal to principal-only
tracking under featureLendingProtocolV1_1, replacing whole-life
(accrual) interest recognition. Adds Accrual/CashBasis namespaces and
three public dispatchers in LendingHelpers, consumed by LoanSet,
LoanPay, and LoanManage without any amendment-awareness in the
transactors themselves. Pre-amendment behavior is unchanged.
Reference VaultVersion::Legacy instead of raw 0 in getVaultVersion's
docstring, correct a stale test label, and rename LoanPay's precision
log fields from ValueChange to AssetsTotalDelta to match what they
actually print
Cash-basis origination never recognizes interest into Vault.AssetsTotal,
so checking interestDue against remaining AssetsMaximum headroom rejects
loans for no reason. Split the check into Accrual/CashBasis namespaces,
mirroring the existing loanOriginationDeltas/loanPaymentDeltas dispatch.
Remove unused vaultMaximum local left over from the AssetsMaximum
guard refactor, and stop the DebtMaximum guard from unconditionally
adding interestDue to the projected DebtTotal. Reuse the existing
loanOriginationDeltas dispatcher, which already excludes interestDue
under cash-basis accounting.
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 previously approved these changes Jul 24, 2026

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

a1q123456
a1q123456 previously approved these changes Jul 27, 2026
Base automatically changed from tapanito/lending-cash-basis to develop July 30, 2026 13:13
@bthomee
bthomee dismissed stale reviews from a1q123456 and gregtatcam July 30, 2026 13:13

The base branch was changed.

@github-actions

Copy link
Copy Markdown

This PR has conflicts, please resolve them in order for the PR to be reviewed.

Tapanito added 2 commits July 30, 2026 17:21
…-split

# Conflicts:
#	include/xrpl/ledger/helpers/LendingHelpers.h
#	src/libxrpl/ledger/helpers/LendingHelpers.cpp
#	src/libxrpl/ledger/helpers/VaultHelpers.cpp
#	src/libxrpl/tx/transactors/lending/LoanManage.cpp
#	src/libxrpl/tx/transactors/lending/LoanPay.cpp
#	src/libxrpl/tx/transactors/lending/LoanSet.cpp
#	src/test/app/LendingHelpers_test.cpp
#	src/test/app/Loan_test.cpp
@github-actions

Copy link
Copy Markdown

All conflicts have been resolved. Assigned reviewers can now start or resume their review.

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

Regression test checks wrong transaction type—see inline.

Comment thread src/test/app/lending/LoanLifecycle_test.cpp

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

UBSan suppression points to nonexistent file — see inline.

Comment thread sanitizers/suppressions/ubsan.supp
Comment thread include/xrpl/beast/unit_test/suite.h
Co-authored-by: Ayaz Salikhov <mathbunnyru@users.noreply.github.com>
@Tapanito
Tapanito requested a review from mathbunnyru August 4, 2026 13:23

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

Dead code in test invariant — see inline.

Comment thread src/test/app/lending/LoanInvariants_test.cpp Outdated
@mathbunnyru
mathbunnyru enabled auto-merge August 4, 2026 13:29

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

Dead code found in 5 locations: unused variables and commented-out lines. See inline.

Comment thread src/test/app/lending/LoanSecurity_test.cpp Outdated
Comment thread src/test/app/lending/LoanSecurity_test.cpp Outdated
Comment thread src/test/app/lending/LoanInvariants_test.cpp Outdated
Comment thread src/test/app/lending/LoanCoverFreezeAuth_test.cpp Outdated
Comment thread src/test/app/lending/LoanCoverFreezeAuth_test.cpp Outdated
@mathbunnyru
mathbunnyru disabled auto-merge August 4, 2026 13:42
@mathbunnyru
mathbunnyru enabled auto-merge August 4, 2026 13:42

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

Most of the diff consists of file renames/deletions with no visible content changes, and the two substantive code snippets (suite.h's new protected runner() accessor, and the jtx::Balance qualification fixes in LoanBroker_test.cpp) look correct and low-risk. The one thing worth double-checking is the ubsan suppression path update, which doesn't line up with the four-suite split described in the MR.

@mathbunnyru
mathbunnyru added this pull request to the merge queue Aug 4, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Aug 4, 2026
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

This PR has conflicts, please resolve them in order for the PR to be reviewed.

…-split

# Conflicts:
#	src/test/app/Loan_test.cpp
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

All conflicts have been resolved. Assigned reviewers can now start or resume their review.

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

Most of the diff is file moves/deletions with no visible content, so the reviewable surface is small: a new protected accessor in suite.h, a renamed+trivially-edited LoanBroker_test.cpp, and a path update in ubsan.supp. The ubsan.supp change looks suspicious — it points at a file name that doesn't match any of the four topical suites described in the MR.

@mathbunnyru
mathbunnyru enabled auto-merge August 4, 2026 15:33
@mathbunnyru
mathbunnyru added this pull request to the merge queue Aug 4, 2026
Merged via the queue into develop with commit c3ee602 Aug 4, 2026
51 checks passed
@mathbunnyru
mathbunnyru deleted the tapanito/loan-test-split branch August 4, 2026 16:10
Tapanito added a commit that referenced this pull request Aug 6, 2026
Loan_test.cpp was split into topical suites under src/test/app/lending/
on develop (#7864). Port testLoanPayFundsConservedPayeeBelowReserve into
LoanPay_test.cpp.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready to merge *PR author* thinks it's ready to merge. Has passed code review. Perf sign-off may still be required.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants