20#ifndef RIPPLE_TEST_JTX_TESTHELPERS_H_INCLUDED
21#define RIPPLE_TEST_JTX_TESTHELPERS_H_INCLUDED
23#include <test/jtx/Env.h>
25#include <xrpld/app/misc/TxQ.h>
27#include <xrpl/basics/base_uint.h>
28#include <xrpl/beast/unit_test/suite.h>
29#include <xrpl/json/json_value.h>
30#include <xrpl/protocol/AccountID.h>
31#include <xrpl/protocol/Quality.h>
32#include <xrpl/protocol/STNumber.h>
33#include <xrpl/protocol/TxFlags.h>
34#include <xrpl/protocol/Units.h>
35#include <xrpl/protocol/jss.h>
39#if (defined(__clang_major__) && __clang_major__ < 15)
40#include <experimental/source_location>
43#include <source_location>
58 class StoredValue =
typename SField::type::value_type,
59 class OutputValue = StoredValue>
63 using SV = StoredValue;
64 using OV = OutputValue;
88template <
class SField,
class StoredValue>
92 using SV = StoredValue;
113 :
public JTxField<SF_UINT32, NetClock::time_point, NetClock::rep>
202template <
class SField,
class UnitTag,
class ValueType>
204 :
public JTxField<SField, unit::ValueUnit<UnitTag, ValueType>, ValueType>
208 using OV = ValueType;
226template <
class JTxField>
286 class ValueType =
typename SField::type::value_type>
290template <
class SField,
class StoredValue =
typename SField::type::value_type>
301template <
typename Input>
304 requires requires(Input& v) {
331template <
typename...
IOU>
337 for (
auto const& line : jrr[jss::lines])
339 for (
auto const& iou : {ious...})
341 if (line[jss::currency].asString() ==
to_string(iou.currency))
344 v[jss::currency] = line[jss::currency];
345 v[jss::balance] = line[jss::balance];
346 v[jss::limit] = line[jss::limit];
347 v[jss::account] = line[jss::account];
348 res[jss::lines].
append(v);
380 return strHex(expected) ==
strHex(sle->getFieldVL(field));
398template <
class T,
class... Args>
403 if constexpr (
sizeof...(args) > 0)
407template <
class... Args>
412 if constexpr (
sizeof...(args) > 0)
423template <
class... Args>
432template <
class... Args>
441 for (
auto const& p : st2)
462 bool defaultLimits =
false);
464template <
typename... Amts>
492 Account
const& acct_a,
493 Account
const& acct_b,
530 account.id(), to.
id(), amount, settleDelay, pk, cancelAfter, dstTag);
558 return channel(account.id(), dst.
id(), seqProxyValue);
604 jv[sfAccount.jsonName] =
to_string(account);
606 jv[sfDestination.jsonName] =
to_string(dest);
607 jv[sfTransactionType.jsonName] = jss::CheckCreate;
618 return create(account.id(), dest.
id(), sendMax);
626template <
class Suite>
639 int line = location.line();
640 char const* file = location.file_name();
641 FeeLevel64 const expectedMin{expectedMinFeeLevel};
642 FeeLevel64 const expectedMed{expectedMedFeeLevel};
644 using namespace std::string_literals;
655 metrics.txCount == expectedCount
663 metrics.txQMaxSize == expectedMaxCount
666 "txQMaxSize: "s +
std::to_string(metrics.txQMaxSize.value_or(0)) +
671 metrics.txInLedger == expectedInLedger
679 metrics.txPerLedger == expectedPerLedger
687 metrics.minProcessingFeeLevel == expectedMin
690 "minProcessingFeeLevel: "s +
696 metrics.medFeeLevel == expectedMed
704 auto const expectedCurFeeLevel = expectedInLedger > expectedPerLedger
705 ? expectedMed * expectedInLedger * expectedInLedger /
706 (expectedPerLedger * expectedPerLedger)
707 : metrics.referenceFeeLevel;
709 metrics.openLedgerFeeLevel == expectedCurFeeLevel
712 "openLedgerFeeLevel: "s +
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 end() const
void push_back(STPath const &e)
std::vector< STPath >::const_iterator begin() const
std::vector< STPath >::size_type size() const
int addRaw(Blob const &vector)
std::string getString() const
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 fee() const
Returns the number of drops.
constexpr value_type value() const
Returns the underlying value.
Json::Value create(A const &account, A const &dest, STAmount const &sendMax)
Create a check.
bool channelExists(ReadView const &view, uint256 const &chan)
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)
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)
STAmount channelBalance(ReadView const &view, uint256 const &chan)
static constexpr FeeLevel64 minEscalationFeeLevel
bool checkArraySize(Json::Value const &val, unsigned int size)
std::uint32_t ownerCount(Env const &env, Account const &account)
Json::Value ledgerEntryRoot(Env &env, Account const &acct)
auto make_vector(Input const &input)
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)
PrettyAmount xrpMinusFee(Env const &env, std::int64_t xrpAmount)
bool equal(STAmount const &sa1, STAmount const &sa2)
bool checkVL(Slice const &result, std::string const &expected)
Json::Value getAccountLines(Env &env, AccountID const &acctId)
bool same(STPathSet const &st1, Args const &... args)
Json::Value ledgerEntryState(Env &env, Account const &acct_a, Account const &acct_b, std::string const ¤cy)
void stpath_append_one(STPath &st, Account const &account)
void stpath_append(STPath &st, T const &t, Args const &... args)
void n_offers(Env &env, std::size_t n, Account const &account, STAmount const &in, STAmount const &out)
Json::Value accountBalance(Env &env, Account const &acct)
STPathElement IPE(Issue const &iss)
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())
static constexpr FeeLevel64 baseFeeLevel
bool expectHolding(Env &env, AccountID const &account, STAmount const &value, bool defaultLimits)
void stpathset_append(STPathSet &st, STPath const &p, Args const &... args)
STPathElement cpe(Currency const &c)
bool expectLedgerEntryRoot(Env &env, Account const &acct, STAmount const &expectedValue)
STPathElement allpe(AccountID const &a, Issue const &iss)
XRPAmount txfee(Env const &env, std::uint16_t n)
STPath stpath(Args const &... args)
Json::Value getAccountOffers(Env &env, AccountID const &acct, bool current)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
TypedField< STBlob > SF_VL
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
TypedField< STBitString< 256 > > SF_UINT256
TypedField< STInteger< std::uint32_t > > SF_UINT32
TypedField< STAccount > SF_ACCOUNT
@ current
This was a new validation and was added.
std::string strHex(FwdIt begin, FwdIt end)
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)
std::string to_string(base_uint< Bits, Tag > const &a)
FeeLevel64 referenceFeeLevel
Reference transaction fee level.
A field with a type known at compile time.
JF operator()(SV const &cond) const
JTxFieldWrapper(SF const &sfield)
JF operator()(std::array< std::uint8_t, N > const &c) const
JF operator()(Slice const &cond) const
JTxFieldWrapper(SF const &sfield)
JF operator()(SV const &value) const
JTxField(SF const &sfield, SV const &value)
void operator()(Env &, JTx &jt) const
Generic helper class for helper clases that set a field on a JTx.
virtual OV value() const =0
JTxField(SF const &sfield, SV const &value)
virtual ~JTxField()=default
virtual void operator()(Env &, JTx &jt) const
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
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)