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