xrpld
Loading...
Searching...
No Matches
Path_test.cpp
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> // IWYU pragma: keep
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>
21
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>
26
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>
50
51#include <algorithm>
52#include <chrono>
53#include <condition_variable>
54#include <cstddef>
55#include <cstdint>
56#include <memory>
57#include <mutex>
58#include <optional>
59#include <set>
60#include <string>
61#include <string_view>
62#include <tuple>
63#include <utility>
64#include <vector>
65
66namespace xrpl::test {
67
68//------------------------------------------------------------------------------
69
70json::Value
71rpf(jtx::Account const& src, jtx::Account const& dst, std::uint32_t numSrc)
72{
74 jv[jss::command] = "ripple_path_find";
75 jv[jss::source_account] = toBase58(src);
76
77 if (numSrc > 0)
78 {
79 auto& sc = (jv[jss::source_currencies] = json::ValueType::Array);
81 while ((numSrc--) != 0u)
82 {
83 j[jss::currency] = std::to_string(numSrc + 100);
84 sc.append(j);
85 }
86 }
87
88 auto const d = toBase58(dst);
89 jv[jss::destination_account] = d;
90
91 json::Value& j = (jv[jss::destination_amount] = json::ValueType::Object);
92 j[jss::currency] = "USD";
93 j[jss::value] = "0.01";
94 j[jss::issuer] = d;
95
96 return jv;
97}
98
99//------------------------------------------------------------------------------
100
102{
105 {
106 // These tests were originally written with search parameters that are
107 // different from the current defaults. This function creates an env
108 // with the search parameters that the tests were written for.
109 using namespace jtx;
110 return Env(*this, envconfig([](std::unique_ptr<Config> cfg) {
111 cfg->pathSearchOld = 7;
112 cfg->pathSearch = 7;
113 cfg->pathSearchMax = 10;
114 return cfg;
115 }));
116 }
117
118public:
119 class Gate
120 {
121 private:
124 bool signaled_ = false;
125
126 public:
127 // Thread safe, blocks until signaled or period expires.
128 // Returns `true` if signaled.
129 template <class Rep, class Period>
130 bool
132 {
134 auto const b = cv_.wait_for(lk, relTime, [this] { return signaled_; });
135 signaled_ = false;
136 return b;
137 }
138
139 void
141 {
142 std::scoped_lock const lk(mutex_);
143 signaled_ = true;
144 cv_.notify_all();
145 }
146 };
147
148 auto
150 jtx::Env& env,
151 jtx::Account const& src,
152 jtx::Account const& dst,
153 STAmount const& saDstAmount,
154 std::optional<STAmount> const& saSendMax = std::nullopt,
155 std::optional<Currency> const& saSrcCurrency = std::nullopt,
156 std::optional<UInt256> const& domain = std::nullopt,
157 std::optional<AccountID> const& saSrcIssuer = std::nullopt)
158 {
159 using namespace jtx;
160
161 auto& app = env.app();
164
165 rpc::JsonContext context{
166 {
167 .j = env.journal,
168 .app = app,
169 .loadType = loadType,
170 .netOps = app.getOPs(),
171 .ledgerMaster = app.getLedgerMaster(),
172 .consumer = c,
173 .role = Role::USER,
174 .coro = {},
175 .infoSub = {},
176 .apiVersion = rpc::kApiVersionIfUnspecified,
177 },
178 {},
179 // NOLINTNEXTLINE(readability-trailing-comma) fix-it drops comma after `{}`
180 {},
181 };
182
184 params[jss::command] = "ripple_path_find";
185 params[jss::source_account] = toBase58(src);
186 params[jss::destination_account] = toBase58(dst);
187 params[jss::destination_amount] = saDstAmount.getJson(JsonOptions::Values::None);
188 if (saSendMax)
189 params[jss::send_max] = saSendMax->getJson(JsonOptions::Values::None);
190 if (saSrcCurrency)
191 {
192 auto& sc = params[jss::source_currencies] = json::ValueType::Array;
194 j[jss::currency] = to_string(saSrcCurrency.value());
195 // Optional issuer for tests that need to exercise
196 // source_currencies entries more precisely than currency alone.
197 if (saSrcIssuer)
198 j[jss::issuer] = toBase58(*saSrcIssuer);
199 sc.append(j);
200 }
201 if (domain)
202 params[jss::domain] = to_string(*domain);
203
204 json::Value result;
205 Gate g;
206 app.getJobQueue().postCoro(JtClient, "RPC-Client", [&](auto const& coro) {
207 context.params = std::move(params);
208 context.coro = coro;
209 rpc::doCommand(context, result);
210 g.signal();
211 });
212
213 using namespace std::chrono_literals;
214 BEAST_EXPECT(g.waitFor(5s));
215 BEAST_EXPECT(!result.isMember(jss::error));
216 return result;
217 }
218
221 jtx::Env& env,
222 jtx::Account const& src,
223 jtx::Account const& dst,
224 STAmount const& saDstAmount,
225 std::optional<STAmount> const& saSendMax = std::nullopt,
226 std::optional<Currency> const& saSrcCurrency = std::nullopt,
227 std::optional<UInt256> const& domain = std::nullopt,
228 std::optional<AccountID> const& saSrcIssuer = std::nullopt)
229 {
231 env, src, dst, saDstAmount, saSendMax, saSrcCurrency, domain, saSrcIssuer);
232 BEAST_EXPECT(!result.isMember(jss::error));
233
234 STAmount da;
235 if (result.isMember(jss::destination_amount))
236 da = amountFromJson(sfGeneric, result[jss::destination_amount]);
237
238 STAmount sa;
239 STPathSet paths;
240 if (result.isMember(jss::alternatives))
241 {
242 auto const& alts = result[jss::alternatives];
243 if (alts.size() > 0)
244 {
245 auto const& path = alts[0u];
246
247 if (path.isMember(jss::source_amount))
248 sa = amountFromJson(sfGeneric, path[jss::source_amount]);
249
250 if (path.isMember(jss::destination_amount))
251 da = amountFromJson(sfGeneric, path[jss::destination_amount]);
252
253 if (path.isMember(jss::paths_computed))
254 {
255 json::Value p;
256 p["Paths"] = path[jss::paths_computed];
257 STParsedJSONObject po("generic", p);
258
259 // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
260 paths = po.object->getFieldPathSet(sfPaths);
261 }
262 }
263 }
264
265 return std::make_tuple(std::move(paths), std::move(sa), std::move(da));
266 }
267
268 void
270 {
271 testcase("source currency limits");
272 using namespace std::chrono_literals;
273 using namespace jtx;
274 Env env = pathTestEnv();
275 auto const gw = Account("gateway");
276 env.fund(XRP(10000), "alice", "bob", gw);
277 env.close();
278 env.trust(gw["USD"](100), "alice", "bob");
279 env.close();
280
281 auto& app = env.app();
284
285 rpc::JsonContext context{
286 {
287 .j = env.journal,
288 .app = app,
289 .loadType = loadType,
290 .netOps = app.getOPs(),
291 .ledgerMaster = app.getLedgerMaster(),
292 .consumer = c,
293 .role = Role::USER,
294 .coro = {},
295 .infoSub = {},
296 .apiVersion = rpc::kApiVersionIfUnspecified,
297 },
298 {},
299 // NOLINTNEXTLINE(readability-trailing-comma) fix-it drops comma after `{}`
300 {},
301 };
302 json::Value result;
303 Gate g;
304 // Test rpc::tuning::max_src_cur source currencies.
305 app.getJobQueue().postCoro(JtClient, "RPC-Client", [&](auto const& coro) {
306 context.params = rpf(Account("alice"), Account("bob"), rpc::tuning::kMaxSrcCur);
307 context.coro = coro;
308 rpc::doCommand(context, result);
309 g.signal();
310 });
311 BEAST_EXPECT(g.waitFor(5s));
312 BEAST_EXPECT(!result.isMember(jss::error));
313
314 // Test more than rpc::tuning::max_src_cur source currencies.
315 app.getJobQueue().postCoro(JtClient, "RPC-Client", [&](auto const& coro) {
316 context.params = rpf(Account("alice"), Account("bob"), rpc::tuning::kMaxSrcCur + 1);
317 context.coro = coro;
318 rpc::doCommand(context, result);
319 g.signal();
320 });
321 BEAST_EXPECT(g.waitFor(5s));
322 BEAST_EXPECT(result[jss::error] == "srcCurMalformed");
323 BEAST_EXPECT(result[jss::error_code] == RpcSrcCurMalformed);
324 BEAST_EXPECT(result[jss::error_message] == "Source currency is malformed.");
325
326 // Test rpc::tuning::max_auto_src_cur source currencies.
327 for (auto i = 0; i < (rpc::tuning::kMaxAutoSrcCur - 1); ++i)
328 env.trust(Account("alice")[std::to_string(i + 100)](100), "bob");
329 app.getJobQueue().postCoro(JtClient, "RPC-Client", [&](auto const& coro) {
330 context.params = rpf(Account("alice"), Account("bob"), 0);
331 context.coro = coro;
332 rpc::doCommand(context, result);
333 g.signal();
334 });
335 BEAST_EXPECT(g.waitFor(5s));
336 BEAST_EXPECT(!result.isMember(jss::error));
337
338 // Test more than rpc::tuning::max_auto_src_cur source currencies.
339 env.trust(Account("alice")["AUD"](100), "bob");
340 app.getJobQueue().postCoro(JtClient, "RPC-Client", [&](auto const& coro) {
341 context.params = rpf(Account("alice"), Account("bob"), 0);
342 context.coro = coro;
343 rpc::doCommand(context, result);
344 g.signal();
345 });
346 BEAST_EXPECT(g.waitFor(5s));
347 BEAST_EXPECT(result[jss::error] == "internal");
348 BEAST_EXPECT(result[jss::error_code] == RpcInternal);
349 BEAST_EXPECT(result[jss::error_message] == "Internal error.");
350 }
351
352 void
354 {
355 testcase("source currency issuer selection");
356 using namespace jtx;
357
358 Env env = pathTestEnv();
359 auto const alice = Account("alice");
360 auto const bob = Account("bob");
361 auto const gateway = Account("gateway");
362
363 env.fund(XRP(10000), alice, bob, gateway);
364 env.close();
365
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)));
372 env.close();
373
374 // Ask for USD from an explicit source issuer while send_max is
375 // Alice-issued USD. The parser should choose gateway-issued USD
376 // because gateway is the issuer in source_currencies.
377 //
378 // The Alice/Bob trust line is intentional: if Alice-issued USD is also
379 // considered as a source asset, pathfinding can produce an additional
380 // alternative. The single expected alternative below verifies that only
381 // the explicit issuer is selected.
382 auto const result = findPathsRequest(
383 env,
384 alice,
385 bob,
386 bob["USD"](-1),
387 alice["USD"](100).value(),
388 usd.currency,
389 std::nullopt,
390 gateway.id());
391 auto const& alternatives = result[jss::alternatives];
392 BEAST_EXPECT(alternatives.size() == 1);
393 auto const sa = amountFromJson(sfGeneric, alternatives[0u][jss::source_amount]);
394 auto const da = amountFromJson(sfGeneric, alternatives[0u][jss::destination_amount]);
395 BEAST_EXPECTS(equal(sa, usd(100)), sa.getFullText());
396 BEAST_EXPECTS(equal(da, bob["USD"](100)), da.getFullText());
397 }
398
399 void
401 {
402 testcase("no direct path no intermediary no alternatives");
403 using namespace jtx;
404 Env env = pathTestEnv();
405 env.fund(XRP(10000), "alice", "bob");
406 env.close();
407
408 auto const result = findPaths(env, "alice", "bob", Account("bob")["USD"](5));
409 BEAST_EXPECT(std::get<0>(result).empty());
410 }
411
412 void
414 {
415 testcase("direct path no intermediary");
416 using namespace jtx;
417 Env env = pathTestEnv();
418 env.fund(XRP(10000), "alice", "bob");
419 env.close();
420 env.trust(Account("alice")["USD"](700), "bob");
421
422 STPathSet st;
423 STAmount sa;
424 std::tie(st, sa, std::ignore) = findPaths(env, "alice", "bob", Account("bob")["USD"](5));
425 BEAST_EXPECT(st.empty());
426 BEAST_EXPECT(equal(sa, Account("alice")["USD"](5)));
427 }
428
429 void
431 {
432 testcase("payment auto path find");
433 using namespace jtx;
434 Env env = pathTestEnv();
435 auto const gw = Account("gateway");
436 auto const usd = gw["USD"];
437 env.fund(XRP(10000), "alice", "bob", gw);
438 env.close();
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)));
443 env.require(Balance("alice", usd(46)));
444 env.require(Balance(gw, Account("alice")["USD"](-46)));
445 env.require(Balance("bob", usd(24)));
446 env.require(Balance(gw, Account("bob")["USD"](-24)));
447 }
448
449 void
450 pathFind(bool const domainEnabled)
451 {
452 testcase(std::string("path find") + (domainEnabled ? " w/ " : " w/o ") + "domain");
453 using namespace jtx;
454 Env env = pathTestEnv();
455 auto const gw = Account("gateway");
456 auto const usd = gw["USD"];
457 env.fund(XRP(10000), "alice", "bob", gw);
458 env.close();
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)));
463
464 std::optional<UInt256> domainID;
465 if (domainEnabled)
466 domainID = setupDomain(env, {"alice", "bob", gw});
467
468 STPathSet st;
469 STAmount sa;
470 std::tie(st, sa, std::ignore) = findPaths(
471 env, "alice", "bob", Account("bob")["USD"](5), std::nullopt, std::nullopt, domainID);
472 BEAST_EXPECT(same(st, stpath("gateway")));
473 BEAST_EXPECT(equal(sa, Account("alice")["USD"](5)));
474 }
475
476 void
477 xrpToXrp(bool const domainEnabled)
478 {
479 using namespace jtx;
480 testcase(std::string("XRP to XRP") + (domainEnabled ? " w/ " : " w/o ") + "domain");
481 Env env = pathTestEnv();
482 env.fund(XRP(10000), "alice", "bob");
483 env.close();
484
485 std::optional<UInt256> domainID;
486 if (domainEnabled)
487 domainID = setupDomain(env, {"alice", "bob"});
488
489 auto const result =
490 findPaths(env, "alice", "bob", XRP(5), std::nullopt, std::nullopt, domainID);
491 BEAST_EXPECT(std::get<0>(result).empty());
492 }
493
494 void
495 pathFindConsumeAll(bool const domainEnabled)
496 {
497 testcase(
498 std::string("path find consume all") + (domainEnabled ? " w/ " : " w/o ") + "domain");
499 using namespace jtx;
500
501 {
502 Env env = pathTestEnv();
503 env.fund(XRP(10000), "alice", "bob", "carol", "dan", "edward");
504 env.close();
505 env.trust(Account("alice")["USD"](10), "bob");
506 env.trust(Account("bob")["USD"](10), "carol");
507 env.trust(Account("carol")["USD"](10), "edward");
508 env.trust(Account("alice")["USD"](100), "dan");
509 env.trust(Account("dan")["USD"](100), "edward");
510
511 std::optional<UInt256> domainID;
512 if (domainEnabled)
513 domainID = setupDomain(env, {"alice", "bob", "carol", "dan", "edward"});
514
515 STPathSet st;
516 STAmount sa;
517 STAmount da;
518 std::tie(st, sa, da) = findPaths(
519 env,
520 "alice",
521 "edward",
522 Account("edward")["USD"](-1),
523 std::nullopt,
524 std::nullopt,
525 domainID);
526 BEAST_EXPECT(same(st, stpath("dan"), stpath("bob", "carol")));
527 BEAST_EXPECT(equal(sa, Account("alice")["USD"](110)));
528 BEAST_EXPECT(equal(da, Account("edward")["USD"](110)));
529 }
530
531 {
532 Env env = pathTestEnv();
533 auto const gw = Account("gateway");
534 auto const usd = gw["USD"];
535 env.fund(XRP(10000), "alice", "bob", "carol", gw);
536 env.close();
537 env.trust(usd(100), "bob", "carol");
538 env.close();
539 env(pay(gw, "carol", usd(100)));
540 env.close();
541
542 std::optional<UInt256> domainID;
543 if (domainEnabled)
544 {
545 domainID = setupDomain(env, {"alice", "bob", "carol", "gateway"});
546 env(offer("carol", XRP(100), usd(100)), Domain(*domainID));
547 }
548 else
549 {
550 env(offer("carol", XRP(100), usd(100)));
551 }
552 env.close();
553
554 STPathSet st;
555 STAmount sa;
556 STAmount da;
557 std::tie(st, sa, da) = findPaths(
558 env,
559 "alice",
560 "bob",
561 Account("bob")["AUD"](-1),
563 std::nullopt,
564 domainID);
565 BEAST_EXPECT(st.empty());
566 std::tie(st, sa, da) = findPaths(
567 env,
568 "alice",
569 "bob",
570 Account("bob")["USD"](-1),
572 std::nullopt,
573 domainID);
574 BEAST_EXPECT(sa == XRP(100));
575 BEAST_EXPECT(equal(da, Account("bob")["USD"](100)));
576
577 // if domain is used, finding path in the open offerbook will return
578 // empty result
579 if (domainEnabled)
580 {
581 std::tie(st, sa, da) = findPaths(
582 env,
583 "alice",
584 "bob",
585 Account("bob")["USD"](-1),
587 std::nullopt,
588 std::nullopt); // not specifying a domain
589 BEAST_EXPECT(st.empty());
590 }
591 }
592 }
593
594 void
595 alternativePathConsumeBoth(bool const domainEnabled)
596 {
597 testcase(
598 std::string("alternative path consume both") + (domainEnabled ? " w/ " : " w/o ") +
599 "domain");
600 using namespace jtx;
601 Env env = pathTestEnv();
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);
607 env.close();
608 env.trust(usd(600), "alice");
609 env.trust(gw2Usd(800), "alice");
610 env.trust(usd(700), "bob");
611 env.trust(gw2Usd(900), "bob");
612
613 std::optional<UInt256> domainID;
614 if (domainEnabled)
615 {
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)),
620 Paths(Account("alice")["USD"]),
621 Domain(*domainID));
622 }
623 else
624 {
625 env(pay(gw, "alice", usd(70)));
626 env(pay(gw2, "alice", gw2Usd(70)));
627 env(pay("alice", "bob", Account("bob")["USD"](140)), Paths(Account("alice")["USD"]));
628 }
629
630 env.require(Balance("alice", usd(0)));
631 env.require(Balance("alice", gw2Usd(0)));
632 env.require(Balance("bob", usd(70)));
633 env.require(Balance("bob", gw2Usd(70)));
634 env.require(Balance(gw, Account("alice")["USD"](0)));
635 env.require(Balance(gw, Account("bob")["USD"](-70)));
636 env.require(Balance(gw2, Account("alice")["USD"](0)));
637 env.require(Balance(gw2, Account("bob")["USD"](-70)));
638 }
639
640 void
641 alternativePathsConsumeBestTransfer(bool const domainEnabled)
642 {
643 testcase(
644 std::string("alternative paths consume best transfer") +
645 (domainEnabled ? " w/ " : " w/o ") + "domain");
646 using namespace jtx;
647 Env env = pathTestEnv();
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);
653 env.close();
654 env(rate(gw2, 1.1));
655 env.trust(usd(600), "alice");
656 env.trust(gw2Usd(800), "alice");
657 env.trust(usd(700), "bob");
658 env.trust(gw2Usd(900), "bob");
659
660 std::optional<UInt256> domainID;
661 if (domainEnabled)
662 {
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));
667 }
668 else
669 {
670 env(pay(gw, "alice", usd(70)));
671 env(pay(gw2, "alice", gw2Usd(70)));
672 env(pay("alice", "bob", usd(70)));
673 }
674 env.require(Balance("alice", usd(0)));
675 env.require(Balance("alice", gw2Usd(70)));
676 env.require(Balance("bob", usd(70)));
677 env.require(Balance("bob", gw2Usd(0)));
678 env.require(Balance(gw, Account("alice")["USD"](0)));
679 env.require(Balance(gw, Account("bob")["USD"](-70)));
680 env.require(Balance(gw2, Account("alice")["USD"](-70)));
681 env.require(Balance(gw2, Account("bob")["USD"](0)));
682 }
683
684 void
686 {
687 testcase("alternative paths - consume best transfer first");
688 using namespace jtx;
689 Env env = pathTestEnv();
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);
695 env.close();
696 env(rate(gw2, 1.1));
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)),
704 Sendmax(Account("alice")["USD"](100)),
705 Paths(Account("alice")["USD"]));
706 env.require(Balance("alice", usd(0)));
707 env.require(Balance("alice", gw2Usd(62.3)));
708 env.require(Balance("bob", usd(70)));
709 env.require(Balance("bob", gw2Usd(7)));
710 env.require(Balance(gw, Account("alice")["USD"](0)));
711 env.require(Balance(gw, Account("bob")["USD"](-70)));
712 env.require(Balance(gw2, Account("alice")["USD"](-62.3)));
713 env.require(Balance(gw2, Account("bob")["USD"](-7)));
714 }
715
716 void
718 {
719 testcase(
720 std::string("alternative paths - limit returned paths to best quality") +
721 (domainEnabled ? " w/ " : " w/o ") + "domain");
722 using namespace jtx;
723 Env env = pathTestEnv();
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);
729 env.close();
730 env(rate("carol", 1.1));
731 env.trust(Account("carol")["USD"](800), "alice", "bob");
732 env.trust(Account("dan")["USD"](800), "alice", "bob");
733 env.trust(usd(800), "alice", "bob");
734 env.trust(gw2Usd(800), "alice", "bob");
735 env.trust(Account("alice")["USD"](800), "dan");
736 env.trust(Account("bob")["USD"](800), "dan");
737 env.close();
738 env(pay(gw2, "alice", gw2Usd(100)));
739 env.close();
740 env(pay("carol", "alice", Account("carol")["USD"](100)));
741 env.close();
742 env(pay(gw, "alice", usd(100)));
743 env.close();
744
745 std::optional<UInt256> domainID;
746 if (domainEnabled)
747 {
748 domainID = setupDomain(env, {"alice", "bob", "carol", "dan", gw, gw2});
749 }
750
751 STPathSet st;
752 STAmount sa;
753 std::tie(st, sa, std::ignore) = findPaths(
754 env, "alice", "bob", Account("bob")["USD"](5), std::nullopt, std::nullopt, domainID);
755 BEAST_EXPECT(
756 same(st, stpath("gateway"), stpath("gateway2"), stpath("dan"), stpath("carol")));
757 BEAST_EXPECT(equal(sa, Account("alice")["USD"](5)));
758 }
759
760 void
761 issuesPathNegativeIssue(bool const domainEnabled)
762 {
763 testcase(
764 std::string("path negative: Issue #5") + (domainEnabled ? " w/ " : " w/o ") + "domain");
765 using namespace jtx;
766 Env env = pathTestEnv();
767 env.fund(XRP(10000), "alice", "bob", "carol", "dan");
768 env.close();
769 env.trust(Account("bob")["USD"](100), "alice", "carol", "dan");
770 env.trust(Account("alice")["USD"](100), "dan");
771 env.trust(Account("carol")["USD"](100), "dan");
772 env(pay("bob", "carol", Account("bob")["USD"](75)));
773 env.require(Balance("bob", Account("carol")["USD"](-75)));
774 env.require(Balance("carol", Account("bob")["USD"](75)));
775 env.close();
776
777 std::optional<UInt256> domainID;
778 if (domainEnabled)
779 {
780 domainID = setupDomain(env, {"alice", "bob", "carol", "dan"});
781 }
782
783 auto result = findPaths(
784 env, "alice", "bob", Account("bob")["USD"](25), std::nullopt, std::nullopt, domainID);
785 BEAST_EXPECT(std::get<0>(result).empty());
786
787 env(pay("alice", "bob", Account("alice")["USD"](25)), Ter(tecPATH_DRY));
788 env.close();
789
790 result = findPaths(
791 env, "alice", "bob", Account("alice")["USD"](25), std::nullopt, std::nullopt, domainID);
792 BEAST_EXPECT(std::get<0>(result).empty());
793
794 env.require(Balance("alice", Account("bob")["USD"](0)));
795 env.require(Balance("alice", Account("dan")["USD"](0)));
796 env.require(Balance("bob", Account("alice")["USD"](0)));
797 env.require(Balance("bob", Account("carol")["USD"](-75)));
798 env.require(Balance("bob", Account("dan")["USD"](0)));
799 env.require(Balance("carol", Account("bob")["USD"](75)));
800 env.require(Balance("carol", Account("dan")["USD"](0)));
801 env.require(Balance("dan", Account("alice")["USD"](0)));
802 env.require(Balance("dan", Account("bob")["USD"](0)));
803 env.require(Balance("dan", Account("carol")["USD"](0)));
804 }
805
806 // alice_ -- limit 40 --> bob_
807 // alice_ --> carol_ --> dan --> bob_
808 // Balance of 100 USD Bob - Balance of 37 USD -> Rod
809 void
811 {
812 testcase("path negative: ripple-client issue #23: smaller");
813 using namespace jtx;
814 Env env = pathTestEnv();
815 env.fund(XRP(10000), "alice", "bob", "carol", "dan");
816 env.close();
817 env.trust(Account("alice")["USD"](40), "bob");
818 env.trust(Account("dan")["USD"](20), "bob");
819 env.trust(Account("alice")["USD"](20), "carol");
820 env.trust(Account("carol")["USD"](20), "dan");
821 env(pay("alice", "bob", Account("bob")["USD"](55)), Paths(Account("alice")["USD"]));
822 env.require(Balance("bob", Account("alice")["USD"](40)));
823 env.require(Balance("bob", Account("dan")["USD"](15)));
824 }
825
826 // alice_ -120 USD-> edward -25 USD-> bob_
827 // alice_ -25 USD-> carol_ -75 USD -> dan -100 USD-> bob_
828 void
830 {
831 testcase("path negative: ripple-client issue #23: larger");
832 using namespace jtx;
833 Env env = pathTestEnv();
834 env.fund(XRP(10000), "alice", "bob", "carol", "dan", "edward");
835 env.close();
836 env.trust(Account("alice")["USD"](120), "edward");
837 env.trust(Account("edward")["USD"](25), "bob");
838 env.trust(Account("dan")["USD"](100), "bob");
839 env.trust(Account("alice")["USD"](25), "carol");
840 env.trust(Account("carol")["USD"](75), "dan");
841 env(pay("alice", "bob", Account("bob")["USD"](50)), Paths(Account("alice")["USD"]));
842 env.require(Balance("alice", Account("edward")["USD"](-25)));
843 env.require(Balance("alice", Account("carol")["USD"](-25)));
844 env.require(Balance("bob", Account("edward")["USD"](25)));
845 env.require(Balance("bob", Account("dan")["USD"](25)));
846 env.require(Balance("carol", Account("alice")["USD"](25)));
847 env.require(Balance("carol", Account("dan")["USD"](-25)));
848 env.require(Balance("dan", Account("carol")["USD"](25)));
849 env.require(Balance("dan", Account("bob")["USD"](-25)));
850 }
851
852 // carol_ holds gateway AUD, sells gateway AUD for XRP
853 // bob_ will hold gateway AUD
854 // alice_ pays bob_ gateway AUD using XRP
855 void
856 viaOffersViaGateway(bool const domainEnabled)
857 {
858 testcase(std::string("via gateway") + (domainEnabled ? " w/ " : " w/o ") + "domain");
859 using namespace jtx;
860 Env env = pathTestEnv();
861 auto const gw = Account("gateway");
862 auto const aud = gw["AUD"];
863 env.fund(XRP(10000), "alice", "bob", "carol", gw);
864 env.close();
865 env(rate(gw, 1.1));
866 env.close();
867 env.trust(aud(100), "bob", "carol");
868 env.close();
869 env(pay(gw, "carol", aud(50)));
870 env.close();
871
872 std::optional<UInt256> domainID;
873 if (domainEnabled)
874 {
875 domainID = setupDomain(env, {"alice", "bob", "carol", gw});
876 env(offer("carol", XRP(50), aud(50)), Domain(*domainID));
877 env.close();
878 env(pay("alice", "bob", aud(10)), Sendmax(XRP(100)), Paths(XRP), Domain(*domainID));
879 env.close();
880 }
881 else
882 {
883 env(offer("carol", XRP(50), aud(50)));
884 env.close();
885 env(pay("alice", "bob", aud(10)), Sendmax(XRP(100)), Paths(XRP));
886 env.close();
887 }
888
889 env.require(Balance("bob", aud(10)));
890 env.require(Balance("carol", aud(39)));
891
892 auto const result = findPaths(
893 env, "alice", "bob", Account("bob")["USD"](25), std::nullopt, std::nullopt, domainID);
894 BEAST_EXPECT(std::get<0>(result).empty());
895 }
896
897 void
899 {
900 testcase("path find");
901 using namespace jtx;
902 Env env = pathTestEnv();
903 env.fund(XRP(10000), "alice", "bob", "carol");
904 env.close();
905 env.trust(Account("alice")["USD"](1000), "bob");
906 env.trust(Account("bob")["USD"](1000), "carol");
907
908 STPathSet st;
909 STAmount sa;
910 std::tie(st, sa, std::ignore) =
911 findPaths(env, "alice", "carol", Account("carol")["USD"](5));
912 BEAST_EXPECT(same(st, stpath("bob")));
913 BEAST_EXPECT(equal(sa, Account("alice")["USD"](5)));
914 }
915
916 void
918 {
919 testcase("quality set and test");
920 using namespace jtx;
921 Env env = pathTestEnv();
922 env.fund(XRP(10000), "alice", "bob");
923 env.close();
924 env(trust("bob", Account("alice")["USD"](1000)),
925 Json("{\"" + sfQualityIn.fieldName + "\": 2000}"),
926 Json("{\"" + sfQualityOut.fieldName + "\": 1400000000}"));
927
928 json::Value jv;
930 R"({
931 "Balance" : {
932 "currency" : "USD",
933 "issuer" : "rrrrrrrrrrrrrrrrrrrrBZbvji",
934 "value" : "0"
935 },
936 "Flags" : 131072,
937 "HighLimit" : {
938 "currency" : "USD",
939 "issuer" : "rPMh7Pi9ct699iZUTWaytJUoHcJ7cgyziK",
940 "value" : "1000"
941 },
942 "HighNode" : "0",
943 "HighQualityIn" : 2000,
944 "HighQualityOut" : 1400000000,
945 "LedgerEntryType" : "RippleState",
946 "LowLimit" : {
947 "currency" : "USD",
948 "issuer" : "rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn",
949 "value" : "0"
950 },
951 "LowNode" : "0"
952 })",
953 jv);
954
955 auto const jvL = env.le(keylet::trustLine(Account("bob").id(), Account("alice")["USD"]))
956 ->getJson(JsonOptions::Values::None);
957 for (auto it = jv.begin(); it != jv.end(); ++it)
958 BEAST_EXPECT(*it == jvL[it.memberName()]);
959 }
960
961 void
963 {
964 testcase("trust normal clear");
965 using namespace jtx;
966 Env env = pathTestEnv();
967 env.fund(XRP(10000), "alice", "bob");
968 env.close();
969 env.trust(Account("bob")["USD"](1000), "alice");
970 env.trust(Account("alice")["USD"](1000), "bob");
971
972 json::Value jv;
974 R"({
975 "Balance" : {
976 "currency" : "USD",
977 "issuer" : "rrrrrrrrrrrrrrrrrrrrBZbvji",
978 "value" : "0"
979 },
980 "Flags" : 196608,
981 "HighLimit" : {
982 "currency" : "USD",
983 "issuer" : "rPMh7Pi9ct699iZUTWaytJUoHcJ7cgyziK",
984 "value" : "1000"
985 },
986 "HighNode" : "0",
987 "LedgerEntryType" : "RippleState",
988 "LowLimit" : {
989 "currency" : "USD",
990 "issuer" : "rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn",
991 "value" : "1000"
992 },
993 "LowNode" : "0"
994 })",
995 jv);
996
997 auto const jvL = env.le(keylet::trustLine(Account("bob").id(), Account("alice")["USD"]))
998 ->getJson(JsonOptions::Values::None);
999 for (auto it = jv.begin(); it != jv.end(); ++it)
1000 BEAST_EXPECT(*it == jvL[it.memberName()]);
1001
1002 env.trust(Account("bob")["USD"](0), "alice");
1003 env.trust(Account("alice")["USD"](0), "bob");
1004 BEAST_EXPECT(
1005 env.le(keylet::trustLine(Account("bob").id(), Account("alice")["USD"])) == nullptr);
1006 }
1007
1008 void
1010 {
1011 testcase("trust auto clear");
1012 using namespace jtx;
1013 Env env = pathTestEnv();
1014 env.fund(XRP(10000), "alice", "bob");
1015 env.close();
1016 env.trust(Account("bob")["USD"](1000), "alice");
1017 env(pay("bob", "alice", Account("bob")["USD"](50)));
1018 env.trust(Account("bob")["USD"](0), "alice");
1019
1020 json::Value jv;
1022 R"({
1023 "Balance" :
1024 {
1025 "currency" : "USD",
1026 "issuer" : "rrrrrrrrrrrrrrrrrrrrBZbvji",
1027 "value" : "50"
1028 },
1029 "Flags" : 65536,
1030 "HighLimit" :
1031 {
1032 "currency" : "USD",
1033 "issuer" : "rPMh7Pi9ct699iZUTWaytJUoHcJ7cgyziK",
1034 "value" : "0"
1035 },
1036 "HighNode" : "0",
1037 "LedgerEntryType" : "RippleState",
1038 "LowLimit" :
1039 {
1040 "currency" : "USD",
1041 "issuer" : "rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn",
1042 "value" : "0"
1043 },
1044 "LowNode" : "0"
1045 })",
1046 jv);
1047
1048 auto const jvL = env.le(keylet::trustLine(Account("alice").id(), Account("bob")["USD"]))
1049 ->getJson(JsonOptions::Values::None);
1050 for (auto it = jv.begin(); it != jv.end(); ++it)
1051 BEAST_EXPECT(*it == jvL[it.memberName()]);
1052
1053 env(pay("alice", "bob", Account("alice")["USD"](50)));
1054 BEAST_EXPECT(
1055 env.le(keylet::trustLine(Account("alice").id(), Account("bob")["USD"])) == nullptr);
1056 }
1057
1058 void
1059 pathFind01(bool const domainEnabled)
1060 {
1061 testcase(
1062 std::string("Path Find: XRP -> XRP and XRP -> IOU") +
1063 (domainEnabled ? " w/ " : " w/o ") + "domain");
1064 using namespace jtx;
1065 Env env = pathTestEnv();
1066 Account const a1{"A1"};
1067 Account const a2{"A2"};
1068 Account const a3{"A3"};
1069 Account const g1{"G1"};
1070 Account const g2{"G2"};
1071 Account const g3{"G3"};
1072 Account const m1{"M1"};
1073
1074 env.fund(XRP(100000), a1);
1075 env.fund(XRP(10000), a2);
1076 env.fund(XRP(1000), a3, g1, g2, g3, m1);
1077 env.close();
1078
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);
1087 env.close();
1088
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)));
1093 env.close();
1094
1096 if (domainEnabled)
1097 {
1098 domainID = setupDomain(env, {a1, a2, a3, g1, g2, g3, m1});
1099 env(offer(m1, g1["XYZ"](1000), g2["XYZ"](1000)), Domain(*domainID));
1100 env(offer(m1, XRP(10000), g3["ABC"](1000)), Domain(*domainID));
1101 env.close();
1102 }
1103 else
1104 {
1105 env(offer(m1, g1["XYZ"](1000), g2["XYZ"](1000)));
1106 env(offer(m1, XRP(10000), g3["ABC"](1000)));
1107 env.close();
1108 }
1109
1110 STPathSet st;
1111 STAmount sa, da;
1112
1113 {
1114 auto const& sendAmt = XRP(10);
1115 std::tie(st, sa, da) =
1116 findPaths(env, a1, a2, sendAmt, std::nullopt, xrpCurrency(), domainID);
1117 BEAST_EXPECT(equal(da, sendAmt));
1118 BEAST_EXPECT(st.empty());
1119 }
1120
1121 {
1122 // no path should exist for this since dest account
1123 // does not exist.
1124 auto const& sendAmt = XRP(200);
1125 std::tie(st, sa, da) =
1126 findPaths(env, a1, Account{"A0"}, sendAmt, std::nullopt, xrpCurrency(), domainID);
1127 BEAST_EXPECT(equal(da, sendAmt));
1128 BEAST_EXPECT(st.empty());
1129 }
1130
1131 {
1132 auto const& sendAmt = g3["ABC"](10);
1133 std::tie(st, sa, da) =
1134 findPaths(env, a2, g3, sendAmt, std::nullopt, xrpCurrency(), domainID);
1135 BEAST_EXPECT(equal(da, sendAmt));
1136 BEAST_EXPECT(equal(sa, XRP(100)));
1137 BEAST_EXPECT(same(st, stpath(ipe(g3["ABC"]))));
1138 }
1139
1140 {
1141 auto const& sendAmt = a2["ABC"](1);
1142 std::tie(st, sa, da) =
1143 findPaths(env, a1, a2, sendAmt, std::nullopt, xrpCurrency(), domainID);
1144 BEAST_EXPECT(equal(da, sendAmt));
1145 BEAST_EXPECT(equal(sa, XRP(10)));
1146 BEAST_EXPECT(same(st, stpath(ipe(g3["ABC"]), g3)));
1147 }
1148
1149 {
1150 auto const& sendAmt = a3["ABC"](1);
1151 std::tie(st, sa, da) =
1152 findPaths(env, a1, a3, sendAmt, std::nullopt, xrpCurrency(), domainID);
1153 BEAST_EXPECT(equal(da, sendAmt));
1154 BEAST_EXPECT(equal(sa, XRP(10)));
1155 BEAST_EXPECT(same(st, stpath(ipe(g3["ABC"]), g3, a2)));
1156 }
1157 }
1158
1159 void
1160 pathFind02(bool const domainEnabled)
1161 {
1162 testcase(
1163 std::string("Path Find: non-XRP -> XRP") + (domainEnabled ? " w/ " : " w/o ") +
1164 "domain");
1165 using namespace jtx;
1166 Env env = pathTestEnv();
1167 Account const a1{"A1"};
1168 Account const a2{"A2"};
1169 Account const g3{"G3"};
1170 Account const m1{"M1"};
1171
1172 env.fund(XRP(1000), a1, a2, g3);
1173 env.fund(XRP(11000), m1);
1174 env.close();
1175
1176 env.trust(g3["ABC"](1000), a1, a2);
1177 env.trust(g3["ABC"](100000), m1);
1178 env.close();
1179
1180 env(pay(g3, a1, g3["ABC"](1000)));
1181 env(pay(g3, a2, g3["ABC"](1000)));
1182 env(pay(g3, m1, g3["ABC"](1200)));
1183 env.close();
1184
1185 std::optional<UInt256> domainID;
1186 if (domainEnabled)
1187 {
1188 domainID = setupDomain(env, {a1, a2, g3, m1});
1189 env(offer(m1, g3["ABC"](1000), XRP(10000)), Domain(*domainID));
1190 }
1191 else
1192 {
1193 env(offer(m1, g3["ABC"](1000), XRP(10000)));
1194 }
1195
1196 STPathSet st;
1197 STAmount sa, da;
1198 auto const& sendAmt = XRP(10);
1199
1200 {
1201 std::tie(st, sa, da) =
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)));
1205 BEAST_EXPECT(same(st, stpath(g3, ipe(xrpIssue()))));
1206 }
1207
1208 // domain offer will not be considered in pathfinding for non-domain
1209 // paths
1210 if (domainEnabled)
1211 {
1212 std::tie(st, sa, da) =
1213 findPaths(env, a1, a2, sendAmt, std::nullopt, a2["ABC"].currency);
1214 BEAST_EXPECT(equal(da, sendAmt));
1215 BEAST_EXPECT(st.empty());
1216 }
1217 }
1218
1219 void
1220 pathFind04(bool const domainEnabled)
1221 {
1222 testcase(
1223 std::string("Path Find: Bitstamp and SnapSwap, liquidity with no offers") +
1224 (domainEnabled ? " w/ " : " w/o ") + "domain");
1225 using namespace jtx;
1226 Env env = pathTestEnv();
1227 Account const a1{"A1"};
1228 Account const a2{"A2"};
1229 Account const g1Bs{"G1BS"};
1230 Account const g2Sw{"G2SW"};
1231 Account const m1{"M1"};
1232
1233 env.fund(XRP(1000), g1Bs, g2Sw, a1, a2);
1234 env.fund(XRP(11000), m1);
1235 env.close();
1236
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);
1241 env.close();
1242
1243 env(pay(g1Bs, a1, g1Bs["HKD"](1000)));
1244 env(pay(g2Sw, a2, g2Sw["HKD"](1000)));
1245 // SnapSwap wants to be able to set trust line quality settings so they
1246 // can charge a fee when transactions ripple across. Liquidity
1247 // provider, via trusting/holding both accounts
1248 env(pay(g1Bs, m1, g1Bs["HKD"](1200)));
1249 env(pay(g2Sw, m1, g2Sw["HKD"](5000)));
1250 env.close();
1251
1252 std::optional<UInt256> domainID;
1253 if (domainEnabled)
1254 domainID = setupDomain(env, {a1, a2, g1Bs, g2Sw, m1});
1255
1256 STPathSet st;
1257 STAmount sa, da;
1258
1259 {
1260 auto const& sendAmt = a2["HKD"](10);
1261 std::tie(st, sa, da) =
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)));
1266 }
1267
1268 {
1269 auto const& sendAmt = a1["HKD"](10);
1270 std::tie(st, sa, da) =
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)));
1275 }
1276
1277 {
1278 auto const& sendAmt = a2["HKD"](10);
1279 std::tie(st, sa, da) =
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)));
1283 BEAST_EXPECT(same(st, stpath(m1, g2Sw)));
1284 }
1285
1286 {
1287 auto const& sendAmt = m1["HKD"](10);
1288 std::tie(st, sa, da) =
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());
1293 }
1294
1295 {
1296 auto const& sendAmt = a1["HKD"](10);
1297 std::tie(st, sa, da) =
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)));
1301 BEAST_EXPECT(same(st, stpath(m1, g1Bs)));
1302 }
1303 }
1304
1305 void
1306 pathFind05(bool const domainEnabled)
1307 {
1308 testcase(
1309 std::string("Path Find: non-XRP -> non-XRP, same currency") +
1310 (domainEnabled ? " w/ " : " w/o ") + "domain");
1311 using namespace jtx;
1312 Env env = pathTestEnv();
1313 Account const a1{"A1"};
1314 Account const a2{"A2"};
1315 Account const a3{"A3"};
1316 Account const a4{"A4"};
1317 Account const g1{"G1"};
1318 Account const g2{"G2"};
1319 Account const g3{"G3"};
1320 Account const g4{"G4"};
1321 Account const m1{"M1"};
1322 Account const m2{"M2"};
1323
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);
1327 env.close();
1328
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);
1336 env.close();
1337
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)));
1345 env.close();
1346
1347 std::optional<UInt256> domainID;
1348 if (domainEnabled)
1349 {
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));
1352 env(offer(m2, XRP(10000), g2["HKD"](1000)), Domain(*domainID));
1353 env(offer(m2, g1["HKD"](1000), XRP(10000)), Domain(*domainID));
1354 }
1355 else
1356 {
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)));
1360 }
1361
1362 STPathSet st;
1363 STAmount sa, da;
1364
1365 {
1366 // A) Borrow or repay --
1367 // Source -> Destination (repay source issuer)
1368 auto const& sendAmt = g1["HKD"](10);
1369 std::tie(st, sa, da) =
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)));
1374 }
1375
1376 {
1377 // A2) Borrow or repay --
1378 // Source -> Destination (repay destination issuer)
1379 auto const& sendAmt = a1["HKD"](10);
1380 std::tie(st, sa, da) =
1381 findPaths(env, a1, g1, sendAmt, std::nullopt, g1["HKD"].currency, domainID);
1382 BEAST_EXPECT(st.empty());
1383 BEAST_EXPECT(equal(da, sendAmt));
1384 BEAST_EXPECT(equal(sa, a1["HKD"](10)));
1385 }
1386
1387 {
1388 // B) Common gateway --
1389 // Source -> AC -> Destination
1390 auto const& sendAmt = a3["HKD"](10);
1391 std::tie(st, sa, da) =
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)));
1395 BEAST_EXPECT(same(st, stpath(g1)));
1396 }
1397
1398 {
1399 // C) Gateway to gateway --
1400 // Source -> OB -> Destination
1401 auto const& sendAmt = g2["HKD"](10);
1402 std::tie(st, sa, da) =
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)));
1406 BEAST_EXPECT(same(
1407 st,
1408 stpath(ipe(g2["HKD"])),
1409 stpath(m1),
1410 stpath(m2),
1411 stpath(ipe(xrpIssue()), ipe(g2["HKD"]))));
1412 }
1413
1414 {
1415 // D) User to unlinked gateway via order book --
1416 // Source -> AC -> OB -> Destination
1417 auto const& sendAmt = g2["HKD"](10);
1418 std::tie(st, sa, da) =
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)));
1422 BEAST_EXPECT(same(
1423 st,
1424 stpath(g1, m1),
1425 stpath(g1, m2),
1426 stpath(g1, ipe(g2["HKD"])),
1427 stpath(g1, ipe(xrpIssue()), ipe(g2["HKD"]))));
1428 }
1429
1430 {
1431 // I4) XRP bridge" --
1432 // Source -> AC -> OB to XRP -> OB from XRP -> AC ->
1433 // Destination
1434 auto const& sendAmt = a2["HKD"](10);
1435 std::tie(st, sa, da) =
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)));
1439 BEAST_EXPECT(same(
1440 st,
1441 stpath(g1, m1, g2),
1442 stpath(g1, m2, g2),
1443 stpath(g1, ipe(g2["HKD"]), g2),
1444 stpath(g1, ipe(xrpIssue()), ipe(g2["HKD"]), g2)));
1445 }
1446 }
1447
1448 void
1449 pathFind06(bool const domainEnabled)
1450 {
1451 testcase(
1452 std::string("Path Find: non-XRP -> non-XRP, same currency)") +
1453 (domainEnabled ? " w/ " : " w/o ") + "domain");
1454 using namespace jtx;
1455 Env env = pathTestEnv();
1456 Account const a1{"A1"};
1457 Account const a2{"A2"};
1458 Account const a3{"A3"};
1459 Account const g1{"G1"};
1460 Account const g2{"G2"};
1461 Account const m1{"M1"};
1462
1463 env.fund(XRP(11000), m1);
1464 env.fund(XRP(1000), a1, a2, a3, g1, g2);
1465 env.close();
1466
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);
1472 env.close();
1473
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)));
1478 env.close();
1479
1480 std::optional<UInt256> domainID;
1481 if (domainEnabled)
1482 {
1483 domainID = setupDomain(env, {a1, a2, a3, g1, g2, m1});
1484 env(offer(m1, g1["HKD"](1000), g2["HKD"](1000)), Domain(*domainID));
1485 }
1486 else
1487 {
1488 env(offer(m1, g1["HKD"](1000), g2["HKD"](1000)));
1489 }
1490
1491 // E) Gateway to user
1492 // Source -> OB -> AC -> Destination
1493 auto const& sendAmt = a2["HKD"](10);
1494 STPathSet st;
1495 STAmount sa, da;
1496 std::tie(st, sa, da) =
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)));
1500 BEAST_EXPECT(same(st, stpath(m1, g2), stpath(ipe(g2["HKD"]), g2)));
1501 }
1502
1503 void
1504 receiveMax(bool const domainEnabled)
1505 {
1506 testcase(std::string("Receive max") + (domainEnabled ? " w/ " : " w/o ") + "domain");
1507
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"];
1514 {
1515 // XRP -> IOU receive max
1516 Env env = pathTestEnv();
1517 env.fund(XRP(10000), alice, bob, charlie, gw);
1518 env.close();
1519 env.trust(usd(100), alice, bob, charlie);
1520 env.close();
1521 env(pay(gw, charlie, usd(10)));
1522 env.close();
1523
1524 std::optional<UInt256> domainID;
1525 if (domainEnabled)
1526 {
1527 domainID = setupDomain(env, {alice, bob, charlie, gw});
1528 env(offer(charlie, XRP(10), usd(10)), Domain(*domainID));
1529 env.close();
1530 }
1531 else
1532 {
1533 env(offer(charlie, XRP(10), usd(10)));
1534 env.close();
1535 }
1536
1537 auto [st, sa, da] =
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))
1542 {
1543 auto const& pathElem = st[0][0];
1544 BEAST_EXPECT(
1545 pathElem.isOffer() && pathElem.getIssuerID() == gw.id() &&
1546 pathElem.getCurrency() == usd.currency);
1547 }
1548 }
1549 {
1550 // IOU -> XRP receive max
1551 Env env = pathTestEnv();
1552 env.fund(XRP(10000), alice, bob, charlie, gw);
1553 env.close();
1554 env.trust(usd(100), alice, bob, charlie);
1555 env.close();
1556 env(pay(gw, alice, usd(10)));
1557 env.close();
1558
1559 std::optional<UInt256> domainID;
1560 if (domainEnabled)
1561 {
1562 domainID = setupDomain(env, {alice, bob, charlie, gw});
1563 env(offer(charlie, usd(10), XRP(10)), Domain(*domainID));
1564 env.close();
1565 }
1566 else
1567 {
1568 env(offer(charlie, usd(10), XRP(10)));
1569 env.close();
1570 }
1571
1572 auto [st, sa, da] =
1573 findPaths(env, alice, bob, drops(-1), usd(100).value(), std::nullopt, domainID);
1574 BEAST_EXPECT(sa == usd(10));
1575 BEAST_EXPECT(equal(da, XRP(10)));
1576 if (BEAST_EXPECT(st.size() == 1 && st[0].size() == 1))
1577 {
1578 auto const& pathElem = st[0][0];
1579 BEAST_EXPECT(
1580 pathElem.isOffer() && pathElem.getIssuerID() == xrpAccount() &&
1581 pathElem.getCurrency() == xrpCurrency());
1582 }
1583 }
1584 }
1585
1586 void
1588 {
1589 using namespace jtx;
1590 // This test will create trust lines with various values of the noRipple
1591 // flag. alice_ <-> george <-> bob_ george will sort of act like a
1592 // gateway, but use a different name to avoid the usual assumptions
1593 // about gateways.
1594 auto const alice = Account("alice");
1595 auto const bob = Account("bob");
1596 auto const george = Account("george");
1597 auto const usd = george["USD"];
1598 auto const test = [&](std::string casename,
1599 bool aliceRipple,
1600 bool bobRipple,
1601 bool expectPath) {
1602 testcase(casename);
1603
1604 Env env = pathTestEnv();
1605 env.fund(XRP(10000), noripple(alice, bob, george));
1606 env.close();
1607 // Set the same flags at both ends of the trustline, even though
1608 // only george's matter.
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));
1613 env.close();
1614 env(pay(george, alice, usd(70)));
1615 env.close();
1616
1617 auto [st, sa, da] = findPaths(env, "alice", "bob", Account("bob")["USD"](5));
1618 BEAST_EXPECT(equal(da, bob["USD"](5)));
1619
1620 if (expectPath)
1621 {
1622 BEAST_EXPECT(st.size() == 1);
1623 BEAST_EXPECT(same(st, stpath("george")));
1624 BEAST_EXPECT(equal(sa, alice["USD"](5)));
1625 }
1626 else
1627 {
1628 BEAST_EXPECT(st.empty());
1629 BEAST_EXPECT(equal(sa, XRP(0)));
1630 }
1631 };
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);
1636 }
1637
1638 void
1640 {
1641 testcase("Hybrid offer path");
1642 using namespace jtx;
1643
1644 // test cases copied from path_find_05 and ensures path results for
1645 // different combinations of open/domain/hybrid offers. `func` is a
1646 // lambda param that creates different types of offers
1647 auto const testPathfind = [&](auto func, bool const domainEnabled = false) {
1648 Env env = pathTestEnv();
1649 Account const a1{"A1"};
1650 Account const a2{"A2"};
1651 Account const a3{"A3"};
1652 Account const a4{"A4"};
1653 Account const g1{"G1"};
1654 Account const g2{"G2"};
1655 Account const g3{"G3"};
1656 Account const g4{"G4"};
1657 Account const m1{"M1"};
1658 Account const m2{"M2"};
1659
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);
1663 env.close();
1664
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);
1672 env.close();
1673
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)));
1681 env.close();
1682
1683 std::optional<UInt256> domainID =
1684 setupDomain(env, {a1, a2, a3, a4, g1, g2, g3, g4, m1, m2});
1685 BEAST_EXPECT(domainID);
1686
1687 func(env, m1, m2, g1, g2, *domainID);
1688
1689 STPathSet st;
1690 STAmount sa, da;
1691
1692 {
1693 // A) Borrow or repay --
1694 // Source -> Destination (repay source issuer)
1695 auto const& sendAmt = g1["HKD"](10);
1696 std::tie(st, sa, da) = findPaths(
1697 env,
1698 a1,
1699 g1,
1700 sendAmt,
1701 std::nullopt,
1702 g1["HKD"].currency,
1703 domainEnabled ? domainID : std::nullopt);
1704 BEAST_EXPECT(st.empty());
1705 BEAST_EXPECT(equal(da, sendAmt));
1706 BEAST_EXPECT(equal(sa, a1["HKD"](10)));
1707 }
1708
1709 {
1710 // A2) Borrow or repay --
1711 // Source -> Destination (repay destination issuer)
1712 auto const& sendAmt = a1["HKD"](10);
1713 std::tie(st, sa, da) = findPaths(
1714 env,
1715 a1,
1716 g1,
1717 sendAmt,
1718 std::nullopt,
1719 g1["HKD"].currency,
1720 domainEnabled ? domainID : std::nullopt);
1721 BEAST_EXPECT(st.empty());
1722 BEAST_EXPECT(equal(da, sendAmt));
1723 BEAST_EXPECT(equal(sa, a1["HKD"](10)));
1724 }
1725
1726 {
1727 // B) Common gateway --
1728 // Source -> AC -> Destination
1729 auto const& sendAmt = a3["HKD"](10);
1730 std::tie(st, sa, da) = findPaths(
1731 env,
1732 a1,
1733 a3,
1734 sendAmt,
1735 std::nullopt,
1736 g1["HKD"].currency,
1737 domainEnabled ? domainID : std::nullopt);
1738 BEAST_EXPECT(equal(da, sendAmt));
1739 BEAST_EXPECT(equal(sa, a1["HKD"](10)));
1740 BEAST_EXPECT(same(st, stpath(g1)));
1741 }
1742
1743 {
1744 // C) Gateway to gateway --
1745 // Source -> OB -> Destination
1746 auto const& sendAmt = g2["HKD"](10);
1747 std::tie(st, sa, da) = findPaths(
1748 env,
1749 g1,
1750 g2,
1751 sendAmt,
1752 std::nullopt,
1753 g1["HKD"].currency,
1754 domainEnabled ? domainID : std::nullopt);
1755 BEAST_EXPECT(equal(da, sendAmt));
1756 BEAST_EXPECT(equal(sa, g1["HKD"](10)));
1757 BEAST_EXPECT(same(
1758 st,
1759 stpath(ipe(g2["HKD"])),
1760 stpath(m1),
1761 stpath(m2),
1762 stpath(ipe(xrpIssue()), ipe(g2["HKD"]))));
1763 }
1764
1765 {
1766 // D) User to unlinked gateway via order book --
1767 // Source -> AC -> OB -> Destination
1768 auto const& sendAmt = g2["HKD"](10);
1769 std::tie(st, sa, da) = findPaths(
1770 env,
1771 a1,
1772 g2,
1773 sendAmt,
1774 std::nullopt,
1775 g1["HKD"].currency,
1776 domainEnabled ? domainID : std::nullopt);
1777 BEAST_EXPECT(equal(da, sendAmt));
1778 BEAST_EXPECT(equal(sa, a1["HKD"](10)));
1779 BEAST_EXPECT(same(
1780 st,
1781 stpath(g1, m1),
1782 stpath(g1, m2),
1783 stpath(g1, ipe(g2["HKD"])),
1784 stpath(g1, ipe(xrpIssue()), ipe(g2["HKD"]))));
1785 }
1786
1787 {
1788 // I4) XRP bridge" --
1789 // Source -> AC -> OB to XRP -> OB from XRP -> AC ->
1790 // Destination
1791 auto const& sendAmt = a2["HKD"](10);
1792 std::tie(st, sa, da) = findPaths(
1793 env,
1794 a1,
1795 a2,
1796 sendAmt,
1797 std::nullopt,
1798 g1["HKD"].currency,
1799 domainEnabled ? domainID : std::nullopt);
1800 BEAST_EXPECT(equal(da, sendAmt));
1801 BEAST_EXPECT(equal(sa, a1["HKD"](10)));
1802 BEAST_EXPECT(same(
1803 st,
1804 stpath(g1, m1, g2),
1805 stpath(g1, m2, g2),
1806 stpath(g1, ipe(g2["HKD"]), g2),
1807 stpath(g1, ipe(xrpIssue()), ipe(g2["HKD"]), g2)));
1808 }
1809 };
1810
1811 // the following tests exercise different combinations of open/hybrid
1812 // offers to make sure that hybrid offers work in pathfinding for open
1813 // order book
1814 {
1815 testPathfind(
1816 [](Env& env, Account m1, Account m2, Account g1, Account g2, UInt256 domainID) {
1817 env(offer(m1, g1["HKD"](1000), g2["HKD"](1000)),
1818 Domain(domainID),
1819 Txflags(tfHybrid));
1820 env(offer(m2, XRP(10000), g2["HKD"](1000)));
1821 env(offer(m2, g1["HKD"](1000), XRP(10000)));
1822 });
1823
1824 testPathfind(
1825 [](Env& env, Account m1, Account m2, Account g1, Account g2, UInt256 domainID) {
1826 env(offer(m1, g1["HKD"](1000), g2["HKD"](1000)),
1827 Domain(domainID),
1828 Txflags(tfHybrid));
1829 env(offer(m2, XRP(10000), g2["HKD"](1000)),
1830 Domain(domainID),
1831 Txflags(tfHybrid));
1832 env(offer(m2, g1["HKD"](1000), XRP(10000)));
1833 });
1834
1835 testPathfind(
1836 [](Env& env, Account m1, Account m2, Account g1, Account g2, UInt256 domainID) {
1837 env(offer(m1, g1["HKD"](1000), g2["HKD"](1000)),
1838 Domain(domainID),
1839 Txflags(tfHybrid));
1840 env(offer(m2, XRP(10000), g2["HKD"](1000)),
1841 Domain(domainID),
1842 Txflags(tfHybrid));
1843 env(offer(m2, g1["HKD"](1000), XRP(10000)),
1844 Domain(domainID),
1845 Txflags(tfHybrid));
1846 });
1847
1848 testPathfind(
1849 [](Env& env, Account m1, Account m2, Account g1, Account g2, UInt256 domainID) {
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)),
1853 Domain(domainID),
1854 Txflags(tfHybrid));
1855 });
1856
1857 testPathfind(
1858 [](Env& env, Account m1, Account m2, Account g1, Account g2, UInt256 domainID) {
1859 env(offer(m1, g1["HKD"](1000), g2["HKD"](1000)));
1860 env(offer(m2, XRP(10000), g2["HKD"](1000)),
1861 Domain(domainID),
1862 Txflags(tfHybrid));
1863 env(offer(m2, g1["HKD"](1000), XRP(10000)),
1864 Domain(domainID),
1865 Txflags(tfHybrid));
1866 });
1867 }
1868
1869 // the following tests exercise different combinations of domain/hybrid
1870 // offers to make sure that hybrid offers work in pathfinding for domain
1871 // order book
1872 {
1873 testPathfind(
1874 [](Env& env, Account m1, Account m2, Account g1, Account g2, UInt256 domainID) {
1875 env(offer(m1, g1["HKD"](1000), g2["HKD"](1000)),
1876 Domain(domainID),
1877 Txflags(tfHybrid));
1878 env(offer(m2, XRP(10000), g2["HKD"](1000)), Domain(domainID));
1879 env(offer(m2, g1["HKD"](1000), XRP(10000)), Domain(domainID));
1881 true);
1882
1883 testPathfind(
1884 [](Env& env, Account m1, Account m2, Account g1, Account g2, UInt256 domainID) {
1885 env(offer(m1, g1["HKD"](1000), g2["HKD"](1000)),
1886 Domain(domainID),
1887 Txflags(tfHybrid));
1888 env(offer(m2, XRP(10000), g2["HKD"](1000)),
1889 Domain(domainID),
1890 Txflags(tfHybrid));
1891 env(offer(m2, g1["HKD"](1000), XRP(10000)), Domain(domainID));
1892 },
1893 true);
1894
1895 testPathfind(
1896 [](Env& env, Account m1, Account m2, Account g1, Account g2, UInt256 domainID) {
1897 env(offer(m1, g1["HKD"](1000), g2["HKD"](1000)), Domain(domainID));
1898 env(offer(m2, XRP(10000), g2["HKD"](1000)), Domain(domainID));
1899 env(offer(m2, g1["HKD"](1000), XRP(10000)),
1900 Domain(domainID),
1901 Txflags(tfHybrid));
1902 },
1903 true);
1904
1905 testPathfind(
1906 [](Env& env, Account m1, Account m2, Account g1, Account g2, UInt256 domainID) {
1907 env(offer(m1, g1["HKD"](1000), g2["HKD"](1000)), Domain(domainID));
1908 env(offer(m2, XRP(10000), g2["HKD"](1000)),
1909 Domain(domainID),
1910 Txflags(tfHybrid));
1911 env(offer(m2, g1["HKD"](1000), XRP(10000)),
1912 Domain(domainID),
1913 Txflags(tfHybrid));
1914 },
1915 true);
1916 }
1917 }
1918
1919 void
1921 {
1922 testcase("AMM not used in domain path");
1923 using namespace jtx;
1924 Env env = pathTestEnv();
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));
1928
1929 STPathSet st;
1930 STAmount sa, da;
1931
1932 auto const& sendAmt = XRP(1);
1933
1934 // doing pathfind with domain won't include amm
1935 std::tie(st, sa, da) =
1936 findPaths(env, bob, carol, sendAmt, std::nullopt, usd.currency, domainID);
1937 BEAST_EXPECT(st.empty());
1938
1939 // a non-domain pathfind returns amm in the path
1940 std::tie(st, sa, da) = findPaths(env, bob, carol, sendAmt, std::nullopt, usd.currency);
1941 BEAST_EXPECT(same(st, stpath(gw, ipe(xrpIssue()))));
1942 }
1943
1944 void
1946 {
1947 testcase("STPathSet::assembleAdd deduplication — O(N^2) regression");
1948
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";
1957
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};
1966
1967 auto ps = STPathSet{STPathSet::DeduplicationTag{}};
1968
1969 auto const createPathElements = [](auto const& account1, auto const& account2) {
1970 auto base = STPath{};
1971 base.pushBack(
1972 STPathElement{STPathElement::TypeAccount, account1, xrpCurrency(), account1});
1973 auto const tail =
1974 STPathElement{STPathElement::TypeAccount, account2, xrpCurrency(), account2};
1975 return std::make_pair(base, tail);
1976 };
1978 {
1979 auto [base, tail] = createPathElements(kAccountID1, kAccountID2);
1980
1981 for (auto i = 0uz; i < 10000; ++i)
1982 {
1983 ps.assembleAdd(base, tail);
1984 }
1985
1986 BEAST_EXPECT(ps.size() == 1);
1987 }
1988
1989 {
1990 auto [base, tail] = createPathElements(kAccountID3, kAccountID4);
1991 ps.assembleAdd(base, tail);
1992 }
1993
1994 {
1995 auto [base, tail] = createPathElements(kAccountID5, kAccountID6);
1996 ps.assembleAdd(base, tail);
1997 }
1998
1999 {
2000 auto [base, tail] = createPathElements(kAccountID7, kAccountID8);
2001
2002 auto const before = ps.size();
2003
2004 for (auto i = 0uz; i < 10000; ++i)
2005 {
2006 ps.assembleAdd(base, tail);
2007 }
2008
2009 BEAST_EXPECT(ps.size() - before == 1);
2010 }
2011
2012 {
2013 auto [base, tail] = createPathElements(kAccountID1, kAccountID3);
2014 auto copy = base;
2015 copy.pushBack(tail);
2016
2017 auto const before = ps.size();
2018
2019 ps.pushBack(copy);
2020 ps.assembleAdd(base, tail);
2021
2022 BEAST_EXPECT(ps.size() - before == 1);
2023 }
2024
2025 {
2026 auto [base, tail] = createPathElements(kAccountID2, kAccountID4);
2027 auto copy = base;
2028 copy.pushBack(tail);
2029
2030 auto const before = ps.size();
2031
2032 ps.emplaceBack(copy);
2033 ps.assembleAdd(base, tail);
2034
2035 BEAST_EXPECT(ps.size() - before == 1);
2036 }
2037
2038 BEAST_EXPECT(ps.size() == 6);
2039 }
2040
2041 void
2043 {
2044 testcase("STPathSet::pushBack/emplaceBack deduplication");
2045
2046 // pushBack and emplaceBack reject duplicates on a set built with the
2047 // DeduplicationTag, and append unconditionally without it. Both
2048 // report which happened. The unconditional case is the one the wire
2049 // and JSON paths rely on: collapsing duplicates there would change the
2050 // signed content of a transaction.
2051
2052 static constexpr AccountID kAccountID1{"A3F19C7B2E5D08146FB93A7C0E2D5184BC6F3A09"};
2053 static constexpr AccountID kAccountID2{"1D7E4B90C2A6F3851E0B9D47A2C5F8136E0A4B7D"};
2054 static constexpr AccountID kAccountID3{"F08C36A1D95E27B40CA1F63E8D204B7950E1C3A6"};
2055
2056 auto const makePath = [](AccountID const& account) {
2057 auto p = STPath{};
2058 p.pushBack(STPathElement{STPathElement::TypeAccount, account, xrpCurrency(), account});
2059 return p;
2060 };
2061
2062 auto const first = makePath(kAccountID1);
2063 auto const second = makePath(kAccountID2);
2064 auto const third = makePath(kAccountID3);
2065
2066 // Deduplicating set: the second insert of a path is rejected, and the
2067 // rejection is reported rather than silently swallowed.
2068 {
2069 auto ps = STPathSet{STPathSet::DeduplicationTag{}};
2070
2071 BEAST_EXPECT(ps.pushBack(first));
2072 BEAST_EXPECT(ps.size() == 1);
2073
2074 BEAST_EXPECT(!ps.pushBack(first));
2075 BEAST_EXPECT(ps.size() == 1);
2076
2077 // emplaceBack sees paths registered by pushBack...
2078 BEAST_EXPECT(!ps.emplaceBack(first));
2079 BEAST_EXPECT(ps.size() == 1);
2080
2081 BEAST_EXPECT(ps.emplaceBack(second));
2082 BEAST_EXPECT(ps.size() == 2);
2083
2084 // ...and pushBack sees paths registered by emplaceBack.
2085 BEAST_EXPECT(!ps.pushBack(second));
2086 BEAST_EXPECT(ps.size() == 2);
2087
2088 // emplaceBack's forwarding form registers the same way.
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);
2093
2094 // A rejected duplicate must not disturb what is already stored.
2095 BEAST_EXPECT(ps[0] == first);
2096 BEAST_EXPECT(ps[1] == second);
2097 BEAST_EXPECT(ps[2] == third);
2098 }
2099
2100 // Without the tag there is no index, so duplicates are appended and
2101 // both methods report success every time.
2102 {
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);
2108
2109 auto named = STPathSet{sfPaths};
2110 BEAST_EXPECT(named.pushBack(first));
2111 BEAST_EXPECT(named.pushBack(first));
2112 BEAST_EXPECT(named.size() == 2);
2113 }
2114 }
2115
2116 void
2118 {
2119 testcase("STPathElement hash injectivity");
2120
2121 auto const zeroCurrency =
2122 STPathElement{AccountID{}, PathAsset{Currency{}}, AccountID{}, true};
2123 auto const zeroMPT = STPathElement{AccountID{}, PathAsset{MPTID{}}, AccountID{}, true};
2124
2125 BEAST_EXPECT(!(zeroCurrency == zeroMPT));
2126
2127 auto const path = [](std::vector<STPathElement> const& elements) {
2128 auto p = STPath{};
2129 for (auto const& element : elements)
2130 p.pushBack(element);
2131 return p;
2132 };
2133
2134 auto const currencyFirst = path({zeroCurrency, zeroMPT});
2135 auto const mptFirst = path({zeroMPT, zeroCurrency});
2136
2137 BEAST_EXPECT(!(currencyFirst == mptFirst));
2138
2139 auto const hasher = HardenedHash<>{};
2140 BEAST_EXPECT(hasher(currencyFirst) != hasher(mptFirst));
2141
2142 auto mask = std::vector<int>{0, 0, 1, 1};
2143 auto hashes = std::set<std::size_t>{};
2144 auto orderings = 0uz;
2145 do
2146 {
2147 auto elements = std::vector<STPathElement>{};
2148 for (auto const isMPT : mask)
2149 {
2150 elements.push_back(isMPT != 0 ? zeroMPT : zeroCurrency);
2151 }
2152 hashes.insert(hasher(path(elements)));
2153 ++orderings;
2154 } while (std::ranges::next_permutation(mask).found);
2155
2156 BEAST_EXPECT(orderings == 6);
2157 BEAST_EXPECT(hashes.size() == orderings);
2158
2159 auto seen = HardenedHashSet<STPath>{};
2160 for (auto const& p : {currencyFirst, mptFirst})
2161 {
2162 seen.emplace(p);
2163 }
2164 BEAST_EXPECT(seen.size() == 2);
2165
2166 // The other half of the invariant: equal elements must hash equally.
2167 // STPathElement::operator== masks type_ down to the TypeAccount bit, so
2168 // elements whose remaining type bits differ still compare equal --
2169 // hashing the full type_ would give them distinct hashes and silently
2170 // defeat deduplication.
2171 static constexpr AccountID kAccount{"A3F19C7B2E5D08146FB93A7C0E2D5184BC6F3A09"};
2172 static constexpr AccountID kIssuer{"1D7E4B90C2A6F3851E0B9D47A2C5F8136E0A4B7D"};
2173
2174 auto const equivalent = std::vector<std::pair<STPathElement, STPathElement>>{
2175 // forceAsset toggles TypeCurrency on an XRP asset.
2176 {
2177 STPathElement{kAccount, PathAsset{xrpCurrency()}, kIssuer, true},
2178 STPathElement{kAccount, PathAsset{xrpCurrency()}, kIssuer, false},
2179 },
2180 // An explicit type mask vs. one derived from the populated fields.
2181 {
2182 STPathElement{STPathElement::TypeAccount, kAccount, xrpCurrency(), kIssuer},
2183 STPathElement{kAccount, PathAsset{xrpCurrency()}, kIssuer, false},
2184 },
2185 };
2186
2187 for (auto const& [lhs, rhs] : equivalent)
2188 {
2189 BEAST_EXPECT(lhs.getNodeType() != rhs.getNodeType());
2190 BEAST_EXPECT(lhs == rhs);
2191
2192 auto const lhsPath = path({lhs});
2193 auto const rhsPath = path({rhs});
2194 BEAST_EXPECT(hasher(lhsPath) == hasher(rhsPath));
2195
2197 equal.emplace(lhsPath);
2198 equal.emplace(rhsPath);
2199 BEAST_EXPECT(equal.size() == 1);
2200 }
2201 }
2202
2203 void
2205 {
2206 testcase("STPathSet deserialization preserves duplicate paths");
2207
2208 // The `Paths` field of a signed transaction must round-trip byte for
2209 // byte. The deduplication index exists solely for pathfinding, so the
2210 // deserializing constructor must never engage it: collapsing duplicates
2211 // on parse would silently change the signed content of a transaction.
2212
2213 static constexpr AccountID kAccountID1{"A3F19C7B2E5D08146FB93A7C0E2D5184BC6F3A09"};
2214 static constexpr AccountID kAccountID2{"1D7E4B90C2A6F3851E0B9D47A2C5F8136E0A4B7D"};
2215
2216 auto const element =
2217 STPathElement{kAccountID1, PathAsset{xrpCurrency()}, kAccountID2, true};
2218
2219 auto path = STPath{};
2220 path.pushBack(element);
2221
2222 static constexpr auto kDuplicates = 64uz;
2223
2224 auto original = STPathSet{sfPaths};
2225 for (auto i = 0uz; i < kDuplicates; ++i)
2226 {
2227 original.pushBack(path);
2228 }
2229
2230 // No index was requested, so nothing is deduplicated on the way in.
2231 BEAST_EXPECT(original.size() == kDuplicates);
2232
2233 auto s = Serializer{};
2234 original.add(s);
2235
2236 auto sit = SerialIter{s.slice()};
2237 auto const parsed = STPathSet{sit, sfPaths};
2238
2239 // The duplicates survive the round trip...
2240 BEAST_EXPECT(parsed.size() == kDuplicates);
2241 BEAST_EXPECT(parsed.isEquivalent(original));
2242
2243 // ...and re-serializing reproduces the original bytes exactly.
2244 auto serialized = Serializer{};
2245 parsed.add(serialized);
2246 BEAST_EXPECT(serialized.getData() == s.getData());
2247
2248 // A parsed set holds no index, so appending to it stays append-only.
2249 auto appended = parsed;
2250 appended.pushBack(path);
2251 BEAST_EXPECT(appended.size() == kDuplicates + 1);
2252 }
2253
2254 void
2255 run() override
2256 {
2274
2275 for (bool const domainEnabled : {false, true})
2276 {
2277 pathFind(domainEnabled);
2278 pathFindConsumeAll(domainEnabled);
2279 alternativePathConsumeBoth(domainEnabled);
2282 issuesPathNegativeIssue(domainEnabled);
2283 viaOffersViaGateway(domainEnabled);
2284 xrpToXrp(domainEnabled);
2285 receiveMax(domainEnabled);
2286
2287 // The following path_find_NN tests are data driven tests
2288 // that were originally implemented in js/coffee and migrated
2289 // here. The quantities and currencies used are taken directly from
2290 // those legacy tests, which in some cases probably represented
2291 // customer use cases.
2292
2293 pathFind01(domainEnabled);
2294 pathFind02(domainEnabled);
2295 pathFind04(domainEnabled);
2296 pathFind05(domainEnabled);
2297 pathFind06(domainEnabled);
2298 }
2299
2301 ammDomainPath();
2302 }
2303};
2304
2306
2307} // namespace xrpl::test
A testsuite class.
Definition suite.h:52
TestcaseT testcase
Memberspace for declaring test cases.
Definition suite.h:155
Unserialize a JSON document into a Value.
Definition json_reader.h:20
bool parse(std::string const &document, Value &root)
Read a Value from a JSON document.
Represents a JSON value.
Definition json_value.h:121
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.
bool empty() const
Definition STPathSet.h:630
A consumption charge.
Definition Charge.h:13
An endpoint that consumes resources.
Definition Consumer.h:20
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 pathFind05(bool const domainEnabled)
void viaOffersViaGateway(bool const domainEnabled)
void trustAutoClearTrustNormalClear()
void alternativePathConsumeBoth(bool const domainEnabled)
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 noDirectPathNoIntermediaryNoAlternatives()
void sourceCurrencyIssuerSelection()
void qualityPathsQualitySetAndTest()
void pathFind(bool const domainEnabled)
void pathFindConsumeAll(bool const domainEnabled)
void trustAutoClearTrustAutoClear()
void alternativePathsConsumeBestTransfer(bool const domainEnabled)
Immutable cryptographic account descriptor.
Definition jtx/Account.h:21
A balance matches.
Definition balance.h:24
A transaction testing environment.
Definition Env.h:161
Application & app()
Definition Env.h:300
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
Definition Env.cpp:133
SLE::const_pointer le(Account const &account) const
Return an account root.
Definition Env.cpp:311
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Definition Env.cpp:323
void trust(STAmount const &amount, Account const &account)
Establish trust lines.
Definition Env.cpp:354
beast::Journal const journal
Definition Env.h:204
void require(Args const &... args)
Check a set of requirements.
Definition Env.h:766
Inject raw JSON.
Definition jtx_json.h:16
Add a path.
Definition paths.h:47
Set Paths, SendMax on a JTx.
Definition paths.h:23
Sets the SendMax on a JTx.
Definition sendmax.h:16
Set the expected result code for a JTx The test will fail if the code doesn't match.
Definition ter.h:18
Set the flags on a JTx.
Definition txflags.h:14
T copy(T... args)
T insert(T... args)
T make_pair(T... args)
T make_tuple(T... args)
@ Array
array value (ordered list)
Definition json_value.h:32
@ Object
object value (collection of name/value pairs).
Definition json_value.h:33
Keylet amm(Asset const &issue1, Asset const &issue2) noexcept
AMM entry.
Definition Indexes.cpp:483
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:233
Keylet trustLine(AccountID const &id0, AccountID const &id1, Currency const &currency) noexcept
The index of a trust line for a given currency.
Definition Indexes.cpp:287
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
Definition ApiVersion.h:34
::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.
Definition pay.cpp:14
XrpT const XRP
Converts to XRP Issue or STAmount.
Definition amount.cpp:92
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.
Definition Env.h:86
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.
Definition offer.cpp:14
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
Definition envconfig.h:38
json::Value trust(Account const &account, STAmount const &amount, std::uint32_t flags)
Modify a trust line.
Definition trust.cpp:18
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.
Definition rate.cpp:15
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
json::Value rpf(jtx::Account const &src, jtx::Account const &dst, std::uint32_t numSrc)
Definition Path_test.cpp:71
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
Issue const & xrpIssue()
Returns an asset specifier that represents XRP.
Definition Issue.h:108
std::unordered_set< Value, Hash, Pred, Allocator > HardenedHashSet
@ RpcInternal
Definition ErrorCodes.h:113
@ RpcSrcCurMalformed
Definition ErrorCodes.h:107
BaseUInt< 256 > Domain
Domain is a 256-bit hash representing a specific domain.
Definition UintTypes.h:59
SField const sfGeneric
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition AccountID.cpp:95
BaseUInt< 160, detail::CurrencyTag > Currency
Currency is a hash representing a specific currency.
Definition UintTypes.h:42
Currency const & xrpCurrency()
XRP currency.
Definition UintTypes.cpp:99
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition base_uint.h:658
@ USER
Definition Role.h:27
BaseUInt< 256 > UInt256
Definition base_uint.h:581
@ JtClient
Definition Job.h:31
BaseUInt< 192 > MPTID
MPTID is a 192-bit value representing MPT Issuance ID, which is a concatenation of a 32-bit sequence ...
Definition UintTypes.h:54
STAmount amountFromJson(SField const &name, json::Value const &v)
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
AccountID const & xrpAccount()
Compute AccountID from public key.
@ tecPATH_DRY
Definition TER.h:305
T next_permutation(T... args)
std::shared_ptr< JobQueue::Coro > coro
Definition Context.h:35
json::Value params
Definition Context.h:51
T tie(T... args)
T to_string(T... args)