rippled
Loading...
Searching...
No Matches
JTx.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_TEST_JTX_JTX_H_INCLUDED
21#define RIPPLE_TEST_JTX_JTX_H_INCLUDED
22
23#include <test/jtx/basic_prop.h>
24#include <test/jtx/requires.h>
25#include <xrpl/json/json_value.h>
26#include <xrpl/protocol/ErrorCodes.h>
27#include <xrpl/protocol/STTx.h>
28#include <xrpl/protocol/TER.h>
29
30#include <functional>
31#include <memory>
32#include <vector>
33
34namespace ripple {
35namespace test {
36namespace jtx {
37
38class Env;
39
43struct JTx
44{
50 rpcException = std::nullopt;
51 bool fill_fee = true;
52 bool fill_seq = true;
53 bool fill_sig = true;
54 bool fill_netid = true;
57
58 JTx() = default;
59 JTx(JTx const&) = default;
60 JTx&
61 operator=(JTx const&) = default;
62 JTx(JTx&&) = default;
63 JTx&
64 operator=(JTx&&) = default;
65
66 JTx(Json::Value&& jv_) : jv(std::move(jv_))
67 {
68 }
69
70 JTx(Json::Value const& jv_) : jv(jv_)
71 {
72 }
73
74 template <class Key>
76 operator[](Key const& key)
77 {
78 return jv[key];
79 }
80
86 template <class Prop>
87 Prop*
89 {
90 for (auto& prop : props_.list)
91 {
92 if (auto test = dynamic_cast<prop_type<Prop>*>(prop.get()))
93 return &test->t;
94 }
95 return nullptr;
96 }
97
98 template <class Prop>
99 Prop const*
100 get() const
101 {
102 for (auto& prop : props_.list)
103 {
104 if (auto test = dynamic_cast<prop_type<Prop> const*>(prop.get()))
105 return &test->t;
106 }
107 return nullptr;
108 }
116 void
118 {
119 for (auto& prop : props_.list)
120 {
121 if (prop->assignable(p.get()))
122 {
123 prop = std::move(p);
124 return;
125 }
126 }
127 props_.list.emplace_back(std::move(p));
128 }
129
130 template <class Prop, class... Args>
131 void
132 set(Args&&... args)
133 {
134 set(std::make_unique<prop_type<Prop>>(std::forward<Args>(args)...));
135 }
138private:
140 {
141 prop_list() = default;
142
143 prop_list(prop_list const& other)
144 {
145 for (auto const& prop : other.list)
146 list.emplace_back(prop->clone());
147 }
148
149 prop_list&
150 operator=(prop_list const& other)
151 {
152 if (this != &other)
153 {
154 list.clear();
155 for (auto const& prop : other.list)
156 list.emplace_back(prop->clone());
157 }
158 return *this;
159 }
160
161 prop_list(prop_list&& src) = default;
162 prop_list&
163 operator=(prop_list&& src) = default;
164
166 };
167
169};
170
171} // namespace jtx
172} // namespace test
173} // namespace ripple
174
175#endif
Represents a JSON value.
Definition: json_value.h:147
A transaction testing environment.
Definition: Env.h:117
Set the expected result code for a JTx The test will fail if the code doesn't match.
Definition: ter.h:34
T get(T... args)
T make_unique(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
@ tesSUCCESS
Definition: TER.h:242
STL namespace.
prop_list & operator=(prop_list &&src)=default
prop_list(prop_list const &other)
Definition: JTx.h:143
prop_list & operator=(prop_list const &other)
Definition: JTx.h:150
std::vector< std::unique_ptr< basic_prop > > list
Definition: JTx.h:165
prop_list(prop_list &&src)=default
Execution context for applying a JSON transaction.
Definition: JTx.h:44
Prop * get()
Return a property if it exists.
Definition: JTx.h:88
JTx(JTx const &)=default
void set(Args &&... args)
Definition: JTx.h:132
JTx(JTx &&)=default
std::optional< std::pair< error_code_i, std::string > > rpcCode
Definition: JTx.h:48
std::shared_ptr< STTx const > stx
Definition: JTx.h:55
Json::Value jv
Definition: JTx.h:45
std::optional< std::pair< std::string, std::optional< std::string > > > rpcException
Definition: JTx.h:50
void set(std::unique_ptr< basic_prop > p)
Set a property If the property already exists, it is replaced.
Definition: JTx.h:117
std::function< void(Env &, JTx &)> signer
Definition: JTx.h:56
JTx(Json::Value &&jv_)
Definition: JTx.h:66
Json::Value & operator[](Key const &key)
Definition: JTx.h:76
JTx & operator=(JTx const &)=default
requires_t require
Definition: JTx.h:46
Prop const * get() const
Definition: JTx.h:100
prop_list props_
Definition: JTx.h:168
JTx(Json::Value const &jv_)
Definition: JTx.h:70
JTx & operator=(JTx &&)=default
Set a property on a JTx.
Definition: prop.h:33