From 0fbe696b35017c544dd91ff1b980b58153d329ae Mon Sep 17 00:00:00 2001 From: Gregory Tsipenyuk Date: Mon, 29 Jan 2024 15:12:16 -0500 Subject: [PATCH] [FOLD] update unit test --- src/test/app/AMM_test.cpp | 85 ++++++++++++++++++++++++++++++++------- 1 file changed, 71 insertions(+), 14 deletions(-) diff --git a/src/test/app/AMM_test.cpp b/src/test/app/AMM_test.cpp index 75b6adbcacc..68d395ce536 100644 --- a/src/test/app/AMM_test.cpp +++ b/src/test/app/AMM_test.cpp @@ -4798,8 +4798,11 @@ struct AMM_test : public jtx::AMMTest auto test = [&](FeatureBitset features, TER const& err1, TER const& err2, + TER const& err3, + TER const& err4, std::uint16_t tfee, - bool closeLedger) { + bool closeLedger, + std::optional extra = std::nullopt) { Env env(*this, features); fund(env, gw, {alice}, XRP(1'000), {USD(10)}); AMM amm( @@ -4808,32 +4811,86 @@ struct AMM_test : public jtx::AMMTest XRP(10), USD(10), {.tfee = tfee, .close = closeLedger}); - amm.deposit(alice, USD(5)); + amm.deposit(alice, USD(10), XRP(10)); amm.vote( - alice, 0, std::nullopt, std::nullopt, std::nullopt, ter(err1)); - amm.withdraw(gw, USD(10), std::nullopt, std::nullopt, ter(err2)); + alice, + tfee, + std::nullopt, + std::nullopt, + std::nullopt, + ter(err1)); + amm.withdraw(gw, USD(1), std::nullopt, std::nullopt, ter(err2)); + // with the amendment disabled and ledger not closed, + // second vote succeeds if the first vote sets the trading fee + // to non-zero; if the first vote sets the trading fee to >0 && <9 + // then the second withdraw succeeds if the second vote sets + // the trading fee so that the discounted fee is non-zero + amm.vote( + alice, 20, std::nullopt, std::nullopt, std::nullopt, ter(err3)); + amm.withdraw(gw, USD(2), std::nullopt, std::nullopt, ter(err4)); }; // ledger is closed after each transaction, vote/withdraw don't fail - // regardless if the amendment is enabled or not - test(all, tesSUCCESS, tesSUCCESS, 0, true); - test(all - fixInnerObjTemplDefault, tesSUCCESS, tesSUCCESS, 0, true); + // regardless whether the amendment is enabled or not + test(all, tesSUCCESS, tesSUCCESS, tesSUCCESS, tesSUCCESS, 0, true); + test( + all - fixInnerObjTemplDefault, + tesSUCCESS, + tesSUCCESS, + tesSUCCESS, + tesSUCCESS, + 0, + true); // ledger is not closed after each transaction // vote/withdraw don't fail if the amendment is enabled - test(all, tesSUCCESS, tesSUCCESS, 0, false); + test(all, tesSUCCESS, tesSUCCESS, tesSUCCESS, tesSUCCESS, 0, false); // vote/withdraw fail if the amendment is not enabled + // second vote/withdraw still fail: second vote fails because + // the initial trading fee is 0, consequently second withdraw fails + // because the second vote fails test( all - fixInnerObjTemplDefault, tefEXCEPTION, tefEXCEPTION, + tefEXCEPTION, + tefEXCEPTION, 0, false); - // if non-zero fee then vote/withdraw don't fail whether the ledger - // is closed or not and the amendment enabled or not - test(all, tesSUCCESS, tesSUCCESS, 100, true); - test(all - fixInnerObjTemplDefault, tesSUCCESS, tesSUCCESS, 100, true); - test(all, tesSUCCESS, tesSUCCESS, 100, false); - test(all - fixInnerObjTemplDefault, tesSUCCESS, tesSUCCESS, 100, false); + // if non-zero trading/discounted fee then vote/withdraw + // don't fail whether the ledger is closed or not and + // the amendment is enabled or not + test(all, tesSUCCESS, tesSUCCESS, tesSUCCESS, tesSUCCESS, 10, true); + test( + all - fixInnerObjTemplDefault, + tesSUCCESS, + tesSUCCESS, + tesSUCCESS, + tesSUCCESS, + 10, + true); + test(all, tesSUCCESS, tesSUCCESS, tesSUCCESS, tesSUCCESS, 10, false); + test( + all - fixInnerObjTemplDefault, + tesSUCCESS, + tesSUCCESS, + tesSUCCESS, + tesSUCCESS, + 10, + false); + // non-zero trading fee but discounted fee is 0, vote doesn't fail + // but withdraw fails + test(all, tesSUCCESS, tesSUCCESS, tesSUCCESS, tesSUCCESS, 9, false); + // second vote sets the trading fee to non-zero, consequently + // second withdraw doesn't fail even if the amendment is not + // enabled and the ledger is not closed + test( + all - fixInnerObjTemplDefault, + tesSUCCESS, + tefEXCEPTION, + tesSUCCESS, + tesSUCCESS, + 9, + false); } void