xrpld
Loading...
Searching...
No Matches
TestHelpers.cpp
1#include <test/jtx/TestHelpers.h>
2
3#include <test/jtx/Account.h>
4#include <test/jtx/Env.h>
5#include <test/jtx/amount.h>
6#include <test/jtx/balance.h> // IWYU pragma: keep
7#include <test/jtx/envconfig.h>
8#include <test/jtx/mpt.h>
9#include <test/jtx/offer.h>
10#include <test/jtx/owners.h>
11#include <test/jtx/rate.h>
12#include <test/jtx/trust.h>
13
14#include <xrpld/core/Config.h>
15#include <xrpld/rpc/RPCHandler.h>
16#include <xrpld/rpc/Role.h>
17
18#include <xrpl/basics/Number.h>
19#include <xrpl/basics/base_uint.h>
20#include <xrpl/basics/chrono.h>
21#include <xrpl/basics/contract.h>
22#include <xrpl/beast/unit_test/suite.h>
23#include <xrpl/beast/utility/instrumentation.h>
24#include <xrpl/core/Job.h>
25#include <xrpl/core/ServiceRegistry.h>
26#include <xrpl/json/json_value.h>
27#include <xrpl/json/to_string.h>
28#include <xrpl/ledger/helpers/DirectoryHelpers.h>
29#include <xrpl/protocol/AccountID.h>
30#include <xrpl/protocol/ApiVersion.h>
31#include <xrpl/protocol/Book.h>
32#include <xrpl/protocol/Indexes.h>
33#include <xrpl/protocol/Issue.h>
34#include <xrpl/protocol/LedgerFormats.h>
35#include <xrpl/protocol/MPTIssue.h>
36#include <xrpl/protocol/PathAsset.h>
37#include <xrpl/protocol/Quality.h>
38#include <xrpl/protocol/SField.h>
39#include <xrpl/protocol/STAmount.h>
40#include <xrpl/protocol/STParsedJSON.h>
41#include <xrpl/protocol/STPathSet.h>
42#include <xrpl/protocol/UintTypes.h>
43#include <xrpl/protocol/XRPAmount.h>
44#include <xrpl/protocol/jss.h>
45#include <xrpl/resource/Charge.h>
46#include <xrpl/resource/Consumer.h>
47#include <xrpl/resource/Fees.h>
48#include <xrpl/tx/paths/detail/Steps.h>
49
50#include <algorithm>
51#include <cstddef>
52#include <cstdint>
53#include <memory>
54#include <optional>
55#include <stdexcept>
56#include <tuple>
57#include <utility>
58#include <variant>
59#include <vector>
60
61namespace xrpl::test::jtx {
62
63// Functions used in debugging
64json::Value
65getAccountOffers(Env& env, AccountID const& acct, bool current)
66{
67 json::Value jv;
68 jv[jss::account] = to_string(acct);
69 return env.rpc("json", "account_offers", to_string(jv))[jss::result];
70}
71
73getAccountLines(Env& env, AccountID const& acctId)
74{
75 json::Value jv;
76 jv[jss::account] = to_string(acctId);
77 return env.rpc("json", "account_lines", to_string(jv))[jss::result];
78}
79
80bool
81checkArraySize(json::Value const& val, unsigned int size)
82{
83 return val.isArray() && val.size() == size;
84}
85
87ownerCount(Env const& env, Account const& account)
88{
89 return env.ownerCount(account);
90}
91
92/* Token (IOU/MPT) Locking */
93/******************************************************************************/
94uint64_t
95mptEscrowed(jtx::Env const& env, jtx::Account const& account, jtx::MPT const& mpt)
96{
97 auto const sle = env.le(keylet::mptoken(mpt.mpt(), account));
98 if (sle && sle->isFieldPresent(sfLockedAmount))
99 return (*sle)[sfLockedAmount];
100 return 0;
101}
102
103uint64_t
104issuerMPTEscrowed(jtx::Env const& env, jtx::MPT const& mpt)
105{
106 auto const sle = env.le(keylet::mptokenIssuance(mpt.mpt()));
107 if (sle && sle->isFieldPresent(sfLockedAmount))
108 return (*sle)[sfLockedAmount];
109 return 0;
110}
111
113issuerBalance(jtx::Env& env, jtx::Account const& account, Issue const& issue)
114{
115 json::Value params;
116 params[jss::account] = account.human();
117 auto jrr = env.rpc("json", "gateway_balances", to_string(params));
118 auto const result = jrr[jss::result];
119 auto const obligations = result[jss::obligations][to_string(issue.currency)];
120 if (obligations.isNull())
121 return {STAmount(issue, 0), account.name()};
122 STAmount const amount = amountFromString(issue, obligations.asString());
123 return {amount, account.name()};
124}
125
127issuerEscrowed(jtx::Env& env, jtx::Account const& account, Issue const& issue)
128{
129 json::Value params;
130 params[jss::account] = account.human();
131 auto jrr = env.rpc("json", "gateway_balances", to_string(params));
132 auto const result = jrr[jss::result];
133 auto const locked = result[jss::locked][to_string(issue.currency)];
134 if (locked.isNull())
135 return {STAmount(issue, 0), account.name()};
136 STAmount const amount = amountFromString(issue, locked.asString());
137 return {amount, account.name()};
138}
139
141sponsoredOwnerCount(Env const& env, Account const& account)
142{
143 return env.sponsoredOwnerCount(account);
144}
145
147sponsoringOwnerCount(Env const& env, Account const& account)
148{
149 return env.sponsoringOwnerCount(account);
150}
151
153sponsoringAccountCount(Env const& env, Account const& account)
154{
155 return env.sponsoringAccountCount(account);
156}
157
158/* Path finding */
159/******************************************************************************/
160void
161stpathAppendOne(STPath& st, Account const& account)
162{
163 st.pushBack(STPathElement({account.id(), std::nullopt, std::nullopt}));
164}
165
166void
168{
169 st.pushBack(pe);
170}
171
172bool
173equal(STAmount const& sa1, STAmount const& sa2)
174{
175 return sa1 == sa2 && sa1.getIssuer() == sa2.getIssuer();
176}
177
178static void
180 json::Value& jv,
181 PathAsset const& srcAsset,
182 std::optional<AccountID> const& srcIssuer)
183{
185 [&]<typename TAsset>(TAsset const& asset) {
187 {
188 jv[jss::currency] = to_string(asset);
189 if (srcIssuer)
190 jv[jss::issuer] = to_string(*srcIssuer);
191 }
192 else
193 {
194 if (srcIssuer)
195 Throw<std::runtime_error>("MPT source_currencies can't have issuer");
196 jv[jss::mpt_issuance_id] = to_string(asset);
197 }
198 },
199 srcAsset.value());
200}
201
203rpf(jtx::Account const& src,
204 jtx::Account const& dst,
205 STAmount const& dstAmount,
206 std::optional<STAmount> const& sendMax,
207 std::optional<PathAsset> const& srcAsset,
208 std::optional<AccountID> const& srcIssuer)
209{
211 jv[jss::command] = "ripple_path_find";
212 jv[jss::source_account] = toBase58(src);
213 jv[jss::destination_account] = toBase58(dst);
214 jv[jss::destination_amount] = dstAmount.getJson(JsonOptions::Values::None);
215 if (sendMax)
216 jv[jss::send_max] = sendMax->getJson(JsonOptions::Values::None);
217 if (srcAsset)
218 {
219 auto& sc = jv[jss::source_currencies] = json::ValueType::Array;
221 addSourceAsset(j, *srcAsset, srcIssuer);
222 sc.append(j);
223 }
224
225 return jv;
226}
227
230{
231 // These tests were originally written with search parameters that are
232 // different from the current defaults. This function creates an env
233 // with the search parameters that the tests were written for.
234 using namespace jtx;
235 return Env(suite, envconfig([](std::unique_ptr<Config> cfg) {
236 cfg->pathSearchOld = 7;
237 cfg->pathSearch = 7;
238 cfg->pathSearchMax = 10;
239 return cfg;
240 }));
241}
242
245 jtx::Env& env,
246 jtx::Account const& src,
247 jtx::Account const& dst,
248 STAmount const& saDstAmount,
249 std::optional<STAmount> const& saSendMax,
250 std::optional<PathAsset> const& srcAsset,
251 std::optional<AccountID> const& srcIssuer,
252 std::optional<UInt256> const& domain)
253{
254 using namespace jtx;
255
256 auto& app = env.app();
259
260 rpc::JsonContext context{
261 {
262 .j = env.journal,
263 .app = app,
264 .loadType = loadType,
265 .netOps = app.getOPs(),
266 .ledgerMaster = app.getLedgerMaster(),
267 .consumer = c,
268 .role = Role::USER,
269 .coro = {},
270 .infoSub = {},
271 .apiVersion = rpc::kApiVersionIfUnspecified,
272 },
273 {},
274 // NOLINTNEXTLINE(readability-trailing-comma) fix-it drops comma after `{}`
275 {},
276 };
277
279 params[jss::command] = "ripple_path_find";
280 params[jss::source_account] = toBase58(src);
281 params[jss::destination_account] = toBase58(dst);
282 params[jss::destination_amount] = saDstAmount.getJson(JsonOptions::Values::None);
283 if (saSendMax)
284 params[jss::send_max] = saSendMax->getJson(JsonOptions::Values::None);
285
286 if (srcAsset)
287 {
288 auto& sc = params[jss::source_currencies] = json::ValueType::Array;
290 addSourceAsset(j, *srcAsset, srcIssuer);
291 sc.append(j);
292 }
293
294 if (domain)
295 params[jss::domain] = to_string(*domain);
296
297 json::Value result;
298 Gate g;
299 app.getJobQueue().postCoro(JtClient, "RPC-Client", [&](auto const& coro) {
300 context.params = std::move(params);
301 context.coro = coro;
302 rpc::doCommand(context, result);
303 g.signal();
304 });
305
306 using namespace std::chrono_literals;
307 using namespace beast::unit_test;
308 g.waitFor(5s);
309 return result;
310}
311
314 jtx::Env& env,
315 jtx::Account const& src,
316 jtx::Account const& dst,
317 STAmount const& saDstAmount,
318 std::optional<STAmount> const& saSendMax,
319 std::optional<PathAsset> const& srcAsset,
320 std::optional<AccountID> const& srcIssuer,
321 std::optional<UInt256> const& domain)
322{
323 json::Value result =
324 findPathsRequest(env, src, dst, saDstAmount, saSendMax, srcAsset, srcIssuer, domain);
325 if (result.isMember(jss::error))
327
328 STAmount da;
329 if (result.isMember(jss::destination_amount))
330 da = amountFromJson(sfGeneric, result[jss::destination_amount]);
331
332 STAmount sa;
333 STPathSet paths;
334 if (result.isMember(jss::alternatives))
335 {
336 auto const& alts = result[jss::alternatives];
337 if (alts.size() > 0)
338 {
339 auto const& path = alts[0u];
340
341 if (path.isMember(jss::source_amount))
342 sa = amountFromJson(sfGeneric, path[jss::source_amount]);
343
344 if (path.isMember(jss::destination_amount))
345 da = amountFromJson(sfGeneric, path[jss::destination_amount]);
346
347 if (path.isMember(jss::paths_computed))
348 {
349 json::Value p;
350 p["Paths"] = path[jss::paths_computed];
351 STParsedJSONObject po("generic", p);
352 if (po.object)
353 paths = po.object->getFieldPathSet(sfPaths);
354 }
355 }
356 }
357
358 return std::make_tuple(std::move(paths), std::move(sa), std::move(da));
359}
360
363 jtx::Env& env,
364 jtx::Account const& src,
365 jtx::Account const& dst,
366 STAmount const& saDstAmount,
367 std::optional<STAmount> const& saSendMax,
368 std::optional<STPathElement> const& srcElement,
369 std::optional<AccountID> const& srcIssuer,
370 std::optional<UInt256> const& domain)
371{
372 // srcElement is optional but is expected to always be present
373 XRPL_ASSERT(
374 srcElement.has_value(), "xrpl::test::jtx::findPathsByElement::srcElement : nullptr");
375
376 return findPaths(
377 env,
378 src,
379 dst,
380 saDstAmount,
381 saSendMax,
382 // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
383 srcElement->getPathAsset(),
384 srcIssuer,
385 domain);
386}
387
388/******************************************************************************/
389
391txFee(Env const& env, std::uint16_t n)
392{
393 return env.current()->fees().base * n;
394}
395
397xrpMinusFee(Env const& env, std::int64_t xrpAmount)
398{
399 auto const feeDrops = env.current()->fees().base;
400 return drops(kJtxDropsPerXrp * xrpAmount - feeDrops);
401};
402
403[[nodiscard]] bool
404expectHolding(Env const& env, AccountID const& account, STAmount const& value, bool defaultLimits)
405{
406 if (auto const sle = env.le(keylet::trustLine(account, value.get<Issue>())))
407 {
408 Issue const issue = value.get<Issue>();
409 bool const accountLow = account < issue.account;
410
411 bool expectDefaultTrustLine = true;
412 if (defaultLimits)
413 {
414 STAmount low{issue};
415 STAmount high{issue};
416
417 low.get<Issue>().account = accountLow ? account : issue.account;
418 high.get<Issue>().account = accountLow ? issue.account : account;
419
420 expectDefaultTrustLine =
421 sle->getFieldAmount(sfLowLimit) == low && sle->getFieldAmount(sfHighLimit) == high;
422 }
423
424 auto amount = sle->getFieldAmount(sfBalance);
425 amount.get<Issue>().account = value.getIssuer();
426 if (!accountLow)
427 amount.negate();
428 return amount == value && expectDefaultTrustLine;
429 }
430 return false;
431}
432
433[[nodiscard]] bool
434expectHolding(Env const& env, AccountID const& account, None const&, Issue const& issue)
435{
436 return !env.le(keylet::trustLine(account, issue));
437}
438
439[[nodiscard]] bool
440expectHolding(Env const& env, AccountID const& account, None const&, MPTIssue const& mptIssue)
441{
442 return !env.le(keylet::mptoken(mptIssue.getMptID(), account));
443}
444
445[[nodiscard]] bool
446expectHolding(Env const& env, AccountID const& account, None const& value)
447{
448 return std::visit(
449 [&](auto const& issue) { return expectHolding(env, account, value, issue); },
450 value.asset.value());
451}
452
453[[nodiscard]] bool
454expectMPT(Env const& env, AccountID const& account, STAmount const& value)
455{
456 auto const mptIssuanceID = keylet::mptokenIssuance(value.asset().get<MPTIssue>());
457 auto const mptToken = env.le(keylet::mptoken(mptIssuanceID.key, account));
458 return mptToken && (*mptToken)[sfMPTAmount] == value.mpt().value();
459}
460
461[[nodiscard]] bool
463 Env const& env,
464 AccountID const& account,
465 std::uint16_t size,
466 std::vector<Amounts> const& toMatch)
467{
468 std::uint16_t cnt = 0;
469 std::uint16_t matched = 0;
470 forEachItem(*env.current(), account, [&](SLE::ConstRef sle) {
471 if (!sle)
472 return false;
473 if (sle->getType() == ltOFFER)
474 {
475 ++cnt;
476 if (std::ranges::find_if(toMatch, [&](auto const& a) {
477 return a.in == sle->getFieldAmount(sfTakerPays) &&
478 a.out == sle->getFieldAmount(sfTakerGets);
479 }) != toMatch.end())
480 ++matched;
481 }
482 return true;
483 });
484 return size == cnt && ((toMatch.empty() && size != 0) || (matched == toMatch.size()));
485}
486
488ownerDirEntries(ReadView const& view, AccountID const& account)
489{
491 forEachItem(view, account, [&result](SLE::ConstRef sle) { result.push_back(sle); });
492 return result;
493}
494
496ledgerEntryRoot(Env& env, Account const& acct)
497{
498 json::Value jvParams;
499 jvParams[jss::ledger_index] = "current";
500 jvParams[jss::account_root] = acct.human();
501 return env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
502}
503
505ledgerEntryState(Env& env, Account const& acctA, Account const& acctB, std::string const& currency)
506{
507 json::Value jvParams;
508 jvParams[jss::ledger_index] = "current";
509 jvParams[jss::ripple_state][jss::currency] = currency;
510 jvParams[jss::ripple_state][jss::accounts] = json::ValueType::Array;
511 jvParams[jss::ripple_state][jss::accounts].append(acctA.human());
512 jvParams[jss::ripple_state][jss::accounts].append(acctB.human());
513 return env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
514}
515
518{
519 json::Value jvParams;
520 jvParams[jss::offer][jss::account] = acct.human();
521 jvParams[jss::offer][jss::seq] = offerSeq;
522 return env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
523}
524
526ledgerEntryMPT(jtx::Env& env, jtx::Account const& acct, MPTID const& mptID)
527{
528 json::Value jvParams;
529 jvParams[jss::mptoken][jss::account] = acct.human();
530 jvParams[jss::mptoken][jss::mpt_issuance_id] = to_string(mptID);
531 return env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
532}
533
535getBookOffers(jtx::Env& env, Asset const& takerPays, Asset const& takerGets)
536{
537 json::Value jvbp;
538 jvbp[jss::ledger_index] = "current";
539 takerPays.setJson(jvbp[jss::taker_pays]);
540 takerGets.setJson(jvbp[jss::taker_gets]);
541 return env.rpc("json", "book_offers", to_string(jvbp))[jss::result];
542}
543
545accountBalance(Env& env, Account const& acct)
546{
547 auto const jrr = ledgerEntryRoot(env, acct);
548 return jrr[jss::node][sfBalance.fieldName];
549}
550
551[[nodiscard]] bool
552expectLedgerEntryRoot(Env& env, Account const& acct, STAmount const& expectedValue)
553{
554 return accountBalance(env, acct) == to_string(expectedValue.xrp());
555}
556
557/* Crossing Limits */
558/******************************************************************************/
559
560void
561nOffers(Env& env, std::size_t n, Account const& account, STAmount const& in, STAmount const& out)
562{
563 auto const ownerCount = env.le(account)->getFieldU32(sfOwnerCount);
564 for (std::size_t i = 0; i < n; i++)
565 {
566 env(offer(account, in, out));
567 env.close();
568 }
569 env.require(Owners(account, ownerCount + n));
570}
571
572/* Pay Strand */
573/***************************************************************/
574
575// Currency path element
577cpe(PathAsset const& pa)
578{
579 return pa.visit(
580 [](Currency const& currency) {
582 },
583 [](MPTID const& mpt) {
585 });
586};
587
588// All path element
590allPathElements(AccountID const& a, Asset const& asset)
591{
592 return STPathElement(a, asset, asset.getIssuer());
593};
594
596ipe(Asset const& asset)
597{
598 return asset.visit(
599 [](Issue const& issue) {
600 return STPathElement(
602 xrpAccount(),
603 issue.currency,
604 issue.account);
605 },
606 [](MPTIssue const& issue) {
607 return STPathElement(
609 xrpAccount(),
610 issue.getMptID(),
611 issue.getIssuer());
612 });
613};
614
615// Issuer path element
617iape(AccountID const& account)
618{
620};
621
622// Account path element
628
629bool
631{
632 if (!s1)
633 return false;
634 return test::directStepEqual(*s1, dsi.src, dsi.dst, dsi.currency);
635}
636
637bool
639{
640 if (!s1)
641 return false;
642 return test::mptEndpointStepEqual(*s1, dsi.src, dsi.dst, dsi.mptid);
643}
644
645bool
647{
648 if (!s1)
649 return false;
650 return test::xrpEndpointStepEqual(*s1, xrpStepInfo.acc);
651}
652
653bool
655{
656 if (!s1)
657 return false;
658 return bookStepEqual(*s1, bsi);
659}
660
661namespace detail {
662
663IOU
665{
666 auto const iou = args.issuer[args.token];
667 if (args.transferFee != 0)
668 {
669 auto const tfee = 1. + (static_cast<double>(args.transferFee) / 100'000);
670 args.env(rate(args.issuer, tfee));
671 }
672 for (auto const& account : args.holders)
673 {
674 args.env(trust(account, iou(args.limit.value_or(1'000))));
675 }
676 return iou;
677}
678
679MPT
681{
682 using namespace jtx;
683 if (args.limit)
684 {
685 MPT const mpt = MPTTester({
686 .env = args.env,
687 .issuer = args.issuer,
688 .holders = args.holders,
689 .transferFee = args.transferFee,
690 .maxAmt = args.limit,
691 });
692 return mpt;
693 }
694
695 MPT const mpt = MPTTester({
696 .env = args.env,
697 .issuer = args.issuer,
698 .holders = args.holders,
699 .transferFee = args.transferFee,
700 });
701 return mpt;
702}
703
704} // namespace detail
705
706/* LoanBroker */
707/******************************************************************************/
708
709namespace loan_broker {
710
712set(AccountID const& account, UInt256 const& vaultId, uint32_t flags)
713{
714 json::Value jv;
715 jv[sfTransactionType] = jss::LoanBrokerSet;
716 jv[sfAccount] = to_string(account);
717 jv[sfVaultID] = to_string(vaultId);
718 jv[sfFlags] = flags;
719 return jv;
720}
721
723del(AccountID const& account, UInt256 const& brokerID, uint32_t flags)
724{
725 json::Value jv;
726 jv[sfTransactionType] = jss::LoanBrokerDelete;
727 jv[sfAccount] = to_string(account);
728 jv[sfLoanBrokerID] = to_string(brokerID);
729 jv[sfFlags] = flags;
730 return jv;
731}
732
735 AccountID const& account,
736 UInt256 const& brokerID,
737 STAmount const& amount,
738 uint32_t flags)
739{
740 json::Value jv;
741 jv[sfTransactionType] = jss::LoanBrokerCoverDeposit;
742 jv[sfAccount] = to_string(account);
743 jv[sfLoanBrokerID] = to_string(brokerID);
744 jv[sfAmount] = amount.getJson(JsonOptions::Values::None);
745 jv[sfFlags] = flags;
746 return jv;
747}
748
751 AccountID const& account,
752 UInt256 const& brokerID,
753 STAmount const& amount,
754 uint32_t flags)
755{
756 json::Value jv;
757 jv[sfTransactionType] = jss::LoanBrokerCoverWithdraw;
758 jv[sfAccount] = to_string(account);
759 jv[sfLoanBrokerID] = to_string(brokerID);
760 jv[sfAmount] = amount.getJson(JsonOptions::Values::None);
761 jv[sfFlags] = flags;
762 return jv;
763}
764
767{
768 json::Value jv;
769 jv[sfTransactionType] = jss::LoanBrokerCoverClawback;
770 jv[sfAccount] = to_string(account);
771 jv[sfFlags] = flags;
772 return jv;
773}
774
775} // namespace loan_broker
776
777/* Loan */
778/******************************************************************************/
779namespace loan {
780
782set(AccountID const& account,
783 UInt256 const& loanBrokerID,
784 Number principalRequested,
785 std::uint32_t flags)
786{
787 json::Value jv;
788 jv[sfTransactionType] = jss::LoanSet;
789 jv[sfAccount] = to_string(account);
790 jv[sfLoanBrokerID] = to_string(loanBrokerID);
791 jv[sfPrincipalRequested] = to_string(principalRequested);
792 jv[sfFlags] = flags;
793 return jv;
794}
795
797manage(AccountID const& account, UInt256 const& loanID, std::uint32_t flags)
798{
799 json::Value jv;
800 jv[sfTransactionType] = jss::LoanManage;
801 jv[sfAccount] = to_string(account);
802 jv[sfLoanID] = to_string(loanID);
803 jv[sfFlags] = flags;
804 return jv;
805}
806
808del(AccountID const& account, UInt256 const& loanID, std::uint32_t flags)
809{
810 json::Value jv;
811 jv[sfTransactionType] = jss::LoanDelete;
812 jv[sfAccount] = to_string(account);
813 jv[sfLoanID] = to_string(loanID);
814 jv[sfFlags] = flags;
815 return jv;
816}
817
819pay(AccountID const& account, UInt256 const& loanID, STAmount const& amount, std::uint32_t flags)
820{
821 json::Value jv;
822 jv[sfTransactionType] = jss::LoanPay;
823 jv[sfAccount] = to_string(account);
824 jv[sfLoanID] = to_string(loanID);
825 jv[sfAmount] = amount.getJson();
826 jv[sfFlags] = flags;
827 return jv;
828}
829
830} // namespace loan
831} // namespace xrpl::test::jtx
A testsuite class.
Definition suite.h:52
Represents a JSON value.
Definition json_value.h:121
bool isArray() const
Value & append(Value const &value)
Append value to array at the end.
UInt size() const
Number of values in array or object.
bool isMember(char const *key) const
Return true if the object has a member named key.
void setJson(json::Value &jv) const
Definition Asset.cpp:33
constexpr auto visit(Visitors &&... visitors) const -> decltype(auto)
Definition Asset.h:117
AccountID const & getIssuer() const
Definition Asset.cpp:21
Specifies an order book.
Definition Book.h:28
A currency issued by an account.
Definition Issue.h:18
Currency currency
Definition Issue.h:20
AccountID account
Definition Issue.h:21
AccountID const & getIssuer() const
Definition Issue.h:30
constexpr MPTID const & getMptID() const
Definition MPTIssue.h:43
Number is a floating point type that can represent a wide range of values.
Definition Number.h:351
constexpr auto visit(Visitors &&... visitors) const -> decltype(auto)
Definition PathAsset.h:52
constexpr std::variant< Currency, MPTID > const & value() const
Definition PathAsset.h:93
A view into a ledger.
Definition ReadView.h:41
constexpr TIss const & get() const
json::Value getJson(JsonOptions=JsonOptions::Values::None) const override
AccountID const & getIssuer() const
Definition STAmount.h:516
std::shared_ptr< STLedgerEntry const > const & ConstRef
Holds the serialized result of parsing an input JSON object.
std::optional< STObject > object
The STObject if the parse was successful.
void pushBack(STPathElement const &e)
Definition STPathSet.h:538
A consumption charge.
Definition Charge.h:13
An endpoint that consumes resources.
Definition Consumer.h:20
Immutable cryptographic account descriptor.
Definition jtx/Account.h:21
std::string const & human() const
Returns the human readable public key.
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
std::uint32_t sponsoringAccountCount(Account const &account) const
Return the number of sponsoring accounts owned by an account.
Definition Env.cpp:293
std::uint32_t sponsoringOwnerCount(Account const &account) const
Return the number of sponsoring objects owned by an account.
Definition Env.cpp:284
SLE::const_pointer le(Account const &account) const
Return an account root.
Definition Env.cpp:311
std::uint32_t ownerCount(Account const &account) const
Return the number of objects owned by an account.
Definition Env.cpp:266
json::Value rpc(unsigned apiVersion, std::unordered_map< std::string, std::string > const &headers, std::string const &cmd, Args &&... args)
Execute an RPC command.
Definition Env.h:1058
std::uint32_t sponsoredOwnerCount(Account const &account) const
Return the number of sponsored objects owned by an account.
Definition Env.cpp:275
beast::Journal const journal
Definition Env.h:204
void require(Args const &... args)
Check a set of requirements.
Definition Env.h:766
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Definition Env.h:377
bool waitFor(std::chrono::duration< Rep, Period > const &relTime)
Converts to IOU Issue or STAmount.
Test helper for creating, mutating, and asserting MPT and confidential MPT ledger state.
Definition mpt.h:512
Converts to MPT Issue or STAmount.
xrpl::MPTID const & mpt() const
Match the number of items in the account's owner directory.
Definition owners.h:55
T is_same_v
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 mptoken(MPTID const &issuanceID, AccountID const &holder) noexcept
Definition Indexes.cpp:547
Keylet mptokenIssuance(MPTID const &issuanceID) noexcept
Definition Indexes.cpp:541
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 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.
MPT issueHelperMPT(IssuerArgs const &args)
IOU issueHelperIOU(IssuerArgs const &args)
json::Value set(AccountID const &account, UInt256 const &vaultId, uint32_t flags)
json::Value coverWithdraw(AccountID const &account, UInt256 const &brokerID, STAmount const &amount, uint32_t flags)
json::Value coverDeposit(AccountID const &account, UInt256 const &brokerID, STAmount const &amount, uint32_t flags)
json::Value del(AccountID const &account, UInt256 const &brokerID, uint32_t flags)
json::Value coverClawback(AccountID const &account, std::uint32_t flags)
json::Value manage(AccountID const &account, UInt256 const &loanID, std::uint32_t flags)
json::Value set(AccountID const &account, UInt256 const &loanBrokerID, Number principalRequested, std::uint32_t flags)
json::Value del(AccountID const &account, UInt256 const &loanID, std::uint32_t flags)
json::Value pay(AccountID const &account, UInt256 const &loanID, STAmount const &amount, std::uint32_t flags)
void nOffers(Env &env, std::size_t n, Account const &account, STAmount const &in, STAmount const &out)
jtx::Env pathTestEnv(beast::unit_test::Suite &suite)
json::Value ledgerEntryMPT(jtx::Env &env, jtx::Account const &acct, MPTID const &mptID)
bool expectLedgerEntryRoot(Env &env, Account const &acct, STAmount const &expectedValue)
PrettyAmount xrpMinusFee(Env const &env, std::int64_t xrpAmount)
STPathElement allPathElements(AccountID const &a, Asset const &asset)
bool expectHolding(Env const &env, AccountID const &account, STAmount const &value, bool defaultLimits)
static void addSourceAsset(json::Value &jv, PathAsset const &srcAsset, std::optional< AccountID > const &srcIssuer)
constexpr XRPAmount kJtxDropsPerXrp
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::optional< PathAsset > const &srcAsset, std::optional< AccountID > const &srcIssuer, std::optional< UInt256 > const &domain)
json::Value getBookOffers(jtx::Env &env, Asset const &takerPays, Asset const &takerGets)
bool expectOffers(Env const &env, AccountID const &account, std::uint16_t size, std::vector< Amounts > const &toMatch)
std::uint32_t sponsoringAccountCount(Env const &env, Account const &account)
std::uint32_t ownerCount(Env const &env, Account const &account)
jtx::PrettyAmount issuerBalance(jtx::Env &env, jtx::Account const &account, Issue const &issue)
XRPAmount txFee(Env const &env, std::uint16_t n)
json::Value rpf(jtx::Account const &src, jtx::Account const &dst, STAmount const &dstAmount, std::optional< STAmount > const &sendMax, std::optional< PathAsset > const &srcAsset, std::optional< AccountID > const &srcIssuer)
std::uint32_t sponsoringOwnerCount(Env const &env, Account const &account)
STPathElement cpe(PathAsset const &pa)
bool expectMPT(Env const &env, AccountID const &account, STAmount const &value)
json::Value findPathsRequest(jtx::Env &env, jtx::Account const &src, jtx::Account const &dst, STAmount const &saDstAmount, std::optional< STAmount > const &saSendMax, std::optional< PathAsset > const &srcAsset, std::optional< AccountID > const &srcIssuer, std::optional< UInt256 > const &domain)
STPathElement ipe(Asset const &asset)
json::Value ledgerEntryState(Env &env, Account const &acctA, Account const &acctB, std::string const &currency)
bool equal(STAmount const &sa1, STAmount const &sa2)
STPathElement iape(AccountID const &account)
json::Value offer(Account const &account, STAmount const &takerPays, STAmount const &takerGets, std::uint32_t flags)
Create an offer.
Definition offer.cpp:14
uint64_t issuerMPTEscrowed(jtx::Env const &env, jtx::MPT const &mpt)
std::uint32_t sponsoredOwnerCount(Env const &env, Account const &account)
json::Value ledgerEntryRoot(Env &env, Account const &acct)
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
Definition envconfig.h:38
std::vector< SLE::const_pointer > ownerDirEntries(ReadView const &view, AccountID const &account)
Return the ledger entries in an account's owner directory.
json::Value trust(Account const &account, STAmount const &amount, std::uint32_t flags)
Modify a trust line.
Definition trust.cpp:18
std::tuple< STPathSet, STAmount, STAmount > findPathsByElement(jtx::Env &env, jtx::Account const &src, jtx::Account const &dst, STAmount const &saDstAmount, std::optional< STAmount > const &saSendMax, std::optional< STPathElement > const &srcElement, std::optional< AccountID > const &srcIssuer, std::optional< UInt256 > const &domain)
void stpathAppendOne(STPath &st, Account const &account)
PrettyAmount drops(Integer i)
Returns an XRP PrettyAmount, which is trivially convertible to STAmount.
json::Value accountBalance(Env &env, Account const &acct)
json::Value rate(Account const &account, double multiplier)
Set a transfer rate.
Definition rate.cpp:15
json::Value getAccountLines(Env &env, AccountID const &acctId)
uint64_t mptEscrowed(jtx::Env const &env, jtx::Account const &account, jtx::MPT const &mpt)
bool checkArraySize(json::Value const &val, unsigned int size)
json::Value ledgerEntryOffer(jtx::Env &env, jtx::Account const &acct, std::uint32_t offerSeq)
jtx::PrettyAmount issuerEscrowed(jtx::Env &env, jtx::Account const &account, Issue const &issue)
STPathElement ape(AccountID const &a)
json::Value getAccountOffers(Env &env, AccountID const &acct, bool current)
bool bookStepEqual(Step const &step, xrpl::Book const &book)
bool xrpEndpointStepEqual(Step const &step, AccountID const &acc)
bool mptEndpointStepEqual(Step const &step, AccountID const &src, AccountID const &dst, MPTID const &mptid)
bool directStepEqual(Step const &step, AccountID const &src, AccountID const &dst, Currency const &currency)
constexpr XRPAmount
Convert XRP to drops (integral types).
Definition TxTest.h:53
void forEachItem(ReadView const &view, Keylet const &root, std::function< void(SLE::ConstRef)> const &f)
Iterate all items in the given directory.
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
STAmount amountFromString(Asset const &asset, std::string const &amount)
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.
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
Definition contract.h:52
T has_value(T... args)
T push_back(T... args)
std::shared_ptr< JobQueue::Coro > coro
Definition Context.h:35
json::Value params
Definition Context.h:51
std::optional< std::uint64_t > limit
std::vector< jtx::Account > holders
Represents an XRP, IOU, or MPT quantity This customizes the string conversion and supports XRP conver...
T value_or(T... args)
T visit(T... args)