xrpld
Loading...
Searching...
No Matches
jtx/TestHelpers.h
1#pragma once
2
3#include <test/jtx/Account.h>
4#include <test/jtx/Env.h>
5#include <test/jtx/JTx.h>
6#include <test/jtx/amount.h>
7
8#include <xrpld/app/misc/TxQ.h>
9
10#include <xrpl/basics/Number.h>
11#include <xrpl/basics/Slice.h>
12#include <xrpl/basics/base_uint.h>
13#include <xrpl/basics/chrono.h>
14#include <xrpl/basics/strHex.h>
15#include <xrpl/beast/unit_test/suite.h>
16#include <xrpl/core/ServiceRegistry.h>
17#include <xrpl/json/json_value.h>
18#include <xrpl/ledger/ReadView.h>
19#include <xrpl/protocol/AccountID.h>
20#include <xrpl/protocol/ApiVersion.h>
21#include <xrpl/protocol/Asset.h>
22#include <xrpl/protocol/Book.h>
23#include <xrpl/protocol/Indexes.h>
24#include <xrpl/protocol/Issue.h>
25#include <xrpl/protocol/JsonRpc.h>
26#include <xrpl/protocol/PathAsset.h>
27#include <xrpl/protocol/Quality.h>
28#include <xrpl/protocol/SField.h>
29#include <xrpl/protocol/STAmount.h>
30#include <xrpl/protocol/STLedgerEntry.h>
31#include <xrpl/protocol/STNumber.h> // IWYU pragma: keep
32#include <xrpl/protocol/STPathSet.h>
33#include <xrpl/protocol/SeqProxy.h>
34#include <xrpl/protocol/Serializer.h>
35#include <xrpl/protocol/UintTypes.h>
36#include <xrpl/protocol/Units.h>
37#include <xrpl/protocol/XRPAmount.h>
38#include <xrpl/protocol/jss.h>
39#include <xrpl/tx/paths/detail/Steps.h>
40
41#include <algorithm>
42#include <array>
43#include <chrono>
44#include <condition_variable>
45#include <cstddef>
46#include <cstdint>
47#include <memory>
48#include <mutex>
49#include <optional>
50#include <source_location>
51#include <string>
52#include <tuple>
53#include <type_traits>
54#include <utility>
55#include <vector>
56
57namespace xrpl::test::jtx {
58
65template <
66 class SField,
67 // NOLINTNEXTLINE(readability-redundant-typename): typename required by MSVC
68 class StoredValue = typename SField::type::value_type,
69 class OutputValue = StoredValue>
71{
72 using SF = SField;
73 using SV = StoredValue;
74 using OV = OutputValue;
75
76protected:
77 SF const& sfield_;
79
80public:
81 explicit JTxField(SF const& sfield, SV value) : sfield_(sfield), value_(std::move(value))
82 {
83 }
84
85 virtual ~JTxField() = default;
86
87 [[nodiscard]] virtual OV
88 value() const = 0;
89
90 virtual void
91 operator()(Env&, JTx& jt) const
92 {
93 jt.jv[sfield_.jsonName] = value();
94 }
95};
96
97template <class SField, class StoredValue>
98struct JTxField<SField, StoredValue, StoredValue>
99{
100 using SF = SField;
101 using SV = StoredValue;
102 using OV = SV;
103
104protected:
105 SF const& sfield_;
107
108public:
109 explicit JTxField(SF const& sfield, SV value) : sfield_(sfield), value_(std::move(value))
110 {
111 }
112
113 void
114 operator()(Env&, JTx& jt) const
115 {
116 jt.jv[sfield_.jsonName] = value_;
117 }
118};
119
120struct TimePointField : public JTxField<SF_UINT32, NetClock::time_point, NetClock::rep>
121{
122 using SF = SF_UINT32;
126
127protected:
128 using Base::value_;
129
130public:
131 explicit TimePointField(SF const& sfield, SV const& value) : JTxField(sfield, value)
132 {
133 }
134
135 [[nodiscard]] OV
136 value() const override
137 {
138 return value_.time_since_epoch().count();
139 }
140};
141
142struct UInt256Field : public JTxField<SF_UINT256, UInt256, std::string>
143{
144 using SF = SF_UINT256;
145 using SV = UInt256;
148
149protected:
150 using Base::value_;
151
152public:
153 explicit UInt256Field(SF const& sfield, SV const& value) : JTxField(sfield, value)
154 {
155 }
156
157 [[nodiscard]] OV
158 value() const override
159 {
160 return to_string(value_);
161 }
162};
163
164struct AccountIdField : public JTxField<SF_ACCOUNT, AccountID, std::string>
165{
166 using SF = SF_ACCOUNT;
167 using SV = AccountID;
170
171protected:
172 using Base::value_;
173
174public:
175 explicit AccountIdField(SF const& sfield, SV const& value) : JTxField(sfield, value)
176 {
177 }
178
179 [[nodiscard]] OV
180 value() const override
181 {
182 return toBase58(value_);
183 }
184};
185
186struct StAmountField : public JTxField<SF_AMOUNT, STAmount, json::Value>
187{
188 using SF = SF_AMOUNT;
189 using SV = STAmount;
192
193protected:
194 using Base::value_;
195
196public:
197 explicit StAmountField(SF const& sfield, SV const& value) : JTxField(sfield, value)
198 {
199 }
200
201 [[nodiscard]] OV
202 value() const override
203 {
204 return value_.getJson(JsonOptions::Values::None);
205 }
206};
207
208struct BlobField : public JTxField<SF_VL, std::string>
209{
210 using SF = SF_VL;
213
214 using JTxField::JTxField;
215
216 explicit BlobField(SF const& sfield, Slice const& cond) : JTxField(sfield, strHex(cond))
217 {
218 }
219
220 template <size_t N>
221 explicit BlobField(SF const& sfield, std::array<std::uint8_t, N> const& c)
222 : BlobField(sfield, makeSlice(c))
223 {
224 }
225};
226
227template <class SField, class UnitTag, class ValueType>
228struct ValueUnitField : public JTxField<SField, unit::ValueUnit<UnitTag, ValueType>, ValueType>
229{
230 using SF = SField;
232 using OV = ValueType;
234
236
237protected:
238 using Base::value_;
239
240public:
241 using JTxField<SF, SV, OV>::JTxField;
242
243 [[nodiscard]] OV
244 value() const override
245 {
246 return value_.value();
247 }
248};
249
250template <class JTxField>
252{
253 using JF = JTxField;
254 using SF = JF::SF;
255 using SV = JF::SV;
256
257protected:
258 SF const& sfield_;
259
260public:
261 explicit JTxFieldWrapper(SF const& sfield) : sfield_(sfield)
262 {
263 }
264
265 JF
266 operator()(SV const& value) const
267 {
268 return JTxField(sfield_, value);
269 }
270};
271
272template <>
274{
275 using JF = BlobField;
276 using SF = JF::SF;
277 using SV = JF::SV;
278
279protected:
280 SF const& sfield_;
281
282public:
283 explicit JTxFieldWrapper(SF const& sfield) : sfield_(sfield)
284 {
285 }
286
287 JF
288 operator()(SV const& cond) const
289 {
290 return JF(sfield_, makeSlice(cond));
291 }
292
293 JF
294 operator()(Slice const& cond) const
295 {
296 return JF(sfield_, cond);
297 }
298
299 template <size_t N>
300 JF
302 {
303 return operator()(makeSlice(c));
304 }
305};
306
307// NOLINTNEXTLINE(readability-redundant-typename): typename required by MSVC
308template <class SField, class UnitTag, class ValueType = typename SField::type::value_type>
310
311// NOLINTNEXTLINE(readability-redundant-typename): typename required by MSVC
312template <class SField, class StoredValue = typename SField::type::value_type>
314
319
321
322// Functions used in debugging
324getAccountOffers(Env& env, AccountID const& acct, bool current = false);
325
326inline json::Value
327getAccountOffers(Env& env, Account const& acct, bool current = false)
328{
329 return getAccountOffers(env, acct.id(), current);
330}
331
333getAccountLines(Env& env, AccountID const& acctId);
334
335inline json::Value
336getAccountLines(Env& env, Account const& acct)
337{
338 return getAccountLines(env, acct.id());
339}
340
341template <typename... IOU>
343getAccountLines(Env& env, AccountID const& acctId, IOU... ious)
344{
345 auto jrr = getAccountLines(env, acctId);
346 json::Value res;
347 for (auto const& line : jrr[jss::lines])
348 {
349 for (auto const& iou : {ious...})
350 {
351 if (line[jss::currency].asString() == to_string(iou.currency))
352 {
353 json::Value v;
354 v[jss::currency] = line[jss::currency];
355 v[jss::balance] = line[jss::balance];
356 v[jss::limit] = line[jss::limit];
357 v[jss::account] = line[jss::account];
358 res[jss::lines].append(v);
359 }
360 }
361 }
362 if (!res.isNull())
363 return res;
364 return jrr;
365}
366
367[[nodiscard]] bool
368checkArraySize(json::Value const& val, unsigned int size);
369
378[[nodiscard]]
379inline bool
381{
382 return reply.isMember(jss::jsonrpc) && reply[jss::jsonrpc] == rpc::kJsonRpcVersion &&
383 reply.isMember(jss::ripplerpc) && reply[jss::ripplerpc] == rpc::kRippleRpcVersion2;
384}
385
392inline void
394{
395 request[jss::jsonrpc] = rpc::kJsonRpcVersion;
396 request[jss::ripplerpc] = rpc::kRippleRpcVersion2;
397}
398
399// Helper function that returns the owner count on an account.
401ownerCount(test::jtx::Env const& env, test::jtx::Account const& account);
402
403/* Token (IOU/MPT) Locking */
404/******************************************************************************/
405uint64_t
406mptEscrowed(jtx::Env const& env, jtx::Account const& account, jtx::MPT const& mpt);
407
408uint64_t
409issuerMPTEscrowed(jtx::Env const& env, jtx::MPT const& mpt);
410
412issuerBalance(jtx::Env& env, jtx::Account const& account, Issue const& issue);
413
415issuerEscrowed(jtx::Env& env, jtx::Account const& account, Issue const& issue);
416
417// Helper function that returns the sponsored owner count on an account.
419sponsoredOwnerCount(test::jtx::Env const& env, test::jtx::Account const& account);
420
421// Helper function that returns the sponsoring owner count on an account.
423sponsoringOwnerCount(test::jtx::Env const& env, test::jtx::Account const& account);
424
425// Helper function that returns the sponsoring account count on an account.
428
429[[nodiscard]]
430inline bool
431checkVL(Slice const& result, std::string const& expected)
432{
433 Serializer s;
434 s.addRaw(result);
435 return s.getString() == expected;
436}
437
438[[nodiscard]]
439inline bool
440checkVL(SLE::ConstRef sle, SField const& field, std::string const& expected)
441{
442 return strHex(expected) == strHex(sle->getFieldVL(field));
443}
444
445/* Path finding */
446/******************************************************************************/
447void
448stpathAppendOne(STPath& st, Account const& account);
449
450template <class T>
451void
452stpathAppendOne(STPath& st, T const& t)
454{
455 stpathAppendOne(st, Account{t});
456}
457
458void
459stpathAppendOne(STPath& st, STPathElement const& pe);
460
461template <class T, class... Args>
462void
463stpathAppend(STPath& st, T const& t, Args const&... args)
464{
465 stpathAppendOne(st, t);
466 if constexpr (sizeof...(args) > 0)
467 stpathAppend(st, args...);
468}
469
470template <class... Args>
471void
472stpathsetAppend(STPathSet& st, STPath const& p, Args const&... args)
473{
474 st.pushBack(p);
475 if constexpr (sizeof...(args) > 0)
476 stpathsetAppend(st, args...);
477}
478
479bool
480equal(STAmount const& sa1, STAmount const& sa2);
481
482template <class... Args>
483STPath
484stpath(Args const&... args)
485{
486 STPath st;
487 stpathAppend(st, args...);
488 return st;
489}
490
491template <class... Args>
492bool
493same(STPathSet const& st1, Args const&... args)
494{
495 STPathSet st2;
496 stpathsetAppend(st2, args...);
497 if (st1.size() != st2.size())
498 return false;
499
500 return std::ranges::all_of(
501 st2, [&st1](auto const& p) { return std::ranges::find(st1, p) != st1.end(); });
502}
503
505rpf(jtx::Account const& src,
506 jtx::Account const& dst,
507 STAmount const& dstAmount,
508 std::optional<STAmount> const& sendMax = std::nullopt,
509 std::optional<PathAsset> const& srcAsset = std::nullopt,
510 std::optional<AccountID> const& srcIssuer = std::nullopt);
511
514
515class Gate
516{
517private:
520 bool signaled_ = false;
521
522public:
523 // Thread safe, blocks until signaled or period expires.
524 // Returns `true` if signaled.
525 template <class Rep, class Period>
526 bool
528 {
530 auto const b = cv_.wait_for(lk, relTime, [this] { return signaled_; });
531 signaled_ = false;
532 return b;
533 }
534
535 void
537 {
538 std::scoped_lock const lk(mutex_);
539 signaled_ = true;
540 cv_.notify_all();
541 }
542};
543
546 jtx::Env& env,
547 jtx::Account const& src,
548 jtx::Account const& dst,
549 STAmount const& saDstAmount,
550 std::optional<STAmount> const& saSendMax = std::nullopt,
551 std::optional<PathAsset> const& srcAsset = std::nullopt,
552 std::optional<AccountID> const& srcIssuer = std::nullopt,
553 std::optional<UInt256> const& domain = std::nullopt);
554
557 jtx::Env& env,
558 jtx::Account const& src,
559 jtx::Account const& dst,
560 STAmount const& saDstAmount,
561 std::optional<STAmount> const& saSendMax = std::nullopt,
562 std::optional<PathAsset> const& srcAsset = std::nullopt,
563 std::optional<AccountID> const& srcIssuer = std::nullopt,
564 std::optional<UInt256> const& domain = std::nullopt);
565
568 jtx::Env& env,
569 jtx::Account const& src,
570 jtx::Account const& dst,
571 STAmount const& saDstAmount,
572 std::optional<STAmount> const& saSendMax = std::nullopt,
573 std::optional<STPathElement> const& srcElement = std::nullopt,
574 std::optional<AccountID> const& srcIssuer = std::nullopt,
575 std::optional<UInt256> const& domain = std::nullopt);
576
577/******************************************************************************/
578
580txFee(Env const& env, std::uint16_t n);
581
583xrpMinusFee(Env const& env, std::int64_t xrpAmount);
584
585bool
587 Env const& env,
588 AccountID const& account,
589 STAmount const& value,
590 bool defaultLimits = false);
591
592template <typename... Amts>
593bool
594expectHolding(Env const& env, AccountID const& account, STAmount const& value, Amts const&... amts)
595{
596 return expectHolding(env, account, value, false) && expectHolding(env, account, amts...);
597}
598
599bool
600expectHolding(Env const& env, AccountID const& account, None const& value);
601
602bool
603expectMPT(Env const& env, AccountID const& account, STAmount const& value);
604
605bool
607 Env const& env,
608 AccountID const& account,
609 std::uint16_t size,
610 std::vector<Amounts> const& toMatch = {});
611
616ownerDirEntries(ReadView const& view, AccountID const& account);
617
619ledgerEntryRoot(Env& env, Account const& acct);
620
622ledgerEntryState(Env& env, Account const& acctA, Account const& acctB, std::string const& currency);
623
625ledgerEntryOffer(jtx::Env& env, jtx::Account const& acct, std::uint32_t offerSeq);
626
628ledgerEntryMPT(jtx::Env& env, jtx::Account const& acct, MPTID const& mptID);
629
631getBookOffers(jtx::Env& env, Asset const& takerPays, Asset const& takerGets);
632
634accountBalance(Env& env, Account const& acct);
635
636[[nodiscard]] bool
637expectLedgerEntryRoot(Env& env, Account const& acct, STAmount const& expectedValue);
638
639/* Crossing Limits */
640/******************************************************************************/
641
642void
643nOffers(Env& env, std::size_t n, Account const& account, STAmount const& in, STAmount const& out);
644
645/* Pay Strand */
646/***************************************************************/
647
654
661
666
667// Currency/MPTID path element
669cpe(PathAsset const& pa);
670
671// Currency/MPTID and issuer path element
673ipe(Asset const& asset);
674
675// Issuer path element
677iape(AccountID const& account);
678
679// Account path element
681ape(AccountID const& a);
682
683// All path element
685allPathElements(AccountID const& a, Asset const& asset);
686
687bool
688equal(std::unique_ptr<Step> const& s1, DirectStepInfo const& dsi);
689
690bool
691equal(std::unique_ptr<Step> const& s1, MPTEndpointStepInfo const& dsi);
692
693bool
694equal(std::unique_ptr<Step> const& s1, XRPEndpointStepInfo const& xrpStepInfo);
695
696bool
697equal(std::unique_ptr<Step> const& s1, xrpl::Book const& bsi);
698
699template <class Iter>
700bool
702{
703 // base case. all args processed and found equal.
704 return true;
705}
706
707template <class Iter, class StepInfo, class... Args>
708bool
709strandEqualHelper(Iter i, StepInfo&& si, Args&&... args)
710{
712 return false;
713 return strandEqualHelper(++i, std::forward<Args>(args)...);
714}
715
716template <class... Args>
717bool
718equal(Strand const& strand, Args&&... args)
719{
720 if (strand.size() != sizeof...(Args))
721 return false;
722 if (strand.empty())
723 return true;
724 return strandEqualHelper(strand.begin(), std::forward<Args>(args)...);
725}
726
727/***************************************************************/
728
729/* Check */
730/***************************************************************/
731namespace check {
732
736template <typename A>
739create(A const& account, A const& dest, STAmount const& sendMax)
740{
741 json::Value jv;
742 jv[sfAccount.jsonName] = to_string(account);
743 jv[sfSendMax.jsonName] = sendMax.getJson(JsonOptions::Values::None);
744 jv[sfDestination.jsonName] = to_string(dest);
745 jv[sfTransactionType.jsonName] = jss::CheckCreate;
746 return jv;
747}
748
749inline json::Value
750create(jtx::Account const& account, jtx::Account const& dest, STAmount const& sendMax)
751{
752 return create(account.id(), dest.id(), sendMax);
753}
754
755} // namespace check
756
759
760inline UInt256
761getCheckIndex(AccountID const& account, std::uint32_t const sequence)
762{
763 return keylet::check(account, SeqProxy::rawSequence(sequence)).key;
764}
765
766template <class Suite>
767void
769 Suite& test,
770 jtx::Env& env,
771 std::size_t expectedCount,
772 std::optional<std::size_t> expectedMaxCount,
773 std::size_t expectedInLedger,
774 std::size_t expectedPerLedger,
775 std::uint64_t expectedMinFeeLevel = kBaseFeeLevel.fee(),
776 std::uint64_t expectedMedFeeLevel = kMinEscalationFeeLevel.fee(),
778{
779 int const line = location.line();
780 char const* file = location.file_name();
781 FeeLevel64 const expectedMin{expectedMinFeeLevel};
782 FeeLevel64 const expectedMed{expectedMedFeeLevel};
783 auto const metrics = env.app().getTxQ().getMetrics(*env.current());
784 using namespace std::string_literals;
785
786 metrics.referenceFeeLevel == kBaseFeeLevel
787 ? test.pass()
788 : test.fail(
789 "reference: "s + std::to_string(metrics.referenceFeeLevel.value()) + "/" +
791 file,
792 line);
793
794 metrics.txCount == expectedCount
795 ? test.pass()
796 : test.fail(
797 "txCount: "s + std::to_string(metrics.txCount) + "/" + std::to_string(expectedCount),
798 file,
799 line);
800
801 metrics.txQMaxSize == expectedMaxCount
802 ? test.pass()
803 : test.fail(
804 "txQMaxSize: "s + std::to_string(metrics.txQMaxSize.value_or(0)) + "/" +
805 std::to_string(expectedMaxCount.value_or(0)),
806 file,
807 line);
808
809 metrics.txInLedger == expectedInLedger
810 ? test.pass()
811 : test.fail(
812 "txInLedger: "s + std::to_string(metrics.txInLedger) + "/" +
813 std::to_string(expectedInLedger),
814 file,
815 line);
816
817 metrics.txPerLedger == expectedPerLedger
818 ? test.pass()
819 : test.fail(
820 "txPerLedger: "s + std::to_string(metrics.txPerLedger) + "/" +
821 std::to_string(expectedPerLedger),
822 file,
823 line);
824
825 metrics.minProcessingFeeLevel == expectedMin
826 ? test.pass()
827 : test.fail(
828 "minProcessingFeeLevel: "s + std::to_string(metrics.minProcessingFeeLevel.value()) +
829 "/" + std::to_string(expectedMin.value()),
830 file,
831 line);
832
833 metrics.medFeeLevel == expectedMed
834 ? test.pass()
835 : test.fail(
836 "medFeeLevel: "s + std::to_string(metrics.medFeeLevel.value()) + "/" +
837 std::to_string(expectedMed.value()),
838 file,
839 line);
840
841 auto const expectedCurFeeLevel = expectedInLedger > expectedPerLedger
842 ? expectedMed * expectedInLedger * expectedInLedger /
843 (expectedPerLedger * expectedPerLedger)
844 : metrics.referenceFeeLevel;
845
846 metrics.openLedgerFeeLevel == expectedCurFeeLevel
847 ? test.pass()
848 : test.fail(
849 "openLedgerFeeLevel: "s + std::to_string(metrics.openLedgerFeeLevel.value()) + "/" +
850 std::to_string(expectedCurFeeLevel.value()),
851 file,
852 line);
853}
854
855/* LoanBroker */
856/******************************************************************************/
857
858namespace loan_broker {
859
861set(AccountID const& account, UInt256 const& vaultId, std::uint32_t flags = 0);
862
863// Use "del" because "delete" is a reserved word in C++.
865del(AccountID const& account, UInt256 const& brokerID, std::uint32_t flags = 0);
866
869 AccountID const& account,
870 UInt256 const& brokerID,
871 STAmount const& amount,
872 std::uint32_t flags = 0);
873
876 AccountID const& account,
877 UInt256 const& brokerID,
878 STAmount const& amount,
879 std::uint32_t flags = 0);
880
881// Must specify at least one of loanBrokerID or amount.
883coverClawback(AccountID const& account, std::uint32_t flags = 0);
884
885auto const kLoanBrokerId = JTxFieldWrapper<UInt256Field>(sfLoanBrokerID);
886
889
890auto const kDebtMaximum = SimpleField<SF_NUMBER>(sfDebtMaximum);
891
893
896
898
900
901} // namespace loan_broker
902
903/* Loan */
904/******************************************************************************/
905namespace loan {
906
908set(AccountID const& account,
909 UInt256 const& loanBrokerID,
910 Number principalRequested,
911 std::uint32_t flags = 0);
912
914
915// For `CounterPartySignature`, use `Sig(sfCounterpartySignature, ...)`
916
917auto const kLoanOriginationFee = SimpleField<SF_NUMBER>(sfLoanOriginationFee);
918
919auto const kLoanServiceFee = SimpleField<SF_NUMBER>(sfLoanServiceFee);
920
921auto const kLatePaymentFee = SimpleField<SF_NUMBER>(sfLatePaymentFee);
922
923auto const kClosePaymentFee = SimpleField<SF_NUMBER>(sfClosePaymentFee);
924
926
928
930
933
935 ValueUnitWrapper<SF_UINT32, unit::TenthBipsTag>(sfOverpaymentInterestRate);
936
937auto const kPaymentTotal = SimpleField<SF_UINT32>(sfPaymentTotal);
938
939auto const kPaymentInterval = SimpleField<SF_UINT32>(sfPaymentInterval);
940
941auto const kGracePeriod = SimpleField<SF_UINT32>(sfGracePeriod);
942
944manage(AccountID const& account, UInt256 const& loanID, std::uint32_t flags);
945
947del(AccountID const& account, UInt256 const& loanID, std::uint32_t flags = 0);
948
950pay(AccountID const& account,
951 UInt256 const& loanID,
952 STAmount const& amount,
953 std::uint32_t flags = 0);
954
955} // namespace loan
956
961{
962private:
964
965public:
966 explicit Expiration(NetClock::time_point const& expiry)
967 : expiry_{expiry.time_since_epoch().count()}
968 {
969 }
970
971 void
972 operator()(Env&, JTx& jt) const
973 {
974 jt[sfExpiration.jsonName] = expiry_;
975 }
976};
977
982{
983private:
985
986public:
987 explicit SourceTag(std::uint32_t tag) : tag_{tag}
988 {
989 }
990
991 void
992 operator()(Env&, JTx& jt) const
993 {
994 jt[sfSourceTag.jsonName] = tag_;
995 }
996};
997
1002{
1003private:
1005
1006public:
1007 explicit DestTag(std::uint32_t tag) : tag_{tag}
1008 {
1009 }
1010
1011 void
1012 operator()(Env&, JTx& jt) const
1013 {
1014 jt[sfDestinationTag.jsonName] = tag_;
1015 }
1016};
1017
1019{
1021 // 3-letter currency if Issue, ignored if MPT
1024 std::vector<jtx::Account> holders = {}; // NOLINT(readability-redundant-member-init)
1025 // trust-limit if Issue, maxAmount if MPT
1027 // 0-50'000 (0-50%)
1029};
1030
1031namespace detail {
1032
1033IOU
1034issueHelperIOU(IssuerArgs const& args);
1035
1036MPT
1037issueHelperMPT(IssuerArgs const& args);
1038
1039} // namespace detail
1040
1041template <typename TTester>
1042void
1049
1050template <typename TTester>
1051void
1062
1063} // namespace xrpl::test::jtx
T all_of(T... args)
A testsuite class.
Definition suite.h:52
Represents a JSON value.
Definition json_value.h:121
bool isNull() const
isNull() tests to see if this field is null.
Value & append(Value const &value)
Append value to array at the end.
bool isMember(char const *key) const
Return true if the object has a member named key.
Specifies an order book.
Definition Book.h:28
A currency issued by an account.
Definition Issue.h:18
std::uint32_t rep
Definition chrono.h:45
std::chrono::time_point< NetClock > time_point
Definition chrono.h:48
Number is a floating point type that can represent a wide range of values.
Definition Number.h:351
A view into a ledger.
Definition ReadView.h:41
Identifies fields.
Definition SField.h:131
json::Value getJson(JsonOptions=JsonOptions::Values::None) const override
std::shared_ptr< STLedgerEntry const > const & ConstRef
std::vector< STPath >::size_type size() const
Definition STPathSet.h:624
bool pushBack(STPath const &e)
pushBack adds a path to the set.
Definition STPathSet.h:669
std::vector< STPath >::const_iterator end() const
Definition STPathSet.h:618
static constexpr SeqProxy rawSequence(std::uint32_t v)
Factory function to return a sequence-based SeqProxy.
Definition SeqProxy.h:62
std::string getString() const
Definition Serializer.h:309
int addRaw(Blob const &vector)
virtual TxQ & getTxQ()=0
An immutable linear range of bytes.
Definition Slice.h:28
Metrics getMetrics(OpenView const &view) const
Returns fee metrics in reference fee level units.
Definition TxQ.cpp:2070
static constexpr FeeLevel64 kBaseLevel
Fee level for single-signed reference transaction.
Definition TxQ.h:64
Immutable cryptographic account descriptor.
Definition jtx/Account.h:21
AccountID id() const
Returns the Account ID.
std::uint32_t const tag_
void operator()(Env &, JTx &jt) const
DestTag(std::uint32_t tag)
A transaction testing environment.
Definition Env.h:161
Application & app()
Definition Env.h:300
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Definition Env.h:377
std::uint32_t const expiry_
Expiration(NetClock::time_point const &expiry)
void operator()(Env &, JTx &jt) const
bool waitFor(std::chrono::duration< Rep, Period > const &relTime)
std::condition_variable cv_
Converts to IOU Issue or STAmount.
Converts to MPT Issue or STAmount.
void operator()(Env &, JTx &jt) const
SourceTag(std::uint32_t tag)
constexpr value_type value() const
Returns the underlying value.
Definition Units.h:338
T current(T... args)
T find(T... args)
T forward(T... args)
T is_constructible_v
T is_same_v
STL namespace.
Keylet check(AccountID const &id, SeqProxy const &seq) noexcept
A Check.
Definition Indexes.cpp:372
constexpr std::string_view kRippleRpcVersion2
Definition ApiVersion.h:57
constexpr std::string_view kJsonRpcVersion
Value of the jsonrpc member of a request and of its reply, fixed at "2.0" by the JSON-RPC specificati...
Definition JsonRpc.h:16
Check operations.
Definition check.h:18
json::Value create(A const &account, A const &dest, STAmount const &sendMax)
Create a check.
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)
auto const kOverpaymentInterestRate
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)
constexpr FeeLevel64 kBaseFeeLevel
bool expectLedgerEntryRoot(Env &env, Account const &acct, STAmount const &expectedValue)
JTxFieldWrapper< JTxField< SField, StoredValue > > SimpleField
PrettyAmount xrpMinusFee(Env const &env, std::int64_t xrpAmount)
constexpr FeeLevel64 kMinEscalationFeeLevel
STPathElement allPathElements(AccountID const &a, Asset const &asset)
bool expectHolding(Env const &env, AccountID const &account, STAmount const &value, bool defaultLimits)
void setEnvelope2(json::Value &request)
Sets the version 2 envelope on request: jsonrpc to rpc::kJsonRpcVersion and ripplerpc to rpc::kRipple...
void testHelper2TokensMix(TTester &&tester)
JTxFieldWrapper< ValueUnitField< SField, UnitTag, ValueType > > ValueUnitWrapper
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)
bool hasEnvelope2(json::Value const &reply)
Reports whether reply carries the version 2 envelope: jsonrpc equal to rpc::kJsonRpcVersion and rippl...
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)
bool same(STPathSet const &st1, Args const &... args)
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)
void checkMetrics(Suite &test, jtx::Env &env, std::size_t expectedCount, std::optional< std::size_t > expectedMaxCount, std::size_t expectedInLedger, std::size_t expectedPerLedger, std::uint64_t expectedMinFeeLevel=kBaseFeeLevel.fee(), std::uint64_t expectedMedFeeLevel=kMinEscalationFeeLevel.fee(), std::source_location const location=std::source_location::current())
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)
bool strandEqualHelper(Iter i)
void testHelper3TokensMix(TTester &&tester)
auto const kData
General field definitions, or fields used in multiple transaction namespaces.
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)
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::vector< SLE::const_pointer > ownerDirEntries(ReadView const &view, AccountID const &account)
Return the ledger entries in an account's owner directory.
void stpathsetAppend(STPathSet &st, STPath const &p, Args const &... args)
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)
json::Value accountBalance(Env &env, Account const &acct)
STPath stpath(Args const &... args)
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)
bool checkVL(Slice const &result, std::string const &expected)
void stpathAppend(STPath &st, T const &t, Args const &... args)
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)
UInt256 getCheckIndex(AccountID const &account, std::uint32_t const sequence)
constexpr XRPAmount
Convert XRP to drops (integral types).
Definition TxTest.h:53
std::string strHex(FwdIt begin, FwdIt end)
Definition strHex.h:13
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
TypedField< STInteger< std::uint32_t > > SF_UINT32
Definition SField.h:343
TypedField< STAmount > SF_AMOUNT
Definition SField.h:357
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition base_uint.h:658
Slice makeSlice(std::array< T, N > const &a)
Definition Slice.h:228
BaseUInt< 256 > UInt256
Definition base_uint.h:581
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
TypedField< STBlob > SF_VL
Definition SField.h:361
FeeLevel< std::uint64_t > FeeLevel64
Definition Units.h:443
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
TypedField< STAccount > SF_ACCOUNT
Definition SField.h:356
TypedField< STBitString< 256 > > SF_UINT256
Definition SField.h:349
UInt256 key
Definition Keylet.h:21
AccountIdField(SF const &sfield, SV const &value)
BlobField(SF const &sfield, std::array< std::uint8_t, N > const &c)
JTxField(SF const &sfield, SV value)
BlobField(SF const &sfield, Slice const &cond)
JTxField< SF, SV, SV > Base
std::optional< std::uint64_t > limit
std::vector< jtx::Account > holders
JF operator()(std::array< std::uint8_t, N > const &c) const
JF operator()(SV const &value) const
Generic helper class for helper classes that set a field on a JTx.
JTxField(SF const &sfield, SV value)
virtual void operator()(Env &, JTx &jt) const
virtual ~JTxField()=default
Execution context for applying a JSON transaction.
Definition JTx.h:27
json::Value jv
Definition JTx.h:28
Represents an XRP, IOU, or MPT quantity This customizes the string conversion and supports XRP conver...
StAmountField(SF const &sfield, SV const &value)
JTxField< SF, SV, OV > Base
TimePointField(SF const &sfield, SV const &value)
JTxField< SF, SV, OV > Base
UInt256Field(SF const &sfield, SV const &value)
unit::ValueUnit< UnitTag, ValueType > SV
T to_string(T... args)
T value_or(T... args)