From daa1303b5a700ee66aee6209e411ad07496b37d5 Mon Sep 17 00:00:00 2001 From: Shawn Xie <35279399+shawnxie999@users.noreply.github.com> Date: Fri, 17 Oct 2025 14:19:19 -0400 Subject: [PATCH] Update decryption test helper function (#5907) --- src/test/jtx/impl/mpt.cpp | 49 +++++++++++++++++++++++++-------------- src/test/jtx/mpt.h | 5 ++++ 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/test/jtx/impl/mpt.cpp b/src/test/jtx/impl/mpt.cpp index 069cdc0da7..fb2e9b4daa 100644 --- a/src/test/jtx/impl/mpt.cpp +++ b/src/test/jtx/impl/mpt.cpp @@ -625,15 +625,6 @@ MPTTester::convert(MPTConvert const& arg) auto const holderAmt = getBalance(*arg.account); auto const prevConfidentialOutstanding = getIssuanceConfidentialBalance(); - auto getDecryptedBalance = - [&](auto const& account, EncryptedBalanceType balanceType) -> uint64_t { - auto maybeEncrypted = getEncryptedBalance(account, balanceType); - auto accountToDecrypt = - balanceType == ISSUER_ENCRYPTED_BALANCE ? issuer_ : account; - return maybeEncrypted ? decryptAmount(accountToDecrypt, *maybeEncrypted) - : 0; - }; - uint64_t prevInboxBalance = getDecryptedBalance(*arg.account, HOLDER_ENCRYPTED_INBOX); uint64_t prevSpendingBalance = @@ -651,27 +642,36 @@ MPTTester::convert(MPTConvert const& arg) curConfidentialOutstanding; })); + uint64_t postInboxBalance = + getDecryptedBalance(*arg.account, HOLDER_ENCRYPTED_INBOX); + uint64_t postIssuerBalance = + getDecryptedBalance(*arg.account, ISSUER_ENCRYPTED_BALANCE); + uint64_t postSpendingBalance = + getDecryptedBalance(*arg.account, HOLDER_ENCRYPTED_SPENDING); + + std::cout << "\n postIssuerBalance is " << postIssuerBalance << '\n'; + std::cout << "\n postInboxBalance is " << postInboxBalance << '\n'; + // spending balance should not change env_.require(requireAny([&]() -> bool { - uint64_t postSpendingBalance = - getDecryptedBalance(*arg.account, HOLDER_ENCRYPTED_SPENDING); return postSpendingBalance == prevSpendingBalance; })); + // issuer's encrypted balance is updated correctly env_.require(requireAny([&]() -> bool { - uint64_t postIssuerBalance = - getDecryptedBalance(*arg.account, ISSUER_ENCRYPTED_BALANCE); - std::cout << "\n postIssuerBalance is " << postIssuerBalance - << '\n'; return prevIssuerBalance + *arg.amt == postIssuerBalance; })); + // holder's inbox balance is updated correctly env_.require(requireAny([&]() -> bool { - uint64_t postInboxBalance = - getDecryptedBalance(*arg.account, HOLDER_ENCRYPTED_INBOX); - std::cout << "\n postInboxBalance is " << postInboxBalance << '\n'; return prevInboxBalance + *arg.amt == postInboxBalance; })); + + // sum of holder's inbox and spending balance should equal to issuer's + // encrypted balance + env_.require(requireAny([&]() -> bool { + return postInboxBalance + postSpendingBalance == postIssuerBalance; + })); } } @@ -741,6 +741,19 @@ MPTTester::decryptAmount(Account const& account, Buffer const& amt) const return decryptedAmt; } +uint64_t +MPTTester::getDecryptedBalance( + Account const& account, + EncryptedBalanceType balanceType) const + +{ + auto maybeEncrypted = getEncryptedBalance(account, balanceType); + auto accountToDecrypt = + balanceType == ISSUER_ENCRYPTED_BALANCE ? issuer_ : account; + return maybeEncrypted ? decryptAmount(accountToDecrypt, *maybeEncrypted) + : 0; +}; + } // namespace jtx } // namespace test } // namespace ripple diff --git a/src/test/jtx/mpt.h b/src/test/jtx/mpt.h index e031e661cb..273d02a9ed 100644 --- a/src/test/jtx/mpt.h +++ b/src/test/jtx/mpt.h @@ -295,6 +295,11 @@ public: uint64_t decryptAmount(Account const& account, Buffer const& amt) const; + uint64_t + getDecryptedBalance( + Account const& account, + EncryptedBalanceType balanceType) const; + private: using SLEP = std::shared_ptr; bool