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/attester.h>
8#include <test/jtx/credentials.h>
9#include <test/jtx/delegate.h>
10#include <test/jtx/deposit.h>
11#include <test/jtx/envconfig.h>
12#include <test/jtx/flags.h>
13#include <test/jtx/mpt.h>
14#include <test/jtx/multisign.h>
15#include <test/jtx/offer.h>
16#include <test/jtx/pay.h>
17#include <test/jtx/permissioned_domains.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#include <test/jtx/xchain_bridge.h>
24#include <xrpl/basics/Number.h>
25#include <xrpl/basics/StringUtilities.h>
26#include <xrpl/basics/base_uint.h>
27#include <xrpl/basics/chrono.h>
28#include <xrpl/basics/contract.h>
29#include <xrpl/basics/strHex.h>
30#include <xrpl/beast/unit_test/suite.h>
31#include <xrpl/beast/utility/Journal.h>
32#include <xrpl/core/ServiceRegistry.h>
33#include <xrpl/core/StartUpType.h>
34#include <xrpl/json/json_value.h>
35#include <xrpl/json/to_string.h>
36#include <xrpl/ledger/OpenView.h>
37#include <xrpl/protocol/AccountID.h>
38#include <xrpl/protocol/ApiVersion.h>
39#include <xrpl/protocol/Asset.h>
40#include <xrpl/protocol/ErrorCodes.h>
41#include <xrpl/protocol/Feature.h>
42#include <xrpl/protocol/Indexes.h>
43#include <xrpl/protocol/Keylet.h>
44#include <xrpl/protocol/Protocol.h>
45#include <xrpl/protocol/SField.h>
46#include <xrpl/protocol/STArray.h>
47#include <xrpl/protocol/STVector256.h>
48#include <xrpl/protocol/STXChainBridge.h>
49#include <xrpl/protocol/SeqProxy.h>
50#include <xrpl/protocol/TxFlags.h>
51#include <xrpl/protocol/jss.h>
60#include <source_location>
108 gMappings, [&fieldName](
auto const& pair) {
return pair.first == fieldName; });
134 return "hex string or object";
138 return "length-2 array of Accounts";
157 if (BEAST_EXPECT(jv.
isMember(jss::status)))
158 BEAST_EXPECTS(jv[jss::status] ==
"error",
std::to_string(location.line()));
159 if (BEAST_EXPECT(jv.
isMember(jss::error)))
162 jv[jss::error] == err,
163 "Expected error " + err +
", received " + jv[jss::error].asString() +
", at line " +
170 "Expected no error message, received \"" + jv[jss::error_message].asString() +
173 else if (BEAST_EXPECT(jv.
isMember(jss::error_message)))
176 jv[jss::error_message] == msg,
177 "Expected error message \"" + msg +
"\", received \"" +
178 jv[jss::error_message].asString() +
"\", at line " +
188 obj[jss::account] =
"rhigTLJJyXXSRUyRCQtqi1NoAZZzZnS4KU";
189 obj[jss::ledger_index] =
"validated";
194 arr[0u] =
"rhigTLJJyXXSRUyRCQtqi1NoAZZzZnS4KU";
195 arr[1u] =
"validated";
209 "0123456789ABCDEFGH",
210 "rJxKV9e9p6wiPw!!!!xrJ4X1n98LosPL1sgcJW",
211 "rPSTrR5yEr11uMkfsz1kHCp9jK4aoa3Avv",
212 "n9K2isxwTxcSHJKxMkJznDoWXAUs7NNy49H9Fknz1pC7oHAH3kH9",
215 "5233D68B4D44388F98559DE42903767803EFA7C1F8D01413FC16EE6B01403D"
237 static auto const& kBadAccountValues = remove({12});
238 static auto const& kBadArrayValues = remove({17, 20});
239 static auto const& kBadBlobValues = remove({3, 7, 8, 16});
240 static auto const& kBadCurrencyValues = remove({14});
241 static auto const& kBadHashValues = remove({2, 3, 7, 8, 16});
242 static auto const& kBadFixedHashValues = remove({1, 2, 3, 4, 7, 8, 16});
243 static auto const& kBadIndexValues = remove({12, 16, 18, 19});
244 static auto const& kBadUInt32Values = remove({2, 3});
245 static auto const& kBadUInt64Values = remove({2, 3});
246 static auto const& kBadIssueValues = remove({});
251 return kBadAccountValues;
254 return kBadArrayValues;
256 return kBadBlobValues;
258 return kBadCurrencyValues;
260 return kBadHashValues;
262 return kBadIndexValues;
264 return kBadFixedHashValues;
266 return kBadIssueValues;
268 return kBadUInt32Values;
270 return kBadUInt64Values;
273 "unknown type " +
std::to_string(
static_cast<uint8_t
>(fieldType)));
282 arr[0u] =
"rhigTLJJyXXSRUyRCQtqi1NoAZZzZnS4KU";
283 arr[1u] =
"r4MrUGTdB57duTnRs6KbsRGQXgkseGb1b5";
288 arr[jss::currency] =
"XRP";
296 return "r4MrUGTdB57duTnRs6KbsRGQXgkseGb1b5";
304 return "5233D68B4D44388F98559DE42903767803EFA7C1F8D01413FC16EE6"
309 return "5233D68B4D44388F98559DE42903767803EFA7C1F8D01413FC16EE6"
312 return kTwoAccountArray;
337 apiVersion,
"json",
"ledger_entry",
to_string(correctRequest))[jss::result];
345 jrr,
"invalidParams",
"No ledger_entry params provided.", location);
348 auto tryField = [&](
json::Value fieldValue) ->
void {
349 correctRequest[fieldName] = fieldValue;
351 apiVersion,
"json",
"ledger_entry",
to_string(correctRequest))[jss::result];
352 auto const expectedErrMsg =
358 for (
auto const& value : badValues)
383 correctRequest[parentFieldName].
removeMember(fieldName);
385 apiVersion,
"json",
"ledger_entry",
to_string(correctRequest))[jss::result];
391 apiVersion,
"json",
"ledger_entry",
to_string(correctRequest))[jss::result];
395 auto tryField = [&](
json::Value fieldValue) ->
void {
396 correctRequest[parentFieldName][fieldName] = fieldValue;
399 apiVersion,
"json",
"ledger_entry",
to_string(correctRequest))[jss::result];
408 for (
auto const& value : badValues)
457 for (
auto const& subfield : subfields)
459 correctOutput[parentField][subfield.fieldName] =
getCorrectValue(subfield.fieldName);
462 for (
auto const& subfield : subfields)
464 auto const fieldType =
getFieldType(subfield.fieldName);
471 subfield.malformedErrorMsg,
489 jvParams[jss::account_root] = alice.
human();
490 jvParams[jss::ledger_hash] =
491 "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
493 auto const jrr = env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
499 jvParams[jss::account_root] = alice.
human();
503 auto tryField = [&](
json::Value fieldValue) ->
void {
504 jvParams[jss::ledger_hash] = fieldValue;
506 apiVersion,
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
508 jrr,
"invalidParams",
"Invalid field 'ledger_hash', not hex string.");
512 for (
auto const& value : badValues)
522 jvParams[jss::ledger_index] =
"validated";
523 jvParams[jss::index] =
524 "00000000000000000000000000000000000000000000000000000000000000"
526 auto const jrr = env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
534 jvParams[jss::features] =
535 "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
537 jvParams[jss::api_version] = apiVersion;
539 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
547 checkErrorValue(jrr,
"invalidParams",
"No ledger_entry params provided.");
560 cfg->fees.referenceFee = 10;
561 Env env{*
this, std::move(cfg)};
571 BEAST_EXPECT(jrr[jss::ledger_hash] ==
ledgerHash);
572 BEAST_EXPECT(jrr[jss::ledger_index] == 3);
579 jvParams[jss::account_root] = alice.
human();
582 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
583 BEAST_EXPECT(jrr.
isMember(jss::node));
584 BEAST_EXPECT(jrr[jss::node][jss::Account] == alice.
human());
585 BEAST_EXPECT(jrr[jss::node][sfBalance.jsonName] ==
"10000000000");
586 accountRootIndex = jrr[jss::index].
asString();
589 static constexpr char kAliceAcctRootBinary[]{
590 "1100612200800000240000000425000000032D00000000559CE54C3B934E4"
591 "73A995B477E92EC229F99CED5B62BF4D2ACE4DC42719103AE2F6240000002"
592 "540BE4008114AE123A8556F3CF91154711376AFB0F894F832B3D"};
596 jvParams[jss::account_root] = alice.
human();
597 jvParams[jss::binary] = 1;
600 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
601 BEAST_EXPECT(jrr.
isMember(jss::node_binary));
602 BEAST_EXPECT(jrr[jss::node_binary] == kAliceAcctRootBinary);
607 jvParams[jss::index] = accountRootIndex;
609 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
610 BEAST_EXPECT(!jrr.
isMember(jss::node_binary));
611 BEAST_EXPECT(jrr.
isMember(jss::node));
612 BEAST_EXPECT(jrr[jss::node][jss::Account] == alice.
human());
613 BEAST_EXPECT(jrr[jss::node][sfBalance.jsonName] ==
"10000000000");
618 jvParams[jss::index] = accountRootIndex;
619 jvParams[jss::binary] = 0;
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");
629 jvParams[jss::account] = alice.
human();
632 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
633 BEAST_EXPECT(jrr.
isMember(jss::node));
634 BEAST_EXPECT(jrr[jss::node][jss::Account] == alice.
human());
635 BEAST_EXPECT(jrr[jss::node][sfBalance.jsonName] ==
"10000000000");
636 accountRootIndex = jrr[jss::index].
asString();
647 jvParams[jss::account_root] =
Account(
"bob").human();
650 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
676 "42426C4D4F1009EE67080A9B7965B44656D7"
677 "714D104A72F9B4369F97ABF044EE"));
680 "4C97EBA926031A7CF7D7B36FDE3ED66DDA54"
681 "21192D63DE53FFB46E43B9DC8373"));
684 "03BDC0099C4E14163ADA272C1B6F6FABB448"
685 "CC3E51F522F978041E4B57D9158C"));
688 "35291ADD2D79EB6991343BDA0912269C817D"
689 "0F094B02226C1C14AD2858962ED4"));
690 sle->setFieldV256(sfAmendments,
STVector256(enabledAmendments));
696 majority1.setFieldH256(
699 "7BB62DC13EC72B775091E9C71BF8CF97E122"
700 "647693B50C5E87A80DFD6FCFAC50"));
701 majority1.setFieldU32(sfCloseTime, 779561310);
702 majorities.
pushBack(std::move(majority1));
705 majority2.setFieldH256(
708 "755C971C29971C9F20C6F080F2ED96F87884"
709 "E40AD19554A5EBECDCEC8A1F77FE"));
710 majority2.setFieldU32(sfCloseTime, 779561310);
711 majorities.
pushBack(std::move(majority2));
713 sle->setFieldArray(sfMajorities, majorities);
724 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
725 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::Amendments);
747 AMM const amm(env, alice,
XRP(10), usd(1000));
753 auto const result = env.
rpc(
"json",
"ledger_entry",
to_string(jvParams));
755 result.isObject() && result.isMember(jss::result) &&
756 !result[jss::result].isMember(jss::error) &&
757 result[jss::result].isMember(jss::node) &&
758 result[jss::result][jss::node].isMember(sfLedgerEntryType.jsonName) &&
759 result[jss::result][jss::node][sfLedgerEntryType.jsonName] == jss::AMM);
767 obj[jss::currency] =
"XRP";
768 ammParams[jss::asset] = obj;
772 ammParams[jss::asset2] =
toJson(usd.
raw());
774 jvParams[jss::amm] = ammParams;
775 auto const result = env.
rpc(
"json",
"ledger_entry",
to_string(jvParams));
777 result.isObject() && result.isMember(jss::result) &&
778 !result[jss::result].isMember(jss::error) &&
779 result[jss::result].isMember(jss::node) &&
780 result[jss::result][jss::node].isMember(sfLedgerEntryType.jsonName) &&
781 result[jss::result][jss::node][sfLedgerEntryType.jsonName] == jss::AMM);
789 {.fieldName = jss::asset, .malformedErrorMsg =
"malformedRequest"},
790 {.fieldName = jss::asset2, .malformedErrorMsg =
"malformedRequest"},
793 auto getIOU = [&](
Env& env) ->
PrettyAsset {
return alice[
"USD"]; };
795 return MPTTester({.env = env, .issuer = alice});
820 jvParams[jss::check] =
to_string(checkId.key);
823 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
824 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::Check);
825 BEAST_EXPECT(jrr[jss::node][sfSendMax.jsonName] ==
"100000000");
833 jvParams[jss::account_root] = alice.
human();
835 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
836 accountRootIndex = jrr[jss::index].
asString();
839 jvParams[jss::check] = accountRootIndex;
842 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
843 checkErrorValue(jrr,
"unexpectedLedgerType",
"Unexpected ledger type.");
859 Account const issuer{
"issuer"};
862 char const credType[] =
"abcde";
864 env.
fund(
XRP(5000), issuer, alice, bob);
876 !jv[jss::result].
isMember(jss::error) && jv[jss::result].
isMember(jss::node) &&
877 jv[jss::result][jss::node].
isMember(sfLedgerEntryType.jsonName) &&
878 jv[jss::result][jss::node][sfLedgerEntryType.jsonName] == jss::Credential);
885 !jv[jss::result].
isMember(jss::error) && jv[jss::result].
isMember(jss::node) &&
886 jv[jss::result][jss::node].
isMember(sfLedgerEntryType.jsonName) &&
887 jv[jss::result][jss::node][sfLedgerEntryType.jsonName] == jss::Credential);
894 "48004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6EA288B"
905 {.fieldName = jss::subject, .malformedErrorMsg =
"malformedRequest"},
906 {.fieldName = jss::issuer, .malformedErrorMsg =
"malformedRequest"},
907 {.fieldName = jss::credential_type, .malformedErrorMsg =
"malformedRequest"},
922 env.
fund(
XRP(10000), alice, bob);
931 jvParams[jss::delegate][jss::account] = alice.
human();
932 jvParams[jss::delegate][jss::authorize] = bob.
human();
935 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
936 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::Delegate);
937 BEAST_EXPECT(jrr[jss::node][sfAccount.jsonName] == alice.
human());
938 BEAST_EXPECT(jrr[jss::node][sfAuthorize.jsonName] == bob.
human());
939 delegateIndex = jrr[jss::node][jss::index].
asString();
944 jvParams[jss::delegate] = delegateIndex;
947 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
948 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::Delegate);
949 BEAST_EXPECT(jrr[jss::node][sfAccount.jsonName] == alice.
human());
950 BEAST_EXPECT(jrr[jss::node][sfAuthorize.jsonName] == bob.
human());
959 {.fieldName = jss::account, .malformedErrorMsg =
"malformedAddress"},
960 {.fieldName = jss::authorize, .malformedErrorMsg =
"malformedAddress"},
976 env.
fund(
XRP(10000), alice, becky);
987 jvParams[jss::deposit_preauth][jss::owner] = alice.
human();
988 jvParams[jss::deposit_preauth][jss::authorized] = becky.
human();
991 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
993 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::DepositPreauth);
994 BEAST_EXPECT(jrr[jss::node][sfAccount.jsonName] == alice.
human());
995 BEAST_EXPECT(jrr[jss::node][sfAuthorize.jsonName] == becky.
human());
996 depositPreauthIndex = jrr[jss::node][jss::index].
asString();
1001 jvParams[jss::deposit_preauth] = depositPreauthIndex;
1004 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1006 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::DepositPreauth);
1007 BEAST_EXPECT(jrr[jss::node][sfAccount.jsonName] == alice.
human());
1008 BEAST_EXPECT(jrr[jss::node][sfAuthorize.jsonName] == becky.
human());
1014 jss::deposit_preauth,
1016 {.fieldName = jss::owner, .malformedErrorMsg =
"malformedOwner"},
1017 {.fieldName = jss::authorized,
1018 .malformedErrorMsg =
"malformedAuthorized",
1027 testcase(
"Deposit Preauth with credentials");
1032 Account const issuer{
"issuer"};
1035 char const credType[] =
"abcde";
1037 env.
fund(
XRP(5000), issuer, alice, bob);
1042 env(
fset(bob, asfDepositAuth));
1051 jvParams[jss::ledger_index] = jss::validated;
1052 jvParams[jss::deposit_preauth][jss::owner] = bob.
human();
1055 auto& arr(jvParams[jss::deposit_preauth][jss::authorized_credentials]);
1058 jo[jss::issuer] = issuer.
human();
1060 arr.append(std::move(jo));
1061 auto const jrr = env.
rpc(
"json",
"ledger_entry",
to_string(jvParams));
1064 jrr.isObject() && jrr.isMember(jss::result) &&
1065 !jrr[jss::result].isMember(jss::error) && jrr[jss::result].isMember(jss::node) &&
1066 jrr[jss::result][jss::node].isMember(sfLedgerEntryType.jsonName) &&
1067 jrr[jss::result][jss::node][sfLedgerEntryType.jsonName] == jss::DepositPreauth);
1073 jvParams[jss::ledger_index] = jss::validated;
1074 jvParams[jss::deposit_preauth][jss::owner] = bob.
human();
1076 auto tryField = [&](
json::Value fieldValue) ->
void {
1079 jo[jss::issuer] = fieldValue;
1082 jvParams[jss::deposit_preauth][jss::authorized_credentials] = arr;
1085 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1086 auto const expectedErrMsg = fieldValue.
isNull()
1089 checkErrorValue(jrr,
"malformedAuthorizedCredentials", expectedErrMsg);
1093 for (
auto const& value : badValues)
1103 jvParams[jss::ledger_index] = jss::validated;
1104 jvParams[jss::deposit_preauth][jss::owner] = bob.
human();
1107 auto& arr(jvParams[jss::deposit_preauth][jss::authorized_credentials]);
1110 jo[jss::issuer] = issuer.
human();
1113 arr.append(std::move(jo));
1114 auto const jrr = env.
rpc(
"json",
"ledger_entry",
to_string(jvParams));
1117 "malformedAuthorizedCredentials",
1124 jvParams[jss::ledger_index] = jss::validated;
1125 jvParams[jss::deposit_preauth][jss::owner] = bob.
human();
1127 auto tryField = [&](
json::Value fieldValue) ->
void {
1130 jo[jss::issuer] = issuer.
human();
1131 jo[jss::credential_type] = fieldValue;
1133 jvParams[jss::deposit_preauth][jss::authorized_credentials] = arr;
1136 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1137 auto const expectedErrMsg = fieldValue.
isNull()
1140 checkErrorValue(jrr,
"malformedAuthorizedCredentials", expectedErrMsg);
1144 for (
auto const& value : badValues)
1154 jvParams[jss::ledger_index] = jss::validated;
1155 jvParams[jss::deposit_preauth][jss::owner] = bob.
human();
1156 jvParams[jss::deposit_preauth][jss::authorized] = alice.
human();
1159 auto& arr(jvParams[jss::deposit_preauth][jss::authorized_credentials]);
1162 jo[jss::issuer] = issuer.
human();
1164 arr.append(std::move(jo));
1166 auto const jrr = env.
rpc(
"json",
"ledger_entry",
to_string(jvParams));
1170 "Must have exactly one of `authorized` and "
1171 "`authorized_credentials`.");
1177 jvParams[jss::ledger_index] = jss::validated;
1178 jvParams[jss::deposit_preauth][jss::owner] = bob.
human();
1182 jss::deposit_preauth,
1183 jss::authorized_credentials,
1185 "malformedAuthorizedCredentials",
1192 jvParams[jss::ledger_index] = jss::validated;
1193 jvParams[jss::deposit_preauth][jss::owner] = bob.
human();
1195 auto& arr(jvParams[jss::deposit_preauth][jss::authorized_credentials]);
1196 arr.append(
"foobar");
1198 auto const jrr = env.
rpc(
"json",
"ledger_entry",
to_string(jvParams));
1201 "malformedAuthorizedCredentials",
1202 "Invalid field 'authorized_credentials', not array of objects.");
1208 jvParams[jss::ledger_index] = jss::validated;
1209 jvParams[jss::deposit_preauth][jss::owner] = bob.
human();
1211 auto& arr(jvParams[jss::deposit_preauth][jss::authorized_credentials]);
1214 arr.
append(std::move(payload));
1216 auto const jrr = env.
rpc(
"json",
"ledger_entry",
to_string(jvParams));
1219 "malformedAuthorizedCredentials",
1220 "Invalid field 'authorized_credentials', not array of objects.");
1226 jvParams[jss::ledger_index] = jss::validated;
1227 jvParams[jss::deposit_preauth][jss::owner] = bob.
human();
1230 auto const jrr = env.
rpc(
"json",
"ledger_entry",
to_string(jvParams));
1233 "malformedAuthorizedCredentials",
1234 "Invalid field 'authorized_credentials', array empty.");
1240 "cred1",
"cred2",
"cred3",
"cred4",
"cred5",
"cred6",
"cred7",
"cred8",
"cred9"};
1244 jvParams[jss::ledger_index] = jss::validated;
1245 jvParams[jss::deposit_preauth][jss::owner] = bob.
human();
1248 auto& arr(jvParams[jss::deposit_preauth][jss::authorized_credentials]);
1250 for (
auto cred : kCredTypes)
1253 jo[jss::issuer] = issuer.
human();
1255 arr.append(std::move(jo));
1258 auto const jrr = env.
rpc(
"json",
"ledger_entry",
to_string(jvParams));
1261 "malformedAuthorizedCredentials",
1262 "Invalid field 'authorized_credentials', array too long.");
1274 auto const usd = gw[
"USD"];
1275 env.
fund(
XRP(10000), alice, gw);
1278 env.
trust(usd(1000), alice);
1283 for (
int d = 1'000'032; d >= 1'000'000; --d)
1293 BEAST_EXPECT(jrr[jss::ledger_hash] ==
ledgerHash);
1294 BEAST_EXPECT(jrr[jss::ledger_index] == 5);
1298 "A33EC6BB85FB5674074C4A3A43373BB17645308F3EAE1933E3E35252162B217D";
1302 jvParams[jss::directory] = dirRootIndex;
1305 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1306 BEAST_EXPECT(jrr[jss::node][sfIndexes.jsonName].
size() == 32);
1312 jvParams[jss::directory][jss::dir_root] = dirRootIndex;
1314 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1315 BEAST_EXPECT(jrr[jss::index] == dirRootIndex);
1321 jvParams[jss::directory][jss::owner] = alice.
human();
1324 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1325 BEAST_EXPECT(jrr[jss::index] == dirRootIndex);
1331 jvParams[jss::directory][jss::dir_root] = dirRootIndex;
1332 jvParams[jss::directory][jss::sub_index] = 1;
1334 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1335 BEAST_EXPECT(jrr[jss::index] != dirRootIndex);
1336 BEAST_EXPECT(jrr[jss::node][sfIndexes.jsonName].
size() == 2);
1342 jvParams[jss::directory][jss::owner] = alice.
human();
1343 jvParams[jss::directory][jss::sub_index] = 1;
1346 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1347 BEAST_EXPECT(jrr[jss::index] != dirRootIndex);
1348 BEAST_EXPECT(jrr[jss::node][sfIndexes.jsonName].
size() == 2);
1361 jvParams[jss::directory][jss::dir_root] = dirRootIndex;
1391 jvParams[jss::directory][jss::owner] = alice.
human();
1392 jvParams[jss::directory][jss::dir_root] = dirRootIndex;
1395 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1397 jrr,
"malformedRequest",
"Must have exactly one of `owner` and `dir_root` fields.");
1403 jvParams[jss::directory][jss::sub_index] = 1;
1406 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1408 jrr,
"malformedRequest",
"Must have exactly one of `owner` and `dir_root` fields.");
1428 jv[jss::TransactionType] = jss::EscrowCreate;
1429 jv[jss::Account] = account.human();
1430 jv[jss::Destination] = to.human();
1432 jv[sfFinishAfter.jsonName] = cancelAfter.time_since_epoch().count() + 2;
1436 using namespace std::chrono_literals;
1437 env(escrowCreate(alice, alice,
XRP(333), env.
now() + 2s));
1446 jvParams[jss::escrow][jss::owner] = alice.
human();
1447 jvParams[jss::escrow][jss::seq] = env.
seq(alice) - 1;
1449 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1450 BEAST_EXPECT(jrr[jss::node][jss::Amount] ==
XRP(333).value().getText());
1451 escrowIndex = jrr[jss::index].
asString();
1456 jvParams[jss::escrow] = escrowIndex;
1459 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1460 BEAST_EXPECT(jrr[jss::node][jss::Amount] ==
XRP(333).value().getText());
1467 {{.fieldName = jss::owner, .malformedErrorMsg =
"malformedOwner"},
1468 {.fieldName = jss::seq, .malformedErrorMsg =
"malformedSeq"}});
1485 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1486 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::FeeSettings);
1507 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1508 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::LedgerHashes);
1524 Account const issuer{
"issuer"};
1526 env.
fund(
XRP(1000), issuer, buyer);
1539 jvParams[jss::nft_offer] =
to_string(offerID);
1541 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1542 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::NFTokenOffer);
1543 BEAST_EXPECT(jrr[jss::node][sfOwner.jsonName] == issuer.
human());
1544 BEAST_EXPECT(jrr[jss::node][sfNFTokenID.jsonName] ==
to_string(nftokenID0));
1545 BEAST_EXPECT(jrr[jss::node][sfAmount.jsonName] ==
"1");
1560 Account const issuer{
"issuer"};
1567 BEAST_EXPECT(env.
le(nftpage) !=
nullptr);
1571 jvParams[jss::nft_page] =
to_string(nftpage.key);
1573 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1574 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::NFTokenPage);
1602 "ED58F6770DB5DD77E59D28CB650EC3816E2FC95021BB56E720C9A1"
1604 disabledValidator.setFieldVL(sfPublicKey, *pubKeyBlob);
1605 disabledValidator.setFieldU32(sfFirstLedgerSequence, 91371264);
1606 disabledValidators.
pushBack(std::move(disabledValidator));
1608 sle->setFieldArray(sfDisabledValidators, disabledValidators);
1612 "8D47FFE664BE6C335108DF689537625855A6"
1613 "A95160CC6D351341B9"
1615 sle->setFieldU32(sfPreviousTxnLgrSeq, 91442944);
1626 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1627 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::NegativeUNL);
1643 auto const usd = gw[
"USD"];
1644 env.
fund(
XRP(10000), alice, gw);
1647 env(
offer(alice, usd(321),
XRP(322)));
1656 jvParams[jss::offer][jss::account] = alice.
human();
1657 jvParams[jss::offer][jss::seq] = env.
seq(alice) - 1;
1660 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1661 BEAST_EXPECT(jrr[jss::node][jss::TakerGets] ==
"322000000");
1662 offerIndex = jrr[jss::index].
asString();
1667 jvParams[jss::offer] = offerIndex;
1669 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1670 BEAST_EXPECT(jrr[jss::node][jss::TakerGets] ==
"322000000");
1678 {{.fieldName = jss::account, .malformedErrorMsg =
"malformedAddress"},
1679 {.fieldName = jss::seq, .malformedErrorMsg =
"malformedRequest"}});
1702 jv[jss::TransactionType] = jss::PaymentChannelCreate;
1703 jv[jss::Account] = account.human();
1704 jv[jss::Destination] = to.human();
1706 jv[sfSettleDelay.jsonName] = settleDelay.count();
1707 jv[sfPublicKey.jsonName] =
strHex(pk.slice());
1711 env(payChanCreate(alice, env.
master,
XRP(57), 18s, alice.
pk()));
1721 jvParams[jss::payment_channel] =
to_string(payChanIndex);
1724 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1725 BEAST_EXPECT(jrr[jss::node][sfAmount.jsonName] ==
"57000000");
1726 BEAST_EXPECT(jrr[jss::node][sfBalance.jsonName] ==
"0");
1727 BEAST_EXPECT(jrr[jss::node][sfSettleDelay.jsonName] == 18);
1735 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1753 auto const usd = gw[
"USD"];
1754 env.
fund(
XRP(10000), alice, gw);
1757 env.
trust(usd(999), alice);
1760 env(
pay(gw, alice, usd(97)));
1764 for (
auto const& fieldName : {jss::ripple_state, jss::state})
1772 jvParams[fieldName][jss::accounts][0u] = alice.
human();
1773 jvParams[fieldName][jss::accounts][1u] = gw.
human();
1774 jvParams[fieldName][jss::currency] =
"USD";
1777 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1778 BEAST_EXPECT(jrr[jss::node][sfBalance.jsonName][jss::value] ==
"-97");
1779 BEAST_EXPECT(jrr[jss::node][sfHighLimit.jsonName][jss::value] ==
"999");
1787 {.fieldName = jss::accounts, .malformedErrorMsg =
"malformedRequest"},
1788 {.fieldName = jss::currency, .malformedErrorMsg =
"malformedCurrency"},
1796 jvParams[fieldName][jss::accounts][0u] = alice.
human();
1797 jvParams[fieldName][jss::currency] =
"USD";
1800 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1804 "Invalid field 'accounts', not length-2 array of "
1812 jvParams[fieldName][jss::accounts][0u] = alice.
human();
1813 jvParams[fieldName][jss::accounts][1u] = gw.
human();
1814 jvParams[fieldName][jss::accounts][2u] = alice.
human();
1815 jvParams[fieldName][jss::currency] =
"USD";
1818 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1822 "Invalid field 'accounts', not length-2 array of "
1829 auto tryField = [&](
json::Value badAccount) ->
void {
1833 jvParams[fieldName][jss::accounts][0u] = badAccount;
1834 jvParams[fieldName][jss::accounts][1u] = gw.
human();
1835 jvParams[fieldName][jss::currency] =
"USD";
1838 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1848 jvParams[fieldName][jss::accounts][0u] = alice.
human();
1849 jvParams[fieldName][jss::accounts][1u] = badAccount;
1850 jvParams[fieldName][jss::currency] =
"USD";
1853 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1862 for (
auto const& value : badValues)
1873 jvParams[fieldName][jss::accounts][0u] = alice.
human();
1874 jvParams[fieldName][jss::accounts][1u] = alice.
human();
1875 jvParams[fieldName][jss::currency] =
"USD";
1878 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1879 checkErrorValue(jrr,
"malformedRequest",
"Cannot have a trustline to self.");
1903 env.
fund(
XRP(10000), alice, bob);
1913 jvParams[jss::sponsorship][jss::sponsor] = alice.
human();
1914 jvParams[jss::sponsorship][jss::sponsee] = bob.
human();
1916 auto const jrr = env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1917 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::Sponsorship);
1918 BEAST_EXPECT(jrr[jss::node][sfOwner.jsonName] == alice.
human());
1919 BEAST_EXPECT(jrr[jss::node][sfSponsee.jsonName] == bob.
human());
1920 BEAST_EXPECT(sponsorshipIndex == jrr[jss::node][jss::index].asString());
1925 jvParams[jss::sponsorship] = sponsorshipIndex;
1928 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1929 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::Sponsorship);
1930 BEAST_EXPECT(jrr[jss::node][sfOwner.jsonName] == alice.
human());
1931 BEAST_EXPECT(jrr[jss::node][sfSponsee.jsonName] == bob.
human());
1932 BEAST_EXPECT(sponsorshipIndex == jrr[jss::node][jss::index].asString());
1940 {.fieldName = jss::sponsor, .malformedErrorMsg =
"malformedSponsor"},
1941 {.fieldName = jss::sponsee, .malformedErrorMsg =
"malformedSponsee"},
1969 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1979 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
1980 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::Ticket);
1981 BEAST_EXPECT(jrr[jss::node][sfTicketSequence.jsonName] == tkt1.
value());
1988 jvParams[jss::ticket][jss::account] = env.
master.
human();
1989 jvParams[jss::ticket][jss::ticket_seq] = tkt1.
value();
1992 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
2001 jvParams[jss::ticket][jss::account] = env.
master.
human();
2002 jvParams[jss::ticket][jss::ticket_seq] = tkt1.
value();
2005 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
2014 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
2015 checkErrorValue(jrr,
"unexpectedLedgerType",
"Unexpected ledger type.");
2024 {.fieldName = jss::account, .malformedErrorMsg =
"malformedAddress"},
2025 {.fieldName = jss::ticket_seq, .malformedErrorMsg =
"malformedRequest"},
2045 jv[jss::TransactionType] = jss::DIDSet;
2046 jv[jss::Account] = account.human();
2052 env(didCreate(alice));
2060 jvParams[jss::did] = alice.
human();
2063 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
2064 BEAST_EXPECT(jrr[jss::node][sfDIDDocument.jsonName] ==
strHex(
std::string{
"data"}));
2073 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
2087 testcase(
"Invalid Oracle Ledger Entry");
2095 env, {.owner = owner, .fee =
static_cast<int>(env.
current()->fees().base.drops())});
2103 {.fieldName = jss::account, .malformedErrorMsg =
"malformedAccount"},
2104 {.fieldName = jss::oracle_document_id,
2105 .malformedErrorMsg =
"malformedDocumentID"},
2118 auto const baseFee =
static_cast<int>(env.
current()->fees().base.drops());
2121 for (
int i = 0; i < 10; ++i)
2126 Oracle const oracle(env, {.owner = owner, .documentID = i, .fee = baseFee});
2130 Oracle const oracle1(env, {.owner = owner, .documentID = i + 10, .fee = baseFee});
2132 oracles.
push_back(oracle1.documentID());
2134 for (
int i = 0; i < accounts.
size(); ++i)
2136 auto const jv = [&]() {
2145 BEAST_EXPECT(jv[jss::node][jss::Owner] ==
to_string(accounts[i]));
2164 MPTTester mptAlice(env, alice, {.holders = {bob}});
2169 .flags = tfMPTCanLock | tfMPTRequireAuth | tfMPTCanEscrow | tfMPTCanTrade |
2170 tfMPTCanTransfer | tfMPTCanClawback});
2171 mptAlice.authorize({.account = bob, .holderCount = 1});
2175 std::string const badMptID =
"00000193B9DDCAF401B5B3B26875986043F82CD0D13B4315";
2179 jvParams[jss::mpt_issuance] =
strHex(mptAlice.issuanceID());
2182 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
2183 BEAST_EXPECT(jrr[jss::node][sfMPTokenMetadata.jsonName] ==
strHex(
std::string{
"123"}));
2184 BEAST_EXPECT(jrr[jss::node][jss::mpt_issuance_id] ==
strHex(mptAlice.issuanceID()));
2189 jvParams[jss::mpt_issuance] = badMptID;
2192 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
2199 jvParams[jss::mptoken][jss::account] = bob.
human();
2200 jvParams[jss::mptoken][jss::mpt_issuance_id] =
strHex(mptAlice.issuanceID());
2203 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
2205 jrr[jss::node][sfMPTokenIssuanceID.jsonName] ==
strHex(mptAlice.issuanceID()));
2211 jvParams[jss::mptoken][jss::account] = bob.
human();
2212 jvParams[jss::mptoken][jss::mpt_issuance_id] = badMptID;
2215 env.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
2234 Account const issuer{
"issuer"};
2238 env.
fund(
XRP(5000), issuer, alice, bob);
2241 auto const seq = env.
seq(alice);
2242 env(
pdomain::setTx(alice, {{.issuer = alice, .credType =
"first credential"}}));
2245 if (!BEAST_EXPECT(objects.size() == 1))
2251 params[jss::ledger_index] = jss::validated;
2252 params[jss::permissioned_domain][jss::account] = alice.
human();
2253 params[jss::permissioned_domain][jss::seq] = seq;
2254 auto jv = env.
rpc(
"json",
"ledger_entry",
to_string(params));
2257 !jv[jss::result].
isMember(jss::error) && jv[jss::result].
isMember(jss::node) &&
2258 jv[jss::result][jss::node].
isMember(sfLedgerEntryType.jsonName) &&
2259 jv[jss::result][jss::node][sfLedgerEntryType.jsonName] == jss::PermissionedDomain);
2266 params[jss::ledger_index] = jss::validated;
2267 params[jss::permissioned_domain] = pdIdx;
2268 jv = env.
rpc(
"json",
"ledger_entry",
to_string(params));
2271 !jv[jss::result].
isMember(jss::error) && jv[jss::result].
isMember(jss::node) &&
2272 jv[jss::result][jss::node].
isMember(sfLedgerEntryType.jsonName) &&
2273 jv[jss::result][jss::node][sfLedgerEntryType.jsonName] == jss::PermissionedDomain);
2279 params[jss::ledger_index] = jss::validated;
2280 params[jss::permissioned_domain] =
2281 "12F1F1F1F180D67377B2FAB292A31C922470326268D2B9B74CD1E582645B9A"
2283 auto const jrr = env.
rpc(
"json",
"ledger_entry",
to_string(params));
2284 checkErrorValue(jrr[jss::result],
"entryNotFound",
"Entry not found.");
2290 jss::permissioned_domain,
2292 {.fieldName = jss::account, .malformedErrorMsg =
"malformedAddress"},
2293 {.fieldName = jss::seq, .malformedErrorMsg =
"malformedRequest"},
2327 auto checkResult = [&](
bool good,
2334 jv.isObject() && jv.isMember(jss::result) &&
2335 !jv[jss::result].isMember(jss::error) &&
2336 jv[jss::result].isMember(jss::node) &&
2337 jv[jss::result][jss::node].isMember(sfLedgerEntryType.jsonName) &&
2338 jv[jss::result][jss::node][sfLedgerEntryType.jsonName] == expectedType,
2344 jv.isObject() && jv.isMember(jss::result) &&
2345 jv[jss::result].isMember(jss::error) &&
2346 !jv[jss::result].isMember(jss::node) &&
2347 jv[jss::result][jss::error] == expectedError.value_or(
"entryNotFound"),
2365 Keylet const& expectedKey,
2367 testcase << expectedType.cStr() << (good ?
"" :
" not") <<
" found";
2369 auto const hexKey =
strHex(expectedKey.key);
2375 params[jss::ledger_index] = jss::validated;
2377 auto const jv = env.
rpc(
"json",
"ledger_entry",
to_string(params));
2378 checkResult(
false, jv, expectedType,
"malformedRequest");
2379 BEAST_EXPECT(!jv[jss::result].isMember(jss::index));
2385 params[jss::ledger_index] = jss::validated;
2386 params[field] =
"arbitrary string";
2387 auto const jv = env.
rpc(
"json",
"ledger_entry",
to_string(params));
2388 checkResult(
false, jv, expectedType,
"malformedRequest");
2389 BEAST_EXPECT(!jv[jss::result].isMember(jss::index));
2395 params[jss::ledger_index] = jss::validated;
2396 params[field] =
false;
2397 auto const jv = env.
rpc(
"json",
"ledger_entry",
to_string(params));
2398 checkResult(
false, jv, expectedType,
"invalidParams");
2399 BEAST_EXPECT(!jv[jss::result].isMember(jss::index));
2407 params[jss::ledger_index] = jss::validated;
2408 params[field] = badKey;
2409 auto const jv = env.
rpc(
"json",
"ledger_entry",
to_string(params));
2410 checkResult(
false, jv, expectedType,
"entryNotFound");
2411 BEAST_EXPECTS(jv[jss::result][jss::index] == badKey,
to_string(jv));
2417 params[jss::ledger_index] = jss::validated;
2418 params[jss::index] = field;
2419 params[jss::api_version] = 2;
2420 auto const jv = env.
rpc(
"json",
"ledger_entry",
to_string(params));
2421 checkResult(
false, jv, expectedType,
"malformedRequest");
2422 BEAST_EXPECT(!jv[jss::result].isMember(jss::index));
2430 params[jss::ledger_index] = jss::validated;
2431 params[field] =
true;
2432 auto const jv = env.
rpc(
"json",
"ledger_entry",
to_string(params));
2434 std::string const pdIdx = jv[jss::result][jss::index].asString();
2435 BEAST_EXPECTS(hexKey == pdIdx,
to_string(jv));
2436 checkResult(good, jv, expectedType);
2445 params[jss::ledger_index] = jss::validated;
2446 params[field] = hexKey;
2447 auto const jv = env.
rpc(
"json",
"ledger_entry",
to_string(params));
2448 checkResult(good, jv, expectedType);
2449 BEAST_EXPECT(jv[jss::result][jss::index].asString() == hexKey);
2456 params[jss::ledger_index] = jss::validated;
2457 params[jss::index] = field;
2458 params[jss::api_version] = 2;
2459 auto const jv = env.
rpc(
"json",
"ledger_entry",
to_string(params));
2460 checkResult(
false, jv, expectedType,
"malformedRequest");
2461 BEAST_EXPECT(!jv[jss::result].isMember(jss::index));
2467 params[jss::ledger_index] = jss::validated;
2468 params[jss::index] = field;
2469 params[jss::api_version] = 3;
2470 auto const jv = env.
rpc(
"json",
"ledger_entry",
to_string(params));
2472 BEAST_EXPECT(jv[jss::result][jss::index].asString() == hexKey);
2473 checkResult(good, jv, expectedType);
2479 params[jss::ledger_index] = jss::validated;
2480 params[jss::index] = pdIdx;
2481 auto const jv = env.
rpc(
"json",
"ledger_entry",
to_string(params));
2483 BEAST_EXPECT(jv[jss::result][jss::index].asString() == hexKey);
2484 checkResult(good, jv, expectedType);
2522 auto checkResult = [&](
bool good,
2529 jv.isObject() && jv.isMember(jss::result) &&
2530 !jv[jss::result].isMember(jss::error) &&
2531 jv[jss::result].isMember(jss::node) &&
2532 jv[jss::result][jss::node].isMember(sfLedgerEntryType.jsonName) &&
2533 jv[jss::result][jss::node][sfLedgerEntryType.jsonName] == jss::LedgerHashes,
2536 jv[jss::result].isMember(jss::node) &&
2537 jv[jss::result][jss::node].isMember(
"Hashes") &&
2538 jv[jss::result][jss::node][
"Hashes"].
size() == expectedCount,
2544 jv.isObject() && jv.isMember(jss::result) &&
2545 jv[jss::result].isMember(jss::error) &&
2546 !jv[jss::result].isMember(jss::node) &&
2547 jv[jss::result][jss::error] == expectedError.value_or(
"entryNotFound"),
2564 [&](
json::Value ledger,
Keylet const& expectedKey,
bool good,
int expectedCount = 0) {
2566 <<
" \"hashes\":" <<
to_string(ledger) << (good ?
"" :
" not") <<
" found";
2568 auto const hexKey =
strHex(expectedKey.key);
2574 params[jss::ledger_index] = jss::validated;
2576 auto jv = env.
rpc(
"json",
"ledger_entry",
to_string(params));
2577 checkResult(
false, jv, 0,
"malformedRequest");
2578 BEAST_EXPECT(!jv[jss::result].isMember(jss::index));
2584 params[jss::ledger_index] = jss::validated;
2585 params[jss::hashes] =
"arbitrary string";
2586 auto const jv = env.
rpc(
"json",
"ledger_entry",
to_string(params));
2587 checkResult(
false, jv, 0,
"malformedRequest");
2588 BEAST_EXPECT(!jv[jss::result].isMember(jss::index));
2594 params[jss::ledger_index] = jss::validated;
2595 params[jss::hashes] =
"10";
2596 auto const jv = env.
rpc(
"json",
"ledger_entry",
to_string(params));
2597 checkResult(
false, jv, 0,
"malformedRequest");
2598 BEAST_EXPECT(!jv[jss::result].isMember(jss::index));
2604 params[jss::ledger_index] = jss::validated;
2605 params[jss::hashes] =
false;
2606 auto const jv = env.
rpc(
"json",
"ledger_entry",
to_string(params));
2607 checkResult(
false, jv, 0,
"invalidParams");
2608 BEAST_EXPECT(!jv[jss::result].isMember(jss::index));
2614 params[jss::ledger_index] = jss::validated;
2615 params[jss::hashes] = -1;
2616 auto const jv = env.
rpc(
"json",
"ledger_entry",
to_string(params));
2617 checkResult(
false, jv, 0,
"internal");
2618 BEAST_EXPECT(!jv[jss::result].isMember(jss::index));
2625 params[jss::ledger_index] = jss::validated;
2626 params[jss::hashes] = badKey;
2627 auto const jv = env.
rpc(
"json",
"ledger_entry",
to_string(params));
2628 checkResult(
false, jv, 0,
"entryNotFound");
2629 BEAST_EXPECT(jv[jss::result][jss::index] == badKey);
2636 params[jss::ledger_index] = jss::validated;
2637 params[jss::hashes] = ledger;
2638 auto const jv = env.
rpc(
"json",
"ledger_entry",
to_string(params));
2639 checkResult(good, jv, expectedCount);
2641 std::string const pdIdx = jv[jss::result][jss::index].asString();
2642 BEAST_EXPECTS(hexKey == pdIdx,
strHex(pdIdx));
2648 params[jss::ledger_index] = jss::validated;
2649 params[jss::hashes] = hexKey;
2650 auto const jv = env.
rpc(
"json",
"ledger_entry",
to_string(params));
2651 checkResult(good, jv, expectedCount);
2654 hexKey == jv[jss::result][jss::index].asString(),
2655 strHex(jv[jss::result][jss::index].asString()));
2661 params[jss::ledger_index] = jss::validated;
2662 params[jss::index] = hexKey;
2663 auto const jv = env.
rpc(
"json",
"ledger_entry",
to_string(params));
2664 checkResult(good, jv, expectedCount);
2667 hexKey == jv[jss::result][jss::index].asString(),
2668 strHex(jv[jss::result][jss::index].asString()));
2680 for (
auto i = env.
current()->seq(); i <= 250; ++i)
2691 for (
auto i = env.
current()->seq(); i <= 260; ++i)
2720 BEAST_EXPECT(jrr[jss::node][sfLedgerEntryType.jsonName] == jss::Check);
2721 BEAST_EXPECT(jrr[jss::node][sfSendMax.jsonName] ==
"100000000");
2767 if (BEAST_EXPECT(jv.
isMember(jss::status)))
2768 BEAST_EXPECT(jv[jss::status] ==
"error");
2769 if (BEAST_EXPECT(jv.
isMember(jss::error)))
2770 BEAST_EXPECT(jv[jss::error] == err);
2776 else if (BEAST_EXPECT(jv.
isMember(jss::error_message)))
2778 BEAST_EXPECT(jv[jss::error_message] == msg);
2799 jvParams[jss::bridge_account] =
mcDoor.human();
2800 jvParams[jss::bridge] =
jvb;
2802 mcEnv.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
2804 BEAST_EXPECT(jrr.
isMember(jss::node));
2805 auto r = jrr[jss::node];
2807 BEAST_EXPECT(r.isMember(jss::Account));
2808 BEAST_EXPECT(r[jss::Account] ==
mcDoor.human());
2810 BEAST_EXPECT(r.isMember(jss::Flags));
2812 BEAST_EXPECT(r.isMember(sfLedgerEntryType.jsonName));
2813 BEAST_EXPECT(r[sfLedgerEntryType.jsonName] == jss::Bridge);
2816 BEAST_EXPECT(r.isMember(sfXChainAccountCreateCount.jsonName));
2817 BEAST_EXPECT(r[sfXChainAccountCreateCount.jsonName].asInt() == 0);
2820 BEAST_EXPECT(r.isMember(sfXChainAccountClaimCount.jsonName));
2821 BEAST_EXPECT(r[sfXChainAccountClaimCount.jsonName].asInt() == 0);
2823 BEAST_EXPECT(r.isMember(jss::index));
2824 bridgeIndex = r[jss::index].asString();
2830 jvParams[jss::index] = bridgeIndex;
2832 mcEnv.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
2834 BEAST_EXPECT(jrr.
isMember(jss::node));
2835 BEAST_EXPECT(jrr[jss::node] == mcBridge);
2842 jvParams[jss::bridge] =
jvb;
2845 mcEnv.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
2859 jvParams[jss::bridge_account] =
mcDoor.human();
2860 jvParams[jss::bridge] =
jvb;
2862 mcEnv.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
2864 BEAST_EXPECT(jrr.
isMember(jss::node));
2865 auto r = jrr[jss::node];
2868 BEAST_EXPECT(r.isMember(sfXChainClaimID.jsonName));
2869 BEAST_EXPECT(r[sfXChainClaimID.jsonName].asInt() == 2);
2876 testcase(
"ledger_entry: xchain_claim_id");
2893 jvParams[jss::xchain_owned_claim_id][jss::xchain_owned_claim_id] = 1;
2895 scEnv.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
2897 BEAST_EXPECT(jrr.
isMember(jss::node));
2898 auto r = jrr[jss::node];
2900 BEAST_EXPECT(r.isMember(jss::Account));
2901 BEAST_EXPECT(r[jss::Account] ==
scAlice.human());
2902 BEAST_EXPECT(r[sfLedgerEntryType.jsonName] == jss::XChainOwnedClaimID);
2903 BEAST_EXPECT(r[sfXChainClaimID.jsonName].asInt() == 1);
2904 BEAST_EXPECT(r[sfOwnerNode.jsonName].asInt() == 0);
2911 jvParams[jss::xchain_owned_claim_id][jss::xchain_owned_claim_id] = 2;
2913 scEnv.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
2915 BEAST_EXPECT(jrr.
isMember(jss::node));
2916 auto r = jrr[jss::node];
2918 BEAST_EXPECT(r.isMember(jss::Account));
2919 BEAST_EXPECT(r[jss::Account] ==
scBob.human());
2920 BEAST_EXPECT(r[sfLedgerEntryType.jsonName] == jss::XChainOwnedClaimID);
2921 BEAST_EXPECT(r[sfXChainClaimID.jsonName].asInt() == 2);
2922 BEAST_EXPECT(r[sfOwnerNode.jsonName].asInt() == 0);
2929 testcase(
"ledger_entry: xchain_create_account_claim_id");
2940 auto const amt =
XRP(1000);
2946 static constexpr size_t kNumAttest = 3;
2959 for (
size_t i = 0; i < kNumAttest; ++i)
2968 jvParams[jss::xchain_owned_create_account_claim_id] =
jvXRPBridgeRPC;
2969 jvParams[jss::xchain_owned_create_account_claim_id]
2970 [jss::xchain_owned_create_account_claim_id] = 1;
2972 scEnv.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
2974 BEAST_EXPECT(jrr.
isMember(jss::node));
2975 auto r = jrr[jss::node];
2977 BEAST_EXPECT(r.isMember(jss::Account));
2980 BEAST_EXPECT(r.isMember(sfXChainAccountCreateCount.jsonName));
2981 BEAST_EXPECT(r[sfXChainAccountCreateCount.jsonName].asInt() == 1);
2983 BEAST_EXPECT(r.isMember(sfXChainCreateAccountAttestations.jsonName));
2984 auto attest = r[sfXChainCreateAccountAttestations.jsonName];
2985 BEAST_EXPECT(attest.isArray());
2986 BEAST_EXPECT(attest.size() == 3);
2990 for (
auto& attestation : a)
2992 attestation = attest[
json::Value::UInt(0)][sfXChainCreateAccountProofSig.jsonName];
2994 attestation.isMember(jss::Amount) &&
2995 attestation[jss::Amount].asInt() == 1000 *
kDropPerXrp);
2997 attestation.isMember(jss::Destination) &&
2998 attestation[jss::Destination] ==
scCarol.human());
3000 attestation.isMember(sfAttestationSignerAccount.jsonName) &&
3002 return attestation[sfAttestationSignerAccount.jsonName] ==
3006 attestation.isMember(sfAttestationRewardAccount.jsonName) &&
3008 return attestation[sfAttestationRewardAccount.jsonName] == account.human();
3011 attestation.isMember(sfWasLockingChainSend.jsonName) &&
3012 attestation[sfWasLockingChainSend.jsonName] == 1);
3014 attestation.isMember(sfSignatureReward.jsonName) &&
3015 attestation[sfSignatureReward.jsonName].asInt() == 1 *
kDropPerXrp);
3029 jvParams[jss::xchain_owned_create_account_claim_id] =
jvXRPBridgeRPC;
3030 jvParams[jss::xchain_owned_create_account_claim_id]
3031 [jss::xchain_owned_create_account_claim_id] = 1;
3033 scEnv.
rpc(
"json",
"ledger_entry",
to_string(jvParams))[jss::result];
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(modify_type 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
static Account const kMaster
The master account that holds all XRP in genesis.
void testCreateAccountClaimID()
void run() override
Runs the suite.
void checkErrorValue(json::Value const &jv, std::string const &err, std::string const &msg)
void runLedgerEntryTest(test::jtx::Env &env, json::StaticString const &parentField, std::source_location const location=std::source_location::current())
void testOracleLedgerEntry()
void testMalformedField(test::jtx::Env &env, json::Value correctRequest, json::StaticString const fieldName, FieldType const typeID, std::string const &expectedError, bool required=true, std::source_location const location=std::source_location::current())
void checkErrorValue(json::Value const &jv, std::string const &err, std::string const &msg, std::source_location const location=std::source_location::current())
void run() override
Runs the suite.
static std::vector< json::Value > getBadValues(FieldType fieldType)
void testDepositPreauth()
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::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{})
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 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.
API version numbers used in later API versions.
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)
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.
json::Value sidechainXchainAccountCreate(Account const &acc, json::Value const &bridge, Account const &dst, AnyAmount const &amt, AnyAmount const &reward)
XrpT const XRP
Converts to XRP Issue or STAmount.
require_t required(Args const &... args)
Compose many condition functors into one.
FeatureBitset testableAmendments()
constexpr std::size_t kUtXchainDefaultNumSigners
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 xchainCreateClaimId(Account const &acc, json::Value const &bridge, STAmount const &reward, Account const &otherChainSource)
JValueVec createAccountAttestations(jtx::Account const &submittingAccount, json::Value const &jvBridge, jtx::Account const &sendingAccount, jtx::AnyAmount const &sendingAmount, jtx::AnyAmount const &rewardAmount, std::vector< jtx::Account > const &rewardAccounts, bool wasLockingChainSend, std::uint64_t createCount, jtx::Account const &dst, std::vector< jtx::Signer > const &signers, std::size_t const numAtts, std::size_t const fromIdx)
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)
static uint256 ledgerHash(LedgerHeader const &info)
std::vector< std::pair< json::StaticString, FieldType > > gMappings
std::string getTypeName(FieldType typeID)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
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
A signer in a SignerList.
void createBridgeObjects(Env &mcEnv, Env &scEnv)
std::vector< Account > const payee
FeatureBitset const features
std::vector< Signer > const signers
static constexpr int kDropPerXrp
json::Value const jvXRPBridgeRPC