2#include <test/jtx/Oracle.h>
3#include <test/jtx/attester.h>
4#include <test/jtx/delegate.h>
5#include <test/jtx/multisign.h>
6#include <test/jtx/xchain_bridge.h>
8#include <xrpl/beast/unit_test.h>
9#include <xrpl/json/json_value.h>
10#include <xrpl/protocol/AccountID.h>
11#include <xrpl/protocol/ErrorCodes.h>
12#include <xrpl/protocol/STXChainBridge.h>
13#include <xrpl/protocol/jss.h>
15#if (defined(__clang_major__) && __clang_major__ < 15)
16#include <experimental/source_location>
19#include <source_location>
59 return pair.first == fieldName;
67 Throw<std::runtime_error>(
92 return "hex string or object";
94 return "length-2 array of Accounts";
96 Throw<std::runtime_error>(
110 if (BEAST_EXPECT(jv.
isMember(jss::status)))
113 if (BEAST_EXPECT(jv.
isMember(jss::error)))
115 jv[jss::error] == err,
116 "Expected error " + err +
", received " +
117 jv[jss::error].asString() +
", at line " +
124 jv[jss::error_message] ==
"",
125 "Expected no error message, received \"" +
126 jv[jss::error_message].asString() +
"\", at line " +
130 else if (BEAST_EXPECT(jv.
isMember(jss::error_message)))
132 jv[jss::error_message] == msg,
133 "Expected error message \"" + msg +
"\", received \"" +
134 jv[jss::error_message].asString() +
"\", at line " +
144 obj[jss::account] =
"rhigTLJJyXXSRUyRCQtqi1NoAZZzZnS4KU";
145 obj[jss::ledger_index] =
"validated";
150 arr[0u] =
"rhigTLJJyXXSRUyRCQtqi1NoAZZzZnS4KU";
151 arr[1u] =
"validated";
165 "0123456789ABCDEFGH",
166 "rJxKV9e9p6wiPw!!!!xrJ4X1n98LosPL1sgcJW",
167 "rPSTrR5yEr11uMkfsz1kHCp9jK4aoa3Avv",
168 "n9K2isxwTxcSHJKxMkJznDoWXAUs7NNy49H9Fknz1pC7oHAH3kH9",
171 "5233D68B4D44388F98559DE42903767803EFA7C1F8D01413FC16EE6B01403D"
182 indices.begin(), indices.end());
187 if (indexSet.
find(i) == indexSet.
end())
195 static auto const& badUInt32Values = remove({2, 3});
196 static auto const& badUInt64Values = remove({2, 3});
197 static auto const& badHashValues = remove({2, 3, 7, 8, 16});
198 static auto const& badAccountValues = remove({12});
199 static auto const& badBlobValues = remove({3, 7, 8, 16});
200 static auto const& badCurrencyValues = remove({14});
201 static auto const& badArrayValues = remove({17, 20});
202 static auto const& badIndexValues = remove({12, 16, 18, 19});
207 return badUInt32Values;
209 return badUInt64Values;
211 return badHashValues;
213 return badAccountValues;
215 return badBlobValues;
217 return badCurrencyValues;
220 return badArrayValues;
222 return badIndexValues;
224 Throw<std::runtime_error>(
235 arr[0u] =
"rhigTLJJyXXSRUyRCQtqi1NoAZZzZnS4KU";
236 arr[1u] =
"r4MrUGTdB57duTnRs6KbsRGQXgkseGb1b5";
248 return "5233D68B4D44388F98559DE42903767803EFA7C1F8D01413FC16EE6"
251 return "r4MrUGTdB57duTnRs6KbsRGQXgkseGb1b5";
259 return "5233D68B4D44388F98559DE42903767803EFA7C1F8D01413FC16EE6"
262 return twoAccountArray;
264 Throw<std::runtime_error>(
295 "No ledger_entry params provided.",
298 auto tryField = [&](
Json::Value fieldValue) ->
void {
299 correctRequest[fieldName] = fieldValue;
305 auto const expectedErrMsg =
311 for (
auto const& value : badValues)
336 correctRequest[parentFieldName].
removeMember(fieldName);
360 auto tryField = [&](
Json::Value fieldValue) ->
void {
361 correctRequest[parentFieldName][fieldName] = fieldValue;
376 for (
auto const& value : badValues)
425 for (
auto const& subfield : subfields)
427 correctOutput[parentField][subfield.fieldName] =
431 for (
auto const& subfield : subfields)
433 auto const fieldType =
getFieldType(subfield.fieldName);
440 subfield.malformedErrorMsg,
450 using namespace test::jtx;
458 jvParams[jss::account_root] = alice.human();
459 jvParams[jss::ledger_hash] =
460 "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
462 auto const jrr = env.
rpc(
463 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
469 jvParams[jss::account_root] = alice.human();
473 auto tryField = [&](
Json::Value fieldValue) ->
void {
474 jvParams[jss::ledger_hash] = fieldValue;
480 auto const expectedErrMsg = fieldValue.
isString()
481 ?
"ledgerHashMalformed"
482 :
"ledgerHashNotString";
487 for (
auto const& value : badValues)
497 jvParams[jss::ledger_index] =
"validated";
498 jvParams[jss::index] =
499 "00000000000000000000000000000000000000000000000000000000000000"
501 auto const jrr = env.
rpc(
502 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
510 jvParams[jss::features] =
511 "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
513 jvParams[jss::api_version] = apiVersion;
515 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
523 "No ledger_entry params provided.");
532 using namespace test::jtx;
535 cfg->FEES.reference_fee = 10;
536 Env env{*
this, std::move(cfg)};
546 BEAST_EXPECT(jrr[jss::ledger_hash] ==
ledgerHash);
547 BEAST_EXPECT(jrr[jss::ledger_index] == 3);
554 jvParams[jss::account_root] = alice.human();
557 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
558 BEAST_EXPECT(jrr.
isMember(jss::node));
559 BEAST_EXPECT(jrr[jss::node][jss::Account] == alice.human());
560 BEAST_EXPECT(jrr[jss::node][sfBalance.jsonName] ==
"10000000000");
561 accountRootIndex = jrr[jss::index].
asString();
564 constexpr char alicesAcctRootBinary[]{
565 "1100612200800000240000000425000000032D00000000559CE54C3B934E4"
566 "73A995B477E92EC229F99CED5B62BF4D2ACE4DC42719103AE2F6240000002"
567 "540BE4008114AE123A8556F3CF91154711376AFB0F894F832B3D"};
571 jvParams[jss::account_root] = alice.human();
572 jvParams[jss::binary] = 1;
575 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
576 BEAST_EXPECT(jrr.
isMember(jss::node_binary));
577 BEAST_EXPECT(jrr[jss::node_binary] == alicesAcctRootBinary);
582 jvParams[jss::index] = accountRootIndex;
584 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
585 BEAST_EXPECT(!jrr.
isMember(jss::node_binary));
586 BEAST_EXPECT(jrr.
isMember(jss::node));
587 BEAST_EXPECT(jrr[jss::node][jss::Account] == alice.human());
588 BEAST_EXPECT(jrr[jss::node][sfBalance.jsonName] ==
"10000000000");
593 jvParams[jss::index] = accountRootIndex;
594 jvParams[jss::binary] = 0;
596 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
597 BEAST_EXPECT(jrr.
isMember(jss::node));
598 BEAST_EXPECT(jrr[jss::node][jss::Account] == alice.human());
599 BEAST_EXPECT(jrr[jss::node][sfBalance.jsonName] ==
"10000000000");
604 jvParams[jss::account] = alice.human();
607 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
608 BEAST_EXPECT(jrr.
isMember(jss::node));
609 BEAST_EXPECT(jrr[jss::node][jss::Account] == alice.human());
610 BEAST_EXPECT(jrr[jss::node][sfBalance.jsonName] ==
"10000000000");
611 accountRootIndex = jrr[jss::index].
asString();
629 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
638 using namespace test::jtx;
653 jvParams[jss::check] =
to_string(checkId.key);
656 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
658 jrr[jss::node][sfLedgerEntryType.jsonName] == jss::Check);
659 BEAST_EXPECT(jrr[jss::node][sfSendMax.jsonName] ==
"100000000");
667 jvParams[jss::account_root] = alice.human();
669 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
670 accountRootIndex = jrr[jss::index].
asString();
673 jvParams[jss::check] = accountRootIndex;
676 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
678 jrr,
"unexpectedLedgerType",
"Unexpected ledger type.");
691 using namespace test::jtx;
694 Account const issuer{
"issuer"};
697 char const credType[] =
"abcde";
699 env.
fund(
XRP(5000), issuer, alice, bob);
711 !jv[jss::result].
isMember(jss::error) &&
712 jv[jss::result].
isMember(jss::node) &&
713 jv[jss::result][jss::node].
isMember(
714 sfLedgerEntryType.jsonName) &&
715 jv[jss::result][jss::node][sfLedgerEntryType.jsonName] ==
723 !jv[jss::result].
isMember(jss::error) &&
724 jv[jss::result].
isMember(jss::node) &&
725 jv[jss::result][jss::node].
isMember(
726 sfLedgerEntryType.jsonName) &&
727 jv[jss::result][jss::node][sfLedgerEntryType.jsonName] ==
735 "48004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6EA288B"
738 jv[jss::result],
"entryNotFound",
"Entry not found.");
747 {jss::subject,
"malformedRequest"},
748 {jss::issuer,
"malformedRequest"},
749 {jss::credential_type,
"malformedRequest"},
759 using namespace test::jtx;
764 env.
fund(
XRP(10000), alice, bob);
773 jvParams[jss::delegate][jss::account] = alice.human();
774 jvParams[jss::delegate][jss::authorize] = bob.human();
777 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
779 jrr[jss::node][sfLedgerEntryType.jsonName] == jss::Delegate);
780 BEAST_EXPECT(jrr[jss::node][sfAccount.jsonName] == alice.human());
781 BEAST_EXPECT(jrr[jss::node][sfAuthorize.jsonName] == bob.human());
782 delegateIndex = jrr[jss::node][jss::index].
asString();
787 jvParams[jss::delegate] = delegateIndex;
790 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
792 jrr[jss::node][sfLedgerEntryType.jsonName] == jss::Delegate);
793 BEAST_EXPECT(jrr[jss::node][sfAccount.jsonName] == alice.human());
794 BEAST_EXPECT(jrr[jss::node][sfAuthorize.jsonName] == bob.human());
803 {jss::account,
"malformedAddress"},
804 {jss::authorize,
"malformedAddress"},
814 using namespace test::jtx;
820 env.
fund(
XRP(10000), alice, becky);
831 jvParams[jss::deposit_preauth][jss::owner] = alice.human();
832 jvParams[jss::deposit_preauth][jss::authorized] = becky.human();
835 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
838 jrr[jss::node][sfLedgerEntryType.jsonName] ==
839 jss::DepositPreauth);
840 BEAST_EXPECT(jrr[jss::node][sfAccount.jsonName] == alice.human());
841 BEAST_EXPECT(jrr[jss::node][sfAuthorize.jsonName] == becky.human());
842 depositPreauthIndex = jrr[jss::node][jss::index].
asString();
847 jvParams[jss::deposit_preauth] = depositPreauthIndex;
850 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
853 jrr[jss::node][sfLedgerEntryType.jsonName] ==
854 jss::DepositPreauth);
855 BEAST_EXPECT(jrr[jss::node][sfAccount.jsonName] == alice.human());
856 BEAST_EXPECT(jrr[jss::node][sfAuthorize.jsonName] == becky.human());
862 jss::deposit_preauth,
864 {jss::owner,
"malformedOwner"},
865 {jss::authorized,
"malformedAuthorized",
false},
873 testcase(
"Deposit Preauth with credentials");
875 using namespace test::jtx;
878 Account const issuer{
"issuer"};
881 char const credType[] =
"abcde";
883 env.
fund(
XRP(5000), issuer, alice, bob);
897 jvParams[jss::ledger_index] = jss::validated;
898 jvParams[jss::deposit_preauth][jss::owner] = bob.human();
900 jvParams[jss::deposit_preauth][jss::authorized_credentials] =
903 jvParams[jss::deposit_preauth][jss::authorized_credentials]);
906 jo[jss::issuer] = issuer.human();
908 arr.append(std::move(jo));
913 jrr.isObject() && jrr.isMember(jss::result) &&
914 !jrr[jss::result].isMember(jss::error) &&
915 jrr[jss::result].isMember(jss::node) &&
916 jrr[jss::result][jss::node].isMember(
917 sfLedgerEntryType.jsonName) &&
918 jrr[jss::result][jss::node][sfLedgerEntryType.jsonName] ==
919 jss::DepositPreauth);
925 jvParams[jss::ledger_index] = jss::validated;
926 jvParams[jss::deposit_preauth][jss::owner] = bob.human();
928 auto tryField = [&](
Json::Value fieldValue) ->
void {
931 jo[jss::issuer] = fieldValue;
934 jvParams[jss::deposit_preauth][jss::authorized_credentials] =
938 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
939 auto const expectedErrMsg = fieldValue.
isNull()
943 jrr,
"malformedAuthorizedCredentials", expectedErrMsg);
947 for (
auto const& value : badValues)
957 jvParams[jss::ledger_index] = jss::validated;
958 jvParams[jss::deposit_preauth][jss::owner] = bob.human();
960 jvParams[jss::deposit_preauth][jss::authorized_credentials] =
963 jvParams[jss::deposit_preauth][jss::authorized_credentials]);
966 jo[jss::issuer] = issuer.human();
969 arr.append(std::move(jo));
974 "malformedAuthorizedCredentials",
976 jss::authorized_credentials,
"array"));
982 jvParams[jss::ledger_index] = jss::validated;
983 jvParams[jss::deposit_preauth][jss::owner] = bob.human();
985 auto tryField = [&](
Json::Value fieldValue) ->
void {
988 jo[jss::issuer] = issuer.human();
989 jo[jss::credential_type] = fieldValue;
991 jvParams[jss::deposit_preauth][jss::authorized_credentials] =
995 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
996 auto const expectedErrMsg = fieldValue.
isNull()
999 jss::credential_type,
"hex string");
1001 jrr,
"malformedAuthorizedCredentials", expectedErrMsg);
1005 for (
auto const& value : badValues)
1015 jvParams[jss::ledger_index] = jss::validated;
1016 jvParams[jss::deposit_preauth][jss::owner] = bob.human();
1017 jvParams[jss::deposit_preauth][jss::authorized] = alice.human();
1019 jvParams[jss::deposit_preauth][jss::authorized_credentials] =
1022 jvParams[jss::deposit_preauth][jss::authorized_credentials]);
1025 jo[jss::issuer] = issuer.human();
1027 arr.append(std::move(jo));
1034 "Must have exactly one of `authorized` and "
1035 "`authorized_credentials`.");
1041 jvParams[jss::ledger_index] = jss::validated;
1042 jvParams[jss::deposit_preauth][jss::owner] = bob.human();
1046 jss::deposit_preauth,
1047 jss::authorized_credentials,
1049 "malformedAuthorizedCredentials",
1056 jvParams[jss::ledger_index] = jss::validated;
1057 jvParams[jss::deposit_preauth][jss::owner] = bob.human();
1058 jvParams[jss::deposit_preauth][jss::authorized_credentials] =
1061 jvParams[jss::deposit_preauth][jss::authorized_credentials]);
1062 arr.append(
"foobar");
1068 "malformedAuthorizedCredentials",
1069 "Invalid field 'authorized_credentials', not array.");
1075 jvParams[jss::ledger_index] = jss::validated;
1076 jvParams[jss::deposit_preauth][jss::owner] = bob.human();
1077 jvParams[jss::deposit_preauth][jss::authorized_credentials] =
1080 jvParams[jss::deposit_preauth][jss::authorized_credentials]);
1083 arr.
append(std::move(payload));
1089 "malformedAuthorizedCredentials",
1090 "Invalid field 'authorized_credentials', not array.");
1096 jvParams[jss::ledger_index] = jss::validated;
1097 jvParams[jss::deposit_preauth][jss::owner] = bob.human();
1098 jvParams[jss::deposit_preauth][jss::authorized_credentials] =
1105 "malformedAuthorizedCredentials",
1106 "Invalid field 'authorized_credentials', array empty.");
1122 sizeof(credTypes) /
sizeof(credTypes[0]) >
1126 jvParams[jss::ledger_index] = jss::validated;
1127 jvParams[jss::deposit_preauth][jss::owner] = bob.human();
1128 jvParams[jss::deposit_preauth][jss::authorized_credentials] =
1132 jvParams[jss::deposit_preauth][jss::authorized_credentials]);
1134 for (
auto cred : credTypes)
1137 jo[jss::issuer] = issuer.human();
1139 arr.append(std::move(jo));
1146 "malformedAuthorizedCredentials",
1147 "Invalid field 'authorized_credentials', array too long.");
1155 using namespace test::jtx;
1159 auto const USD = gw[
"USD"];
1160 env.
fund(
XRP(10000), alice, gw);
1163 env.
trust(USD(1000), alice);
1168 for (
int d = 1'000'032; d >= 1'000'000; --d)
1178 BEAST_EXPECT(jrr[jss::ledger_hash] ==
ledgerHash);
1179 BEAST_EXPECT(jrr[jss::ledger_index] == 5);
1183 "A33EC6BB85FB5674074C4A3A43373BB17645308F3EAE1933E3E35252162B217D";
1187 jvParams[jss::directory] = dirRootIndex;
1190 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
1191 BEAST_EXPECT(jrr[jss::node][sfIndexes.jsonName].
size() == 32);
1197 jvParams[jss::directory][jss::dir_root] = dirRootIndex;
1199 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
1200 BEAST_EXPECT(jrr[jss::index] == dirRootIndex);
1206 jvParams[jss::directory][jss::owner] = alice.human();
1209 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
1210 BEAST_EXPECT(jrr[jss::index] == dirRootIndex);
1216 jvParams[jss::directory][jss::dir_root] = dirRootIndex;
1217 jvParams[jss::directory][jss::sub_index] = 1;
1219 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
1220 BEAST_EXPECT(jrr[jss::index] != dirRootIndex);
1221 BEAST_EXPECT(jrr[jss::node][sfIndexes.jsonName].
size() == 2);
1227 jvParams[jss::directory][jss::owner] = alice.human();
1228 jvParams[jss::directory][jss::sub_index] = 1;
1231 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
1232 BEAST_EXPECT(jrr[jss::index] != dirRootIndex);
1233 BEAST_EXPECT(jrr[jss::node][sfIndexes.jsonName].
size() == 2);
1244 "malformedRequest");
1250 jvParams[jss::directory][jss::dir_root] = dirRootIndex;
1280 jvParams[jss::directory][jss::owner] = alice.human();
1281 jvParams[jss::directory][jss::dir_root] = dirRootIndex;
1284 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
1288 "Must have exactly one of `owner` and `dir_root` fields.");
1294 jvParams[jss::directory][jss::sub_index] = 1;
1297 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
1301 "Must have exactly one of `owner` and `dir_root` fields.");
1309 using namespace test::jtx;
1321 jv[jss::TransactionType] = jss::EscrowCreate;
1322 jv[jss::Account] = account.human();
1323 jv[jss::Destination] = to.human();
1325 jv[sfFinishAfter.jsonName] =
1326 cancelAfter.time_since_epoch().count() + 2;
1330 using namespace std::chrono_literals;
1331 env(escrowCreate(alice, alice,
XRP(333), env.
now() + 2s));
1340 jvParams[jss::escrow][jss::owner] = alice.human();
1341 jvParams[jss::escrow][jss::seq] = env.
seq(alice) - 1;
1343 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
1345 jrr[jss::node][jss::Amount] ==
XRP(333).value().getText());
1346 escrowIndex = jrr[jss::index].
asString();
1351 jvParams[jss::escrow] = escrowIndex;
1354 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
1356 jrr[jss::node][jss::Amount] ==
XRP(333).value().getText());
1363 {{jss::owner,
"malformedOwner"}, {jss::seq,
"malformedSeq"}});
1371 using namespace test::jtx;
1375 auto const USD = gw[
"USD"];
1376 env.
fund(
XRP(10000), alice, gw);
1379 env(
offer(alice, USD(321),
XRP(322)));
1388 jvParams[jss::offer][jss::account] = alice.human();
1389 jvParams[jss::offer][jss::seq] = env.
seq(alice) - 1;
1392 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
1393 BEAST_EXPECT(jrr[jss::node][jss::TakerGets] ==
"322000000");
1394 offerIndex = jrr[jss::index].
asString();
1399 jvParams[jss::offer] = offerIndex;
1401 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
1402 BEAST_EXPECT(jrr[jss::node][jss::TakerGets] ==
"322000000");
1410 {{jss::account,
"malformedAddress"},
1411 {jss::seq,
"malformedRequest"}});
1419 using namespace test::jtx;
1434 jv[jss::TransactionType] = jss::PaymentChannelCreate;
1435 jv[jss::Account] = account.human();
1436 jv[jss::Destination] = to.human();
1438 jv[sfSettleDelay.jsonName] = settleDelay.count();
1439 jv[sfPublicKey.jsonName] =
strHex(pk.slice());
1443 env(payChanCreate(alice, env.
master,
XRP(57), 18s, alice.pk()));
1453 jvParams[jss::payment_channel] =
to_string(payChanIndex);
1456 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
1457 BEAST_EXPECT(jrr[jss::node][sfAmount.jsonName] ==
"57000000");
1458 BEAST_EXPECT(jrr[jss::node][sfBalance.jsonName] ==
"0");
1459 BEAST_EXPECT(jrr[jss::node][sfSettleDelay.jsonName] == 18);
1467 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
1481 using namespace test::jtx;
1485 auto const USD = gw[
"USD"];
1486 env.
fund(
XRP(10000), alice, gw);
1489 env.
trust(USD(999), alice);
1492 env(
pay(gw, alice, USD(97)));
1496 for (
auto const& fieldName : {jss::ripple_state, jss::state})
1504 jvParams[fieldName][jss::accounts][0u] = alice.human();
1505 jvParams[fieldName][jss::accounts][1u] = gw.human();
1506 jvParams[fieldName][jss::currency] =
"USD";
1509 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
1511 jrr[jss::node][sfBalance.jsonName][jss::value] ==
"-97");
1513 jrr[jss::node][sfHighLimit.jsonName][jss::value] ==
"999");
1521 {jss::accounts,
"malformedRequest"},
1522 {jss::currency,
"malformedCurrency"},
1530 jvParams[fieldName][jss::accounts][0u] = alice.human();
1531 jvParams[fieldName][jss::currency] =
"USD";
1534 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
1538 "Invalid field 'accounts', not length-2 array of "
1546 jvParams[fieldName][jss::accounts][0u] = alice.human();
1547 jvParams[fieldName][jss::accounts][1u] = gw.human();
1548 jvParams[fieldName][jss::accounts][2u] = alice.human();
1549 jvParams[fieldName][jss::currency] =
"USD";
1552 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
1556 "Invalid field 'accounts', not length-2 array of "
1563 auto tryField = [&](
Json::Value badAccount) ->
void {
1567 jvParams[fieldName][jss::accounts][0u] = badAccount;
1568 jvParams[fieldName][jss::accounts][1u] = gw.human();
1569 jvParams[fieldName][jss::currency] =
"USD";
1579 jss::accounts,
"array of Accounts"));
1585 jvParams[fieldName][jss::accounts][0u] = alice.human();
1586 jvParams[fieldName][jss::accounts][1u] = badAccount;
1587 jvParams[fieldName][jss::currency] =
"USD";
1597 jss::accounts,
"array of Accounts"));
1602 for (
auto const& value : badValues)
1613 jvParams[fieldName][jss::accounts][0u] = alice.human();
1614 jvParams[fieldName][jss::accounts][1u] = alice.human();
1615 jvParams[fieldName][jss::currency] =
"USD";
1618 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
1622 "Cannot have a trustline to self.");
1631 using namespace test::jtx;
1647 jvParams[jss::ticket] =
1651 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
1660 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
1662 jrr[jss::node][sfLedgerEntryType.jsonName] == jss::Ticket);
1663 BEAST_EXPECT(jrr[jss::node][sfTicketSequence.jsonName] == tkt1);
1669 jvParams[jss::ticket][jss::account] = env.
master.
human();
1670 jvParams[jss::ticket][jss::ticket_seq] = tkt1 + 1;
1673 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
1675 jrr[jss::node][jss::index] ==
1682 jvParams[jss::ticket][jss::account] = env.
master.
human();
1683 jvParams[jss::ticket][jss::ticket_seq] = tkt1 + 2;
1686 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
1695 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
1697 jrr,
"unexpectedLedgerType",
"Unexpected ledger type.");
1706 {jss::account,
"malformedAddress"},
1707 {jss::ticket_seq,
"malformedRequest"},
1716 using namespace test::jtx;
1727 jv[jss::TransactionType] = jss::DIDSet;
1728 jv[jss::Account] = account.human();
1734 env(didCreate(alice));
1742 jvParams[jss::did] = alice.human();
1745 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
1747 jrr[jss::node][sfDIDDocument.jsonName] ==
1758 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
1769 "malformedAddress");
1776 testcase(
"Invalid Oracle Ledger Entry");
1786 .fee =
static_cast<int>(env.
current()->fees().base.drops())});
1794 {jss::account,
"malformedAccount"},
1795 {jss::oracle_document_id,
"malformedDocumentID"},
1808 auto const baseFee =
1809 static_cast<int>(env.
current()->fees().base.drops());
1812 for (
int i = 0; i < 10; ++i)
1818 env, {.owner = owner, .documentID = i, .fee = baseFee});
1823 env, {.owner = owner, .documentID = i + 10, .fee = baseFee});
1825 oracles.
push_back(oracle1.documentID());
1827 for (
int i = 0; i < accounts.
size(); ++i)
1829 auto const jv = [&]() {
1832 return Oracle::ledgerEntry(env, accounts[i], oracles[i]);
1834 return Oracle::ledgerEntry(
1840 jv[jss::node][jss::Owner] ==
to_string(accounts[i]));
1853 using namespace test::jtx;
1859 MPTTester mptAlice(env, alice, {.holders = {bob}});
1866 mptAlice.authorize({.account = bob, .holderCount = 1});
1871 "00000193B9DDCAF401B5B3B26875986043F82CD0D13B4315";
1875 jvParams[jss::mpt_issuance] =
strHex(mptAlice.issuanceID());
1878 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
1880 jrr[jss::node][sfMPTokenMetadata.jsonName] ==
1883 jrr[jss::node][jss::mpt_issuance_id] ==
1884 strHex(mptAlice.issuanceID()));
1889 jvParams[jss::mpt_issuance] = badMptID;
1892 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
1899 jvParams[jss::mptoken][jss::account] = bob.
human();
1900 jvParams[jss::mptoken][jss::mpt_issuance_id] =
1901 strHex(mptAlice.issuanceID());
1904 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
1906 jrr[jss::node][sfMPTokenIssuanceID.jsonName] ==
1907 strHex(mptAlice.issuanceID()));
1913 jvParams[jss::mptoken][jss::account] = bob.
human();
1914 jvParams[jss::mptoken][jss::mpt_issuance_id] = badMptID;
1917 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
1928 "malformedRequest");
1937 using namespace test::jtx;
1940 Account const issuer{
"issuer"};
1944 env.
fund(
XRP(5000), issuer, alice, bob);
1947 auto const seq = env.
seq(alice);
1951 if (!BEAST_EXPECT(objects.size() == 1))
1957 params[jss::ledger_index] = jss::validated;
1958 params[jss::permissioned_domain][jss::account] = alice.human();
1959 params[jss::permissioned_domain][jss::seq] =
seq;
1960 auto jv = env.
rpc(
"json",
"ledger_entry",
to_string(params));
1963 !jv[jss::result].
isMember(jss::error) &&
1964 jv[jss::result].
isMember(jss::node) &&
1965 jv[jss::result][jss::node].
isMember(
1966 sfLedgerEntryType.jsonName) &&
1967 jv[jss::result][jss::node][sfLedgerEntryType.jsonName] ==
1968 jss::PermissionedDomain);
1975 params[jss::ledger_index] = jss::validated;
1976 params[jss::permissioned_domain] = pdIdx;
1977 jv = env.
rpc(
"json",
"ledger_entry",
to_string(params));
1980 !jv[jss::result].
isMember(jss::error) &&
1981 jv[jss::result].
isMember(jss::node) &&
1982 jv[jss::result][jss::node].
isMember(
1983 sfLedgerEntryType.jsonName) &&
1984 jv[jss::result][jss::node][sfLedgerEntryType.jsonName] ==
1985 jss::PermissionedDomain);
1991 params[jss::ledger_index] = jss::validated;
1992 params[jss::permissioned_domain] =
1993 "12F1F1F1F180D67377B2FAB292A31C922470326268D2B9B74CD1E582645B9A"
1995 auto const jrr = env.
rpc(
"json",
"ledger_entry",
to_string(params));
1997 jrr[jss::result],
"entryNotFound",
"Entry not found.");
2003 jss::permissioned_domain,
2005 {jss::account,
"malformedAddress"},
2006 {jss::seq,
"malformedRequest"},
2015 using namespace test::jtx;
2031 env.
rpc(
"ledger_entry",
to_string(checkId.key))[jss::result];
2033 jrr[jss::node][sfLedgerEntryType.jsonName] == jss::Check);
2034 BEAST_EXPECT(jrr[jss::node][sfSendMax.jsonName] ==
"100000000");
2073 if (BEAST_EXPECT(jv.
isMember(jss::status)))
2074 BEAST_EXPECT(jv[jss::status] ==
"error");
2075 if (BEAST_EXPECT(jv.
isMember(jss::error)))
2076 BEAST_EXPECT(jv[jss::error] == err);
2081 jv[jss::error_message] ==
"");
2083 else if (BEAST_EXPECT(jv.
isMember(jss::error_message)))
2084 BEAST_EXPECT(jv[jss::error_message] == msg);
2091 using namespace test::jtx;
2105 jvParams[jss::bridge] =
jvb;
2107 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
2109 BEAST_EXPECT(jrr.
isMember(jss::node));
2110 auto r = jrr[jss::node];
2112 BEAST_EXPECT(r.isMember(jss::Account));
2115 BEAST_EXPECT(r.isMember(jss::Flags));
2117 BEAST_EXPECT(r.isMember(sfLedgerEntryType.jsonName));
2118 BEAST_EXPECT(r[sfLedgerEntryType.jsonName] == jss::Bridge);
2121 BEAST_EXPECT(r.isMember(sfXChainAccountCreateCount.jsonName));
2122 BEAST_EXPECT(r[sfXChainAccountCreateCount.jsonName].asInt() == 0);
2125 BEAST_EXPECT(r.isMember(sfXChainAccountClaimCount.jsonName));
2126 BEAST_EXPECT(r[sfXChainAccountClaimCount.jsonName].asInt() == 0);
2128 BEAST_EXPECT(r.isMember(jss::index));
2129 bridge_index = r[jss::index].asString();
2135 jvParams[jss::index] = bridge_index;
2137 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
2139 BEAST_EXPECT(jrr.
isMember(jss::node));
2140 BEAST_EXPECT(jrr[jss::node] == mcBridge);
2147 jvParams[jss::bridge] =
jvb;
2150 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
2165 jvParams[jss::bridge] =
jvb;
2167 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
2169 BEAST_EXPECT(jrr.
isMember(jss::node));
2170 auto r = jrr[jss::node];
2173 BEAST_EXPECT(r.isMember(sfXChainClaimID.jsonName));
2174 BEAST_EXPECT(r[sfXChainClaimID.jsonName].asInt() == 2);
2181 testcase(
"ledger_entry: xchain_claim_id");
2182 using namespace test::jtx;
2199 jvParams[jss::xchain_owned_claim_id][jss::xchain_owned_claim_id] =
2202 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
2204 BEAST_EXPECT(jrr.
isMember(jss::node));
2205 auto r = jrr[jss::node];
2207 BEAST_EXPECT(r.isMember(jss::Account));
2210 r[sfLedgerEntryType.jsonName] == jss::XChainOwnedClaimID);
2211 BEAST_EXPECT(r[sfXChainClaimID.jsonName].asInt() == 1);
2212 BEAST_EXPECT(r[sfOwnerNode.jsonName].asInt() == 0);
2219 jvParams[jss::xchain_owned_claim_id][jss::xchain_owned_claim_id] =
2222 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
2224 BEAST_EXPECT(jrr.
isMember(jss::node));
2225 auto r = jrr[jss::node];
2227 BEAST_EXPECT(r.isMember(jss::Account));
2228 BEAST_EXPECT(r[jss::Account] ==
scBob.
human());
2230 r[sfLedgerEntryType.jsonName] == jss::XChainOwnedClaimID);
2231 BEAST_EXPECT(r[sfXChainClaimID.jsonName].asInt() == 2);
2232 BEAST_EXPECT(r[sfOwnerNode.jsonName].asInt() == 0);
2239 testcase(
"ledger_entry: xchain_create_account_claim_id");
2240 using namespace test::jtx;
2251 auto const amt =
XRP(1000);
2258 size_t constexpr num_attest = 3;
2271 for (
size_t i = 0; i < num_attest; ++i)
2273 scEnv(attestations[i]);
2280 jvParams[jss::xchain_owned_create_account_claim_id] =
2282 jvParams[jss::xchain_owned_create_account_claim_id]
2283 [jss::xchain_owned_create_account_claim_id] = 1;
2285 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
2287 BEAST_EXPECT(jrr.
isMember(jss::node));
2288 auto r = jrr[jss::node];
2290 BEAST_EXPECT(r.isMember(jss::Account));
2293 BEAST_EXPECT(r.isMember(sfXChainAccountCreateCount.jsonName));
2294 BEAST_EXPECT(r[sfXChainAccountCreateCount.jsonName].asInt() == 1);
2297 r.isMember(sfXChainCreateAccountAttestations.jsonName));
2298 auto attest = r[sfXChainCreateAccountAttestations.jsonName];
2299 BEAST_EXPECT(attest.isArray());
2300 BEAST_EXPECT(attest.size() == 3);
2302 sfXChainCreateAccountProofSig.jsonName));
2304 for (
size_t i = 0; i < num_attest; ++i)
2307 [sfXChainCreateAccountProofSig.jsonName];
2309 a[i].isMember(jss::Amount) &&
2312 a[i].isMember(jss::Destination) &&
2315 a[i].isMember(sfAttestationSignerAccount.jsonName) &&
2318 return a[i][sfAttestationSignerAccount.jsonName] ==
2322 a[i].isMember(sfAttestationRewardAccount.jsonName) &&
2327 return a[i][sfAttestationRewardAccount.jsonName] ==
2331 a[i].isMember(sfWasLockingChainSend.jsonName) &&
2332 a[i][sfWasLockingChainSend.jsonName] == 1);
2334 a[i].isMember(sfSignatureReward.jsonName) &&
2335 a[i][sfSignatureReward.jsonName].
asInt() ==
2344 scEnv(attestations[i]);
2350 jvParams[jss::xchain_owned_create_account_claim_id] =
2352 jvParams[jss::xchain_owned_create_account_claim_id]
2353 [jss::xchain_owned_create_account_claim_id] = 1;
2355 "json",
"ledger_entry",
to_string(jvParams))[jss::result];
Lightweight wrapper to tag static string.
constexpr char const * c_str() 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 toStyledString() const
void clear()
Remove all object members and array elements.
Value removeMember(char const *key)
Remove and return the named member.
std::string asString() const
Returns the unquoted string value.
bool isNull() const
isNull() tests to see if this field is null.
bool isMember(char const *key) const
Return true if the object has a member named key.
testcase_t testcase
Memberspace for declaring test cases.
void fail(String const &reason, char const *file, int line)
Record a failure.
void testLedgerEntryCreateAccountClaimID()
void testLedgerEntryBridge()
void testLedgerEntryClaimID()
void checkErrorValue(Json::Value const &jv, std::string const &err, std::string const &msg)
void run() override
Runs the suite.
void runLedgerEntryTest(test::jtx::Env &env, Json::StaticString const &parentField, source_location const location=source_location::current())
void testLedgerEntryDelegate()
void testInvalidOracleLedgerEntry()
void testLedgerEntryTicket()
void testLedgerEntryCheck()
void testLedgerEntryOffer()
void testLedgerEntryDepositPreauthCred()
void testLedgerEntryMPT()
std::vector< Json::Value > getBadValues(FieldType fieldType)
void testLedgerEntryDepositPreauth()
void testLedgerEntryPermissionedDomain()
void testOracleLedgerEntry()
void testMalformedSubfield(test::jtx::Env &env, Json::Value correctRequest, Json::StaticString parentFieldName, Json::StaticString fieldName, FieldType typeID, std::string const &expectedError, bool required=true, source_location const location=source_location::current())
void testLedgerEntryAccountRoot()
void testLedgerEntryDID()
void runLedgerEntryTest(test::jtx::Env &env, Json::StaticString const &parentField, std::vector< Subfield > const &subfields, source_location const location=source_location::current())
void testLedgerEntryRippleState()
void checkErrorValue(Json::Value const &jv, std::string const &err, std::string const &msg, source_location const location=source_location::current())
void testLedgerEntryDirectory()
void testLedgerEntryInvalid()
void testLedgerEntryCLI()
Json::Value getCorrectValue(Json::StaticString fieldName)
void run() override
Runs the suite.
void testLedgerEntryPayChan()
void testLedgerEntryEscrow()
void testMalformedField(test::jtx::Env &env, Json::Value correctRequest, Json::StaticString const fieldName, FieldType const typeID, std::string const &expectedError, bool required=true, source_location const location=source_location::current())
void testLedgerEntryCredentials()
Immutable cryptographic account descriptor.
AccountID id() const
Returns the Account ID.
static Account const master
The master account.
std::string const & human() const
Returns the human readable public key.
A transaction testing environment.
std::shared_ptr< ReadView const > closed()
Returns the last closed ledger.
std::uint32_t seq(Account const &account) const
Returns the next sequence number on account.
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
void trust(STAmount const &amount, Account const &account)
Establish trust lines.
NetClock::time_point now()
Returns the current network time.
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 fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
void create(MPTCreate const &arg=MPTCreate{})
Oracle class facilitates unit-testing of the Price Oracle feature.
Set the expected result code for a JTx The test will fail if the code doesn't match.
@ arrayValue
array value (ordered list)
@ objectValue
object value (collection of name/value pairs).
std::string missing_field_message(std::string const &name)
std::string expected_field_message(std::string const &name, std::string const &type)
Keylet permissionedDomain(AccountID const &account, std::uint32_t seq) noexcept
Keylet account(AccountID const &id) noexcept
AccountID root.
Keylet check(AccountID const &id, std::uint32_t seq) noexcept
A Check.
Keylet payChan(AccountID const &src, AccountID const &dst, std::uint32_t seq) noexcept
A PaymentChannel.
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 auth(Account const &account, Account const &auth)
Preauthorize for deposit.
Json::Value authCredentials(jtx::Account const &account, std::vector< AuthorizeCredentials > const &auth)
Json::Value setTx(AccountID const &account, Credentials const &credentials, std::optional< uint256 > domain)
std::map< uint256, Json::Value > getObjects(Account const &account, Env &env, bool withType)
Json::Value create(Account const &account, std::uint32_t count)
Create one of more tickets.
PrettyAmount drops(Integer i)
Returns an XRP PrettyAmount, which is trivially convertible to STAmount.
Json::Value fset(Account const &account, std::uint32_t on, std::uint32_t off=0)
Add and/or remove flag.
Json::Value sidechain_xchain_account_create(Account const &acc, Json::Value const &bridge, Account const &dst, AnyAmount const &amt, AnyAmount const &reward)
constexpr std::size_t UT_XCHAIN_DEFAULT_NUM_SIGNERS
Json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
JValueVec create_account_attestations(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)
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
require_t required(Args const &... args)
Compose many condition functors into one.
FeatureBitset testable_amendments()
Json::Value xchain_create_claim_id(Account const &acc, Json::Value const &bridge, STAmount const &reward, Account const &otherChainSource)
Json::Value offer(Account const &account, STAmount const &takerPays, STAmount const &takerGets, std::uint32_t flags)
Create an offer.
XRP_t const XRP
Converts to XRP Issue or STAmount.
static uint256 ledgerHash(LedgerInfo const &info)
std::vector< std::pair< Json::StaticString, FieldType > > mappings
FieldType getFieldType(Json::StaticString fieldName)
std::string getTypeName(FieldType typeID)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
constexpr std::uint32_t asfDepositAuth
constexpr std::uint32_t const tfMPTCanTransfer
constexpr std::uint32_t const tfMPTCanTrade
std::string strHex(FwdIt begin, FwdIt end)
std::size_t constexpr maxCredentialsArraySize
The maximum number of credentials can be passed in array.
void forAllApiVersions(Fn const &fn, Args &&... args)
uint256 getTicketIndex(AccountID const &account, std::uint32_t uSequence)
std::string to_string(base_uint< Bits, Tag > const &a)
constexpr std::uint32_t const tfMPTCanEscrow
constexpr std::uint32_t const tfMPTRequireAuth
constexpr std::uint32_t const tfMPTCanLock
constexpr std::uint32_t const tfMPTCanClawback
Json::StaticString fieldName
std::string malformedErrorMsg
std::vector< Account > const payee
static constexpr int drop_per_xrp
FeatureBitset const features
std::vector< signer > const signers
void createBridgeObjects(Env &mcEnv, Env &scEnv)
Json::Value const jvXRPBridgeRPC
Set the sequence number on a JTx.
A signer in a SignerList.