1#ifndef XRPL_TEST_JTX_ENV_H_INCLUDED
2#define XRPL_TEST_JTX_ENV_H_INCLUDED
4#include <test/jtx/AbstractClient.h>
5#include <test/jtx/Account.h>
6#include <test/jtx/JTx.h>
7#include <test/jtx/ManualTimeKeeper.h>
8#include <test/jtx/amount.h>
9#include <test/jtx/envconfig.h>
10#include <test/jtx/require.h>
11#include <test/jtx/tags.h>
12#include <test/jtx/vault.h>
13#include <test/unit_test/SuiteJournal.h>
15#include <xrpld/app/ledger/Ledger.h>
16#include <xrpld/app/ledger/OpenLedger.h>
17#include <xrpld/app/main/Application.h>
18#include <xrpld/app/paths/Pathfinder.h>
19#include <xrpld/core/Config.h>
21#include <xrpl/basics/Log.h>
22#include <xrpl/basics/chrono.h>
23#include <xrpl/beast/utility/Journal.h>
24#include <xrpl/json/json_value.h>
25#include <xrpl/json/to_string.h>
26#include <xrpl/protocol/ApiVersion.h>
27#include <xrpl/protocol/Feature.h>
28#include <xrpl/protocol/Indexes.h>
29#include <xrpl/protocol/Issue.h>
30#include <xrpl/protocol/STAmount.h>
31#include <xrpl/protocol/STObject.h>
32#include <xrpl/protocol/STTx.h>
47template <
class... Args>
51 return {{account, args...}};
61 for (
auto const& [s, vote] : sa)
67 Throw<std::runtime_error>(
68 "Unknown feature: " + s +
" in allAmendments.");
171 ,
bundle_(suite_,
std::move(config),
std::move(logs), thresh)
177 features, [&appFeats =
app().config().features](
uint256 const& f) {
282 template <
class... Args>
284 rpc(
unsigned apiVersion,
289 template <
class... Args>
293 template <
class... Args>
299 template <
class... Args>
358 template <
class Rep,
class Period>
487 template <
class JsonValue,
class... FN>
489 jt(JsonValue&& jv, FN
const&... fN)
499 template <
class JsonValue,
class... FN>
513 template <
class JsonValue,
class... FN>
515 json(JsonValue&& jv, FN
const&... fN)
518 return std::move(tj.jv);
526 template <
class... Args>
556 ParsedResult
const& parsed,
561 template <
class JsonValue,
class... FN>
563 apply(JsonValue&& jv, FN
const&... fN)
569 template <
class JsonValue,
class... FN>
621 return current()->rules().enabled(feature);
631 fund(
true, amount, account);
634 template <std::
size_t N>
638 for (
auto const& account : list)
639 fund(
false, amount, account);
669 template <
class Arg,
class... Args>
674 if constexpr (
sizeof...(args) > 0)
675 fund(amount, args...);
699 template <
class... Accounts>
705 Accounts
const&... toN)
708 trust(amount, to1, toN...);
751 template <
class... FN>
755 (fN(*
this, stx), ...);
759 template <
class... FN>
763 (fN(*
this,
jt), ...);
770template <
class... Args>
784template <
class... Args>
795template <
class... Args>
808template <
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.