1#include <test/jtx/AMM.h>
2#include <test/jtx/AMMTest.h>
3#include <test/jtx/Account.h>
4#include <test/jtx/Env.h>
5#include <test/jtx/TestHelpers.h>
6#include <test/jtx/amount.h>
7#include <test/jtx/balance.h>
8#include <test/jtx/domain.h>
9#include <test/jtx/envconfig.h>
10#include <test/jtx/jtx_json.h>
11#include <test/jtx/offer.h>
12#include <test/jtx/owners.h>
13#include <test/jtx/paths.h>
14#include <test/jtx/pay.h>
15#include <test/jtx/permissioned_dex.h>
16#include <test/jtx/rate.h>
17#include <test/jtx/sendmax.h>
18#include <test/jtx/ter.h>
19#include <test/jtx/trust.h>
20#include <test/jtx/txflags.h>
22#include <xrpld/core/Config.h>
23#include <xrpld/rpc/RPCHandler.h>
24#include <xrpld/rpc/Role.h>
25#include <xrpld/rpc/detail/Tuning.h>
27#include <xrpl/basics/base_uint.h>
28#include <xrpl/basics/hardened_hash.h>
29#include <xrpl/beast/unit_test/suite.h>
30#include <xrpl/core/Job.h>
31#include <xrpl/core/JobQueue.h>
32#include <xrpl/json/json_reader.h>
33#include <xrpl/json/json_value.h>
34#include <xrpl/protocol/AccountID.h>
35#include <xrpl/protocol/ApiVersion.h>
36#include <xrpl/protocol/ErrorCodes.h>
37#include <xrpl/protocol/Indexes.h>
38#include <xrpl/protocol/Issue.h>
39#include <xrpl/protocol/SField.h>
40#include <xrpl/protocol/STAmount.h>
41#include <xrpl/protocol/STParsedJSON.h>
42#include <xrpl/protocol/STPathSet.h>
43#include <xrpl/protocol/TER.h>
44#include <xrpl/protocol/TxFlags.h>
45#include <xrpl/protocol/UintTypes.h>
46#include <xrpl/protocol/jss.h>
47#include <xrpl/resource/Charge.h>
48#include <xrpl/resource/Consumer.h>
49#include <xrpl/resource/Fees.h>
74 jv[jss::command] =
"ripple_path_find";
75 jv[jss::source_account] =
toBase58(src);
81 while ((numSrc--) != 0u)
89 jv[jss::destination_account] = d;
92 j[jss::currency] =
"USD";
93 j[jss::value] =
"0.01";
111 cfg->pathSearchOld = 7;
113 cfg->pathSearchMax = 10;
129 template <
class Rep,
class Period>
134 auto const b =
cv_.wait_for(lk, relTime, [
this] {
return signaled_; });
161 auto& app = env.
app();
169 .loadType = loadType,
170 .netOps = app.getOPs(),
171 .ledgerMaster = app.getLedgerMaster(),
184 params[jss::command] =
"ripple_path_find";
185 params[jss::source_account] =
toBase58(src);
186 params[jss::destination_account] =
toBase58(dst);
194 j[jss::currency] =
to_string(saSrcCurrency.value());
198 j[jss::issuer] =
toBase58(*saSrcIssuer);
202 params[jss::domain] =
to_string(*domain);
206 app.getJobQueue().postCoro(
JtClient,
"RPC-Client", [&](
auto const& coro) {
207 context.
params = std::move(params);
213 using namespace std::chrono_literals;
215 BEAST_EXPECT(!result.
isMember(jss::error));
231 env, src, dst, saDstAmount, saSendMax, saSrcCurrency, domain, saSrcIssuer);
232 BEAST_EXPECT(!result.
isMember(jss::error));
235 if (result.
isMember(jss::destination_amount))
240 if (result.
isMember(jss::alternatives))
242 auto const& alts = result[jss::alternatives];
245 auto const&
path = alts[0u];
247 if (
path.isMember(jss::source_amount))
250 if (
path.isMember(jss::destination_amount))
253 if (
path.isMember(jss::paths_computed))
256 p[
"Paths"] =
path[jss::paths_computed];
260 paths = po.
object->getFieldPathSet(sfPaths);
265 return std::make_tuple(std::move(paths), std::move(sa), std::move(da));
272 using namespace std::chrono_literals;
275 auto const gw =
Account(
"gateway");
276 env.
fund(
XRP(10000),
"alice",
"bob", gw);
278 env.
trust(gw[
"USD"](100),
"alice",
"bob");
281 auto& app = env.
app();
289 .loadType = loadType,
290 .netOps = app.getOPs(),
291 .ledgerMaster = app.getLedgerMaster(),
305 app.getJobQueue().postCoro(
JtClient,
"RPC-Client", [&](
auto const& coro) {
312 BEAST_EXPECT(!result.
isMember(jss::error));
315 app.getJobQueue().postCoro(
JtClient,
"RPC-Client", [&](
auto const& coro) {
322 BEAST_EXPECT(result[jss::error] ==
"srcCurMalformed");
324 BEAST_EXPECT(result[jss::error_message] ==
"Source currency is malformed.");
329 app.getJobQueue().postCoro(
JtClient,
"RPC-Client", [&](
auto const& coro) {
336 BEAST_EXPECT(!result.
isMember(jss::error));
340 app.getJobQueue().postCoro(
JtClient,
"RPC-Client", [&](
auto const& coro) {
347 BEAST_EXPECT(result[jss::error] ==
"internal");
348 BEAST_EXPECT(result[jss::error_code] ==
RpcInternal);
349 BEAST_EXPECT(result[jss::error_message] ==
"Internal error.");
355 testcase(
"source currency issuer selection");
359 auto const alice =
Account(
"alice");
360 auto const bob =
Account(
"bob");
361 auto const gateway =
Account(
"gateway");
363 env.
fund(
XRP(10000), alice, bob, gateway);
366 auto const usd = gateway[
"USD"];
367 env.
trust(usd(600), alice);
368 env.
trust(usd(700), bob);
369 env.
trust(alice[
"USD"](700), bob);
370 env(
pay(gateway, alice, usd(70)));
371 env(
pay(gateway, bob, usd(50)));
387 alice[
"USD"](100).value(),
391 auto const& alternatives = result[jss::alternatives];
392 BEAST_EXPECT(alternatives.size() == 1);
395 BEAST_EXPECTS(
equal(sa, usd(100)), sa.getFullText());
396 BEAST_EXPECTS(
equal(da, bob[
"USD"](100)), da.getFullText());
402 testcase(
"no direct path no intermediary no alternatives");
405 env.
fund(
XRP(10000),
"alice",
"bob");
408 auto const result =
findPaths(env,
"alice",
"bob",
Account(
"bob")[
"USD"](5));
409 BEAST_EXPECT(std::get<0>(result).empty());
415 testcase(
"direct path no intermediary");
418 env.
fund(
XRP(10000),
"alice",
"bob");
425 BEAST_EXPECT(st.
empty());
435 auto const gw =
Account(
"gateway");
436 auto const usd = gw[
"USD"];
437 env.
fund(
XRP(10000),
"alice",
"bob", gw);
439 env.
trust(usd(600),
"alice");
440 env.
trust(usd(700),
"bob");
441 env(
pay(gw,
"alice", usd(70)));
442 env(
pay(
"alice",
"bob", usd(24)));
455 auto const gw =
Account(
"gateway");
456 auto const usd = gw[
"USD"];
457 env.
fund(
XRP(10000),
"alice",
"bob", gw);
459 env.
trust(usd(600),
"alice");
460 env.
trust(usd(700),
"bob");
461 env(
pay(gw,
"alice", usd(70)));
462 env(
pay(gw,
"bob", usd(50)));
471 env,
"alice",
"bob",
Account(
"bob")[
"USD"](5), std::nullopt, std::nullopt, domainID);
482 env.
fund(
XRP(10000),
"alice",
"bob");
490 findPaths(env,
"alice",
"bob",
XRP(5), std::nullopt, std::nullopt, domainID);
491 BEAST_EXPECT(std::get<0>(result).empty());
498 std::string(
"path find consume all") + (domainEnabled ?
" w/ " :
" w/o ") +
"domain");
503 env.
fund(
XRP(10000),
"alice",
"bob",
"carol",
"dan",
"edward");
513 domainID =
setupDomain(env, {
"alice",
"bob",
"carol",
"dan",
"edward"});
533 auto const gw =
Account(
"gateway");
534 auto const usd = gw[
"USD"];
535 env.
fund(
XRP(10000),
"alice",
"bob",
"carol", gw);
537 env.
trust(usd(100),
"bob",
"carol");
539 env(
pay(gw,
"carol", usd(100)));
545 domainID =
setupDomain(env, {
"alice",
"bob",
"carol",
"gateway"});
550 env(
offer(
"carol",
XRP(100), usd(100)));
565 BEAST_EXPECT(st.
empty());
574 BEAST_EXPECT(sa ==
XRP(100));
589 BEAST_EXPECT(st.
empty());
598 std::string(
"alternative path consume both") + (domainEnabled ?
" w/ " :
" w/o ") +
602 auto const gw =
Account(
"gateway");
603 auto const usd = gw[
"USD"];
604 auto const gw2 =
Account(
"gateway2");
605 auto const gw2Usd = gw2[
"USD"];
606 env.
fund(
XRP(10000),
"alice",
"bob", gw, gw2);
608 env.
trust(usd(600),
"alice");
609 env.
trust(gw2Usd(800),
"alice");
610 env.
trust(usd(700),
"bob");
611 env.
trust(gw2Usd(900),
"bob");
616 domainID =
setupDomain(env, {
"alice",
"bob",
"gateway",
"gateway2"});
617 env(
pay(gw,
"alice", usd(70)),
Domain(*domainID));
618 env(
pay(gw2,
"alice", gw2Usd(70)),
Domain(*domainID));
619 env(
pay(
"alice",
"bob",
Account(
"bob")[
"USD"](140)),
625 env(
pay(gw,
"alice", usd(70)));
626 env(
pay(gw2,
"alice", gw2Usd(70)));
644 std::string(
"alternative paths consume best transfer") +
645 (domainEnabled ?
" w/ " :
" w/o ") +
"domain");
648 auto const gw =
Account(
"gateway");
649 auto const usd = gw[
"USD"];
650 auto const gw2 =
Account(
"gateway2");
651 auto const gw2Usd = gw2[
"USD"];
652 env.
fund(
XRP(10000),
"alice",
"bob", gw, gw2);
655 env.
trust(usd(600),
"alice");
656 env.
trust(gw2Usd(800),
"alice");
657 env.
trust(usd(700),
"bob");
658 env.
trust(gw2Usd(900),
"bob");
663 domainID =
setupDomain(env, {
"alice",
"bob",
"gateway",
"gateway2"});
664 env(
pay(gw,
"alice", usd(70)),
Domain(*domainID));
665 env(
pay(gw2,
"alice", gw2Usd(70)),
Domain(*domainID));
666 env(
pay(
"alice",
"bob", usd(70)),
Domain(*domainID));
670 env(
pay(gw,
"alice", usd(70)));
671 env(
pay(gw2,
"alice", gw2Usd(70)));
672 env(
pay(
"alice",
"bob", usd(70)));
687 testcase(
"alternative paths - consume best transfer first");
690 auto const gw =
Account(
"gateway");
691 auto const usd = gw[
"USD"];
692 auto const gw2 =
Account(
"gateway2");
693 auto const gw2Usd = gw2[
"USD"];
694 env.
fund(
XRP(10000),
"alice",
"bob", gw, gw2);
697 env.
trust(usd(600),
"alice");
698 env.
trust(gw2Usd(800),
"alice");
699 env.
trust(usd(700),
"bob");
700 env.
trust(gw2Usd(900),
"bob");
701 env(
pay(gw,
"alice", usd(70)));
702 env(
pay(gw2,
"alice", gw2Usd(70)));
703 env(
pay(
"alice",
"bob",
Account(
"bob")[
"USD"](77)),
720 std::string(
"alternative paths - limit returned paths to best quality") +
721 (domainEnabled ?
" w/ " :
" w/o ") +
"domain");
724 auto const gw =
Account(
"gateway");
725 auto const usd = gw[
"USD"];
726 auto const gw2 =
Account(
"gateway2");
727 auto const gw2Usd = gw2[
"USD"];
728 env.
fund(
XRP(10000),
"alice",
"bob",
"carol",
"dan", gw, gw2);
730 env(
rate(
"carol", 1.1));
731 env.
trust(
Account(
"carol")[
"USD"](800),
"alice",
"bob");
733 env.
trust(usd(800),
"alice",
"bob");
734 env.
trust(gw2Usd(800),
"alice",
"bob");
738 env(
pay(gw2,
"alice", gw2Usd(100)));
740 env(
pay(
"carol",
"alice",
Account(
"carol")[
"USD"](100)));
742 env(
pay(gw,
"alice", usd(100)));
748 domainID =
setupDomain(env, {
"alice",
"bob",
"carol",
"dan", gw, gw2});
754 env,
"alice",
"bob",
Account(
"bob")[
"USD"](5), std::nullopt, std::nullopt, domainID);
764 std::string(
"path negative: Issue #5") + (domainEnabled ?
" w/ " :
" w/o ") +
"domain");
767 env.
fund(
XRP(10000),
"alice",
"bob",
"carol",
"dan");
769 env.
trust(
Account(
"bob")[
"USD"](100),
"alice",
"carol",
"dan");
772 env(
pay(
"bob",
"carol",
Account(
"bob")[
"USD"](75)));
780 domainID =
setupDomain(env, {
"alice",
"bob",
"carol",
"dan"});
784 env,
"alice",
"bob",
Account(
"bob")[
"USD"](25), std::nullopt, std::nullopt, domainID);
785 BEAST_EXPECT(std::get<0>(result).empty());
791 env,
"alice",
"bob",
Account(
"alice")[
"USD"](25), std::nullopt, std::nullopt, domainID);
792 BEAST_EXPECT(std::get<0>(result).empty());
812 testcase(
"path negative: ripple-client issue #23: smaller");
815 env.
fund(
XRP(10000),
"alice",
"bob",
"carol",
"dan");
831 testcase(
"path negative: ripple-client issue #23: larger");
834 env.
fund(
XRP(10000),
"alice",
"bob",
"carol",
"dan",
"edward");
861 auto const gw =
Account(
"gateway");
862 auto const aud = gw[
"AUD"];
863 env.
fund(
XRP(10000),
"alice",
"bob",
"carol", gw);
867 env.
trust(aud(100),
"bob",
"carol");
869 env(
pay(gw,
"carol", aud(50)));
875 domainID =
setupDomain(env, {
"alice",
"bob",
"carol", gw});
883 env(
offer(
"carol",
XRP(50), aud(50)));
893 env,
"alice",
"bob",
Account(
"bob")[
"USD"](25), std::nullopt, std::nullopt, domainID);
894 BEAST_EXPECT(std::get<0>(result).empty());
903 env.
fund(
XRP(10000),
"alice",
"bob",
"carol");
922 env.
fund(
XRP(10000),
"alice",
"bob");
925 Json(
"{\"" + sfQualityIn.fieldName +
"\": 2000}"),
926 Json(
"{\"" + sfQualityOut.fieldName +
"\": 1400000000}"));
933 "issuer" : "rrrrrrrrrrrrrrrrrrrrBZbvji",
939 "issuer" : "rPMh7Pi9ct699iZUTWaytJUoHcJ7cgyziK",
943 "HighQualityIn" : 2000,
944 "HighQualityOut" : 1400000000,
945 "LedgerEntryType" : "RippleState",
948 "issuer" : "rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn",
957 for (
auto it = jv.
begin(); it != jv.
end(); ++it)
958 BEAST_EXPECT(*it == jvL[it.memberName()]);
977 "issuer" : "rrrrrrrrrrrrrrrrrrrrBZbvji",
983 "issuer" : "rPMh7Pi9ct699iZUTWaytJUoHcJ7cgyziK",
987 "LedgerEntryType" : "RippleState",
990 "issuer" : "rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn",
999 for (
auto it = jv.
begin(); it != jv.
end(); ++it)
1000 BEAST_EXPECT(*it == jvL[it.memberName()]);
1012 using namespace jtx;
1014 env.
fund(
XRP(10000),
"alice",
"bob");
1017 env(
pay(
"bob",
"alice",
Account(
"bob")[
"USD"](50)));
1026 "issuer" : "rrrrrrrrrrrrrrrrrrrrBZbvji",
1033 "issuer" : "rPMh7Pi9ct699iZUTWaytJUoHcJ7cgyziK",
1037 "LedgerEntryType" : "RippleState",
1041 "issuer" : "rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn",
1050 for (
auto it = jv.
begin(); it != jv.
end(); ++it)
1051 BEAST_EXPECT(*it == jvL[it.memberName()]);
1053 env(
pay(
"alice",
"bob",
Account(
"alice")[
"USD"](50)));
1062 std::string(
"Path Find: XRP -> XRP and XRP -> IOU") +
1063 (domainEnabled ?
" w/ " :
" w/o ") +
"domain");
1064 using namespace jtx;
1074 env.fund(
XRP(100000), a1);
1075 env.fund(
XRP(10000), a2);
1076 env.fund(
XRP(1000), a3, g1, g2, g3, m1);
1079 env.trust(g1[
"XYZ"](5000), a1);
1080 env.trust(g3[
"ABC"](5000), a1);
1081 env.trust(g2[
"XYZ"](5000), a2);
1082 env.trust(g3[
"ABC"](5000), a2);
1083 env.trust(a2[
"ABC"](1000), a3);
1084 env.trust(g1[
"XYZ"](100000), m1);
1085 env.trust(g2[
"XYZ"](100000), m1);
1086 env.trust(g3[
"ABC"](100000), m1);
1089 env(
pay(g1, a1, g1[
"XYZ"](3500)));
1090 env(
pay(g3, a1, g3[
"ABC"](1200)));
1091 env(
pay(g2, m1, g2[
"XYZ"](25000)));
1092 env(
pay(g3, m1, g3[
"ABC"](25000)));
1098 domainID =
setupDomain(env, {a1, a2, a3, g1, g2, g3, m1});
1099 env(
offer(m1, g1[
"XYZ"](1000), g2[
"XYZ"](1000)),
Domain(*domainID));
1105 env(
offer(m1, g1[
"XYZ"](1000), g2[
"XYZ"](1000)));
1106 env(
offer(m1,
XRP(10000), g3[
"ABC"](1000)));
1114 auto const& sendAmt =
XRP(10);
1117 BEAST_EXPECT(
equal(da, sendAmt));
1118 BEAST_EXPECT(st.
empty());
1124 auto const& sendAmt =
XRP(200);
1127 BEAST_EXPECT(
equal(da, sendAmt));
1128 BEAST_EXPECT(st.
empty());
1132 auto const& sendAmt = g3[
"ABC"](10);
1135 BEAST_EXPECT(
equal(da, sendAmt));
1141 auto const& sendAmt = a2[
"ABC"](1);
1144 BEAST_EXPECT(
equal(da, sendAmt));
1150 auto const& sendAmt = a3[
"ABC"](1);
1153 BEAST_EXPECT(
equal(da, sendAmt));
1163 std::string(
"Path Find: non-XRP -> XRP") + (domainEnabled ?
" w/ " :
" w/o ") +
1165 using namespace jtx;
1172 env.fund(
XRP(1000), a1, a2, g3);
1173 env.fund(
XRP(11000), m1);
1176 env.trust(g3[
"ABC"](1000), a1, a2);
1177 env.trust(g3[
"ABC"](100000), m1);
1180 env(
pay(g3, a1, g3[
"ABC"](1000)));
1181 env(
pay(g3, a2, g3[
"ABC"](1000)));
1182 env(
pay(g3, m1, g3[
"ABC"](1200)));
1185 std::optional<UInt256> domainID;
1193 env(
offer(m1, g3[
"ABC"](1000),
XRP(10000)));
1198 auto const& sendAmt =
XRP(10);
1202 findPaths(env, a1, a2, sendAmt, std::nullopt, a2[
"ABC"].currency, domainID);
1203 BEAST_EXPECT(
equal(da, sendAmt));
1204 BEAST_EXPECT(
equal(sa, a1[
"ABC"](1)));
1213 findPaths(env, a1, a2, sendAmt, std::nullopt, a2[
"ABC"].currency);
1214 BEAST_EXPECT(
equal(da, sendAmt));
1215 BEAST_EXPECT(st.empty());
1223 std::string(
"Path Find: Bitstamp and SnapSwap, liquidity with no offers") +
1224 (domainEnabled ?
" w/ " :
" w/o ") +
"domain");
1225 using namespace jtx;
1233 env.fund(
XRP(1000), g1Bs, g2Sw, a1, a2);
1234 env.fund(
XRP(11000), m1);
1237 env.trust(g1Bs[
"HKD"](2000), a1);
1238 env.trust(g2Sw[
"HKD"](2000), a2);
1239 env.trust(g1Bs[
"HKD"](100000), m1);
1240 env.trust(g2Sw[
"HKD"](100000), m1);
1243 env(
pay(g1Bs, a1, g1Bs[
"HKD"](1000)));
1244 env(
pay(g2Sw, a2, g2Sw[
"HKD"](1000)));
1248 env(
pay(g1Bs, m1, g1Bs[
"HKD"](1200)));
1249 env(
pay(g2Sw, m1, g2Sw[
"HKD"](5000)));
1254 domainID =
setupDomain(env, {a1, a2, g1Bs, g2Sw, m1});
1260 auto const& sendAmt = a2[
"HKD"](10);
1262 findPaths(env, a1, a2, sendAmt, std::nullopt, a2[
"HKD"].currency, domainID);
1263 BEAST_EXPECT(
equal(da, sendAmt));
1264 BEAST_EXPECT(
equal(sa, a1[
"HKD"](10)));
1265 BEAST_EXPECT(
same(st,
stpath(g1Bs, m1, g2Sw)));
1269 auto const& sendAmt = a1[
"HKD"](10);
1271 findPaths(env, a2, a1, sendAmt, std::nullopt, a1[
"HKD"].currency, domainID);
1272 BEAST_EXPECT(
equal(da, sendAmt));
1273 BEAST_EXPECT(
equal(sa, a2[
"HKD"](10)));
1274 BEAST_EXPECT(
same(st,
stpath(g2Sw, m1, g1Bs)));
1278 auto const& sendAmt = a2[
"HKD"](10);
1280 findPaths(env, g1Bs, a2, sendAmt, std::nullopt, a1[
"HKD"].currency, domainID);
1281 BEAST_EXPECT(
equal(da, sendAmt));
1282 BEAST_EXPECT(
equal(sa, g1Bs[
"HKD"](10)));
1287 auto const& sendAmt = m1[
"HKD"](10);
1289 findPaths(env, m1, g1Bs, sendAmt, std::nullopt, a1[
"HKD"].currency, domainID);
1290 BEAST_EXPECT(
equal(da, sendAmt));
1291 BEAST_EXPECT(
equal(sa, m1[
"HKD"](10)));
1292 BEAST_EXPECT(st.empty());
1296 auto const& sendAmt = a1[
"HKD"](10);
1298 findPaths(env, g2Sw, a1, sendAmt, std::nullopt, a1[
"HKD"].currency, domainID);
1299 BEAST_EXPECT(
equal(da, sendAmt));
1300 BEAST_EXPECT(
equal(sa, g2Sw[
"HKD"](10)));
1309 std::string(
"Path Find: non-XRP -> non-XRP, same currency") +
1310 (domainEnabled ?
" w/ " :
" w/o ") +
"domain");
1311 using namespace jtx;
1324 env.fund(
XRP(1000), a1, a2, a3, g1, g2, g3, g4);
1325 env.fund(
XRP(10000), a4);
1326 env.fund(
XRP(11000), m1, m2);
1329 env.trust(g1[
"HKD"](2000), a1);
1330 env.trust(g2[
"HKD"](2000), a2);
1331 env.trust(g1[
"HKD"](2000), a3);
1332 env.trust(g1[
"HKD"](100000), m1);
1333 env.trust(g2[
"HKD"](100000), m1);
1334 env.trust(g1[
"HKD"](100000), m2);
1335 env.trust(g2[
"HKD"](100000), m2);
1338 env(
pay(g1, a1, g1[
"HKD"](1000)));
1339 env(
pay(g2, a2, g2[
"HKD"](1000)));
1340 env(
pay(g1, a3, g1[
"HKD"](1000)));
1341 env(
pay(g1, m1, g1[
"HKD"](1200)));
1342 env(
pay(g2, m1, g2[
"HKD"](5000)));
1343 env(
pay(g1, m2, g1[
"HKD"](1200)));
1344 env(
pay(g2, m2, g2[
"HKD"](5000)));
1347 std::optional<UInt256> domainID;
1350 domainID =
setupDomain(env, {a1, a2, a3, a4, g1, g2, g3, g4, m1, m2});
1351 env(
offer(m1, g1[
"HKD"](1000), g2[
"HKD"](1000)),
Domain(*domainID));
1357 env(
offer(m1, g1[
"HKD"](1000), g2[
"HKD"](1000)));
1358 env(
offer(m2,
XRP(10000), g2[
"HKD"](1000)));
1359 env(
offer(m2, g1[
"HKD"](1000),
XRP(10000)));
1368 auto const& sendAmt = g1[
"HKD"](10);
1370 findPaths(env, a1, g1, sendAmt, std::nullopt, g1[
"HKD"].currency, domainID);
1371 BEAST_EXPECT(st.empty());
1372 BEAST_EXPECT(
equal(da, sendAmt));
1373 BEAST_EXPECT(
equal(sa, a1[
"HKD"](10)));
1379 auto const& sendAmt = a1[
"HKD"](10);
1381 findPaths(env, a1, g1, sendAmt, std::nullopt, g1[
"HKD"].currency, domainID);
1382 BEAST_EXPECT(st.empty());
1383 BEAST_EXPECT(
equal(da, sendAmt));
1390 auto const& sendAmt = a3[
"HKD"](10);
1392 findPaths(env, a1, a3, sendAmt, std::nullopt, g1[
"HKD"].currency, domainID);
1393 BEAST_EXPECT(
equal(da, sendAmt));
1394 BEAST_EXPECT(
equal(sa, a1[
"HKD"](10)));
1401 auto const& sendAmt = g2[
"HKD"](10);
1403 findPaths(env, g1, g2, sendAmt, std::nullopt, g1[
"HKD"].currency, domainID);
1404 BEAST_EXPECT(
equal(da, sendAmt));
1405 BEAST_EXPECT(
equal(sa, g1[
"HKD"](10)));
1417 auto const& sendAmt = g2[
"HKD"](10);
1419 findPaths(env, a1, g2, sendAmt, std::nullopt, g1[
"HKD"].currency, domainID);
1420 BEAST_EXPECT(
equal(da, sendAmt));
1421 BEAST_EXPECT(
equal(sa, a1[
"HKD"](10)));
1434 auto const& sendAmt = a2[
"HKD"](10);
1436 findPaths(env, a1, a2, sendAmt, std::nullopt, g1[
"HKD"].currency, domainID);
1437 BEAST_EXPECT(
equal(da, sendAmt));
1438 BEAST_EXPECT(
equal(sa, a1[
"HKD"](10)));
1452 std::string(
"Path Find: non-XRP -> non-XRP, same currency)") +
1453 (domainEnabled ?
" w/ " :
" w/o ") +
"domain");
1454 using namespace jtx;
1463 env.fund(
XRP(11000), m1);
1464 env.fund(
XRP(1000), a1, a2, a3, g1, g2);
1467 env.trust(g1[
"HKD"](2000), a1);
1468 env.trust(g2[
"HKD"](2000), a2);
1469 env.trust(a2[
"HKD"](2000), a3);
1470 env.trust(g1[
"HKD"](100000), m1);
1471 env.trust(g2[
"HKD"](100000), m1);
1474 env(
pay(g1, a1, g1[
"HKD"](1000)));
1475 env(
pay(g2, a2, g2[
"HKD"](1000)));
1476 env(
pay(g1, m1, g1[
"HKD"](5000)));
1477 env(
pay(g2, m1, g2[
"HKD"](5000)));
1480 std::optional<UInt256> domainID;
1483 domainID =
setupDomain(env, {a1, a2, a3, g1, g2, m1});
1484 env(
offer(m1, g1[
"HKD"](1000), g2[
"HKD"](1000)),
Domain(*domainID));
1488 env(
offer(m1, g1[
"HKD"](1000), g2[
"HKD"](1000)));
1493 auto const& sendAmt = a2[
"HKD"](10);
1497 findPaths(env, g1, a2, sendAmt, std::nullopt, g1[
"HKD"].currency, domainID);
1498 BEAST_EXPECT(
equal(da, sendAmt));
1499 BEAST_EXPECT(
equal(sa, g1[
"HKD"](10)));
1506 testcase(std::string(
"Receive max") + (domainEnabled ?
" w/ " :
" w/o ") +
"domain");
1508 using namespace jtx;
1509 auto const alice =
Account(
"alice");
1510 auto const bob =
Account(
"bob");
1511 auto const charlie =
Account(
"charlie");
1512 auto const gw =
Account(
"gw");
1513 auto const usd = gw[
"USD"];
1517 env.fund(
XRP(10000), alice, bob, charlie, gw);
1519 env.trust(usd(100), alice, bob, charlie);
1521 env(
pay(gw, charlie, usd(10)));
1527 domainID =
setupDomain(env, {alice, bob, charlie, gw});
1533 env(
offer(charlie,
XRP(10), usd(10)));
1538 findPaths(env, alice, bob, usd(-1),
XRP(100).value(), std::nullopt, domainID);
1539 BEAST_EXPECT(sa ==
XRP(10));
1540 BEAST_EXPECT(
equal(da, usd(10)));
1541 if (BEAST_EXPECT(st.size() == 1 && st[0].size() == 1))
1543 auto const& pathElem = st[0][0];
1545 pathElem.isOffer() && pathElem.getIssuerID() == gw.id() &&
1546 pathElem.getCurrency() == usd.currency);
1552 env.fund(
XRP(10000), alice, bob, charlie, gw);
1554 env.trust(usd(100), alice, bob, charlie);
1556 env(
pay(gw, alice, usd(10)));
1559 std::optional<UInt256> domainID;
1562 domainID =
setupDomain(env, {alice, bob, charlie, gw});
1568 env(
offer(charlie, usd(10),
XRP(10)));
1573 findPaths(env, alice, bob,
drops(-1), usd(100).value(), std::nullopt, domainID);
1574 BEAST_EXPECT(sa == usd(10));
1576 if (BEAST_EXPECT(st.size() == 1 && st[0].size() == 1))
1578 auto const& pathElem = st[0][0];
1580 pathElem.isOffer() && pathElem.getIssuerID() ==
xrpAccount() &&
1589 using namespace jtx;
1594 auto const alice =
Account(
"alice");
1595 auto const bob =
Account(
"bob");
1596 auto const george =
Account(
"george");
1597 auto const usd = george[
"USD"];
1605 env.fund(
XRP(10000),
noripple(alice, bob, george));
1609 env(
trust(alice, usd(100), aliceRipple ? tfClearNoRipple : tfSetNoRipple));
1610 env(
trust(george, alice[
"USD"](100), aliceRipple ? tfClearNoRipple : tfSetNoRipple));
1611 env(
trust(bob, usd(100), bobRipple ? tfClearNoRipple : tfSetNoRipple));
1612 env(
trust(george, bob[
"USD"](100), bobRipple ? tfClearNoRipple : tfSetNoRipple));
1614 env(
pay(george, alice, usd(70)));
1617 auto [st, sa, da] =
findPaths(env,
"alice",
"bob",
Account(
"bob")[
"USD"](5));
1618 BEAST_EXPECT(
equal(da, bob[
"USD"](5)));
1622 BEAST_EXPECT(st.size() == 1);
1624 BEAST_EXPECT(
equal(sa, alice[
"USD"](5)));
1628 BEAST_EXPECT(st.empty());
1632 test(
"ripple -> ripple",
true,
true,
true);
1633 test(
"ripple -> no ripple",
true,
false,
true);
1634 test(
"no ripple -> ripple",
false,
true,
true);
1635 test(
"no ripple -> no ripple",
false,
false,
false);
1642 using namespace jtx;
1647 auto const testPathfind = [&](
auto func,
bool const domainEnabled =
false) {
1660 env.fund(
XRP(1000), a1, a2, a3, g1, g2, g3, g4);
1661 env.fund(
XRP(10000), a4);
1662 env.fund(
XRP(11000), m1, m2);
1665 env.trust(g1[
"HKD"](2000), a1);
1666 env.trust(g2[
"HKD"](2000), a2);
1667 env.trust(g1[
"HKD"](2000), a3);
1668 env.trust(g1[
"HKD"](100000), m1);
1669 env.trust(g2[
"HKD"](100000), m1);
1670 env.trust(g1[
"HKD"](100000), m2);
1671 env.trust(g2[
"HKD"](100000), m2);
1674 env(
pay(g1, a1, g1[
"HKD"](1000)));
1675 env(
pay(g2, a2, g2[
"HKD"](1000)));
1676 env(
pay(g1, a3, g1[
"HKD"](1000)));
1677 env(
pay(g1, m1, g1[
"HKD"](1200)));
1678 env(
pay(g2, m1, g2[
"HKD"](5000)));
1679 env(
pay(g1, m2, g1[
"HKD"](1200)));
1680 env(
pay(g2, m2, g2[
"HKD"](5000)));
1683 std::optional<UInt256> domainID =
1684 setupDomain(env, {a1, a2, a3, a4, g1, g2, g3, g4, m1, m2});
1685 BEAST_EXPECT(domainID);
1687 func(env, m1, m2, g1, g2, *domainID);
1695 auto const& sendAmt = g1[
"HKD"](10);
1703 domainEnabled ? domainID : std::nullopt);
1704 BEAST_EXPECT(st.empty());
1705 BEAST_EXPECT(
equal(da, sendAmt));
1706 BEAST_EXPECT(
equal(sa, a1[
"HKD"](10)));
1712 auto const& sendAmt = a1[
"HKD"](10);
1720 domainEnabled ? domainID : std::nullopt);
1721 BEAST_EXPECT(st.empty());
1722 BEAST_EXPECT(
equal(da, sendAmt));
1723 BEAST_EXPECT(
equal(sa, a1[
"HKD"](10)));
1729 auto const& sendAmt = a3[
"HKD"](10);
1737 domainEnabled ? domainID : std::nullopt);
1738 BEAST_EXPECT(
equal(da, sendAmt));
1739 BEAST_EXPECT(
equal(sa, a1[
"HKD"](10)));
1746 auto const& sendAmt = g2[
"HKD"](10);
1754 domainEnabled ? domainID : std::nullopt);
1755 BEAST_EXPECT(
equal(da, sendAmt));
1756 BEAST_EXPECT(
equal(sa, g1[
"HKD"](10)));
1768 auto const& sendAmt = g2[
"HKD"](10);
1776 domainEnabled ? domainID : std::nullopt);
1777 BEAST_EXPECT(
equal(da, sendAmt));
1778 BEAST_EXPECT(
equal(sa, a1[
"HKD"](10)));
1791 auto const& sendAmt = a2[
"HKD"](10);
1799 domainEnabled ? domainID : std::nullopt);
1800 BEAST_EXPECT(
equal(da, sendAmt));
1801 BEAST_EXPECT(
equal(sa, a1[
"HKD"](10)));
1817 env(
offer(m1, g1[
"HKD"](1000), g2[
"HKD"](1000)),
1820 env(
offer(m2,
XRP(10000), g2[
"HKD"](1000)));
1821 env(
offer(m2, g1[
"HKD"](1000),
XRP(10000)));
1826 env(
offer(m1, g1[
"HKD"](1000), g2[
"HKD"](1000)),
1829 env(
offer(m2,
XRP(10000), g2[
"HKD"](1000)),
1832 env(
offer(m2, g1[
"HKD"](1000),
XRP(10000)));
1837 env(
offer(m1, g1[
"HKD"](1000), g2[
"HKD"](1000)),
1840 env(
offer(m2,
XRP(10000), g2[
"HKD"](1000)),
1843 env(
offer(m2, g1[
"HKD"](1000),
XRP(10000)),
1850 env(
offer(m1, g1[
"HKD"](1000), g2[
"HKD"](1000)));
1851 env(
offer(m2,
XRP(10000), g2[
"HKD"](1000)));
1852 env(
offer(m2, g1[
"HKD"](1000),
XRP(10000)),
1859 env(
offer(m1, g1[
"HKD"](1000), g2[
"HKD"](1000)));
1860 env(
offer(m2,
XRP(10000), g2[
"HKD"](1000)),
1863 env(
offer(m2, g1[
"HKD"](1000),
XRP(10000)),
1875 env(
offer(m1, g1[
"HKD"](1000), g2[
"HKD"](1000)),
1885 env(
offer(m1, g1[
"HKD"](1000), g2[
"HKD"](1000)),
1888 env(
offer(m2,
XRP(10000), g2[
"HKD"](1000)),
1897 env(
offer(m1, g1[
"HKD"](1000), g2[
"HKD"](1000)),
Domain(domainID));
1899 env(
offer(m2, g1[
"HKD"](1000),
XRP(10000)),
1907 env(
offer(m1, g1[
"HKD"](1000), g2[
"HKD"](1000)),
Domain(domainID));
1908 env(
offer(m2,
XRP(10000), g2[
"HKD"](1000)),
1911 env(
offer(m2, g1[
"HKD"](1000),
XRP(10000)),
1922 testcase(
"AMM not used in domain path");
1923 using namespace jtx;
1925 PermissionedDEX
const permDex(env);
1926 auto const& [gw, domainOwner, alice, bob, carol, usd, domainID, credType] = permDex;
1927 AMM
const amm(env, alice,
XRP(10), usd(50));
1932 auto const& sendAmt =
XRP(1);
1936 findPaths(env, bob, carol, sendAmt, std::nullopt, usd.currency, domainID);
1937 BEAST_EXPECT(st.empty());
1940 std::tie(st, sa, da) =
findPaths(env, bob, carol, sendAmt, std::nullopt, usd.currency);
1947 testcase(
"STPathSet::assembleAdd deduplication — O(N^2) regression");
1949 static constexpr std::string_view kAccount1 =
"A3F19C7B2E5D08146FB93A7C0E2D5184BC6F3A09";
1950 static constexpr std::string_view kAccount2 =
"1D7E4B90C2A6F3851E0B9D47A2C5F8136E0A4B7D";
1951 static constexpr std::string_view kAccount3 =
"F08C36A1D95E27B40CA1F63E8D204B7950E1C3A6";
1952 static constexpr std::string_view kAccount4 =
"4B6209E7F1A3C85D0E94B27Af3D6018C5A7E92B4";
1953 static constexpr std::string_view kAccount5 =
"9E2D7041BCA3F6589D013E7B2A4C6F80159D3E7A";
1954 static constexpr std::string_view kAccount6 =
"7C5A91E384F2D06BA19C4E73D820F516B3A9C0E4";
1955 static constexpr std::string_view kAccount7 =
"2F8B043C6A1E9D75B0C38E14F6A2D509731BC4E8";
1956 static constexpr std::string_view kAccount8 =
"E61D9A30F47C285BA0D31E96C7B4F802513A8D6F";
1958 static constexpr AccountID kAccountID1{kAccount1};
1959 static constexpr AccountID kAccountID2{kAccount2};
1960 static constexpr AccountID kAccountID3{kAccount3};
1961 static constexpr AccountID kAccountID4{kAccount4};
1962 static constexpr AccountID kAccountID5{kAccount5};
1963 static constexpr AccountID kAccountID6{kAccount6};
1964 static constexpr AccountID kAccountID7{kAccount7};
1965 static constexpr AccountID kAccountID8{kAccount8};
1967 auto ps = STPathSet{STPathSet::DeduplicationTag{}};
1969 auto const createPathElements = [](
auto const& account1,
auto const& account2) {
1970 auto base = STPath{};
1979 auto [base, tail] = createPathElements(kAccountID1, kAccountID2);
1981 for (
auto i = 0uz; i < 10000; ++i)
1983 ps.assembleAdd(base, tail);
1986 BEAST_EXPECT(ps.size() == 1);
1990 auto [base, tail] = createPathElements(kAccountID3, kAccountID4);
1991 ps.assembleAdd(base, tail);
1995 auto [base, tail] = createPathElements(kAccountID5, kAccountID6);
1996 ps.assembleAdd(base, tail);
2000 auto [base, tail] = createPathElements(kAccountID7, kAccountID8);
2002 auto const before = ps.size();
2004 for (
auto i = 0uz; i < 10000; ++i)
2006 ps.assembleAdd(base, tail);
2009 BEAST_EXPECT(ps.size() - before == 1);
2013 auto [base, tail] = createPathElements(kAccountID1, kAccountID3);
2015 copy.pushBack(tail);
2017 auto const before = ps.size();
2020 ps.assembleAdd(base, tail);
2022 BEAST_EXPECT(ps.size() - before == 1);
2026 auto [base, tail] = createPathElements(kAccountID2, kAccountID4);
2028 copy.pushBack(tail);
2030 auto const before = ps.size();
2032 ps.emplaceBack(copy);
2033 ps.assembleAdd(base, tail);
2035 BEAST_EXPECT(ps.size() - before == 1);
2038 BEAST_EXPECT(ps.size() == 6);
2044 testcase(
"STPathSet::pushBack/emplaceBack deduplication");
2052 static constexpr AccountID kAccountID1{
"A3F19C7B2E5D08146FB93A7C0E2D5184BC6F3A09"};
2053 static constexpr AccountID kAccountID2{
"1D7E4B90C2A6F3851E0B9D47A2C5F8136E0A4B7D"};
2054 static constexpr AccountID kAccountID3{
"F08C36A1D95E27B40CA1F63E8D204B7950E1C3A6"};
2056 auto const makePath = [](
AccountID const& account) {
2062 auto const first = makePath(kAccountID1);
2063 auto const second = makePath(kAccountID2);
2064 auto const third = makePath(kAccountID3);
2069 auto ps = STPathSet{STPathSet::DeduplicationTag{}};
2071 BEAST_EXPECT(ps.pushBack(first));
2072 BEAST_EXPECT(ps.size() == 1);
2074 BEAST_EXPECT(!ps.pushBack(first));
2075 BEAST_EXPECT(ps.size() == 1);
2078 BEAST_EXPECT(!ps.emplaceBack(first));
2079 BEAST_EXPECT(ps.size() == 1);
2081 BEAST_EXPECT(ps.emplaceBack(second));
2082 BEAST_EXPECT(ps.size() == 2);
2085 BEAST_EXPECT(!ps.pushBack(second));
2086 BEAST_EXPECT(ps.size() == 2);
2089 BEAST_EXPECT(ps.emplaceBack(std::vector<STPathElement>{third.front()}));
2090 BEAST_EXPECT(ps.size() == 3);
2091 BEAST_EXPECT(!ps.pushBack(third));
2092 BEAST_EXPECT(ps.size() == 3);
2095 BEAST_EXPECT(ps[0] == first);
2096 BEAST_EXPECT(ps[1] == second);
2097 BEAST_EXPECT(ps[2] == third);
2103 auto plain = STPathSet{};
2104 BEAST_EXPECT(plain.pushBack(first));
2105 BEAST_EXPECT(plain.pushBack(first));
2106 BEAST_EXPECT(plain.emplaceBack(first));
2107 BEAST_EXPECT(plain.size() == 3);
2109 auto named = STPathSet{sfPaths};
2110 BEAST_EXPECT(named.pushBack(first));
2111 BEAST_EXPECT(named.pushBack(first));
2112 BEAST_EXPECT(named.size() == 2);
2119 testcase(
"STPathElement hash injectivity");
2121 auto const zeroCurrency =
2125 BEAST_EXPECT(!(zeroCurrency == zeroMPT));
2127 auto const path = [](std::vector<STPathElement>
const& elements) {
2129 for (
auto const& element : elements)
2130 p.pushBack(element);
2134 auto const currencyFirst = path({zeroCurrency, zeroMPT});
2135 auto const mptFirst = path({zeroMPT, zeroCurrency});
2137 BEAST_EXPECT(!(currencyFirst == mptFirst));
2140 BEAST_EXPECT(hasher(currencyFirst) != hasher(mptFirst));
2144 auto orderings = 0uz;
2148 for (
auto const isMPT : mask)
2150 elements.push_back(isMPT != 0 ? zeroMPT : zeroCurrency);
2152 hashes.
insert(hasher(path(elements)));
2156 BEAST_EXPECT(orderings == 6);
2157 BEAST_EXPECT(hashes.size() == orderings);
2160 for (
auto const& p : {currencyFirst, mptFirst})
2164 BEAST_EXPECT(seen.size() == 2);
2171 static constexpr AccountID kAccount{
"A3F19C7B2E5D08146FB93A7C0E2D5184BC6F3A09"};
2172 static constexpr AccountID kIssuer{
"1D7E4B90C2A6F3851E0B9D47A2C5F8136E0A4B7D"};
2174 auto const equivalent = std::vector<std::pair<STPathElement, STPathElement>>{
2177 STPathElement{kAccount, PathAsset{
xrpCurrency()}, kIssuer,
true},
2178 STPathElement{kAccount, PathAsset{
xrpCurrency()}, kIssuer,
false},
2183 STPathElement{kAccount, PathAsset{
xrpCurrency()}, kIssuer,
false},
2187 for (
auto const& [lhs, rhs] : equivalent)
2189 BEAST_EXPECT(lhs.getNodeType() != rhs.getNodeType());
2190 BEAST_EXPECT(lhs == rhs);
2192 auto const lhsPath =
path({lhs});
2193 auto const rhsPath =
path({rhs});
2194 BEAST_EXPECT(hasher(lhsPath) == hasher(rhsPath));
2197 equal.emplace(lhsPath);
2198 equal.emplace(rhsPath);
2199 BEAST_EXPECT(
equal.size() == 1);
2206 testcase(
"STPathSet deserialization preserves duplicate paths");
2213 static constexpr AccountID kAccountID1{
"A3F19C7B2E5D08146FB93A7C0E2D5184BC6F3A09"};
2214 static constexpr AccountID kAccountID2{
"1D7E4B90C2A6F3851E0B9D47A2C5F8136E0A4B7D"};
2216 auto const element =
2217 STPathElement{kAccountID1, PathAsset{
xrpCurrency()}, kAccountID2,
true};
2219 auto path = STPath{};
2220 path.pushBack(element);
2222 static constexpr auto kDuplicates = 64uz;
2224 auto original = STPathSet{sfPaths};
2225 for (
auto i = 0uz; i < kDuplicates; ++i)
2227 original.pushBack(path);
2231 BEAST_EXPECT(original.size() == kDuplicates);
2233 auto s = Serializer{};
2236 auto sit = SerialIter{s.slice()};
2237 auto const parsed = STPathSet{sit, sfPaths};
2240 BEAST_EXPECT(parsed.size() == kDuplicates);
2241 BEAST_EXPECT(parsed.isEquivalent(original));
2244 auto serialized = Serializer{};
2245 parsed.add(serialized);
2246 BEAST_EXPECT(serialized.getData() == s.getData());
2249 auto appended = parsed;
2250 appended.pushBack(path);
2251 BEAST_EXPECT(appended.size() == kDuplicates + 1);
2275 for (
bool const domainEnabled : {
false,
true})
TestcaseT testcase
Memberspace for declaring test cases.
Unserialize a JSON document into a Value.
bool parse(std::string const &document, Value &root)
Read a Value from a JSON document.
const_iterator begin() const
const_iterator end() const
bool isMember(char const *key) const
Return true if the object has a member named key.
Seed functor once per construction.
json::Value getJson(JsonOptions=JsonOptions::Values::None) const override
Holds the serialized result of parsing an input JSON object.
std::optional< STObject > object
The STObject if the parse was successful.
An endpoint that consumes resources.
std::condition_variable cv_
bool waitFor(std::chrono::duration< Rep, Period > const &relTime)
void pathFind06(bool const domainEnabled)
void issuesPathNegativeRippleClientIssue23Larger()
void testAssembleAddDeduplication()
void run() override
Runs the suite.
void issuesPathNegativeIssue(bool const domainEnabled)
void alternativePathsConsumeBestTransferFirst()
void xrpToXrp(bool const domainEnabled)
void pathFind01(bool const domainEnabled)
void pathFind04(bool const domainEnabled)
auto findPathsRequest(jtx::Env &env, jtx::Account const &src, jtx::Account const &dst, STAmount const &saDstAmount, std::optional< STAmount > const &saSendMax=std::nullopt, std::optional< Currency > const &saSrcCurrency=std::nullopt, std::optional< UInt256 > const &domain=std::nullopt, std::optional< AccountID > const &saSrcIssuer=std::nullopt)
void receiveMax(bool const domainEnabled)
void alternativePathsLimitReturnedPathsToBestQuality(bool const domainEnabled)
void testPathHashInjectivity()
void pathFind05(bool const domainEnabled)
void viaOffersViaGateway(bool const domainEnabled)
void trustAutoClearTrustNormalClear()
void paymentAutoPathFind()
void directPathNoIntermediary()
void alternativePathConsumeBoth(bool const domainEnabled)
void norippleCombinations()
void testPushBackDeduplication()
void issuesPathNegativeRippleClientIssue23Smaller()
std::tuple< STPathSet, STAmount, STAmount > findPaths(jtx::Env &env, jtx::Account const &src, jtx::Account const &dst, STAmount const &saDstAmount, std::optional< STAmount > const &saSendMax=std::nullopt, std::optional< Currency > const &saSrcCurrency=std::nullopt, std::optional< UInt256 > const &domain=std::nullopt, std::optional< AccountID > const &saSrcIssuer=std::nullopt)
void testDeserializationPreservesDuplicates()
void pathFind02(bool const domainEnabled)
void indirectPathsPathFind()
void noDirectPathNoIntermediaryNoAlternatives()
void sourceCurrencyIssuerSelection()
void qualityPathsQualitySetAndTest()
void pathFind(bool const domainEnabled)
void pathFindConsumeAll(bool const domainEnabled)
void trustAutoClearTrustAutoClear()
void alternativePathsConsumeBestTransfer(bool const domainEnabled)
void sourceCurrenciesLimit()
Immutable cryptographic account descriptor.
A transaction testing environment.
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
SLE::const_pointer le(Account const &account) const
Return an account root.
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
void trust(STAmount const &amount, Account const &account)
Establish trust lines.
beast::Journal const journal
void require(Args const &... args)
Check a set of requirements.
Set Paths, SendMax on a JTx.
Sets the SendMax on a JTx.
Set the expected result code for a JTx The test will fail if the code doesn't match.
@ Array
array value (ordered list)
@ Object
object value (collection of name/value pairs).
Keylet amm(Asset const &issue1, Asset const &issue2) noexcept
AMM entry.
Keylet account(AccountID const &id) noexcept
AccountID root.
Keylet trustLine(AccountID const &id0, AccountID const &id1, Currency const ¤cy) noexcept
The index of a trust line for a given currency.
Charge const kFeeReferenceRpc
static constexpr int kMaxSrcCur
Maximum number of source currencies allowed in a path find request.
static constexpr int kMaxAutoSrcCur
Maximum number of auto source currencies in a path find request.
static constexpr auto kApiVersionIfUnspecified
::rpc::Status doCommand(rpc::JsonContext &context, json::Value &result)
Execute an RPC command and store the results in a json::Value.
json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
XrpT const XRP
Converts to XRP Issue or STAmount.
bool same(STPathSet const &st1, Args const &... args)
STPathElement ipe(Asset const &asset)
std::array< Account, 1+sizeof...(Args)> noripple(Account const &account, Args const &... args)
Designate accounts as no-ripple in Env::fund.
bool equal(STAmount const &sa1, STAmount const &sa2)
json::Value offer(Account const &account, STAmount const &takerPays, STAmount const &takerGets, std::uint32_t flags)
Create an offer.
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
json::Value trust(Account const &account, STAmount const &amount, std::uint32_t flags)
Modify a trust line.
UInt256 setupDomain(jtx::Env &env, std::vector< jtx::Account > const &accounts, jtx::Account const &domainOwner, std::string const &credType)
PrettyAmount drops(Integer i)
Returns an XRP PrettyAmount, which is trivially convertible to STAmount.
STPath stpath(Args const &... args)
json::Value rate(Account const &account, double multiplier)
Set a transfer rate.
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
json::Value rpf(jtx::Account const &src, jtx::Account const &dst, std::uint32_t numSrc)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Issue const & xrpIssue()
Returns an asset specifier that represents XRP.
std::unordered_set< Value, Hash, Pred, Allocator > HardenedHashSet
BaseUInt< 256 > Domain
Domain is a 256-bit hash representing a specific domain.
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
BaseUInt< 160, detail::CurrencyTag > Currency
Currency is a hash representing a specific currency.
Currency const & xrpCurrency()
XRP currency.
std::string to_string(BaseUInt< Bits, Tag > const &a)
BaseUInt< 192 > MPTID
MPTID is a 192-bit value representing MPT Issuance ID, which is a concatenation of a 32-bit sequence ...
STAmount amountFromJson(SField const &name, json::Value const &v)
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
AccountID const & xrpAccount()
Compute AccountID from public key.
T next_permutation(T... args)
std::shared_ptr< JobQueue::Coro > coro