Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: enable unit tests to work with variable reference fee #5145

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/test/app/AMMExtended_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3230,7 +3230,9 @@ struct AMMExtended_test : public jtx::AMMTest
txflags(tfPartialPayment),
sendmax(XRP(5)),
ter(tecPATH_PARTIAL));
env.require(balance(alice, XRP(9'999.99999)));
env.require(balance(
alice,
drops(10'000'000'000 - env.current()->fees().base.drops())));
env.require(balance(bob, XRP(10'000)));
}

Expand Down
49 changes: 34 additions & 15 deletions src/test/app/AMM_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1239,14 +1239,15 @@ struct AMM_test : public jtx::AMMTest

// Equal deposit: 1000000 tokens, 10% of the current pool
testAMM([&](AMM& ammAlice, Env& env) {
auto const baseFee = env.current()->fees().base;
ammAlice.deposit(carol, 1'000'000);
BEAST_EXPECT(ammAlice.expectBalances(
XRP(11'000), USD(11'000), IOUAmount{11'000'000, 0}));
// 30,000 less deposited 1,000
BEAST_EXPECT(expectLine(env, carol, USD(29'000)));
// 30,000 less deposited 1,000 and 10 drops tx fee
BEAST_EXPECT(
expectLedgerEntryRoot(env, carol, XRPAmount{28'999'999'990}));
BEAST_EXPECT(expectLedgerEntryRoot(
env, carol, XRPAmount{29'000'000'000 - baseFee}));
});

// equal asset deposit: unit test to exercise the rounding-down of
Expand Down Expand Up @@ -2056,6 +2057,7 @@ struct AMM_test : public jtx::AMMTest
// Equal withdrawal by Carol: 1000000 of tokens, 10% of the current
// pool
testAMM([&](AMM& ammAlice, Env& env) {
auto const baseFee = env.current()->fees().base.drops();
// Single deposit of 100000 worth of tokens,
// which is 10% of the pool. Carol is LP now.
ammAlice.deposit(carol, 1'000'000);
Expand All @@ -2066,16 +2068,16 @@ struct AMM_test : public jtx::AMMTest
// 30,000 less deposited 1,000
BEAST_EXPECT(expectLine(env, carol, USD(29'000)));
// 30,000 less deposited 1,000 and 10 drops tx fee
BEAST_EXPECT(
expectLedgerEntryRoot(env, carol, XRPAmount{28'999'999'990}));
BEAST_EXPECT(expectLedgerEntryRoot(
env, carol, XRPAmount{29'000'000'000 - baseFee}));

// Carol withdraws all tokens
ammAlice.withdraw(carol, 1'000'000);
BEAST_EXPECT(
ammAlice.expectLPTokens(carol, IOUAmount(beast::Zero())));
BEAST_EXPECT(expectLine(env, carol, USD(30'000)));
BEAST_EXPECT(
expectLedgerEntryRoot(env, carol, XRPAmount{29'999'999'980}));
BEAST_EXPECT(expectLedgerEntryRoot(
env, carol, XRPAmount{30'000'000'000 - 2 * baseFee}));
});

// Equal withdrawal by tokens 1000000, 10%
Expand Down Expand Up @@ -3222,12 +3224,14 @@ struct AMM_test : public jtx::AMMTest
// preflight tests
{
Env env(*this, features);
auto const baseFee = env.current()->fees().base;

fund(env, gw, {alice, bob}, XRP(2'000), {USD(2'000)});
AMM amm(env, gw, XRP(1'000), USD(1'010), false, 1'000);
Json::Value tx = amm.bid({.account = alice, .bidMin = 500});

{
auto jtx = env.jt(tx, seq(1), fee(10));
auto jtx = env.jt(tx, seq(1), fee(baseFee));
env.app().config().features.erase(featureAMM);
PreflightContext pfctx(
env.app(),
Expand All @@ -3241,7 +3245,7 @@ struct AMM_test : public jtx::AMMTest
}

{
auto jtx = env.jt(tx, seq(1), fee(10));
auto jtx = env.jt(tx, seq(1), fee(baseFee));
jtx.jv["TxnSignature"] = "deadbeef";
jtx.stx = env.ust(jtx);
PreflightContext pfctx(
Expand All @@ -3255,7 +3259,7 @@ struct AMM_test : public jtx::AMMTest
}

{
auto jtx = env.jt(tx, seq(1), fee(10));
auto jtx = env.jt(tx, seq(1), fee(baseFee));
jtx.jv["Asset2"]["currency"] = "XRP";
jtx.jv["Asset2"].removeMember("issuer");
jtx.stx = env.ust(jtx);
Expand Down Expand Up @@ -3314,11 +3318,12 @@ struct AMM_test : public jtx::AMMTest

// Can't pay into AMM with escrow.
testAMM([&](AMM& ammAlice, Env& env) {
auto const baseFee = env.current()->fees().base;
env(escrow(carol, ammAlice.ammAccount(), XRP(1)),
condition(cb1),
finish_time(env.now() + 1s),
cancel_time(env.now() + 2s),
fee(1'500),
fee(baseFee * 150),
ter(tecNO_PERMISSION));
});

Expand Down Expand Up @@ -4407,6 +4412,7 @@ struct AMM_test : public jtx::AMMTest

// Offer crossing with AMM LPTokens and XRP.
testAMM([&](AMM& ammAlice, Env& env) {
auto const baseFee = env.current()->fees().base.drops();
auto const token1 = ammAlice.lptIssue();
auto priceXRP = withdrawByTokens(
STAmount{XRPAmount{10'000'000'000}},
Expand All @@ -4432,15 +4438,19 @@ struct AMM_test : public jtx::AMMTest
env(ammAlice.bid({.account = carol, .bidMin = 100}));
BEAST_EXPECT(ammAlice.expectLPTokens(carol, IOUAmount{4'999'900}));
BEAST_EXPECT(ammAlice.expectAuctionSlot(0, 0, IOUAmount{100}));
BEAST_EXPECT(accountBalance(env, carol) == "22499999960");
BEAST_EXPECT(
accountBalance(env, carol) ==
std::to_string(22500000000 - 4 * baseFee));
priceXRP = withdrawByTokens(
STAmount{XRPAmount{10'000'000'000}},
STAmount{token1, 9'999'900},
STAmount{token1, 4'999'900},
0);
// Carol withdraws
ammAlice.withdrawAll(carol, XRP(0));
BEAST_EXPECT(accountBalance(env, carol) == "29999949949");
BEAST_EXPECT(
accountBalance(env, carol) ==
std::to_string(29999949999 - 5 * baseFee));
BEAST_EXPECT(ammAlice.expectBalances(
XRPAmount{10'000'000'000} - priceXRP,
USD(10'000),
Expand Down Expand Up @@ -5154,7 +5164,10 @@ struct AMM_test : public jtx::AMMTest
BEAST_EXPECT(expectLine(env, alice, USD(30'000)));
// alice XRP balance is 30,000initial - 50 ammcreate fee -
// 10drops fee
BEAST_EXPECT(accountBalance(env, alice) == "29949999990");
BEAST_EXPECT(
accountBalance(env, alice) ==
std::to_string(
29950000000 - env.current()->fees().base.drops()));
},
std::nullopt,
0,
Expand Down Expand Up @@ -5210,13 +5223,19 @@ struct AMM_test : public jtx::AMMTest
BEAST_EXPECT(accountBalance(env, simon) == xrpBalance);
BEAST_EXPECT(accountBalance(env, chris) == xrpBalance);
BEAST_EXPECT(accountBalance(env, dan) == xrpBalance);

auto const baseFee = env.current()->fees().base.drops();
// 30,000 initial - (deposit+withdraw) * 10
BEAST_EXPECT(accountBalance(env, carol) == "29999999800");
BEAST_EXPECT(
accountBalance(env, carol) ==
std::to_string(30000000000 - 20 * baseFee));
BEAST_EXPECT(accountBalance(env, ed) == xrpBalance);
BEAST_EXPECT(accountBalance(env, paul) == xrpBalance);
BEAST_EXPECT(accountBalance(env, nataly) == xrpBalance);
// 30,000 initial - 50 ammcreate fee - 10drops withdraw fee
BEAST_EXPECT(accountBalance(env, alice) == "29949999990");
BEAST_EXPECT(
accountBalance(env, alice) ==
std::to_string(29950000000 - baseFee));
});
}

Expand Down
9 changes: 6 additions & 3 deletions src/test/app/DID_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ struct DID_test : public beast::unit_test::suite
// the reserve for creating a DID.
auto const acctReserve = env.current()->fees().accountReserve(0);
auto const incReserve = env.current()->fees().increment;
auto const baseFee = env.current()->fees().base;
env.fund(acctReserve, alice);
env.close();
BEAST_EXPECT(env.balance(alice) == acctReserve);
Expand All @@ -98,8 +99,10 @@ struct DID_test : public beast::unit_test::suite
BEAST_EXPECT(ownerCount(env, alice) == 0);

// Pay alice almost enough to make the reserve for a DID.
env(pay(env.master, alice, incReserve + drops(19)));
BEAST_EXPECT(env.balance(alice) == acctReserve + incReserve + drops(9));
env(pay(env.master, alice, drops(incReserve + 2 * baseFee - 1)));
BEAST_EXPECT(
env.balance(alice) ==
acctReserve + incReserve + drops(baseFee - 1));
env.close();

// alice still does not have enough XRP for the reserve of a DID.
Expand All @@ -108,7 +111,7 @@ struct DID_test : public beast::unit_test::suite
BEAST_EXPECT(ownerCount(env, alice) == 0);

// Pay alice enough to make the reserve for a DID.
env(pay(env.master, alice, drops(11)));
env(pay(env.master, alice, drops(baseFee + 1)));
env.close();

// Now alice can create a DID.
Expand Down
3 changes: 2 additions & 1 deletion src/test/app/DeliverMin_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ class DeliverMin_test : public beast::unit_test::suite
txflags(tfPartialPayment),
sendmax(XRP(5)),
ter(tecPATH_PARTIAL));
env.require(balance("alice", XRP(9999.99999)));
env.require(balance(
"alice", XRP(10000) - drops(env.current()->fees().base)));
env.require(balance("bob", XRP(10000)));
}

Expand Down
11 changes: 6 additions & 5 deletions src/test/app/DepositAuth_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,19 @@ struct DepositAuth_test : public beast::unit_test::suite
Account const bob{"bob"};

Env env(*this);
auto const baseFee = env.current()->fees().base;

env.fund(XRP(10000), alice, bob);

// bob sets the lsfDepositAuth flag.
env(fset(bob, asfDepositAuth), fee(drops(10)));
env(fset(bob, asfDepositAuth), fee(drops(baseFee)));
env.close();
BEAST_EXPECT(env.balance(bob, XRP) == XRP(10000) - drops(10));
BEAST_EXPECT(env.balance(bob, XRP) == XRP(10000) - drops(baseFee));

// bob has more XRP than the base reserve. Any XRP payment should fail.
env(pay(alice, bob, drops(1)), ter(tecNO_PERMISSION));
env.close();
BEAST_EXPECT(env.balance(bob, XRP) == XRP(10000) - drops(10));
BEAST_EXPECT(env.balance(bob, XRP) == XRP(10000) - drops(baseFee));

// Change bob's XRP balance to exactly the base reserve.
{
Expand Down Expand Up @@ -257,7 +258,7 @@ struct DepositAuth_test : public beast::unit_test::suite
BEAST_EXPECT(env.balance(bob, XRP) == drops(1));

// Pay bob enough so he can afford the fee to clear lsfDepositAuth.
env(pay(alice, bob, drops(9)));
env(pay(alice, bob, drops(baseFee - 1)));
env.close();

// Interestingly, at this point the terINSUF_FEE_B retry grabs the
Expand Down Expand Up @@ -550,7 +551,7 @@ struct DepositPreauth_test : public beast::unit_test::suite
env.require(owners(becky, 0));

// carol gets enough XRP to (barely) meet the reserve.
env(pay(alice, carol, drops(11)));
env(pay(alice, carol, drops(env.current()->fees().base + 1)));
env.close();
env(deposit::auth(carol, becky));
env.close();
Expand Down
Loading
Loading