From c325b6c7f5db20b51fb3ae4ed581670ea3313d32 Mon Sep 17 00:00:00 2001 From: Bronek Kozicki Date: Fri, 17 Jan 2025 15:46:26 +0000 Subject: [PATCH] Fix Vault unit tests --- include/xrpl/protocol/STAmount.h | 1 + src/libxrpl/protocol/STAmount.cpp | 2 ++ src/test/app/Vault_test.cpp | 13 ++++++------- src/xrpld/app/tx/detail/VaultClawback.cpp | 14 +++++++------- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/include/xrpl/protocol/STAmount.h b/include/xrpl/protocol/STAmount.h index 20465c8d8a..655801eb1e 100644 --- a/include/xrpl/protocol/STAmount.h +++ b/include/xrpl/protocol/STAmount.h @@ -556,6 +556,7 @@ STAmount::operator=(Number const& number) mIsNegative = number.mantissa() < 0; mValue = mIsNegative ? -number.mantissa() : number.mantissa(); mOffset = number.exponent(); + canonicalize(); return *this; } diff --git a/src/libxrpl/protocol/STAmount.cpp b/src/libxrpl/protocol/STAmount.cpp index d9538a88d4..dad5f435c4 100644 --- a/src/libxrpl/protocol/STAmount.cpp +++ b/src/libxrpl/protocol/STAmount.cpp @@ -276,6 +276,7 @@ STAmount::xrp() const "Cannot return non-native STAmount as XRPAmount"); auto drops = static_cast(mValue); + XRPL_ASSERT(mOffset == 0, "ripple::STAmount::xrp : amount is canonical"); if (mIsNegative) drops = -drops; @@ -305,6 +306,7 @@ STAmount::mpt() const Throw("Cannot return STAmount as MPTAmount"); auto value = static_cast(mValue); + XRPL_ASSERT(mOffset == 0, "ripple::STAmount::mpt : amount is canonical"); if (mIsNegative) value = -value; diff --git a/src/test/app/Vault_test.cpp b/src/test/app/Vault_test.cpp index 83c09eb8be..b309a21a2f 100644 --- a/src/test/app/Vault_test.cpp +++ b/src/test/app/Vault_test.cpp @@ -175,13 +175,12 @@ class Vault_test : public beast::unit_test::suite env(tx, ter(tecNO_PERMISSION)); } - // TODO: Fix this - // { - // testcase("delete empty vault"); - // auto tx = vault.del({.owner = owner, .id = keylet.key}); - // env(tx); - // BEAST_EXPECT(!env.le(keylet)); - // } + { + testcase("delete empty vault"); + auto tx = vault.del({.owner = owner, .id = keylet.key}); + env(tx); + BEAST_EXPECT(!env.le(keylet)); + } } TEST_CASE(Sequences) diff --git a/src/xrpld/app/tx/detail/VaultClawback.cpp b/src/xrpld/app/tx/detail/VaultClawback.cpp index 9ef7022b9a..a4f6eff2b7 100644 --- a/src/xrpld/app/tx/detail/VaultClawback.cpp +++ b/src/xrpld/app/tx/detail/VaultClawback.cpp @@ -107,14 +107,14 @@ VaultClawback::doApply() vault->at(sfAssetAvailable) -= assets; view().update(vault); - // auto const& vaultAccount = vault->at(sfAccount); - // // Transfer shares from holder to vault. - // if (auto ter = accountSend(view(), holder, vaultAccount, shares, j_)) - // return ter; + auto const& vaultAccount = vault->at(sfAccount); + // Transfer shares from holder to vault. + if (auto ter = accountSend(view(), holder, vaultAccount, shares, j_)) + return ter; - // // Transfer assets from vault to issuer. - // if (auto ter = accountSend(view(), vaultAccount, account_, assets, j_)) - // return ter; + // Transfer assets from vault to issuer. + if (auto ter = accountSend(view(), vaultAccount, account_, assets, j_)) + return ter; return tesSUCCESS; }