rippled
Loading...
Searching...
No Matches
rpc.h
1#ifndef XRPL_TEST_JTX_RPC_H_INCLUDED
2#define XRPL_TEST_JTX_RPC_H_INCLUDED
3
4#include <test/jtx/Env.h>
5
6#include <tuple>
7
8namespace ripple {
9namespace test {
10namespace jtx {
11
15class rpc
16{
17private:
22
23public:
26 : code_(code), errorMessage_(m)
27 {
28 }
29
31 explicit rpc(
32 std::string error,
33 std::optional<std::string> exceptionMessage = {})
34 : error_(error), errorException_(exceptionMessage)
35 {
36 }
37
38 void
39 operator()(Env&, JTx& jt) const
40 {
41 // The RPC request should fail. RPC errors result in telENV_RPC_FAILED.
43 if (code_)
44 {
45 auto const& errorInfo = RPC::get_error_info(*code_);
46 // When an RPC request returns an error code ('error_code'), it
47 // always includes an error message ('error_message'), and sometimes
48 // includes an error token ('error'). If it does, the error token is
49 // always obtained from the lookup into the ErrorInfo lookup table.
50 //
51 // Take advantage of that fact to populate jt.rpcException. The
52 // check will be aware of whether the rpcExcpetion can be safely
53 // ignored.
54 jt.rpcCode = {
55 *code_,
56 errorMessage_ ? *errorMessage_ : errorInfo.message.c_str()};
57 jt.rpcException = {errorInfo.token.c_str(), std::nullopt};
58 }
59 if (error_)
61 }
62};
63
64} // namespace jtx
65} // namespace test
66} // namespace ripple
67
68#endif
A transaction testing environment.
Definition Env.h:102
Set the expected result code for a JTx The test will fail if the code doesn't match.
Definition rpc.h:16
void operator()(Env &, JTx &jt) const
Definition rpc.h:39
std::optional< std::string > error_
Definition rpc.h:20
std::optional< std::string > errorException_
Definition rpc.h:21
rpc(error_code_i code, std::optional< std::string > m={})
If there's an error code, we expect an error message.
Definition rpc.h:25
std::optional< std::string > errorMessage_
Definition rpc.h:19
std::optional< error_code_i > code_
Definition rpc.h:18
rpc(std::string error, std::optional< std::string > exceptionMessage={})
If there is not a code, we expect an exception message.
Definition rpc.h:31
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:6
@ telENV_RPC_FAILED
Definition TER.h:49
Execution context for applying a JSON transaction.
Definition JTx.h:26
std::optional< std::pair< error_code_i, std::string > > rpcCode
Definition JTx.h:30
std::optional< std::pair< std::string, std::optional< std::string > > > rpcException
Definition JTx.h:32
std::optional< TER > ter
Definition JTx.h:29