fixes typos and improves test coverage

This commit is contained in:
Vito
2026-03-04 13:03:51 +01:00
parent ebfa659593
commit cc9dbe2243
4 changed files with 74 additions and 17 deletions

View File

@@ -60,7 +60,7 @@ VaultDelete::preclaim(PreclaimContext const& ctx)
if (!sleMPT)
{
// LCOV_EXCL_START
JLOG(ctx.j.error()) << "VaultDeposit: missing issuance of vault shares.";
JLOG(ctx.j.error()) << "VaultDelete: missing issuance of vault shares.";
return tecOBJECT_NOT_FOUND;
// LCOV_EXCL_STOP
}
@@ -68,7 +68,7 @@ VaultDelete::preclaim(PreclaimContext const& ctx)
if (sleMPT->at(sfIssuer) != vault->getAccountID(sfAccount))
{
// LCOV_EXCL_START
JLOG(ctx.j.error()) << "VaultDeposit: invalid owner of vault shares.";
JLOG(ctx.j.error()) << "VaultDelete: invalid owner of vault shares.";
return tecNO_PERMISSION;
// LCOV_EXCL_STOP
}

View File

@@ -10,17 +10,22 @@ assetsToSharesDeposit(
{
XRPL_ASSERT(vault && vault->getType() == ltVAULT, "xrpl::assetsToSharesDeposit : Vault sle");
XRPL_ASSERT(
issuance && issuance->getType() == ltMPTOKEN_ISSUANCE, "xrpl::assetsToSharesDeposit : MPTokenIssuance sle");
issuance && issuance->getType() == ltMPTOKEN_ISSUANCE,
"xrpl::assetsToSharesDeposit : MPTokenIssuance sle");
XRPL_ASSERT(!assets.negative(), "xrpl::assetsToSharesDeposit : non-negative assets");
XRPL_ASSERT(assets.asset() == vault->at(sfAsset), "xrpl::assetsToSharesDeposit : assets and vault match");
XRPL_ASSERT(
assets.asset() == vault->at(sfAsset),
"xrpl::assetsToSharesDeposit : assets and vault match");
if (assets.negative() || assets.asset() != vault->at(sfAsset))
return std::nullopt; // LCOV_EXCL_LINE
Number const assetTotal = vault->at(sfAssetsTotal);
STAmount shares{vault->at(sfShareMPTID)};
if (assetTotal == 0)
return STAmount{shares.asset(), Number(assets.mantissa(), assets.exponent() + vault->at(sfScale)).truncate()};
return STAmount{
shares.asset(),
Number(assets.mantissa(), assets.exponent() + vault->at(sfScale)).truncate()};
Number const shareTotal = issuance->at(sfOutstandingAmount);
shares = ((shareTotal * assets) / assetTotal).truncate();
@@ -35,17 +40,21 @@ sharesToAssetsDeposit(
{
XRPL_ASSERT(vault && vault->getType() == ltVAULT, "xrpl::sharesToAssetsDeposit : Vault sle");
XRPL_ASSERT(
issuance && issuance->getType() == ltMPTOKEN_ISSUANCE, "xrpl::sharesToAssetsDeposit : MPTokenIssuance sle");
issuance && issuance->getType() == ltMPTOKEN_ISSUANCE,
"xrpl::sharesToAssetsDeposit : MPTokenIssuance sle");
XRPL_ASSERT(!shares.negative(), "xrpl::sharesToAssetsDeposit : non-negative shares");
XRPL_ASSERT(shares.asset() == vault->at(sfShareMPTID), "xrpl::sharesToAssetsDeposit : shares and vault match");
XRPL_ASSERT(
shares.asset() == vault->at(sfShareMPTID),
"xrpl::sharesToAssetsDeposit : shares and vault match");
if (shares.negative() || shares.asset() != vault->at(sfShareMPTID))
return std::nullopt; // LCOV_EXCL_LINE
Number const assetTotal = vault->at(sfAssetsTotal);
STAmount assets{vault->at(sfAsset)};
if (assetTotal == 0)
return STAmount{assets.asset(), shares.mantissa(), shares.exponent() - vault->at(sfScale), false};
return STAmount{
assets.asset(), shares.mantissa(), shares.exponent() - vault->at(sfScale), false};
Number const shareTotal = issuance->at(sfOutstandingAmount);
assets = (assetTotal * shares) / shareTotal;
@@ -61,10 +70,13 @@ assetsToSharesWithdraw(
{
XRPL_ASSERT(vault && vault->getType() == ltVAULT, "xrpl::assetsToSharesWithdraw : Vault sle");
XRPL_ASSERT(
issuance && issuance->getType() == ltMPTOKEN_ISSUANCE, "xrpl::assetsToSharesWithdraw : MPTokenIssuance sle");
issuance && issuance->getType() == ltMPTOKEN_ISSUANCE,
"xrpl::assetsToSharesWithdraw : MPTokenIssuance sle");
XRPL_ASSERT(!assets.negative(), "xrpl::assetsToSharesDeposit : non-negative assets");
XRPL_ASSERT(assets.asset() == vault->at(sfAsset), "xrpl::assetsToSharesWithdraw : assets and vault match");
XRPL_ASSERT(!assets.negative(), "xrpl::assetsToSharesWithdraw : non-negative assets");
XRPL_ASSERT(
assets.asset() == vault->at(sfAsset),
"xrpl::assetsToSharesWithdraw : assets and vault match");
if (assets.negative() || assets.asset() != vault->at(sfAsset))
return std::nullopt; // LCOV_EXCL_LINE
@@ -89,10 +101,13 @@ sharesToAssetsWithdraw(
{
XRPL_ASSERT(vault && vault->getType() == ltVAULT, "xrpl::sharesToAssetsWithdraw : Vault sle");
XRPL_ASSERT(
issuance && issuance->getType() == ltMPTOKEN_ISSUANCE, "xrpl::sharesToAssetsWithdraw : MPTokenIssuance sle");
issuance && issuance->getType() == ltMPTOKEN_ISSUANCE,
"xrpl::sharesToAssetsWithdraw : MPTokenIssuance sle");
XRPL_ASSERT(!shares.negative(), "xrpl::sharesToAssetsDeposit : non-negative shares");
XRPL_ASSERT(shares.asset() == vault->at(sfShareMPTID), "xrpl::sharesToAssetsWithdraw : shares and vault match");
XRPL_ASSERT(!shares.negative(), "xrpl::sharesToAssetsWithdraw : non-negative shares");
XRPL_ASSERT(
shares.asset() == vault->at(sfShareMPTID),
"xrpl::sharesToAssetsWithdraw : shares and vault match");
if (shares.negative() || shares.asset() != vault->at(sfShareMPTID))
return std::nullopt; // LCOV_EXCL_LINE
@@ -107,7 +122,9 @@ sharesToAssetsWithdraw(
}
[[nodiscard]] bool
isVaultInsolvent(std::shared_ptr<SLE const> const& vault, std::shared_ptr<SLE const> const& shareIssuance)
isVaultInsolvent(
std::shared_ptr<SLE const> const& vault,
std::shared_ptr<SLE const> const& shareIssuance)
{
XRPL_ASSERT(vault && vault->getType() == ltVAULT, "xrpl::isVaultInsolvent : Vault sle");
XRPL_ASSERT(

View File

@@ -23,7 +23,6 @@ VaultSet::checkExtraFeatures(PreflightContext const& ctx)
std::uint32_t
VaultSet::getFlagsMask(PreflightContext const& ctx)
{
// VaultSet mask is built assuming fixLendingProtocolV1_1 is enabled
if (ctx.rules.enabled(fixLendingProtocolV1_1))
return tfVaultSetMask;
@@ -137,7 +136,7 @@ VaultSet::preclaim(PreclaimContext const& ctx)
if (ctx.view.rules().enabled(fixLendingProtocolV1_1))
{
// The Vault does not configured to support deposit blocking
// The Vault is not configured to support deposit blocking
if (!vault->isFlag(lsfVaultOwnerCanBlockDeposit) &&
(ctx.tx.isFlag(tfVaultDepositBlock) || ctx.tx.isFlag(tfVaultDepositUnblock)))
{

View File

@@ -5768,9 +5768,17 @@ class Vault_test : public beast::unit_test::suite
}),
ter(tesSUCCESS),
THISLINE);
env(vault.deposit({
.depositor = other,
.id = keylet.key,
.amount = XRP(10'000),
}),
ter(tesSUCCESS),
THISLINE);
blockVault(tesSUCCESS, keylet);
// Owner is blocked from depositing to the vault
env(vault.deposit({
.depositor = owner,
.id = keylet.key,
@@ -5779,6 +5787,15 @@ class Vault_test : public beast::unit_test::suite
ter(tecNO_PERMISSION),
THISLINE);
// Other accounts are also blocked from depositing to the vault
env(vault.deposit({
.depositor = other,
.id = keylet.key,
.amount = XRP(10'000),
}),
ter(tecNO_PERMISSION),
THISLINE);
// Block vault withdrawal works as normal
env(vault.withdraw({
.depositor = owner,
@@ -5788,6 +5805,14 @@ class Vault_test : public beast::unit_test::suite
ter(tesSUCCESS),
THISLINE);
env(vault.withdraw({
.depositor = other,
.id = keylet.key,
.amount = XRP(10'000),
}),
ter(tesSUCCESS),
THISLINE);
unblockVault(tesSUCCESS, keylet);
env(vault.deposit({
@@ -5798,6 +5823,14 @@ class Vault_test : public beast::unit_test::suite
ter(tesSUCCESS),
THISLINE);
env(vault.deposit({
.depositor = other,
.id = keylet.key,
.amount = XRP(10'000),
}),
ter(tesSUCCESS),
THISLINE);
// Withdraw to keep the vault empty
env(vault.withdraw({
.depositor = owner,
@@ -5806,6 +5839,14 @@ class Vault_test : public beast::unit_test::suite
}),
ter(tesSUCCESS),
THISLINE);
env(vault.withdraw({
.depositor = other,
.id = keylet.key,
.amount = XRP(10'000),
}),
ter(tesSUCCESS),
THISLINE);
}
{