Skip to content

Commit

Permalink
[FOLD] update unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
gregtatcam committed Jan 29, 2024
1 parent b978e23 commit 0fbe696
Showing 1 changed file with 71 additions and 14 deletions.
85 changes: 71 additions & 14 deletions src/test/app/AMM_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::uint16_t> extra = std::nullopt) {
Env env(*this, features);
fund(env, gw, {alice}, XRP(1'000), {USD(10)});
AMM amm(
Expand All @@ -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
Expand Down

0 comments on commit 0fbe696

Please sign in to comment.