|
xrpld
|
A transaction testing environment. More...
#include <Env.h>

Classes | |
| struct | ParsedResult |
| Used by parseResult() and postConditions(). More... | |
| struct | AppBundle |
| class | ParseFailureGuard |
| RAII class to set and restore the parse failure flag (setParseFailureExpected). More... | |
Public Member Functions | |
| Env ()=delete | |
| Env & | operator= (Env const &)=delete |
| Env (Env const &)=delete | |
| 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. | |
| 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, 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 (beast::unit_test::Suite &suite, beast::Severity thresh=beast::Severity::Error) | |
| Create Env with only the current test suite. | |
| virtual | ~Env ()=default |
| Application & | app () |
| Application const & | app () const |
| ManualTimeKeeper & | timeKeeper () |
| NetClock::time_point | now () |
| Returns the current network time. | |
| AbstractClient & | client () |
| Returns the connected client. | |
| template<class... Args> | |
| json::Value | rpc (unsigned apiVersion, std::unordered_map< std::string, std::string > const &headers, std::string const &cmd, Args &&... args) |
| Execute an RPC command. | |
| template<class... Args> | |
| json::Value | rpc (unsigned apiVersion, std::string const &cmd, Args &&... args) |
| template<class... Args> | |
| json::Value | rpc (std::unordered_map< std::string, std::string > const &headers, std::string const &cmd, Args &&... args) |
| template<class... Args> | |
| json::Value | rpc (std::string const &cmd, Args &&... args) |
| std::shared_ptr< OpenView const > | current () const |
| Returns the current ledger. | |
| std::shared_ptr< ReadView const > | closed () |
| Returns the last closed ledger. | |
| bool | close (NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt) |
| Close and advance the ledger. | |
| template<class Rep, class Period> | |
| bool | close (std::chrono::duration< Rep, Period > const &elapsed) |
| Close and advance the ledger. | |
| bool | close () |
| Close and advance the ledger. | |
| 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 operations initiated by the close have been started. | |
| bool | disconnectClient (std::chrono::steady_clock::duration timeout=std::chrono::seconds{1}) |
| Disconnect the Env's built-in client and wait for the server to register the dropped connection. | |
| void | trace (int howMany=-1) |
| Turn on JSON tracing. | |
| void | notrace () |
| Turn off JSON tracing. | |
| void | setParseFailureExpected (bool b) |
| ParseFailureGuard | getParseFailureGuard (bool b) |
| Gets an RAII guard to set and restore the parse failure flag. | |
| void | disableSigs () |
| Turn off signature checks. | |
| void | setRetries (unsigned r=5) |
| unsigned | retries () const |
| void | memoize (Account const &account) |
| Associate AccountID with account. | |
| PrettyAmount | balance (Account const &account) const |
| Returns the XRP balance on an account. | |
| std::uint32_t | seq (Account const &account) const |
| Returns the next sequence number on account. | |
| PrettyAmount | balance (Account const &account, Asset const &asset) const |
| Return the balance on an account. | |
| PrettyAmount | limit (Account const &account, Issue const &issue) const |
| Returns the IOU limit on an account. | |
| std::uint32_t | ownerCount (Account const &account) const |
| Return the number of objects owned by an account. | |
| std::uint32_t | sponsoredOwnerCount (Account const &account) const |
| Return the number of sponsored objects owned by an account. | |
| std::uint32_t | sponsoringOwnerCount (Account const &account) const |
| Return the number of sponsoring objects owned by an account. | |
| std::uint32_t | sponsoringAccountCount (Account const &account) const |
| Return the number of sponsoring accounts owned by an account. | |
| SLE::const_pointer | le (Account const &account) const |
| Return an account root. | |
| SLE::const_pointer | le (Keylet const &k) const |
| Return a ledger entry. | |
| template<class JsonValue, class... FN> | |
| JTx | jt (JsonValue &&jv, FN const &... fN) |
| Create a JTx from parameters. | |
| template<class JsonValue, class... FN> | |
| JTx | jtnofill (JsonValue &&jv, FN const &... fN) |
| Create a JTx from parameters. | |
| template<class JsonValue, class... FN> | |
| json::Value | json (JsonValue &&jv, FN const &... fN) |
| Create JSON from parameters. | |
| template<class... Args> | |
| void | require (Args const &... args) |
| Check a set of requirements. | |
| virtual void | submit (JTx const &jt, std::source_location const &loc=std::source_location::current()) |
| Submit an existing JTx. | |
| 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. | |
| 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. | |
| TER | ter () const |
| Return the TER for the last JTx. | |
| std::shared_ptr< STObject const > | meta () |
| Return metadata for the last JTx. | |
| std::shared_ptr< STTx const > | tx () const |
| Return the tx data for the last JTx. | |
| void | enableFeature (uint256 const feature) |
| void | disableFeature (uint256 const feature) |
| bool | enabled (uint256 feature) const |
| template<class Arg, class... Args> | |
| void | fund (STAmount const &amount, Arg const &arg, Args const &... args) |
| Create a new account with some XRP. | |
| 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 first editing the JSON. | |
| Account const & | lookup (AccountID const &id) const |
| Returns the Account given the AccountID. | |
| Account const & | lookup (std::string const &base58ID) const |
| template<class... FN> | |
| Env & | apply (WithSourceLocation< json::Value > jv, FN const &... fN) |
| Apply funclets and submit. | |
| template<class... FN> | |
| Env & | apply (WithSourceLocation< JTx > jv, FN const &... fN) |
| template<class... FN> | |
| Env & | operator() (WithSourceLocation< json::Value > jv, FN const &... fN) |
| template<class... FN> | |
| Env & | operator() (WithSourceLocation< JTx > jv, FN const &... fN) |
| void | trust (STAmount const &amount, Account const &account) |
| Establish trust lines. | |
| template<class... Accounts> | |
| void | trust (STAmount const &amount, Account const &to0, Account const &to1, Accounts const &... toN) |
Static Public Member Functions | |
| static ParsedResult | parseResult (json::Value const &jr) |
| Gets the TER result and didApply flag from a RPC Json result object. | |
Public Attributes | |
| beast::unit_test::Suite & | test |
| Account const & | master = Account::kMaster |
| beast::Journal const | journal |
Protected Member Functions | |
| json::Value | doRpc (unsigned apiVersion, std::vector< std::string > const &args, std::unordered_map< std::string, std::string > const &headers={}) |
| void | autofillSig (JTx &jt) |
| virtual void | autofill (JTx &jt) |
| std::shared_ptr< STTx const > | st (JTx const &jt) |
| Create a STTx from a JTx The framework requires that JSON is valid. | |
| template<class... FN> | |
| void | invoke (STTx &stx, FN const &... fN) |
| template<class... FN> | |
| void | invoke (JTx &jt, FN const &... fN) |
Protected Attributes | |
| int | trace_ = 0 |
| TestStopwatch | stopwatch_ |
| uint256 | txid_ |
| TER | ter_ = tesSUCCESS |
| bool | parseFailureExpected_ = false |
| unsigned | retries_ = 5 |
| std::unordered_map< AccountID, Account > | map_ |
Private Member Functions | |
| bool | drainServerIo (std::chrono::steady_clock::duration timeout) |
| Drain the (single) server io_context thread once. | |
| void | fund (bool setDefaultRipple, STAmount const &amount, Account const &account) |
| void | fundArg (STAmount const &amount, Account const &account) |
| template<std::size_t N> | |
| void | fundArg (STAmount const &amount, std::array< Account, N > const &list) |
Private Attributes | |
| AppBundle | bundle_ |
|
delete |
|
delete |
| xrpl::test::jtx::Env::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.
This constructor will create an Env with the specified configuration and takes ownership the passed Config pointer. Features will be enabled according to rules described below (see next constructor).
| suite | the current unit_test::suite |
| config | The desired Config - ownership will be taken by moving the pointer. See envconfig and related functions for common config tweaks. |
| args | with_only_features() to explicitly enable or supported_features_except() to enable all and disable specific features. |
| xrpl::test::jtx::Env::Env | ( | beast::unit_test::Suite & | suite, |
| FeatureBitset | features, | ||
| std::unique_ptr< Logs > | logs = nullptr ) |
Create Env with default config and specified features.
This constructor will create an Env with the standard Env configuration (from envconfig()) and features explicitly specified. Use with_only_features(...) or supported_features_except(...) to create a collection of features appropriate for passing here.
| suite | the current unit_test::suite |
| args | collection of features |
| xrpl::test::jtx::Env::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.
This constructor will create an Env with the specified configuration and takes ownership the passed Config pointer. All supported amendments are enabled by this version of the constructor.
| suite | the current unit_test::suite |
| config | The desired Config - ownership will be taken by moving the pointer. See envconfig and related functions for common config tweaks. |
| xrpl::test::jtx::Env::Env | ( | beast::unit_test::Suite & | suite, |
| beast::Severity | thresh = beast::Severity::Error ) |
|
virtualdefault |
| Application & xrpl::test::jtx::Env::app | ( | ) |
|
nodiscard |
| ManualTimeKeeper & xrpl::test::jtx::Env::timeKeeper | ( | ) |
| NetClock::time_point xrpl::test::jtx::Env::now | ( | ) |
| AbstractClient & xrpl::test::jtx::Env::client | ( | ) |
| json::Value xrpl::test::jtx::Env::rpc | ( | unsigned | apiVersion, |
| std::unordered_map< std::string, std::string > const & | headers, | ||
| std::string const & | cmd, | ||
| Args &&... | args ) |
| json::Value xrpl::test::jtx::Env::rpc | ( | unsigned | apiVersion, |
| std::string const & | cmd, | ||
| Args &&... | args ) |
| json::Value xrpl::test::jtx::Env::rpc | ( | std::unordered_map< std::string, std::string > const & | headers, |
| std::string const & | cmd, | ||
| Args &&... | args ) |
| json::Value xrpl::test::jtx::Env::rpc | ( | std::string const & | cmd, |
| Args &&... | args ) |
|
nodiscard |
| std::shared_ptr< ReadView const > xrpl::test::jtx::Env::closed | ( | ) |
| bool xrpl::test::jtx::Env::close | ( | NetClock::time_point | closeTime, |
| std::optional< std::chrono::milliseconds > | consensusDelay = std::nullopt ) |
Close and advance the ledger.
The resulting close time will be different and greater than the previous close time, and at or after the passed-in close time.
Effects:
Creates a new closed ledger from the last closed ledger. All transactions that made it into the open ledger are applied to the closed ledger. The Application network time is set to the close time of the resulting ledger.
| bool xrpl::test::jtx::Env::close | ( | std::chrono::duration< Rep, Period > const & | elapsed | ) |
| bool xrpl::test::jtx::Env::close | ( | ) |
|
nodiscard |
Close and advance the ledger, then synchronize with the server's io_context to ensure all async operations initiated by the close have been started.
This function performs the same ledger close as close(), but additionally ensures that all tasks posted to the server's io_context (such as WebSocket subscription message sends) have been initiated before returning.
What it guarantees:
What it does NOT guarantee:
Use this instead of close() when:
| timeout | Maximum time to wait for the barrier task to execute |
|
nodiscard |
Disconnect the Env's built-in client and wait for the server to register the dropped connection.
Env holds one persistent client connection to the server's RPC port for its whole lifetime (see client()), and that connection counts against the port's connection limit. Tests that need a known starting occupancy can call this to deterministically release that slot instead of waiting out the server's localhost idle timeout.
The server decrements its per-port connection count in the peer's destructor, which runs when the io_context processes the end-of-stream on the closed socket. After closing the client this drains the server's io_context twice: the first barrier guarantees the reactor has reaped the closed socket and queued the peer's teardown, and the second guarantees that teardown (and therefore the count decrement) has run.
This is only sound when the server uses a single io_context thread, so that draining establishes ordering against the teardown - configure the Env with singleThreadIo() (as syncClose() also requires). Like syncClose(), it relies on loopback teardown latency being negligible.
| timeout | Maximum time to wait for each barrier task to execute |
| void xrpl::test::jtx::Env::trace | ( | int | howMany = -1 | ) |
|
nodiscard |
| void xrpl::test::jtx::Env::disableSigs | ( | ) |
| void xrpl::test::jtx::Env::memoize | ( | Account const & | account | ) |
|
nodiscard |
|
nodiscard |
|
nodiscard |
|
nodiscard |
|
nodiscard |
|
nodiscard |
|
nodiscard |
|
nodiscard |
|
nodiscard |
|
nodiscard |
|
nodiscard |
| JTx xrpl::test::jtx::Env::jt | ( | JsonValue && | jv, |
| FN const &... | fN ) |
| JTx xrpl::test::jtx::Env::jtnofill | ( | JsonValue && | jv, |
| FN const &... | fN ) |
| json::Value xrpl::test::jtx::Env::json | ( | JsonValue && | jv, |
| FN const &... | fN ) |
| void xrpl::test::jtx::Env::require | ( | Args const &... | args | ) |
|
static |
|
virtual |
| void xrpl::test::jtx::Env::signAndSubmit | ( | JTx const & | jt, |
| json::Value | params = json::ValueType::Null, | ||
| std::source_location const & | loc = std::source_location::current() ) |
| void xrpl::test::jtx::Env::postconditions | ( | JTx const & | jt, |
| ParsedResult const & | parsed, | ||
| json::Value const & | jr = json::Value(), | ||
| std::source_location const & | loc = std::source_location::current() ) |
| Env & xrpl::test::jtx::Env::apply | ( | WithSourceLocation< json::Value > | jv, |
| FN const &... | fN ) |
| Env & xrpl::test::jtx::Env::apply | ( | WithSourceLocation< JTx > | jv, |
| FN const &... | fN ) |
| Env & xrpl::test::jtx::Env::operator() | ( | WithSourceLocation< json::Value > | jv, |
| FN const &... | fN ) |
| Env & xrpl::test::jtx::Env::operator() | ( | WithSourceLocation< JTx > | jv, |
| FN const &... | fN ) |
|
nodiscard |
| std::shared_ptr< STObject const > xrpl::test::jtx::Env::meta | ( | ) |
Return metadata for the last JTx.
NOTE: this has a side effect of closing the open ledger. The ledger will only be closed if it includes transactions.
Effects:
The open ledger is closed as if by a call to close(). The metadata for the last transaction ID, if any, is returned.
|
nodiscard |
| void xrpl::test::jtx::Env::enableFeature | ( | uint256 const | feature | ) |
| void xrpl::test::jtx::Env::disableFeature | ( | uint256 const | feature | ) |
|
nodiscard |
|
nodiscardprivate |
Drain the (single) server io_context thread once.
Posts a barrier task to the server's io_context and blocks until it runs, so every task queued before it has been processed. Only meaningful with a single io thread (see syncClose()/disconnectClient()).
| timeout | Maximum time to wait for the barrier task to execute |
|
private |
| void xrpl::test::jtx::Env::fund | ( | STAmount const & | amount, |
| Arg const & | arg, | ||
| Args const &... | args ) |
Create a new account with some XRP.
These convenience functions are for easy set-up of the environment, they bypass fee, seq, and sig settings. The XRP is transferred from the master account.
Preconditions: The account must not already exist
Effects: The asfDefaultRipple on the account is set, and the sequence number is incremented, unless the account is wrapped with a call to noripple.
The account's XRP balance is set to amount.
Generates a test that the balance is set.
| amount | The amount of XRP to transfer to each account. |
| args | A heterogeneous list of accounts to fund or calls to noripple with lists of accounts to fund. |
Establish trust lines.
These convenience functions are for easy set-up of the environment, they bypass fee, seq, and sig settings.
Preconditions: The account must already exist
Effects: A trust line is added for the account. The account's sequence number is incremented. The account is refunded for the transaction fee to set the trust line.
The refund comes from the master account.
| std::shared_ptr< STTx const > xrpl::test::jtx::Env::ust | ( | JTx const & | jt | ) |
|
protected |
|
protected |
|
protectedvirtual |
|
protected |
Create a STTx from a JTx The framework requires that JSON is valid.
On a parse error, the JSON is logged and an exception thrown.
| ParseError |
|
protected |
|
protected |
| beast::unit_test::Suite& xrpl::test::jtx::Env::test |
| Account const& xrpl::test::jtx::Env::master = Account::kMaster |
| beast::Journal const xrpl::test::jtx::Env::journal |
|
protected |
|
protected |
|
protected |
|
protected |