From cc9dbe2243f644f35244d03044fa5171c4e6eef4 Mon Sep 17 00:00:00 2001 From: Vito <5780819+Tapanito@users.noreply.github.com> Date: Wed, 4 Mar 2026 13:03:51 +0100 Subject: [PATCH] fixes typos and improves test coverage --- .../tx/transactors/Vault/VaultDelete.cpp | 4 +- .../tx/transactors/Vault/VaultHelpers.cpp | 43 +++++++++++++------ src/libxrpl/tx/transactors/Vault/VaultSet.cpp | 3 +- src/test/app/Vault_test.cpp | 41 ++++++++++++++++++ 4 files changed, 74 insertions(+), 17 deletions(-) diff --git a/src/libxrpl/tx/transactors/Vault/VaultDelete.cpp b/src/libxrpl/tx/transactors/Vault/VaultDelete.cpp index bea335a451..d1e09f97d9 100644 --- a/src/libxrpl/tx/transactors/Vault/VaultDelete.cpp +++ b/src/libxrpl/tx/transactors/Vault/VaultDelete.cpp @@ -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 } diff --git a/src/libxrpl/tx/transactors/Vault/VaultHelpers.cpp b/src/libxrpl/tx/transactors/Vault/VaultHelpers.cpp index 82b04cdbe5..7380b7f0a9 100644 --- a/src/libxrpl/tx/transactors/Vault/VaultHelpers.cpp +++ b/src/libxrpl/tx/transactors/Vault/VaultHelpers.cpp @@ -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 const& vault, std::shared_ptr const& shareIssuance) +isVaultInsolvent( + std::shared_ptr const& vault, + std::shared_ptr const& shareIssuance) { XRPL_ASSERT(vault && vault->getType() == ltVAULT, "xrpl::isVaultInsolvent : Vault sle"); XRPL_ASSERT( diff --git a/src/libxrpl/tx/transactors/Vault/VaultSet.cpp b/src/libxrpl/tx/transactors/Vault/VaultSet.cpp index 8ac905192c..54024dcb52 100644 --- a/src/libxrpl/tx/transactors/Vault/VaultSet.cpp +++ b/src/libxrpl/tx/transactors/Vault/VaultSet.cpp @@ -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))) { diff --git a/src/test/app/Vault_test.cpp b/src/test/app/Vault_test.cpp index 66101fc252..88733d4834 100644 --- a/src/test/app/Vault_test.cpp +++ b/src/test/app/Vault_test.cpp @@ -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); } {