63 char const* command = jss::tx.cStr();
64 char const* binary = jss::binary.cStr();
69 Env env{*
this, features};
70 auto const alice =
Account(
"alice");
71 env.fund(XRP(1000), alice);
76 auto const startLegSeq = env.current()->header().seq;
77 for (
int i = 0; i < 750; ++i)
82 metas.
emplace_back(env.closed()->txRead(env.tx()->getTransactionID()).second);
84 auto const endLegSeq = env.closed()->header().seq;
87 for (
size_t i = 0; i < txns.
size(); ++i)
89 auto const& tx = txns[i];
90 auto const& meta = metas[i];
91 auto const result = env.rpc(
98 BEAST_EXPECT(result[jss::result][jss::status] == jss::success);
99 BEAST_EXPECT(result[jss::result][jss::tx] ==
strHex(tx->getSerializer().getData()));
100 BEAST_EXPECT(result[jss::result][jss::meta] ==
strHex(meta->getSerializer().getData()));
103 auto const tx = env.jt(noop(alice), Seq(env.seq(alice))).stx;
104 for (
int deltaEndSeq = 0; deltaEndSeq < 2; ++deltaEndSeq)
106 auto const result = env.rpc(
113 BEAST_EXPECT(result[jss::result][jss::status] == jss::error);
114 BEAST_EXPECT(result[jss::result][jss::error] == notFound);
115 BEAST_EXPECT(result[jss::result][jss::error_code] ==
RpcTxnNotFound);
116 BEAST_EXPECT(result[jss::result][jss::error_message] ==
"Transaction not found.");
118 if (deltaEndSeq != 0)
120 BEAST_EXPECT(!result[jss::result][jss::searched_all].asBool());
124 BEAST_EXPECT(result[jss::result][jss::searched_all].asBool());
129 for (
auto&& tx : txns)
131 auto const result = env.rpc(
138 BEAST_EXPECT(result[jss::result][jss::status] == jss::success);
139 BEAST_EXPECT(!result[jss::result][jss::searched_all].asBool());
142 auto const deletedLedger = (startLegSeq + endLegSeq) / 2;
145 env.app().getRelationalDatabase().deleteTransactionByLedgerSeq(deletedLedger);
148 for (
int deltaEndSeq = 0; deltaEndSeq < 2; ++deltaEndSeq)
150 auto const result = env.rpc(
157 BEAST_EXPECT(result[jss::result][jss::status] == jss::error);
158 BEAST_EXPECT(result[jss::result][jss::error] == notFound);
159 BEAST_EXPECT(result[jss::result][jss::error_code] ==
RpcTxnNotFound);
160 BEAST_EXPECT(result[jss::result][jss::error_message] ==
"Transaction not found.");
161 BEAST_EXPECT(!result[jss::result][jss::searched_all].asBool());
167 auto const result = env.rpc(
173 BEAST_EXPECT(result[jss::result][jss::status] == jss::error);
174 BEAST_EXPECT(result[jss::result][jss::error] == notFound);
175 BEAST_EXPECT(result[jss::result][jss::error_code] ==
RpcTxnNotFound);
176 BEAST_EXPECT(result[jss::result][jss::error_message] ==
"Transaction not found.");
178 BEAST_EXPECT(!result[jss::result][jss::searched_all].asBool());
184 auto const result = env.rpc(
190 BEAST_EXPECT(result[jss::result][jss::status] == jss::error);
191 BEAST_EXPECT(result[jss::result][jss::error] == notFound);
192 BEAST_EXPECT(result[jss::result][jss::error_code] ==
RpcTxnNotFound);
193 BEAST_EXPECT(result[jss::result][jss::error_message] ==
"Transaction not found.");
195 BEAST_EXPECT(result[jss::result][jss::searched_all].asBool());
201 auto const result = env.rpc(
207 BEAST_EXPECT(result[jss::result][jss::status] == jss::success);
208 BEAST_EXPECT(!result[jss::result].isMember(jss::searched_all));
213 auto const result = env.rpc(
220 BEAST_EXPECT(result[jss::result][jss::status] == jss::error);
221 BEAST_EXPECT(result[jss::result][jss::error] == invalid);
223 BEAST_EXPECT(result[jss::result][jss::error_message] ==
"Ledger range is invalid.");
225 BEAST_EXPECT(!result[jss::result].isMember(jss::searched_all));
230 auto const result = env.rpc(
237 BEAST_EXPECT(result[jss::result][jss::status] == jss::error);
238 BEAST_EXPECT(result[jss::result][jss::error] == invalid);
240 BEAST_EXPECT(result[jss::result][jss::error_message] ==
"Ledger range is invalid.");
242 BEAST_EXPECT(!result[jss::result].isMember(jss::searched_all));
247 auto const result = env.rpc(
250 BEAST_EXPECT(result[jss::result][jss::status] == jss::error);
251 BEAST_EXPECT(result[jss::result][jss::error] == invalid);
253 BEAST_EXPECT(result[jss::result][jss::error_message] ==
"Ledger range is invalid.");
255 BEAST_EXPECT(!result[jss::result].isMember(jss::searched_all));
263 BEAST_EXPECT(result[jss::result][jss::status] == jss::error);
264 BEAST_EXPECT(result[jss::result][jss::error] == invalid);
266 BEAST_EXPECT(result[jss::result][jss::error_message] ==
"Ledger range is invalid.");
268 BEAST_EXPECT(!result[jss::result].isMember(jss::searched_all));
273 auto const result = env.rpc(command,
to_string(tx->getTransactionID()),
to_string(20));
280 BEAST_EXPECT(result[jss::result][jss::status] == jss::error);
282 BEAST_EXPECT(!result[jss::result].isMember(jss::searched_all));
287 auto const result = env.rpc(
294 BEAST_EXPECT(result[jss::result][jss::status] == jss::error);
295 BEAST_EXPECT(result[jss::result][jss::error] == excessive);
297 BEAST_EXPECT(result[jss::result][jss::error_message] ==
"Ledger range exceeds 1000.");
299 BEAST_EXPECT(!result[jss::result].isMember(jss::searched_all));
311 char const* command = jss::tx.cStr();
312 char const* binary = jss::binary.cStr();
318 uint32_t
const netID = env.app().getNetworkIDService().getNetworkID();
320 auto const alice =
Account(
"alice");
321 env.fund(XRP(1000), alice);
326 auto const startLegSeq = env.current()->header().seq;
327 for (
int i = 0; i < 750; ++i)
332 metas.
emplace_back(env.closed()->txRead(env.tx()->getTransactionID()).second);
334 auto const endLegSeq = env.closed()->header().seq;
337 for (
size_t i = 0; i < txns.
size(); ++i)
339 auto const& tx = txns[i];
340 auto const& meta = metas[i];
341 uint32_t
const txnIdx = meta->getFieldU32(sfTransactionIndex);
342 auto const result = env.rpc(
350 BEAST_EXPECT(result[jss::result][jss::status] == jss::success);
351 BEAST_EXPECT(result[jss::result][jss::tx] ==
strHex(tx->getSerializer().getData()));
352 BEAST_EXPECT(result[jss::result][jss::meta] ==
strHex(meta->getSerializer().getData()));
355 auto const tx = env.jt(noop(alice), Seq(env.seq(alice))).stx;
357 auto const ctid = *
rpc::encodeCTID(endLegSeq, tx->getSeqProxy().value(), netID);
358 for (
int deltaEndSeq = 0; deltaEndSeq < 2; ++deltaEndSeq)
360 auto const result = env.rpc(
363 BEAST_EXPECT(result[jss::result][jss::status] == jss::error);
364 BEAST_EXPECT(result[jss::result][jss::error] == notFound);
365 BEAST_EXPECT(result[jss::result][jss::error_code] ==
RpcTxnNotFound);
366 BEAST_EXPECT(result[jss::result][jss::error_message] ==
"Transaction not found.");
368 if (deltaEndSeq != 0)
370 BEAST_EXPECT(!result[jss::result][jss::searched_all].asBool());
374 BEAST_EXPECT(!result[jss::result][jss::searched_all].asBool());
379 for (
size_t i = 0; i < txns.
size(); ++i)
382 auto const& meta = metas[i];
383 uint32_t
const txnIdx = meta->getFieldU32(sfTransactionIndex);
384 auto const result = env.rpc(
392 BEAST_EXPECT(result[jss::result][jss::status] == jss::success);
393 BEAST_EXPECT(!result[jss::result][jss::searched_all].asBool());
396 auto const deletedLedger = (startLegSeq + endLegSeq) / 2;
399 env.app().getRelationalDatabase().deleteTransactionByLedgerSeq(deletedLedger);
402 for (
int deltaEndSeq = 0; deltaEndSeq < 2; ++deltaEndSeq)
404 auto const result = env.rpc(
407 BEAST_EXPECT(result[jss::result][jss::status] == jss::error);
408 BEAST_EXPECT(result[jss::result][jss::error] == notFound);
409 BEAST_EXPECT(result[jss::result][jss::error_code] ==
RpcTxnNotFound);
410 BEAST_EXPECT(result[jss::result][jss::error_message] ==
"Transaction not found.");
411 BEAST_EXPECT(!result[jss::result][jss::searched_all].asBool());
420 BEAST_EXPECT(result[jss::result][jss::status] == jss::error);
421 BEAST_EXPECT(result[jss::result][jss::error] == notFound);
422 BEAST_EXPECT(result[jss::result][jss::error_code] ==
RpcTxnNotFound);
423 BEAST_EXPECT(result[jss::result][jss::error_message] ==
"Transaction not found.");
425 BEAST_EXPECT(!result[jss::result][jss::searched_all].asBool());
434 BEAST_EXPECT(result[jss::result][jss::status] == jss::error);
435 BEAST_EXPECT(result[jss::result][jss::error] == notFound);
436 BEAST_EXPECT(result[jss::result][jss::error_code] ==
RpcTxnNotFound);
437 BEAST_EXPECT(result[jss::result][jss::error_message] ==
"Transaction not found.");
439 BEAST_EXPECT(!result[jss::result][jss::searched_all].asBool());
445 auto const& meta = metas[0];
446 uint32_t
const txnIdx = meta->getFieldU32(sfTransactionIndex);
447 auto const result = env.rpc(
454 BEAST_EXPECT(result[jss::result][jss::status] == jss::success);
455 BEAST_EXPECT(!result[jss::result].isMember(jss::searched_all));
460 auto const result = env.rpc(
463 BEAST_EXPECT(result[jss::result][jss::status] == jss::error);
464 BEAST_EXPECT(result[jss::result][jss::error] == invalid);
466 BEAST_EXPECT(result[jss::result][jss::error_message] ==
"Ledger range is invalid.");
468 BEAST_EXPECT(!result[jss::result].isMember(jss::searched_all));
476 BEAST_EXPECT(result[jss::result][jss::status] == jss::error);
477 BEAST_EXPECT(result[jss::result][jss::error] == invalid);
479 BEAST_EXPECT(result[jss::result][jss::error_message] ==
"Ledger range is invalid.");
481 BEAST_EXPECT(!result[jss::result].isMember(jss::searched_all));
488 BEAST_EXPECT(result[jss::result][jss::status] == jss::error);
489 BEAST_EXPECT(result[jss::result][jss::error] == invalid);
491 BEAST_EXPECT(result[jss::result][jss::error_message] ==
"Ledger range is invalid.");
493 BEAST_EXPECT(!result[jss::result].isMember(jss::searched_all));
498 auto const result = env.rpc(command, ctid, binary,
to_string(20));
500 BEAST_EXPECT(result[jss::result][jss::status] == jss::error);
501 BEAST_EXPECT(result[jss::result][jss::error] == invalid);
503 BEAST_EXPECT(result[jss::result][jss::error_message] ==
"Ledger range is invalid.");
505 BEAST_EXPECT(!result[jss::result].isMember(jss::searched_all));
510 auto const result = env.rpc(command, ctid,
to_string(20));
517 BEAST_EXPECT(result[jss::result][jss::status] == jss::error);
519 BEAST_EXPECT(!result[jss::result].isMember(jss::searched_all));
524 auto const result = env.rpc(
527 BEAST_EXPECT(result[jss::result][jss::status] == jss::error);
528 BEAST_EXPECT(result[jss::result][jss::error] == excessive);
530 BEAST_EXPECT(result[jss::result][jss::error_message] ==
"Ledger range exceeds 1000.");
532 BEAST_EXPECT(!result[jss::result].isMember(jss::searched_all));
627 for (uint32_t
const netID : {11111, 65535, 65536})
630 BEAST_EXPECT(netID == env.app().getNetworkIDService().getNetworkID());
632 auto const alice =
Account(
"alice");
633 auto const bob =
Account(
"bob");
635 auto const startLegSeq = env.current()->header().seq;
636 env.fund(XRP(10000), alice, bob);
637 env(pay(alice, bob, XRP(10)));
644 BEAST_EXPECT(ctid == std::nullopt);
649 jsonTx[jss::binary] =
false;
650 jsonTx[jss::ctid] = *ctid;
652 auto const jrr = env.rpc(
"json",
"tx",
to_string(jsonTx))[jss::result];
653 BEAST_EXPECT(jrr[jss::ctid] == ctid);
654 BEAST_EXPECT(jrr.isMember(jss::hash));
660 std::uint32_t const netID = env.app().getNetworkIDService().getNetworkID();
665 std::uint32_t const startLegSeq = env.current()->header().seq;
666 env.fund(XRP(10000), alice, bob);
667 env(pay(alice, bob, XRP(10)));
672 auto const isUpper = [](
char c) {
return std::isupper(c) != 0; };
682 *iter = std::tolower(*iter);
684 BEAST_EXPECT(ctid != mixedCase);
687 jsonTx[jss::binary] =
false;
688 jsonTx[jss::ctid] = mixedCase;
691 BEAST_EXPECT(jrr[jss::ctid] == ctid);
692 BEAST_EXPECT(jrr[jss::hash]);
699 for (uint32_t
const netID : {2, 1024, 65535, 65536})
702 BEAST_EXPECT(netID == env.app().getNetworkIDService().getNetworkID());
704 auto const alice =
Account(
"alice");
705 auto const bob =
Account(
"bob");
707 env.fund(XRP(10000), alice, bob);
708 env(pay(alice, bob, XRP(10)));
711 auto const ledgerSeq = env.current()->header().seq;
719 params[jss::transaction] = hash;
720 auto const jrr = env.rpc(
"json",
"tx",
to_string(params))[jss::result];
721 BEAST_EXPECT(jrr[jss::hash] == hash);
723 BEAST_EXPECT(jrr.isMember(jss::ctid) == (netID <= 0xFFFF));
724 if (jrr.isMember(jss::ctid))
728 jrr[jss::ctid] == *ctid);
735 uint32_t
const netID = env.app().getNetworkIDService().getNetworkID();
737 auto const alice =
Account(
"alice");
738 auto const bob =
Account(
"bob");
740 auto const startLegSeq = env.current()->header().seq;
741 env.fund(XRP(10000), alice, bob);
742 env(pay(alice, bob, XRP(10)));
748 jsonTx[jss::binary] =
false;
749 jsonTx[jss::ctid] = ctid;
751 auto const jrr = env.rpc(
"json",
"tx",
to_string(jsonTx))[jss::result];
752 BEAST_EXPECT(jrr[jss::error] ==
"wrongNetwork");
755 jrr[jss::error_message] ==
756 "Wrong network. You should submit this request to a node "
757 "running on NetworkID: 21338");
770 cfg->fees.referenceFee = 10;
776 auto const usd{gw[
"USD"]};
778 env.fund(XRP(1000000), alice, gw);
785 env(pay(alice, gw, XRP(100)));
790 env.closed()->txRead(env.tx()->getTransactionID()).second;
793 expected[jss::DeliverMax] = expected[jss::Amount];
801 [&env, txn, apiVersion] {
803 params[jss::transaction] =
to_string(txn->getTransactionID());
804 params[jss::binary] =
false;
805 params[jss::api_version] = apiVersion;
806 return env.client().invoke(
"tx", params);
810 BEAST_EXPECT(result[jss::result][jss::status] == jss::success);
813 BEAST_EXPECT(result[jss::result][jss::close_time_iso] ==
"2000-01-01T00:00:20Z");
814 BEAST_EXPECT(result[jss::result][jss::hash] ==
to_string(txn->getTransactionID()));
815 BEAST_EXPECT(result[jss::result][jss::validated] ==
true);
816 BEAST_EXPECT(result[jss::result][jss::ledger_index] == 4);
818 result[jss::result][jss::ledger_hash] ==
819 "CBA44903F72735C7BC0803388C319299E7AF09DEE2CDD6E454512DC4382EB1ED");
822 for (
auto memberIt = expected.
begin(); memberIt != expected.
end(); memberIt++)
825 auto const& resultTransaction =
826 (apiVersion > 1 ? result[jss::result][jss::tx_json] : result[jss::result]);
827 if (BEAST_EXPECT(resultTransaction.isMember(name)))
829 auto const received = resultTransaction[name];
831 received == *memberIt,
832 "Transaction contains \n\"" + name +
"\": "
849 cfg->fees.referenceFee = 10;
854 auto const usd{gw[
"USD"]};
856 env.fund(XRP(1000000), alice, gw);
860 "3F8BDE5A5F82C4F4708E5E9255B713E303E6E1A371FD5C7A704AFD1387C23981");
863 env.closed()->txRead(txn->getTransactionID()).second;
868 json::Value const result = [&env, txn, apiVersion] {
870 params[jss::transaction] =
to_string(txn->getTransactionID());
871 params[jss::binary] =
true;
872 params[jss::api_version] = apiVersion;
873 return env.client().invoke(
"tx", params);
876 if (BEAST_EXPECT(result[jss::status] ==
"success"))
878 BEAST_EXPECT(result[jss::result][jss::status] ==
"success");
879 BEAST_EXPECT(result[jss::result][jss::validated] ==
true);
880 BEAST_EXPECT(result[jss::result][jss::hash] ==
to_string(txn->getTransactionID()));
881 BEAST_EXPECT(result[jss::result][jss::ledger_index] == 3);
882 BEAST_EXPECT(result[jss::result][jss::ctid] ==
"C000000300030000");
886 BEAST_EXPECT(result[jss::result][jss::tx_blob] == expectedTxBlob);
887 BEAST_EXPECT(result[jss::result][jss::meta_blob] == expectedMetaBlob);
889 result[jss::result][jss::ledger_hash] ==
890 "3DAA1AD2334EA6F69EEEB0454E52FC64CA9209E8EF86BE72CF1D54A2ABC6BA05");
891 BEAST_EXPECT(result[jss::result][jss::close_time_iso] ==
"2000-01-01T00:00:10Z");
895 BEAST_EXPECT(result[jss::result][jss::tx] == expectedTxBlob);
896 BEAST_EXPECT(result[jss::result][jss::meta] == expectedMetaBlob);
897 BEAST_EXPECT(result[jss::result][jss::date] == 10);
905 testcase(
"SignFor NetworkID validation");
909 Account const signer{
"signer"};
913 cfg->networkId = networkID;
918 auto const setupEnv = [&](Env& env) {
919 env.fund(XRP(10'000), owner, signer);
921 env(signers(owner, 1, {{signer, 1}}));
925 auto const makeTx = [&](Env& env) {
927 tx[jss::TransactionType] = jss::AccountSet;
928 tx[jss::Account] = owner.human();
929 tx[jss::Sequence] = env.seq(owner);
930 tx[jss::Fee] =
"100";
931 tx[jss::SigningPubKey] =
"";
935 auto const signFor = [&](Env& env,
json::Value const& tx) {
937 signReq[jss::tx_json] = tx;
938 signReq[jss::account] = signer.human();
939 signReq[jss::secret] = signer.name();
940 return env.rpc(
"json",
"sign_for",
to_string(signReq))[jss::result];
945 Env env{*
this, makeConfig(500)};
948 auto const tx = makeTx(env);
949 auto result = signFor(env, tx);
951 BEAST_EXPECT(result[jss::status] ==
"success");
952 BEAST_EXPECT(!result[jss::tx_json].isMember(jss::NetworkID));
957 Env env{*
this, makeConfig(2040)};
960 auto const tx = makeTx(env);
961 auto result = signFor(env, tx);
963 BEAST_EXPECT(result[jss::error] ==
"invalidParams");
965 BEAST_EXPECT(result[jss::error_message] ==
"Missing field 'tx_json.NetworkID'.");
970 Env env{*
this, makeConfig(2040)};
973 auto tx = makeTx(env);
974 tx[jss::NetworkID] =
"not_a_number";
975 auto result = signFor(env, tx);
977 BEAST_EXPECT(result[jss::error] ==
"invalidParams");
979 BEAST_EXPECT(result[jss::error_message] ==
"Invalid field 'tx_json.NetworkID'.");
984 Env env{*
this, makeConfig(2040)};
987 auto tx = makeTx(env);
988 tx[jss::NetworkID] = 2040.1;
989 auto result = signFor(env, tx);
991 BEAST_EXPECT(result[jss::error] ==
"invalidParams");
993 BEAST_EXPECT(result[jss::error_message] ==
"Invalid field 'tx_json.NetworkID'.");
999 Env env{*
this, makeConfig(2040)};
1002 auto tx = makeTx(env);
1003 tx[jss::NetworkID] = 9999;
1004 auto result = signFor(env, tx);
1006 BEAST_EXPECT(result[jss::error] ==
"invalidParams");
1008 BEAST_EXPECT(result[jss::error_message] ==
"Invalid field 'tx_json.NetworkID'.");
1013 Env env{*
this, makeConfig(2040)};
1016 auto tx = makeTx(env);
1017 tx[jss::NetworkID] = 2040;
1018 auto result = signFor(env, tx);
1020 BEAST_EXPECT(result[jss::status] ==
"success");
1021 BEAST_EXPECT(result[jss::tx_json][jss::NetworkID].asUInt() == 2040);