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