3#include <test/jtx/Account.h>
4#include <test/jtx/Env.h>
5#include <test/jtx/JTx.h>
6#include <test/jtx/amount.h>
8#include <xrpld/app/misc/TxQ.h>
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/protocol/AccountID.h>
19#include <xrpl/protocol/Asset.h>
20#include <xrpl/protocol/Book.h>
21#include <xrpl/protocol/Indexes.h>
22#include <xrpl/protocol/PathAsset.h>
23#include <xrpl/protocol/PublicKey.h>
24#include <xrpl/protocol/Quality.h>
25#include <xrpl/protocol/SField.h>
26#include <xrpl/protocol/STAmount.h>
27#include <xrpl/protocol/STNumber.h>
28#include <xrpl/protocol/STPathSet.h>
29#include <xrpl/protocol/SeqProxy.h>
30#include <xrpl/protocol/Serializer.h>
31#include <xrpl/protocol/UintTypes.h>
32#include <xrpl/protocol/Units.h>
33#include <xrpl/protocol/XRPAmount.h>
34#include <xrpl/protocol/jss.h>
35#include <xrpl/tx/paths/detail/Steps.h>
46#include <source_location>
64 class StoredValue =
typename SField::type::value_type,
65 class OutputValue = StoredValue>
69 using SV = StoredValue;
70 using OV = OutputValue;
83 [[nodiscard]]
virtual OV
93template <
class SField,
class StoredValue>
97 using SV = StoredValue;
134 return value_.time_since_epoch().count();
223template <
class SField,
class UnitTag,
class ValueType>
228 using OV = ValueType;
246template <
class JTxField>
304template <
class SField,
class UnitTag,
class ValueType =
typename SField::type::value_type>
308template <
class SField,
class StoredValue =
typename SField::type::value_type>
337template <
typename...
IOU>
343 for (
auto const& line : jrr[jss::lines])
345 for (
auto const& iou : {ious...})
347 if (line[jss::currency].asString() ==
to_string(iou.currency))
350 v[jss::currency] = line[jss::currency];
351 v[jss::balance] = line[jss::balance];
352 v[jss::limit] = line[jss::limit];
353 v[jss::account] = line[jss::account];
354 res[jss::lines].
append(v);
395 return strHex(expected) ==
strHex(sle->getFieldVL(field));
414template <
class T,
class... Args>
419 if constexpr (
sizeof...(args) > 0)
423template <
class... Args>
428 if constexpr (
sizeof...(args) > 0)
435template <
class... Args>
444template <
class... Args>
478 template <
class Rep,
class Period>
483 auto b =
cv_.wait_for(lk, relTime, [
this] {
return signaled_; });
543 bool defaultLimits =
false);
545template <
typename... Amts>
610 return create(account.id(), to.
id(), amount, settleDelay, pk, cancelAfter, dstTag);
635 return channel(account.id(), dst.
id(), seqProxyValue);
714template <
class Iter,
class StepInfo,
class... Args>
723template <
class... Args>
725equal(Strand
const& strand, Args&&... args)
727 if (strand.size() !=
sizeof...(Args))
749 jv[sfAccount.jsonName] =
to_string(account);
751 jv[sfDestination.jsonName] =
to_string(dest);
752 jv[sfTransactionType.jsonName] = jss::CheckCreate;
759 return create(account.id(), dest.
id(), sendMax);
773template <
class Suite>
786 int const line = location.line();
787 char const* file = location.file_name();
788 FeeLevel64 const expectedMin{expectedMinFeeLevel};
789 FeeLevel64 const expectedMed{expectedMedFeeLevel};
791 using namespace std::string_literals;
801 metrics.txCount == expectedCount
808 metrics.txQMaxSize == expectedMaxCount
816 metrics.txInLedger == expectedInLedger
824 metrics.txPerLedger == expectedPerLedger
832 metrics.minProcessingFeeLevel == expectedMin
840 metrics.medFeeLevel == expectedMed
848 auto const expectedCurFeeLevel = expectedInLedger > expectedPerLedger
849 ? expectedMed * expectedInLedger * expectedInLedger /
850 (expectedPerLedger * expectedPerLedger)
853 metrics.openLedgerFeeLevel == expectedCurFeeLevel
915 Number principalRequested,
972 :
expiry_{expiry.time_since_epoch().count()}
979 jt[sfExpiration.jsonName] =
expiry_;
999 jt[sfSourceTag.jsonName] =
tag_;
1019 jt[sfDestinationTag.jsonName] =
tag_;
1046template <
typename TTester>
1055template <
typename TTester>
bool isNull() const
isNull() tests to see if this field is null.
Value & append(Value const &value)
Append value to array at the end.
std::chrono::time_point< NetClock > time_point
std::chrono::duration< rep, period > duration
Number is a floating point type that can represent a wide range of values.
json::Value getJson(JsonOptions=JsonOptions::Values::None) const override
std::shared_ptr< STLedgerEntry const > const & ConstRef
std::vector< STPath >::size_type size() const
bool pushBack(STPath const &e)
pushBack adds a path to the set.
std::vector< STPath >::const_iterator end() const
static constexpr SeqProxy rawSequence(std::uint32_t v)
Factory function to return a sequence-based SeqProxy.
std::string getString() const
int addRaw(Blob const &vector)
An immutable linear range of bytes.
Metrics getMetrics(OpenView const &view) const
Returns fee metrics in reference fee level units.
static constexpr FeeLevel64 kBaseLevel
Fee level for single-signed reference transaction.
Immutable cryptographic account descriptor.
AccountID id() const
Returns the Account ID.
void operator()(Env &, JTx &jt) const
DestTag(std::uint32_t tag)
A transaction testing environment.
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
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.
Keylet check(AccountID const &id, SeqProxy const &seq) noexcept
A Check.
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)
auto const kManagementFeeRate
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)
auto const kCoverRateMinimum
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)
auto const kCoverRateLiquidation
json::Value coverClawback(AccountID const &account, std::uint32_t flags)
json::Value manage(AccountID const &account, UInt256 const &loanID, std::uint32_t flags)
auto const kLoanOriginationFee
json::Value set(AccountID const &account, UInt256 const &loanBrokerID, Number principalRequested, std::uint32_t flags)
auto const kPaymentInterval
auto const kLoanServiceFee
auto const kOverpaymentInterestRate
auto const kCloseInterestRate
auto const kOverpaymentFee
auto const kClosePaymentFee
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)
auto const kLatePaymentFee
auto const kLateInterestRate
json::Value claim(AccountID const &account, UInt256 const &channel, std::optional< STAmount > const &balance, std::optional< STAmount > const &amount, std::optional< Slice > const &signature, std::optional< PublicKey > const &pk)
json::Value fund(AccountID const &account, UInt256 const &channel, STAmount const &amount, std::optional< NetClock::time_point > const &expiration)
json::Value create(AccountID const &account, AccountID const &to, STAmount const &amount, NetClock::duration const &settleDelay, PublicKey const &pk, std::optional< NetClock::time_point > const &cancelAfter, std::optional< std::uint32_t > const &dstTag)
STAmount channelBalance(ReadView const &view, UInt256 const &chan)
bool channelExists(ReadView const &view, UInt256 const &chan)
UInt256 channel(AccountID const &account, AccountID const &dst, std::uint32_t seqProxyValue)
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)
bool expectMPT(Env &env, AccountID const &account, STAmount const &value)
JTxFieldWrapper< JTxField< SField, StoredValue > > SimpleField
PrettyAmount xrpMinusFee(Env const &env, std::int64_t xrpAmount)
constexpr FeeLevel64 kMinEscalationFeeLevel
bool expectOffers(Env &env, AccountID const &account, std::uint16_t size, std::vector< Amounts > const &toMatch)
STPathElement allPathElements(AccountID const &a, Asset const &asset)
void testHelper2TokensMix(TTester &&tester)
bool expectHolding(Env &env, AccountID const &account, STAmount const &value, bool defaultLimits)
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)
json::Value getBookOffers(jtx::Env &env, Asset const &takerPays, Asset const &takerGets)
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)
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)
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 ¤cy)
bool equal(STAmount const &sa1, STAmount const &sa2)
STPathElement iape(AccountID const &account)
std::uint32_t sponsoredOwnerCount(Env const &env, Account const &account)
json::Value ledgerEntryRoot(Env &env, Account const &acct)
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)
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)
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).
std::string strHex(FwdIt begin, FwdIt end)
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
BaseUInt< 160, detail::CurrencyTag > Currency
Currency is a hash representing a specific currency.
TypedField< STInteger< std::uint32_t > > SF_UINT32
TypedField< STAmount > SF_AMOUNT
std::string to_string(BaseUInt< Bits, Tag > const &a)
Slice makeSlice(std::array< T, N > const &a)
BaseUInt< 192 > MPTID
MPTID is a 192-bit value representing MPT Issuance ID, which is a concatenation of a 32-bit sequence ...
TypedField< STBlob > SF_VL
FeeLevel< std::uint64_t > FeeLevel64
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
TypedField< STAccount > SF_ACCOUNT
TypedField< STBitString< 256 > > SF_UINT256
OV value() const override
JTxField< SF, SV, OV > Base
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::uint16_t transferFee
std::vector< jtx::Account > holders
JF operator()(std::array< std::uint8_t, N > const &c) const
JF operator()(Slice const &cond) const
JF operator()(SV const &cond) const
JTxFieldWrapper(SF const &sfield)
JTxFieldWrapper(SF const &sfield)
JF operator()(SV const &value) const
void operator()(Env &, JTx &jt) const
JTxField(SF const &sfield, SV value)
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 OV value() const=0
virtual ~JTxField()=default
Execution context for applying a JSON transaction.
Represents an XRP, IOU, or MPT quantity This customizes the string conversion and supports XRP conver...
StAmountField(SF const &sfield, SV const &value)
OV value() const override
JTxField< SF, SV, OV > Base
TimePointField(SF const &sfield, SV const &value)
JTxField< SF, SV, OV > Base
OV value() const override
JTxField< SF, SV, OV > Base
OV value() const override
UInt256Field(SF const &sfield, SV const &value)
JTxField< SF, SV, OV > Base
unit::ValueUnit< UnitTag, ValueType > SV
OV value() const override