rippled
Loading...
Searching...
No Matches
rpc.h
1#pragma once
2
3#include <test/jtx/Env.h>
4
5#include <tuple>
6
7namespace xrpl {
8namespace test {
9namespace jtx {
10
14class rpc
15{
16private:
21
22public:
25 {
26 }
27
29 explicit rpc(std::string error, std::optional<std::string> exceptionMessage = {})
30 : error_(error), errorException_(exceptionMessage)
31 {
32 }
33
34 void
35 operator()(Env&, JTx& jt) const
36 {
37 // The RPC request should fail. RPC errors result in telENV_RPC_FAILED.
39 if (code_)
40 {
41 auto const& errorInfo = RPC::get_error_info(*code_);
42 // When an RPC request returns an error code ('error_code'), it
43 // always includes an error message ('error_message'), and sometimes
44 // includes an error token ('error'). If it does, the error token is
45 // always obtained from the lookup into the ErrorInfo lookup table.
46 //
47 // Take advantage of that fact to populate jt.rpcException. The
48 // check will be aware of whether the rpcException can be safely
49 // ignored.
50 jt.rpcCode = {*code_, errorMessage_ ? *errorMessage_ : errorInfo.message.c_str()};
51 jt.rpcException = {errorInfo.token.c_str(), std::nullopt};
52 }
53 if (error_)
55 }
56};
57
58} // namespace jtx
59} // namespace test
60} // namespace xrpl
A transaction testing environment.
Definition Env.h:119
Set the expected result code for a JTx The test will fail if the code doesn't match.
Definition rpc.h:15
std::optional< std::string > error_
Definition rpc.h:19
rpc(std::string error, std::optional< std::string > exceptionMessage={})
If there is not a code, we expect an exception message.
Definition rpc.h:29
std::optional< std::string > errorMessage_
Definition rpc.h:18
void operator()(Env &, JTx &jt) const
Definition rpc.h:35
std::optional< error_code_i > code_
Definition rpc.h:17
std::optional< std::string > errorException_
Definition rpc.h:20
rpc(error_code_i code, std::optional< std::string > m={})
If there's an error code, we expect an error message.
Definition rpc.h:24
T is_same_v
ErrorInfo const & get_error_info(error_code_i code)
Returns an ErrorInfo that reflects the error code.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ telENV_RPC_FAILED
Definition TER.h:48
error_code_i
Definition ErrorCodes.h:20
Execution context for applying a JSON transaction.
Definition JTx.h:25
std::optional< TER > ter
Definition JTx.h:28
std::optional< std::pair< error_code_i, std::string > > rpcCode
Definition JTx.h:29
std::optional< std::pair< std::string, std::optional< std::string > > > rpcException
Definition JTx.h:30