18 #include <ripple/app/paths/Flow.h>
19 #include <ripple/app/paths/RippleCalc.h>
20 #include <ripple/app/paths/impl/Steps.h>
21 #include <ripple/basics/contract.h>
22 #include <ripple/basics/safe_cast.h>
23 #include <ripple/core/Config.h>
24 #include <ripple/ledger/ApplyViewImpl.h>
25 #include <ripple/ledger/PaymentSandbox.h>
26 #include <ripple/ledger/Sandbox.h>
27 #include <ripple/protocol/Feature.h>
28 #include <ripple/protocol/jss.h>
29 #include "ripple/app/paths/AMMContext.h"
31 #include <test/jtx/PathSet.h>
32 #include <test/jtx/TestHelpers.h>
82 auto const useHigh = src.
id() > dst.
id();
83 return sle->isFlag(
trustFlag(flag, useHigh));
85 Throw<std::runtime_error>(
"No line in getTrustFlag");
113 template <
class Iter>
121 template <
class Iter,
class StepInfo,
class... Args>
125 if (!
equal(*i, std::forward<StepInfo>(si)))
130 template <
class... Args>
132 equal(Strand
const& strand, Args&&... args)
134 if (strand.size() !=
sizeof...(Args))
200 return state_ & (1 << safe_cast<int>(s));
206 for (
auto const s : sb)
217 for (
auto const s : sb)
264 class CurrencyFactory>
270 CurrencyFactory&& currencyF,
307 col.emplace_back(acc, cur, iss);
310 STPathElement::Type::typeBoundary,
384 assert(!offererIndex || offererIndex < numAct);
393 constexpr
size_t bufSize = 32;
396 for (
size_t id = 0;
id < numAct; ++id)
398 snprintf(buf, bufSize,
"A%zu",
id);
402 for (
size_t id = 0;
id < numCur; ++id)
405 snprintf(buf, bufSize,
"CC%zu",
id);
407 snprintf(buf, bufSize,
"C%zu",
id);
409 snprintf(buf, bufSize,
"%zu",
id);
421 for (
auto ai2 =
accounts.begin(); ai2 != aie; ++ai2)
427 env.
trust((*ai1)[cn](1
'000'000), *ai2);
433 auto const& src = *ai1;
434 auto const& dst = *ai2;
435 env(pay(src, dst, src[cn](500000)));
449 for (
auto takerPays = ious.
begin(), ie = ious.
end(); takerPays != ie;
452 for (
auto takerGets = ious.
begin(); takerGets != ie; ++takerGets)
454 if (takerPays == takerGets)
457 offererIndex ?
accounts[*offererIndex] : takerGets->account;
458 if (owner.id() != takerGets->account.id())
459 env(pay(takerGets->account, owner, (*takerGets)(1000)));
461 env(offer(owner, (*takerPays)(1000), (*takerGets)(1000)),
468 for (
auto const& iou : ious)
471 offererIndex ?
accounts[*offererIndex] : iou.account;
482 auto add = [&](
auto const& a) {
505 auto const sle = v.
read(k);
511 auto const sle = v.
read(k);
523 auto const b1 = xrpBalance(v1, ak);
524 auto const b2 = xrpBalance(v2, ak);
530 for (
auto ai2 =
accounts.begin(); ai2 != aie; ++ai2)
538 auto const b1 = lineBalance(v1, lk);
539 auto const b2 = lineBalance(v2, lk);
545 return diffs.
empty();
577 prefix.
empty() ? nullptr : &prefix.
back();
582 auto const resultSize = prefix.
size() + suffix.
size() + 2;
583 outerResult.
reserve(resultSize);
588 outerResult = prefix;
602 result = outerResult;
612 f(sendMax, deliver, result);
623 testcase(
"To Strand");
627 auto const alice =
Account(
"alice");
628 auto const bob =
Account(
"bob");
629 auto const carol =
Account(
"carol");
632 auto const USD = gw[
"USD"];
633 auto const EUR = gw[
"EUR"];
635 auto const eurC = EUR.currency;
636 auto const usdC = USD.currency;
644 auto test = [&,
this](
646 Issue const& deliver,
650 auto&&... expSteps) {
663 BEAST_EXPECT(
ter == expTer);
664 if (
sizeof...(expSteps) != 0)
666 strand,
std::forward<decltype(expSteps)>(expSteps)...));
670 Env env(*
this, features);
671 env.
fund(
XRP(10000), alice, bob, gw);
672 env.
trust(USD(1000), alice, bob);
673 env.
trust(EUR(1000), alice, bob);
674 env(pay(gw, alice, EUR(100)));
714 Env env(*
this, features);
715 env.
fund(
XRP(10000), alice, bob, carol, gw);
719 env.
trust(USD(1000), alice, bob, carol);
722 env(pay(gw, alice, USD(100)));
723 env(pay(gw, carol, USD(100)));
734 env.
trust(EUR(1000), alice, bob);
759 env.
trust(carol[
"USD"](1000), bob);
767 B{USD, carol[
"USD"]},
768 D{carol, bob, usdC});
904 Env env(*
this, features);
906 env.
fund(
XRP(10000), alice, bob, carol, gw);
907 env.
trust(USD(10000), alice, bob, carol);
908 env.
trust(EUR(10000), alice, bob, carol);
910 env(pay(gw, bob, USD(100)));
911 env(pay(gw, bob, EUR(100)));
913 env(offer(bob,
XRP(100), USD(100)));
918 env(pay(alice, carol, USD(100)),
919 path(~USD, ~EUR, ~USD),
926 Env env(*
this, features);
928 env.
trust(USD(1000), alice, bob);
929 env(pay(gw, alice, USD(100)));
935 Env env(*
this, features);
936 env.
fund(
XRP(10000), alice, bob, gw);
937 env.
trust(USD(1000), alice, bob);
938 env(pay(gw, alice, USD(100)));
960 Env env(*
this, features);
961 env.
fund(
XRP(10000), alice, bob, gw);
962 env.
trust(USD(1000), alice, bob);
963 env(pay(gw, alice, USD(100)));
973 Env env(*
this, features);
974 env.
fund(
XRP(10000), alice, bob, gw);
976 env.
trust(USD(1000), alice, bob);
978 env(trust(gw, alice[
"USD"](1000),
tfSetfAuth));
980 env(pay(gw, alice, USD(100)));
998 BEAST_EXPECT(
equal(strand, D{alice, gw, usdC}));
1003 Env env(*
this, features);
1004 env.
fund(
XRP(10000), alice, bob, gw);
1005 env.
trust(USD(1000), alice, bob);
1006 env(pay(gw, alice, USD(100)));
1036 using namespace jtx;
1037 testcase(
"RIPD1373");
1039 auto const alice =
Account(
"alice");
1040 auto const bob =
Account(
"bob");
1041 auto const carol =
Account(
"carol");
1042 auto const gw =
Account(
"gw");
1043 auto const USD = gw[
"USD"];
1044 auto const EUR = gw[
"EUR"];
1047 Env env(*
this, features);
1048 env.
fund(
XRP(10000), alice, bob, gw);
1050 env.
trust(USD(1000), alice, bob);
1051 env.
trust(EUR(1000), alice, bob);
1052 env.
trust(bob[
"USD"](1000), alice, gw);
1053 env.
trust(bob[
"EUR"](1000), alice, gw);
1058 env(offer(bob, bob[
"USD"](100), bob[
"EUR"](100)),
1062 Path const p = [&] {
1071 env(pay(alice, alice, EUR(1)),
1079 Env env(*
this, features);
1081 env.
fund(
XRP(10000), alice, bob, carol, gw);
1082 env.
trust(USD(10000), alice, bob, carol);
1084 env(pay(gw, bob, USD(100)));
1090 env(pay(alice, carol,
XRP(100)),
1097 Env env(*
this, features);
1099 env.
fund(
XRP(10000), alice, bob, carol, gw);
1100 env.
trust(USD(10000), alice, bob, carol);
1102 env(pay(gw, bob, USD(100)));
1108 env(pay(alice, carol,
XRP(100)),
1119 testcase(
"test loop");
1120 using namespace jtx;
1122 auto const alice =
Account(
"alice");
1123 auto const bob =
Account(
"bob");
1124 auto const carol =
Account(
"carol");
1125 auto const gw =
Account(
"gw");
1126 auto const USD = gw[
"USD"];
1127 auto const EUR = gw[
"EUR"];
1128 auto const CNY = gw[
"CNY"];
1131 Env env(*
this, features);
1133 env.
fund(
XRP(10000), alice, bob, carol, gw);
1134 env.
trust(USD(10000), alice, bob, carol);
1136 env(pay(gw, bob, USD(100)));
1137 env(pay(gw, alice, USD(100)));
1143 env(pay(alice, carol, USD(100)),
1150 Env env(*
this, features);
1152 env.
fund(
XRP(10000), alice, bob, carol, gw);
1153 env.
trust(USD(10000), alice, bob, carol);
1154 env.
trust(EUR(10000), alice, bob, carol);
1155 env.
trust(CNY(10000), alice, bob, carol);
1157 env(pay(gw, bob, USD(100)));
1158 env(pay(gw, bob, EUR(100)));
1159 env(pay(gw, bob, CNY(100)));
1166 env(pay(alice, carol, CNY(100)),
1168 path(~USD, ~EUR, ~USD, ~CNY),
1177 testcase(
"test no account");
1178 using namespace jtx;
1180 auto const alice =
Account(
"alice");
1181 auto const bob =
Account(
"bob");
1182 auto const gw =
Account(
"gw");
1183 auto const USD = gw[
"USD"];
1185 Env env(*
this, features);
1186 env.
fund(
XRP(10000), alice, bob, gw);
1257 using namespace jtx;