18 #include <ripple/beast/unit_test.h>
19 #include <ripple/protocol/Feature.h>
31 testcase(
"Step Limit");
34 Env env(*
this, features);
36 auto const gw =
Account(
"gateway");
37 auto const USD = gw[
"USD"];
39 env.
fund(
XRP(100000000), gw,
"alice",
"bob",
"carol",
"dan");
40 env.
trust(USD(1),
"bob");
41 env(pay(gw,
"bob", USD(1)));
42 env.
trust(USD(1),
"dan");
43 env(pay(gw,
"dan", USD(1)));
49 env(offer(
"alice", USD(1000),
XRP(1000)));
59 env(offer(
"carol", USD(1000),
XRP(1000)));
71 testcase(
"Crossing Limit");
74 Env env(*
this, features);
76 auto const gw =
Account(
"gateway");
77 auto const USD = gw[
"USD"];
84 env.
fund(
XRP(100000000), gw,
"alice",
"bob",
"carol");
85 int const bobsOfferCount = maxConsumed + 150;
86 env.
trust(USD(bobsOfferCount),
"bob");
87 env(pay(gw,
"bob", USD(bobsOfferCount)));
89 n_offers(env, bobsOfferCount,
"bob",
XRP(1), USD(1));
93 env(offer(
"alice", USD(bobsOfferCount),
XRP(bobsOfferCount)));
101 env(offer(
"carol", USD(1000),
XRP(1000)));
111 testcase(
"Step And Crossing Limit");
114 Env env(*
this, features);
116 auto const gw =
Account(
"gateway");
117 auto const USD = gw[
"USD"];
119 env.
fund(
XRP(100000000), gw,
"alice",
"bob",
"carol",
"dan",
"evita");
125 int const maxConsumed = isFlowCross ? 1000 : 850;
127 int const evitasOfferCount{maxConsumed + 49};
128 env.
trust(USD(1000),
"alice");
129 env(pay(gw,
"alice", USD(1000)));
130 env.
trust(USD(1000),
"carol");
131 env(pay(gw,
"carol", USD(1)));
132 env.
trust(USD(evitasOfferCount + 1),
"evita");
133 env(pay(gw,
"evita", USD(evitasOfferCount + 1)));
142 int const carolsOfferCount{isFlowCross ? 700 : 850};
144 n_offers(env, carolsOfferCount,
"carol",
XRP(1), USD(1));
145 n_offers(env, evitasOfferCount,
"evita",
XRP(1), USD(1));
150 env(offer(
"bob", USD(1000),
XRP(1000)));
162 env(offer(
"dan", USD(maxConsumed + 50),
XRP(maxConsumed + 50)));
176 testcase(
"Auto Bridged Limits Taker");
179 Env env(*
this, features);
181 auto const gw =
Account(
"gateway");
182 auto const USD = gw[
"USD"];
183 auto const EUR = gw[
"EUR"];
185 env.
fund(
XRP(100000000), gw,
"alice",
"bob",
"carol",
"dan",
"evita");
187 env.
trust(USD(2000),
"alice");
188 env(pay(gw,
"alice", USD(2000)));
189 env.
trust(USD(1000),
"carol");
190 env(pay(gw,
"carol", USD(3)));
191 env.
trust(USD(1000),
"evita");
192 env(pay(gw,
"evita", USD(1000)));
197 n_offers(env, 1001,
"evita", EUR(1), USD(1));
215 env.
trust(EUR(10000),
"bob");
217 env(pay(gw,
"bob", EUR(1000)));
219 env(offer(
"bob", USD(2000), EUR(2000)));
244 env.
trust(EUR(10000),
"dan");
246 env(pay(gw,
"dan", EUR(1000)));
249 env(offer(
"dan", USD(900), EUR(900)));
272 testcase(
"Auto Bridged Limits FlowCross");
280 auto const gw =
Account(
"gateway");
281 auto const alice =
Account(
"alice");
282 auto const bob =
Account(
"bob");
283 auto const carol =
Account(
"carol");
285 auto const USD = gw[
"USD"];
286 auto const EUR = gw[
"EUR"];
301 Env env(*
this, features);
303 env.
fund(
XRP(100000000), gw, alice, bob, carol);
305 env.
trust(USD(4000), alice);
306 env(pay(gw, alice, USD(4000)));
307 env.
trust(USD(1000), carol);
308 env(pay(gw, carol, USD(3)));
315 env, 801, carol,
XRP(1), USD(3));
318 n_offers(env, 1, alice, EUR(500), USD(500));
358 env.
trust(EUR(10000), bob);
360 env(pay(gw, bob, EUR(2000)));
362 env(offer(bob, USD(4000), EUR(4000)));
372 auto const numAOffers =
373 2000 + 100 + 1000 + 1 - (2 * 100 + 2 * 199 + 1 + 1);
380 Env env(*
this, features);
382 env.
fund(
XRP(100000000), gw, alice, bob, carol);
384 env.
trust(USD(4000), alice);
385 env(pay(gw, alice, USD(4000)));
386 env.
trust(USD(1000), carol);
387 env(pay(gw, carol, USD(3)));
391 n_offers(env, 1, alice, EUR(1), USD(10));
395 env, 801, carol,
XRP(1), USD(3));
398 n_offers(env, 1, alice, EUR(499), USD(499));
431 env.
trust(EUR(10000), bob);
433 env(pay(gw, bob, EUR(2000)));
435 env(offer(bob, USD(4000), EUR(4000)));
445 auto const numAOffers =
446 1 + 2000 + 100 + 1000 + 1 - (1 + 2 * 100 + 2 * 199 + 1 + 1);
477 testcase(
"Offer Overflow");
481 auto const gw =
Account(
"gateway");
482 auto const alice =
Account(
"alice");
483 auto const bob =
Account(
"bob");
485 auto const USD = gw[
"USD"];
487 Env env(*
this, features);
489 env.
fund(
XRP(100000000), gw, alice, bob);
491 env.
trust(USD(8000), alice);
492 env.
trust(USD(8000), bob);
495 env(pay(gw, alice, USD(8000)));
527 auto const expectedTER = [&]() ->
TER {
528 if (withFlowCross && !withSortStrands)
533 env(offer(bob, USD(8000),
XRP(8000)),
ter(expectedTER));
536 auto const expectedUSD = [&] {
539 if (!withSortStrands)