xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
test
protocol
InnerObjectFormats_test.cpp
1
2
#include <test/jtx/Env.h>
3
4
#include <xrpl/basics/contract.h>
5
#include <xrpl/beast/unit_test/suite.h>
6
#include <xrpl/json/json_reader.h>
// json::Reader
7
#include <xrpl/json/json_value.h>
8
#include <xrpl/protocol/ErrorCodes.h>
// rpc::containsError
9
#include <xrpl/protocol/STParsedJSON.h>
// STParsedJSONObject
10
11
#include <
stdexcept
>
12
#include <
string
>
13
14
namespace
xrpl
{
15
16
namespace
inner_object_formats_unit_test_detail
{
17
18
struct
TestJSONTxt
19
{
20
std::string
const
txt
;
21
bool
const
expectFail
;
22
};
23
24
static
TestJSONTxt
const
kTestArray
[] = {
25
26
// Valid SignerEntry
27
{
28
.txt = R
"({
29
"Account" : "rDg53Haik2475DJx8bjMDSDPj4VX7htaMd",
30
"SignerEntries" :
31
[
32
{
33
"SignerEntry" :
34
{
35
"Account" : "rnUy2SHTrB9DubsPmkJZUXTf5FcNDGrYEA",
36
"SignerWeight" : 4
37
}
38
},
39
{
40
"SignerEntry" :
41
{
42
"Account" : "rPcNzota6B8YBokhYtcTNqQVCngtbnWfux",
43
"SignerWeight" : 3
44
}
45
}
46
],
47
"SignerQuorum" : 7,
48
"TransactionType" : "SignerListSet"
49
})",
50
.expectFail =
false
,
51
},
52
53
// SignerEntry missing Account
54
{
55
.txt = R
"({
56
"Account" : "rDg53Haik2475DJx8bjMDSDPj4VX7htaMd",
57
"SignerEntries" :
58
[
59
{
60
"SignerEntry" :
61
{
62
"Account" : "rnUy2SHTrB9DubsPmkJZUXTf5FcNDGrYEA",
63
"SignerWeight" : 4
64
}
65
},
66
{
67
"SignerEntry" :
68
{
69
"SignerWeight" : 3
70
}
71
}
72
],
73
"SignerQuorum" : 7,
74
"TransactionType" : "SignerListSet"
75
})",
76
.expectFail =
true
,
77
},
78
79
// SignerEntry missing SignerWeight
80
{
81
.txt = R
"({
82
"Account" : "rDg53Haik2475DJx8bjMDSDPj4VX7htaMd",
83
"SignerEntries" :
84
[
85
{
86
"SignerEntry" :
87
{
88
"Account" : "rnUy2SHTrB9DubsPmkJZUXTf5FcNDGrYEA",
89
"SignerWeight" : 4
90
}
91
},
92
{
93
"SignerEntry" :
94
{
95
"Account" : "rPcNzota6B8YBokhYtcTNqQVCngtbnWfux",
96
}
97
}
98
],
99
"SignerQuorum" : 7,
100
"TransactionType" : "SignerListSet"
101
})",
102
.expectFail =
true
,
103
},
104
105
// SignerEntry with unexpected Amount
106
{
107
.txt = R
"({
108
"Account" : "rDg53Haik2475DJx8bjMDSDPj4VX7htaMd",
109
"SignerEntries" :
110
[
111
{
112
"SignerEntry" :
113
{
114
"Account" : "rnUy2SHTrB9DubsPmkJZUXTf5FcNDGrYEA",
115
"SignerWeight" : 4
116
}
117
},
118
{
119
"SignerEntry" :
120
{
121
"Amount" : "1000000",
122
"Account" : "rPcNzota6B8YBokhYtcTNqQVCngtbnWfux",
123
"SignerWeight" : 3
124
}
125
}
126
],
127
"SignerQuorum" : 7,
128
"TransactionType" : "SignerListSet"
129
})",
130
.expectFail =
true
,
131
},
132
133
// SignerEntry with no Account and unexpected Amount
134
{
135
.txt = R
"({
136
"Account" : "rDg53Haik2475DJx8bjMDSDPj4VX7htaMd",
137
"SignerEntries" :
138
[
139
{
140
"SignerEntry" :
141
{
142
"Account" : "rnUy2SHTrB9DubsPmkJZUXTf5FcNDGrYEA",
143
"SignerWeight" : 4
144
}
145
},
146
{
147
"SignerEntry" :
148
{
149
"Amount" : "10000000",
150
"SignerWeight" : 3
151
}
152
}
153
],
154
"SignerQuorum" : 7,
155
"TransactionType" : "SignerListSet"
156
})",
157
.expectFail =
true
,
158
},
159
160
};
161
162
}
// namespace inner_object_formats_unit_test_detail
163
164
class
InnerObjectFormatsParsedJSON_test
:
public
beast::unit_test::Suite
165
{
166
public
:
167
void
168
run
()
override
169
{
170
using namespace
inner_object_formats_unit_test_detail
;
171
172
// Instantiate a jtx::Env so debugLog writes are exercised.
173
test::jtx::Env
const
env(*
this
);
174
175
for
(
auto
const
&
test
: kTestArray)
176
{
177
json::Value
req;
178
json::Reader
().
parse
(
test
.txt, req);
179
if
(
rpc::containsError
(req))
180
{
181
Throw<std::runtime_error>
(
182
"Internal InnerObjectFormatsParsedJSON error. Bad JSON."
);
183
}
184
STParsedJSONObject
const
parsed(
"request"
, req);
185
bool
const
noObj = !parsed.
object
.has_value();
186
if
(noObj ==
test
.expectFail)
187
{
188
pass
();
189
}
190
else
191
{
192
std::string
errStr(
"Unexpected STParsedJSON result on:\n"
);
193
errStr +=
test
.txt;
194
fail
(errStr);
195
}
196
}
197
}
198
};
199
200
BEAST_DEFINE_TESTSUITE
(InnerObjectFormatsParsedJSON,
protocol
,
xrpl
);
201
202
}
// namespace xrpl
std::string
beast::unit_test::Suite
A testsuite class.
Definition
suite.h:52
beast::unit_test::Suite::pass
void pass()
Record a successful test condition.
Definition
suite.h:532
beast::unit_test::Suite::fail
void fail(String const &reason, char const *file, int line)
Record a failure.
Definition
suite.h:554
json::Reader
Unserialize a JSON document into a Value.
Definition
json_reader.h:20
json::Reader::parse
bool parse(std::string const &document, Value &root)
Read a Value from a JSON document.
Definition
json_reader.cpp:63
json::Value
Represents a JSON value.
Definition
json_value.h:121
xrpl::InnerObjectFormatsParsedJSON_test
Definition
InnerObjectFormats_test.cpp:165
xrpl::InnerObjectFormatsParsedJSON_test::run
void run() override
Runs the suite.
Definition
InnerObjectFormats_test.cpp:168
xrpl::STParsedJSONObject
Holds the serialized result of parsing an input JSON object.
Definition
STParsedJSON.h:28
xrpl::STParsedJSONObject::object
std::optional< STObject > object
The STObject if the parse was successful.
Definition
STParsedJSON.h:50
xrpl::test::jtx::Env
A transaction testing environment.
Definition
Env.h:161
protocol
Definition
LedgerNodeHelpers.h:9
xrpl::inner_object_formats_unit_test_detail
Definition
InnerObjectFormats_test.cpp:16
xrpl::inner_object_formats_unit_test_detail::kTestArray
static TestJSONTxt const kTestArray[]
Definition
InnerObjectFormats_test.cpp:24
xrpl::rpc::containsError
bool containsError(json::Value const &json)
Returns true if the json contains an rpc error specification.
Definition
ErrorCodes.cpp:206
xrpl::test
Definition
STLedgerEntry.h:21
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::BEAST_DEFINE_TESTSUITE
BEAST_DEFINE_TESTSUITE(AccountTxPaging, app, xrpl)
xrpl::Throw
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
Definition
contract.h:52
stdexcept
string
xrpl::inner_object_formats_unit_test_detail::TestJSONTxt
Definition
InnerObjectFormats_test.cpp:19
xrpl::inner_object_formats_unit_test_detail::TestJSONTxt::expectFail
bool const expectFail
Definition
InnerObjectFormats_test.cpp:21
xrpl::inner_object_formats_unit_test_detail::TestJSONTxt::txt
std::string const txt
Definition
InnerObjectFormats_test.cpp:20
Generated by
1.17.0