18 #include <ripple/beast/unit_test.h>
19 #include <ripple/protocol/Feature.h>
21 #include <test/jtx/TestHelpers.h>
32 testcase(
"Step Limit");
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)));
72 testcase(
"Crossing Limit");
75 Env env(*
this, features);
77 auto const gw =
Account(
"gateway");
78 auto const USD = gw[
"USD"];
85 env.
fund(
XRP(100000000), gw,
"alice",
"bob",
"carol");
86 int const bobsOfferCount = maxConsumed + 150;
87 env.
trust(USD(bobsOfferCount),
"bob");
88 env(pay(gw,
"bob", USD(bobsOfferCount)));
90 n_offers(env, bobsOfferCount,
"bob",
XRP(1), USD(1));
94 env(offer(
"alice", USD(bobsOfferCount),
XRP(bobsOfferCount)));
102 env(offer(
"carol", USD(1000),
XRP(1000)));
112 testcase(
"Step And Crossing Limit");
115 Env env(*
this, features);
117 auto const gw =
Account(
"gateway");
118 auto const USD = gw[
"USD"];
120 env.
fund(
XRP(100000000), gw,
"alice",
"bob",
"carol",
"dan",
"evita");
126 int const maxConsumed = isFlowCross ? 1000 : 850;
128 int const evitasOfferCount{maxConsumed + 49};
129 env.
trust(USD(1000),
"alice");
130 env(pay(gw,
"alice", USD(1000)));
131 env.
trust(USD(1000),
"carol");
132 env(pay(gw,
"carol", USD(1)));
133 env.
trust(USD(evitasOfferCount + 1),
"evita");
134 env(pay(gw,
"evita", USD(evitasOfferCount + 1)));
143 int const carolsOfferCount{isFlowCross ? 700 : 850};
145 n_offers(env, carolsOfferCount,
"carol",
XRP(1), USD(1));
146 n_offers(env, evitasOfferCount,
"evita",
XRP(1), USD(1));
151 env(offer(
"bob", USD(1000),
XRP(1000)));
163 env(offer(
"dan", USD(maxConsumed + 50),
XRP(maxConsumed + 50)));
177 testcase(
"Auto Bridged Limits Taker");
180 Env env(*
this, features);
182 auto const gw =
Account(
"gateway");
183 auto const USD = gw[
"USD"];
184 auto const EUR = gw[
"EUR"];
186 env.
fund(
XRP(100000000), gw,
"alice",
"bob",
"carol",
"dan",
"evita");
188 env.
trust(USD(2000),
"alice");
189 env(pay(gw,
"alice", USD(2000)));
190 env.
trust(USD(1000),
"carol");
191 env(pay(gw,
"carol", USD(3)));
192 env.
trust(USD(1000),
"evita");
193 env(pay(gw,
"evita", USD(1000)));
198 n_offers(env, 1001,
"evita", EUR(1), USD(1));
216 env.
trust(EUR(10000),
"bob");
218 env(pay(gw,
"bob", EUR(1000)));
220 env(offer(
"bob", USD(2000), EUR(2000)));
245 env.
trust(EUR(10000),
"dan");
247 env(pay(gw,
"dan", EUR(1000)));
250 env(offer(
"dan", USD(900), EUR(900)));
273 testcase(
"Auto Bridged Limits FlowCross");
281 auto const gw =
Account(
"gateway");
282 auto const alice =
Account(
"alice");
283 auto const bob =
Account(
"bob");
284 auto const carol =
Account(
"carol");
286 auto const USD = gw[
"USD"];
287 auto const EUR = gw[
"EUR"];
302 Env env(*
this, features);
304 env.
fund(
XRP(100000000), gw, alice, bob, carol);
306 env.
trust(USD(4000), alice);
307 env(pay(gw, alice, USD(4000)));
308 env.
trust(USD(1000), carol);
309 env(pay(gw, carol, USD(3)));
316 env, 801, carol,
XRP(1), USD(3));
319 n_offers(env, 1, alice, EUR(500), USD(500));
359 env.
trust(EUR(10000), bob);
361 env(pay(gw, bob, EUR(2000)));
363 env(offer(bob, USD(4000), EUR(4000)));
373 auto const numAOffers =
374 2000 + 100 + 1000 + 1 - (2 * 100 + 2 * 199 + 1 + 1);
381 Env env(*
this, features);
383 env.
fund(
XRP(100000000), gw, alice, bob, carol);
385 env.
trust(USD(4000), alice);
386 env(pay(gw, alice, USD(4000)));
387 env.
trust(USD(1000), carol);
388 env(pay(gw, carol, USD(3)));
392 n_offers(env, 1, alice, EUR(1), USD(10));
396 env, 801, carol,
XRP(1), USD(3));
399 n_offers(env, 1, alice, EUR(499), USD(499));
432 env.
trust(EUR(10000), bob);
434 env(pay(gw, bob, EUR(2000)));
436 env(offer(bob, USD(4000), EUR(4000)));
446 auto const numAOffers =
447 1 + 2000 + 100 + 1000 + 1 - (1 + 2 * 100 + 2 * 199 + 1 + 1);
478 testcase(
"Offer Overflow");
482 auto const gw =
Account(
"gateway");
483 auto const alice =
Account(
"alice");
484 auto const bob =
Account(
"bob");
486 auto const USD = gw[
"USD"];
488 Env env(*
this, features);
490 env.
fund(
XRP(100000000), gw, alice, bob);
492 env.
trust(USD(8000), alice);
493 env.
trust(USD(8000), bob);
496 env(pay(gw, alice, USD(8000)));
528 auto const expectedTER = [&]() ->
TER {
529 if (withFlowCross && !withSortStrands)
534 env(offer(bob, USD(8000),
XRP(8000)),
ter(expectedTER));
537 auto const expectedUSD = [&] {
540 if (!withSortStrands)