Add unit tests for invariant checks

Signed-off-by: JCW <a1q123456@users.noreply.github.com>
This commit is contained in:
JCW
2026-03-23 17:45:23 +00:00
parent eb46d9e417
commit 85ede3e422

View File

@@ -1987,6 +1987,7 @@ class Invariants_test : public beast::unit_test::suite
[](SLE::pointer& sle) { sle->at(sfManagementFeeRate) += 1; },
[](SLE::pointer& sle) { sle->at(sfCoverRateMinimum) += 1; },
[](SLE::pointer& sle) { sle->at(sfCoverRateLiquidation) += 1; },
[](SLE::pointer& sle) { sle->setFlag(lsfLoanBrokerPrivate); },
[](SLE::pointer& sle) { sle->at(sfLedgerEntryType) += 1; },
[](SLE::pointer& sle) { sle->at(sfLedgerIndex) = sle->at(sfVaultID).value(); },
});
@@ -2251,6 +2252,25 @@ class Invariants_test : public beast::unit_test::suite
STTx{ttLOAN_BROKER_SET, [](STObject& tx) {}},
{tecINVARIANT_FAILED, tefINVARIANT_FAILED},
createLoanBroker);
doInvariantCheck(
{{"DomainID is set on public Loan Broker"}},
[&](Account const& A1, Account const& A2, ApplyContext& ac) {
if (loanBrokerKeylet.type != ltLOAN_BROKER)
return false;
auto sleBroker = ac.view().peek(loanBrokerKeylet);
if (!sleBroker)
return false;
// Set DomainID without lsfLoanBrokerPrivate flag
sleBroker->clearFlag(lsfLoanBrokerPrivate);
sleBroker->at(sfDomainID) = uint256(42);
ac.view().update(sleBroker);
return true;
},
XRPAmount{},
STTx{ttLOAN_BROKER_SET, [](STObject& tx) {}},
{tecINVARIANT_FAILED, tefINVARIANT_FAILED},
createLoanBroker);
}
}