xrpld
Loading...
Searching...
No Matches
LedgerEntry_test.cpp
1#include <test/jtx/AMM.h>
2#include <test/jtx/Account.h>
3#include <test/jtx/Env.h>
4#include <test/jtx/Oracle.h>
5#include <test/jtx/TestHelpers.h>
6#include <test/jtx/amount.h>
7#include <test/jtx/credentials.h>
8#include <test/jtx/delegate.h>
9#include <test/jtx/deposit.h>
10#include <test/jtx/envconfig.h>
11#include <test/jtx/flags.h>
12#include <test/jtx/mpt.h>
13#include <test/jtx/multisign.h>
14#include <test/jtx/offer.h>
15#include <test/jtx/pay.h>
16#include <test/jtx/permissioned_domains.h>
17#include <test/jtx/proposal.h>
18#include <test/jtx/sponsor.h>
19#include <test/jtx/ticket.h>
20#include <test/jtx/token.h>
21#include <test/jtx/txflags.h>
22
23#include <xrpl/basics/Number.h>
24#include <xrpl/basics/StringUtilities.h>
25#include <xrpl/basics/base_uint.h>
26#include <xrpl/basics/chrono.h>
27#include <xrpl/basics/contract.h>
28#include <xrpl/basics/strHex.h>
29#include <xrpl/beast/unit_test/suite.h>
30#include <xrpl/beast/utility/Journal.h>
31#include <xrpl/core/ServiceRegistry.h>
32#include <xrpl/core/StartUpType.h>
33#include <xrpl/json/json_value.h>
34#include <xrpl/json/to_string.h>
35#include <xrpl/ledger/OpenView.h>
36#include <xrpl/protocol/AccountID.h>
37#include <xrpl/protocol/ApiVersion.h>
38#include <xrpl/protocol/Asset.h>
39#include <xrpl/protocol/ErrorCodes.h>
40#include <xrpl/protocol/Feature.h>
41#include <xrpl/protocol/Indexes.h>
42#include <xrpl/protocol/Keylet.h>
43#include <xrpl/protocol/Protocol.h>
44#include <xrpl/protocol/PublicKey.h>
45#include <xrpl/protocol/SField.h>
46#include <xrpl/protocol/STArray.h>
47#include <xrpl/protocol/STObject.h>
48#include <xrpl/protocol/STVector256.h>
49#include <xrpl/protocol/SeqProxy.h>
50#include <xrpl/protocol/TxFlags.h>
51#include <xrpl/protocol/jss.h>
52
53#include <algorithm>
54#include <array>
55#include <chrono>
56#include <cstddef>
57#include <cstdint>
58#include <memory>
59#include <optional>
60#include <source_location>
61#include <stdexcept>
62#include <string>
63#include <unordered_set>
64#include <utility>
65#include <vector>
66
67namespace xrpl::test {
68
84
86 {jss::account, FieldType::AccountField},
87 {jss::accounts, FieldType::TwoAccountArrayField},
88 {jss::asset, FieldType::AssetField},
89 {jss::asset2, FieldType::AssetField},
90 {jss::authorize, FieldType::AccountField},
91 {jss::authorized, FieldType::AccountField},
92 {jss::credential_type, FieldType::BlobField},
93 {jss::currency, FieldType::CurrencyField},
94 {jss::destination, FieldType::AccountField},
95 {jss::issuer, FieldType::AccountField},
96 {jss::oracle_document_id, FieldType::UInt32Field},
97 {jss::owner, FieldType::AccountField},
98 {jss::seq, FieldType::UInt32Field},
99 {jss::sponsor, FieldType::AccountField},
100 {jss::sponsee, FieldType::AccountField},
101 {jss::subject, FieldType::AccountField},
102 {jss::ticket_seq, FieldType::UInt32Field},
103};
104
107{
108 auto const it = std::ranges::find_if(
109 gMappings, [&fieldName](auto const& pair) { return pair.first == fieldName; });
110 if (it != gMappings.end())
111 {
112 return it->second;
113 }
114
115 Throw<std::runtime_error>("`gMappings` is missing field " + std::string(fieldName.cStr()));
116}
117
120{
121 switch (typeID)
122 {
124 return "AccountID";
126 return "array";
128 return "hex string";
130 return "Currency";
133 return "hex string";
135 return "hex string or object";
137 return "Asset";
139 return "length-2 array of Accounts";
142 return "number";
143 default:
145 "unknown type " + std::to_string(static_cast<uint8_t>(typeID)));
146 }
147}
148
150{
151 void
153 json::Value const& jv,
154 std::string const& err,
155 ErrorCodeI code,
156 std::string const& msg,
158 {
159 if (BEAST_EXPECT(jv.isMember(jss::status)))
160 BEAST_EXPECTS(jv[jss::status] == "error", std::to_string(location.line()));
161 if (BEAST_EXPECT(jv.isMember(jss::error)))
162 {
163 BEAST_EXPECTS(
164 jv[jss::error] == err,
165 "Expected error " + err + ", received " + jv[jss::error].asString() + ", at line " +
166 std::to_string(location.line()) + ", " + jv.toStyledString());
167 }
168 if (BEAST_EXPECT(jv.isMember(jss::error_code)))
169 {
170 BEAST_EXPECTS(
171 jv[jss::error_code] == code,
172 "Expected error code " + std::to_string(code) + ", received " +
173 jv[jss::error_code].asString() + ", at line " +
174 std::to_string(location.line()) + ", " + jv.toStyledString());
175 }
176 if (msg.empty())
177 {
178 BEAST_EXPECTS(
179 jv[jss::error_message] == json::ValueType::Null || jv[jss::error_message] == "",
180 "Expected no error message, received \"" + jv[jss::error_message].asString() +
181 "\", at line " + std::to_string(location.line()) + ", " + jv.toStyledString());
182 }
183 else if (BEAST_EXPECT(jv.isMember(jss::error_message)))
184 {
185 BEAST_EXPECTS(
186 jv[jss::error_message] == msg,
187 "Expected error message \"" + msg + "\", received \"" +
188 jv[jss::error_message].asString() + "\", at line " +
189 std::to_string(location.line()) + ", " + jv.toStyledString());
190 }
191 }
192
195 {
196 static json::Value const kInjectObject = [] {
198 obj[jss::account] = "rhigTLJJyXXSRUyRCQtqi1NoAZZzZnS4KU";
199 obj[jss::ledger_index] = "validated";
200 return obj;
201 }();
202 static json::Value const kInjectArray = [] {
204 arr[0u] = "rhigTLJJyXXSRUyRCQtqi1NoAZZzZnS4KU";
205 arr[1u] = "validated";
206 return arr;
207 }();
208 static std::array<json::Value, 21> const kAllBadValues = {
209 "", // 0
210 true, // 1
211 1, // 2
212 "1", // 3
213 -1, // 4
214 1.1, // 5
215 "-1", // 6
216 "abcdef", // 7
217 "ABCDEF", // 8
218 "12KK", // 9
219 "0123456789ABCDEFGH", // 10
220 "rJxKV9e9p6wiPw!!!!xrJ4X1n98LosPL1sgcJW", // 11
221 "rPSTrR5yEr11uMkfsz1kHCp9jK4aoa3Avv", // 12
222 "n9K2isxwTxcSHJKxMkJznDoWXAUs7NNy49H9Fknz1pC7oHAH3kH9", // 13
223 "USD", // 14
224 "USDollars", // 15
225 "5233D68B4D44388F98559DE42903767803EFA7C1F8D01413FC16EE6B01403D"
226 "6D", // 16
229 kInjectObject, // 19
230 kInjectArray, // 20
231 };
232
233 auto const remove = [&](std::vector<std::uint8_t> indices) -> std::vector<json::Value> {
234 std::unordered_set<std::uint8_t> const indexSet(indices.begin(), indices.end());
236 values.reserve(kAllBadValues.size() - indexSet.size());
237 for (std::size_t i = 0; i < kAllBadValues.size(); ++i)
238 {
239 if (!indexSet.contains(i))
240 {
241 values.push_back(kAllBadValues[i]);
242 }
243 }
244 return values;
245 };
246
247 static auto const& kBadAccountValues = remove({12});
248 static auto const& kBadArrayValues = remove({17, 20});
249 static auto const& kBadBlobValues = remove({3, 7, 8, 16});
250 static auto const& kBadCurrencyValues = remove({14});
251 static auto const& kBadHashValues = remove({2, 3, 7, 8, 16});
252 static auto const& kBadFixedHashValues = remove({1, 2, 3, 4, 7, 8, 16});
253 static auto const& kBadIndexValues = remove({12, 16, 18, 19});
254 static auto const& kBadUInt32Values = remove({2, 3});
255 static auto const& kBadUInt64Values = remove({2, 3});
256 static auto const& kBadIssueValues = remove({});
257
258 switch (fieldType)
259 {
261 return kBadAccountValues;
264 return kBadArrayValues;
266 return kBadBlobValues;
268 return kBadCurrencyValues;
270 return kBadHashValues;
272 return kBadIndexValues;
274 return kBadFixedHashValues;
276 return kBadIssueValues;
278 return kBadUInt32Values;
280 return kBadUInt64Values;
281 default:
283 "unknown type " + std::to_string(static_cast<uint8_t>(fieldType)));
284 }
285 }
286
287 static json::Value
289 {
290 static json::Value const kTwoAccountArray = [] {
292 arr[0u] = "rhigTLJJyXXSRUyRCQtqi1NoAZZzZnS4KU";
293 arr[1u] = "r4MrUGTdB57duTnRs6KbsRGQXgkseGb1b5";
294 return arr;
295 }();
296 static json::Value const kIssueObject = [] {
298 arr[jss::currency] = "XRP";
299 return arr;
300 }();
301
302 auto const typeID = getFieldType(fieldName);
303 switch (typeID)
304 {
306 return "r4MrUGTdB57duTnRs6KbsRGQXgkseGb1b5";
310 return "ABCDEF";
312 return "USD";
314 return "5233D68B4D44388F98559DE42903767803EFA7C1F8D01413FC16EE6"
315 "B01403D6D";
317 return kIssueObject;
319 return "5233D68B4D44388F98559DE42903767803EFA7C1F8D01413FC16EE6"
320 "B01403D6D";
322 return kTwoAccountArray;
325 return 1;
326 default:
328 "unknown type " + std::to_string(static_cast<uint8_t>(typeID)));
329 }
330 }
331
332 void
334 test::jtx::Env& env,
335 json::Value correctRequest,
336 json::StaticString const fieldName,
337 FieldType const typeID,
338 std::string const& expectedError,
339 bool required = true,
340 std::optional<std::string> typeNameOverride = std::nullopt,
342 {
343 forAllApiVersions([&, this](unsigned apiVersion) {
344 if (required)
345 {
346 correctRequest.removeMember(fieldName);
347 json::Value const jrr = env.rpc(
348 apiVersion, "json", "ledger_entry", to_string(correctRequest))[jss::result];
349 if (apiVersion < 2u)
350 {
351 BEAST_EXPECTS(jrr[jss::status] == "error", std::to_string(location.line()));
352 BEAST_EXPECTS(
353 jrr[jss::error] == "unknownOption", std::to_string(location.line()));
354 BEAST_EXPECTS(!jrr.isMember(jss::error_code), std::to_string(location.line()));
355 BEAST_EXPECTS(
356 jrr[jss::error_message].isNull(), std::to_string(location.line()));
357 }
358 else
359 {
361 jrr,
362 "invalidParams",
364 "No ledger_entry params provided.",
365 location);
366 }
367 }
368 auto const tryField = [&](json::Value fieldValue) -> void {
369 correctRequest[fieldName] = fieldValue;
370 json::Value const jrr = env.rpc(
371 apiVersion, "json", "ledger_entry", to_string(correctRequest))[jss::result];
372 auto const expectedErrMsg = rpc::expectedFieldMessage(
373 fieldName, typeNameOverride.value_or(getTypeName(typeID)));
374 checkErrorValue(jrr, expectedError, RpcInvalidParams, expectedErrMsg, location);
375 };
376
377 auto const& badValues = getBadValues(typeID);
378 for (auto const& value : badValues)
379 {
380 tryField(value);
381 }
382 if (required)
383 {
384 tryField(json::ValueType::Null);
385 }
386 });
387 }
388
389 void
391 test::jtx::Env& env,
392 json::Value correctRequest,
393 json::StaticString parentFieldName,
394 json::StaticString fieldName,
395 FieldType typeID,
396 std::string const& expectedError,
397 bool required = true,
399 {
400 forAllApiVersions([&, this](unsigned apiVersion) {
401 if (required)
402 {
403 correctRequest[parentFieldName].removeMember(fieldName);
404 json::Value const jrr = env.rpc(
405 apiVersion, "json", "ledger_entry", to_string(correctRequest))[jss::result];
407 jrr,
408 "malformedRequest",
410 rpc::missingFieldMessage(fieldName.cStr()),
411 location);
412
413 correctRequest[parentFieldName][fieldName] = json::ValueType::Null;
414 json::Value const jrr2 = env.rpc(
415 apiVersion, "json", "ledger_entry", to_string(correctRequest))[jss::result];
417 jrr2,
418 "malformedRequest",
420 rpc::missingFieldMessage(fieldName.cStr()),
421 location);
422 }
423 auto const tryField = [&](json::Value fieldValue) -> void {
424 correctRequest[parentFieldName][fieldName] = fieldValue;
425
426 json::Value const jrr = env.rpc(
427 apiVersion, "json", "ledger_entry", to_string(correctRequest))[jss::result];
429 jrr,
430 expectedError,
432 rpc::expectedFieldMessage(fieldName, getTypeName(typeID)),
433 location);
434 };
435
436 auto const& badValues = getBadValues(typeID);
437 for (auto const& value : badValues)
438 {
439 tryField(value);
440 }
441 });
442 }
443
444 // No subfields
445 void
447 test::jtx::Env& env,
448 json::StaticString const& parentField,
450 {
452 env,
453 json::Value{},
454 parentField,
456 "malformedRequest",
457 true,
458 std::nullopt,
459 location);
460 }
461
468
469 void
471 test::jtx::Env& env,
472 json::StaticString const& parentField,
473 std::vector<Subfield> const& subfields,
474 std::optional<std::string> parentTypeNameOverride = std::nullopt,
476 {
478 env,
479 json::Value{},
480 parentField,
482 "malformedRequest",
483 true,
484 parentTypeNameOverride,
485 location);
486
487 json::Value correctOutput;
488 correctOutput[parentField] = json::ValueType::Object;
489 for (auto const& subfield : subfields)
490 {
491 correctOutput[parentField][subfield.fieldName] = getCorrectValue(subfield.fieldName);
492 }
493
494 for (auto const& subfield : subfields)
495 {
496 auto const fieldType = getFieldType(subfield.fieldName);
498 env,
499 correctOutput,
500 parentField,
501 subfield.fieldName,
502 fieldType,
503 subfield.malformedErrorMsg,
504 subfield.required,
505 location);
506 }
507 }
508
509 void
511 {
512 testcase("Invalid requests");
513 using namespace test::jtx;
514 Env env{*this};
515 Account const alice{"alice"};
516 env.fund(XRP(10000), alice);
517 env.close();
518 {
519 // Missing ledger_entry ledger_hash
520 json::Value jvParams;
521 jvParams[jss::account_root] = alice.human();
522 jvParams[jss::ledger_hash] =
523 "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
524 "AA";
525 auto const jrr = env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
526 checkErrorValue(jrr, "lgrNotFound", RpcLgrNotFound, "ledgerNotFound");
527 }
528 {
529 // Missing ledger_entry ledger_hash
530 json::Value jvParams;
531 jvParams[jss::account_root] = alice.human();
532 auto const typeId = FieldType::HashField;
533
534 forAllApiVersions([&, this](unsigned apiVersion) {
535 auto const tryField = [&](json::Value fieldValue) -> void {
536 jvParams[jss::ledger_hash] = fieldValue;
537 json::Value const jrr = env.rpc(
538 apiVersion, "json", "ledger_entry", to_string(jvParams))[jss::result];
540 jrr,
541 "invalidParams",
543 "Invalid field 'ledger_hash', not hex string.");
544 };
545
546 auto const& badValues = getBadValues(typeId);
547 for (auto const& value : badValues)
548 {
549 tryField(value);
550 }
551 });
552 }
553
554 {
555 // ask for an zero index
556 json::Value jvParams;
557 jvParams[jss::ledger_index] = "validated";
558 jvParams[jss::index] =
559 "00000000000000000000000000000000000000000000000000000000000000"
560 "00";
561 auto const jrr = env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
562 checkErrorValue(jrr, "entryNotFound", RpcEntryNotFound, "Entry not found.");
563 }
564
565 forAllApiVersions([&, this](unsigned apiVersion) {
566 // "features" is not an option supported by ledger_entry.
567 {
569 jvParams[jss::features] =
570 "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
571 "AAAAAAAAAA";
572 jvParams[jss::api_version] = apiVersion;
573 json::Value const jrr =
574 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
575
576 if (apiVersion < 2u)
577 {
578 BEAST_EXPECT(jrr[jss::status] == "error");
579 BEAST_EXPECT(jrr[jss::error] == "unknownOption");
580 BEAST_EXPECT(!jrr.isMember(jss::error_code));
581 BEAST_EXPECT(jrr[jss::error_message].isNull());
582 }
583 else
584 {
586 jrr, "invalidParams", RpcInvalidParams, "No ledger_entry params provided.");
587 }
588 }
589 });
590 }
591
592 void
594 {
595 testcase("AccountRoot");
596 using namespace test::jtx;
597
598 auto cfg = envconfig();
599 cfg->fees.referenceFee = 10;
600 Env env{*this, std::move(cfg)};
601
602 Account const alice{"alice"};
603 env.fund(XRP(10000), alice);
604 env.close();
605
606 std::string const ledgerHash{to_string(env.closed()->header().hash)};
607 {
608 // Exercise ledger_closed along the way.
609 json::Value const jrr = env.rpc("ledger_closed")[jss::result];
610 BEAST_EXPECT(jrr[jss::ledger_hash] == ledgerHash);
611 BEAST_EXPECT(jrr[jss::ledger_index] == 3);
612 }
613
614 std::string accountRootIndex;
615 {
616 // Request alice's account root.
617 json::Value jvParams;
618 jvParams[jss::account_root] = alice.human();
619 jvParams[jss::ledger_hash] = ledgerHash;
620 json::Value const jrr =
621 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
622 BEAST_EXPECT(jrr.isMember(jss::node));
623 BEAST_EXPECT(jrr[jss::node][jss::Account] == alice.human());
624 BEAST_EXPECT(jrr[jss::node][sfBalance.jsonName] == "10000000000");
625 accountRootIndex = jrr[jss::index].asString();
626 }
627 {
628 static constexpr char kAliceAcctRootBinary[]{
629 "1100612200800000240000000425000000032D00000000559CE54C3B934E4"
630 "73A995B477E92EC229F99CED5B62BF4D2ACE4DC42719103AE2F6240000002"
631 "540BE4008114AE123A8556F3CF91154711376AFB0F894F832B3D",
632 };
633
634 // Request alice's account root, but with binary == true;
635 json::Value jvParams;
636 jvParams[jss::account_root] = alice.human();
637 jvParams[jss::binary] = 1;
638 jvParams[jss::ledger_hash] = ledgerHash;
639 json::Value const jrr =
640 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
641 BEAST_EXPECT(jrr.isMember(jss::node_binary));
642 BEAST_EXPECT(jrr[jss::node_binary] == kAliceAcctRootBinary);
643 }
644 {
645 // Request alice's account root using the index.
646 json::Value jvParams;
647 jvParams[jss::index] = accountRootIndex;
648 json::Value const jrr =
649 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
650 BEAST_EXPECT(!jrr.isMember(jss::node_binary));
651 BEAST_EXPECT(jrr.isMember(jss::node));
652 BEAST_EXPECT(jrr[jss::node][jss::Account] == alice.human());
653 BEAST_EXPECT(jrr[jss::node][sfBalance.jsonName] == "10000000000");
654 }
655 {
656 // Request alice's account root by index, but with binary == false.
657 json::Value jvParams;
658 jvParams[jss::index] = accountRootIndex;
659 jvParams[jss::binary] = 0;
660 json::Value const jrr =
661 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
662 BEAST_EXPECT(jrr.isMember(jss::node));
663 BEAST_EXPECT(jrr[jss::node][jss::Account] == alice.human());
664 BEAST_EXPECT(jrr[jss::node][sfBalance.jsonName] == "10000000000");
665 }
666 {
667 // Check alias
668 json::Value jvParams;
669 jvParams[jss::account] = alice.human();
670 jvParams[jss::ledger_hash] = ledgerHash;
671 json::Value const jrr =
672 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
673 BEAST_EXPECT(jrr.isMember(jss::node));
674 BEAST_EXPECT(jrr[jss::node][jss::Account] == alice.human());
675 BEAST_EXPECT(jrr[jss::node][sfBalance.jsonName] == "10000000000");
676 accountRootIndex = jrr[jss::index].asString();
677 }
678 {
679 // Check malformed cases
680 json::Value const jvParams;
682 env, jvParams, jss::account_root, FieldType::AccountField, "malformedAddress");
683 }
684 {
685 // Request an account that is not in the ledger.
686 json::Value jvParams;
687 jvParams[jss::account_root] = Account("bob").human();
688 jvParams[jss::ledger_hash] = ledgerHash;
689 json::Value const jrr =
690 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
691 checkErrorValue(jrr, "entryNotFound", RpcEntryNotFound, "Entry not found.");
692 }
693 }
694
695 void
697 {
698 testcase("Amendments");
699 using namespace test::jtx;
700 Env env{*this};
701
702 // positive test
703 {
705
706 // easier to hack an object into the ledger than generate it
707 // legitimately
708 {
709 auto const amendments = [&](OpenView& view, beast::Journal) -> bool {
710 auto const sle = std::make_shared<SLE>(keylet);
711
712 // Create Amendments vector (enabled amendments)
713 std::vector<UInt256> enabledAmendments;
714 enabledAmendments.push_back(
716 "42426C4D4F1009EE67080A9B7965B44656D7"
717 "714D104A72F9B4369F97ABF044EE"));
718 enabledAmendments.push_back(
720 "4C97EBA926031A7CF7D7B36FDE3ED66DDA54"
721 "21192D63DE53FFB46E43B9DC8373"));
722 enabledAmendments.push_back(
724 "03BDC0099C4E14163ADA272C1B6F6FABB448"
725 "CC3E51F522F978041E4B57D9158C"));
726 enabledAmendments.push_back(
728 "35291ADD2D79EB6991343BDA0912269C817D"
729 "0F094B02226C1C14AD2858962ED4"));
730 sle->setFieldV256(sfAmendments, STVector256(enabledAmendments));
731
732 // Create Majorities array
733 STArray majorities;
734
735 auto majority1 = STObject::makeInnerObject(sfMajority);
736 majority1.setFieldH256(
737 sfAmendment,
739 "7BB62DC13EC72B775091E9C71BF8CF97E122"
740 "647693B50C5E87A80DFD6FCFAC50"));
741 majority1.setFieldU32(sfCloseTime, 779561310);
742 majorities.pushBack(std::move(majority1));
743
744 auto majority2 = STObject::makeInnerObject(sfMajority);
745 majority2.setFieldH256(
746 sfAmendment,
748 "755C971C29971C9F20C6F080F2ED96F87884"
749 "E40AD19554A5EBECDCEC8A1F77FE"));
750 majority2.setFieldU32(sfCloseTime, 779561310);
751 majorities.pushBack(std::move(majority2));
752
753 sle->setFieldArray(sfMajorities, majorities);
754
755 view.rawInsert(sle);
756 return true;
757 };
758 env.app().getOpenLedger().modify(amendments);
759 }
760
761 json::Value jvParams;
762 jvParams[jss::amendments] = to_string(keylet.key);
763 json::Value const jrr =
764 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
765 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::Amendments);
766 }
767
768 // negative tests
770 env, json::Value{}, jss::amendments, FieldType::FixedHashField, "malformedRequest");
771 }
772
773 void
775 {
776 testcase("AMM");
777 using namespace test::jtx;
778 Account const alice{"alice"};
779
780 auto const test = [&](auto&& getAsset) {
781 Env env{*this};
782
783 // positive test
784 env.fund(XRP(10000), alice);
785 env.close();
786 PrettyAsset const usd = getAsset(env);
787 AMM const amm(env, alice, XRP(10), usd(1000));
788 env.close();
789
790 {
791 json::Value jvParams;
792 jvParams[jss::amm] = to_string(amm.ammID());
793 auto const result = env.rpc("json", "ledger_entry", to_string(jvParams));
794 BEAST_EXPECT(
795 result.isObject() && result.isMember(jss::result) &&
796 !result[jss::result].isMember(jss::error) &&
797 result[jss::result].isMember(jss::node) &&
798 result[jss::result][jss::node].isMember(sfLedgerEntryType.jsonName) &&
799 result[jss::result][jss::node][sfLedgerEntryType.jsonName] == jss::AMM);
800 }
801
802 {
803 json::Value jvParams;
805 {
807 obj[jss::currency] = "XRP";
808 ammParams[jss::asset] = obj;
809 }
810 {
812 ammParams[jss::asset2] = toJson(usd.raw());
813 }
814 jvParams[jss::amm] = ammParams;
815 auto const result = env.rpc("json", "ledger_entry", to_string(jvParams));
816 BEAST_EXPECT(
817 result.isObject() && result.isMember(jss::result) &&
818 !result[jss::result].isMember(jss::error) &&
819 result[jss::result].isMember(jss::node) &&
820 result[jss::result][jss::node].isMember(sfLedgerEntryType.jsonName) &&
821 result[jss::result][jss::node][sfLedgerEntryType.jsonName] == jss::AMM);
822 }
823
824 // negative tests
826 env,
827 jss::amm,
828 {
829 {.fieldName = jss::asset, .malformedErrorMsg = "malformedRequest"},
830 {.fieldName = jss::asset2, .malformedErrorMsg = "malformedRequest"},
831 });
832 };
833 auto const getIOU = [&](Env& env) -> PrettyAsset { return alice["USD"]; };
834 auto const getMPT = [&](Env& env) -> PrettyAsset {
835 return MPTTester({.env = env, .issuer = alice});
836 };
837 test(getIOU);
838 test(getMPT);
839 }
840
841 void
843 {
844 testcase("Check");
845 using namespace test::jtx;
846 Env env{*this};
847 Account const alice{"alice"};
848 env.fund(XRP(10000), alice);
849 env.close();
850
851 auto const checkSeq = env.seq(env.master);
852 auto const checkId = keylet::check(env.master, SeqProxy::rawSequence(checkSeq));
853
854 env(check::create(env.master, alice, XRP(100)));
855 env.close();
856
857 std::string const ledgerHash{to_string(env.closed()->header().hash)};
858 {
859 // Request a check.
860 json::Value jvParams;
861 jvParams[jss::check] = to_string(checkId.key);
862 jvParams[jss::ledger_hash] = ledgerHash;
863 json::Value const jrr =
864 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
865 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::Check);
866 BEAST_EXPECT(jrr[jss::node][sfSendMax.jsonName] == "100000000");
867 }
868 {
869 // Request a check by account and seq.
870 json::Value jvParams;
871 jvParams[jss::check] = json::ValueType::Object;
872 jvParams[jss::check][jss::account] = env.master.human();
873 jvParams[jss::check][jss::seq] = checkSeq;
874 jvParams[jss::ledger_hash] = ledgerHash;
875 json::Value const jrr =
876 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
877 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::Check);
878 BEAST_EXPECT(jrr[jss::node][sfSendMax.jsonName] == "100000000");
879 BEAST_EXPECT(jrr[jss::index] == to_string(checkId.key));
880 }
881 {
882 // Request a non-existent check by account and seq.
883 json::Value jvParams;
884 jvParams[jss::check] = json::ValueType::Object;
885 jvParams[jss::check][jss::account] = env.master.human();
886 jvParams[jss::check][jss::seq] = checkSeq + 1000;
887 jvParams[jss::ledger_hash] = ledgerHash;
888 json::Value const jrr =
889 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
890 checkErrorValue(jrr, "entryNotFound", RpcEntryNotFound, "Entry not found.");
891 }
892 {
893 // Request an index that is not a check. We'll use alice's
894 // account root index.
895 std::string accountRootIndex;
896 {
897 json::Value jvParams;
898 jvParams[jss::account_root] = alice.human();
899 json::Value const jrr =
900 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
901 accountRootIndex = jrr[jss::index].asString();
902 }
903 json::Value jvParams;
904 jvParams[jss::check] = accountRootIndex;
905 jvParams[jss::ledger_hash] = ledgerHash;
906 json::Value const jrr =
907 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
909 jrr, "unexpectedLedgerType", RpcUnexpectedLedgerType, "Unexpected ledger type.");
910 }
911 {
912 // Check malformed cases
914 env,
915 jss::check,
916 {
917 {.fieldName = jss::account, .malformedErrorMsg = "malformedAddress"},
918 {.fieldName = jss::seq, .malformedErrorMsg = "malformedRequest"},
919 });
920 }
921 }
922
923 void
925 {
926 testcase("Credentials");
927
928 using namespace test::jtx;
929
930 Env env(*this);
931 Account const issuer{"issuer"};
932 Account const alice{"alice"};
933 Account const bob{"bob"};
934 char const credType[] = "abcde";
935
936 env.fund(XRP(5000), issuer, alice, bob);
937 env.close();
938
939 // Setup credentials with DepositAuth object for Alice and Bob
940 env(credentials::create(alice, issuer, credType));
941 env.close();
942
943 {
944 // Succeed
945 auto jv = credentials::ledgerEntry(env, alice, issuer, credType);
946 BEAST_EXPECT(
947 jv.isObject() && jv.isMember(jss::result) &&
948 !jv[jss::result].isMember(jss::error) && jv[jss::result].isMember(jss::node) &&
949 jv[jss::result][jss::node].isMember(sfLedgerEntryType.jsonName) &&
950 jv[jss::result][jss::node][sfLedgerEntryType.jsonName] == jss::Credential);
951
952 std::string const credIdx = jv[jss::result][jss::index].asString();
953
954 jv = credentials::ledgerEntry(env, credIdx);
955 BEAST_EXPECT(
956 jv.isObject() && jv.isMember(jss::result) &&
957 !jv[jss::result].isMember(jss::error) && jv[jss::result].isMember(jss::node) &&
958 jv[jss::result][jss::node].isMember(sfLedgerEntryType.jsonName) &&
959 jv[jss::result][jss::node][sfLedgerEntryType.jsonName] == jss::Credential);
960 }
961
962 {
963 // Fail, credential doesn't exist
964 auto const jv = credentials::ledgerEntry(
965 env,
966 "48004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6EA288B"
967 "E4");
968 checkErrorValue(jv[jss::result], "entryNotFound", RpcEntryNotFound, "Entry not found.");
969 }
970
971 {
972 // Check all malformed cases
974 env,
975 jss::credential,
976 {
977 {.fieldName = jss::subject, .malformedErrorMsg = "malformedRequest"},
978 {.fieldName = jss::issuer, .malformedErrorMsg = "malformedRequest"},
979 {.fieldName = jss::credential_type, .malformedErrorMsg = "malformedRequest"},
980 });
981 }
982 }
983
984 void
986 {
987 testcase("Delegate");
988
989 using namespace test::jtx;
990
991 Env env{*this};
992 Account const alice{"alice"};
993 Account const bob{"bob"};
994 env.fund(XRP(10000), alice, bob);
995 env.close();
996 env(delegate::set(alice, bob, {"Payment", "CheckCreate"}));
997 env.close();
998 std::string const ledgerHash{to_string(env.closed()->header().hash)};
999 std::string delegateIndex;
1000 {
1001 // Request by account and authorize
1002 json::Value jvParams;
1003 jvParams[jss::delegate][jss::account] = alice.human();
1004 jvParams[jss::delegate][jss::authorize] = bob.human();
1005 jvParams[jss::ledger_hash] = ledgerHash;
1006 json::Value const jrr =
1007 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
1008 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::Delegate);
1009 BEAST_EXPECT(jrr[jss::node][sfAccount.jsonName] == alice.human());
1010 BEAST_EXPECT(jrr[jss::node][sfAuthorize.jsonName] == bob.human());
1011 delegateIndex = jrr[jss::node][jss::index].asString();
1012 }
1013 {
1014 // Request by index.
1015 json::Value jvParams;
1016 jvParams[jss::delegate] = delegateIndex;
1017 jvParams[jss::ledger_hash] = ledgerHash;
1018 json::Value const jrr =
1019 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
1020 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::Delegate);
1021 BEAST_EXPECT(jrr[jss::node][sfAccount.jsonName] == alice.human());
1022 BEAST_EXPECT(jrr[jss::node][sfAuthorize.jsonName] == bob.human());
1023 }
1024
1025 {
1026 // Check all malformed cases
1028 env,
1029 jss::delegate,
1030 {
1031 {.fieldName = jss::account, .malformedErrorMsg = "malformedAddress"},
1032 {.fieldName = jss::authorize, .malformedErrorMsg = "malformedAddress"},
1033 });
1034 }
1035 }
1036
1037 void
1039 {
1040 testcase("Deposit Preauth");
1041
1042 using namespace test::jtx;
1043
1044 Env env{*this};
1045 Account const alice{"alice"};
1046 Account const becky{"becky"};
1047
1048 env.fund(XRP(10000), alice, becky);
1049 env.close();
1050
1051 env(deposit::auth(alice, becky));
1052 env.close();
1053
1054 std::string const ledgerHash{to_string(env.closed()->header().hash)};
1055 std::string depositPreauthIndex;
1056 {
1057 // Request a depositPreauth by owner and authorized.
1058 json::Value jvParams;
1059 jvParams[jss::deposit_preauth][jss::owner] = alice.human();
1060 jvParams[jss::deposit_preauth][jss::authorized] = becky.human();
1061 jvParams[jss::ledger_hash] = ledgerHash;
1062 json::Value const jrr =
1063 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
1064
1065 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::DepositPreauth);
1066 BEAST_EXPECT(jrr[jss::node][sfAccount.jsonName] == alice.human());
1067 BEAST_EXPECT(jrr[jss::node][sfAuthorize.jsonName] == becky.human());
1068 depositPreauthIndex = jrr[jss::node][jss::index].asString();
1069 }
1070 {
1071 // Request a depositPreauth by index.
1072 json::Value jvParams;
1073 jvParams[jss::deposit_preauth] = depositPreauthIndex;
1074 jvParams[jss::ledger_hash] = ledgerHash;
1075 json::Value const jrr =
1076 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
1077
1078 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::DepositPreauth);
1079 BEAST_EXPECT(jrr[jss::node][sfAccount.jsonName] == alice.human());
1080 BEAST_EXPECT(jrr[jss::node][sfAuthorize.jsonName] == becky.human());
1081 }
1082 {
1083 // test all missing/malformed field cases
1085 env,
1086 jss::deposit_preauth,
1087 {
1088 {.fieldName = jss::owner, .malformedErrorMsg = "malformedOwner"},
1089 {
1090 .fieldName = jss::authorized,
1091 .malformedErrorMsg = "malformedAuthorized",
1092 .required = false,
1093 },
1094 });
1095 }
1096 }
1097
1098 void
1100 {
1101 testcase("Deposit Preauth with credentials");
1102
1103 using namespace test::jtx;
1104
1105 Env env(*this);
1106 Account const issuer{"issuer"};
1107 Account const alice{"alice"};
1108 Account const bob{"bob"};
1109 char const credType[] = "abcde";
1110
1111 env.fund(XRP(5000), issuer, alice, bob);
1112 env.close();
1113
1114 {
1115 // Setup Bob with DepositAuth
1116 env(fset(bob, asfDepositAuth));
1117 env.close();
1118 env(deposit::authCredentials(bob, {{.issuer = issuer, .credType = credType}}));
1119 env.close();
1120 }
1121
1122 {
1123 // Succeed
1124 json::Value jvParams;
1125 jvParams[jss::ledger_index] = jss::validated;
1126 jvParams[jss::deposit_preauth][jss::owner] = bob.human();
1127
1128 jvParams[jss::deposit_preauth][jss::authorized_credentials] = json::ValueType::Array;
1129 auto& arr(jvParams[jss::deposit_preauth][jss::authorized_credentials]);
1130
1131 json::Value jo;
1132 jo[jss::issuer] = issuer.human();
1133 jo[jss::credential_type] = strHex(std::string_view(credType));
1134 arr.append(std::move(jo));
1135 auto const jrr = env.rpc("json", "ledger_entry", to_string(jvParams));
1136
1137 BEAST_EXPECT(
1138 jrr.isObject() && jrr.isMember(jss::result) &&
1139 !jrr[jss::result].isMember(jss::error) && jrr[jss::result].isMember(jss::node) &&
1140 jrr[jss::result][jss::node].isMember(sfLedgerEntryType.jsonName) &&
1141 jrr[jss::result][jss::node][sfLedgerEntryType.jsonName] == jss::DepositPreauth);
1142 }
1143
1144 {
1145 // Failed, invalid account
1146 json::Value jvParams;
1147 jvParams[jss::ledger_index] = jss::validated;
1148 jvParams[jss::deposit_preauth][jss::owner] = bob.human();
1149
1150 auto const tryField = [&](json::Value fieldValue) -> void {
1152 json::Value jo;
1153 jo[jss::issuer] = fieldValue;
1154 jo[jss::credential_type] = strHex(std::string_view(credType));
1155 arr.append(jo);
1156 jvParams[jss::deposit_preauth][jss::authorized_credentials] = arr;
1157
1158 json::Value const jrr =
1159 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
1160 auto const expectedErrMsg = fieldValue.isNull()
1161 ? rpc::missingFieldMessage(jss::issuer.cStr())
1162 : rpc::expectedFieldMessage(jss::issuer, "AccountID");
1164 jrr, "malformedAuthorizedCredentials", RpcInvalidParams, expectedErrMsg);
1165 };
1166
1167 auto const& badValues = getBadValues(FieldType::AccountField);
1168 for (auto const& value : badValues)
1169 {
1170 tryField(value);
1171 }
1172 tryField(json::ValueType::Null);
1173 }
1174
1175 {
1176 // Failed, duplicates in credentials
1177 json::Value jvParams;
1178 jvParams[jss::ledger_index] = jss::validated;
1179 jvParams[jss::deposit_preauth][jss::owner] = bob.human();
1180
1181 jvParams[jss::deposit_preauth][jss::authorized_credentials] = json::ValueType::Array;
1182 auto& arr(jvParams[jss::deposit_preauth][jss::authorized_credentials]);
1183
1184 json::Value jo;
1185 jo[jss::issuer] = issuer.human();
1186 jo[jss::credential_type] = strHex(std::string_view(credType));
1187 arr.append(jo);
1188 arr.append(std::move(jo));
1189 auto const jrr = env.rpc("json", "ledger_entry", to_string(jvParams));
1191 jrr[jss::result],
1192 "malformedAuthorizedCredentials",
1194 rpc::expectedFieldMessage(jss::authorized_credentials, "array"));
1195 }
1196
1197 {
1198 // Failed, invalid credential_type
1199 json::Value jvParams;
1200 jvParams[jss::ledger_index] = jss::validated;
1201 jvParams[jss::deposit_preauth][jss::owner] = bob.human();
1202
1203 auto const tryField = [&](json::Value fieldValue) -> void {
1205 json::Value jo;
1206 jo[jss::issuer] = issuer.human();
1207 jo[jss::credential_type] = fieldValue;
1208 arr.append(jo);
1209 jvParams[jss::deposit_preauth][jss::authorized_credentials] = arr;
1210
1211 json::Value const jrr =
1212 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
1213 auto const expectedErrMsg = fieldValue.isNull()
1214 ? rpc::missingFieldMessage(jss::credential_type.cStr())
1215 : rpc::expectedFieldMessage(jss::credential_type, "hex string");
1217 jrr, "malformedAuthorizedCredentials", RpcInvalidParams, expectedErrMsg);
1218 };
1219
1220 auto const& badValues = getBadValues(FieldType::BlobField);
1221 for (auto const& value : badValues)
1222 {
1223 tryField(value);
1224 }
1225 tryField(json::ValueType::Null);
1226 }
1227
1228 {
1229 // Failed, authorized and authorized_credentials both present
1230 json::Value jvParams;
1231 jvParams[jss::ledger_index] = jss::validated;
1232 jvParams[jss::deposit_preauth][jss::owner] = bob.human();
1233 jvParams[jss::deposit_preauth][jss::authorized] = alice.human();
1234
1235 jvParams[jss::deposit_preauth][jss::authorized_credentials] = json::ValueType::Array;
1236 auto& arr(jvParams[jss::deposit_preauth][jss::authorized_credentials]);
1237
1238 json::Value jo;
1239 jo[jss::issuer] = issuer.human();
1240 jo[jss::credential_type] = strHex(std::string_view(credType));
1241 arr.append(std::move(jo));
1242
1243 auto const jrr = env.rpc("json", "ledger_entry", to_string(jvParams));
1245 jrr[jss::result],
1246 "malformedRequest",
1248 "Must have exactly one of `authorized` and "
1249 "`authorized_credentials`.");
1250 }
1251
1252 {
1253 // Failed, authorized_credentials is not an array
1254 json::Value jvParams;
1255 jvParams[jss::ledger_index] = jss::validated;
1256 jvParams[jss::deposit_preauth][jss::owner] = bob.human();
1258 env,
1259 jvParams,
1260 jss::deposit_preauth,
1261 jss::authorized_credentials,
1263 "malformedAuthorizedCredentials",
1264 false);
1265 }
1266
1267 {
1268 // Failed, authorized_credentials contains string data
1269 json::Value jvParams;
1270 jvParams[jss::ledger_index] = jss::validated;
1271 jvParams[jss::deposit_preauth][jss::owner] = bob.human();
1272 jvParams[jss::deposit_preauth][jss::authorized_credentials] = json::ValueType::Array;
1273 auto& arr(jvParams[jss::deposit_preauth][jss::authorized_credentials]);
1274 arr.append("foobar");
1275
1276 auto const jrr = env.rpc("json", "ledger_entry", to_string(jvParams));
1278 jrr[jss::result],
1279 "malformedAuthorizedCredentials",
1281 "Invalid field 'authorized_credentials', not array of objects.");
1282 }
1283
1284 {
1285 // Failed, authorized_credentials contains arrays
1286 json::Value jvParams;
1287 jvParams[jss::ledger_index] = jss::validated;
1288 jvParams[jss::deposit_preauth][jss::owner] = bob.human();
1289 jvParams[jss::deposit_preauth][jss::authorized_credentials] = json::ValueType::Array;
1290 auto& arr(jvParams[jss::deposit_preauth][jss::authorized_credentials]);
1292 payload.append(42);
1293 arr.append(std::move(payload));
1294
1295 auto const jrr = env.rpc("json", "ledger_entry", to_string(jvParams));
1297 jrr[jss::result],
1298 "malformedAuthorizedCredentials",
1300 "Invalid field 'authorized_credentials', not array of objects.");
1301 }
1302
1303 {
1304 // Failed, authorized_credentials is empty array
1305 json::Value jvParams;
1306 jvParams[jss::ledger_index] = jss::validated;
1307 jvParams[jss::deposit_preauth][jss::owner] = bob.human();
1308 jvParams[jss::deposit_preauth][jss::authorized_credentials] = json::ValueType::Array;
1309
1310 auto const jrr = env.rpc("json", "ledger_entry", to_string(jvParams));
1312 jrr[jss::result],
1313 "malformedAuthorizedCredentials",
1315 "Invalid field 'authorized_credentials', array empty.");
1316 }
1317
1318 {
1319 // Failed, authorized_credentials is too long
1320 static std::array<std::string_view, 9> const kCredTypes = {
1321 "cred1",
1322 "cred2",
1323 "cred3",
1324 "cred4",
1325 "cred5",
1326 "cred6",
1327 "cred7",
1328 "cred8",
1329 "cred9",
1330 };
1331 static_assert(sizeof(kCredTypes) / sizeof(kCredTypes[0]) > kMaxCredentialsArraySize);
1332
1333 json::Value jvParams;
1334 jvParams[jss::ledger_index] = jss::validated;
1335 jvParams[jss::deposit_preauth][jss::owner] = bob.human();
1336 jvParams[jss::deposit_preauth][jss::authorized_credentials] = json::ValueType::Array;
1337
1338 auto& arr(jvParams[jss::deposit_preauth][jss::authorized_credentials]);
1339
1340 for (auto const cred : kCredTypes)
1341 {
1342 json::Value jo;
1343 jo[jss::issuer] = issuer.human();
1344 jo[jss::credential_type] = strHex(std::string_view(cred));
1345 arr.append(std::move(jo));
1346 }
1347
1348 auto const jrr = env.rpc("json", "ledger_entry", to_string(jvParams));
1350 jrr[jss::result],
1351 "malformedAuthorizedCredentials",
1353 "Invalid field 'authorized_credentials', array too long.");
1354 }
1355 }
1356
1357 void
1359 {
1360 testcase("Directory");
1361 using namespace test::jtx;
1362 Env env{*this};
1363 Account const alice{"alice"};
1364 Account const gw{"gateway"};
1365 auto const usd = gw["USD"];
1366 env.fund(XRP(10000), alice, gw);
1367 env.close();
1368
1369 env.trust(usd(1000), alice);
1370 env.close();
1371
1372 // Run up the number of directory entries so alice has two
1373 // directory nodes.
1374 for (int d = 1'000'032; d >= 1'000'000; --d)
1375 {
1376 env(offer(alice, usd(1), drops(d)));
1377 }
1378 env.close();
1379
1380 std::string const ledgerHash{to_string(env.closed()->header().hash)};
1381 {
1382 // Exercise ledger_closed along the way.
1383 json::Value const jrr = env.rpc("ledger_closed")[jss::result];
1384 BEAST_EXPECT(jrr[jss::ledger_hash] == ledgerHash);
1385 BEAST_EXPECT(jrr[jss::ledger_index] == 5);
1386 }
1387
1388 std::string const dirRootIndex =
1389 "A33EC6BB85FB5674074C4A3A43373BB17645308F3EAE1933E3E35252162B217D";
1390 {
1391 // Locate directory by index.
1392 json::Value jvParams;
1393 jvParams[jss::directory] = dirRootIndex;
1394 jvParams[jss::ledger_hash] = ledgerHash;
1395 json::Value const jrr =
1396 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
1397 BEAST_EXPECT(jrr[jss::node][sfIndexes.jsonName].size() == 32);
1398 }
1399 {
1400 // Locate directory by directory root.
1401 json::Value jvParams;
1402 jvParams[jss::directory] = json::ValueType::Object;
1403 jvParams[jss::directory][jss::dir_root] = dirRootIndex;
1404 json::Value const jrr =
1405 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
1406 BEAST_EXPECT(jrr[jss::index] == dirRootIndex);
1407 }
1408 {
1409 // Locate directory by owner.
1410 json::Value jvParams;
1411 jvParams[jss::directory] = json::ValueType::Object;
1412 jvParams[jss::directory][jss::owner] = alice.human();
1413 jvParams[jss::ledger_hash] = ledgerHash;
1414 json::Value const jrr =
1415 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
1416 BEAST_EXPECT(jrr[jss::index] == dirRootIndex);
1417 }
1418 {
1419 // Locate directory by directory root and sub_index.
1420 json::Value jvParams;
1421 jvParams[jss::directory] = json::ValueType::Object;
1422 jvParams[jss::directory][jss::dir_root] = dirRootIndex;
1423 jvParams[jss::directory][jss::sub_index] = 1;
1424 json::Value const jrr =
1425 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
1426 BEAST_EXPECT(jrr[jss::index] != dirRootIndex);
1427 BEAST_EXPECT(jrr[jss::node][sfIndexes.jsonName].size() == 2);
1428 }
1429 {
1430 // Locate directory by owner and sub_index.
1431 json::Value jvParams;
1432 jvParams[jss::directory] = json::ValueType::Object;
1433 jvParams[jss::directory][jss::owner] = alice.human();
1434 jvParams[jss::directory][jss::sub_index] = 1;
1435 jvParams[jss::ledger_hash] = ledgerHash;
1436 json::Value const jrr =
1437 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
1438 BEAST_EXPECT(jrr[jss::index] != dirRootIndex);
1439 BEAST_EXPECT(jrr[jss::node][sfIndexes.jsonName].size() == 2);
1440 }
1441 {
1442 // Bad directory argument.
1443 json::Value jvParams;
1444 jvParams[jss::ledger_hash] = ledgerHash;
1446 env, jvParams, jss::directory, FieldType::HashOrObjectField, "malformedRequest");
1447 }
1448 {
1449 // Non-integer sub_index.
1450 json::Value jvParams;
1451 jvParams[jss::directory] = json::ValueType::Object;
1452 jvParams[jss::directory][jss::dir_root] = dirRootIndex;
1453 jvParams[jss::ledger_hash] = ledgerHash;
1455 env,
1456 jvParams,
1457 jss::directory,
1458 jss::sub_index,
1460 "malformedRequest",
1461 false);
1462 }
1463 {
1464 // Malformed owner entry.
1465 json::Value jvParams;
1466 jvParams[jss::directory] = json::ValueType::Object;
1467
1468 jvParams[jss::ledger_hash] = ledgerHash;
1470 env,
1471 jvParams,
1472 jss::directory,
1473 jss::owner,
1475 "malformedAddress",
1476 false);
1477 }
1478 {
1479 // Malformed directory object. Specifies both dir_root and owner.
1480 json::Value jvParams;
1481 jvParams[jss::directory] = json::ValueType::Object;
1482 jvParams[jss::directory][jss::owner] = alice.human();
1483 jvParams[jss::directory][jss::dir_root] = dirRootIndex;
1484 jvParams[jss::ledger_hash] = ledgerHash;
1485 json::Value const jrr =
1486 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
1488 jrr,
1489 "malformedRequest",
1491 "Must have exactly one of `owner` and `dir_root` fields.");
1492 }
1493 {
1494 // Incomplete directory object. Missing both dir_root and owner.
1495 json::Value jvParams;
1496 jvParams[jss::directory] = json::ValueType::Object;
1497 jvParams[jss::directory][jss::sub_index] = 1;
1498 jvParams[jss::ledger_hash] = ledgerHash;
1499 json::Value const jrr =
1500 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
1502 jrr,
1503 "malformedRequest",
1505 "Must have exactly one of `owner` and `dir_root` fields.");
1506 }
1507 }
1508
1509 void
1511 {
1512 testcase("Escrow");
1513 using namespace test::jtx;
1514 Env env{*this};
1515 Account const alice{"alice"};
1516 env.fund(XRP(10000), alice);
1517 env.close();
1518
1519 // Lambda to create an escrow.
1520 auto const escrowCreate = [](test::jtx::Account const& account,
1521 test::jtx::Account const& to,
1522 STAmount const& amount,
1523 NetClock::time_point const& cancelAfter) {
1524 json::Value jv;
1525 jv[jss::TransactionType] = jss::EscrowCreate;
1526 jv[jss::Account] = account.human();
1527 jv[jss::Destination] = to.human();
1528 jv[jss::Amount] = amount.getJson(JsonOptions::Values::None);
1529 jv[sfFinishAfter.jsonName] = cancelAfter.time_since_epoch().count() + 2;
1530 return jv;
1531 };
1532
1533 using namespace std::chrono_literals;
1534 env(escrowCreate(alice, alice, XRP(333), env.now() + 2s));
1535 env.close();
1536
1537 std::string const ledgerHash{to_string(env.closed()->header().hash)};
1538 std::string escrowIndex;
1539 {
1540 // Request the escrow using owner and sequence.
1541 json::Value jvParams;
1542 jvParams[jss::escrow] = json::ValueType::Object;
1543 jvParams[jss::escrow][jss::owner] = alice.human();
1544 jvParams[jss::escrow][jss::seq] = env.seq(alice) - 1;
1545 json::Value const jrr =
1546 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
1547 BEAST_EXPECT(jrr[jss::node][jss::Amount] == XRP(333).value().getText());
1548 escrowIndex = jrr[jss::index].asString();
1549 }
1550 {
1551 // Request the escrow by index.
1552 json::Value jvParams;
1553 jvParams[jss::escrow] = escrowIndex;
1554 jvParams[jss::ledger_hash] = ledgerHash;
1555 json::Value const jrr =
1556 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
1557 BEAST_EXPECT(jrr[jss::node][jss::Amount] == XRP(333).value().getText());
1558 }
1559 {
1560 // Malformed escrow fields
1562 env,
1563 jss::escrow,
1564 {
1565 {.fieldName = jss::owner, .malformedErrorMsg = "malformedOwner"},
1566 {.fieldName = jss::seq, .malformedErrorMsg = "malformedSeq"},
1567 });
1568 }
1569 }
1570
1571 void
1573 {
1574 testcase("Fee Settings");
1575 using namespace test::jtx;
1576 Env env{*this};
1577
1578 // positive test
1579 {
1581 json::Value jvParams;
1582 jvParams[jss::fee] = to_string(keylet.key);
1583 json::Value const jrr =
1584 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
1585 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::FeeSettings);
1586 }
1587
1588 // negative tests
1590 env, json::Value{}, jss::fee, FieldType::FixedHashField, "malformedRequest");
1591 }
1592
1593 void
1595 {
1596 testcase("Ledger Hashes");
1597 using namespace test::jtx;
1598 Env env{*this};
1599
1600 // positive test
1601 {
1602 Keylet const keylet = keylet::skip();
1603 json::Value jvParams;
1604 jvParams[jss::hashes] = to_string(keylet.key);
1605 json::Value const jrr =
1606 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
1607 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::LedgerHashes);
1608 }
1609
1610 // negative tests
1612 env, json::Value{}, jss::hashes, FieldType::FixedHashField, "malformedRequest");
1613 }
1614
1615 void
1617 {
1618 testcase("NFT Offer");
1619 using namespace test::jtx;
1620 Env env{*this};
1621
1622 // positive test
1623 Account const issuer{"issuer"};
1624 Account const buyer{"buyer"};
1625 env.fund(XRP(1000), issuer, buyer);
1626
1627 UInt256 const nftokenID0 = token::getNextID(env, issuer, 0, tfTransferable);
1628 env(token::mint(issuer, 0), Txflags(tfTransferable));
1629 env.close();
1630 std::uint32_t const offerSeq = env.seq(issuer);
1631 UInt256 const offerID = keylet::nftokenOffer(issuer, SeqProxy::rawSequence(offerSeq)).key;
1632 env(token::createOffer(issuer, nftokenID0, drops(1)),
1633 token::Destination(buyer),
1634 Txflags(tfSellNFToken));
1635
1636 {
1637 json::Value jvParams;
1638 jvParams[jss::nft_offer] = to_string(offerID);
1639 json::Value const jrr =
1640 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
1641 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::NFTokenOffer);
1642 BEAST_EXPECT(jrr[jss::node][sfOwner.jsonName] == issuer.human());
1643 BEAST_EXPECT(jrr[jss::node][sfNFTokenID.jsonName] == to_string(nftokenID0));
1644 BEAST_EXPECT(jrr[jss::node][sfAmount.jsonName] == "1");
1645 }
1646 {
1647 // Request by owner and seq.
1648 json::Value jvParams;
1649 jvParams[jss::nft_offer] = json::ValueType::Object;
1650 jvParams[jss::nft_offer][jss::owner] = issuer.human();
1651 jvParams[jss::nft_offer][jss::seq] = offerSeq;
1652 json::Value const jrr =
1653 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
1654 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::NFTokenOffer);
1655 BEAST_EXPECT(jrr[jss::node][sfOwner.jsonName] == issuer.human());
1656 BEAST_EXPECT(jrr[jss::node][sfNFTokenID.jsonName] == to_string(nftokenID0));
1657 BEAST_EXPECT(jrr[jss::node][sfAmount.jsonName] == "1");
1658 BEAST_EXPECT(jrr[jss::index] == to_string(offerID));
1659 }
1660 {
1661 // Request a non-existent offer by owner and seq.
1662 json::Value jvParams;
1663 jvParams[jss::nft_offer] = json::ValueType::Object;
1664 jvParams[jss::nft_offer][jss::owner] = issuer.human();
1665 jvParams[jss::nft_offer][jss::seq] = offerSeq + 1000;
1666 json::Value const jrr =
1667 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
1668 checkErrorValue(jrr, "entryNotFound", RpcEntryNotFound, "Entry not found.");
1669 }
1670
1671 // negative tests
1673 env,
1674 jss::nft_offer,
1675 {
1676 {.fieldName = jss::owner, .malformedErrorMsg = "malformedOwner"},
1677 {.fieldName = jss::seq, .malformedErrorMsg = "malformedRequest"},
1678 });
1679 }
1680
1681 void
1683 {
1684 testcase("NFT Page");
1685 using namespace test::jtx;
1686 Env env{*this};
1687
1688 // positive test
1689 Account const issuer{"issuer"};
1690 env.fund(XRP(1000), issuer);
1691
1692 env(token::mint(issuer, 0), Txflags(tfTransferable));
1693 env.close();
1694
1695 auto const nftpage = keylet::nftokenPageMax(issuer);
1696 BEAST_EXPECT(env.le(nftpage) != nullptr);
1697
1698 {
1699 json::Value jvParams;
1700 jvParams[jss::nft_page] = to_string(nftpage.key);
1701 json::Value const jrr =
1702 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
1703 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::NFTokenPage);
1704 }
1705
1706 // negative tests
1707 runLedgerEntryTest(env, jss::nft_page);
1708 }
1709
1710 void
1712 {
1713 testcase("Negative UNL");
1714 using namespace test::jtx;
1715 Env env{*this};
1716
1717 // positive test
1718 {
1720
1721 // easier to hack an object into the ledger than generate it
1722 // legitimately
1723 {
1724 auto const nUNL = [&](OpenView& view, beast::Journal) -> bool {
1725 auto const sle = std::make_shared<SLE>(keylet);
1726
1727 // Create DisabledValidators array
1728 STArray disabledValidators;
1729 auto disabledValidator = STObject::makeInnerObject(sfDisabledValidator);
1730 auto pubKeyBlob = strUnHex(
1731 "ED58F6770DB5DD77E59D28CB650EC3816E2FC95021BB56E720C9A1"
1732 "2DA79C58A3AB");
1733 disabledValidator.setFieldVL(sfPublicKey, *pubKeyBlob);
1734 disabledValidator.setFieldU32(sfFirstLedgerSequence, 91371264);
1735 disabledValidators.pushBack(std::move(disabledValidator));
1736
1737 sle->setFieldArray(sfDisabledValidators, disabledValidators);
1738 sle->setFieldH256(
1739 sfPreviousTxnID,
1741 "8D47FFE664BE6C335108DF689537625855A6"
1742 "A95160CC6D351341B9"
1743 "2624D9C5E3"));
1744 sle->setFieldU32(sfPreviousTxnLgrSeq, 91442944);
1745
1746 view.rawInsert(sle);
1747 return true;
1748 };
1749 env.app().getOpenLedger().modify(nUNL);
1750 }
1751
1752 json::Value jvParams;
1753 jvParams[jss::nunl] = to_string(keylet.key);
1754 json::Value const jrr =
1755 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
1756 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::NegativeUNL);
1757 }
1758
1759 // negative tests
1761 env, json::Value{}, jss::nunl, FieldType::FixedHashField, "malformedRequest");
1762 }
1763
1764 void
1766 {
1767 testcase("Offer");
1768 using namespace test::jtx;
1769 Env env{*this};
1770 Account const alice{"alice"};
1771 Account const gw{"gateway"};
1772 auto const usd = gw["USD"];
1773 env.fund(XRP(10000), alice, gw);
1774 env.close();
1775
1776 env(offer(alice, usd(321), XRP(322)));
1777 env.close();
1778
1779 std::string const ledgerHash{to_string(env.closed()->header().hash)};
1780 std::string offerIndex;
1781 {
1782 // Request the offer using owner and sequence.
1783 json::Value jvParams;
1784 jvParams[jss::offer] = json::ValueType::Object;
1785 jvParams[jss::offer][jss::account] = alice.human();
1786 jvParams[jss::offer][jss::seq] = env.seq(alice) - 1;
1787 jvParams[jss::ledger_hash] = ledgerHash;
1788 json::Value const jrr =
1789 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
1790 BEAST_EXPECT(jrr[jss::node][jss::TakerGets] == "322000000");
1791 offerIndex = jrr[jss::index].asString();
1792 }
1793 {
1794 // Request the offer using its index.
1795 json::Value jvParams;
1796 jvParams[jss::offer] = offerIndex;
1797 json::Value const jrr =
1798 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
1799 BEAST_EXPECT(jrr[jss::node][jss::TakerGets] == "322000000");
1800 }
1801
1802 {
1803 // Malformed offer fields
1805 env,
1806 jss::offer,
1807 {
1808 {.fieldName = jss::account, .malformedErrorMsg = "malformedAddress"},
1809 {.fieldName = jss::seq, .malformedErrorMsg = "malformedRequest"},
1810 });
1811 }
1812 }
1813
1814 void
1816 {
1817 testcase("Pay Chan");
1818 using namespace test::jtx;
1819 using namespace std::literals::chrono_literals;
1820 Env env{*this};
1821 Account const alice{"alice"};
1822
1823 env.fund(XRP(10000), alice);
1824 env.close();
1825
1826 // Lambda to create a PayChan.
1827 auto const payChanCreate = [](test::jtx::Account const& account,
1828 test::jtx::Account const& to,
1829 STAmount const& amount,
1830 NetClock::duration const& settleDelay,
1831 PublicKey const& pk) {
1832 json::Value jv;
1833 jv[jss::TransactionType] = jss::PaymentChannelCreate;
1834 jv[jss::Account] = account.human();
1835 jv[jss::Destination] = to.human();
1836 jv[jss::Amount] = amount.getJson(JsonOptions::Values::None);
1837 jv[sfSettleDelay.jsonName] = settleDelay.count();
1838 jv[sfPublicKey.jsonName] = strHex(pk.slice());
1839 return jv;
1840 };
1841
1842 auto const payChanSeq = env.seq(alice);
1843 env(payChanCreate(alice, env.master, XRP(57), 18s, alice.pk()));
1844 env.close();
1845
1846 std::string const ledgerHash{to_string(env.closed()->header().hash)};
1847
1848 UInt256 const payChanIndex{
1849 keylet::payChannel(alice, env.master, SeqProxy::rawSequence(payChanSeq)).key};
1850 {
1851 // Request the payment channel using its index.
1852 json::Value jvParams;
1853 jvParams[jss::payment_channel] = to_string(payChanIndex);
1854 jvParams[jss::ledger_hash] = ledgerHash;
1855 json::Value const jrr =
1856 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
1857 BEAST_EXPECT(jrr[jss::node][sfAmount.jsonName] == "57000000");
1858 BEAST_EXPECT(jrr[jss::node][sfBalance.jsonName] == "0");
1859 BEAST_EXPECT(jrr[jss::node][sfSettleDelay.jsonName] == 18);
1860 }
1861 {
1862 // Request the payment channel by account, destination, and seq.
1863 json::Value jvParams;
1864 jvParams[jss::payment_channel] = json::ValueType::Object;
1865 jvParams[jss::payment_channel][jss::account] = alice.human();
1866 jvParams[jss::payment_channel][jss::destination] = env.master.human();
1867 jvParams[jss::payment_channel][jss::seq] = payChanSeq;
1868 jvParams[jss::ledger_hash] = ledgerHash;
1869 json::Value const jrr =
1870 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
1871 BEAST_EXPECT(jrr[jss::node][sfAmount.jsonName] == "57000000");
1872 BEAST_EXPECT(jrr[jss::node][sfBalance.jsonName] == "0");
1873 BEAST_EXPECT(jrr[jss::node][sfSettleDelay.jsonName] == 18);
1874 BEAST_EXPECT(jrr[jss::index] == to_string(payChanIndex));
1875 }
1876 {
1877 // Request a non-existent payment channel by account, destination, and seq.
1878 json::Value jvParams;
1879 jvParams[jss::payment_channel] = json::ValueType::Object;
1880 jvParams[jss::payment_channel][jss::account] = alice.human();
1881 jvParams[jss::payment_channel][jss::destination] = env.master.human();
1882 jvParams[jss::payment_channel][jss::seq] = payChanSeq + 1000;
1883 jvParams[jss::ledger_hash] = ledgerHash;
1884 json::Value const jrr =
1885 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
1886 checkErrorValue(jrr, "entryNotFound", RpcEntryNotFound, "Entry not found.");
1887 }
1888 {
1889 // Request an index that is not a payment channel.
1890 json::Value jvParams;
1891 jvParams[jss::payment_channel] = ledgerHash;
1892 jvParams[jss::ledger_hash] = ledgerHash;
1893 json::Value const jrr =
1894 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
1895 checkErrorValue(jrr, "entryNotFound", RpcEntryNotFound, "Entry not found.");
1896 }
1897
1898 {
1899 // Malformed paychan field
1901 env,
1902 jss::payment_channel,
1903 {
1904 {.fieldName = jss::account, .malformedErrorMsg = "malformedAddress"},
1905 {.fieldName = jss::destination, .malformedErrorMsg = "malformedAddress"},
1906 {.fieldName = jss::seq, .malformedErrorMsg = "malformedRequest"},
1907 });
1908 }
1909 }
1910
1911 void
1913 {
1914 testcase("RippleState");
1915 using namespace test::jtx;
1916 Env env{*this};
1917 Account const alice{"alice"};
1918 Account const gw{"gateway"};
1919 auto const usd = gw["USD"];
1920 env.fund(XRP(10000), alice, gw);
1921 env.close();
1922
1923 env.trust(usd(999), alice);
1924 env.close();
1925
1926 env(pay(gw, alice, usd(97)));
1927 env.close();
1928
1929 // check both aliases
1930 for (auto const& fieldName : {jss::ripple_state, jss::state})
1931 {
1932 std::string const ledgerHash{to_string(env.closed()->header().hash)};
1933 {
1934 // Request the trust line using the accounts and currency.
1935 json::Value jvParams;
1936 jvParams[fieldName] = json::ValueType::Object;
1937 jvParams[fieldName][jss::accounts] = json::ValueType::Array;
1938 jvParams[fieldName][jss::accounts][0u] = alice.human();
1939 jvParams[fieldName][jss::accounts][1u] = gw.human();
1940 jvParams[fieldName][jss::currency] = "USD";
1941 jvParams[jss::ledger_hash] = ledgerHash;
1942 json::Value const jrr =
1943 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
1944 BEAST_EXPECT(jrr[jss::node][sfBalance.jsonName][jss::value] == "-97");
1945 BEAST_EXPECT(jrr[jss::node][sfHighLimit.jsonName][jss::value] == "999");
1946 }
1947 {
1948 // test basic malformed scenarios
1950 env,
1951 fieldName,
1952 {
1953 {.fieldName = jss::accounts, .malformedErrorMsg = "malformedRequest"},
1954 {.fieldName = jss::currency, .malformedErrorMsg = "malformedCurrency"},
1955 });
1956 }
1957 {
1958 // ripple_state one of the accounts is missing.
1959 json::Value jvParams;
1960 jvParams[fieldName] = json::ValueType::Object;
1961 jvParams[fieldName][jss::accounts] = json::ValueType::Array;
1962 jvParams[fieldName][jss::accounts][0u] = alice.human();
1963 jvParams[fieldName][jss::currency] = "USD";
1964 jvParams[jss::ledger_hash] = ledgerHash;
1965 json::Value const jrr =
1966 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
1968 jrr,
1969 "malformedRequest",
1971 "Invalid field 'accounts', not length-2 array of "
1972 "Accounts.");
1973 }
1974 {
1975 // ripple_state more than 2 accounts.
1976 json::Value jvParams;
1977 jvParams[fieldName] = json::ValueType::Object;
1978 jvParams[fieldName][jss::accounts] = json::ValueType::Array;
1979 jvParams[fieldName][jss::accounts][0u] = alice.human();
1980 jvParams[fieldName][jss::accounts][1u] = gw.human();
1981 jvParams[fieldName][jss::accounts][2u] = alice.human();
1982 jvParams[fieldName][jss::currency] = "USD";
1983 jvParams[jss::ledger_hash] = ledgerHash;
1984 json::Value const jrr =
1985 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
1987 jrr,
1988 "malformedRequest",
1990 "Invalid field 'accounts', not length-2 array of "
1991 "Accounts.");
1992 }
1993 {
1994 // ripple_state account[0] / account[1] is not an account.
1995 json::Value jvParams;
1996 jvParams[fieldName] = json::ValueType::Object;
1997 auto const tryField = [&](json::Value badAccount) -> void {
1998 {
1999 // account[0]
2000 jvParams[fieldName][jss::accounts] = json::ValueType::Array;
2001 jvParams[fieldName][jss::accounts][0u] = badAccount;
2002 jvParams[fieldName][jss::accounts][1u] = gw.human();
2003 jvParams[fieldName][jss::currency] = "USD";
2004
2005 json::Value const jrr =
2006 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
2008 jrr,
2009 "malformedAddress",
2011 rpc::expectedFieldMessage(jss::accounts, "array of Accounts"));
2012 }
2013
2014 {
2015 // account[1]
2016 jvParams[fieldName][jss::accounts] = json::ValueType::Array;
2017 jvParams[fieldName][jss::accounts][0u] = alice.human();
2018 jvParams[fieldName][jss::accounts][1u] = badAccount;
2019 jvParams[fieldName][jss::currency] = "USD";
2020
2021 json::Value const jrr =
2022 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
2024 jrr,
2025 "malformedAddress",
2027 rpc::expectedFieldMessage(jss::accounts, "array of Accounts"));
2028 }
2029 };
2030
2031 auto const& badValues = getBadValues(FieldType::AccountField);
2032 for (auto const& value : badValues)
2033 {
2034 tryField(value);
2035 }
2036 tryField(json::ValueType::Null);
2037 }
2038 {
2039 // ripple_state account[0] == account[1].
2040 json::Value jvParams;
2041 jvParams[fieldName] = json::ValueType::Object;
2042 jvParams[fieldName][jss::accounts] = json::ValueType::Array;
2043 jvParams[fieldName][jss::accounts][0u] = alice.human();
2044 jvParams[fieldName][jss::accounts][1u] = alice.human();
2045 jvParams[fieldName][jss::currency] = "USD";
2046 jvParams[jss::ledger_hash] = ledgerHash;
2047 json::Value const jrr =
2048 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
2050 jrr, "malformedRequest", RpcInvalidParams, "Cannot have a trustline to self.");
2051 }
2052 }
2053 }
2054
2055 void
2057 {
2058 testcase("Signer List");
2059 using namespace test::jtx;
2060 Env env{*this};
2061 Account const alice{"alice"};
2062 Account const bogie{"bogie"};
2063 Account const demon{"demon"};
2064
2065 env.fund(XRP(10000), alice);
2066 env.close();
2067
2068 // Attach phantom signers to alice.
2069 env(signers(alice, 1, {{bogie, 1}, {demon, 1}}));
2070 env.close();
2071
2072 std::string const ledgerHash{to_string(env.closed()->header().hash)};
2073 auto const signerListIndex = keylet::signerList(alice).key;
2074 {
2075 // Request by hash.
2076 json::Value jvParams;
2077 jvParams[jss::signer_list] = to_string(signerListIndex);
2078 jvParams[jss::ledger_hash] = ledgerHash;
2079 json::Value const jrr =
2080 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
2081 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::SignerList);
2082 BEAST_EXPECT(jrr[jss::node][sfSignerQuorum.jsonName] == 1);
2083 }
2084 {
2085 // Request by account.
2086 json::Value jvParams;
2087 jvParams[jss::signer_list] = json::ValueType::Object;
2088 jvParams[jss::signer_list][jss::account] = alice.human();
2089 jvParams[jss::ledger_hash] = ledgerHash;
2090 json::Value const jrr =
2091 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
2092 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::SignerList);
2093 BEAST_EXPECT(jrr[jss::node][sfSignerQuorum.jsonName] == 1);
2094 BEAST_EXPECT(jrr[jss::index] == to_string(signerListIndex));
2095 }
2096 {
2097 // Request a non-existent signer list by account.
2098 json::Value jvParams;
2099 jvParams[jss::signer_list] = json::ValueType::Object;
2100 jvParams[jss::signer_list][jss::account] = env.master.human();
2101 jvParams[jss::ledger_hash] = ledgerHash;
2102 json::Value const jrr =
2103 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
2104 checkErrorValue(jrr, "entryNotFound", RpcEntryNotFound, "Entry not found.");
2105 }
2106 {
2107 // Request an index that is not a signer list.
2108 json::Value jvParams;
2109 jvParams[jss::signer_list] = ledgerHash;
2110 jvParams[jss::ledger_hash] = ledgerHash;
2111 json::Value const jrr =
2112 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
2113 checkErrorValue(jrr, "entryNotFound", RpcEntryNotFound, "Entry not found.");
2114 }
2115
2116 {
2117 // Malformed signer_list fields
2119 env,
2120 jss::signer_list,
2121 {
2122 {.fieldName = jss::account, .malformedErrorMsg = "malformedAddress"},
2123 });
2124 }
2125 }
2126
2127 void
2129 {
2130 testcase("Sponsorship");
2131
2132 using namespace test::jtx;
2133
2134 Env env{*this};
2135 Account const alice{"alice"};
2136 Account const bob{"bob"};
2137 env.fund(XRP(10000), alice, bob);
2138 env.close();
2139 env(sponsor::set(alice, 0, 100), sponsor::SponseeAcc(bob));
2140 env.close();
2141 std::string const ledgerHash{to_string(env.closed()->header().hash)};
2142 auto const sponsorshipIndex = to_string(keylet::sponsorship(alice.id(), bob.id()).key);
2143
2144 {
2145 // Request by sponsor and sponsee.
2146 json::Value jvParams;
2147 jvParams[jss::sponsorship][jss::sponsor] = alice.human();
2148 jvParams[jss::sponsorship][jss::sponsee] = bob.human();
2149 jvParams[jss::ledger_hash] = ledgerHash;
2150 auto const jrr = env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
2151 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::Sponsorship);
2152 BEAST_EXPECT(jrr[jss::node][sfOwner.jsonName] == alice.human());
2153 BEAST_EXPECT(jrr[jss::node][sfSponsee.jsonName] == bob.human());
2154 BEAST_EXPECT(sponsorshipIndex == jrr[jss::node][jss::index].asString());
2155 }
2156 {
2157 // Request by index.
2158 json::Value jvParams;
2159 jvParams[jss::sponsorship] = sponsorshipIndex;
2160 jvParams[jss::ledger_hash] = ledgerHash;
2161 json::Value const jrr =
2162 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
2163 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::Sponsorship);
2164 BEAST_EXPECT(jrr[jss::node][sfOwner.jsonName] == alice.human());
2165 BEAST_EXPECT(jrr[jss::node][sfSponsee.jsonName] == bob.human());
2166 BEAST_EXPECT(sponsorshipIndex == jrr[jss::node][jss::index].asString());
2167 }
2168 {
2169 // Check all malformed cases.
2171 env,
2172 jss::sponsorship,
2173 {
2174 {.fieldName = jss::sponsor, .malformedErrorMsg = "malformedSponsor"},
2175 {.fieldName = jss::sponsee, .malformedErrorMsg = "malformedSponsee"},
2176 });
2177 }
2178 }
2179
2180 void
2182 {
2183 testcase("Ticket");
2184 using namespace test::jtx;
2185 Env env{*this};
2186 env.close();
2187
2188 // Create two tickets.
2189 SeqProxy tkt1 = SeqProxy::rawTicket(env.seq(env.master));
2190 env(ticket::create(env.master, 2));
2191 env.close();
2192
2193 std::string const ledgerHash{to_string(env.closed()->header().hash)};
2194 // Request four tickets: one before the first one we created, the
2195 // two created tickets, and the ticket that would come after the
2196 // last created ticket.
2197 {
2198 // Not a valid ticket requested by index.
2199 json::Value jvParams;
2200 jvParams[jss::ticket] = to_string(keylet::ticket(env.master, tkt1).key);
2201 jvParams[jss::ledger_hash] = ledgerHash;
2202 json::Value const jrr =
2203 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
2204 checkErrorValue(jrr, "entryNotFound", RpcEntryNotFound, "Entry not found.");
2205 }
2206 {
2207 // First real ticket requested by index.
2208 json::Value jvParams;
2209 tkt1.advanceBy(1);
2210 jvParams[jss::ticket] = to_string(keylet::ticket(env.master, tkt1).key);
2211 jvParams[jss::ledger_hash] = ledgerHash;
2212 json::Value const jrr =
2213 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
2214 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::Ticket);
2215 BEAST_EXPECT(jrr[jss::node][sfTicketSequence.jsonName] == tkt1.value());
2216 }
2217 {
2218 // Second real ticket requested by account and sequence.
2219 tkt1.advanceBy(1);
2220 json::Value jvParams;
2221 jvParams[jss::ticket] = json::ValueType::Object;
2222 jvParams[jss::ticket][jss::account] = env.master.human();
2223 jvParams[jss::ticket][jss::ticket_seq] = tkt1.value();
2224 jvParams[jss::ledger_hash] = ledgerHash;
2225 json::Value const jrr =
2226 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
2227 BEAST_EXPECT(
2228 jrr[jss::node][jss::index] == to_string(keylet::ticket(env.master, tkt1).key));
2229 }
2230 {
2231 // Not a valid ticket requested by account and sequence.
2232 tkt1.advanceBy(1);
2233 json::Value jvParams;
2234 jvParams[jss::ticket] = json::ValueType::Object;
2235 jvParams[jss::ticket][jss::account] = env.master.human();
2236 jvParams[jss::ticket][jss::ticket_seq] = tkt1.value();
2237 jvParams[jss::ledger_hash] = ledgerHash;
2238 json::Value const jrr =
2239 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
2240 checkErrorValue(jrr, "entryNotFound", RpcEntryNotFound, "Entry not found.");
2241 }
2242 {
2243 // Request a ticket using an account root entry.
2244 json::Value jvParams;
2245 jvParams[jss::ticket] = to_string(keylet::account(env.master).key);
2246 jvParams[jss::ledger_hash] = ledgerHash;
2247 json::Value const jrr =
2248 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
2250 jrr, "unexpectedLedgerType", RpcUnexpectedLedgerType, "Unexpected ledger type.");
2251 }
2252
2253 {
2254 // test basic malformed scenarios
2256 env,
2257 jss::ticket,
2258 {
2259 {.fieldName = jss::account, .malformedErrorMsg = "malformedAddress"},
2260 {.fieldName = jss::ticket_seq, .malformedErrorMsg = "malformedRequest"},
2261 });
2262 }
2263 }
2264
2265 void
2267 {
2268 testcase("TransactionProposal");
2269 using namespace test::jtx;
2270 using namespace std::literals::chrono_literals;
2271
2272 Env env{*this};
2273
2274 Account const target{"target"};
2275 Account const bob{"bob"};
2276 env.fund(XRP(10000), target, bob);
2277 env.close();
2278
2279 // A ticket for the proposal to be built against, and the proposal
2280 // itself (an unsigned Payment payload).
2281 std::uint32_t const ticketSeq = proposal::createTicket(env, target);
2282 env(proposal::create(
2283 target,
2284 proposal::unsignedPayload(env, pay(target, bob, XRP(1)), ticketSeq),
2285 proposal::expiration(env, 100s)),
2287 env.close();
2288
2289 std::string const ledgerHash{to_string(env.closed()->header().hash)};
2290 auto const proposalIndex = to_string(keylet::txProposal(target.id(), ticketSeq).key);
2291
2292 {
2293 // Request by target account and ticket sequence.
2294 json::Value jvParams;
2295 jvParams[jss::transaction_proposal][jss::account] = target.human();
2296 jvParams[jss::transaction_proposal][jss::ticket_seq] = ticketSeq;
2297 jvParams[jss::ledger_hash] = ledgerHash;
2298 auto const jrr = env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
2299 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::TransactionProposal);
2300 BEAST_EXPECT(proposalIndex == jrr[jss::node][jss::index].asString());
2301 }
2302 {
2303 // Request by object index (hex string form).
2304 json::Value jvParams;
2305 jvParams[jss::transaction_proposal] = proposalIndex;
2306 jvParams[jss::ledger_hash] = ledgerHash;
2307 auto const jrr = env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
2308 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::TransactionProposal);
2309 BEAST_EXPECT(proposalIndex == jrr[jss::node][jss::index].asString());
2310 }
2311 {
2312 // No proposal exists against this (account, ticket_seq) pair.
2313 json::Value jvParams;
2314 jvParams[jss::transaction_proposal][jss::account] = target.human();
2315 jvParams[jss::transaction_proposal][jss::ticket_seq] = ticketSeq + 1;
2316 jvParams[jss::ledger_hash] = ledgerHash;
2317 auto const jrr = env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
2318 checkErrorValue(jrr, "entryNotFound", RpcEntryNotFound, "Entry not found.");
2319 }
2320 {
2321 // Lookup by an index of the wrong entry type.
2322 json::Value jvParams;
2323 jvParams[jss::transaction_proposal] = to_string(keylet::account(target).key);
2324 jvParams[jss::ledger_hash] = ledgerHash;
2325 auto const jrr = env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
2327 jrr, "unexpectedLedgerType", RpcUnexpectedLedgerType, "Unexpected ledger type.");
2328 }
2329
2330 {
2331 // Malformed cases (missing / wrong-type subfields, and a
2332 // non-object non-hex-string parent value). Once the parent has
2333 // been shown not to be an object, parseTransactionProposal names
2334 // "hex string" — not "hex string or object" — as the form still
2335 // on the table.
2337 env,
2338 jss::transaction_proposal,
2339 {
2340 {.fieldName = jss::account, .malformedErrorMsg = "malformedAddress"},
2341 {.fieldName = jss::ticket_seq, .malformedErrorMsg = "malformedRequest"},
2342 },
2343 "hex string");
2344 }
2345 }
2346
2347 void
2349 {
2350 testcase("DID");
2351 using namespace test::jtx;
2352 using namespace std::literals::chrono_literals;
2353 Env env{*this};
2354 Account const alice{"alice"};
2355
2356 env.fund(XRP(10000), alice);
2357 env.close();
2358
2359 // Lambda to create a DID.
2360 auto const didCreate = [](test::jtx::Account const& account) {
2361 json::Value jv;
2362 jv[jss::TransactionType] = jss::DIDSet;
2363 jv[jss::Account] = account.human();
2364 jv[sfDIDDocument.jsonName] = strHex(std::string{"data"});
2365 jv[sfURI.jsonName] = strHex(std::string{"uri"});
2366 return jv;
2367 };
2368
2369 env(didCreate(alice));
2370 env.close();
2371
2372 std::string const ledgerHash{to_string(env.closed()->header().hash)};
2373
2374 {
2375 // Request the DID using its index.
2376 json::Value jvParams;
2377 jvParams[jss::did] = alice.human();
2378 jvParams[jss::ledger_hash] = ledgerHash;
2379 json::Value const jrr =
2380 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
2381 BEAST_EXPECT(jrr[jss::node][sfDIDDocument.jsonName] == strHex(std::string{"data"}));
2382 BEAST_EXPECT(jrr[jss::node][sfURI.jsonName] == strHex(std::string{"uri"}));
2383 }
2384 {
2385 // Request an index that is not a DID.
2386 json::Value jvParams;
2387 jvParams[jss::did] = env.master.human();
2388 jvParams[jss::ledger_hash] = ledgerHash;
2389 json::Value const jrr =
2390 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
2391 checkErrorValue(jrr, "entryNotFound", RpcEntryNotFound, "Entry not found.");
2392 }
2393 {
2394 // Malformed DID index
2395 json::Value const jvParams;
2397 env, jvParams, jss::did, FieldType::AccountField, "malformedAddress");
2398 }
2399 }
2400
2401 void
2403 {
2404 testcase("Invalid Oracle Ledger Entry");
2405 using namespace xrpl::test::jtx;
2406 using namespace xrpl::test::jtx::oracle;
2407
2408 Env env(*this);
2409 Account const owner("owner");
2410 env.fund(XRP(1'000), owner);
2411 Oracle const oracle(
2412 env, {.owner = owner, .fee = static_cast<int>(env.current()->fees().base.drops())});
2413
2414 {
2415 // test basic malformed scenarios
2417 env,
2418 jss::oracle,
2419 {
2420 {.fieldName = jss::account, .malformedErrorMsg = "malformedAccount"},
2421 {
2422 .fieldName = jss::oracle_document_id,
2423 .malformedErrorMsg = "malformedDocumentID",
2424 },
2425 });
2426 }
2427 }
2428
2429 void
2431 {
2432 testcase("Oracle Ledger Entry");
2433 using namespace xrpl::test::jtx;
2434 using namespace xrpl::test::jtx::oracle;
2435
2436 Env env(*this);
2437 auto const baseFee = static_cast<int>(env.current()->fees().base.drops());
2438 std::vector<AccountID> accounts;
2440 for (int i = 0; i < 10; ++i)
2441 {
2442 Account const owner(std::string("owner") + std::to_string(i));
2443 env.fund(XRP(1'000), owner);
2444 // different accounts can have the same asset pair
2445 Oracle const oracle(env, {.owner = owner, .documentID = i, .fee = baseFee});
2446 accounts.push_back(owner.id());
2447 oracles.push_back(oracle.documentID());
2448 // same account can have different asset pair
2449 Oracle const oracle1(env, {.owner = owner, .documentID = i + 10, .fee = baseFee});
2450 accounts.push_back(owner.id());
2451 oracles.push_back(oracle1.documentID());
2452 }
2453 for (int i = 0; i < accounts.size(); ++i)
2454 {
2455 auto const jv = [&] {
2456 // document id is uint32
2457 if (i % 2)
2458 return Oracle::ledgerEntry(env, accounts[i], oracles[i]);
2459 // document id is string
2460 return Oracle::ledgerEntry(env, accounts[i], std::to_string(oracles[i]));
2461 }();
2462 try
2463 {
2464 BEAST_EXPECT(jv[jss::node][jss::Owner] == to_string(accounts[i]));
2465 }
2466 catch (...)
2467 {
2468 fail();
2469 }
2470 }
2471 }
2472
2473 void
2475 {
2476 testcase("MPT");
2477 using namespace test::jtx;
2478 using namespace std::literals::chrono_literals;
2479 Env env{*this};
2480 Account const alice{"alice"};
2481 Account const bob("bob");
2482
2483 MPTTester mptAlice(env, alice, {.holders = {bob}});
2484 mptAlice.create({
2485 .transferFee = 10,
2486 .metadata = "123",
2487 .ownerCount = 1,
2488 .flags = tfMPTCanLock | tfMPTRequireAuth | tfMPTCanEscrow | tfMPTCanTrade |
2489 tfMPTCanTransfer | tfMPTCanClawback,
2490 });
2491 mptAlice.authorize({.account = bob, .holderCount = 1});
2492
2493 std::string const ledgerHash{to_string(env.closed()->header().hash)};
2494
2495 std::string const badMptID = "00000193B9DDCAF401B5B3B26875986043F82CD0D13B4315";
2496 {
2497 // Request the MPTIssuance using its MPTIssuanceID.
2498 json::Value jvParams;
2499 jvParams[jss::mpt_issuance] = strHex(mptAlice.issuanceID());
2500 jvParams[jss::ledger_hash] = ledgerHash;
2501 json::Value const jrr =
2502 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
2503 BEAST_EXPECT(jrr[jss::node][sfMPTokenMetadata.jsonName] == strHex(std::string{"123"}));
2504 BEAST_EXPECT(jrr[jss::node][jss::mpt_issuance_id] == strHex(mptAlice.issuanceID()));
2505 }
2506 {
2507 // Request an index that is not a MPTIssuance.
2508 json::Value jvParams;
2509 jvParams[jss::mpt_issuance] = badMptID;
2510 jvParams[jss::ledger_hash] = ledgerHash;
2511 json::Value const jrr =
2512 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
2513 checkErrorValue(jrr, "entryNotFound", RpcEntryNotFound, "Entry not found.");
2514 }
2515 {
2516 // Request the MPToken using its owner + mptIssuanceID.
2517 json::Value jvParams;
2518 jvParams[jss::mptoken] = json::ValueType::Object;
2519 jvParams[jss::mptoken][jss::account] = bob.human();
2520 jvParams[jss::mptoken][jss::mpt_issuance_id] = strHex(mptAlice.issuanceID());
2521 jvParams[jss::ledger_hash] = ledgerHash;
2522 json::Value const jrr =
2523 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
2524 BEAST_EXPECT(
2525 jrr[jss::node][sfMPTokenIssuanceID.jsonName] == strHex(mptAlice.issuanceID()));
2526 }
2527 {
2528 // Request the MPToken using a bad mptIssuanceID.
2529 json::Value jvParams;
2530 jvParams[jss::mptoken] = json::ValueType::Object;
2531 jvParams[jss::mptoken][jss::account] = bob.human();
2532 jvParams[jss::mptoken][jss::mpt_issuance_id] = badMptID;
2533 jvParams[jss::ledger_hash] = ledgerHash;
2534 json::Value const jrr =
2535 env.rpc("json", "ledger_entry", to_string(jvParams))[jss::result];
2536 checkErrorValue(jrr, "entryNotFound", RpcEntryNotFound, "Entry not found.");
2537 }
2538 {
2539 // Malformed MPTIssuance index
2540 json::Value const jvParams;
2542 env, jvParams, jss::mptoken, FieldType::HashOrObjectField, "malformedRequest");
2543 }
2544 }
2545
2546 void
2548 {
2549 testcase("PermissionedDomain");
2550
2551 using namespace test::jtx;
2552
2553 Env env(*this, testableAmendments() | featurePermissionedDomains);
2554 Account const issuer{"issuer"};
2555 Account const alice{"alice"};
2556 Account const bob{"bob"};
2557
2558 env.fund(XRP(5000), issuer, alice, bob);
2559 env.close();
2560
2561 auto const seq = env.seq(alice);
2562 env(pdomain::setTx(alice, {{.issuer = alice, .credType = "first credential"}}));
2563 env.close();
2564 auto const objects = pdomain::getObjects(alice, env);
2565 if (!BEAST_EXPECT(objects.size() == 1))
2566 return;
2567
2568 {
2569 // Succeed
2570 json::Value params;
2571 params[jss::ledger_index] = jss::validated;
2572 params[jss::permissioned_domain][jss::account] = alice.human();
2573 params[jss::permissioned_domain][jss::seq] = seq;
2574 auto jv = env.rpc("json", "ledger_entry", to_string(params));
2575 BEAST_EXPECT(
2576 jv.isObject() && jv.isMember(jss::result) &&
2577 !jv[jss::result].isMember(jss::error) && jv[jss::result].isMember(jss::node) &&
2578 jv[jss::result][jss::node].isMember(sfLedgerEntryType.jsonName) &&
2579 jv[jss::result][jss::node][sfLedgerEntryType.jsonName] == jss::PermissionedDomain);
2580
2581 std::string const pdIdx = jv[jss::result][jss::index].asString();
2582 BEAST_EXPECT(
2583 strHex(keylet::permissionedDomain(alice, SeqProxy::rawSequence(seq)).key) == pdIdx);
2584
2585 params.clear();
2586 params[jss::ledger_index] = jss::validated;
2587 params[jss::permissioned_domain] = pdIdx;
2588 jv = env.rpc("json", "ledger_entry", to_string(params));
2589 BEAST_EXPECT(
2590 jv.isObject() && jv.isMember(jss::result) &&
2591 !jv[jss::result].isMember(jss::error) && jv[jss::result].isMember(jss::node) &&
2592 jv[jss::result][jss::node].isMember(sfLedgerEntryType.jsonName) &&
2593 jv[jss::result][jss::node][sfLedgerEntryType.jsonName] == jss::PermissionedDomain);
2594 }
2595
2596 {
2597 // Fail, invalid permissioned domain index
2598 json::Value params;
2599 params[jss::ledger_index] = jss::validated;
2600 params[jss::permissioned_domain] =
2601 "12F1F1F1F180D67377B2FAB292A31C922470326268D2B9B74CD1E582645B9A"
2602 "DE";
2603 auto const jrr = env.rpc("json", "ledger_entry", to_string(params));
2605 jrr[jss::result], "entryNotFound", RpcEntryNotFound, "Entry not found.");
2606 }
2607 {
2608 // test basic malformed scenarios
2610 env,
2611 jss::permissioned_domain,
2612 {
2613 {.fieldName = jss::account, .malformedErrorMsg = "malformedAddress"},
2614 {.fieldName = jss::seq, .malformedErrorMsg = "malformedRequest"},
2615 });
2616 }
2617 }
2618
2622 void
2624 {
2625 using namespace test::jtx;
2626
2627 Account const alice{"alice"};
2628 Account const bob{"bob"};
2629
2630 Env env{*this, envconfig([](auto cfg) {
2631 cfg->startUp = StartUpType::Fresh;
2632 return cfg;
2633 })};
2634
2635 env.close();
2636
2648 auto checkResult = [&](bool good,
2649 json::Value const& jv,
2650 json::StaticString const& expectedType,
2651 std::optional<std::string> const& expectedError = {},
2652 ErrorCodeI expectedCode = RpcEntryNotFound,
2653 std::string const& expectedMessage = "Entry not found.") {
2654 if (good)
2655 {
2656 BEAST_EXPECTS(
2657 jv.isObject() && jv.isMember(jss::result) &&
2658 !jv[jss::result].isMember(jss::error) &&
2659 jv[jss::result].isMember(jss::node) &&
2660 jv[jss::result][jss::node].isMember(sfLedgerEntryType.jsonName) &&
2661 jv[jss::result][jss::node][sfLedgerEntryType.jsonName] == expectedType,
2662 to_string(jv));
2663 }
2664 else
2665 {
2666 BEAST_EXPECTS(
2667 jv.isObject() && jv.isMember(jss::result) &&
2668 !jv[jss::result].isMember(jss::node) &&
2669 jv[jss::result][jss::error] == expectedError.value_or("entryNotFound") &&
2670 jv[jss::result][jss::error_code] == expectedCode &&
2671 jv[jss::result][jss::error_message] == expectedMessage,
2672 to_string(jv));
2673 }
2674 };
2675
2687 auto const test = [&](json::StaticString const& field,
2688 json::StaticString const& expectedType,
2689 Keylet const& expectedKey,
2690 bool good) {
2691 testcase << expectedType.cStr() << (good ? "" : " not") << " found";
2692
2693 auto const hexKey = strHex(expectedKey.key);
2694
2695 {
2696 // Test bad values
2697 // "field":null
2698 json::Value params;
2699 params[jss::ledger_index] = jss::validated;
2700 params[field] = json::ValueType::Null;
2701 auto const jv = env.rpc("json", "ledger_entry", to_string(params));
2702 checkResult(
2703 false,
2704 jv,
2705 expectedType,
2706 "malformedRequest",
2708 rpc::expectedFieldMessage(field, "hex string"));
2709 BEAST_EXPECT(!jv[jss::result].isMember(jss::index));
2710 }
2711
2712 {
2713 json::Value params;
2714 // "field":"string"
2715 params[jss::ledger_index] = jss::validated;
2716 params[field] = "arbitrary string";
2717 auto const jv = env.rpc("json", "ledger_entry", to_string(params));
2718 checkResult(
2719 false,
2720 jv,
2721 expectedType,
2722 "malformedRequest",
2724 rpc::expectedFieldMessage(field, "hex string"));
2725 BEAST_EXPECT(!jv[jss::result].isMember(jss::index));
2726 }
2727
2728 {
2729 json::Value params;
2730 // "field":false
2731 params[jss::ledger_index] = jss::validated;
2732 params[field] = false;
2733 auto const jv = env.rpc("json", "ledger_entry", to_string(params));
2734 checkResult(
2735 false,
2736 jv,
2737 expectedType,
2738 "invalidParams",
2740 rpc::expectedFieldMessage(field, "true"));
2741 BEAST_EXPECT(!jv[jss::result].isMember(jss::index));
2742 }
2743
2744 {
2745 json::Value params;
2746
2747 // "field":[incorrect index hash]
2748 auto const badKey = strHex(expectedKey.key + UInt256{1});
2749 params[jss::ledger_index] = jss::validated;
2750 params[field] = badKey;
2751 auto const jv = env.rpc("json", "ledger_entry", to_string(params));
2752 checkResult(
2753 false, jv, expectedType, "entryNotFound", RpcEntryNotFound, "Entry not found.");
2754 BEAST_EXPECTS(jv[jss::result][jss::index] == badKey, to_string(jv));
2755 }
2756
2757 {
2758 json::Value params;
2759 // "index":"field" using API 2
2760 params[jss::ledger_index] = jss::validated;
2761 params[jss::index] = field;
2762 params[jss::api_version] = 2;
2763 auto const jv = env.rpc("json", "ledger_entry", to_string(params));
2764 checkResult(
2765 false,
2766 jv,
2767 expectedType,
2768 "malformedRequest",
2770 rpc::expectedFieldMessage(jss::index, "hex string"));
2771 BEAST_EXPECT(!jv[jss::result].isMember(jss::index));
2772 }
2773
2774 std::string const pdIdx = [&] {
2775 {
2776 json::Value params;
2777 // Test good values
2778 // Use the "field":true notation
2779 params[jss::ledger_index] = jss::validated;
2780 params[field] = true;
2781 auto const jv = env.rpc("json", "ledger_entry", to_string(params));
2782 // Index will always be returned for valid parameters.
2783 std::string const pdIdx = jv[jss::result][jss::index].asString();
2784 BEAST_EXPECTS(hexKey == pdIdx, to_string(jv));
2785 checkResult(good, jv, expectedType);
2786
2787 return pdIdx;
2788 }
2789 }();
2790
2791 {
2792 json::Value params;
2793 // "field":"[index hash]"
2794 params[jss::ledger_index] = jss::validated;
2795 params[field] = hexKey;
2796 auto const jv = env.rpc("json", "ledger_entry", to_string(params));
2797 checkResult(good, jv, expectedType);
2798 BEAST_EXPECT(jv[jss::result][jss::index].asString() == hexKey);
2799 }
2800
2801 {
2802 // Bad value
2803 // Use the "index":"field" notation with API 2
2804 json::Value params;
2805 params[jss::ledger_index] = jss::validated;
2806 params[jss::index] = field;
2807 params[jss::api_version] = 2;
2808 auto const jv = env.rpc("json", "ledger_entry", to_string(params));
2809 checkResult(
2810 false,
2811 jv,
2812 expectedType,
2813 "malformedRequest",
2815 rpc::expectedFieldMessage(jss::index, "hex string"));
2816 BEAST_EXPECT(!jv[jss::result].isMember(jss::index));
2817 }
2818
2819 {
2820 json::Value params;
2821 // Use the "index":"field" notation with API 3
2822 params[jss::ledger_index] = jss::validated;
2823 params[jss::index] = field;
2824 params[jss::api_version] = 3;
2825 auto const jv = env.rpc("json", "ledger_entry", to_string(params));
2826 // Index is correct either way
2827 BEAST_EXPECT(jv[jss::result][jss::index].asString() == hexKey);
2828 checkResult(good, jv, expectedType);
2829 }
2830
2831 {
2832 json::Value params;
2833 // Use the "index":"[index hash]" notation
2834 params[jss::ledger_index] = jss::validated;
2835 params[jss::index] = pdIdx;
2836 auto const jv = env.rpc("json", "ledger_entry", to_string(params));
2837 // Index is correct either way
2838 BEAST_EXPECT(jv[jss::result][jss::index].asString() == hexKey);
2839 checkResult(good, jv, expectedType);
2840 }
2841 };
2842
2843 test(jss::amendments, jss::Amendments, keylet::amendments(), true);
2844 test(jss::fee, jss::FeeSettings, keylet::feeSettings(), true);
2845 // There won't be an nunl
2846 test(jss::nunl, jss::NegativeUNL, keylet::negativeUNL(), false);
2847 // Can only get the short skip list this way
2848 test(jss::hashes, jss::LedgerHashes, keylet::skip(), true);
2849 }
2850
2851 void
2853 {
2854 using namespace test::jtx;
2855
2856 Account const alice{"alice"};
2857 Account const bob{"bob"};
2858
2859 Env env{*this, envconfig([](auto cfg) {
2860 cfg->startUp = StartUpType::Fresh;
2861 return cfg;
2862 })};
2863
2864 env.close();
2865
2877 auto checkResult = [&](bool good,
2878 json::Value const& jv,
2879 int expectedCount,
2880 std::optional<std::string> const& expectedError = {},
2881 ErrorCodeI expectedCode = RpcEntryNotFound,
2882 std::string const& expectedMessage = "Entry not found.") {
2883 if (good)
2884 {
2885 BEAST_EXPECTS(
2886 jv.isObject() && jv.isMember(jss::result) &&
2887 !jv[jss::result].isMember(jss::error) &&
2888 jv[jss::result].isMember(jss::node) &&
2889 jv[jss::result][jss::node].isMember(sfLedgerEntryType.jsonName) &&
2890 jv[jss::result][jss::node][sfLedgerEntryType.jsonName] == jss::LedgerHashes,
2891 to_string(jv));
2892 BEAST_EXPECTS(
2893 jv[jss::result].isMember(jss::node) &&
2894 jv[jss::result][jss::node].isMember("Hashes") &&
2895 jv[jss::result][jss::node]["Hashes"].size() == expectedCount,
2896 to_string(jv[jss::result][jss::node]["Hashes"].size()));
2897 }
2898 else
2899 {
2900 BEAST_EXPECTS(
2901 jv.isObject() && jv.isMember(jss::result) &&
2902 !jv[jss::result].isMember(jss::node) &&
2903 jv[jss::result][jss::error] == expectedError.value_or("entryNotFound") &&
2904 jv[jss::result][jss::error_code] == expectedCode &&
2905 jv[jss::result][jss::error_message] == expectedMessage,
2906 to_string(jv));
2907 }
2908 };
2909
2921 auto const test =
2922 [&](json::Value ledger, Keylet const& expectedKey, bool good, int expectedCount = 0) {
2923 testcase << "LedgerHashes: seq: " << env.current()->header().seq
2924 << " \"hashes\":" << to_string(ledger) << (good ? "" : " not") << " found";
2925
2926 auto const hexKey = strHex(expectedKey.key);
2927
2928 {
2929 // Test bad values
2930 // "hashes":null
2931 json::Value params;
2932 params[jss::ledger_index] = jss::validated;
2933 params[jss::hashes] = json::ValueType::Null;
2934 auto jv = env.rpc("json", "ledger_entry", to_string(params));
2935 checkResult(
2936 false,
2937 jv,
2938 0,
2939 "malformedRequest",
2941 rpc::expectedFieldMessage(jss::hashes, "hex string"));
2942 BEAST_EXPECT(!jv[jss::result].isMember(jss::index));
2943 }
2944
2945 {
2946 json::Value params;
2947 // "hashes":"non-uint string"
2948 params[jss::ledger_index] = jss::validated;
2949 params[jss::hashes] = "arbitrary string";
2950 auto const jv = env.rpc("json", "ledger_entry", to_string(params));
2951 checkResult(
2952 false,
2953 jv,
2954 0,
2955 "malformedRequest",
2957 rpc::expectedFieldMessage(jss::hashes, "hex string"));
2958 BEAST_EXPECT(!jv[jss::result].isMember(jss::index));
2959 }
2960
2961 {
2962 json::Value params;
2963 // "hashes":"uint string" is invalid, too
2964 params[jss::ledger_index] = jss::validated;
2965 params[jss::hashes] = "10";
2966 auto const jv = env.rpc("json", "ledger_entry", to_string(params));
2967 checkResult(
2968 false,
2969 jv,
2970 0,
2971 "malformedRequest",
2973 rpc::expectedFieldMessage(jss::hashes, "hex string"));
2974 BEAST_EXPECT(!jv[jss::result].isMember(jss::index));
2975 }
2976
2977 {
2978 json::Value params;
2979 // "hashes":false
2980 params[jss::ledger_index] = jss::validated;
2981 params[jss::hashes] = false;
2982 auto const jv = env.rpc("json", "ledger_entry", to_string(params));
2983 checkResult(
2984 false,
2985 jv,
2986 0,
2987 "invalidParams",
2989 rpc::expectedFieldMessage(jss::hashes, "true"));
2990 BEAST_EXPECT(!jv[jss::result].isMember(jss::index));
2991 }
2992
2993 {
2994 json::Value params;
2995 // "hashes":-1
2996 params[jss::ledger_index] = jss::validated;
2997 params[jss::hashes] = -1;
2998 auto const jv = env.rpc("json", "ledger_entry", to_string(params));
2999 checkResult(false, jv, 0, "internal", RpcInternal, "Internal error.");
3000 BEAST_EXPECT(!jv[jss::result].isMember(jss::index));
3001 }
3002
3003 // "hashes":[incorrect index hash]
3004 {
3005 json::Value params;
3006 auto const badKey = strHex(expectedKey.key + UInt256{1});
3007 params[jss::ledger_index] = jss::validated;
3008 params[jss::hashes] = badKey;
3009 auto const jv = env.rpc("json", "ledger_entry", to_string(params));
3010 checkResult(
3011 false, jv, 0, "entryNotFound", RpcEntryNotFound, "Entry not found.");
3012 BEAST_EXPECT(jv[jss::result][jss::index] == badKey);
3013 }
3014
3015 {
3016 json::Value params;
3017 // Test good values
3018 // Use the "hashes":ledger notation
3019 params[jss::ledger_index] = jss::validated;
3020 params[jss::hashes] = ledger;
3021 auto const jv = env.rpc("json", "ledger_entry", to_string(params));
3022 checkResult(good, jv, expectedCount);
3023 // Index will always be returned for valid parameters.
3024 std::string const pdIdx = jv[jss::result][jss::index].asString();
3025 BEAST_EXPECTS(hexKey == pdIdx, strHex(pdIdx));
3026 }
3027
3028 {
3029 json::Value params;
3030 // "hashes":"[index hash]"
3031 params[jss::ledger_index] = jss::validated;
3032 params[jss::hashes] = hexKey;
3033 auto const jv = env.rpc("json", "ledger_entry", to_string(params));
3034 checkResult(good, jv, expectedCount);
3035 // Index is correct either way
3036 BEAST_EXPECTS(
3037 hexKey == jv[jss::result][jss::index].asString(),
3038 strHex(jv[jss::result][jss::index].asString()));
3039 }
3040
3041 {
3042 json::Value params;
3043 // Use the "index":"[index hash]" notation
3044 params[jss::ledger_index] = jss::validated;
3045 params[jss::index] = hexKey;
3046 auto const jv = env.rpc("json", "ledger_entry", to_string(params));
3047 checkResult(good, jv, expectedCount);
3048 // Index is correct either way
3049 BEAST_EXPECTS(
3050 hexKey == jv[jss::result][jss::index].asString(),
3051 strHex(jv[jss::result][jss::index].asString()));
3052 }
3053 };
3054
3055 // short skip list
3056 test(true, keylet::skip(), true, 2);
3057 // long skip list at index 0
3058 test(1, keylet::skip(1), false);
3059 // long skip list at index 1
3060 test(1 << 17, keylet::skip(1 << 17), false);
3061
3062 // Close more ledgers, but stop short of the flag ledger
3063 for (auto i = env.current()->seq(); i <= 250; ++i)
3064 env.close();
3065
3066 // short skip list
3067 test(true, keylet::skip(), true, 249);
3068 // long skip list at index 0
3069 test(1, keylet::skip(1), false);
3070 // long skip list at index 1
3071 test(1 << 17, keylet::skip(1 << 17), false);
3072
3073 // Close a flag ledger so the first "long" skip list is created
3074 for (auto i = env.current()->seq(); i <= 260; ++i)
3075 env.close();
3076
3077 // short skip list
3078 test(true, keylet::skip(), true, 256);
3079 // long skip list at index 0
3080 test(1, keylet::skip(1), true, 1);
3081 // long skip list at index 1
3082 test(1 << 17, keylet::skip(1 << 17), false);
3083 }
3084
3085 void
3087 {
3088 testcase("command-line");
3089 using namespace test::jtx;
3090
3091 Env env{*this};
3092 Account const alice{"alice"};
3093 env.fund(XRP(10000), alice);
3094 env.close();
3095
3096 auto const checkId = keylet::check(env.master, SeqProxy::rawSequence(env.seq(env.master)));
3097
3098 env(check::create(env.master, alice, XRP(100)));
3099 env.close();
3100
3101 // Request a check.
3102 json::Value const jrr = env.rpc("ledger_entry", to_string(checkId.key))[jss::result];
3103 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::Check);
3104 BEAST_EXPECT(jrr[jss::node][sfSendMax.jsonName] == "100000000");
3105 }
3106
3107public:
3108 void
3109 run() override
3110 {
3111 testInvalid();
3114 testAMM();
3115 testCheck();
3117 testDelegate();
3120 testDirectory();
3121 testEscrow();
3127 testOffer();
3128 testPayChan();
3132 testTicket();
3134 testDID();
3137 testMPT();
3139 testFixed();
3140 testHashes();
3141 testCLI();
3142 }
3143};
3144
3146
3147} // namespace xrpl::test
A generic endpoint for log messages.
Definition Journal.h:44
A testsuite class.
Definition suite.h:52
void fail(String const &reason, char const *file, int line)
Record a failure.
Definition suite.h:554
TestcaseT testcase
Memberspace for declaring test cases.
Definition suite.h:155
Lightweight wrapper to tag static string.
Definition json_value.h:52
constexpr char const * cStr() const
Definition json_value.h:65
Represents a JSON value.
Definition json_value.h:121
Value removeMember(char const *key)
Remove and return the named member.
bool isNull() const
isNull() tests to see if this field is null.
bool isObject() const
std::string toStyledString() const
Value & append(Value const &value)
Append value to array at the end.
UInt size() const
Number of values in array or object.
std::string asString() const
Returns the unquoted string value.
bool isMember(char const *key) const
Return true if the object has a member named key.
void clear()
Remove all object members and array elements.
static BaseUInt fromVoid(void const *data)
Definition base_uint.h:340
std::chrono::time_point< NetClock > time_point
Definition chrono.h:48
std::chrono::duration< rep, period > duration
Definition chrono.h:47
bool modify(ModifyType const &f)
Modify the open ledger.
Writable ledger view that accumulates state and tx changes.
Definition OpenView.h:59
void rawInsert(SLE::Ref sle) override
Unconditionally insert a state item.
Definition OpenView.cpp:240
A public key.
Definition PublicKey.h:53
void pushBack(STObject const &object)
Definition STArray.h:212
static STObject makeInnerObject(SField const &name)
Definition STObject.cpp:79
A type that represents either a sequence value or a ticket value.
Definition SeqProxy.h:37
static constexpr SeqProxy rawSequence(std::uint32_t v)
Factory function to return a sequence-based SeqProxy.
Definition SeqProxy.h:62
SeqProxy & advanceBy(std::uint32_t amount)
Definition SeqProxy.h:102
static constexpr SeqProxy rawTicket(std::uint32_t v)
Factory function to return a ticket-based SeqProxy.
Definition SeqProxy.h:74
constexpr std::uint32_t value() const
Definition SeqProxy.h:80
virtual OpenLedger & getOpenLedger()=0
void runLedgerEntryTest(test::jtx::Env &env, json::StaticString const &parentField, std::source_location const location=std::source_location::current())
void run() override
Runs the suite.
void testMalformedField(test::jtx::Env &env, json::Value correctRequest, json::StaticString const fieldName, FieldType const typeID, std::string const &expectedError, bool required=true, std::optional< std::string > typeNameOverride=std::nullopt, std::source_location const location=std::source_location::current())
static std::vector< json::Value > getBadValues(FieldType fieldType)
void checkErrorValue(json::Value const &jv, std::string const &err, ErrorCodeI code, std::string const &msg, std::source_location const location=std::source_location::current())
void testMalformedSubfield(test::jtx::Env &env, json::Value correctRequest, json::StaticString parentFieldName, json::StaticString fieldName, FieldType typeID, std::string const &expectedError, bool required=true, std::source_location const location=std::source_location::current())
void testFixed()
Test the ledger entry types that don't take parameters.
void runLedgerEntryTest(test::jtx::Env &env, json::StaticString const &parentField, std::vector< Subfield > const &subfields, std::optional< std::string > parentTypeNameOverride=std::nullopt, std::source_location const location=std::source_location::current())
static json::Value getCorrectValue(json::StaticString fieldName)
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
Application & app()
Definition Env.h:300
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
std::shared_ptr< ReadView const > closed()
Returns the last closed ledger.
Definition Env.cpp:127
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
Account const & master
Definition Env.h:165
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
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Definition Env.h:377
NetClock::time_point now()
Returns the current network time.
Definition Env.h:326
Test helper for creating, mutating, and asserting MPT and confidential MPT ledger state.
Definition mpt.h:512
void create(MPTCreate const &arg=MPTCreate{}, std::source_location const &loc=std::source_location::current())
Definition mpt.cpp:346
Set the flags on a JTx.
Definition txflags.h:14
Oracle class facilitates unit-testing of the Price Oracle feature.
static json::Value ledgerEntry(Env &env, std::optional< std::variant< AccountID, std::string > > const &account, std::optional< AnyValue > const &documentID, std::optional< std::string > const &index=std::nullopt)
Definition Oracle.cpp:322
Sets the optional Destination field on an NFTokenOffer.
Definition token.h:166
T contains(T... args)
T current(T... args)
T empty(T... args)
T find_if(T... args)
T make_shared(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 computation functions.
Definition Indexes.h:39
Keylet const & skip() noexcept
The index of the "short" skip list.
Definition Indexes.cpp:245
Keylet nftokenOffer(AccountID const &owner, SeqProxy const &seq)
An offer from an account to buy or sell an NFT.
Definition Indexes.cpp:465
Keylet payChannel(AccountID const &src, AccountID const &dst, SeqProxy const &seq) noexcept
A PaymentChannel.
Definition Indexes.cpp:436
Keylet const & negativeUNL() noexcept
The (fixed) index of the object containing the ledger negativeUNL.
Definition Indexes.cpp:274
Keylet const & feeSettings() noexcept
The (fixed) index of the object containing the ledger fees.
Definition Indexes.cpp:267
Keylet const & amendments() noexcept
The index of the amendment table.
Definition Indexes.cpp:260
Keylet signerList(AccountID const &account) noexcept
A SignerList.
Definition Indexes.cpp:360
Keylet txProposal(AccountID const &target, std::uint32_t ticketSequence) noexcept
A TransactionProposal.
Definition Indexes.cpp:378
Keylet check(AccountID const &id, SeqProxy const &seq) noexcept
A Check.
Definition Indexes.cpp:372
Keylet ticket(AccountID const &id, SeqProxy const &ticketSeq)
A ticket belonging to an account.
Definition Indexes.cpp:344
Keylet permissionedDomain(AccountID const &account, SeqProxy const &seq) noexcept
Definition Indexes.cpp:583
Keylet nftokenPageMax(AccountID const &owner)
A keylet for the owner's last possible NFT page.
Definition Indexes.cpp:450
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:233
Keylet sponsorship(AccountID const &sponsor, AccountID const &sponsee) noexcept
A Sponsorship.
Definition Indexes.cpp:366
The api_version numbers this server serves.
Definition ApiVersion.h:26
std::string expectedFieldMessage(std::string const &name, std::string const &type)
Definition ErrorCodes.h:297
std::string missingFieldMessage(std::string const &name)
Definition ErrorCodes.h:237
json::Value create(A const &account, A const &dest, STAmount const &sendMax)
Create a check.
json::Value create(jtx::Account const &subject, jtx::Account const &issuer, std::string_view credType)
Definition creds.cpp:16
json::Value ledgerEntry(jtx::Env &env, jtx::Account const &subject, jtx::Account const &issuer, std::string_view credType)
Definition creds.cpp:56
json::Value set(jtx::Account const &account, jtx::Account const &authorize, std::vector< std::string > const &permissions)
Definition delegate.cpp:17
json::Value authCredentials(jtx::Account const &account, std::vector< AuthorizeCredentials > const &auth)
Definition deposit.cpp:38
json::Value auth(Account const &account, Account const &auth)
Preauthorize for deposit.
Definition deposit.cpp:16
std::map< UInt256, json::Value > getObjects(Account const &account, Env &env, bool withType)
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 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
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
json::Value createOffer(jtx::Account const &account, UInt256 const &nftokenID, STAmount const &amount)
Create an NFTokenOffer.
Definition token.cpp:96
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
RequireT required(Args const &... args)
Compose many condition functors into one.
Definition require.h: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
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
Definition envconfig.h:38
PrettyAmount drops(Integer i)
Returns an XRP PrettyAmount, which is trivially convertible to STAmount.
json::Value signers(Account const &account, std::uint32_t quorum, std::vector< Signer > const &v)
Definition multisign.cpp:31
json::Value fset(Account const &account, std::uint32_t on, std::uint32_t off=0)
Add and/or remove flag.
Definition flags.cpp:15
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
FieldType getFieldType(json::StaticString fieldName)
std::vector< std::pair< json::StaticString, FieldType > > gMappings
static UInt256 ledgerHash(LedgerHeader const &info)
std::string getTypeName(FieldType typeID)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
ErrorCodeI
Definition ErrorCodes.h:23
@ RpcInternal
Definition ErrorCodes.h:113
@ RpcLgrNotFound
Definition ErrorCodes.h:55
@ RpcEntryNotFound
Definition ErrorCodes.h:144
@ RpcUnexpectedLedgerType
Definition ErrorCodes.h:145
@ RpcInvalidParams
Definition ErrorCodes.h:67
void forAllApiVersions(Fn const &fn, Args &&... args)
Definition ApiVersion.h:159
std::string strHex(FwdIt begin, FwdIt end)
Definition strHex.h:13
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition base_uint.h:658
json::Value toJson(Asset const &asset)
Definition Asset.h:168
BaseUInt< 256 > UInt256
Definition base_uint.h:581
Asset getAsset(T const &amt)
constexpr std::size_t kMaxCredentialsArraySize
The maximum number of credentials can be passed in array.
Definition Protocol.h:281
std::optional< Blob > strUnHex(std::size_t strSize, Iterator begin, Iterator end)
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
Definition contract.h:52
T push_back(T... args)
T reserve(T... args)
T size(T... args)
A pair of SHAMap key and LedgerEntryType.
Definition Keylet.h:20
UInt256 key
Definition Keylet.h:21
T to_string(T... args)