Add deep freeze check to LoanBrokerDelete (#6053)

- Add logging for missing vault
- Fix unit test
This commit is contained in:
Vito Tumas
2025-11-25 00:17:34 +01:00
committed by GitHub
parent 3ef6508490
commit 24586ef394
2 changed files with 42 additions and 1 deletions

View File

@@ -1063,6 +1063,20 @@ class LoanBroker_test : public beast::unit_test::suite
// preclaim: tecHAS_OBLIGATIONS
env(del(alice, brokerKeylet.key), ter(tecHAS_OBLIGATIONS));
// Repay and delete the loan
auto const loanKeylet = keylet::loan(brokerKeylet.key, 1);
env(loan::pay(borrower, loanKeylet.key, asset(50).value()));
env(loan::del(alice, loanKeylet.key));
env(trust(issuer, asset(0), alice, tfSetFreeze | tfSetDeepFreeze));
// preclaim: tecFROZEN (deep frozen)
env(del(alice, brokerKeylet.key), ter(tecFROZEN));
env(trust(
issuer, asset(0), alice, tfClearFreeze | tfClearDeepFreeze));
// successful delete the loan broker object
env(del(alice, brokerKeylet.key), ter(tesSUCCESS));
}
else
env(del(alice, brokerKeylet.key));

View File

@@ -33,7 +33,10 @@ LoanBrokerDelete::preclaim(PreclaimContext const& ctx)
JLOG(ctx.j.warn()) << "LoanBroker does not exist.";
return tecNO_ENTRY;
}
if (account != sleBroker->at(sfOwner))
auto const brokerOwner = sleBroker->at(sfOwner);
if (account != brokerOwner)
{
JLOG(ctx.j.warn()) << "Account is not the owner of the LoanBroker.";
return tecNO_PERMISSION;
@@ -68,6 +71,30 @@ LoanBrokerDelete::preclaim(PreclaimContext const& ctx)
}
}
auto const vault = ctx.view.read(keylet::vault(sleBroker->at(sfVaultID)));
if (!vault)
{
// LCOV_EXCL_START
JLOG(ctx.j.fatal()) << "Vault is missing for Broker " << brokerID;
return tefBAD_LEDGER;
// LCOV_EXCL_STOP
}
Asset const asset = vault->at(sfAsset);
auto const coverAvailable =
STAmount{asset, sleBroker->at(sfCoverAvailable)};
// If there are assets in the cover, broker will receive them on deletion.
// So we need to check if the broker owner is deep frozen for that asset.
if (coverAvailable > beast::zero)
{
if (auto const ret = checkDeepFrozen(ctx.view, brokerOwner, asset))
{
JLOG(ctx.j.warn()) << "Broker owner account is frozen.";
return ret;
}
}
return tesSUCCESS;
}