20 #ifndef RIPPLE_TEST_JTX_ENV_H_INCLUDED
21 #define RIPPLE_TEST_JTX_ENV_H_INCLUDED
23 #include <ripple/app/ledger/Ledger.h>
24 #include <ripple/app/ledger/OpenLedger.h>
25 #include <ripple/app/main/Application.h>
26 #include <ripple/app/paths/Pathfinder.h>
27 #include <ripple/basics/Log.h>
28 #include <ripple/basics/chrono.h>
29 #include <ripple/beast/utility/Journal.h>
30 #include <ripple/core/Config.h>
31 #include <ripple/json/json_value.h>
32 #include <ripple/json/to_string.h>
33 #include <ripple/ledger/CachedSLEs.h>
34 #include <ripple/protocol/Feature.h>
35 #include <ripple/protocol/Indexes.h>
36 #include <ripple/protocol/Issue.h>
37 #include <ripple/protocol/STAmount.h>
38 #include <ripple/protocol/STObject.h>
39 #include <ripple/protocol/STTx.h>
42 #include <test/jtx/AbstractClient.h>
43 #include <test/jtx/Account.h>
44 #include <test/jtx/JTx.h>
45 #include <test/jtx/ManualTimeKeeper.h>
46 #include <test/jtx/amount.h>
47 #include <test/jtx/envconfig.h>
48 #include <test/jtx/require.h>
49 #include <test/jtx/tags.h>
50 #include <test/unit_test/SuiteJournal.h>
62 template <
class... Args>
66 return {{account, args...}};
76 for (
auto const& [s, vote] : sa)
82 Throw<std::runtime_error>(
83 "Unknown feature: " + s +
" in supportedAmendments.");
109 return std::make_unique<SuiteJournalSink>(partition,
threshold,
suite_);
134 beast::unit_test::suite& suite,
166 Env(beast::unit_test::suite& suite_,
172 ,
bundle_(suite_,
std::move(config),
std::move(logs), thresh)
178 features, [&appFeats =
app().config().features](
uint256 const& f) {
213 Env(beast::unit_test::suite& suite_,
238 virtual ~Env() =
default;
281 template <
class... Args>
287 template <
class... Args>
346 template <
class Rep,
class Period>
437 template <
class JsonValue,
class... FN>
439 jt(JsonValue&& jv, FN
const&... fN)
441 JTx jt(std::forward<JsonValue>(jv));
451 template <
class JsonValue,
class... FN>
453 json(JsonValue&& jv, FN
const&... fN)
455 auto tj =
jt(std::forward<JsonValue>(jv), fN...);
456 return std::move(tj.jv);
464 template <
class... Args>
496 template <
class JsonValue,
class... FN>
498 apply(JsonValue&& jv, FN
const&... fN)
500 submit(
jt(std::forward<JsonValue>(jv), fN...));
503 template <
class JsonValue,
class... FN>
507 apply(std::forward<JsonValue>(jv), fN...);
556 fund(
true, amount, account);
559 template <std::
size_t N>
563 for (
auto const& account : list)
564 fund(
false, amount, account);
594 template <
class Arg,
class... Args>
599 if constexpr (
sizeof...(args) > 0)
600 fund(amount, args...);
624 template <
class... Accounts>
630 Accounts
const&... toN)
633 trust(amount, to1, toN...);
666 template <
class... FN>
670 (fN(*
this, stx), ...);
674 template <
class... FN>
678 (fN(*
this,
jt), ...);
685 template <
class... Args>
696 template <
class... Args>
703 std::forward<Args>(args)...);
void invoke(STTx &stx, FN const &... fN)
virtual bool checkSigs() const =0
Env(beast::unit_test::suite &suite_, FeatureBitset features)
Create Env with default config and specified features.
void autofill_sig(JTx &jt)
beast::unit_test::suite & suite_
void fund(STAmount const &amount, Arg const &arg, Args const &... args)
Create a new account with some XRP.
A pair of SHAMap key and LedgerEntryType.
std::shared_ptr< OpenView const > current() const
Returns a view to the current open ledger.
A currency issued by an account.
Manages partitions for logging.
std::unordered_map< AccountID, Account > map_
std::unique_ptr< AbstractClient > client
std::shared_ptr< STTx const > tx() const
Return the tx data for the last JTx.
Set the expected result code for a JTx The test will fail if the code doesn't match.
void require(Args const &... args)
Check a set of requirements.
void apply(JsonValue &&jv, FN const &... fN)
Apply funclets and submit.
std::shared_ptr< ReadView const > closed()
Returns the last closed ledger.
void fund_arg(STAmount const &amount, std::array< Account, N > const &list)
void enableFeature(uint256 const feature)
ManualTimeKeeper * timeKeeper
std::shared_ptr< STTx const > stx
JTx jt(JsonValue &&jv, FN const &... fN)
Create a JTx from parameters.
const beast::Journal journal
void notrace()
Turn off JSON tracing.
void disable_sigs()
Turn off signature checks.
ManualTimeKeeper & timeKeeper()
~SuiteLogs() override=default
void sign_and_submit(JTx const &jt, Json::Value params=Json::nullValue)
Use the submit RPC command with a provided JTx object.
static void initPathTable()
PrettyAmount balance(Account const &account) const
Returns the XRP balance on an account.
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
virtual OpenLedger & openLedger()=0
TER ter() const
Return the TER for the last JTx.
void trust(STAmount const &amount, Account const &account)
Establish trust lines.
std::shared_ptr< STTx const > st(JTx const &jt)
Create a STTx from a JTx The framework requires that JSON is valid.
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.
static std::pair< TER, bool > parseResult(Json::Value const &jr)
Gets the TER result and didApply flag from a RPC Json result object.
SuiteLogs(beast::unit_test::suite &suite)
std::shared_ptr< STObject const > meta()
Return metadata for the last JTx.
void foreachFeature(FeatureBitset bs, F &&f)
bool close(std::chrono::duration< Rep, Period > const &elapsed)
Close and advance the ledger.
void operator()(JsonValue &&jv, FN const &... fN)
void trace(int howMany=-1)
Turn on JSON tracing.
void postconditions(JTx const &jt, TER ter, bool didApply)
Check expected postconditions of JTx submission.
Execution context for applying a JSON transaction.
virtual void submit(JTx const &jt)
Submit an existing JTx.
Account const & lookup(AccountID const &id) const
Returns the Account given the AccountID.
A generic endpoint for log messages.
FeatureBitset supported_amendments()
static const Account master
The master account.
std::uint32_t seq(Account const &account) const
Returns the next sequence number on account.
Application const & app() const
beast::unit_test::suite & test
void invoke(JTx &jt, FN const &... fN)
require_t required(Args const &... args)
Compose many condition functors into one.
AbstractClient & client()
Returns the connected client.
beast::severities::Severity threshold() const
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Env & operator=(Env const &)=delete
virtual beast::Journal journal(std::string const &name)=0
std::array< Account, 1+sizeof...(Args)> noripple(Account const &account, Args const &... args)
Designate accounts as no-ripple in Env::fund.
virtual void autofill(JTx &jt)
Json::Value do_rpc(std::vector< std::string > const &args, std::unordered_map< std::string, std::string > const &headers={})
NetClock::time_point now()
Returns the current network time.
bool close()
Close and advance the ledger.
Severity
Severity level / threshold of a Journal message.
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
std::shared_ptr< SLE const > le(Account const &account) const
Return an account root.
std::unique_ptr< Application > owned
Env(beast::unit_test::suite &suite_)
Create Env with only the current test suite.
void disableFeature(uint256 const feature)
Immutable cryptographic account descriptor.
void fund_arg(STAmount const &amount, Account const &account)
time_point now() const override
Returns the estimate of wall time, in network time.
std::optional< uint256 > getRegisteredFeature(std::string const &name)
void memoize(Account const &account)
Associate AccountID with account.
std::unique_ptr< beast::Journal::Sink > makeSink(std::string const &partition, beast::severities::Severity threshold) override
std::map< std::string, VoteBehavior > const & supportedAmendments()
Amendments that this server supports and the default voting behavior.
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Json::Value json(JsonValue &&jv, FN const &... fN)
Create JSON from parameters.
void trust(STAmount const &amount, Account const &to0, Account const &to1, Accounts const &... toN)
A transaction testing environment.
Json::Value rpc(std::unordered_map< std::string, std::string > const &headers, std::string const &cmd, Args &&... args)
Execute an RPC command.
Represents an XRP or IOU quantity This customizes the string conversion and supports XRP conversions ...
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.