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>
30 #include <test/jtx/PathSet.h>
80 auto const useHigh = src.
id() > dst.
id();
81 return sle->isFlag(
trustFlag(flag, useHigh));
83 Throw<std::runtime_error>(
"No line in getTrustFlag");
111 template <
class Iter>
119 template <
class Iter,
class StepInfo,
class... Args>
123 if (!
equal(*i, std::forward<StepInfo>(si)))
128 template <
class... Args>
130 equal(Strand
const& strand, Args&&... args)
132 if (strand.size() !=
sizeof...(Args))
218 return state_ & (1 << safe_cast<int>(s));
224 for (
auto const s : sb)
235 for (
auto const s : sb)
282 class CurrencyFactory>
288 CurrencyFactory&& currencyF,
325 col.emplace_back(acc, cur, iss);
328 STPathElement::Type::typeBoundary,
402 assert(!offererIndex || offererIndex < numAct);
411 constexpr
size_t bufSize = 32;
414 for (
size_t id = 0;
id < numAct; ++id)
416 snprintf(buf, bufSize,
"A%zu",
id);
420 for (
size_t id = 0;
id < numCur; ++id)
423 snprintf(buf, bufSize,
"CC%zu",
id);
425 snprintf(buf, bufSize,
"C%zu",
id);
427 snprintf(buf, bufSize,
"%zu",
id);
439 for (
auto ai2 =
accounts.begin(); ai2 != aie; ++ai2)
445 env.
trust((*ai1)[cn](1
'000'000), *ai2);
451 auto const& src = *ai1;
452 auto const& dst = *ai2;
453 env(
pay(src, dst, src[cn](500000)));
467 for (
auto takerPays = ious.
begin(), ie = ious.
end(); takerPays != ie;
470 for (
auto takerGets = ious.
begin(); takerGets != ie; ++takerGets)
472 if (takerPays == takerGets)
475 offererIndex ?
accounts[*offererIndex] : takerGets->account;
476 if (owner.id() != takerGets->account.id())
477 env(
pay(takerGets->account, owner, (*takerGets)(1000)));
479 env(offer(owner, (*takerPays)(1000), (*takerGets)(1000)),
486 for (
auto const& iou : ious)
489 offererIndex ?
accounts[*offererIndex] : iou.account;
500 auto add = [&](
auto const& a) {
523 auto const sle = v.
read(k);
529 auto const sle = v.
read(k);
541 auto const b1 = xrpBalance(v1, ak);
542 auto const b2 = xrpBalance(v2, ak);
548 for (
auto ai2 =
accounts.begin(); ai2 != aie; ++ai2)
556 auto const b1 = lineBalance(v1, lk);
557 auto const b2 = lineBalance(v2, lk);
563 return diffs.
empty();
595 prefix.
empty() ? nullptr : &prefix.
back();
600 auto const resultSize = prefix.
size() + suffix.
size() + 2;
601 outerResult.
reserve(resultSize);
606 outerResult = prefix;
620 result = outerResult;
630 f(sendMax, deliver, result);
641 testcase(
"To Strand");
645 auto const alice =
Account(
"alice");
646 auto const bob =
Account(
"bob");
647 auto const carol =
Account(
"carol");
650 auto const USD = gw[
"USD"];
651 auto const EUR = gw[
"EUR"];
653 auto const eurC = EUR.currency;
654 auto const usdC = USD.currency;
660 auto test = [&,
this](
662 Issue const& deliver,
666 auto&&... expSteps) {
678 BEAST_EXPECT(
ter == expTer);
679 if (
sizeof...(expSteps) != 0)
681 strand,
std::forward<decltype(expSteps)>(expSteps)...));
685 Env env(*
this, features);
686 env.
fund(
XRP(10000), alice, bob, gw);
687 env.
trust(USD(1000), alice, bob);
688 env.
trust(EUR(1000), alice, bob);
689 env(
pay(gw, alice, EUR(100)));
727 Env env(*
this, features);
728 env.
fund(
XRP(10000), alice, bob, carol, gw);
732 env.
trust(USD(1000), alice, bob, carol);
735 env(
pay(gw, alice, USD(100)));
736 env(
pay(gw, carol, USD(100)));
747 env.
trust(EUR(1000), alice, bob);
772 env.
trust(carol[
"USD"](1000), bob);
780 B{USD, carol[
"USD"]},
781 D{carol, bob, usdC});
914 Env env(*
this, features);
916 env.
fund(
XRP(10000), alice, bob, carol, gw);
917 env.
trust(USD(10000), alice, bob, carol);
918 env.
trust(EUR(10000), alice, bob, carol);
920 env(
pay(gw, bob, USD(100)));
921 env(
pay(gw, bob, EUR(100)));
923 env(offer(bob,
XRP(100), USD(100)));
928 env(
pay(alice, carol, USD(100)),
929 path(~USD, ~EUR, ~USD),
936 Env env(*
this, features);
938 env.
trust(USD(1000), alice, bob);
939 env(
pay(gw, alice, USD(100)));
945 Env env(*
this, features);
946 env.
fund(
XRP(10000), alice, bob, gw);
947 env.
trust(USD(1000), alice, bob);
948 env(
pay(gw, alice, USD(100)));
970 Env env(*
this, features);
971 env.
fund(
XRP(10000), alice, bob, gw);
972 env.
trust(USD(1000), alice, bob);
973 env(
pay(gw, alice, USD(100)));
983 Env env(*
this, features);
984 env.
fund(
XRP(10000), alice, bob, gw);
986 env.
trust(USD(1000), alice, bob);
990 env(
pay(gw, alice, USD(100)));
1007 BEAST_EXPECT(
equal(strand, D{alice, gw, usdC}));
1012 Env env(*
this, features);
1013 env.
fund(
XRP(10000), alice, bob, gw);
1014 env.
trust(USD(1000), alice, bob);
1015 env(
pay(gw, alice, USD(100)));
1044 using namespace jtx;
1045 testcase(
"RIPD1373");
1047 auto const alice =
Account(
"alice");
1048 auto const bob =
Account(
"bob");
1049 auto const carol =
Account(
"carol");
1050 auto const gw =
Account(
"gw");
1051 auto const USD = gw[
"USD"];
1052 auto const EUR = gw[
"EUR"];
1055 Env env(*
this, features);
1056 env.
fund(
XRP(10000), alice, bob, gw);
1058 env.
trust(USD(1000), alice, bob);
1059 env.
trust(EUR(1000), alice, bob);
1060 env.
trust(bob[
"USD"](1000), alice, gw);
1061 env.
trust(bob[
"EUR"](1000), alice, gw);
1066 env(offer(bob, bob[
"USD"](100), bob[
"EUR"](100)),
1070 Path const p = [&] {
1079 env(
pay(alice, alice, EUR(1)),
1087 Env env(*
this, features);
1089 env.
fund(
XRP(10000), alice, bob, carol, gw);
1090 env.
trust(USD(10000), alice, bob, carol);
1092 env(
pay(gw, bob, USD(100)));
1098 env(
pay(alice, carol,
XRP(100)),
1105 Env env(*
this, features);
1107 env.
fund(
XRP(10000), alice, bob, carol, gw);
1108 env.
trust(USD(10000), alice, bob, carol);
1110 env(
pay(gw, bob, USD(100)));
1116 env(
pay(alice, carol,
XRP(100)),
1127 testcase(
"test loop");
1128 using namespace jtx;
1130 auto const alice =
Account(
"alice");
1131 auto const bob =
Account(
"bob");
1132 auto const carol =
Account(
"carol");
1133 auto const gw =
Account(
"gw");
1134 auto const USD = gw[
"USD"];
1135 auto const EUR = gw[
"EUR"];
1136 auto const CNY = gw[
"CNY"];
1139 Env env(*
this, features);
1141 env.
fund(
XRP(10000), alice, bob, carol, gw);
1142 env.
trust(USD(10000), alice, bob, carol);
1144 env(
pay(gw, bob, USD(100)));
1145 env(
pay(gw, alice, USD(100)));
1151 env(
pay(alice, carol, USD(100)),
1158 Env env(*
this, features);
1160 env.
fund(
XRP(10000), alice, bob, carol, gw);
1161 env.
trust(USD(10000), alice, bob, carol);
1162 env.
trust(EUR(10000), alice, bob, carol);
1163 env.
trust(CNY(10000), alice, bob, carol);
1165 env(
pay(gw, bob, USD(100)));
1166 env(
pay(gw, bob, EUR(100)));
1167 env(
pay(gw, bob, CNY(100)));
1174 env(
pay(alice, carol, CNY(100)),
1176 path(~USD, ~EUR, ~USD, ~CNY),
1185 testcase(
"test no account");
1186 using namespace jtx;
1188 auto const alice =
Account(
"alice");
1189 auto const bob =
Account(
"bob");
1190 auto const gw =
Account(
"gw");
1191 auto const USD = gw[
"USD"];
1193 Env env(*
this, features);
1194 env.
fund(
XRP(10000), alice, bob, gw);
1265 using namespace jtx;