xrpld
Loading...
Searching...
No Matches
AccountObjects_test.cpp
1#include <test/jtx/AMM.h>
2#include <test/jtx/Env.h>
3#include <test/jtx/TestHelpers.h>
4#include <test/jtx/amount.h>
5#include <test/jtx/deposit.h>
6#include <test/jtx/multisign.h>
7#include <test/jtx/offer.h>
8#include <test/jtx/owners.h> // IWYU pragma: keep
9#include <test/jtx/pay.h>
10#include <test/jtx/permissioned_domains.h>
11#include <test/jtx/proposal.h>
12#include <test/jtx/sig.h>
13#include <test/jtx/sponsor.h>
14#include <test/jtx/ticket.h>
15#include <test/jtx/token.h>
16#include <test/jtx/trust.h>
17#include <test/jtx/txflags.h>
18
19#include <xrpl/basics/base_uint.h>
20#include <xrpl/basics/strHex.h>
21#include <xrpl/beast/unit_test/suite.h>
22#include <xrpl/json/json_reader.h>
23#include <xrpl/json/json_value.h>
24#include <xrpl/json/to_string.h>
25#include <xrpl/protocol/AccountID.h>
26#include <xrpl/protocol/ErrorCodes.h>
27#include <xrpl/protocol/Feature.h>
28#include <xrpl/protocol/Indexes.h>
29#include <xrpl/protocol/SField.h>
30#include <xrpl/protocol/Seed.h>
31#include <xrpl/protocol/SeqProxy.h>
32#include <xrpl/protocol/TxFlags.h>
33#include <xrpl/protocol/jss.h>
34#include <xrpl/protocol/nft.h>
35#include <xrpl/tx/transactors/nft/NFTokenMint.h>
36
37#include <algorithm>
38#include <chrono> // IWYU pragma: keep
39#include <cstdint>
40#include <iterator>
41#include <optional>
42#include <ranges>
43#include <vector>
44
45namespace xrpl::test {
46
47static char const* gBobAccountObjects[] = {
48 R"json({
49 "Account" : "rPMh7Pi9ct699iZUTWaytJUoHcJ7cgyziK",
50 "BookDirectory" : "50AD0A9E54D2B381288D535EB724E4275FFBF41580D28A925D038D7EA4C68000",
51 "BookNode" : "0",
52 "Flags" : 65536,
53 "LedgerEntryType" : "Offer",
54 "OwnerNode" : "0",
55 "Sequence" : 6,
56 "TakerGets" : {
57 "currency" : "USD",
58 "issuer" : "rPMh7Pi9ct699iZUTWaytJUoHcJ7cgyziK",
59 "value" : "1"
60 },
61 "TakerPays" : "100000000",
62 "index" : "29665262716C19830E26AEEC0916E476FC7D8EF195FF3B4F06829E64F82A3B3E"
63})json",
64 R"json({
65 "Balance" : {
66 "currency" : "USD",
67 "issuer" : "rrrrrrrrrrrrrrrrrrrrBZbvji",
68 "value" : "-1000"
69 },
70 "Flags" : 131072,
71 "HighLimit" : {
72 "currency" : "USD",
73 "issuer" : "rPMh7Pi9ct699iZUTWaytJUoHcJ7cgyziK",
74 "value" : "1000"
75 },
76 "HighNode" : "0",
77 "LedgerEntryType" : "RippleState",
78 "LowLimit" : {
79 "currency" : "USD",
80 "issuer" : "r9cZvwKU3zzuZK9JFovGg1JC5n7QiqNL8L",
81 "value" : "0"
82 },
83 "LowNode" : "0",
84 "index" : "D13183BCFFC9AAC9F96AEBB5F66E4A652AD1F5D10273AEB615478302BEBFD4A4"
85})json",
86 R"json({
87 "Balance" : {
88 "currency" : "USD",
89 "issuer" : "rrrrrrrrrrrrrrrrrrrrBZbvji",
90 "value" : "-1000"
91 },
92 "Flags" : 131072,
93 "HighLimit" : {
94 "currency" : "USD",
95 "issuer" : "rPMh7Pi9ct699iZUTWaytJUoHcJ7cgyziK",
96 "value" : "1000"
97 },
98 "HighNode" : "0",
99 "LedgerEntryType" : "RippleState",
100 "LowLimit" : {
101 "currency" : "USD",
102 "issuer" : "r32rQHyesiTtdWFU7UJVtff4nCR5SHCbJW",
103 "value" : "0"
104 },
105 "LowNode" : "0",
106 "index" : "D89BC239086183EB9458C396E643795C1134963E6550E682A190A5F021766D43"
107})json",
108 R"json({
109 "Account" : "rPMh7Pi9ct699iZUTWaytJUoHcJ7cgyziK",
110 "BookDirectory" : "B025997A323F5C3E03DDF1334471F5984ABDE31C59D463525D038D7EA4C68000",
111 "BookNode" : "0",
112 "Flags" : 65536,
113 "LedgerEntryType" : "Offer",
114 "OwnerNode" : "0",
115 "Sequence" : 7,
116 "TakerGets" : {
117 "currency" : "USD",
118 "issuer" : "r32rQHyesiTtdWFU7UJVtff4nCR5SHCbJW",
119 "value" : "1"
120 },
121 "TakerPays" : "100000000",
122 "index" : "F03ABE26CB8C5F4AFB31A86590BD25C64C5756FCE5CE9704C27AFE291A4A29A1"
123})json",
124};
125
127{
128public:
129 void
131 {
132 testcase("error cases");
133
134 using namespace jtx;
135 Env env(*this);
136
137 // test error on no account
138 {
139 json::Value const params;
140 auto resp = env.rpc("json", "account_objects", to_string(params));
141 BEAST_EXPECT(resp[jss::result][jss::error] == "invalidParams");
142 BEAST_EXPECT(resp[jss::result][jss::error_code] == RpcInvalidParams);
143 BEAST_EXPECT(resp[jss::result][jss::error_message] == "Missing field 'account'.");
144 }
145 // test account non-string
146 {
147 auto const testInvalidAccountParam = [&](auto const& param) {
148 json::Value params;
149 params[jss::account] = param;
150 auto jrr = env.rpc("json", "account_objects", to_string(params))[jss::result];
151 BEAST_EXPECT(jrr[jss::error] == "invalidParams");
152 BEAST_EXPECT(jrr[jss::error_code] == RpcInvalidParams);
153 BEAST_EXPECT(jrr[jss::error_message] == "Invalid field 'account'.");
154 };
155
156 testInvalidAccountParam(1);
157 testInvalidAccountParam(1.1);
158 testInvalidAccountParam(true);
159 testInvalidAccountParam(json::Value(json::ValueType::Null));
160 testInvalidAccountParam(json::Value(json::ValueType::Object));
161 testInvalidAccountParam(json::Value(json::ValueType::Array));
162 }
163 // test error on malformed account string.
164 {
165 json::Value params;
166 params[jss::account] = "n94JNrQYkDrpt62bbSR7nVEhdyAvcJXRAsjEkFYyqRkh9SUTYEqV";
167 auto resp = env.rpc("json", "account_objects", to_string(params));
168 BEAST_EXPECT(resp[jss::result][jss::error] == "actMalformed");
169 BEAST_EXPECT(resp[jss::result][jss::error_code] == RpcActMalformed);
170 BEAST_EXPECT(resp[jss::result][jss::error_message] == "Account malformed.");
171 }
172 // test error on account that's not in the ledger.
173 {
174 json::Value params;
175 params[jss::account] = Account{"bogie"}.human();
176 auto resp = env.rpc("json", "account_objects", to_string(params));
177 BEAST_EXPECT(resp[jss::result][jss::error] == "actNotFound");
178 BEAST_EXPECT(resp[jss::result][jss::error_code] == RpcActNotFound);
179 BEAST_EXPECT(resp[jss::result][jss::error_message] == "Account not found.");
180 }
181 Account const bob{"bob"};
182 // test error on large ledger_index.
183 {
184 json::Value params;
185 params[jss::account] = bob.human();
186 params[jss::ledger_index] = 10;
187 auto resp = env.rpc("json", "account_objects", to_string(params));
188 BEAST_EXPECT(resp[jss::result][jss::error] == "lgrNotFound");
189 BEAST_EXPECT(resp[jss::result][jss::error_code] == RpcLgrNotFound);
190 BEAST_EXPECT(resp[jss::result][jss::error_message] == "ledgerNotFound");
191 }
192
193 env.fund(XRP(1000), bob);
194 // test error on type param not a string
195 {
196 json::Value params;
197 params[jss::account] = bob.human();
198 params[jss::type] = 10;
199 auto resp = env.rpc("json", "account_objects", to_string(params));
200 BEAST_EXPECT(resp[jss::result][jss::error] == "invalidParams");
201 BEAST_EXPECT(resp[jss::result][jss::error_code] == RpcInvalidParams);
202 BEAST_EXPECT(
203 resp[jss::result][jss::error_message] == "Invalid field 'type', not string.");
204 }
205 // test error on type param not a valid type
206 {
207 json::Value params;
208 params[jss::account] = bob.human();
209 params[jss::type] = "expedited";
210 auto resp = env.rpc("json", "account_objects", to_string(params));
211 BEAST_EXPECT(resp[jss::result][jss::error] == "invalidParams");
212 BEAST_EXPECT(resp[jss::result][jss::error_code] == RpcInvalidParams);
213 BEAST_EXPECT(resp[jss::result][jss::error_message] == "Invalid field 'type'.");
214 }
215 // test error on limit -ve
216 {
217 json::Value params;
218 params[jss::account] = bob.human();
219 params[jss::limit] = -1;
220 auto resp = env.rpc("json", "account_objects", to_string(params));
221 BEAST_EXPECT(resp[jss::result][jss::error] == "invalidParams");
222 BEAST_EXPECT(resp[jss::result][jss::error_code] == RpcInvalidParams);
223 BEAST_EXPECT(
224 resp[jss::result][jss::error_message] ==
225 "Invalid field 'limit', not unsigned integer.");
226 }
227 // test error on sponsored param not a boolean
228 {
229 json::Value params;
230 params[jss::account] = bob.human();
231 params[jss::sponsored] = "true";
232 auto resp = env.rpc("json", "account_objects", to_string(params));
233 BEAST_EXPECT(resp[jss::result][jss::error] == "invalidParams");
234 BEAST_EXPECT(resp[jss::result][jss::error_code] == RpcInvalidParams);
235 BEAST_EXPECT(
236 resp[jss::result][jss::error_message] == "Invalid field 'sponsored', not boolean.");
237 }
238 // test errors on marker
239 {
240 Account const gw{"G"};
241 env.fund(XRP(1000), gw);
242 auto const usd = gw["USD"];
243 env.trust(usd(1000), bob);
244 env(pay(gw, bob, XRP(1)));
245 env(offer(bob, XRP(100), bob["USD"](1)), Txflags(tfPassive));
246
247 json::Value params;
248 params[jss::account] = bob.human();
249 params[jss::limit] = 1;
250 auto resp = env.rpc("json", "account_objects", to_string(params));
251
252 auto const resumeMarker = resp[jss::result][jss::marker];
253 std::string mark = to_string(resumeMarker);
254 params[jss::marker] = 10;
255 resp = env.rpc("json", "account_objects", to_string(params));
256 BEAST_EXPECT(resp[jss::result][jss::error] == "invalidParams");
257 BEAST_EXPECT(resp[jss::result][jss::error_code] == RpcInvalidParams);
258 BEAST_EXPECT(
259 resp[jss::result][jss::error_message] == "Invalid field 'marker', not string.");
260
261 params[jss::marker] = "This is a string with no comma";
262 resp = env.rpc("json", "account_objects", to_string(params));
263 BEAST_EXPECT(resp[jss::result][jss::error] == "invalidParams");
264 BEAST_EXPECT(resp[jss::result][jss::error_code] == RpcInvalidParams);
265 BEAST_EXPECT(resp[jss::result][jss::error_message] == "Invalid field 'marker'.");
266
267 params[jss::marker] = "This string has a comma, but is not hex";
268 resp = env.rpc("json", "account_objects", to_string(params));
269 BEAST_EXPECT(resp[jss::result][jss::error] == "invalidParams");
270 BEAST_EXPECT(resp[jss::result][jss::error_code] == RpcInvalidParams);
271 BEAST_EXPECT(resp[jss::result][jss::error_message] == "Invalid field 'marker'.");
272
273 params[jss::marker] = std::string(&mark[1U], 64);
274 resp = env.rpc("json", "account_objects", to_string(params));
275 BEAST_EXPECT(resp[jss::result][jss::error] == "invalidParams");
276 BEAST_EXPECT(resp[jss::result][jss::error_code] == RpcInvalidParams);
277 BEAST_EXPECT(resp[jss::result][jss::error_message] == "Invalid field 'marker'.");
278
279 params[jss::marker] = std::string(&mark[1U], 65);
280 resp = env.rpc("json", "account_objects", to_string(params));
281 BEAST_EXPECT(resp[jss::result][jss::error] == "invalidParams");
282 BEAST_EXPECT(resp[jss::result][jss::error_code] == RpcInvalidParams);
283 BEAST_EXPECT(resp[jss::result][jss::error_message] == "Invalid field 'marker'.");
284
285 params[jss::marker] = std::string(&mark[1U], 65) + "not hex";
286 resp = env.rpc("json", "account_objects", to_string(params));
287 BEAST_EXPECT(resp[jss::result][jss::error] == "invalidParams");
288 BEAST_EXPECT(resp[jss::result][jss::error_code] == RpcInvalidParams);
289 BEAST_EXPECT(resp[jss::result][jss::error_message] == "Invalid field 'marker'.");
290
291 // Should this be an error?
292 // A hex digit is absent from the end of marker.
293 // No account objects returned.
294 params[jss::marker] = std::string(&mark[1U], 128);
295 resp = env.rpc("json", "account_objects", to_string(params));
296 BEAST_EXPECT(resp[jss::result][jss::account_objects].size() == 0);
297 }
298 }
299
300 void
302 {
303 testcase("unsteppedThenStepped");
304
305 using namespace jtx;
306 Env env(*this);
307
308 Account const gw1{"G1"};
309 Account const gw2{"G2"};
310 Account const bob{"bob"};
311
312 auto const usD1 = gw1["USD"];
313 auto const usD2 = gw2["USD"];
314
315 env.fund(XRP(1000), gw1, gw2, bob);
316 env.trust(usD1(1000), bob);
317 env.trust(usD2(1000), bob);
318
319 env(pay(gw1, bob, usD1(1000)));
320 env(pay(gw2, bob, usD2(1000)));
321
322 env(offer(bob, XRP(100), bob["USD"](1)), Txflags(tfPassive));
323 env(offer(bob, XRP(100), usD1(1)), Txflags(tfPassive));
324
325 json::Value bobj[4];
326 for (int i = 0; i < 4; ++i)
328
329 // test 'unstepped'
330 // i.e. request account objects without explicit limit/marker paging
331 {
332 json::Value params;
333 params[jss::account] = bob.human();
334 auto resp = env.rpc("json", "account_objects", to_string(params));
335 BEAST_EXPECT(!resp.isMember(jss::marker));
336
337 BEAST_EXPECT(resp[jss::result][jss::account_objects].size() == 4);
338 for (int i = 0; i < 4; ++i)
339 {
340 auto& aobj = resp[jss::result][jss::account_objects][i];
341 aobj.removeMember("PreviousTxnID");
342 aobj.removeMember("PreviousTxnLgrSeq");
343 BEAST_EXPECT(aobj == bobj[i]);
344 }
345 }
346 // test request with type parameter as filter, unstepped
347 {
348 json::Value params;
349 params[jss::account] = bob.human();
350 params[jss::type] = jss::state;
351 auto resp = env.rpc("json", "account_objects", to_string(params));
352 BEAST_EXPECT(!resp.isMember(jss::marker));
353
354 BEAST_EXPECT(resp[jss::result][jss::account_objects].size() == 2);
355 for (int i = 0; i < 2; ++i)
356 {
357 auto& aobj = resp[jss::result][jss::account_objects][i];
358 aobj.removeMember("PreviousTxnID");
359 aobj.removeMember("PreviousTxnLgrSeq");
360 BEAST_EXPECT(aobj == bobj[i + 1]);
361 }
362 }
363 // test stepped one-at-a-time with limit=1, resume from prev marker
364 {
365 json::Value params;
366 params[jss::account] = bob.human();
367 params[jss::limit] = 1;
368 for (int i = 0; i < 4; ++i)
369 {
370 auto resp = env.rpc("json", "account_objects", to_string(params));
371 auto& aobjs = resp[jss::result][jss::account_objects];
372 BEAST_EXPECT(aobjs.size() == 1);
373 auto& aobj = aobjs[0U];
374 if (i < 3)
375 {
376 BEAST_EXPECT(resp[jss::result][jss::limit] == 1);
377 }
378 else
379 {
380 BEAST_EXPECT(!resp[jss::result].isMember(jss::limit));
381 }
382
383 aobj.removeMember("PreviousTxnID");
384 aobj.removeMember("PreviousTxnLgrSeq");
385
386 BEAST_EXPECT(aobj == bobj[i]);
387
388 params[jss::marker] = resp[jss::result][jss::marker];
389 }
390 }
391 }
392
393 void
395 {
396 // The preceding test case, unsteppedThenStepped(), found a bug in the
397 // support for NFToken Pages. So we're leaving that test alone when
398 // adding tests to exercise NFTokenPages.
399 testcase("unsteppedThenSteppedWithNFTs");
400
401 using namespace jtx;
402 Env env(*this);
403
404 Account const gw1{"G1"};
405 Account const gw2{"G2"};
406 Account const bob{"bob"};
407
408 auto const usD1 = gw1["USD"];
409 auto const usD2 = gw2["USD"];
410
411 env.fund(XRP(1000), gw1, gw2, bob);
412 env.close();
413
414 // Check behavior if there are no account objects.
415 {
416 // Unpaged
417 json::Value params;
418 params[jss::account] = bob.human();
419 auto resp = env.rpc("json", "account_objects", to_string(params));
420 BEAST_EXPECT(!resp.isMember(jss::marker));
421 BEAST_EXPECT(resp[jss::result][jss::account_objects].size() == 0);
422
423 // Limit == 1
424 params[jss::limit] = 1;
425 resp = env.rpc("json", "account_objects", to_string(params));
426 BEAST_EXPECT(!resp.isMember(jss::marker));
427 BEAST_EXPECT(resp[jss::result][jss::account_objects].size() == 0);
428 }
429
430 // Check behavior if there are only NFTokens.
431 env(token::mint(bob, 0u), Txflags(tfTransferable));
432 env.close();
433
434 // test 'unstepped'
435 // i.e. request account objects without explicit limit/marker paging
436 json::Value unpaged;
437 {
438 json::Value params;
439 params[jss::account] = bob.human();
440 auto resp = env.rpc("json", "account_objects", to_string(params));
441 BEAST_EXPECT(!resp.isMember(jss::marker));
442
443 unpaged = resp[jss::result][jss::account_objects];
444 BEAST_EXPECT(unpaged.size() == 1);
445 }
446 // test request with type parameter as filter, unstepped
447 {
448 json::Value params;
449 params[jss::account] = bob.human();
450 params[jss::type] = jss::nft_page;
451 auto resp = env.rpc("json", "account_objects", to_string(params));
452 BEAST_EXPECT(!resp.isMember(jss::marker));
453 json::Value& aobjs = resp[jss::result][jss::account_objects];
454 BEAST_EXPECT(aobjs.size() == 1);
455 BEAST_EXPECT(aobjs[0u][sfLedgerEntryType.jsonName] == jss::NFTokenPage);
456 BEAST_EXPECT(aobjs[0u][sfNFTokens.jsonName].size() == 1);
457 }
458 // test stepped one-at-a-time with limit=1, resume from prev marker
459 {
460 json::Value params;
461 params[jss::account] = bob.human();
462 params[jss::limit] = 1;
463
464 json::Value resp = env.rpc("json", "account_objects", to_string(params));
465 json::Value& aobjs = resp[jss::result][jss::account_objects];
466 BEAST_EXPECT(aobjs.size() == 1);
467 auto const& aobj = aobjs[0U];
468 BEAST_EXPECT(!resp[jss::result].isMember(jss::limit));
469 BEAST_EXPECT(!resp[jss::result].isMember(jss::marker));
470
471 BEAST_EXPECT(aobj == unpaged[0u]);
472 }
473
474 // Add more objects in addition to the NFToken Page.
475 env.trust(usD1(1000), bob);
476 env.trust(usD2(1000), bob);
477
478 env(pay(gw1, bob, usD1(1000)));
479 env(pay(gw2, bob, usD2(1000)));
480
481 env(offer(bob, XRP(100), bob["USD"](1)), Txflags(tfPassive));
482 env(offer(bob, XRP(100), usD1(1)), Txflags(tfPassive));
483 env.close();
484
485 // test 'unstepped'
486 {
487 json::Value params;
488 params[jss::account] = bob.human();
489 auto resp = env.rpc("json", "account_objects", to_string(params));
490 BEAST_EXPECT(!resp.isMember(jss::marker));
491
492 unpaged = resp[jss::result][jss::account_objects];
493 BEAST_EXPECT(unpaged.size() == 5);
494 }
495 // test request with type parameter as filter, unstepped
496 {
497 json::Value params;
498 params[jss::account] = bob.human();
499 params[jss::type] = jss::nft_page;
500 auto resp = env.rpc("json", "account_objects", to_string(params));
501 BEAST_EXPECT(!resp.isMember(jss::marker));
502 json::Value& aobjs = resp[jss::result][jss::account_objects];
503 BEAST_EXPECT(aobjs.size() == 1);
504 BEAST_EXPECT(aobjs[0u][sfLedgerEntryType.jsonName] == jss::NFTokenPage);
505 BEAST_EXPECT(aobjs[0u][sfNFTokens.jsonName].size() == 1);
506 }
507 // test stepped one-at-a-time with limit=1, resume from prev marker
508 {
509 json::Value params;
510 params[jss::account] = bob.human();
511 params[jss::limit] = 1;
512 for (int i = 0; i < 5; ++i)
513 {
514 json::Value resp = env.rpc("json", "account_objects", to_string(params));
515 json::Value& aobjs = resp[jss::result][jss::account_objects];
516 BEAST_EXPECT(aobjs.size() == 1);
517 auto const& aobj = aobjs[0U];
518 if (i < 4)
519 {
520 BEAST_EXPECT(resp[jss::result][jss::limit] == 1);
521 BEAST_EXPECT(resp[jss::result].isMember(jss::marker));
522 }
523 else
524 {
525 BEAST_EXPECT(!resp[jss::result].isMember(jss::limit));
526 BEAST_EXPECT(!resp[jss::result].isMember(jss::marker));
527 }
528
529 BEAST_EXPECT(aobj == unpaged[i]);
530
531 params[jss::marker] = resp[jss::result][jss::marker];
532 }
533 }
534
535 // Make sure things still work if there is more than 1 NFT Page.
536 for (int i = 0; i < 32; ++i)
537 {
538 env(token::mint(bob, 0u), Txflags(tfTransferable));
539 env.close();
540 }
541 // test 'unstepped'
542 {
543 json::Value params;
544 params[jss::account] = bob.human();
545 auto resp = env.rpc("json", "account_objects", to_string(params));
546 BEAST_EXPECT(!resp.isMember(jss::marker));
547
548 unpaged = resp[jss::result][jss::account_objects];
549 BEAST_EXPECT(unpaged.size() == 6);
550 }
551 // test request with type parameter as filter, unstepped
552 {
553 json::Value params;
554 params[jss::account] = bob.human();
555 params[jss::type] = jss::nft_page;
556 auto resp = env.rpc("json", "account_objects", to_string(params));
557 BEAST_EXPECT(!resp.isMember(jss::marker));
558 json::Value const& aobjs = resp[jss::result][jss::account_objects];
559 BEAST_EXPECT(aobjs.size() == 2);
560 }
561 // test stepped one-at-a-time with limit=1, resume from prev marker
562 {
563 json::Value params;
564 params[jss::account] = bob.human();
565 params[jss::limit] = 1;
566 for (int i = 0; i < 6; ++i)
567 {
568 json::Value resp = env.rpc("json", "account_objects", to_string(params));
569 json::Value& aobjs = resp[jss::result][jss::account_objects];
570 BEAST_EXPECT(aobjs.size() == 1);
571 auto const& aobj = aobjs[0U];
572 if (i < 5)
573 {
574 BEAST_EXPECT(resp[jss::result][jss::limit] == 1);
575 BEAST_EXPECT(resp[jss::result].isMember(jss::marker));
576 }
577 else
578 {
579 BEAST_EXPECT(!resp[jss::result].isMember(jss::limit));
580 BEAST_EXPECT(!resp[jss::result].isMember(jss::marker));
581 }
582
583 BEAST_EXPECT(aobj == unpaged[i]);
584
585 params[jss::marker] = resp[jss::result][jss::marker];
586 }
587 }
588 }
589
590 void
592 {
593 testcase("object types");
594
595 // Give gw a bunch of ledger objects and make sure we can retrieve
596 // them by type.
597 using namespace jtx;
598
599 Account const alice{"alice"};
600 Account const gw{"gateway"};
601 auto const usd = gw["USD"];
602
603 auto const features = testableAmendments() | featurePermissionedDomains;
604 Env env(*this, features);
605
606 // Make a lambda we can use to get "account_objects" easily.
607 auto const acctObjs = [&env](
608 AccountID const& acct,
610 std::optional<std::uint16_t> limit = std::nullopt,
611 std::optional<std::string> marker = std::nullopt) {
612 json::Value params;
613 params[jss::account] = to_string(acct);
614 if (type)
615 params[jss::type] = *type;
616 if (limit)
617 params[jss::limit] = *limit;
618 if (marker)
619 params[jss::marker] = *marker;
620 params[jss::ledger_index] = "validated";
621 return env.rpc("json", "account_objects", to_string(params));
622 };
623
624 // Make a lambda that easily identifies the size of account objects.
625 auto acctObjsIsSize = [](json::Value const& resp, unsigned size) {
626 return resp[jss::result][jss::account_objects].isArray() &&
627 (resp[jss::result][jss::account_objects].size() == size);
628 };
629
630 // Make a lambda that checks if the response has error for invalid type
631 auto const acctObjsTypeIsInvalid = [](json::Value const& resp) {
632 return resp[jss::result][jss::error] == "invalidParams" &&
633 resp[jss::result][jss::error_code] == RpcInvalidParams &&
634 resp[jss::result][jss::error_message] == "Invalid field \'type\'.";
635 };
636
637 env.fund(XRP(10000), gw, alice);
638 env.close();
639
640 // Since the account is empty now, all account objects should come
641 // back empty.
642 BEAST_EXPECT(acctObjsIsSize(acctObjs(gw, jss::account), 0));
643 BEAST_EXPECT(acctObjsIsSize(acctObjs(gw, jss::check), 0));
644 BEAST_EXPECT(acctObjsIsSize(acctObjs(gw, jss::deposit_preauth), 0));
645 BEAST_EXPECT(acctObjsIsSize(acctObjs(gw, jss::escrow), 0));
646 BEAST_EXPECT(acctObjsIsSize(acctObjs(gw, jss::nft_page), 0));
647 BEAST_EXPECT(acctObjsIsSize(acctObjs(gw, jss::offer), 0));
648 BEAST_EXPECT(acctObjsIsSize(acctObjs(gw, jss::payment_channel), 0));
649 BEAST_EXPECT(acctObjsIsSize(acctObjs(gw, jss::signer_list), 0));
650 BEAST_EXPECT(acctObjsIsSize(acctObjs(gw, jss::state), 0));
651 BEAST_EXPECT(acctObjsIsSize(acctObjs(gw, jss::ticket), 0));
652 BEAST_EXPECT(acctObjsIsSize(acctObjs(gw, jss::amm), 0));
653 BEAST_EXPECT(acctObjsIsSize(acctObjs(gw, jss::did), 0));
654 BEAST_EXPECT(acctObjsIsSize(acctObjs(gw, jss::permissioned_domain), 0));
655 BEAST_EXPECT(acctObjsIsSize(acctObjs(gw, jss::sponsorship), 0));
656
657 // we expect invalid field type reported for the following types
658 BEAST_EXPECT(acctObjsTypeIsInvalid(acctObjs(gw, jss::amendments)));
659 BEAST_EXPECT(acctObjsTypeIsInvalid(acctObjs(gw, jss::directory)));
660 BEAST_EXPECT(acctObjsTypeIsInvalid(acctObjs(gw, jss::fee)));
661 BEAST_EXPECT(acctObjsTypeIsInvalid(acctObjs(gw, jss::hashes)));
662 BEAST_EXPECT(acctObjsTypeIsInvalid(acctObjs(gw, jss::NegativeUNL)));
663
664 // gw mints an NFT so we can find it.
665 UInt256 const nftID{token::getNextID(env, gw, 0u, tfTransferable)};
666 env(token::mint(gw, 0u), Txflags(tfTransferable));
667 env.close();
668 {
669 // Find the NFToken page and make sure it's the right one.
670 json::Value const resp = acctObjs(gw, jss::nft_page);
671 BEAST_EXPECT(acctObjsIsSize(resp, 1));
672
673 auto const& nftPage = resp[jss::result][jss::account_objects][0u];
674 BEAST_EXPECT(nftPage[sfNFTokens.jsonName].size() == 1);
675 BEAST_EXPECT(
676 nftPage[sfNFTokens.jsonName][0u][sfNFToken.jsonName][sfNFTokenID.jsonName] ==
677 to_string(nftID));
678 }
679
680 // Set up a trust line so we can find it.
681 env.trust(usd(1000), alice);
682 env.close();
683 env(pay(gw, alice, usd(5)));
684 env.close();
685 {
686 // Find the trustline and make sure it's the right one.
687 json::Value const resp = acctObjs(gw, jss::state);
688 BEAST_EXPECT(acctObjsIsSize(resp, 1));
689
690 auto const& state = resp[jss::result][jss::account_objects][0u];
691 BEAST_EXPECT(state[sfBalance.jsonName][jss::value].asInt() == -5);
692 BEAST_EXPECT(state[sfHighLimit.jsonName][jss::value].asUInt() == 1000);
693 }
694 // gw writes a check for USD(10) to alice.
695 env(check::create(gw, alice, usd(10)));
696 env.close();
697 {
698 // Find the check.
699 json::Value const resp = acctObjs(gw, jss::check);
700 BEAST_EXPECT(acctObjsIsSize(resp, 1));
701
702 auto const& check = resp[jss::result][jss::account_objects][0u];
703 BEAST_EXPECT(check[sfAccount.jsonName] == gw.human());
704 BEAST_EXPECT(check[sfDestination.jsonName] == alice.human());
705 BEAST_EXPECT(check[sfSendMax.jsonName][jss::value].asUInt() == 10);
706 }
707 // gw preauthorizes payments from alice.
708 env(deposit::auth(gw, alice));
709 env.close();
710 {
711 // Find the pre-authorization.
712 json::Value const resp = acctObjs(gw, jss::deposit_preauth);
713 BEAST_EXPECT(acctObjsIsSize(resp, 1));
714
715 auto const& preauth = resp[jss::result][jss::account_objects][0u];
716 BEAST_EXPECT(preauth[sfAccount.jsonName] == gw.human());
717 BEAST_EXPECT(preauth[sfAuthorize.jsonName] == alice.human());
718 }
719 {
720 // gw creates an escrow that we can look for in the ledger.
721 json::Value jvEscrow;
722 jvEscrow[jss::TransactionType] = jss::EscrowCreate;
723 jvEscrow[jss::Account] = gw.human();
724 jvEscrow[jss::Destination] = gw.human();
725 jvEscrow[jss::Amount] = XRP(100).value().getJson(JsonOptions::Values::None);
726 jvEscrow[sfFinishAfter.jsonName] = env.now().time_since_epoch().count() + 1;
727 env(jvEscrow);
728 env.close();
729 }
730 {
731 // Find the escrow.
732 json::Value const resp = acctObjs(gw, jss::escrow);
733 BEAST_EXPECT(acctObjsIsSize(resp, 1));
734
735 auto const& escrow = resp[jss::result][jss::account_objects][0u];
736 BEAST_EXPECT(escrow[sfAccount.jsonName] == gw.human());
737 BEAST_EXPECT(escrow[sfDestination.jsonName] == gw.human());
738 BEAST_EXPECT(escrow[sfAmount.jsonName].asUInt() == 100'000'000);
739 }
740
741 {
742 std::string const credentialType1 = "credential1";
743 Account const issuer("issuer");
744 env.fund(XRP(5000), issuer);
745
746 // gw creates an PermissionedDomain.
747 env(pdomain::setTx(gw, {{.issuer = issuer, .credType = credentialType1}}));
748 env.close();
749
750 // Find the PermissionedDomain.
751 json::Value const resp = acctObjs(gw, jss::permissioned_domain);
752 BEAST_EXPECT(acctObjsIsSize(resp, 1));
753
754 auto const& permissionedDomain = resp[jss::result][jss::account_objects][0u];
755 BEAST_EXPECT(
756 permissionedDomain.isMember(jss::Owner) &&
757 (permissionedDomain[jss::Owner] == gw.human()));
758 bool const check1 = BEAST_EXPECT(
759 permissionedDomain.isMember(jss::AcceptedCredentials) &&
760 permissionedDomain[jss::AcceptedCredentials].isArray() &&
761 (permissionedDomain[jss::AcceptedCredentials].size() == 1) &&
762 (permissionedDomain[jss::AcceptedCredentials][0u].isMember(jss::Credential)));
763
764 if (check1)
765 {
766 auto const& credential =
767 permissionedDomain[jss::AcceptedCredentials][0u][jss::Credential];
768 BEAST_EXPECT(
769 credential.isMember(sfIssuer.jsonName) &&
770 (credential[sfIssuer.jsonName] == issuer.human()));
771 BEAST_EXPECT(
772 credential.isMember(sfCredentialType.jsonName) &&
773 (credential[sfCredentialType.jsonName] == strHex(credentialType1)));
774 }
775 }
776
777 // gw creates an offer that we can look for in the ledger.
778 env(offer(gw, usd(7), XRP(14)));
779 env.close();
780 {
781 // Find the offer.
782 json::Value const resp = acctObjs(gw, jss::offer);
783 BEAST_EXPECT(acctObjsIsSize(resp, 1));
784
785 auto const& offer = resp[jss::result][jss::account_objects][0u];
786 BEAST_EXPECT(offer[sfAccount.jsonName] == gw.human());
787 BEAST_EXPECT(offer[sfTakerGets.jsonName].asUInt() == 14'000'000);
788 BEAST_EXPECT(offer[sfTakerPays.jsonName][jss::value].asUInt() == 7);
789 }
790 {
791 // Create a payment channel from qw to alice that we can look
792 // for.
793 json::Value jvPayChan;
794 jvPayChan[jss::TransactionType] = jss::PaymentChannelCreate;
795 jvPayChan[jss::Account] = gw.human();
796 jvPayChan[jss::Destination] = alice.human();
797 jvPayChan[jss::Amount] = XRP(300).value().getJson(JsonOptions::Values::None);
798 jvPayChan[sfSettleDelay.jsonName] = 24 * 60 * 60;
799 jvPayChan[sfPublicKey.jsonName] = strHex(gw.pk().slice());
800 env(jvPayChan);
801 env.close();
802 }
803 {
804 // Find the payment channel.
805 json::Value const resp = acctObjs(gw, jss::payment_channel);
806 BEAST_EXPECT(acctObjsIsSize(resp, 1));
807
808 auto const& payChan = resp[jss::result][jss::account_objects][0u];
809 BEAST_EXPECT(payChan[sfAccount.jsonName] == gw.human());
810 BEAST_EXPECT(payChan[sfAmount.jsonName].asUInt() == 300'000'000);
811 BEAST_EXPECT(payChan[sfSettleDelay.jsonName].asUInt() == 24 * 60 * 60);
812 }
813
814 {
815 // gw creates a DID that we can look for in the ledger.
816 json::Value jvDID;
817 jvDID[jss::TransactionType] = jss::DIDSet;
818 jvDID[jss::Account] = gw.human();
819 jvDID[sfURI.jsonName] = strHex(std::string{"uri"});
820 env(jvDID);
821 env.close();
822 }
823 {
824 // Find the DID.
825 json::Value const resp = acctObjs(gw, jss::did);
826 BEAST_EXPECT(acctObjsIsSize(resp, 1));
827
828 auto const& did = resp[jss::result][jss::account_objects][0u];
829 BEAST_EXPECT(did[sfAccount.jsonName] == gw.human());
830 BEAST_EXPECT(did[sfURI.jsonName] == strHex(std::string{"uri"}));
831 }
832 // Make gw multisigning by adding a signerList.
833 env(jtx::signers(gw, 6, {{alice, 7}}));
834 env.close();
835 {
836 // Find the signer list.
837 json::Value const resp = acctObjs(gw, jss::signer_list);
838 BEAST_EXPECT(acctObjsIsSize(resp, 1));
839
840 auto const& signerList = resp[jss::result][jss::account_objects][0u];
841 BEAST_EXPECT(signerList[sfSignerQuorum.jsonName] == 6);
842 auto const& entry = signerList[sfSignerEntries.jsonName][0u][sfSignerEntry.jsonName];
843 BEAST_EXPECT(entry[sfAccount.jsonName] == alice.human());
844 BEAST_EXPECT(entry[sfSignerWeight.jsonName].asUInt() == 7);
845 }
846
847 {
848 auto const seq = env.seq(gw);
849 // Create a Ticket for gw.
850 env(ticket::create(gw, 1));
851 env.close();
852
853 // Find the ticket.
854 json::Value const resp = acctObjs(gw, jss::ticket);
855 BEAST_EXPECT(acctObjsIsSize(resp, 1));
856
857 auto const& ticket = resp[jss::result][jss::account_objects][0u];
858 BEAST_EXPECT(ticket[sfAccount.jsonName] == gw.human());
859 BEAST_EXPECT(ticket[sfLedgerEntryType.jsonName] == jss::Ticket);
860 BEAST_EXPECT(ticket[sfTicketSequence.jsonName].asUInt() == seq + 1);
861 }
862
863 {
864 // Create a sponsorship
865 env(sponsor::set(alice, tfSponsorshipSetRequireSignForFee, 200, XRP(100), drops(10)),
867 env.close();
868
869 // Find the sponsorship.
870 for (auto const& acct : {alice, gw})
871 {
872 json::Value const resp = acctObjs(acct, jss::sponsorship);
873 BEAST_EXPECT(acctObjsIsSize(resp, 1));
874
875 auto const& sponsorship = resp[jss::result][jss::account_objects][0u];
876
877 BEAST_EXPECT(sponsorship[sfOwner.jsonName] == alice.human());
878 BEAST_EXPECT(sponsorship[sfSponsee.jsonName] == gw.human());
879 BEAST_EXPECT(
880 sponsorship[sfFlags.jsonName].asUInt() == tfSponsorshipSetRequireSignForFee);
881 BEAST_EXPECT(sponsorship[sfRemainingOwnerCount.jsonName].asUInt() == 200);
882 BEAST_EXPECT(sponsorship[sfFeeAmount.jsonName].asUInt() == 100000000);
883 BEAST_EXPECT(sponsorship[sfMaxFee.jsonName].asUInt() == 10);
884 }
885 }
886
887 {
888 // See how "deletion_blockers_only" handles gw's directory.
889 json::Value params;
890 params[jss::account] = gw.human();
891 params[jss::deletion_blockers_only] = true;
892 auto resp = env.rpc("json", "account_objects", to_string(params));
893
894 std::vector<std::string> const expectedLedgerTypes = [] {
896 jss::Escrow.cStr(),
897 jss::Check.cStr(),
898 jss::NFTokenPage.cStr(),
899 jss::RippleState.cStr(),
900 jss::PayChannel.cStr(),
901 jss::PermissionedDomain.cStr(),
902 jss::Sponsorship.cStr(),
903 };
905 return v;
906 }();
907
908 std::uint32_t const expectedAccountObjects{
909 static_cast<std::uint32_t>(std::size(expectedLedgerTypes)),
910 };
911
912 if (BEAST_EXPECT(acctObjsIsSize(resp, expectedAccountObjects)))
913 {
914 auto const& aobjs = resp[jss::result][jss::account_objects];
915 std::vector<std::string> gotLedgerTypes;
916 gotLedgerTypes.reserve(expectedAccountObjects);
917 for (std::uint32_t i = 0; i < expectedAccountObjects; ++i)
918 {
919 gotLedgerTypes.push_back(aobjs[i]["LedgerEntryType"].asString());
920 }
921 std::ranges::sort(gotLedgerTypes);
922 BEAST_EXPECT(gotLedgerTypes == expectedLedgerTypes);
923 }
924 }
925 {
926 // See how "deletion_blockers_only" with `type` handles gw's
927 // directory.
928 json::Value params;
929 params[jss::account] = gw.human();
930 params[jss::deletion_blockers_only] = true;
931 params[jss::type] = jss::escrow;
932 auto resp = env.rpc("json", "account_objects", to_string(params));
933
934 if (BEAST_EXPECT(acctObjsIsSize(resp, 1u)))
935 {
936 auto const& aobjs = resp[jss::result][jss::account_objects];
937 BEAST_EXPECT(aobjs[0u]["LedgerEntryType"] == jss::Escrow);
938 }
939 }
940 {
941 // Make a lambda to get the types
942 auto getTypes = [&](json::Value const& resp, std::vector<std::string>& typesOut) {
943 auto const objs = resp[jss::result][jss::account_objects];
944 for (auto const& obj : resp[jss::result][jss::account_objects])
945 typesOut.push_back(obj[sfLedgerEntryType.fieldName].asString());
946 std::ranges::sort(typesOut);
947 };
948 // Make a lambda we can use to check the number of fetched
949 // account objects and their ledger type
950 auto const expectObjects = [&](json::Value const& resp,
951 std::vector<std::string> const& types) -> bool {
952 if (!acctObjsIsSize(resp, types.size()))
953 return false;
955 getTypes(resp, typesOut);
956 return types == typesOut;
957 };
958 // Find AMM objects
959 AMM amm(env, gw, XRP(1'000), usd(1'000));
960 amm.deposit(alice, usd(1));
961 // AMM account has 4 objects: AMM object and 3 trustlines
962 auto const lines = getAccountLines(env, amm.ammAccount());
963 BEAST_EXPECT(lines[jss::lines].size() == 3);
964 // request AMM only, doesn't depend on the limit
965 BEAST_EXPECT(acctObjsIsSize(acctObjs(amm.ammAccount(), jss::amm), 1));
966 // request first two objects
967 auto resp = acctObjs(amm.ammAccount(), std::nullopt, 2);
969 getTypes(resp, typesOut);
970 // request next two objects
971 resp = acctObjs(
972 amm.ammAccount(), std::nullopt, 10, resp[jss::result][jss::marker].asString());
973 getTypes(resp, typesOut);
974 BEAST_EXPECT(
975 (typesOut ==
977 jss::AMM.cStr(),
978 jss::RippleState.cStr(),
979 jss::RippleState.cStr(),
980 jss::RippleState.cStr()}));
981 // filter by state: there are three trustlines
982 resp = acctObjs(amm.ammAccount(), jss::state, 10);
983 BEAST_EXPECT(expectObjects(
984 resp, {jss::RippleState.cStr(), jss::RippleState.cStr(), jss::RippleState.cStr()}));
985 // AMM account doesn't own offers
986 BEAST_EXPECT(acctObjsIsSize(acctObjs(amm.ammAccount(), jss::offer), 0));
987 // gw account doesn't own AMM object
988 BEAST_EXPECT(acctObjsIsSize(acctObjs(gw, jss::amm), 0));
989 }
990
991 // we still expect invalid field type reported for the following types
992 BEAST_EXPECT(acctObjsTypeIsInvalid(acctObjs(gw, jss::amendments)));
993 BEAST_EXPECT(acctObjsTypeIsInvalid(acctObjs(gw, jss::directory)));
994 BEAST_EXPECT(acctObjsTypeIsInvalid(acctObjs(gw, jss::fee)));
995 BEAST_EXPECT(acctObjsTypeIsInvalid(acctObjs(gw, jss::hashes)));
996 BEAST_EXPECT(acctObjsTypeIsInvalid(acctObjs(gw, jss::NegativeUNL)));
997
998 // Run up the number of directory entries so gw has two
999 // directory nodes.
1000 for (int d = 1'000'032; d >= 1'000'000; --d)
1001 {
1002 env(offer(gw, usd(1), drops(d)));
1003 env.close();
1004 }
1005
1006 // Verify that the non-returning types still don't return anything.
1007 BEAST_EXPECT(acctObjsIsSize(acctObjs(gw, jss::account), 0));
1008 }
1009
1010 void
1012 {
1013 // there's some bug found in account_nfts method that it did not
1014 // return invalid params when providing unassociated nft marker.
1015 // this test tests both situations when providing valid nft marker
1016 // and unassociated nft marker.
1017 testcase("NFTsMarker");
1018
1019 using namespace jtx;
1020 Env env(*this);
1021
1022 Account const bob{"bob"};
1023 env.fund(XRP(10000), bob);
1024
1025 static constexpr unsigned kNftsSize = 10;
1026 for (unsigned i = 0; i < kNftsSize; i++)
1027 {
1028 env(token::mint(bob, 0));
1029 }
1030
1031 env.close();
1032
1033 // save the NFTokenIDs to use later
1034 std::vector<json::Value> tokenIDs;
1035 {
1036 json::Value params;
1037 params[jss::account] = bob.human();
1038 params[jss::ledger_index] = "validated";
1039 json::Value const resp = env.rpc("json", "account_nfts", to_string(params));
1040 json::Value const& nfts = resp[jss::result][jss::account_nfts];
1041 for (json::Value const& nft : nfts)
1042 tokenIDs.push_back(nft["NFTokenID"]);
1043 }
1044
1045 // this lambda function is used to check if the account_nfts method
1046 // returns the correct token information. lastIndex is used to query the
1047 // last marker.
1048 auto const compareNFTs = [&tokenIDs, &env, &bob](
1049 unsigned const limit, unsigned const lastIndex) {
1050 json::Value params;
1051 params[jss::account] = bob.human();
1052 params[jss::limit] = limit;
1053 params[jss::marker] = tokenIDs[lastIndex];
1054 params[jss::ledger_index] = "validated";
1055 json::Value const resp = env.rpc("json", "account_nfts", to_string(params));
1056
1057 if (resp[jss::result].isMember(jss::error))
1058 return false;
1059
1060 json::Value const& nfts = resp[jss::result][jss::account_nfts];
1061 unsigned const nftsCount =
1062 tokenIDs.size() - lastIndex - 1 < limit ? tokenIDs.size() - lastIndex - 1 : limit;
1063
1064 if (nfts.size() != nftsCount)
1065 return false;
1066
1067 for (unsigned i = 0; i < nftsCount; i++)
1068 {
1069 if (nfts[i]["NFTokenID"] != tokenIDs[lastIndex + 1 + i])
1070 return false;
1071 }
1072
1073 return true;
1074 };
1075
1076 // test a valid marker which is equal to the third tokenID
1077 BEAST_EXPECT(compareNFTs(4, 2));
1078
1079 // test a valid marker which is equal to the 8th tokenID
1080 BEAST_EXPECT(compareNFTs(4, 7));
1081
1082 // lambda that holds common code for invalid cases.
1083 auto const testInvalidMarker = [&env, &bob](auto marker, char const* errorMessage) {
1084 json::Value params;
1085 params[jss::account] = bob.human();
1086 params[jss::limit] = 4;
1087 params[jss::ledger_index] = jss::validated;
1088 params[jss::marker] = marker;
1089 json::Value const resp = env.rpc("json", "account_nfts", to_string(params));
1090 return resp[jss::result][jss::error] == "invalidParams" &&
1091 resp[jss::result][jss::error_code] == RpcInvalidParams &&
1092 resp[jss::result][jss::error_message] == errorMessage;
1093 };
1094
1095 // test an invalid marker that is not a string
1096 BEAST_EXPECT(testInvalidMarker(17, "Invalid field \'marker\', not string."));
1097
1098 // test an invalid marker that has a non-hex character
1099 BEAST_EXPECT(testInvalidMarker(
1100 "00000000F51DFC2A09D62CBBA1DFBDD4691DAC96AD98B900000000000000000G",
1101 "Invalid field \'marker\'."));
1102
1103 // this lambda function is used to create some fake marker using given
1104 // taxon and sequence because we want to test some unassociated markers
1105 // later
1106 auto const createFakeNFTMarker = [](AccountID const& issuer,
1107 std::uint32_t taxon,
1108 std::uint32_t tokenSeq,
1109 std::uint16_t flags = 0,
1110 std::uint16_t fee = 0) {
1111 // the marker has the exact same format as an NFTokenID
1112 return to_string(
1113 NFTokenMint::createNFTokenID(flags, fee, issuer, nft::toTaxon(taxon), tokenSeq));
1114 };
1115
1116 // test an unassociated marker which does not exist in the NFTokenIDs
1117 BEAST_EXPECT(testInvalidMarker(
1118 createFakeNFTMarker(bob.id(), 0x000000000, 0x00000000), "Invalid field \'marker\'."));
1119
1120 // test an unassociated marker which exceeds the maximum value of the
1121 // existing NFTokenID
1122 BEAST_EXPECT(testInvalidMarker(
1123 createFakeNFTMarker(bob.id(), 0xFFFFFFFF, 0xFFFFFFFF), "Invalid field \'marker\'."));
1124 }
1125
1126 void
1128 {
1129 testcase("account_nfts");
1130
1131 using namespace jtx;
1132 Env env(*this);
1133
1134 // test validation
1135 {
1136 auto const testInvalidAccountParam = [&](auto const& param) {
1137 json::Value params;
1138 params[jss::account] = param;
1139 auto jrr = env.rpc("json", "account_nfts", to_string(params))[jss::result];
1140 BEAST_EXPECT(jrr[jss::error] == "invalidParams");
1141 BEAST_EXPECT(jrr[jss::error_code] == RpcInvalidParams);
1142 BEAST_EXPECT(jrr[jss::error_message] == "Invalid field 'account'.");
1143 };
1144
1145 testInvalidAccountParam(1);
1146 testInvalidAccountParam(1.1);
1147 testInvalidAccountParam(true);
1148 testInvalidAccountParam(json::Value(json::ValueType::Null));
1149 testInvalidAccountParam(json::Value(json::ValueType::Object));
1150 testInvalidAccountParam(json::Value(json::ValueType::Array));
1151 }
1152
1153 Account const alice{"alice"};
1154 env.fund(XRP(10000), alice);
1155 for (auto i = 0uz; i < 3uz; ++i)
1156 env(token::mint(alice, 0));
1157 env.close();
1158
1159 auto const request = [&env](json::Value const& params) {
1160 return env.rpc("json", "account_nfts", to_string(params))[jss::result];
1161 };
1162
1163 {
1164 auto const jrr = request(json::Value{json::ValueType::Object});
1165 BEAST_EXPECT(jrr[jss::error] == "invalidParams");
1166 BEAST_EXPECT(jrr[jss::error_code] == RpcInvalidParams);
1167 BEAST_EXPECT(jrr[jss::error_message] == "Missing field 'account'.");
1168 }
1169
1170 {
1171 json::Value params;
1172 params[jss::account] = "llIIOO";
1173 auto const jrr = request(params);
1174 BEAST_EXPECT(jrr[jss::error] == "actMalformed");
1175 BEAST_EXPECT(jrr[jss::error_code] == RpcActMalformed);
1176 BEAST_EXPECT(jrr[jss::error_message] == "Account malformed.");
1177 BEAST_EXPECT(!jrr.isMember(jss::ledger_current_index));
1178 }
1179
1180 {
1181 json::Value params;
1182 params[jss::account] = Account{"bob"}.human();
1183 auto const jrr = request(params);
1184 BEAST_EXPECT(jrr[jss::error] == "actNotFound");
1185 BEAST_EXPECT(jrr[jss::error_code] == RpcActNotFound);
1186 BEAST_EXPECT(jrr[jss::error_message] == "Account not found.");
1187 }
1188
1189 auto const testInvalidLimit = [&](json::Value const& limit, char const* errorMessage) {
1190 json::Value params;
1191 params[jss::account] = alice.human();
1192 params[jss::limit] = limit;
1193 auto const jrr = request(params);
1194 BEAST_EXPECT(jrr[jss::error] == "invalidParams");
1195 BEAST_EXPECT(jrr[jss::error_code] == RpcInvalidParams);
1196 BEAST_EXPECT(jrr[jss::error_message] == errorMessage);
1197 };
1198
1199 testInvalidLimit("1", "Invalid field 'limit', not unsigned integer.");
1200 testInvalidLimit(-1, "Invalid field 'limit', not unsigned integer.");
1201 testInvalidLimit(true, "Invalid field 'limit', not unsigned integer.");
1202 testInvalidLimit(0, "Invalid field 'limit'.");
1203
1204 {
1205 json::Value params;
1206 params[jss::account] = alice.human();
1207 params[jss::limit] = json::Value{json::ValueType::Null};
1208 auto const jrr = request(params);
1209 BEAST_EXPECT(!jrr.isMember(jss::error));
1210 BEAST_EXPECT(jrr[jss::account_nfts].size() == 3u);
1211 }
1212
1213 {
1214 json::Value params;
1215 params[jss::account] = alice.human();
1216 params[jss::limit] = 1;
1217 auto const first = request(params);
1218 BEAST_EXPECT(first[jss::account_nfts].size() == 1u);
1219 BEAST_EXPECT(first[jss::limit] == 1);
1220 BEAST_EXPECT(first.isMember(jss::marker));
1221 BEAST_EXPECT(!first.isMember(jss::account));
1222
1223 params[jss::limit] = 3;
1224 params[jss::marker] = first[jss::marker];
1225 auto const last = request(params);
1226 BEAST_EXPECT(last[jss::account_nfts].size() == 2u);
1227 BEAST_EXPECT(!last.isMember(jss::limit));
1228 BEAST_EXPECT(!last.isMember(jss::marker));
1229 BEAST_EXPECT(last[jss::account] == alice.human());
1230 }
1231
1232 {
1233 json::Value params;
1234 params[jss::account] = "llIIOO";
1235 params[jss::ledger_hash] = 1;
1236 auto const jrr = request(params);
1237 BEAST_EXPECT(jrr[jss::error] == "invalidParams");
1238 BEAST_EXPECT(jrr[jss::error_code] == RpcInvalidParams);
1239 BEAST_EXPECT(jrr[jss::error_message] == "Invalid field 'ledger_hash', not hex string.");
1240 }
1241
1242 {
1243 json::Value params;
1244 params[jss::account] = Account{"bob"}.human();
1245 params[jss::limit] = 0;
1246 auto const jrr = request(params);
1247 BEAST_EXPECT(jrr[jss::error] == "invalidParams");
1248 BEAST_EXPECT(jrr[jss::error_code] == RpcInvalidParams);
1249 BEAST_EXPECT(jrr[jss::error_message] == "Invalid field 'limit'.");
1250 }
1251
1252 {
1253 json::Value params;
1254 params[jss::account] = alice.human();
1255 params[jss::ledger_index] = 1000;
1256 params[jss::limit] = 0;
1257 auto const jrr = request(params);
1258 BEAST_EXPECT(jrr[jss::error] == "invalidParams");
1259 BEAST_EXPECT(jrr[jss::error_code] == RpcInvalidParams);
1260 BEAST_EXPECT(jrr[jss::error_message] == "Invalid field 'limit'.");
1261 }
1262
1263 {
1264 json::Value params;
1265 params[jss::account] = Account{"bob"}.human();
1266 params[jss::marker] = "NOT_A_MARKER";
1267 auto const jrr = request(params);
1268 BEAST_EXPECT(jrr[jss::error] == "invalidParams");
1269 BEAST_EXPECT(jrr[jss::error_code] == RpcInvalidParams);
1270 BEAST_EXPECT(jrr[jss::error_message] == "Invalid field 'marker'.");
1271 }
1272
1273 {
1274 json::Value params;
1275 params[jss::account] = alice.human();
1276 params[jss::ledger_index] = 1000;
1277 params[jss::marker] = 17;
1278 auto const jrr = request(params);
1279 BEAST_EXPECT(jrr[jss::error] == "invalidParams");
1280 BEAST_EXPECT(jrr[jss::error_code] == RpcInvalidParams);
1281 BEAST_EXPECT(jrr[jss::error_message] == "Invalid field 'marker', not string.");
1282 }
1283 }
1284
1285 void
1287 {
1288 testcase("AccountObjectMarker");
1289
1290 using namespace jtx;
1291 Env env(*this);
1292
1293 Account const alice{"alice"};
1294 Account const bob{"bob"};
1295 Account const carol{"carol"};
1296 env.fund(XRP(10000), alice, bob, carol);
1297
1298 unsigned const accountObjectSize = 30;
1299 for (unsigned i = 0; i < accountObjectSize; i++)
1300 env(check::create(alice, bob, XRP(10)));
1301
1302 for (unsigned i = 0; i < 10; i++)
1303 env(token::mint(carol, 0));
1304
1305 env.close();
1306
1307 unsigned const limit = 11;
1308 json::Value marker;
1309
1310 // test account_objects with a limit and update marker
1311 {
1312 json::Value params;
1313 params[jss::account] = bob.human();
1314 params[jss::limit] = limit;
1315 params[jss::ledger_index] = "validated";
1316 auto resp = env.rpc("json", "account_objects", to_string(params));
1317 auto const& accountObjects = resp[jss::result][jss::account_objects];
1318 marker = resp[jss::result][jss::marker];
1319 BEAST_EXPECT(!resp[jss::result].isMember(jss::error));
1320 BEAST_EXPECT(accountObjects.size() == limit);
1321 }
1322
1323 // test account_objects with valid marker and update marker
1324 {
1325 json::Value params;
1326 params[jss::account] = bob.human();
1327 params[jss::limit] = limit;
1328 params[jss::marker] = marker;
1329 params[jss::ledger_index] = "validated";
1330 auto resp = env.rpc("json", "account_objects", to_string(params));
1331 auto const& accountObjects = resp[jss::result][jss::account_objects];
1332 marker = resp[jss::result][jss::marker];
1333 BEAST_EXPECT(!resp[jss::result].isMember(jss::error));
1334 BEAST_EXPECT(accountObjects.size() == limit);
1335 }
1336
1337 // this lambda function is used to check invalid marker response.
1338 auto const testInvalidMarker = [&](std::string& marker) {
1339 json::Value params;
1340 params[jss::account] = bob.human();
1341 params[jss::limit] = limit;
1342 params[jss::ledger_index] = jss::validated;
1343 params[jss::marker] = marker;
1344 json::Value const resp = env.rpc("json", "account_objects", to_string(params));
1345 return resp[jss::result][jss::error] == "invalidParams" &&
1346 resp[jss::result][jss::error_code] == RpcInvalidParams &&
1347 resp[jss::result][jss::error_message] == "Invalid field \'marker\'.";
1348 };
1349
1350 auto const markerStr = marker.asString();
1351 auto const& idx = markerStr.find(',');
1352 auto const dirIndex = markerStr.substr(0, idx);
1353 auto const entryIndex = markerStr.substr(idx + 1);
1354
1355 // test account_objects with an invalid marker that contains no ','
1356 {
1357 std::string s = dirIndex + entryIndex;
1358 BEAST_EXPECT(testInvalidMarker(s));
1359 }
1360
1361 // test invalid marker by adding invalid string after the maker:
1362 // "dirIndex,entryIndex,1234"
1363 {
1364 std::string s = markerStr + ",1234";
1365 BEAST_EXPECT(testInvalidMarker(s));
1366 }
1367
1368 // test account_objects with an invalid marker containing invalid
1369 // dirIndex by replacing some characters from the dirIndex.
1370 {
1371 std::string s = markerStr;
1372 s.replace(0, 7, "FFFFFFF");
1373 BEAST_EXPECT(testInvalidMarker(s));
1374 }
1375
1376 // test account_objects with an invalid marker containing invalid
1377 // entryIndex by replacing some characters from the entryIndex.
1378 {
1379 std::string s = entryIndex;
1380 s.replace(0, 7, "FFFFFFF");
1381 s = dirIndex + ',' + s;
1382 BEAST_EXPECT(testInvalidMarker(s));
1383 }
1384
1385 // test account_objects with an invalid marker containing invalid
1386 // dirIndex with marker: ",entryIndex"
1387 {
1388 std::string s = ',' + entryIndex;
1389 BEAST_EXPECT(testInvalidMarker(s));
1390 }
1391
1392 // test account_objects with marker: "0,entryIndex", this is still
1393 // valid, because when dirIndex = 0, we will use root key to find
1394 // dir.
1395 {
1396 std::string const s = "0," + entryIndex;
1397 json::Value params;
1398 params[jss::account] = bob.human();
1399 params[jss::limit] = limit;
1400 params[jss::marker] = s;
1401 params[jss::ledger_index] = "validated";
1402 auto resp = env.rpc("json", "account_objects", to_string(params));
1403 auto const& accountObjects = resp[jss::result][jss::account_objects];
1404 BEAST_EXPECT(!resp[jss::result].isMember(jss::error));
1405 BEAST_EXPECT(accountObjects.size() == limit);
1406 }
1407
1408 // test account_objects with an invalid marker containing invalid
1409 // entryIndex with marker: "dirIndex,"
1410 {
1411 std::string s = dirIndex + ',';
1412 BEAST_EXPECT(testInvalidMarker(s));
1413 }
1414
1415 // test account_objects with an invalid marker containing invalid
1416 // entryIndex with marker: "dirIndex,0"
1417 {
1418 std::string s = dirIndex + ",0";
1419 BEAST_EXPECT(testInvalidMarker(s));
1420 }
1421
1422 // continue getting account_objects with valid marker. This will be the
1423 // last page, so response will not contain any marker.
1424 {
1425 json::Value params;
1426 params[jss::account] = bob.human();
1427 params[jss::limit] = limit;
1428 params[jss::marker] = marker;
1429 params[jss::ledger_index] = "validated";
1430 auto resp = env.rpc("json", "account_objects", to_string(params));
1431 auto const& accountObjects = resp[jss::result][jss::account_objects];
1432 BEAST_EXPECT(!resp[jss::result].isMember(jss::error));
1433 BEAST_EXPECT(accountObjects.size() == accountObjectSize - (limit * 2));
1434 BEAST_EXPECT(!resp[jss::result].isMember(jss::marker));
1435 }
1436
1437 // test account_objects when the account only have nft pages, but
1438 // provided invalid entry index.
1439 {
1440 json::Value params;
1441 params[jss::account] = carol.human();
1442 params[jss::limit] = 10;
1443 params[jss::marker] = "0," + entryIndex;
1444 params[jss::ledger_index] = "validated";
1445 auto resp = env.rpc("json", "account_objects", to_string(params));
1446 auto const& accountObjects = resp[jss::result][jss::account_objects];
1447 BEAST_EXPECT(accountObjects.size() == 0);
1448 }
1449 }
1450
1451 void
1453 {
1454 testcase("SponsoredFilter");
1455 using namespace jtx;
1456
1457 Env env(*this, testableAmendments());
1458 Account const alice("alice");
1459 Account const bob("bob");
1460 Account const sponsor1("sponsor1");
1461 Account const gw("gw");
1462 auto const usd = gw["USD"];
1463
1464 env.fund(XRP(10000), alice, bob, sponsor1, gw);
1465 env.close();
1466
1467 // Helper to call account_objects with sponsored filter
1468 auto const acctObjsSponsored = [](Env& testEnv,
1469 AccountID const& acct,
1470 bool sponsored,
1472 std::nullopt) {
1473 json::Value params;
1474 params[jss::account] = to_string(acct);
1475 params[jss::sponsored] = sponsored;
1476 if (type)
1477 params[jss::type] = *type;
1478 params[jss::ledger_index] = "validated";
1479 return testEnv.rpc("json", "account_objects", to_string(params));
1480 };
1481
1482 // Create a trust line for bob (not sponsored)
1483 env(trust(bob, usd(1000)));
1484 env.close();
1485
1486 // sponsored=true should not find any objects for bob (doesn't have any sponsored objects)
1487 {
1488 auto const resp = acctObjsSponsored(env, bob.id(), true);
1489 auto const& objs = resp[jss::result][jss::account_objects];
1490 BEAST_EXPECT(objs.size() == 0);
1491 }
1492
1493 // Now sponsor bob's trust line
1494 auto const trustId = keylet::trustLine(bob, gw, usd.currency);
1495 if (!BEAST_EXPECT(env.le(trustId)))
1496 return;
1497
1498 env(sponsor::transfer(bob, tfSponsorshipCreate, trustId.key),
1499 sponsor::As(sponsor1, spfSponsorReserve),
1500 Sig(sfSponsorSignature, sponsor1));
1501 env.close();
1502
1503 // Verify trust line has sponsor field
1504 {
1505 auto const sle = env.le(trustId);
1506 if (!BEAST_EXPECT(sle))
1507 return;
1508 BEAST_EXPECT(sle->isFieldPresent(sfHighSponsor) || sle->isFieldPresent(sfLowSponsor));
1509 }
1510
1511 // sponsored=true on bob should include the sponsored trust line
1512 {
1513 auto const resp = acctObjsSponsored(env, bob.id(), true);
1514 auto const& objs = resp[jss::result][jss::account_objects];
1515 if (!BEAST_EXPECT(objs.size() == 1))
1516 return;
1517
1518 auto const& obj = objs[0u];
1519 BEAST_EXPECT(obj[sfLedgerEntryType.jsonName] == jss::RippleState);
1520 BEAST_EXPECT(
1521 obj.isMember(sfHighSponsor.jsonName) || obj.isMember(sfLowSponsor.jsonName));
1522 }
1523
1524 // sponsored=false on bob should NOT include the sponsored trust line
1525 {
1526 auto const resp = acctObjsSponsored(env, bob.id(), false);
1527 BEAST_EXPECT(resp[jss::result][jss::account_objects].size() == 0);
1528 }
1529
1530 // A trust line sponsored on either side is classified as sponsored
1531 // for both parties.
1532 {
1533 Env env(*this, testableAmendments());
1534 Account const issuer("issuer");
1535 Account const user("user");
1536 Account const sponsor("sponsor");
1537 auto const usd = issuer["USD"];
1538
1539 env.fund(XRP(10000), issuer, user, sponsor);
1540 env.close();
1541
1542 env(trust(issuer, user["USD"](100)));
1543 env.close();
1544
1545 env(trust(user, usd(100)));
1546 env.close();
1547
1548 auto const trustId = keylet::trustLine(user, issuer, usd.currency);
1549 if (!BEAST_EXPECT(env.le(trustId)))
1550 return;
1551
1552 env(sponsor::transfer(user, tfSponsorshipCreate, trustId.key),
1554 Sig(sfSponsorSignature, sponsor));
1555 env.close();
1556
1557 auto const line = env.le(trustId);
1558 if (!BEAST_EXPECT(line))
1559 return;
1560
1561 auto const userIsHigh = line->getFieldAmount(sfHighLimit).getIssuer() == user.id();
1562 auto const& userSponsorField = userIsHigh ? sfHighSponsor : sfLowSponsor;
1563 auto const& issuerSponsorField = userIsHigh ? sfLowSponsor : sfHighSponsor;
1564
1565 BEAST_EXPECT(line->isFieldPresent(userSponsorField));
1566 BEAST_EXPECT(!line->isFieldPresent(issuerSponsorField));
1567
1568 {
1569 auto const resp = acctObjsSponsored(env, user.id(), true, jss::state);
1570 auto const& objs = resp[jss::result][jss::account_objects];
1571 if (BEAST_EXPECT(objs.size() == 1))
1572 BEAST_EXPECT(objs[0u][sfLedgerEntryType.jsonName] == jss::RippleState);
1573 }
1574 {
1575 auto const resp = acctObjsSponsored(env, user.id(), false, jss::state);
1576 auto const& objs = resp[jss::result][jss::account_objects];
1577 BEAST_EXPECT(objs.size() == 0);
1578 }
1579 {
1580 auto const resp = acctObjsSponsored(env, issuer.id(), true, jss::state);
1581 auto const& objs = resp[jss::result][jss::account_objects];
1582 if (BEAST_EXPECT(objs.size() == 1))
1583 BEAST_EXPECT(objs[0u][sfLedgerEntryType.jsonName] == jss::RippleState);
1584 }
1585 {
1586 auto const resp = acctObjsSponsored(env, issuer.id(), false, jss::state);
1587 auto const& objs = resp[jss::result][jss::account_objects];
1588 BEAST_EXPECT(objs.size() == 0);
1589 }
1590 }
1591
1592 // A sponsored Check is classified as sponsored in both the writer's
1593 // and the destination's results.
1594 {
1595 Env env(*this, testableAmendments());
1596 Account const owner("owner");
1597 Account const dest("dest");
1598 Account const sponsor("sponsor");
1599
1600 env.fund(XRP(10000), owner, dest, sponsor);
1601 env.close();
1602
1603 auto const checkSeq = env.seq(owner);
1604 env(check::create(owner, dest, XRP(1)));
1605 env.close();
1606
1607 auto const checkId = keylet::check(owner, SeqProxy::rawSequence(checkSeq));
1608 if (!BEAST_EXPECT(env.le(checkId)))
1609 return;
1610
1611 env(sponsor::transfer(owner, tfSponsorshipCreate, checkId.key),
1613 Sig(sfSponsorSignature, sponsor));
1614 env.close();
1615
1616 {
1617 auto const sle = env.le(checkId);
1618 if (!BEAST_EXPECT(sle))
1619 return;
1620 BEAST_EXPECT(sle->isFieldPresent(sfSponsor));
1621 }
1622
1623 for (auto const& acct : {owner.id(), dest.id()})
1624 {
1625 {
1626 auto const resp = acctObjsSponsored(env, acct, true, jss::check);
1627 auto const& objs = resp[jss::result][jss::account_objects];
1628 if (BEAST_EXPECT(objs.size() == 1))
1629 BEAST_EXPECT(objs[0u][sfLedgerEntryType.jsonName] == jss::Check);
1630 }
1631 {
1632 auto const resp = acctObjsSponsored(env, acct, false, jss::check);
1633 BEAST_EXPECT(resp[jss::result][jss::account_objects].size() == 0);
1634 }
1635 }
1636 }
1637
1638 // A Sponsorship object is visible to both sides.
1639 {
1640 Env env(*this, testableAmendments());
1641 Account const owner("owner");
1642 Account const sponsee("sponsee");
1643
1644 env.fund(XRP(10000), owner, sponsee);
1645 env.close();
1646
1647 env(sponsor::set(owner, 0, 100, XRP(100)), sponsor::SponseeAcc(sponsee));
1648 env.close();
1649
1650 auto const sponsorshipKeylet = keylet::sponsorship(owner, sponsee);
1651 if (!BEAST_EXPECT(env.le(sponsorshipKeylet)))
1652 return;
1653
1654 {
1655 auto const resp = acctObjsSponsored(env, owner.id(), false, jss::sponsorship);
1656 auto const& objs = resp[jss::result][jss::account_objects];
1657 if (BEAST_EXPECT(objs.size() == 1))
1658 BEAST_EXPECT(objs[0u][sfLedgerEntryType.jsonName] == jss::Sponsorship);
1659 }
1660 {
1661 auto const resp = acctObjsSponsored(env, sponsee.id(), false, jss::sponsorship);
1662 auto const& objs = resp[jss::result][jss::account_objects];
1663 if (BEAST_EXPECT(objs.size() == 1))
1664 BEAST_EXPECT(objs[0u][sfLedgerEntryType.jsonName] == jss::Sponsorship);
1665 }
1666 {
1667 auto const resp = acctObjsSponsored(env, owner.id(), true, jss::sponsorship);
1668 auto const& objs = resp[jss::result][jss::account_objects];
1669 BEAST_EXPECT(objs.size() == 0);
1670 }
1671 {
1672 auto const resp = acctObjsSponsored(env, sponsee.id(), true, jss::sponsorship);
1673 auto const& objs = resp[jss::result][jss::account_objects];
1674 BEAST_EXPECT(objs.size() == 0);
1675 }
1676 }
1677 }
1678
1679 void
1681 {
1682 testcase("AccountObjectDoesntShowCancelledOffers");
1683
1684 using namespace jtx;
1685 Env env(*this);
1686
1687 Account const alice{"alice"};
1688 Account const bob{"bob"};
1689 auto const eur = bob["EUR"];
1690 env.fund(XRP(10000), alice, bob);
1691 env.close();
1692
1693 auto const rpcAccountObjects = [&](std::optional<uint32_t> limit = std::nullopt) {
1694 json::Value params;
1695 params[jss::account] = alice.human();
1696 if (limit.has_value())
1697 {
1698 params[jss::limit] = *limit;
1699 }
1700 return env.rpc("json", "account_objects", to_string(params));
1701 };
1702
1703 auto const numEntries = 33;
1705 seqs.reserve(numEntries);
1706 for ([[maybe_unused]] auto const _ : std::ranges::iota_view{0, numEntries})
1707 {
1708 json::Value params;
1709 params[jss::secret] = toBase58(generateSeed("alice"));
1710 params[jss::tx_json] = offer(alice, eur(1), XRP(2));
1711 auto const res = env.rpc("json", "submit", to_string(params))[jss::result];
1712 BEAST_EXPECT(res[jss::engine_result].asString() == "tesSUCCESS");
1713 seqs.push_back(env.seq(alice));
1714 }
1715
1716 auto res = rpcAccountObjects();
1717 BEAST_EXPECT(res[jss::result][jss::account_objects].size() == numEntries);
1718 BEAST_EXPECT(not res[jss::result].isMember(jss::limit));
1719 BEAST_EXPECT(not res[jss::result].isMember(jss::marker));
1720
1721 for (auto const s : std::views::all(seqs) | std::views::take(numEntries - 1))
1722 {
1723 json::Value params;
1724 params[jss::secret] = toBase58(generateSeed("alice"));
1725 params[jss::tx_json] = offerCancel(alice, s - 1);
1726 auto const res = env.rpc("json", "submit", to_string(params))[jss::result];
1727 BEAST_EXPECT(res[jss::engine_result].asString() == "tesSUCCESS");
1728 }
1729
1730 res = rpcAccountObjects();
1731 BEAST_EXPECT(res[jss::result][jss::account_objects].size() == 1);
1732 BEAST_EXPECT(not res[jss::result].isMember(jss::limit));
1733 BEAST_EXPECT(not res[jss::result].isMember(jss::marker));
1734
1735 {
1736 json::Value params;
1737 params[jss::secret] = toBase58(generateSeed("alice"));
1738 json::Value txJson;
1739 txJson[jss::TransactionType] = jss::NFTokenMint;
1740 txJson[jss::Account] = to_string(alice.id());
1741 txJson["NFTokenTaxon"] = 1;
1742 params[jss::tx_json] = txJson;
1743 auto const res = env.rpc("json", "submit", to_string(params))[jss::result];
1744 BEAST_EXPECT(res[jss::engine_result].asString() == "tesSUCCESS");
1745 }
1746 env.close();
1747
1748 res = rpcAccountObjects();
1749 BEAST_EXPECT(res[jss::result][jss::account_objects].size() == 2);
1750 BEAST_EXPECT(not res[jss::result].isMember(jss::limit));
1751 BEAST_EXPECT(not res[jss::result].isMember(jss::marker));
1752
1753 res = rpcAccountObjects(1);
1754 BEAST_EXPECT(res[jss::result][jss::account_objects].size() == 1);
1755 BEAST_EXPECT(res[jss::result][jss::limit].asUInt() == 1);
1756 BEAST_EXPECT(res[jss::result].isMember(jss::marker));
1757 }
1758
1759 // A TransactionProposal blocks AccountDelete (it is not in
1760 // nonObligationDeleter) but was omitted from kDeletionBlockers, so
1761 // deletion_blockers_only reported a clean directory. Tickets on the
1762 // same account are auto-removed at delete time and must stay omitted.
1763 void
1765 {
1766 testcase("deletion_blockers_only includes TransactionProposal");
1767
1768 using namespace jtx;
1769 using namespace std::chrono_literals;
1770
1771 Env env{*this, testableAmendments()};
1772
1773 Account const alice{"alice"};
1774 Account const bob{"bob"};
1775 env.fund(XRP(10000), alice, bob);
1776 env.close();
1777
1778 std::uint32_t const ticketSeq = proposal::createTicket(env, alice);
1779 env(proposal::create(
1780 alice,
1781 proposal::unsignedPayload(env, pay(alice, bob, XRP(1)), ticketSeq),
1782 proposal::expiration(env, 100s)),
1784 env.close();
1785
1786 json::Value params;
1787 params[jss::account] = alice.human();
1788 params[jss::deletion_blockers_only] = true;
1789 params[jss::ledger_index] = "validated";
1790
1791 {
1792 auto const resp = env.rpc("json", "account_objects", to_string(params));
1793 auto const& aobjs = resp[jss::result][jss::account_objects];
1794 if (BEAST_EXPECT(aobjs.isArray() && aobjs.size() == 1))
1795 {
1796 BEAST_EXPECT(aobjs[0u][sfLedgerEntryType.jsonName] == jss::TransactionProposal);
1797 BEAST_EXPECT(aobjs[0u][sfOwner.jsonName] == alice.human());
1798 }
1799 }
1800
1801 {
1802 params[jss::type] = jss::transaction_proposal;
1803 auto const resp = env.rpc("json", "account_objects", to_string(params));
1804 auto const& aobjs = resp[jss::result][jss::account_objects];
1805 if (BEAST_EXPECT(aobjs.isArray() && aobjs.size() == 1))
1806 BEAST_EXPECT(aobjs[0u][sfLedgerEntryType.jsonName] == jss::TransactionProposal);
1807 }
1808
1809 {
1810 params[jss::type] = jss::check;
1811 auto const resp = env.rpc("json", "account_objects", to_string(params));
1812 auto const& aobjs = resp[jss::result][jss::account_objects];
1813 BEAST_EXPECT(aobjs.isArray() && aobjs.size() == 0);
1814 }
1815 }
1816
1817 void
1831};
1832
1834
1835} // namespace xrpl::test
A testsuite class.
Definition suite.h:52
TestcaseT testcase
Memberspace for declaring test cases.
Definition suite.h:155
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:121
bool isArray() const
UInt size() const
Number of values in array or object.
UInt asUInt() const
std::string asString() const
Returns the unquoted string value.
static UInt256 createNFTokenID(std::uint16_t flags, std::uint16_t fee, AccountID const &issuer, nft::Taxon taxon, std::uint32_t tokenSeq)
Slice slice() const noexcept
Definition PublicKey.h:115
static constexpr SeqProxy rawSequence(std::uint32_t v)
Factory function to return a sequence-based SeqProxy.
Definition SeqProxy.h:62
void run() override
Runs the suite.
Convenience class to test AMM functionality.
Immutable cryptographic account descriptor.
Definition jtx/Account.h:21
std::string const & human() const
Returns the human readable public key.
PublicKey const & pk() const
Return the public key.
Definition jtx/Account.h:84
AccountID id() const
Returns the Account ID.
A transaction testing environment.
Definition Env.h:161
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
Definition Env.cpp:133
SLE::const_pointer le(Account const &account) const
Return an account root.
Definition Env.cpp:311
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Definition Env.cpp:323
std::uint32_t seq(Account const &account) const
Returns the next sequence number on account.
Definition Env.cpp:302
json::Value rpc(unsigned apiVersion, std::unordered_map< std::string, std::string > const &headers, std::string const &cmd, Args &&... args)
Execute an RPC command.
Definition Env.h:1058
void trust(STAmount const &amount, Account const &account)
Establish trust lines.
Definition Env.cpp:354
NetClock::time_point now()
Returns the current network time.
Definition Env.h:326
Set the regular signature on a JTx.
Definition sig.h:19
Set the flags on a JTx.
Definition txflags.h:14
T find(T... args)
@ Array
array value (ordered list)
Definition json_value.h:32
@ Object
object value (collection of name/value pairs).
Definition json_value.h:33
@ Null
'null' value
Definition json_value.h:26
Keylet check(AccountID const &id, SeqProxy const &seq) noexcept
A Check.
Definition Indexes.cpp:372
Keylet sponsorship(AccountID const &sponsor, AccountID const &sponsee) noexcept
A Sponsorship.
Definition Indexes.cpp:366
Keylet trustLine(AccountID const &id0, AccountID const &id1, Currency const &currency) noexcept
The index of a trust line for a given currency.
Definition Indexes.cpp:287
Taxon toTaxon(std::uint32_t i)
Definition nft.h:21
The api_version numbers this server serves.
Definition ApiVersion.h:26
Check operations.
Definition check.h:18
json::Value create(A const &account, A const &dest, STAmount const &sendMax)
Create a check.
json::Value auth(Account const &account, Account const &auth)
Preauthorize for deposit.
Definition deposit.cpp:16
DID operations.
Definition did.h:16
Escrow operations.
Definition escrow.h:25
json::Value setTx(AccountID const &account, Credentials const &credentials, std::optional< UInt256 > domain)
Create create()
Check the ledger effects a TransactionProposalCreate must have, whatever its outcome: on tesSUCCESS a...
Definition proposal.h:89
std::uint32_t createTicket(Env &env, Account const &account, std::uint32_t count)
Create tickets for a proposal to be built against, and close the ledger.
Definition proposal.cpp:128
json::Value unsignedPayload(Env const &env, json::Value tx, std::uint32_t ticketSeq)
Put a transaction of any type into the form a proposal stores it in: unsigned and ticket-based,...
Definition proposal.cpp:61
json::Value create(Account const &proposer, json::Value const &proposedTx, std::uint32_t expiration)
Build a TransactionProposalCreate carrying an unsigned proposed transaction.
Definition proposal.cpp:40
std::uint32_t expiration(Env &env, NetClock::duration delta)
An absolute expiration delta past the environment's current time.
Definition proposal.cpp:139
json::Value transfer(jtx::Account const &account, uint32_t flags, std::optional< UInt256 > const &index)
Definition sponsor.cpp:52
json::Value set(jtx::Account const &account, uint32_t flags, std::optional< int32_t > const reserveCountDelta, std::optional< STAmount > const feeAmountDelta, std::optional< STAmount > const maxFee)
Definition sponsor.cpp:22
Ticket operations.
Definition ticket.cpp:13
json::Value create(Account const &account, std::uint32_t count)
Create one of more tickets.
Definition ticket.cpp:16
json::Value mint(jtx::Account const &account, std::uint32_t nfTokenTaxon)
Mint an NFToken.
Definition token.cpp:23
UInt256 getNextID(jtx::Env const &env, jtx::Account const &issuer, std::uint32_t nfTokenTaxon, std::uint16_t flags, std::uint16_t xferFee)
Get the next NFTokenID that will be issued.
Definition token.cpp:57
json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
Definition pay.cpp:14
json::Value offerCancel(Account const &account, std::uint32_t offerSeq)
Cancel an offer.
Definition offer.cpp:31
XrpT const XRP
Converts to XRP Issue or STAmount.
Definition amount.cpp:92
FeatureBitset testableAmendments()
Definition Env.h:92
json::Value offer(Account const &account, STAmount const &takerPays, STAmount const &takerGets, std::uint32_t flags)
Create an offer.
Definition offer.cpp:14
json::Value trust(Account const &account, STAmount const &amount, std::uint32_t flags)
Modify a trust line.
Definition trust.cpp:18
PrettyAmount drops(Integer i)
Returns an XRP PrettyAmount, which is trivially convertible to STAmount.
json::Value getAccountLines(Env &env, AccountID const &acctId)
json::Value signers(Account const &account, std::uint32_t quorum, std::vector< Signer > const &v)
Definition multisign.cpp:31
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
static char const * gBobAccountObjects[]
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ RpcLgrNotFound
Definition ErrorCodes.h:55
@ RpcActNotFound
Definition ErrorCodes.h:53
@ RpcActMalformed
Definition ErrorCodes.h:73
@ RpcInvalidParams
Definition ErrorCodes.h:67
std::string strHex(FwdIt begin, FwdIt end)
Definition strHex.h:13
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition AccountID.cpp:95
Seed generateSeed(std::string const &passPhrase)
Generate a seed deterministically.
Definition Seed.cpp:58
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition base_uint.h:658
BaseUInt< 256 > UInt256
Definition base_uint.h:581
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
constexpr FlagValue spfSponsorReserve
Definition TxFlags.h:468
T has_value(T... args)
T push_back(T... args)
T replace(T... args)
T reserve(T... args)
T size(T... args)
T sort(T... args)
T time_since_epoch(T... args)