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
{.txt = R
"({
28
"Account" : "rDg53Haik2475DJx8bjMDSDPj4VX7htaMd",
29
"SignerEntries" :
30
[
31
{
32
"SignerEntry" :
33
{
34
"Account" : "rnUy2SHTrB9DubsPmkJZUXTf5FcNDGrYEA",
35
"SignerWeight" : 4
36
}
37
},
38
{
39
"SignerEntry" :
40
{
41
"Account" : "rPcNzota6B8YBokhYtcTNqQVCngtbnWfux",
42
"SignerWeight" : 3
43
}
44
}
45
],
46
"SignerQuorum" : 7,
47
"TransactionType" : "SignerListSet"
48
})",
49
.expectFail =
false
},
50
51
// SignerEntry missing Account
52
{.txt = R
"({
53
"Account" : "rDg53Haik2475DJx8bjMDSDPj4VX7htaMd",
54
"SignerEntries" :
55
[
56
{
57
"SignerEntry" :
58
{
59
"Account" : "rnUy2SHTrB9DubsPmkJZUXTf5FcNDGrYEA",
60
"SignerWeight" : 4
61
}
62
},
63
{
64
"SignerEntry" :
65
{
66
"SignerWeight" : 3
67
}
68
}
69
],
70
"SignerQuorum" : 7,
71
"TransactionType" : "SignerListSet"
72
})",
73
.expectFail =
true
},
74
75
// SignerEntry missing SignerWeight
76
{.txt = R
"({
77
"Account" : "rDg53Haik2475DJx8bjMDSDPj4VX7htaMd",
78
"SignerEntries" :
79
[
80
{
81
"SignerEntry" :
82
{
83
"Account" : "rnUy2SHTrB9DubsPmkJZUXTf5FcNDGrYEA",
84
"SignerWeight" : 4
85
}
86
},
87
{
88
"SignerEntry" :
89
{
90
"Account" : "rPcNzota6B8YBokhYtcTNqQVCngtbnWfux",
91
}
92
}
93
],
94
"SignerQuorum" : 7,
95
"TransactionType" : "SignerListSet"
96
})",
97
.expectFail =
true
},
98
99
// SignerEntry with unexpected Amount
100
{.txt = R
"({
101
"Account" : "rDg53Haik2475DJx8bjMDSDPj4VX7htaMd",
102
"SignerEntries" :
103
[
104
{
105
"SignerEntry" :
106
{
107
"Account" : "rnUy2SHTrB9DubsPmkJZUXTf5FcNDGrYEA",
108
"SignerWeight" : 4
109
}
110
},
111
{
112
"SignerEntry" :
113
{
114
"Amount" : "1000000",
115
"Account" : "rPcNzota6B8YBokhYtcTNqQVCngtbnWfux",
116
"SignerWeight" : 3
117
}
118
}
119
],
120
"SignerQuorum" : 7,
121
"TransactionType" : "SignerListSet"
122
})",
123
.expectFail =
true
},
124
125
// SignerEntry with no Account and unexpected Amount
126
{.txt = R
"({
127
"Account" : "rDg53Haik2475DJx8bjMDSDPj4VX7htaMd",
128
"SignerEntries" :
129
[
130
{
131
"SignerEntry" :
132
{
133
"Account" : "rnUy2SHTrB9DubsPmkJZUXTf5FcNDGrYEA",
134
"SignerWeight" : 4
135
}
136
},
137
{
138
"SignerEntry" :
139
{
140
"Amount" : "10000000",
141
"SignerWeight" : 3
142
}
143
}
144
],
145
"SignerQuorum" : 7,
146
"TransactionType" : "SignerListSet"
147
})",
148
.expectFail =
true
},
149
150
};
151
152
}
// namespace inner_object_formats_unit_test_detail
153
154
class
InnerObjectFormatsParsedJSON_test
:
public
beast::unit_test::Suite
155
{
156
public
:
157
void
158
run
()
override
159
{
160
using namespace
inner_object_formats_unit_test_detail
;
161
162
// Instantiate a jtx::Env so debugLog writes are exercised.
163
test::jtx::Env
const
env(*
this
);
164
165
for
(
auto
const
&
test
: kTestArray)
166
{
167
json::Value
req;
168
json::Reader
().
parse
(
test
.txt, req);
169
if
(
rpc::containsError
(req))
170
{
171
Throw<std::runtime_error>
(
172
"Internal InnerObjectFormatsParsedJSON error. Bad JSON."
);
173
}
174
STParsedJSONObject
const
parsed(
"request"
, req);
175
bool
const
noObj = !parsed.
object
.has_value();
176
if
(noObj ==
test
.expectFail)
177
{
178
pass
();
179
}
180
else
181
{
182
std::string
errStr(
"Unexpected STParsedJSON result on:\n"
);
183
errStr +=
test
.txt;
184
fail
(errStr);
185
}
186
}
187
}
188
};
189
190
BEAST_DEFINE_TESTSUITE
(InnerObjectFormatsParsedJSON,
protocol
,
xrpl
);
191
192
}
// 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:117
xrpl::InnerObjectFormatsParsedJSON_test
Definition
InnerObjectFormats_test.cpp:155
xrpl::InnerObjectFormatsParsedJSON_test::run
void run() override
Runs the suite.
Definition
InnerObjectFormats_test.cpp:158
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