3#include <test/jtx/AbstractClient.h>
4#include <test/jtx/Account.h>
5#include <test/jtx/JTx.h>
6#include <test/jtx/ManualTimeKeeper.h>
7#include <test/jtx/amount.h>
8#include <test/jtx/envconfig.h>
9#include <test/jtx/require.h>
10#include <test/jtx/tags.h>
11#include <test/jtx/vault.h>
12#include <test/unit_test/SuiteJournal.h>
14#include <xrpld/app/ledger/OpenLedger.h>
15#include <xrpld/app/main/Application.h>
16#include <xrpld/core/Config.h>
17#include <xrpld/rpc/detail/Pathfinder.h>
19#include <xrpl/basics/Log.h>
20#include <xrpl/basics/chrono.h>
21#include <xrpl/beast/utility/Journal.h>
22#include <xrpl/json/json_value.h>
23#include <xrpl/json/to_string.h>
24#include <xrpl/ledger/Ledger.h>
25#include <xrpl/protocol/ApiVersion.h>
26#include <xrpl/protocol/Feature.h>
27#include <xrpl/protocol/Indexes.h>
28#include <xrpl/protocol/Issue.h>
29#include <xrpl/protocol/STAmount.h>
30#include <xrpl/protocol/STObject.h>
31#include <xrpl/protocol/STTx.h>
35#include <source_location>
68template <
class... Args>
72 return {{account, args...}};
82 for (
auto const& [s, vote] : sa)
110 for (
auto const& f : features)
112 auto const n = result.
size();
323 template <
class... Args>
325 rpc(
unsigned apiVersion,
330 template <
class... Args>
334 template <
class... Args>
340 template <
class... Args>
399 template <
class Rep,
class Period>
453 app().getNumberOfThreads() == 1,
454 "syncClose() is only useful on an application with a single thread");
455 auto const result =
close();
457 auto future = serverBarrier->get_future();
458 boost::asio::post(
app().getIOContext(), [serverBarrier]() { serverBarrier->set_value(); });
459 auto const status = future.wait_for(timeout);
460 return result && status == std::future_status::ready;
500 [[nodiscard]]
unsigned
564 template <
class JsonValue,
class... FN>
566 jt(JsonValue&& jv, FN
const&... fN)
576 template <
class JsonValue,
class... FN>
590 template <
class JsonValue,
class... FN>
592 json(JsonValue&& jv, FN
const&... fN)
595 return std::move(tj.jv);
603 template <
class... Args>
636 ParsedResult
const& parsed,
642 template <
class... FN>
650 template <
class... FN>
658 template <
class... FN>
662 return apply(std::move(jv), fN...);
665 template <
class... FN>
669 return apply(std::move(jv), fN...);
717 return current()->rules().enabled(feature);
727 fund(
true, amount, account);
730 template <std::
size_t N>
734 for (
auto const& account : list)
735 fund(
false, amount, account);
765 template <
class Arg,
class... Args>
770 if constexpr (
sizeof...(args) > 0)
771 fund(amount, args...);
795 template <
class... Accounts>
800 trust(amount, to1, toN...);
843 template <
class... FN>
847 (fN(*
this, stx), ...);
851 template <
class... FN>
855 (fN(*
this,
jt), ...);
862template <
class... Args>
873template <
class... Args>
884template <
class... Args>
897template <
class... Args>
A generic endpoint for log messages.
virtual bool checkSigs() const =0
A currency issued by an account.
beast::Severity threshold() const
Logs(beast::Severity level)
std::chrono::time_point< NetClock > time_point
std::shared_ptr< OpenView const > current() const
Returns a view to the current open ledger.
static void initPathTable()
std::shared_ptr< STLedgerEntry const > const_pointer
virtual OpenLedger & getOpenLedger()=0
time_point now() const override
Returns the current time.
Immutable cryptographic account descriptor.
static Account const kMaster
The master account.
A transaction testing environment.
bool close(std::chrono::duration< Rep, Period > const &elapsed)
Close and advance the ledger.
void notrace()
Turn off JSON tracing.
bool syncClose(std::chrono::steady_clock::duration timeout=std::chrono::seconds{1})
Close and advance the ledger, then synchronize with the server's io_context to ensure all async opera...
std::shared_ptr< STTx const > st(JTx const &jt)
Create a STTx from a JTx The framework requires that JSON is valid.
TER ter() const
Return the TER for the last JTx.
void invoke(JTx &jt, FN const &... fN)
void setRetries(unsigned r=5)
void disableSigs()
Turn off signature checks.
void fund(STAmount const &amount, Arg const &arg, Args const &... args)
Create a new account with some XRP.
Env(beast::unit_test::Suite &suite, FeatureBitset features, std::unique_ptr< Logs > logs=nullptr)
Create Env with default config and specified features.
Env(beast::unit_test::Suite &suite, beast::Severity thresh=beast::Severity::Error)
Create Env with only the current test suite.
Env(beast::unit_test::Suite &suite, std::unique_ptr< Config > config, std::unique_ptr< Logs > logs=nullptr, beast::Severity thresh=beast::Severity::Error)
Create Env using suite and Config pointer.
Env & operator()(WithSourceLocation< JTx > jv, FN const &... fN)
json::Value json(JsonValue &&jv, FN const &... fN)
Create JSON from parameters.
SLE::const_pointer le(Account const &account) const
Return an account root.
std::uint32_t ownerCount(Account const &account) const
Return the number of objects owned by an account.
void fundArg(STAmount const &amount, std::array< Account, N > const &list)
std::shared_ptr< ReadView const > closed()
Returns the last closed ledger.
static ParsedResult parseResult(json::Value const &jr)
Gets the TER result and didApply flag from a RPC Json result object.
Account const & lookup(AccountID const &id) const
Returns the Account given the AccountID.
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
virtual void submit(JTx const &jt, std::source_location const &loc=std::source_location::current())
Submit an existing JTx.
Env(beast::unit_test::Suite &suite, std::unique_ptr< Config > config, FeatureBitset features, std::unique_ptr< Logs > logs=nullptr, beast::Severity thresh=beast::Severity::Error)
Create Env using suite, Config pointer, and explicit features.
void enableFeature(uint256 const feature)
Env & apply(WithSourceLocation< JTx > jv, FN const &... fN)
PrettyAmount limit(Account const &account, Issue const &issue) const
Returns the IOU limit on an account.
void disableFeature(uint256 const feature)
json::Value doRpc(unsigned apiVersion, std::vector< std::string > const &args, std::unordered_map< std::string, std::string > const &headers={})
std::uint32_t seq(Account const &account) const
Returns the next sequence number on account.
virtual void autofill(JTx &jt)
void postconditions(JTx const &jt, ParsedResult const &parsed, json::Value const &jr=json::Value(), std::source_location const &loc=std::source_location::current())
Check expected postconditions of JTx submission.
bool close()
Close and advance the ledger.
json::Value rpc(unsigned apiVersion, std::unordered_map< std::string, std::string > const &headers, std::string const &cmd, Args &&... args)
Execute an RPC command.
void setParseFailureExpected(bool b)
Application const & app() const
void autofillSig(JTx &jt)
void signAndSubmit(JTx const &jt, json::Value params=json::ValueType::Null, std::source_location const &loc=std::source_location::current())
Use the submit RPC command with a provided JTx object.
Env & operator()(WithSourceLocation< json::Value > jv, FN const &... fN)
JTx jt(JsonValue &&jv, FN const &... fN)
Create a JTx from parameters.
PrettyAmount balance(Account const &account) const
Returns the XRP balance on an account.
beast::unit_test::Suite & test
void trust(STAmount const &amount, Account const &to0, Account const &to1, Accounts const &... toN)
void trust(STAmount const &amount, Account const &account)
Establish trust lines.
std::shared_ptr< STTx const > ust(JTx const &jt)
Create a STTx from a JTx without sanitizing Use to inject bogus values into test transactions by firs...
std::shared_ptr< STObject const > meta()
Return metadata for the last JTx.
Env & apply(WithSourceLocation< json::Value > jv, FN const &... fN)
Apply funclets and submit.
JTx jtnofill(JsonValue &&jv, FN const &... fN)
Create a JTx from parameters.
void invoke(STTx &stx, FN const &... fN)
std::unordered_map< AccountID, Account > map_
void fundArg(STAmount const &amount, Account const &account)
ManualTimeKeeper & timeKeeper()
bool parseFailureExpected_
std::shared_ptr< STTx const > tx() const
Return the tx data for the last JTx.
bool enabled(uint256 feature) const
Env & operator=(Env const &)=delete
void memoize(Account const &account)
Associate AccountID with account.
beast::Journal const journal
AbstractClient & client()
Returns the connected client.
void require(Args const &... args)
Check a set of requirements.
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
NetClock::time_point now()
Returns the current network time.
void trace(int howMany=-1)
Turn on JSON tracing.
~SuiteLogs() override=default
beast::unit_test::Suite & suite_
SuiteLogs(beast::unit_test::Suite &suite)
std::unique_ptr< beast::Journal::Sink > makeSink(std::string const &partition, beast::Severity threshold) override
Severity
Severity level / threshold of a Journal message.
static constexpr auto kApiCommandLineVersion
std::vector< FeatureBitset > amendmentCombinations(std::initializer_list< uint256 > features, FeatureBitset seed)
Returns all 2^N permutations of a seed FeatureBitset with each subset of the given features excluded.
require_t required(Args const &... args)
Compose many condition functors into one.
FeatureBitset testableAmendments()
std::array< Account, 1+sizeof...(Args)> noripple(Account const &account, Args const &... args)
Designate accounts as no-ripple in Env::fund.
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
void foreachFeature(FeatureBitset bs, F &&f)
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
std::map< std::string, AmendmentSupport > const & allAmendments()
All amendments libxrpl knows about.
TERSubset< CanCvtToTER > TER
beast::ManualClock< std::chrono::steady_clock > TestStopwatch
A manual Stopwatch for unit tests.
std::optional< uint256 > getRegisteredFeature(std::string const &name)
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
A pair of SHAMap key and LedgerEntryType.
ManualTimeKeeper * timeKeeper
std::unique_ptr< AbstractClient > client
std::unique_ptr< Application > owned
Used by parseResult() and postConditions().
std::optional< ErrorCodeI > rpcCode
Execution context for applying a JSON transaction.
Represents an XRP, IOU, or MPT quantity This customizes the string conversion and supports XRP conver...
Wrapper that captures std::source_location when implicitly constructed.
WithSourceLocation(T v, std::source_location l=std::source_location::current())