1#ifndef XRPL_TEST_JTX_TESTHELPERS_H_INCLUDED
2#define XRPL_TEST_JTX_TESTHELPERS_H_INCLUDED
4#include <test/jtx/Env.h>
6#include <xrpld/app/misc/TxQ.h>
8#include <xrpl/basics/base_uint.h>
9#include <xrpl/beast/unit_test/suite.h>
10#include <xrpl/json/json_value.h>
11#include <xrpl/protocol/AccountID.h>
12#include <xrpl/protocol/Quality.h>
13#include <xrpl/protocol/STNumber.h>
14#include <xrpl/protocol/TxFlags.h>
15#include <xrpl/protocol/Units.h>
16#include <xrpl/protocol/jss.h>
20#if (defined(__clang_major__) && __clang_major__ < 15)
21#include <experimental/source_location>
24#include <source_location>
39 class StoredValue =
typename SField::type::value_type,
40 class OutputValue = StoredValue>
44 using SV = StoredValue;
45 using OV = OutputValue;
69template <
class SField,
class StoredValue>
73 using SV = StoredValue;
94 :
public JTxField<SF_UINT32, NetClock::time_point, NetClock::rep>
206template <
class SField,
class UnitTag,
class ValueType>
208 :
public JTxField<SField, unit::ValueUnit<UnitTag, ValueType>, ValueType>
212 using OV = ValueType;
230template <
class JTxField>
290 class ValueType =
typename SField::type::value_type>
294template <
class SField,
class StoredValue =
typename SField::type::value_type>
307template <
typename Input>
310 requires requires(Input& v) {
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);
386 return strHex(expected) ==
strHex(sle->getFieldVL(field));
404template <
class T,
class... Args>
409 if constexpr (
sizeof...(args) > 0)
413template <
class... Args>
418 if constexpr (
sizeof...(args) > 0)
429template <
class... Args>
438template <
class... Args>
447 for (
auto const& p : st2)
468 bool defaultLimits =
false);
470template <
typename... Amts>
498 Account
const& acct_a,
499 Account
const& acct_b,
536 account.id(), to.
id(),
amount, settleDelay, pk, cancelAfter, dstTag);
564 return channel(account.id(), dst.
id(), seqProxyValue);
610 jv[sfAccount.jsonName] =
to_string(account);
612 jv[sfDestination.jsonName] =
to_string(dest);
613 jv[sfTransactionType.jsonName] = jss::CheckCreate;
624 return create(account.id(), dest.
id(), sendMax);
632template <
class Suite>
645 int line = location.line();
646 char const* file = location.file_name();
647 FeeLevel64 const expectedMin{expectedMinFeeLevel};
648 FeeLevel64 const expectedMed{expectedMedFeeLevel};
650 using namespace std::string_literals;
661 metrics.txCount == expectedCount
669 metrics.txQMaxSize == expectedMaxCount
672 "txQMaxSize: "s +
std::to_string(metrics.txQMaxSize.value_or(0)) +
677 metrics.txInLedger == expectedInLedger
685 metrics.txPerLedger == expectedPerLedger
693 metrics.minProcessingFeeLevel == expectedMin
696 "minProcessingFeeLevel: "s +
702 metrics.medFeeLevel == expectedMed
710 auto const expectedCurFeeLevel = expectedInLedger > expectedPerLedger
711 ? expectedMed * expectedInLedger * expectedInLedger /
712 (expectedPerLedger * expectedPerLedger)
713 : metrics.referenceFeeLevel;
715 metrics.openLedgerFeeLevel == expectedCurFeeLevel
718 "openLedgerFeeLevel: "s +
728namespace loanBroker {
779 Number principalRequested,
Value & append(Value const &value)
Append value to array at the end.
bool isNull() const
isNull() tests to see if this field is null.
A currency issued by an account.
std::chrono::time_point< NetClock > time_point
Json::StaticString const jsonName
Json::Value getJson(JsonOptions=JsonOptions::none) const override
std::vector< STPath >::const_iterator begin() const
void push_back(STPath const &e)
std::vector< STPath >::size_type size() const
std::vector< STPath >::const_iterator end() const
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 baseLevel
Fee level for single-signed reference transaction.
Immutable cryptographic account descriptor.
AccountID id() const
Returns the Account ID.
A transaction testing environment.
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Converts to IOU Issue or STAmount.
constexpr value_type value() const
Returns the underlying value.
constexpr value_type fee() const
Returns the number of drops.
Json::Value create(A const &account, A const &dest, STAmount const &sendMax)
Create a check.
auto const coverRateMinimum
Json::Value coverDeposit(AccountID const &account, uint256 const &brokerID, STAmount const &amount, uint32_t flags)
auto const coverRateLiquidation
Json::Value coverWithdraw(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)
auto const managementFeeRate
auto const loanOriginationFee
auto const loanServiceFee
Json::Value pay(AccountID const &account, uint256 const &loanID, STAmount const &amount, std::uint32_t flags)
auto const paymentInterval
auto const overpaymentFee
auto const lateInterestRate
auto const latePaymentFee
auto const overpaymentInterestRate
auto const closePaymentFee
Json::Value manage(AccountID const &account, uint256 const &loanID, std::uint32_t flags)
auto const closeInterestRate
Json::Value del(AccountID const &account, uint256 const &loanID, std::uint32_t flags)
STAmount channelBalance(ReadView const &view, uint256 const &chan)
uint256 channel(AccountID const &account, AccountID const &dst, std::uint32_t seqProxyValue)
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)
bool channelExists(ReadView const &view, uint256 const &chan)
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)
static constexpr FeeLevel64 baseFeeLevel
auto make_vector(Input const &input)
bool expectLedgerEntryRoot(Env &env, Account const &acct, STAmount const &expectedValue)
Json::Value getAccountOffers(Env &env, AccountID const &acct, bool current)
PrettyAmount xrpMinusFee(Env const &env, std::int64_t xrpAmount)
auto const data
General field definitions, or fields used in multiple transaction namespaces.
bool expectOffers(Env &env, AccountID const &account, std::uint16_t size, std::vector< Amounts > const &toMatch)
bool expectHolding(Env &env, AccountID const &account, STAmount const &value, bool defaultLimits)
Json::Value ledgerEntryState(Env &env, Account const &acct_a, Account const &acct_b, std::string const ¤cy)
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)
STPathElement allpe(AccountID const &a, Issue const &iss)
void stpathset_append(STPathSet &st, STPath const &p, Args const &... args)
void stpath_append(STPath &st, T const &t, Args const &... args)
Json::Value accountBalance(Env &env, Account const &acct)
STPathElement IPE(Issue const &iss)
STPathElement cpe(Currency const &c)
Json::Value ledgerEntryRoot(Env &env, Account const &acct)
bool equal(STAmount const &sa1, STAmount const &sa2)
bool checkArraySize(Json::Value const &val, unsigned int size)
STPath stpath(Args const &... args)
void stpath_append_one(STPath &st, Account const &account)
void n_offers(Env &env, std::size_t n, Account const &account, STAmount const &in, STAmount const &out)
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=baseFeeLevel.fee(), std::uint64_t expectedMedFeeLevel=minEscalationFeeLevel.fee(), source_location const location=source_location::current())
bool checkVL(Slice const &result, std::string const &expected)
Json::Value getAccountLines(Env &env, AccountID const &acctId)
static constexpr FeeLevel64 minEscalationFeeLevel
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
bool set(T &target, std::string const &name, Section const §ion)
Set a value from a configuration Section If the named value is not found or doesn't parse as a T,...
TypedField< STAmount > SF_AMOUNT
std::string to_string(base_uint< Bits, Tag > const &a)
std::string strHex(FwdIt begin, FwdIt end)
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
TypedField< STBlob > SF_VL
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
@ current
This was a new validation and was added.
TypedField< STBitString< 256 > > SF_UINT256
TypedField< STAccount > SF_ACCOUNT
std::enable_if_t< std::is_same< T, char >::value||std::is_same< T, unsigned char >::value, Slice > makeSlice(std::array< T, N > const &a)
TypedField< STInteger< std::uint32_t > > SF_UINT32
FeeLevel64 referenceFeeLevel
Reference transaction fee level.
A field with a type known at compile time.
JF operator()(std::array< std::uint8_t, N > const &c) const
JTxFieldWrapper(SF const &sfield)
JF operator()(SV const &cond) const
JF operator()(Slice const &cond) const
JTxFieldWrapper(SF const &sfield)
JF operator()(SV const &value) const
void operator()(Env &, JTx &jt) const
JTxField(SF const &sfield, SV const &value)
Generic helper class for helper classes that set a field on a JTx.
JTxField(SF const &sfield, SV const &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 or IOU quantity This customizes the string conversion and supports XRP conversions ...
OV value() const override
accountIDField(SF const &sfield, SV const &value)
blobField(SF const &sfield, Slice const &cond)
blobField(SF const &sfield, std::array< std::uint8_t, N > const &c)
OV value() const override
stAmountField(SF const &sfield, SV const &value)
OV value() const override
timePointField(SF const &sfield, SV const &value)
OV value() const override
uint256Field(SF const &sfield, SV const &value)
unit::ValueUnit< UnitTag, ValueType > SV
OV value() const override
T time_since_epoch(T... args)