20#ifndef RIPPLE_TEST_JTX_ENV_H_INCLUDED
21#define RIPPLE_TEST_JTX_ENV_H_INCLUDED
23#include <test/jtx/AbstractClient.h>
24#include <test/jtx/Account.h>
25#include <test/jtx/JTx.h>
26#include <test/jtx/ManualTimeKeeper.h>
27#include <test/jtx/amount.h>
28#include <test/jtx/envconfig.h>
29#include <test/jtx/require.h>
30#include <test/jtx/tags.h>
31#include <test/jtx/vault.h>
32#include <test/unit_test/SuiteJournal.h>
34#include <xrpld/app/ledger/Ledger.h>
35#include <xrpld/app/ledger/OpenLedger.h>
36#include <xrpld/app/main/Application.h>
37#include <xrpld/app/paths/Pathfinder.h>
38#include <xrpld/core/Config.h>
39#include <xrpld/rpc/detail/RPCHelpers.h>
41#include <xrpl/basics/Log.h>
42#include <xrpl/basics/chrono.h>
43#include <xrpl/beast/utility/Journal.h>
44#include <xrpl/json/json_value.h>
45#include <xrpl/json/to_string.h>
46#include <xrpl/protocol/Feature.h>
47#include <xrpl/protocol/Indexes.h>
48#include <xrpl/protocol/Issue.h>
49#include <xrpl/protocol/STAmount.h>
50#include <xrpl/protocol/STObject.h>
51#include <xrpl/protocol/STTx.h>
66template <
class... Args>
70 return {{account, args...}};
80 for (
auto const& [s, vote] : sa)
86 Throw<std::runtime_error>(
87 "Unknown feature: " + s +
" in allAmendments.");
190 ,
bundle_(suite_,
std::move(config),
std::move(logs), thresh)
196 features, [&appFeats =
app().config().features](
uint256 const& f) {
301 template <
class... Args>
303 rpc(
unsigned apiVersion,
308 template <
class... Args>
312 template <
class... Args>
318 template <
class... Args>
377 template <
class Rep,
class Period>
506 template <
class JsonValue,
class... FN>
508 jt(JsonValue&& jv, FN
const&... fN)
518 template <
class JsonValue,
class... FN>
532 template <
class JsonValue,
class... FN>
534 json(JsonValue&& jv, FN
const&... fN)
537 return std::move(tj.jv);
545 template <
class... Args>
575 ParsedResult
const& parsed,
580 template <
class JsonValue,
class... FN>
582 apply(JsonValue&& jv, FN
const&... fN)
588 template <
class JsonValue,
class... FN>
640 return current()->rules().enabled(feature);
650 fund(
true, amount, account);
653 template <std::
size_t N>
657 for (
auto const& account : list)
658 fund(
false, amount, account);
688 template <
class Arg,
class... Args>
693 if constexpr (
sizeof...(args) > 0)
694 fund(amount, args...);
718 template <
class... Accounts>
724 Accounts
const&... toN)
727 trust(amount, to1, toN...);
770 template <
class... FN>
774 (fN(*
this, stx), ...);
778 template <
class... FN>
782 (fN(*
this,
jt), ...);
789template <
class... Args>
803template <
class... Args>
814template <
class... Args>
827template <
class... Args>
A generic endpoint for log messages.
virtual OpenLedger & openLedger()=0
virtual bool checkSigs() const =0
A currency issued by an account.
Manages partitions for logging.
beast::severities::Severity threshold() const
std::shared_ptr< OpenView const > current() const
Returns a view to the current open ledger.
static void initPathTable()
time_point now() const override
Returns the current time.
Immutable cryptographic account descriptor.
static Account const master
The master account.
A transaction testing environment.
void fund_arg(STAmount const &amount, std::array< Account, N > const &list)
Json::Value json(JsonValue &&jv, FN const &... fN)
Create JSON from parameters.
std::shared_ptr< ReadView const > closed()
Returns the last closed ledger.
void trace(int howMany=-1)
Turn on JSON tracing.
void disableFeature(uint256 const feature)
bool parseFailureExpected_
static ParsedResult parseResult(Json::Value const &jr)
Gets the TER result and didApply flag from a RPC Json result object.
Env(beast::unit_test::suite &suite_, std::unique_ptr< Config > config, std::unique_ptr< Logs > logs=nullptr, beast::severities::Severity thresh=beast::severities::kError)
Create Env using suite and Config pointer.
std::uint32_t ownerCount(Account const &account) const
Return the number of objects owned by an account.
std::unordered_map< AccountID, Account > map_
void notrace()
Turn off JSON tracing.
void require(Args const &... args)
Check a set of requirements.
void trust(STAmount const &amount, Account const &to0, Account const &to1, Accounts const &... toN)
TER ter() const
Return the TER for the last JTx.
beast::unit_test::suite & test
bool close(std::chrono::duration< Rep, Period > const &elapsed)
Close and advance the ledger.
PrettyAmount limit(Account const &account, Issue const &issue) const
Returns the IOU limit on an account.
std::shared_ptr< STTx const > tx() const
Return the tx data for the last JTx.
void invoke(JTx &jt, FN const &... fN)
Env & operator=(Env const &)=delete
Env & operator()(JsonValue &&jv, FN const &... fN)
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
void postconditions(JTx const &jt, ParsedResult const &parsed, Json::Value const &jr=Json::Value())
Check expected postconditions of JTx submission.
bool enabled(uint256 feature) const
void sign_and_submit(JTx const &jt, Json::Value params=Json::nullValue)
Use the submit RPC command with a provided JTx object.
AbstractClient & client()
Returns the connected client.
void autofill_sig(JTx &jt)
void trust(STAmount const &amount, Account const &account)
Establish trust lines.
void fund(STAmount const &amount, Arg const &arg, Args const &... args)
Create a new account with some XRP.
Json::Value do_rpc(unsigned apiVersion, std::vector< std::string > const &args, std::unordered_map< std::string, std::string > const &headers={})
void invoke(STTx &stx, FN const &... fN)
std::shared_ptr< STTx const > st(JTx const &jt)
Create a STTx from a JTx The framework requires that JSON is valid.
void enableFeature(uint256 const feature)
Env(beast::unit_test::suite &suite_)
Create Env with only the current test suite.
Account const & lookup(AccountID const &id) const
Returns the Account given the AccountID.
JTx jt(JsonValue &&jv, FN const &... fN)
Create a JTx from parameters.
NetClock::time_point now()
Returns the current network time.
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...
beast::Journal const journal
ManualTimeKeeper & timeKeeper()
Json::Value rpc(unsigned apiVersion, std::unordered_map< std::string, std::string > const &headers, std::string const &cmd, Args &&... args)
Execute an RPC command.
virtual void submit(JTx const &jt)
Submit an existing JTx.
Env & apply(JsonValue &&jv, FN const &... fN)
Apply funclets and submit.
void disable_sigs()
Turn off signature checks.
void set_retries(unsigned r=5)
bool close()
Close and advance the ledger.
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Application const & app() const
std::shared_ptr< STObject const > meta()
Return metadata for the last JTx.
JTx jtnofill(JsonValue &&jv, FN const &... fN)
Create a JTx from parameters.
void set_parse_failure_expected(bool b)
void memoize(Account const &account)
Associate AccountID with account.
Env(beast::unit_test::suite &suite_, std::unique_ptr< Config > config, FeatureBitset features, std::unique_ptr< Logs > logs=nullptr, beast::severities::Severity thresh=beast::severities::kError)
Create Env using suite, Config pointer, and explicit features.
std::shared_ptr< SLE const > le(Account const &account) const
Return an account root.
void fund_arg(STAmount const &amount, Account const &account)
Env(beast::unit_test::suite &suite_, FeatureBitset features, std::unique_ptr< Logs > logs=nullptr)
Create Env with default config and specified features.
SuiteLogs(beast::unit_test::suite &suite)
beast::unit_test::suite & suite_
std::unique_ptr< beast::Journal::Sink > makeSink(std::string const &partition, beast::severities::Severity threshold) override
~SuiteLogs() override=default
Set the expected result code for a JTx The test will fail if the code doesn't match.
Set the expected result code for a JTx The test will fail if the code doesn't match.
Severity
Severity level / threshold of a Journal message.
static constexpr auto apiCommandLineVersion
static autofill_t const autofill
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
require_t required(Args const &... args)
Compose many condition functors into one.
FeatureBitset testable_amendments()
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::map< std::string, AmendmentSupport > const & allAmendments()
All amendments libxrpl knows about.
std::optional< uint256 > getRegisteredFeature(std::string const &name)
void foreachFeature(FeatureBitset bs, F &&f)
A pair of SHAMap key and LedgerEntryType.
std::unique_ptr< Application > owned
ManualTimeKeeper * timeKeeper
std::unique_ptr< AbstractClient > client
Used by parseResult() and postConditions()
std::optional< error_code_i > rpcCode
Execution context for applying a JSON transaction.
std::shared_ptr< STTx const > stx
Represents an XRP or IOU quantity This customizes the string conversion and supports XRP conversions ...
Set the sequence number on a JTx.