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>
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>
60#include <source_location>
109 gMappings, [&fieldName](
auto const& pair) {
return pair.first == fieldName; });
135 return "hex string or object";
139 return "length-2 array of Accounts";
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)))
164 jv[jss::error] == err,
165 "Expected error " + err +
", received " + jv[jss::error].asString() +
", at line " +
168 if (BEAST_EXPECT(jv.
isMember(jss::error_code)))
171 jv[jss::error_code] == code,
173 jv[jss::error_code].asString() +
", at line " +
180 "Expected no error message, received \"" + jv[jss::error_message].asString() +
183 else if (BEAST_EXPECT(jv.
isMember(jss::error_message)))
186 jv[jss::error_message] == msg,
187 "Expected error message \"" + msg +
"\", received \"" +
188 jv[jss::error_message].asString() +
"\", at line " +
198 obj[jss::account] =
"rhigTLJJyXXSRUyRCQtqi1NoAZZzZnS4KU";
199 obj[jss::ledger_index] =
"validated";
204 arr[0u] =
"rhigTLJJyXXSRUyRCQtqi1NoAZZzZnS4KU";
205 arr[1u] =
"validated";
219 "0123456789ABCDEFGH",
220 "rJxKV9e9p6wiPw!!!!xrJ4X1n98LosPL1sgcJW",
221 "rPSTrR5yEr11uMkfsz1kHCp9jK4aoa3Avv",
222 "n9K2isxwTxcSHJKxMkJznDoWXAUs7NNy49H9Fknz1pC7oHAH3kH9",
225 "5233D68B4D44388F98559DE42903767803EFA7C1F8D01413FC16EE6B01403D"
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({});
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;
283 "unknown type " +
std::to_string(
static_cast<uint8_t
>(fieldType)));
292 arr[0u] =
"rhigTLJJyXXSRUyRCQtqi1NoAZZzZnS4KU";
293 arr[1u] =
"r4MrUGTdB57duTnRs6KbsRGQXgkseGb1b5";
298 arr[jss::currency] =
"XRP";
306 return "r4MrUGTdB57duTnRs6KbsRGQXgkseGb1b5";
314 return "5233D68B4D44388F98559DE42903767803EFA7C1F8D01413FC16EE6"
319 return "5233D68B4D44388F98559DE42903767803EFA7C1F8D01413FC16EE6"
322 return kTwoAccountArray;
348 apiVersion,
"json",
"ledger_entry",
to_string(correctRequest))[jss::result];
351 BEAST_EXPECTS(jrr[jss::status] ==
"error",
std::to_string(location.line()));
353 jrr[jss::error] ==
"unknownOption",
std::to_string(location.line()));
356 jrr[jss::error_message].isNull(),
std::to_string(location.line()));
364 "No ledger_entry params provided.",
368 auto const tryField = [&](
json::Value fieldValue) ->
void {
369 correctRequest[fieldName] = fieldValue;
371 apiVersion,
"json",
"ledger_entry",
to_string(correctRequest))[jss::result];
373 fieldName, typeNameOverride.value_or(
getTypeName(typeID)));
378 for (
auto const& value : badValues)
403 correctRequest[parentFieldName].
removeMember(fieldName);
405 apiVersion,
"json",
"ledger_entry",
to_string(correctRequest))[jss::result];
415 apiVersion,
"json",
"ledger_entry",
to_string(correctRequest))[jss::result];
423 auto const tryField = [&](
json::Value fieldValue) ->
void {
424 correctRequest[parentFieldName][fieldName] = fieldValue;
427 apiVersion,
"json",
"ledger_entry",
to_string(correctRequest))[jss::result];
437 for (
auto const& value : badValues)
484 parentTypeNameOverride,
489 for (
auto const& subfield : subfields)
491 correctOutput[parentField][subfield.fieldName] =
getCorrectValue(subfield.fieldName);
494 for (
auto const& subfield : subfields)
496 auto const fieldType =
getFieldType(subfield.fieldName);
503 subfield.malformedErrorMsg,
521 jvParams[jss::account_root] = alice.
human();
522 jvParams[jss::ledger_hash] =
523 "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
525 auto const jrr = env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
531 jvParams[jss::account_root] = alice.
human();
535 auto const tryField = [&](
json::Value fieldValue) ->
void {
536 jvParams[jss::ledger_hash] = fieldValue;
538 apiVersion,
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
543 "Invalid field 'ledger_hash', not hex string.");
547 for (
auto const& value : badValues)
557 jvParams[jss::ledger_index] =
"validated";
558 jvParams[jss::index] =
559 "00000000000000000000000000000000000000000000000000000000000000"
561 auto const jrr = env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
569 jvParams[jss::features] =
570 "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
572 jvParams[jss::api_version] = apiVersion;
574 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
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());
586 jrr,
"invalidParams",
RpcInvalidParams,
"No ledger_entry params provided.");
599 cfg->fees.referenceFee = 10;
600 Env env{*
this, std::move(cfg)};
610 BEAST_EXPECT(jrr[jss::ledger_hash] ==
ledgerHash);
611 BEAST_EXPECT(jrr[jss::ledger_index] == 3);
618 jvParams[jss::account_root] = alice.
human();
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();
628 static constexpr char kAliceAcctRootBinary[]{
629 "1100612200800000240000000425000000032D00000000559CE54C3B934E4"
630 "73A995B477E92EC229F99CED5B62BF4D2ACE4DC42719103AE2F6240000002"
631 "540BE4008114AE123A8556F3CF91154711376AFB0F894F832B3D",
636 jvParams[jss::account_root] = alice.
human();
637 jvParams[jss::binary] = 1;
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);
647 jvParams[jss::index] = accountRootIndex;
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");
658 jvParams[jss::index] = accountRootIndex;
659 jvParams[jss::binary] = 0;
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");
669 jvParams[jss::account] = alice.
human();
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();
687 jvParams[jss::account_root] =
Account(
"bob").human();
690 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
716 "42426C4D4F1009EE67080A9B7965B44656D7"
717 "714D104A72F9B4369F97ABF044EE"));
720 "4C97EBA926031A7CF7D7B36FDE3ED66DDA54"
721 "21192D63DE53FFB46E43B9DC8373"));
724 "03BDC0099C4E14163ADA272C1B6F6FABB448"
725 "CC3E51F522F978041E4B57D9158C"));
728 "35291ADD2D79EB6991343BDA0912269C817D"
729 "0F094B02226C1C14AD2858962ED4"));
730 sle->setFieldV256(sfAmendments,
STVector256(enabledAmendments));
736 majority1.setFieldH256(
739 "7BB62DC13EC72B775091E9C71BF8CF97E122"
740 "647693B50C5E87A80DFD6FCFAC50"));
741 majority1.setFieldU32(sfCloseTime, 779561310);
742 majorities.
pushBack(std::move(majority1));
745 majority2.setFieldH256(
748 "755C971C29971C9F20C6F080F2ED96F87884"
749 "E40AD19554A5EBECDCEC8A1F77FE"));
750 majority2.setFieldU32(sfCloseTime, 779561310);
751 majorities.
pushBack(std::move(majority2));
753 sle->setFieldArray(sfMajorities, majorities);
764 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
765 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::Amendments);
787 AMM const amm(env, alice,
XRP(10), usd(1000));
793 auto const result = env.
rpc(
"json",
"ledger_entry",
to_string(jvParams));
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);
807 obj[jss::currency] =
"XRP";
808 ammParams[jss::asset] = obj;
812 ammParams[jss::asset2] =
toJson(usd.
raw());
814 jvParams[jss::amm] = ammParams;
815 auto const result = env.
rpc(
"json",
"ledger_entry",
to_string(jvParams));
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);
829 {.fieldName = jss::asset, .malformedErrorMsg =
"malformedRequest"},
830 {.fieldName = jss::asset2, .malformedErrorMsg =
"malformedRequest"},
833 auto const getIOU = [&](
Env& env) ->
PrettyAsset {
return alice[
"USD"]; };
835 return MPTTester({.env = env, .issuer = alice});
851 auto const checkSeq = env.
seq(env.
master);
861 jvParams[jss::check] =
to_string(checkId.key);
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");
872 jvParams[jss::check][jss::account] = env.
master.
human();
873 jvParams[jss::check][jss::seq] = checkSeq;
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));
885 jvParams[jss::check][jss::account] = env.
master.
human();
886 jvParams[jss::check][jss::seq] = checkSeq + 1000;
889 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
898 jvParams[jss::account_root] = alice.
human();
900 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
901 accountRootIndex = jrr[jss::index].
asString();
904 jvParams[jss::check] = accountRootIndex;
907 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
917 {.fieldName = jss::account, .malformedErrorMsg =
"malformedAddress"},
918 {.fieldName = jss::seq, .malformedErrorMsg =
"malformedRequest"},
931 Account const issuer{
"issuer"};
934 char const credType[] =
"abcde";
936 env.
fund(
XRP(5000), issuer, alice, bob);
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);
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);
966 "48004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6EA288B"
977 {.fieldName = jss::subject, .malformedErrorMsg =
"malformedRequest"},
978 {.fieldName = jss::issuer, .malformedErrorMsg =
"malformedRequest"},
979 {.fieldName = jss::credential_type, .malformedErrorMsg =
"malformedRequest"},
994 env.
fund(
XRP(10000), alice, bob);
1003 jvParams[jss::delegate][jss::account] = alice.
human();
1004 jvParams[jss::delegate][jss::authorize] = bob.
human();
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();
1016 jvParams[jss::delegate] = delegateIndex;
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());
1031 {.fieldName = jss::account, .malformedErrorMsg =
"malformedAddress"},
1032 {.fieldName = jss::authorize, .malformedErrorMsg =
"malformedAddress"},
1048 env.
fund(
XRP(10000), alice, becky);
1059 jvParams[jss::deposit_preauth][jss::owner] = alice.
human();
1060 jvParams[jss::deposit_preauth][jss::authorized] = becky.
human();
1063 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
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();
1073 jvParams[jss::deposit_preauth] = depositPreauthIndex;
1076 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
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());
1086 jss::deposit_preauth,
1088 {.fieldName = jss::owner, .malformedErrorMsg =
"malformedOwner"},
1090 .fieldName = jss::authorized,
1091 .malformedErrorMsg =
"malformedAuthorized",
1101 testcase(
"Deposit Preauth with credentials");
1106 Account const issuer{
"issuer"};
1109 char const credType[] =
"abcde";
1111 env.
fund(
XRP(5000), issuer, alice, bob);
1116 env(
fset(bob, asfDepositAuth));
1125 jvParams[jss::ledger_index] = jss::validated;
1126 jvParams[jss::deposit_preauth][jss::owner] = bob.
human();
1129 auto& arr(jvParams[jss::deposit_preauth][jss::authorized_credentials]);
1132 jo[jss::issuer] = issuer.
human();
1134 arr.append(std::move(jo));
1135 auto const jrr = env.
rpc(
"json",
"ledger_entry",
to_string(jvParams));
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);
1147 jvParams[jss::ledger_index] = jss::validated;
1148 jvParams[jss::deposit_preauth][jss::owner] = bob.
human();
1150 auto const tryField = [&](
json::Value fieldValue) ->
void {
1153 jo[jss::issuer] = fieldValue;
1156 jvParams[jss::deposit_preauth][jss::authorized_credentials] = arr;
1159 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1160 auto const expectedErrMsg = fieldValue.
isNull()
1168 for (
auto const& value : badValues)
1178 jvParams[jss::ledger_index] = jss::validated;
1179 jvParams[jss::deposit_preauth][jss::owner] = bob.
human();
1182 auto& arr(jvParams[jss::deposit_preauth][jss::authorized_credentials]);
1185 jo[jss::issuer] = issuer.
human();
1188 arr.append(std::move(jo));
1189 auto const jrr = env.
rpc(
"json",
"ledger_entry",
to_string(jvParams));
1192 "malformedAuthorizedCredentials",
1200 jvParams[jss::ledger_index] = jss::validated;
1201 jvParams[jss::deposit_preauth][jss::owner] = bob.
human();
1203 auto const tryField = [&](
json::Value fieldValue) ->
void {
1206 jo[jss::issuer] = issuer.
human();
1207 jo[jss::credential_type] = fieldValue;
1209 jvParams[jss::deposit_preauth][jss::authorized_credentials] = arr;
1212 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1213 auto const expectedErrMsg = fieldValue.
isNull()
1221 for (
auto const& value : badValues)
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();
1236 auto& arr(jvParams[jss::deposit_preauth][jss::authorized_credentials]);
1239 jo[jss::issuer] = issuer.
human();
1241 arr.append(std::move(jo));
1243 auto const jrr = env.
rpc(
"json",
"ledger_entry",
to_string(jvParams));
1248 "Must have exactly one of `authorized` and "
1249 "`authorized_credentials`.");
1255 jvParams[jss::ledger_index] = jss::validated;
1256 jvParams[jss::deposit_preauth][jss::owner] = bob.
human();
1260 jss::deposit_preauth,
1261 jss::authorized_credentials,
1263 "malformedAuthorizedCredentials",
1270 jvParams[jss::ledger_index] = jss::validated;
1271 jvParams[jss::deposit_preauth][jss::owner] = bob.
human();
1273 auto& arr(jvParams[jss::deposit_preauth][jss::authorized_credentials]);
1274 arr.append(
"foobar");
1276 auto const jrr = env.
rpc(
"json",
"ledger_entry",
to_string(jvParams));
1279 "malformedAuthorizedCredentials",
1281 "Invalid field 'authorized_credentials', not array of objects.");
1287 jvParams[jss::ledger_index] = jss::validated;
1288 jvParams[jss::deposit_preauth][jss::owner] = bob.
human();
1290 auto& arr(jvParams[jss::deposit_preauth][jss::authorized_credentials]);
1293 arr.
append(std::move(payload));
1295 auto const jrr = env.
rpc(
"json",
"ledger_entry",
to_string(jvParams));
1298 "malformedAuthorizedCredentials",
1300 "Invalid field 'authorized_credentials', not array of objects.");
1306 jvParams[jss::ledger_index] = jss::validated;
1307 jvParams[jss::deposit_preauth][jss::owner] = bob.
human();
1310 auto const jrr = env.
rpc(
"json",
"ledger_entry",
to_string(jvParams));
1313 "malformedAuthorizedCredentials",
1315 "Invalid field 'authorized_credentials', array empty.");
1334 jvParams[jss::ledger_index] = jss::validated;
1335 jvParams[jss::deposit_preauth][jss::owner] = bob.
human();
1338 auto& arr(jvParams[jss::deposit_preauth][jss::authorized_credentials]);
1340 for (
auto const cred : kCredTypes)
1343 jo[jss::issuer] = issuer.
human();
1345 arr.append(std::move(jo));
1348 auto const jrr = env.
rpc(
"json",
"ledger_entry",
to_string(jvParams));
1351 "malformedAuthorizedCredentials",
1353 "Invalid field 'authorized_credentials', array too long.");
1365 auto const usd = gw[
"USD"];
1366 env.
fund(
XRP(10000), alice, gw);
1369 env.
trust(usd(1000), alice);
1374 for (
int d = 1'000'032; d >= 1'000'000; --d)
1384 BEAST_EXPECT(jrr[jss::ledger_hash] ==
ledgerHash);
1385 BEAST_EXPECT(jrr[jss::ledger_index] == 5);
1389 "A33EC6BB85FB5674074C4A3A43373BB17645308F3EAE1933E3E35252162B217D";
1393 jvParams[jss::directory] = dirRootIndex;
1396 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1397 BEAST_EXPECT(jrr[jss::node][sfIndexes.jsonName].
size() == 32);
1403 jvParams[jss::directory][jss::dir_root] = dirRootIndex;
1405 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1406 BEAST_EXPECT(jrr[jss::index] == dirRootIndex);
1412 jvParams[jss::directory][jss::owner] = alice.
human();
1415 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1416 BEAST_EXPECT(jrr[jss::index] == dirRootIndex);
1422 jvParams[jss::directory][jss::dir_root] = dirRootIndex;
1423 jvParams[jss::directory][jss::sub_index] = 1;
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);
1433 jvParams[jss::directory][jss::owner] = alice.
human();
1434 jvParams[jss::directory][jss::sub_index] = 1;
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);
1452 jvParams[jss::directory][jss::dir_root] = dirRootIndex;
1482 jvParams[jss::directory][jss::owner] = alice.
human();
1483 jvParams[jss::directory][jss::dir_root] = dirRootIndex;
1486 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1491 "Must have exactly one of `owner` and `dir_root` fields.");
1497 jvParams[jss::directory][jss::sub_index] = 1;
1500 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1505 "Must have exactly one of `owner` and `dir_root` fields.");
1525 jv[jss::TransactionType] = jss::EscrowCreate;
1526 jv[jss::Account] = account.human();
1527 jv[jss::Destination] = to.human();
1529 jv[sfFinishAfter.jsonName] = cancelAfter.time_since_epoch().count() + 2;
1533 using namespace std::chrono_literals;
1534 env(escrowCreate(alice, alice,
XRP(333), env.
now() + 2s));
1543 jvParams[jss::escrow][jss::owner] = alice.
human();
1544 jvParams[jss::escrow][jss::seq] = env.
seq(alice) - 1;
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();
1553 jvParams[jss::escrow] = escrowIndex;
1556 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1557 BEAST_EXPECT(jrr[jss::node][jss::Amount] ==
XRP(333).value().getText());
1565 {.fieldName = jss::owner, .malformedErrorMsg =
"malformedOwner"},
1566 {.fieldName = jss::seq, .malformedErrorMsg =
"malformedSeq"},
1584 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1585 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::FeeSettings);
1606 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1607 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::LedgerHashes);
1623 Account const issuer{
"issuer"};
1625 env.
fund(
XRP(1000), issuer, buyer);
1638 jvParams[jss::nft_offer] =
to_string(offerID);
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");
1650 jvParams[jss::nft_offer][jss::owner] = issuer.
human();
1651 jvParams[jss::nft_offer][jss::seq] = offerSeq;
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));
1664 jvParams[jss::nft_offer][jss::owner] = issuer.
human();
1665 jvParams[jss::nft_offer][jss::seq] = offerSeq + 1000;
1667 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1676 {.fieldName = jss::owner, .malformedErrorMsg =
"malformedOwner"},
1677 {.fieldName = jss::seq, .malformedErrorMsg =
"malformedRequest"},
1689 Account const issuer{
"issuer"};
1696 BEAST_EXPECT(env.
le(nftpage) !=
nullptr);
1700 jvParams[jss::nft_page] =
to_string(nftpage.key);
1702 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1703 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::NFTokenPage);
1731 "ED58F6770DB5DD77E59D28CB650EC3816E2FC95021BB56E720C9A1"
1733 disabledValidator.setFieldVL(sfPublicKey, *pubKeyBlob);
1734 disabledValidator.setFieldU32(sfFirstLedgerSequence, 91371264);
1735 disabledValidators.
pushBack(std::move(disabledValidator));
1737 sle->setFieldArray(sfDisabledValidators, disabledValidators);
1741 "8D47FFE664BE6C335108DF689537625855A6"
1742 "A95160CC6D351341B9"
1744 sle->setFieldU32(sfPreviousTxnLgrSeq, 91442944);
1755 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1756 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::NegativeUNL);
1772 auto const usd = gw[
"USD"];
1773 env.
fund(
XRP(10000), alice, gw);
1776 env(
offer(alice, usd(321),
XRP(322)));
1785 jvParams[jss::offer][jss::account] = alice.
human();
1786 jvParams[jss::offer][jss::seq] = env.
seq(alice) - 1;
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();
1796 jvParams[jss::offer] = offerIndex;
1798 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1799 BEAST_EXPECT(jrr[jss::node][jss::TakerGets] ==
"322000000");
1808 {.fieldName = jss::account, .malformedErrorMsg =
"malformedAddress"},
1809 {.fieldName = jss::seq, .malformedErrorMsg =
"malformedRequest"},
1833 jv[jss::TransactionType] = jss::PaymentChannelCreate;
1834 jv[jss::Account] = account.human();
1835 jv[jss::Destination] = to.human();
1837 jv[sfSettleDelay.jsonName] = settleDelay.count();
1838 jv[sfPublicKey.jsonName] =
strHex(pk.slice());
1842 auto const payChanSeq = env.
seq(alice);
1843 env(payChanCreate(alice, env.
master,
XRP(57), 18s, alice.
pk()));
1853 jvParams[jss::payment_channel] =
to_string(payChanIndex);
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);
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;
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));
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;
1885 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1894 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1902 jss::payment_channel,
1904 {.fieldName = jss::account, .malformedErrorMsg =
"malformedAddress"},
1905 {.fieldName = jss::destination, .malformedErrorMsg =
"malformedAddress"},
1906 {.fieldName = jss::seq, .malformedErrorMsg =
"malformedRequest"},
1919 auto const usd = gw[
"USD"];
1920 env.
fund(
XRP(10000), alice, gw);
1923 env.
trust(usd(999), alice);
1926 env(
pay(gw, alice, usd(97)));
1930 for (
auto const& fieldName : {jss::ripple_state, jss::state})
1938 jvParams[fieldName][jss::accounts][0u] = alice.
human();
1939 jvParams[fieldName][jss::accounts][1u] = gw.
human();
1940 jvParams[fieldName][jss::currency] =
"USD";
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");
1953 {.fieldName = jss::accounts, .malformedErrorMsg =
"malformedRequest"},
1954 {.fieldName = jss::currency, .malformedErrorMsg =
"malformedCurrency"},
1962 jvParams[fieldName][jss::accounts][0u] = alice.
human();
1963 jvParams[fieldName][jss::currency] =
"USD";
1966 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1971 "Invalid field 'accounts', not length-2 array of "
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";
1985 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1990 "Invalid field 'accounts', not length-2 array of "
1997 auto const tryField = [&](
json::Value badAccount) ->
void {
2001 jvParams[fieldName][jss::accounts][0u] = badAccount;
2002 jvParams[fieldName][jss::accounts][1u] = gw.
human();
2003 jvParams[fieldName][jss::currency] =
"USD";
2006 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
2017 jvParams[fieldName][jss::accounts][0u] = alice.
human();
2018 jvParams[fieldName][jss::accounts][1u] = badAccount;
2019 jvParams[fieldName][jss::currency] =
"USD";
2022 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
2032 for (
auto const& value : badValues)
2043 jvParams[fieldName][jss::accounts][0u] = alice.
human();
2044 jvParams[fieldName][jss::accounts][1u] = alice.
human();
2045 jvParams[fieldName][jss::currency] =
"USD";
2048 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
2050 jrr,
"malformedRequest",
RpcInvalidParams,
"Cannot have a trustline to self.");
2069 env(
signers(alice, 1, {{bogie, 1}, {demon, 1}}));
2077 jvParams[jss::signer_list] =
to_string(signerListIndex);
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);
2088 jvParams[jss::signer_list][jss::account] = alice.
human();
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));
2100 jvParams[jss::signer_list][jss::account] = env.
master.
human();
2103 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
2112 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
2122 {.fieldName = jss::account, .malformedErrorMsg =
"malformedAddress"},
2137 env.
fund(
XRP(10000), alice, bob);
2147 jvParams[jss::sponsorship][jss::sponsor] = alice.
human();
2148 jvParams[jss::sponsorship][jss::sponsee] = bob.
human();
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());
2159 jvParams[jss::sponsorship] = sponsorshipIndex;
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());
2174 {.fieldName = jss::sponsor, .malformedErrorMsg =
"malformedSponsor"},
2175 {.fieldName = jss::sponsee, .malformedErrorMsg =
"malformedSponsee"},
2203 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
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());
2222 jvParams[jss::ticket][jss::account] = env.
master.
human();
2223 jvParams[jss::ticket][jss::ticket_seq] = tkt1.
value();
2226 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
2235 jvParams[jss::ticket][jss::account] = env.
master.
human();
2236 jvParams[jss::ticket][jss::ticket_seq] = tkt1.
value();
2239 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
2248 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
2259 {.fieldName = jss::account, .malformedErrorMsg =
"malformedAddress"},
2260 {.fieldName = jss::ticket_seq, .malformedErrorMsg =
"malformedRequest"},
2274 Account const target{
"target"};
2276 env.
fund(
XRP(10000), target, bob);
2295 jvParams[jss::transaction_proposal][jss::account] = target.
human();
2296 jvParams[jss::transaction_proposal][jss::ticket_seq] = ticketSeq;
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());
2305 jvParams[jss::transaction_proposal] = proposalIndex;
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());
2314 jvParams[jss::transaction_proposal][jss::account] = target.
human();
2315 jvParams[jss::transaction_proposal][jss::ticket_seq] = ticketSeq + 1;
2317 auto const jrr = env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
2325 auto const jrr = env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
2338 jss::transaction_proposal,
2340 {.fieldName = jss::account, .malformedErrorMsg =
"malformedAddress"},
2341 {.fieldName = jss::ticket_seq, .malformedErrorMsg =
"malformedRequest"},
2362 jv[jss::TransactionType] = jss::DIDSet;
2363 jv[jss::Account] = account.human();
2369 env(didCreate(alice));
2377 jvParams[jss::did] = alice.
human();
2380 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
2381 BEAST_EXPECT(jrr[jss::node][sfDIDDocument.jsonName] ==
strHex(
std::string{
"data"}));
2390 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
2404 testcase(
"Invalid Oracle Ledger Entry");
2412 env, {.owner = owner, .fee =
static_cast<int>(env.
current()->fees().base.drops())});
2420 {.fieldName = jss::account, .malformedErrorMsg =
"malformedAccount"},
2422 .fieldName = jss::oracle_document_id,
2423 .malformedErrorMsg =
"malformedDocumentID",
2437 auto const baseFee =
static_cast<int>(env.
current()->fees().base.drops());
2440 for (
int i = 0; i < 10; ++i)
2445 Oracle const oracle(env, {.owner = owner, .documentID = i, .fee = baseFee});
2449 Oracle const oracle1(env, {.owner = owner, .documentID = i + 10, .fee = baseFee});
2451 oracles.
push_back(oracle1.documentID());
2453 for (
int i = 0; i < accounts.
size(); ++i)
2455 auto const jv = [&] {
2464 BEAST_EXPECT(jv[jss::node][jss::Owner] ==
to_string(accounts[i]));
2483 MPTTester mptAlice(env, alice, {.holders = {bob}});
2488 .flags = tfMPTCanLock | tfMPTRequireAuth | tfMPTCanEscrow | tfMPTCanTrade |
2489 tfMPTCanTransfer | tfMPTCanClawback,
2491 mptAlice.authorize({.account = bob, .holderCount = 1});
2495 std::string const badMptID =
"00000193B9DDCAF401B5B3B26875986043F82CD0D13B4315";
2499 jvParams[jss::mpt_issuance] =
strHex(mptAlice.issuanceID());
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()));
2509 jvParams[jss::mpt_issuance] = badMptID;
2512 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
2519 jvParams[jss::mptoken][jss::account] = bob.
human();
2520 jvParams[jss::mptoken][jss::mpt_issuance_id] =
strHex(mptAlice.issuanceID());
2523 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
2525 jrr[jss::node][sfMPTokenIssuanceID.jsonName] ==
strHex(mptAlice.issuanceID()));
2531 jvParams[jss::mptoken][jss::account] = bob.
human();
2532 jvParams[jss::mptoken][jss::mpt_issuance_id] = badMptID;
2535 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
2554 Account const issuer{
"issuer"};
2558 env.
fund(
XRP(5000), issuer, alice, bob);
2561 auto const seq = env.
seq(alice);
2562 env(
pdomain::setTx(alice, {{.issuer = alice, .credType =
"first credential"}}));
2565 if (!BEAST_EXPECT(objects.size() == 1))
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));
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);
2586 params[jss::ledger_index] = jss::validated;
2587 params[jss::permissioned_domain] = pdIdx;
2588 jv = env.
rpc(
"json",
"ledger_entry",
to_string(params));
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);
2599 params[jss::ledger_index] = jss::validated;
2600 params[jss::permissioned_domain] =
2601 "12F1F1F1F180D67377B2FAB292A31C922470326268D2B9B74CD1E582645B9A"
2603 auto const jrr = env.
rpc(
"json",
"ledger_entry",
to_string(params));
2611 jss::permissioned_domain,
2613 {.fieldName = jss::account, .malformedErrorMsg =
"malformedAddress"},
2614 {.fieldName = jss::seq, .malformedErrorMsg =
"malformedRequest"},
2648 auto checkResult = [&](
bool good,
2653 std::string const& expectedMessage =
"Entry not found.") {
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,
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,
2689 Keylet const& expectedKey,
2691 testcase << expectedType.cStr() << (good ?
"" :
" not") <<
" found";
2693 auto const hexKey =
strHex(expectedKey.key);
2699 params[jss::ledger_index] = jss::validated;
2701 auto const jv = env.
rpc(
"json",
"ledger_entry",
to_string(params));
2709 BEAST_EXPECT(!jv[jss::result].isMember(jss::index));
2715 params[jss::ledger_index] = jss::validated;
2716 params[field] =
"arbitrary string";
2717 auto const jv = env.
rpc(
"json",
"ledger_entry",
to_string(params));
2725 BEAST_EXPECT(!jv[jss::result].isMember(jss::index));
2731 params[jss::ledger_index] = jss::validated;
2732 params[field] =
false;
2733 auto const jv = env.
rpc(
"json",
"ledger_entry",
to_string(params));
2741 BEAST_EXPECT(!jv[jss::result].isMember(jss::index));
2749 params[jss::ledger_index] = jss::validated;
2750 params[field] = badKey;
2751 auto const jv = env.
rpc(
"json",
"ledger_entry",
to_string(params));
2753 false, jv, expectedType,
"entryNotFound",
RpcEntryNotFound,
"Entry not found.");
2754 BEAST_EXPECTS(jv[jss::result][jss::index] == badKey,
to_string(jv));
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));
2771 BEAST_EXPECT(!jv[jss::result].isMember(jss::index));
2779 params[jss::ledger_index] = jss::validated;
2780 params[field] =
true;
2781 auto const jv = env.
rpc(
"json",
"ledger_entry",
to_string(params));
2783 std::string const pdIdx = jv[jss::result][jss::index].asString();
2784 BEAST_EXPECTS(hexKey == pdIdx,
to_string(jv));
2785 checkResult(good, jv, expectedType);
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);
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));
2816 BEAST_EXPECT(!jv[jss::result].isMember(jss::index));
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));
2827 BEAST_EXPECT(jv[jss::result][jss::index].asString() == hexKey);
2828 checkResult(good, jv, expectedType);
2834 params[jss::ledger_index] = jss::validated;
2835 params[jss::index] = pdIdx;
2836 auto const jv = env.
rpc(
"json",
"ledger_entry",
to_string(params));
2838 BEAST_EXPECT(jv[jss::result][jss::index].asString() == hexKey);
2839 checkResult(good, jv, expectedType);
2877 auto checkResult = [&](
bool good,
2882 std::string const& expectedMessage =
"Entry not found.") {
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,
2893 jv[jss::result].isMember(jss::node) &&
2894 jv[jss::result][jss::node].isMember(
"Hashes") &&
2895 jv[jss::result][jss::node][
"Hashes"].
size() == expectedCount,
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,
2922 [&](
json::Value ledger,
Keylet const& expectedKey,
bool good,
int expectedCount = 0) {
2924 <<
" \"hashes\":" <<
to_string(ledger) << (good ?
"" :
" not") <<
" found";
2926 auto const hexKey =
strHex(expectedKey.key);
2932 params[jss::ledger_index] = jss::validated;
2934 auto jv = env.
rpc(
"json",
"ledger_entry",
to_string(params));
2942 BEAST_EXPECT(!jv[jss::result].isMember(jss::index));
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));
2958 BEAST_EXPECT(!jv[jss::result].isMember(jss::index));
2964 params[jss::ledger_index] = jss::validated;
2965 params[jss::hashes] =
"10";
2966 auto const jv = env.
rpc(
"json",
"ledger_entry",
to_string(params));
2974 BEAST_EXPECT(!jv[jss::result].isMember(jss::index));
2980 params[jss::ledger_index] = jss::validated;
2981 params[jss::hashes] =
false;
2982 auto const jv = env.
rpc(
"json",
"ledger_entry",
to_string(params));
2990 BEAST_EXPECT(!jv[jss::result].isMember(jss::index));
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));
3007 params[jss::ledger_index] = jss::validated;
3008 params[jss::hashes] = badKey;
3009 auto const jv = env.
rpc(
"json",
"ledger_entry",
to_string(params));
3012 BEAST_EXPECT(jv[jss::result][jss::index] == badKey);
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);
3024 std::string const pdIdx = jv[jss::result][jss::index].asString();
3025 BEAST_EXPECTS(hexKey == pdIdx,
strHex(pdIdx));
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);
3037 hexKey == jv[jss::result][jss::index].asString(),
3038 strHex(jv[jss::result][jss::index].asString()));
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);
3050 hexKey == jv[jss::result][jss::index].asString(),
3051 strHex(jv[jss::result][jss::index].asString()));
3063 for (
auto i = env.
current()->seq(); i <= 250; ++i)
3074 for (
auto i = env.
current()->seq(); i <= 260; ++i)
3103 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::Check);
3104 BEAST_EXPECT(jrr[jss::node][sfSendMax.jsonName] ==
"100000000");
A generic endpoint for log messages.
void fail(String const &reason, char const *file, int line)
Record a failure.
TestcaseT testcase
Memberspace for declaring test cases.
Lightweight wrapper to tag static string.
constexpr char const * cStr() const
Value removeMember(char const *key)
Remove and return the named member.
bool isNull() const
isNull() tests to see if this field is null.
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)
std::chrono::time_point< NetClock > time_point
std::chrono::duration< rep, period > duration
bool modify(ModifyType const &f)
Modify the open ledger.
Writable ledger view that accumulates state and tx changes.
void rawInsert(SLE::Ref sle) override
Unconditionally insert a state item.
void pushBack(STObject const &object)
static STObject makeInnerObject(SField const &name)
A type that represents either a sequence value or a ticket value.
static constexpr SeqProxy rawSequence(std::uint32_t v)
Factory function to return a sequence-based SeqProxy.
SeqProxy & advanceBy(std::uint32_t amount)
static constexpr SeqProxy rawTicket(std::uint32_t v)
Factory function to return a ticket-based SeqProxy.
constexpr std::uint32_t value() const
virtual OpenLedger & getOpenLedger()=0
void runLedgerEntryTest(test::jtx::Env &env, json::StaticString const &parentField, std::source_location const location=std::source_location::current())
void testOracleLedgerEntry()
void run() override
Runs the suite.
void testTransactionProposal()
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 testDepositPreauth()
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 testPermissionedDomain()
void testDepositPreauthCred()
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())
void testInvalidOracleLedgerEntry()
static json::Value getCorrectValue(json::StaticString fieldName)
Convenience class to test AMM functionality.
Immutable cryptographic account descriptor.
std::string const & human() const
Returns the human readable public key.
PublicKey const & pk() const
Return the public key.
AccountID id() const
Returns the Account ID.
A transaction testing environment.
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
SLE::const_pointer le(Account const &account) const
Return an account root.
std::shared_ptr< ReadView const > closed()
Returns the last closed ledger.
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
std::uint32_t seq(Account const &account) const
Returns the next sequence number on account.
json::Value rpc(unsigned apiVersion, std::unordered_map< std::string, std::string > const &headers, std::string const &cmd, Args &&... args)
Execute an RPC command.
void trust(STAmount const &amount, Account const &account)
Establish trust lines.
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
NetClock::time_point now()
Returns the current network time.
Test helper for creating, mutating, and asserting MPT and confidential MPT ledger state.
void create(MPTCreate const &arg=MPTCreate{}, std::source_location const &loc=std::source_location::current())
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)
Sets the optional Destination field on an NFTokenOffer.
@ Array
array value (ordered list)
@ Object
object value (collection of name/value pairs).
Keylet computation functions.
Keylet const & skip() noexcept
The index of the "short" skip list.
Keylet nftokenOffer(AccountID const &owner, SeqProxy const &seq)
An offer from an account to buy or sell an NFT.
Keylet payChannel(AccountID const &src, AccountID const &dst, SeqProxy const &seq) noexcept
A PaymentChannel.
Keylet const & negativeUNL() noexcept
The (fixed) index of the object containing the ledger negativeUNL.
Keylet const & feeSettings() noexcept
The (fixed) index of the object containing the ledger fees.
Keylet const & amendments() noexcept
The index of the amendment table.
Keylet signerList(AccountID const &account) noexcept
A SignerList.
Keylet txProposal(AccountID const &target, std::uint32_t ticketSequence) noexcept
A TransactionProposal.
Keylet check(AccountID const &id, SeqProxy const &seq) noexcept
A Check.
Keylet ticket(AccountID const &id, SeqProxy const &ticketSeq)
A ticket belonging to an account.
Keylet permissionedDomain(AccountID const &account, SeqProxy const &seq) noexcept
Keylet nftokenPageMax(AccountID const &owner)
A keylet for the owner's last possible NFT page.
Keylet account(AccountID const &id) noexcept
AccountID root.
Keylet sponsorship(AccountID const &sponsor, AccountID const &sponsee) noexcept
A Sponsorship.
The api_version numbers this server serves.
std::string expectedFieldMessage(std::string const &name, std::string const &type)
std::string missingFieldMessage(std::string const &name)
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)
json::Value ledgerEntry(jtx::Env &env, jtx::Account const &subject, jtx::Account const &issuer, std::string_view credType)
json::Value set(jtx::Account const &account, jtx::Account const &authorize, std::vector< std::string > const &permissions)
json::Value authCredentials(jtx::Account const &account, std::vector< AuthorizeCredentials > const &auth)
json::Value auth(Account const &account, Account const &auth)
Preauthorize for deposit.
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...
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.
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,...
json::Value create(Account const &proposer, json::Value const &proposedTx, std::uint32_t expiration)
Build a TransactionProposalCreate carrying an unsigned proposed transaction.
std::uint32_t expiration(Env &env, NetClock::duration delta)
An absolute expiration delta past the environment's current time.
json::Value create(Account const &account, std::uint32_t count)
Create one of more tickets.
json::Value mint(jtx::Account const &account, std::uint32_t nfTokenTaxon)
Mint an NFToken.
json::Value createOffer(jtx::Account const &account, UInt256 const &nftokenID, STAmount const &amount)
Create an NFTokenOffer.
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.
json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
RequireT required(Args const &... args)
Compose many condition functors into one.
XrpT const XRP
Converts to XRP Issue or STAmount.
FeatureBitset testableAmendments()
json::Value offer(Account const &account, STAmount const &takerPays, STAmount const &takerGets, std::uint32_t flags)
Create an offer.
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
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)
json::Value fset(Account const &account, std::uint32_t on, std::uint32_t off=0)
Add and/or remove flag.
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.
@ RpcUnexpectedLedgerType
void forAllApiVersions(Fn const &fn, Args &&... args)
std::string strHex(FwdIt begin, FwdIt end)
std::string to_string(BaseUInt< Bits, Tag > const &a)
json::Value toJson(Asset const &asset)
Asset getAsset(T const &amt)
constexpr std::size_t kMaxCredentialsArraySize
The maximum number of credentials can be passed in array.
std::optional< Blob > strUnHex(std::size_t strSize, Iterator begin, Iterator end)
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
A pair of SHAMap key and LedgerEntryType.
json::StaticString fieldName
std::string malformedErrorMsg
Asset const & raw() const