20#ifndef RIPPLE_TEST_JTX_TESTHELPERS_H_INCLUDED
21#define RIPPLE_TEST_JTX_TESTHELPERS_H_INCLUDED
23#include <test/jtx/Env.h>
25#include <xrpl/basics/base_uint.h>
26#include <xrpl/beast/unit_test/suite.h>
27#include <xrpl/json/json_value.h>
28#include <xrpl/protocol/AccountID.h>
29#include <xrpl/protocol/Quality.h>
30#include <xrpl/protocol/TxFlags.h>
31#include <xrpl/protocol/jss.h>
35#if (defined(__clang_major__) && __clang_major__ < 15)
36#include <experimental/source_location>
39#include <source_location>
51template <
typename Input>
54 requires requires(Input& v) {
81template <
typename...
IOU>
87 for (
auto const& line : jrr[jss::lines])
89 for (
auto const& iou : {ious...})
91 if (line[jss::currency].asString() ==
to_string(iou.currency))
94 v[jss::currency] = line[jss::currency];
95 v[jss::balance] = line[jss::balance];
96 v[jss::limit] = line[jss::limit];
97 v[jss::account] = line[jss::account];
129template <
class T,
class... Args>
134 if constexpr (
sizeof...(args) > 0)
138template <
class... Args>
143 if constexpr (
sizeof...(args) > 0)
154template <
class... Args>
163template <
class... Args>
172 for (
auto const& p : st2)
193 bool defaultLimits =
false);
195template <
typename... Amts>
203 return expectLine(env, account, value,
false) &&
223 Account
const& acct_a,
224 Account
const& acct_b,
260 account.id(), to.
id(), amount, settleDelay, pk, cancelAfter, dstTag);
288 return channel(account.id(), dst.
id(), seqProxyValue);
327 requires std::is_same_v<A, AccountID>
332 jv[sfAccount.jsonName] =
to_string(account);
334 jv[sfDestination.jsonName] =
to_string(dest);
335 jv[sfTransactionType.jsonName] = jss::CheckCreate;
346 return create(account.id(), dest.
id(), sendMax);
354template <
class Suite>
367 int line = location.line();
368 char const* file = location.file_name();
369 FeeLevel64 const expectedMin{expectedMinFeeLevel};
370 FeeLevel64 const expectedMed{expectedMedFeeLevel};
372 using namespace std::string_literals;
383 metrics.txCount == expectedCount
391 metrics.txQMaxSize == expectedMaxCount
394 "txQMaxSize: "s +
std::to_string(metrics.txQMaxSize.value_or(0)) +
399 metrics.txInLedger == expectedInLedger
407 metrics.txPerLedger == expectedPerLedger
415 metrics.minProcessingFeeLevel == expectedMin
418 "minProcessingFeeLevel: "s +
424 metrics.medFeeLevel == expectedMed
432 auto const expectedCurFeeLevel = expectedInLedger > expectedPerLedger
433 ? expectedMed * expectedInLedger * expectedInLedger /
434 (expectedPerLedger * expectedPerLedger)
435 : metrics.referenceFeeLevel;
437 metrics.openLedgerFeeLevel == expectedCurFeeLevel
440 "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.
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
Metrics getMetrics(OpenView const &view) const
Returns fee metrics in reference fee level units.
constexpr value_type value() const
Returns the underlying value.
constexpr value_type fee() const
Returns the number of drops.
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.
Json::Value create(A const &account, A const &dest, STAmount const &sendMax)
Create a check.
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)
bool expectOffers(Env &env, AccountID const &account, std::uint16_t size, std::vector< Amounts > const &toMatch)
STAmount channelBalance(ReadView const &view, uint256 const &chan)
uint256 channel(AccountID const &account, AccountID const &dst, std::uint32_t seqProxyValue)
PrettyAmount xrpMinusFee(Env const &env, std::int64_t xrpAmount)
bool expectLine(Env &env, AccountID const &account, STAmount const &value, bool defaultLimits)
bool equal(STAmount const &sa1, STAmount const &sa2)
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 fund(jtx::Env &env, jtx::Account const &gw, std::vector< jtx::Account > const &accounts, std::vector< STAmount > const &amts, Fund how)
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())
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)
static constexpr FeeLevel64 baseFeeLevel
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)
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)
bool channelExists(ReadView const &view, uint256 const &chan)
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.
@ current
This was a new validation and was added.
std::string to_string(base_uint< Bits, Tag > const &a)
FeeLevel64 referenceFeeLevel
Reference transaction fee level.
Represents an XRP or IOU quantity This customizes the string conversion and supports XRP conversions ...