rippled
Loading...
Searching...
No Matches
JTx.h
1#ifndef XRPL_TEST_JTX_JTX_H_INCLUDED
2#define XRPL_TEST_JTX_JTX_H_INCLUDED
3
4#include <test/jtx/basic_prop.h>
5#include <test/jtx/requires.h>
6
7#include <xrpl/json/json_value.h>
8#include <xrpl/protocol/ErrorCodes.h>
9#include <xrpl/protocol/STTx.h>
10#include <xrpl/protocol/TER.h>
11
12#include <functional>
13#include <memory>
14#include <vector>
15
16namespace xrpl {
17namespace test {
18namespace jtx {
19
20class Env;
21
25struct JTx
26{
33 bool fill_fee = true;
34 bool fill_seq = true;
35 bool fill_sig = true;
36 bool fill_netid = true;
38 // Functions that sign the transaction from the Account
40 // Functions that sign something else after the mainSigners, such as
41 // sfCounterpartySignature
43 // Metadata about the unit test itself
44 // The line where the JTx was constructed
46
47 JTx() = default;
48 JTx(JTx const&) = default;
49 JTx&
50 operator=(JTx const&) = default;
51 JTx(JTx&&) = default;
52 JTx&
53 operator=(JTx&&) = default;
54
55 JTx(Json::Value&& jv_) : jv(std::move(jv_))
56 {
57 }
58
59 JTx(Json::Value const& jv_) : jv(jv_)
60 {
61 }
62
63 template <class Key>
65 operator[](Key const& key)
66 {
67 return jv[key];
68 }
69
75 template <class Prop>
76 Prop*
78 {
79 for (auto& prop : props_.list)
80 {
81 if (auto test = dynamic_cast<prop_type<Prop>*>(prop.get()))
82 return &test->t;
83 }
84 return nullptr;
85 }
86
87 template <class Prop>
88 Prop const*
89 get() const
90 {
91 for (auto& prop : props_.list)
92 {
93 if (auto test = dynamic_cast<prop_type<Prop> const*>(prop.get()))
94 return &test->t;
95 }
96 return nullptr;
97 }
105 void
107 {
108 for (auto& prop : props_.list)
109 {
110 if (prop->assignable(p.get()))
111 {
112 prop = std::move(p);
113 return;
114 }
115 }
116 props_.list.emplace_back(std::move(p));
117 }
118
119 template <class Prop, class... Args>
120 void
121 set(Args&&... args)
122 {
124 }
127private:
129 {
130 prop_list() = default;
131
132 prop_list(prop_list const& other)
133 {
134 for (auto const& prop : other.list)
135 list.emplace_back(prop->clone());
136 }
137
138 prop_list&
139 operator=(prop_list const& other)
140 {
141 if (this != &other)
142 {
143 list.clear();
144 for (auto const& prop : other.list)
145 list.emplace_back(prop->clone());
146 }
147 return *this;
148 }
149
150 prop_list(prop_list&& src) = default;
151 prop_list&
152 operator=(prop_list&& src) = default;
153
155 };
156
158};
159
160} // namespace jtx
161} // namespace test
162} // namespace xrpl
163
164#endif
Represents a JSON value.
Definition json_value.h:131
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 ter.h:16
T get(T... args)
T is_same_v
T make_unique(T... args)
STL namespace.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
@ tesSUCCESS
Definition TER.h:226
std::vector< std::unique_ptr< basic_prop > > list
Definition JTx.h:154
prop_list(prop_list const &other)
Definition JTx.h:132
prop_list & operator=(prop_list const &other)
Definition JTx.h:139
prop_list & operator=(prop_list &&src)=default
prop_list(prop_list &&src)=default
Execution context for applying a JSON transaction.
Definition JTx.h:26
Prop const * get() const
Definition JTx.h:89
JTx & operator=(JTx const &)=default
JTx & operator=(JTx &&)=default
Prop * get()
Return a property if it exists.
Definition JTx.h:77
JTx(Json::Value const &jv_)
Definition JTx.h:59
JTx(JTx &&)=default
void set(Args &&... args)
Definition JTx.h:121
std::vector< std::function< void(Env &, JTx &)> > postSigners
Definition JTx.h:42
std::vector< std::function< void(Env &, JTx &)> > mainSigners
Definition JTx.h:39
requires_t require
Definition JTx.h:28
std::shared_ptr< STTx const > stx
Definition JTx.h:37
std::optional< std::pair< error_code_i, std::string > > rpcCode
Definition JTx.h:30
JTx(Json::Value &&jv_)
Definition JTx.h:55
std::optional< std::pair< std::string, std::optional< std::string > > > rpcException
Definition JTx.h:32
void set(std::unique_ptr< basic_prop > p)
Set a property If the property already exists, it is replaced.
Definition JTx.h:106
prop_list props_
Definition JTx.h:157
JTx(JTx const &)=default
Json::Value & operator[](Key const &key)
Definition JTx.h:65
std::optional< int > testLine
Definition JTx.h:45
Json::Value jv
Definition JTx.h:27
Set a property on a JTx.
Definition prop.h:15