20#include <xrpl/beast/unit_test.h>
21#include <xrpl/protocol/Feature.h>
35 Env env(*
this, features);
37 auto const gw =
Account(
"gateway");
38 auto const USD = gw[
"USD"];
40 env.
fund(
XRP(100000000), gw,
"alice",
"bob",
"carol",
"dan");
41 env.
trust(USD(1),
"bob");
42 env(
pay(gw,
"bob", USD(1)));
43 env.
trust(USD(1),
"dan");
44 env(
pay(gw,
"dan", USD(1)));
50 env(
offer(
"alice", USD(1000),
XRP(1000)));
60 env(
offer(
"carol", USD(1000),
XRP(1000)));
75 Env env(*
this, features);
77 auto const gw =
Account(
"gateway");
78 auto const USD = gw[
"USD"];
81 int const maxConsumed = 1000;
83 env.
fund(
XRP(100000000), gw,
"alice",
"bob",
"carol");
84 int const bobsOfferCount = maxConsumed + 150;
85 env.
trust(USD(bobsOfferCount),
"bob");
86 env(
pay(gw,
"bob", USD(bobsOfferCount)));
88 n_offers(env, bobsOfferCount,
"bob",
XRP(1), USD(1));
92 env(
offer(
"alice", USD(bobsOfferCount),
XRP(bobsOfferCount)));
100 env(
offer(
"carol", USD(1000),
XRP(1000)));
110 testcase(
"Step And Crossing Limit");
113 Env env(*
this, features);
115 auto const gw =
Account(
"gateway");
116 auto const USD = gw[
"USD"];
118 env.
fund(
XRP(100000000), gw,
"alice",
"bob",
"carol",
"dan",
"evita");
121 int const maxConsumed = 1000;
123 int const evitasOfferCount{maxConsumed + 49};
124 env.
trust(USD(1000),
"alice");
125 env(
pay(gw,
"alice", USD(1000)));
126 env.
trust(USD(1000),
"carol");
127 env(
pay(gw,
"carol", USD(1)));
128 env.
trust(USD(evitasOfferCount + 1),
"evita");
129 env(
pay(gw,
"evita", USD(evitasOfferCount + 1)));
132 int const carolsOfferCount{700};
134 n_offers(env, carolsOfferCount,
"carol",
XRP(1), USD(1));
135 n_offers(env, evitasOfferCount,
"evita",
XRP(1), USD(1));
140 env(
offer(
"bob", USD(1000),
XRP(1000)));
152 env(
offer(
"dan", USD(maxConsumed + 50),
XRP(maxConsumed + 50)));
166 testcase(
"Auto Bridged Limits Taker");
169 Env env(*
this, features);
171 auto const gw =
Account(
"gateway");
172 auto const USD = gw[
"USD"];
173 auto const EUR = gw[
"EUR"];
175 env.
fund(
XRP(100000000), gw,
"alice",
"bob",
"carol",
"dan",
"evita");
177 env.
trust(USD(2000),
"alice");
178 env(
pay(gw,
"alice", USD(2000)));
179 env.
trust(USD(1000),
"carol");
180 env(
pay(gw,
"carol", USD(3)));
181 env.
trust(USD(1000),
"evita");
182 env(
pay(gw,
"evita", USD(1000)));
187 n_offers(env, 1001,
"evita", EUR(1), USD(1));
205 env.
trust(EUR(10000),
"bob");
207 env(
pay(gw,
"bob", EUR(1000)));
209 env(
offer(
"bob", USD(2000), EUR(2000)));
234 env.
trust(EUR(10000),
"dan");
236 env(
pay(gw,
"dan", EUR(1000)));
239 env(
offer(
"dan", USD(900), EUR(900)));
270 auto const gw =
Account(
"gateway");
271 auto const alice =
Account(
"alice");
272 auto const bob =
Account(
"bob");
273 auto const carol =
Account(
"carol");
275 auto const USD = gw[
"USD"];
276 auto const EUR = gw[
"EUR"];
291 Env env(*
this, features);
293 env.
fund(
XRP(100000000), gw, alice, bob, carol);
295 env.
trust(USD(4000), alice);
296 env(
pay(gw, alice, USD(4000)));
297 env.
trust(USD(1000), carol);
298 env(
pay(gw, carol, USD(3)));
305 env, 801, carol,
XRP(1), USD(3));
308 n_offers(env, 1, alice, EUR(500), USD(500));
348 env.
trust(EUR(10000), bob);
350 env(
pay(gw, bob, EUR(2000)));
352 env(
offer(bob, USD(4000), EUR(4000)));
362 auto const numAOffers =
363 2000 + 100 + 1000 + 1 - (2 * 100 + 2 * 199 + 1 + 1);
370 Env env(*
this, features);
372 env.
fund(
XRP(100000000), gw, alice, bob, carol);
374 env.
trust(USD(4000), alice);
375 env(
pay(gw, alice, USD(4000)));
376 env.
trust(USD(1000), carol);
377 env(
pay(gw, carol, USD(3)));
381 n_offers(env, 1, alice, EUR(1), USD(10));
385 env, 801, carol,
XRP(1), USD(3));
388 n_offers(env, 1, alice, EUR(499), USD(499));
421 env.
trust(EUR(10000), bob);
423 env(
pay(gw, bob, EUR(2000)));
425 env(
offer(bob, USD(4000), EUR(4000)));
435 auto const numAOffers =
436 1 + 2000 + 100 + 1000 + 1 - (1 + 2 * 100 + 2 * 199 + 1 + 1);
451 auto const gw =
Account(
"gateway");
452 auto const alice =
Account(
"alice");
453 auto const bob =
Account(
"bob");
455 auto const USD = gw[
"USD"];
457 Env env(*
this, features);
459 env.
fund(
XRP(100000000), gw, alice, bob);
461 env.
trust(USD(8000), alice);
462 env.
trust(USD(8000), bob);
465 env(
pay(gw, alice, USD(8000)));
494 bool const withSortStrands = features[featureFlowSortStrands];
496 auto const expectedTER = [&]() ->
TER {
497 if (!withSortStrands)
502 env(
offer(bob, USD(8000),
XRP(8000)),
ter(expectedTER));
505 auto const expectedUSD = [&] {
506 if (!withSortStrands)
527 testAll(sa - featureFlowSortStrands);
528 testAll(sa - featurePermissionedDEX);
529 testAll(sa - featureFlowSortStrands - featurePermissionedDEX);
533BEAST_DEFINE_TESTSUITE_MANUAL_PRIO(CrossingLimits, app,
ripple, 10);
testcase_t testcase
Memberspace for declaring test cases.
void testStepAndCrossingLimit(FeatureBitset features)
void testAutoBridgedLimitsTaker(FeatureBitset features)
void testAutoBridgedLimits(FeatureBitset features)
void testStepLimit(FeatureBitset features)
void testCrossingLimit(FeatureBitset features)
void run() override
Runs the suite.
void testOfferOverflow(FeatureBitset features)
Immutable cryptographic account descriptor.
A transaction testing environment.
void require(Args const &... args)
Check a set of requirements.
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
void trust(STAmount const &amount, Account const &account)
Establish trust lines.
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Match the number of items in the account's owner directory.
Set the expected result code for a JTx The test will fail if the code doesn't match.
owner_count< ltOFFER > offers
Match the number of offers in the account's owner directory.
Json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
void n_offers(Env &env, std::size_t n, Account const &account, STAmount const &in, STAmount const &out)
FeatureBitset testable_amendments()
Json::Value offer(Account const &account, STAmount const &takerPays, STAmount const &takerGets, std::uint32_t flags)
Create an offer.
XRP_t const XRP
Converts to XRP Issue or STAmount.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.