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>
81 auto const useHigh = src.
id() > dst.
id();
82 return sle->isFlag(
trustFlag(flag, useHigh));
84 Throw<std::runtime_error>(
"No line in getTrustFlag");
112 template <
class Iter>
120 template <
class Iter,
class StepInfo,
class... Args>
124 if (!
equal(*i, std::forward<StepInfo>(si)))
129 template <
class... Args>
131 equal(Strand
const& strand, Args&&... args)
133 if (strand.size() !=
sizeof...(Args))
199 return state_ & (1 << safe_cast<int>(s));
205 for (
auto const s : sb)
216 for (
auto const s : sb)
263 class CurrencyFactory>
269 CurrencyFactory&& currencyF,
306 col.emplace_back(acc, cur, iss);
309 STPathElement::Type::typeBoundary,
383 assert(!offererIndex || offererIndex < numAct);
392 constexpr
size_t bufSize = 32;
395 for (
size_t id = 0;
id < numAct; ++id)
397 snprintf(buf, bufSize,
"A%zu",
id);
401 for (
size_t id = 0;
id < numCur; ++id)
404 snprintf(buf, bufSize,
"CC%zu",
id);
406 snprintf(buf, bufSize,
"C%zu",
id);
408 snprintf(buf, bufSize,
"%zu",
id);
420 for (
auto ai2 =
accounts.begin(); ai2 != aie; ++ai2)
426 env.
trust((*ai1)[cn](1
'000'000), *ai2);
432 auto const& src = *ai1;
433 auto const& dst = *ai2;
434 env(pay(src, dst, src[cn](500000)));
448 for (
auto takerPays = ious.
begin(), ie = ious.
end(); takerPays != ie;
451 for (
auto takerGets = ious.
begin(); takerGets != ie; ++takerGets)
453 if (takerPays == takerGets)
456 offererIndex ?
accounts[*offererIndex] : takerGets->account;
457 if (owner.id() != takerGets->account.id())
458 env(pay(takerGets->account, owner, (*takerGets)(1000)));
460 env(offer(owner, (*takerPays)(1000), (*takerGets)(1000)),
467 for (
auto const& iou : ious)
470 offererIndex ?
accounts[*offererIndex] : iou.account;
481 auto add = [&](
auto const& a) {
504 auto const sle = v.
read(k);
510 auto const sle = v.
read(k);
522 auto const b1 = xrpBalance(v1, ak);
523 auto const b2 = xrpBalance(v2, ak);
529 for (
auto ai2 =
accounts.begin(); ai2 != aie; ++ai2)
537 auto const b1 = lineBalance(v1, lk);
538 auto const b2 = lineBalance(v2, lk);
544 return diffs.
empty();
576 prefix.
empty() ? nullptr : &prefix.
back();
581 auto const resultSize = prefix.
size() + suffix.
size() + 2;
582 outerResult.
reserve(resultSize);
587 outerResult = prefix;
601 result = outerResult;
611 f(sendMax, deliver, result);
622 testcase(
"To Strand");
626 auto const alice =
Account(
"alice");
627 auto const bob =
Account(
"bob");
628 auto const carol =
Account(
"carol");
631 auto const USD = gw[
"USD"];
632 auto const EUR = gw[
"EUR"];
634 auto const eurC = EUR.currency;
635 auto const usdC = USD.currency;
643 auto test = [&,
this](
645 Issue const& deliver,
649 auto&&... expSteps) {
662 BEAST_EXPECT(
ter == expTer);
663 if (
sizeof...(expSteps) != 0)
665 strand,
std::forward<decltype(expSteps)>(expSteps)...));
669 Env env(*
this, features);
670 env.
fund(
XRP(10000), alice, bob, gw);
671 env.
trust(USD(1000), alice, bob);
672 env.
trust(EUR(1000), alice, bob);
673 env(pay(gw, alice, EUR(100)));
713 Env env(*
this, features);
714 env.
fund(
XRP(10000), alice, bob, carol, gw);
718 env.
trust(USD(1000), alice, bob, carol);
721 env(pay(gw, alice, USD(100)));
722 env(pay(gw, carol, USD(100)));
733 env.
trust(EUR(1000), alice, bob);
758 env.
trust(carol[
"USD"](1000), bob);
766 B{USD, carol[
"USD"]},
767 D{carol, bob, usdC});
903 Env env(*
this, features);
905 env.
fund(
XRP(10000), alice, bob, carol, gw);
906 env.
trust(USD(10000), alice, bob, carol);
907 env.
trust(EUR(10000), alice, bob, carol);
909 env(pay(gw, bob, USD(100)));
910 env(pay(gw, bob, EUR(100)));
912 env(offer(bob,
XRP(100), USD(100)));
917 env(pay(alice, carol, USD(100)),
918 path(~USD, ~EUR, ~USD),
925 Env env(*
this, features);
927 env.
trust(USD(1000), alice, bob);
928 env(pay(gw, alice, USD(100)));
934 Env env(*
this, features);
935 env.
fund(
XRP(10000), alice, bob, gw);
936 env.
trust(USD(1000), alice, bob);
937 env(pay(gw, alice, USD(100)));
959 Env env(*
this, features);
960 env.
fund(
XRP(10000), alice, bob, gw);
961 env.
trust(USD(1000), alice, bob);
962 env(pay(gw, alice, USD(100)));
972 Env env(*
this, features);
973 env.
fund(
XRP(10000), alice, bob, gw);
975 env.
trust(USD(1000), alice, bob);
977 env(trust(gw, alice[
"USD"](1000),
tfSetfAuth));
979 env(pay(gw, alice, USD(100)));
997 BEAST_EXPECT(
equal(strand, D{alice, gw, usdC}));
1002 Env env(*
this, features);
1003 env.
fund(
XRP(10000), alice, bob, gw);
1004 env.
trust(USD(1000), alice, bob);
1005 env(pay(gw, alice, USD(100)));
1035 using namespace jtx;
1036 testcase(
"RIPD1373");
1038 auto const alice =
Account(
"alice");
1039 auto const bob =
Account(
"bob");
1040 auto const carol =
Account(
"carol");
1041 auto const gw =
Account(
"gw");
1042 auto const USD = gw[
"USD"];
1043 auto const EUR = gw[
"EUR"];
1046 Env env(*
this, features);
1047 env.
fund(
XRP(10000), alice, bob, gw);
1049 env.
trust(USD(1000), alice, bob);
1050 env.
trust(EUR(1000), alice, bob);
1051 env.
trust(bob[
"USD"](1000), alice, gw);
1052 env.
trust(bob[
"EUR"](1000), alice, gw);
1057 env(offer(bob, bob[
"USD"](100), bob[
"EUR"](100)),
1061 Path const p = [&] {
1070 env(pay(alice, alice, EUR(1)),
1078 Env env(*
this, features);
1080 env.
fund(
XRP(10000), alice, bob, carol, gw);
1081 env.
trust(USD(10000), alice, bob, carol);
1083 env(pay(gw, bob, USD(100)));
1089 env(pay(alice, carol,
XRP(100)),
1096 Env env(*
this, features);
1098 env.
fund(
XRP(10000), alice, bob, carol, gw);
1099 env.
trust(USD(10000), alice, bob, carol);
1101 env(pay(gw, bob, USD(100)));
1107 env(pay(alice, carol,
XRP(100)),
1118 testcase(
"test loop");
1119 using namespace jtx;
1121 auto const alice =
Account(
"alice");
1122 auto const bob =
Account(
"bob");
1123 auto const carol =
Account(
"carol");
1124 auto const gw =
Account(
"gw");
1125 auto const USD = gw[
"USD"];
1126 auto const EUR = gw[
"EUR"];
1127 auto const CNY = gw[
"CNY"];
1130 Env env(*
this, features);
1132 env.
fund(
XRP(10000), alice, bob, carol, gw);
1133 env.
trust(USD(10000), alice, bob, carol);
1135 env(pay(gw, bob, USD(100)));
1136 env(pay(gw, alice, USD(100)));
1142 env(pay(alice, carol, USD(100)),
1149 Env env(*
this, features);
1151 env.
fund(
XRP(10000), alice, bob, carol, gw);
1152 env.
trust(USD(10000), alice, bob, carol);
1153 env.
trust(EUR(10000), alice, bob, carol);
1154 env.
trust(CNY(10000), alice, bob, carol);
1156 env(pay(gw, bob, USD(100)));
1157 env(pay(gw, bob, EUR(100)));
1158 env(pay(gw, bob, CNY(100)));
1165 env(pay(alice, carol, CNY(100)),
1167 path(~USD, ~EUR, ~USD, ~CNY),
1176 testcase(
"test no account");
1177 using namespace jtx;
1179 auto const alice =
Account(
"alice");
1180 auto const bob =
Account(
"bob");
1181 auto const gw =
Account(
"gw");
1182 auto const USD = gw[
"USD"];
1184 Env env(*
this, features);
1185 env.
fund(
XRP(10000), alice, bob, gw);
1256 using namespace jtx;