xrpld
Loading...
Searching...
No Matches
InvariantsPseudoAccount_test.cpp
1#include <test/app/invariants/InvariantsBase.h>
2#include <test/jtx/AMM.h>
3#include <test/jtx/Account.h>
4#include <test/jtx/Env.h>
5#include <test/jtx/TestHelpers.h>
6#include <test/jtx/amount.h>
7#include <test/jtx/fee.h>
8#include <test/jtx/mpt.h>
9#include <test/jtx/pay.h>
10#include <test/jtx/sig.h>
11#include <test/jtx/trust.h>
12#include <test/jtx/vault.h>
13#include <test/unit_test/SuiteJournal.h>
14
15#include <xrpl/basics/Number.h>
16#include <xrpl/basics/Slice.h>
17#include <xrpl/basics/base_uint.h>
18#include <xrpl/beast/unit_test/suite.h>
19#include <xrpl/beast/utility/Journal.h>
20#include <xrpl/ledger/ApplyView.h>
21#include <xrpl/ledger/OpenView.h>
22#include <xrpl/ledger/helpers/AccountRootHelpers.h>
23#include <xrpl/ledger/helpers/DirectoryHelpers.h>
24#include <xrpl/protocol/AccountID.h>
25#include <xrpl/protocol/Feature.h>
26#include <xrpl/protocol/Indexes.h>
27#include <xrpl/protocol/Issue.h>
28#include <xrpl/protocol/Keylet.h>
29#include <xrpl/protocol/LedgerFormats.h>
30#include <xrpl/protocol/Rules.h>
31#include <xrpl/protocol/SField.h>
32#include <xrpl/protocol/STLedgerEntry.h>
33#include <xrpl/protocol/STObject.h>
34#include <xrpl/protocol/STTx.h>
35#include <xrpl/protocol/SeqProxy.h>
36#include <xrpl/protocol/TER.h>
37#include <xrpl/protocol/TxFlags.h>
38#include <xrpl/protocol/TxFormats.h>
39#include <xrpl/protocol/XRPAmount.h>
40#include <xrpl/tx/ApplyContext.h>
41#include <xrpl/tx/Transactor.h>
42#include <xrpl/tx/applySteps.h>
43
44#include <array>
45#include <chrono>
46#include <cstdint>
47#include <functional>
48#include <initializer_list>
49#include <memory>
50#include <optional>
51#include <string>
52#include <utility>
53#include <vector>
54
55namespace xrpl::test {
56
58{
60
61 void
63 {
64 testcase << "valid pseudo accounts";
65
66 using namespace jtx;
67
68 AccountID pseudoAccountID;
69 Preclose const createPseudo = [&, this](Account const& a, Account const& b, Env& env) {
70 PrettyAsset const xrpAsset{xrpIssue(), 1'000'000};
71
72 // Create vault
73 Vault const vault{env};
74 auto [tx, vKeylet] = vault.create({.owner = a, .asset = xrpAsset});
75 env(tx);
76 env.close();
77 if (auto const vSle = env.le(vKeylet); BEAST_EXPECT(vSle))
78 {
79 pseudoAccountID = vSle->at(sfAccount);
80 }
81
82 return BEAST_EXPECT(env.le(keylet::account(pseudoAccountID)));
83 };
84
85 /* Cases to check
86 "pseudo-account has 0 pseudo-account fields set"
87 "pseudo-account has 2 pseudo-account fields set"
88 "pseudo-account sequence changed"
89 "pseudo-account flags are not set"
90 "pseudo-account has a regular key"
91 "pseudo-account has a sponsorship field"
92 */
93 struct Mod
94 {
95 std::string expectedFailure;
96 std::function<void(SLE::pointer&)> func;
97 };
98 auto const mods = std::to_array<Mod>({
99 {
100 .expectedFailure = "pseudo-account has 0 pseudo-account fields set",
101 .func =
102 [this](SLE::pointer& sle) {
103 BEAST_EXPECT(sle->at(~sfVaultID));
104 sle->at(~sfVaultID) = std::nullopt;
105 },
106 },
107 {
108 .expectedFailure = "pseudo-account sequence changed",
109 .func = [](SLE::pointer& sle) { sle->at(sfSequence) = 12345; },
110 },
111 {
112 .expectedFailure = "pseudo-account flags are not set",
113 .func = [](SLE::pointer& sle) { sle->at(sfFlags) = lsfNoFreeze; },
114 },
115 {
116 .expectedFailure = "pseudo-account has a regular key",
117 .func = [](SLE::pointer& sle) { sle->at(sfRegularKey) = Account("regular").id(); },
118 },
119 {
120 .expectedFailure = "pseudo-account has a sponsorship field",
121 .func = [](SLE::pointer& sle) { sle->at(sfSponsoredOwnerCount) = 1; },
122 },
123 {
124 .expectedFailure = "pseudo-account has a sponsorship field",
125 .func = [](SLE::pointer& sle) { sle->at(sfSponsoringOwnerCount) = 1; },
126 },
127 {
128 .expectedFailure = "pseudo-account has a sponsorship field",
129 .func = [](SLE::pointer& sle) { sle->at(sfSponsoringAccountCount) = 1; },
130 },
131 {
132 .expectedFailure = "pseudo-account has a sponsorship field",
133 .func = [](SLE::pointer& sle) { sle->at(sfSponsor) = Account("sponsor").id(); },
134 },
135 });
136
137 for (auto const& mod : mods)
138 {
140 {{mod.expectedFailure}},
141 [&](Account const& a1, Account const&, ApplyContext& ac) {
142 auto sle = ac.view().peek(keylet::account(pseudoAccountID));
143 if (!sle)
144 return false;
145 mod.func(sle);
146 ac.view().update(sle);
147 return true;
148 },
149 XRPAmount{},
150 STTx{ttACCOUNT_SET, [](STObject& tx) {}},
152 createPseudo);
153 }
154 for (auto const pField : getPseudoAccountFields())
155 {
156 // createPseudo creates a vault, so sfVaultID will be set, and
157 // setting it again will not cause an error
158 if (pField == &sfVaultID)
159 continue;
161 {{"pseudo-account has 2 pseudo-account fields set"}},
162 [&](Account const& a1, Account const&, ApplyContext& ac) {
163 auto const sle = ac.view().peek(keylet::account(pseudoAccountID));
164 if (!sle)
165 return false;
166
167 auto const vaultID = ~sle->at(~sfVaultID);
168 BEAST_EXPECT(vaultID && !sle->isFieldPresent(*pField));
169 sle->setFieldH256(*pField, *vaultID);
170
171 ac.view().update(sle);
172 return true;
173 },
174 XRPAmount{},
175 STTx{ttACCOUNT_SET, [](STObject& tx) {}},
177 createPseudo);
178 }
179
180 // Take one of the regular accounts and set the sequence to 0, which
181 // will make it look like a pseudo-account
183 {
184 {"pseudo-account has 0 pseudo-account fields set"},
185 {"pseudo-account sequence changed"},
186 {"pseudo-account flags are not set"},
187 },
188 [&](Account const& a1, Account const&, ApplyContext& ac) {
189 auto const sle = ac.view().peek(keylet::account(a1.id()));
190 if (!sle)
191 return false;
192 sle->at(sfSequence) = 0;
193 ac.view().update(sle);
194 return true;
195 });
196 }
197
198 void
200 {
201 testcase << "valid loan broker";
202
203 using namespace jtx;
204
205 enum class Asset { XRP, IOU, MPT };
206 auto const assetTypes = std::to_array({Asset::XRP, Asset::IOU, Asset::MPT});
207
208 for (auto const assetType : assetTypes)
209 {
210 // Initialize with a placeholder value because there's no default
211 // ctor
212 auto const setupAsset =
213 [&](Account const& alice, Account const& issuer, Env& env) -> PrettyAsset {
214 switch (assetType)
215 {
216 case Asset::IOU: {
217 PrettyAsset const iouAsset = issuer["IOU"];
218 env(trust(alice, iouAsset(1000)));
219 env(pay(issuer, alice, iouAsset(1000)));
220 env.close();
221 return iouAsset;
222 }
223 case Asset::MPT: {
224 MPTTester mptt{env, issuer, kMptInitNoFund};
225 mptt.create({.flags = tfMPTCanClawback | tfMPTCanTransfer | tfMPTCanLock});
226 PrettyAsset const mptAsset = mptt.issuanceID();
227 mptt.authorize({.account = alice});
228 env(pay(issuer, alice, mptAsset(1000)));
229 env.close();
230 return mptAsset;
231 }
232 case Asset::XRP:
233 default:
234 return PrettyAsset{xrpIssue(), 1'000'000};
235 }
236 };
237
238 Keylet loanBrokerKeylet = keylet::amendments();
240 [&, this](Account const& alice, Account const& issuer, Env& env) {
241 auto const asset = setupAsset(alice, issuer, env);
242 loanBrokerKeylet = this->createLoanBroker(alice, env, asset);
243 return BEAST_EXPECT(env.le(loanBrokerKeylet));
244 };
245
246 // Ensure the test scenarios are set up completely. The test cases
247 // will need to recompute any of these values it needs for itself
248 // rather than trying to return a bunch of items
249 auto setupTest = [&, this](Account const& a1, Account const&, ApplyContext& ac)
251 if (loanBrokerKeylet.type != ltLOAN_BROKER)
252 return {};
253 auto const sleBroker = ac.view().peek(loanBrokerKeylet);
254 if (!sleBroker)
255 return {};
256 if (!BEAST_EXPECT(sleBroker->at(sfOwnerCount) == 0))
257 return {};
258 // Need to touch sleBroker so that it is included in the
259 // modified entries for the invariant to find
260 ac.view().update(sleBroker);
261
262 // The pseudo-account holds the directory, so get it
263 auto const pseudoAccountID = sleBroker->at(sfAccount);
264 auto const pseudoAccountKeylet = keylet::account(pseudoAccountID);
265 // Strictly speaking, we don't need to load the
266 // ACCOUNT_ROOT, but check anyway
267 auto const slePseudo = ac.view().peek(pseudoAccountKeylet);
268 if (!BEAST_EXPECT(slePseudo))
269 return {};
270 // Make sure the directory doesn't already exist
271 auto const dirKeylet = keylet::ownerDir(pseudoAccountID);
272 auto sleDir = ac.view().peek(dirKeylet);
273 auto const describe = describeOwnerDir(pseudoAccountID);
274 if (!sleDir)
275 {
276 // Create the directory
277 BEAST_EXPECT(
279 ac.view(), dirKeylet, loanBrokerKeylet.key, describe) == 0);
280
281 sleDir = ac.view().peek(dirKeylet);
282 }
283
284 return std::make_pair(slePseudo, sleDir);
285 };
286
288 {
289 {
290 "Loan Broker with zero OwnerCount has multiple directory "
291 "pages",
292 },
293 },
294 [&setupTest, this](Account const& a1, Account const& a2, ApplyContext& ac) {
295 auto test = setupTest(a1, a2, ac);
296 if (!test || !test->first || !test->second)
297 return false;
298
299 auto const slePseudo = test->first;
300 auto const sleDir = test->second;
301 auto const describe = describeOwnerDir(slePseudo->at(sfAccount));
302
303 BEAST_EXPECT(
305 ac.view(),
306 0,
307 sleDir,
308 0,
309 sleDir,
310 slePseudo->key(),
311 keylet::page(sleDir->key(), 0),
312 describe) == 1);
313
314 return true;
315 },
316 XRPAmount{},
317 STTx{ttLOAN_BROKER_SET, [](STObject& tx) {}},
320
322 {
323 {
324 "Loan Broker with zero OwnerCount has multiple indexes in "
325 "the Directory root",
326 },
327 },
328 [&setupTest](Account const& a1, Account const& a2, ApplyContext& ac) {
329 auto test = setupTest(a1, a2, ac);
330 if (!test || !test->first || !test->second)
331 return false;
332
333 auto const slePseudo = test->first;
334 auto const sleDir = test->second;
335 auto indexes = sleDir->getFieldV256(sfIndexes);
336
337 // Put some extra garbage into the directory
338 for (auto const& key : {slePseudo->key(), sleDir->key()})
339 {
340 ::xrpl::directory::insertKey(ac.view(), sleDir, 0, false, indexes, key);
341 }
342
343 return true;
344 },
345 XRPAmount{},
346 STTx{ttLOAN_BROKER_SET, [](STObject& tx) {}},
349
351 {{"Loan Broker directory corrupt"}},
352 [&setupTest](Account const& a1, Account const& a2, ApplyContext& ac) {
353 auto test = setupTest(a1, a2, ac);
354 if (!test || !test->first || !test->second)
355 return false;
356
357 auto const slePseudo = test->first;
358 auto const sleDir = test->second;
359 auto const describe = describeOwnerDir(slePseudo->at(sfAccount));
360 // Empty vector will overwrite the existing entry for the
361 // holding, if any, avoiding the "has multiple indexes"
362 // failure.
363 STVector256 indexes;
364
365 // Put one meaningless key into the directory
366 auto const key = keylet::account(Account("random").id()).key;
367 ::xrpl::directory::insertKey(ac.view(), sleDir, 0, false, indexes, key);
368
369 return true;
370 },
371 XRPAmount{},
372 STTx{ttLOAN_BROKER_SET, [](STObject& tx) {}},
375
377 {
378 {
379 "Loan Broker with zero OwnerCount has an unexpected entry in "
380 "the directory",
381 },
382 },
383 [&setupTest](Account const& a1, Account const& a2, ApplyContext& ac) {
384 auto test = setupTest(a1, a2, ac);
385 if (!test || !test->first || !test->second)
386 return false;
387
388 auto const slePseudo = test->first;
389 auto const sleDir = test->second;
390 // Empty vector will overwrite the existing entry for the
391 // holding, if any, avoiding the "has multiple indexes"
392 // failure.
393 STVector256 indexes;
394
396 ac.view(), sleDir, 0, false, indexes, slePseudo->key());
397
398 return true;
399 },
400 XRPAmount{},
401 STTx{ttLOAN_BROKER_SET, [](STObject& tx) {}},
404
406 {{"Loan Broker sequence number decreased"}},
407 [&](Account const& a1, Account const& a2, ApplyContext& ac) {
408 if (loanBrokerKeylet.type != ltLOAN_BROKER)
409 return false;
410 auto const sleBroker = ac.view().peek(loanBrokerKeylet);
411 if (!sleBroker)
412 return false;
413 if (!BEAST_EXPECT(sleBroker->at(sfLoanSequence) > 0))
414 return false;
415 // Need to touch sleBroker so that it is included in the
416 // modified entries for the invariant to find
417 ac.view().update(sleBroker);
418
419 sleBroker->at(sfLoanSequence) -= 1;
420
421 return true;
422 },
423 XRPAmount{},
424 STTx{ttLOAN_BROKER_SET, [](STObject& tx) {}},
427
428 // Test: cover available less than pseudo-account asset balance
429 {
430 Keylet brokerKeylet = keylet::amendments();
431 Preclose const createBrokerWithCover =
432 [&, this](Account const& alice, Account const& issuer, Env& env) {
433 auto const asset = setupAsset(alice, issuer, env);
434 brokerKeylet = this->createLoanBroker(alice, env, asset);
435 if (!BEAST_EXPECT(env.le(brokerKeylet)))
436 return false;
437 env(loan_broker::coverDeposit(alice, brokerKeylet.key, asset(10)));
438 env.close();
439 return BEAST_EXPECT(env.le(brokerKeylet));
440 };
441
443 {{"Loan Broker cover available is less than pseudo-account asset balance"}},
444 [&](Account const&, Account const&, ApplyContext& ac) {
445 auto const sle = ac.view().peek(brokerKeylet);
446 if (!BEAST_EXPECT(sle))
447 return false;
448 // Pseudo-account holds 10 units, set cover to 5
449 sle->at(sfCoverAvailable) = Number(5);
450 ac.view().update(sle);
451 return true;
452 },
453 XRPAmount{},
454 STTx{ttLOAN_BROKER_SET, [](STObject& tx) {}},
456 createBrokerWithCover);
457 }
458
459 // Test: cover available greater than pseudo-account asset balance
460 // (requires fixCleanup3_1_3)
462 {{"Loan Broker cover available is greater than pseudo-account asset balance"}},
463 [&](Account const&, Account const&, ApplyContext& ac) {
464 auto const sle = ac.view().peek(loanBrokerKeylet);
465 if (!BEAST_EXPECT(sle))
466 return false;
467 // Pseudo-account has no cover deposited; set cover
468 // higher than any incidental balance
469 sle->at(sfCoverAvailable) = Number(1'000'000);
470 ac.view().update(sle);
471 return true;
472 },
473 XRPAmount{},
474 STTx{ttLOAN_BROKER_SET, [](STObject& tx) {}},
477
479 {{"DomainID is set on public Loan Broker"}},
480 [&](Account const&, Account const&, ApplyContext& ac) {
481 if (loanBrokerKeylet.type != ltLOAN_BROKER)
482 return false;
483 auto const sleBroker = ac.view().peek(loanBrokerKeylet);
484 if (!sleBroker)
485 return false;
486 // Set DomainID without lsfLoanBrokerPrivate flag
487 sleBroker->clearFlag(lsfLoanBrokerPrivate);
488 sleBroker->at(sfDomainID) = uint256(42);
489 ac.view().update(sleBroker);
490 return true;
491 },
492 XRPAmount{},
493 STTx{ttLOAN_BROKER_SET, [](STObject& tx) {}},
496
498 {{"Loan Broker DomainID is zero"}},
499 [&](Account const&, Account const&, ApplyContext& ac) {
500 if (loanBrokerKeylet.type != ltLOAN_BROKER)
501 return false;
502 auto const sleBroker = ac.view().peek(loanBrokerKeylet);
503 if (!sleBroker)
504 return false;
505 // Private broker with a zero DomainID
506 sleBroker->setFlag(lsfLoanBrokerPrivate);
507 sleBroker->at(sfDomainID) = uint256{};
508 ac.view().update(sleBroker);
509 return true;
510 },
511 XRPAmount{},
512 STTx{ttLOAN_BROKER_SET, [](STObject& tx) {}},
515
516 // Use the highest bit, which is the least likely to be given to a
517 // LoanBroker flag in future
518 std::uint32_t constexpr unknownFlag = 0x80000000;
519
521 {{"Loan Broker contains an unknown flag"}},
522 [&](Account const&, Account const&, ApplyContext& ac) {
523 if (loanBrokerKeylet.type != ltLOAN_BROKER)
524 return false;
525 auto const sleBroker = ac.view().peek(loanBrokerKeylet);
526 if (!sleBroker)
527 return false;
528 // Public broker with an unknown flag
529 sleBroker->setFlag(unknownFlag);
530 ac.view().update(sleBroker);
531 return true;
532 },
533 XRPAmount{},
534 STTx{ttLOAN_BROKER_SET, [](STObject& tx) {}},
537
539 {{"Loan Broker contains an unknown flag"}},
540 [&](Account const&, Account const&, ApplyContext& ac) {
541 if (loanBrokerKeylet.type != ltLOAN_BROKER)
542 return false;
543 auto const sleBroker = ac.view().peek(loanBrokerKeylet);
544 if (!sleBroker)
545 return false;
546 // Private broker with a valid DomainID and an unknown flag
547 sleBroker->setFlag(lsfLoanBrokerPrivate | unknownFlag);
548 sleBroker->at(sfDomainID) = uint256(42);
549 ac.view().update(sleBroker);
550 return true;
551 },
552 XRPAmount{},
553 STTx{ttLOAN_BROKER_SET, [](STObject& tx) {}},
556
557 // Deleting the IOU holding while leaving the broker unchanged must
558 // still expose CoverAvailable exceeding the now-zero balance: the
559 // broker is discovered through the deleted trust line. XRP has no
560 // holding SLE, while deleting an MPToken triggers other invariants,
561 // so IOU isolates this check. Verify that fixCleanup3_1_3 gates it
562 // by expecting failure only when the amendment is enabled.
563 if (assetType == Asset::IOU)
564 {
565 Keylet brokerKeylet = keylet::amendments();
566 Preclose const createBrokerWithCover =
567 [&, this](Account const& alice, Account const& issuer, Env& env) {
568 auto const asset = setupAsset(alice, issuer, env);
569 brokerKeylet = this->createLoanBroker(alice, env, asset);
570 if (!BEAST_EXPECT(env.le(brokerKeylet)))
571 return false;
572 env(loan_broker::coverDeposit(alice, brokerKeylet.key, asset(10)));
573 env.close();
574 return BEAST_EXPECT(env.le(brokerKeylet));
575 };
576
577 Precheck const deleteHolding =
578 [&](Account const&, Account const&, ApplyContext& ac) {
579 if (brokerKeylet.type != ltLOAN_BROKER)
580 return false;
581 // Read (don't touch) the broker so it is only found via
582 // the deleted holding, not as a modified entry.
583 auto const sleBroker = ac.view().read(brokerKeylet);
584 if (!BEAST_EXPECT(sleBroker))
585 return false;
586 auto const pseudoAccountID = sleBroker->at(sfAccount);
587
588 // Erase every holding in the pseudo-account directory
589 // and the directory root itself, mirroring a bug that
590 // removed the cover holding without zeroing
591 // CoverAvailable. Removing the root also keeps the
592 // zero-OwnerCount directory check from firing first.
593 auto const sleDir = ac.view().peek(keylet::ownerDir(pseudoAccountID));
594 if (!BEAST_EXPECT(sleDir))
595 return false;
596 for (auto const& index : sleDir->getFieldV256(sfIndexes))
597 {
598 if (auto const holding = ac.view().peek(keylet::unchecked(index)))
599 {
600 ac.view().erase(holding);
601 }
602 }
603 ac.view().erase(sleDir);
604 return true;
605 };
606
607 // With fixCleanup3_1_3: the invariant fires.
609 makeEnv(all_),
610 {{"Loan Broker cover available is greater than pseudo-account asset balance"}},
611 deleteHolding,
612 XRPAmount{},
613 STTx{ttACCOUNT_SET, [](STObject&) {}},
615 createBrokerWithCover);
616
617 // Without fixCleanup3_1_3: the same state is silently accepted.
619 makeEnv(all_ - fixCleanup3_1_3),
620 {},
621 deleteHolding,
622 XRPAmount{},
623 STTx{ttACCOUNT_SET, [](STObject&) {}},
625 createBrokerWithCover);
626 }
627
628 // A LoanBroker may only be removed by ttLOAN_BROKER_DELETE. Erase
629 // the broker in the apply view under a non-delete tx type and
630 // expect the deletion-tx invariant to fire.
632 {{"Loan Broker deleted by a transaction other than LoanBrokerDelete"}},
633 [&](Account const&, Account const&, ApplyContext& ac) {
634 if (loanBrokerKeylet.type != ltLOAN_BROKER)
635 return false;
636 auto const sleBroker = ac.view().peek(loanBrokerKeylet);
637 if (!BEAST_EXPECT(sleBroker))
638 return false;
639 ac.view().erase(sleBroker);
640 return true;
641 },
642 XRPAmount{},
643 STTx{ttACCOUNT_SET, [](STObject&) {}},
646 }
647
648 // A LoanBrokerDelete must not remove a broker whose pre-transaction
649 // DebtTotal is non-zero. visitEntry captures `before` from the parent
650 // view, so the DebtTotal must be seeded in the OpenView before the
651 // ApplyContext is constructed; a Precheck modification would only
652 // land in the applyView (visible as `after`) and would leave `before`
653 // at the createLoanBroker-produced zero.
654 {
655 Env env{*this};
656 Account const a1{"A1"};
657 Account const a2{"A2"};
658 env.fund(XRP(1000), a1, a2);
659 env.close();
660
661 PrettyAsset const xrpAsset{xrpIssue(), 1'000'000};
662 auto const brokerKeylet = createLoanBroker(a1, env, xrpAsset);
663 if (!BEAST_EXPECT(env.le(brokerKeylet)))
664 return;
665 env.close();
666
667 OpenView ov{*env.current()};
668
669 // Seed a non-zero DebtTotal in the base view so `before` at
670 // visitEntry time reports it.
671 {
672 auto const sleBrokerRead = ov.read(brokerKeylet);
673 if (!BEAST_EXPECT(sleBrokerRead))
674 return;
675 auto const sleBroker = std::make_shared<SLE>(*sleBrokerRead);
676 sleBroker->at(sfDebtTotal) = Number(1);
677 ov.rawReplace(sleBroker);
678 }
679
680 STTx const tx{ttLOAN_BROKER_DELETE, [](STObject&) {}};
682 beast::Journal const jlog{sink};
683 ApplyContext ac{
684 env.app(), ov, tx, tesSUCCESS, env.current()->fees().base, TapNone, jlog};
685 CurrentTransactionRulesGuard const rulesGuard(ov.rules());
686
687 auto const sleBroker = ac.view().peek(brokerKeylet);
688 if (!BEAST_EXPECT(sleBroker))
689 return;
690 ac.view().erase(sleBroker);
691
692 auto transactor = makeTransactor(ac);
693 if (!BEAST_EXPECT(transactor))
694 return;
695 TER const result = transactor->checkInvariants(
697 BEAST_EXPECT(result == tecINVARIANT_FAILED);
698 BEAST_EXPECT(
699 sink.messages().str().contains("Loan Broker deleted with non-zero debt total"));
700 }
701
702 // Residual DebtTotal dust that rounds to zero at the vault asset's
703 // scale must not trip the invariant: LoanBrokerDelete::preclaim
704 // deliberately permits it, so the invariant must not be stricter.
705 // Other invariants may still object to a hand-erased broker, so only
706 // the absence of the DebtTotal complaint is asserted.
707 {
708 Env env{*this};
709 Account const a1{"A1"};
710 Account const a2{"A2"};
711 env.fund(XRP(1000), a1, a2);
712 env.close();
713
714 PrettyAsset const xrpAsset{xrpIssue(), 1'000'000};
715 auto const brokerKeylet = createLoanBroker(a1, env, xrpAsset);
716 if (!BEAST_EXPECT(env.le(brokerKeylet)))
717 return;
718 env.close();
719
720 OpenView ov{*env.current()};
721
722 // A thousandth of a drop: non-zero, but zero once quantized to XRP.
723 {
724 auto const sleBrokerRead = ov.read(brokerKeylet);
725 if (!BEAST_EXPECT(sleBrokerRead))
726 return;
727 auto const sleBroker = std::make_shared<SLE>(*sleBrokerRead);
728 sleBroker->at(sfDebtTotal) = Number(1, -3);
729 ov.rawReplace(sleBroker);
730 }
731
732 STTx const tx{ttLOAN_BROKER_DELETE, [](STObject&) {}};
734 beast::Journal const jlog{sink};
735 ApplyContext ac{
736 env.app(), ov, tx, tesSUCCESS, env.current()->fees().base, TapNone, jlog};
737 CurrentTransactionRulesGuard const rulesGuard(ov.rules());
738
739 auto const sleBroker = ac.view().peek(brokerKeylet);
740 if (!BEAST_EXPECT(sleBroker))
741 return;
742 ac.view().erase(sleBroker);
743
744 auto transactor = makeTransactor(ac);
745 if (!BEAST_EXPECT(transactor))
746 return;
747 [[maybe_unused]] TER const result = transactor->checkInvariants(
749 BEAST_EXPECT(
750 !sink.messages().str().contains("Loan Broker deleted with non-zero debt total"));
751 }
752
753 // A LoanBrokerDelete must not remove a broker whose pre-transaction
754 // OwnerCount is non-zero. DebtTotal is left at zero so the earlier
755 // check passes and the OwnerCount check is what fires.
756 {
757 Env env{*this};
758 Account const a1{"A1"};
759 Account const a2{"A2"};
760 env.fund(XRP(1000), a1, a2);
761 env.close();
762
763 PrettyAsset const xrpAsset{xrpIssue(), 1'000'000};
764 auto const brokerKeylet = createLoanBroker(a1, env, xrpAsset);
765 if (!BEAST_EXPECT(env.le(brokerKeylet)))
766 return;
767 env.close();
768
769 OpenView ov{*env.current()};
770
771 {
772 auto const sleBrokerRead = ov.read(brokerKeylet);
773 if (!BEAST_EXPECT(sleBrokerRead))
774 return;
775 auto const sleBroker = std::make_shared<SLE>(*sleBrokerRead);
776 sleBroker->at(sfOwnerCount) = 1;
777 ov.rawReplace(sleBroker);
778 }
779
780 STTx const tx{ttLOAN_BROKER_DELETE, [](STObject&) {}};
782 beast::Journal const jlog{sink};
783 ApplyContext ac{
784 env.app(), ov, tx, tesSUCCESS, env.current()->fees().base, TapNone, jlog};
785 CurrentTransactionRulesGuard const rulesGuard(ov.rules());
786
787 auto const sleBroker = ac.view().peek(brokerKeylet);
788 if (!BEAST_EXPECT(sleBroker))
789 return;
790 ac.view().erase(sleBroker);
791
792 auto transactor = makeTransactor(ac);
793 if (!BEAST_EXPECT(transactor))
794 return;
795 TER const result = transactor->checkInvariants(
797 BEAST_EXPECT(result == tecINVARIANT_FAILED);
798 BEAST_EXPECT(
799 sink.messages().str().contains("Loan Broker deleted with non-zero owner count"));
800 }
801
802 // Only one LoanBroker may be deleted per transaction. Create two
803 // brokers under different owners, then erase both in the apply view
804 // and expect the multi-deletion invariant to fire.
805 {
806 Keylet loanBrokerKeylet1 = keylet::amendments();
807 Keylet loanBrokerKeylet2 = keylet::amendments();
808 Preclose const createTwoBrokers = [&, this](
809 Account const& a1, Account const& a2, Env& env) {
810 PrettyAsset const xrpAsset{xrpIssue(), 1'000'000};
811 loanBrokerKeylet1 = this->createLoanBroker(a1, env, xrpAsset);
812 loanBrokerKeylet2 = this->createLoanBroker(a2, env, xrpAsset);
813 return BEAST_EXPECT(env.le(loanBrokerKeylet1) && env.le(loanBrokerKeylet2));
814 };
815
817 {{"more than one Loan Broker deleted in a single transaction"}},
818 [&](Account const&, Account const&, ApplyContext& ac) {
819 auto const sle1 = ac.view().peek(loanBrokerKeylet1);
820 auto const sle2 = ac.view().peek(loanBrokerKeylet2);
821 if (!BEAST_EXPECT(sle1 && sle2))
822 return false;
823 ac.view().erase(sle1);
824 ac.view().erase(sle2);
825 return true;
826 },
827 XRPAmount{},
828 STTx{ttLOAN_BROKER_DELETE, [](STObject&) {}},
830 createTwoBrokers);
831 }
832 }
833
834 // Fabricate a credential with the given subject and link it into the
835 // subject's owner directory, as a transactor bug bypassing the
836 // CredentialCreate guard would.
837 static bool
838 pinCredential(AccountID const& subject, AccountID const& issuer, ApplyContext& ac)
839 {
840 Slice const credType{"pinned", 6};
841 auto const cred = std::make_shared<SLE>(keylet::credential(subject, issuer, credType));
842 cred->setAccountID(sfSubject, subject);
843 cred->setAccountID(sfIssuer, issuer);
844 cred->setFieldVL(sfCredentialType, credType);
845 auto const page =
846 ac.view().dirInsert(keylet::ownerDir(subject), cred->key(), describeOwnerDir(subject));
847 if (!page)
848 return false;
849 cred->setFieldU64(sfSubjectNode, *page);
850 ac.view().insert(cred);
851 return true;
852 }
853
854 // Link an existing entry into the owner directory of `owner`, as a
855 // transactor bug that attaches someone else's entry would.
856 static bool
857 linkEntry(AccountID const& owner, uint256 const& key, ApplyContext& ac)
858 {
859 return ac.view()
860 .dirInsert(keylet::ownerDir(owner), key, describeOwnerDir(owner))
861 .has_value();
862 }
863
864 // Pin an object to a pseudo-account. The invariant rejects it with
865 // `message` only once fixCleanup3_5_0 is enabled.
866 void
868 FeatureBitset features,
869 std::string const& message,
870 Precheck const& pin,
871 Preclose const& setup)
872 {
873 bool const enabled = features[fixCleanup3_5_0];
874 TER const failed = enabled ? TER{tecINVARIANT_FAILED} : TER{tesSUCCESS};
875 TER const retried = enabled ? TER{tefINVARIANT_FAILED} : TER{tesSUCCESS};
877 makeEnv(features),
879 pin,
880 XRPAmount{},
881 STTx{ttACCOUNT_SET, [](STObject&) {}},
882 {failed, retried},
883 setup);
884 }
885
886 // The pseudo-account of the vault the broker operates on.
888 brokerVaultPseudo(Keylet const& brokerKeylet, ApplyContext& ac)
889 {
890 auto const sleBroker = ac.view().read(brokerKeylet);
891 if (!sleBroker)
892 return std::nullopt;
893 auto const sleVault = ac.view().read(keylet::vault(sleBroker->at(sfVaultID)));
894 if (!sleVault)
895 return std::nullopt;
896 return sleVault->at(sfAccount);
897 }
898
899 static char const*
901 {
902 return features[fixCleanup3_5_0] ? "post-Cleanup3.5" : "pre-Cleanup3.5";
903 }
904
905 void
907 {
908 using namespace jtx;
909
910 std::optional<Keylet> vaultKeylet;
911 Preclose const createVault = [&](Account const& a1, Account const&, Env& env) -> bool {
912 Vault const vault{env};
913 auto [tx, k] = vault.create({.owner = a1, .asset = xrpIssue()});
914 env(tx);
915 env.close();
916 vaultKeylet = k;
917 return true;
918 };
919
920 auto const vaultPseudo = [&](ApplyContext& ac) -> std::optional<AccountID> {
921 if (!vaultKeylet)
922 return std::nullopt;
923 auto const sleVault = ac.view().read(*vaultKeylet);
924 if (!sleVault)
925 return std::nullopt;
926 return sleVault->at(sfAccount);
927 };
928
929 testcase << "vault pseudo-account pinned by a credential, " << cleanupLabel(features);
931 features,
932 "may not own Credential",
933 [&](Account const&, Account const& a2, ApplyContext& ac) {
934 auto const pseudo = vaultPseudo(ac);
935 return pseudo && pinCredential(*pseudo, a2.id(), ac);
936 },
937 createVault);
938
939 testcase << "vault pseudo-account pinned by a check, " << cleanupLabel(features);
940 vaultKeylet.reset();
942 features,
943 "may not own Check",
944 [&](Account const&, Account const& a2, ApplyContext& ac) {
945 auto const pseudo = vaultPseudo(ac);
946 if (!pseudo)
947 return false;
948
949 auto const sleAcct = ac.view().peek(keylet::account(a2.id()));
950 if (!sleAcct)
951 return false;
952
953 auto const check = std::make_shared<SLE>(
954 keylet::check(a2.id(), SeqProxy::rawSequence((*sleAcct)[sfSequence])));
955 check->setAccountID(sfAccount, a2.id());
956 check->setAccountID(sfDestination, *pseudo);
957 auto const page = ac.view().dirInsert(
958 keylet::ownerDir(*pseudo), check->key(), describeOwnerDir(*pseudo));
959 if (!page)
960 return false;
961 check->setFieldU64(sfDestinationNode, *page);
962 ac.view().insert(check);
963 return true;
964 },
965 createVault);
966
967 testcase << "vault pseudo-account links a missing object, " << cleanupLabel(features);
968 vaultKeylet.reset();
970 features,
971 "owner directory links a missing object",
972 [&](Account const&, Account const& a2, ApplyContext& ac) {
973 auto const pseudo = vaultPseudo(ac);
974 if (!pseudo)
975 return false;
976
977 // Link a key with no ledger entry behind it.
978 auto const missing = keylet::check(a2.id(), SeqProxy::rawSequence(0));
979 return linkEntry(*pseudo, missing.key, ac);
980 },
981 createVault);
982
983 testcase << "vault pseudo-account linked to an unrelated trust line, "
984 << cleanupLabel(features);
985 vaultKeylet.reset();
987 features,
988 "may not own RippleState",
989 [&](Account const& a1, Account const& a2, ApplyContext& ac) {
990 auto const pseudo = vaultPseudo(ac);
991 return pseudo && linkEntry(*pseudo, keylet::trustLine(a1, a2["EUR"]).key, ac);
992 },
993 [&](Account const& a1, Account const& a2, Env& env) -> bool {
994 env(trust(a1, a2["EUR"](100)));
995 return createVault(a1, a2, env);
996 });
997
998 testcase << "vault pseudo-account linked to another vault's loan broker, "
999 << cleanupLabel(features);
1000 std::optional<Keylet> broker;
1001 std::optional<Keylet> otherBroker;
1003 features,
1004 "may not own LoanBroker",
1005 [&](Account const&, Account const&, ApplyContext& ac) {
1006 if (!broker || !otherBroker)
1007 return false;
1008 auto const pseudo = brokerVaultPseudo(*broker, ac);
1009 return pseudo && linkEntry(*pseudo, otherBroker->key, ac);
1010 },
1011 [&, this](Account const& a1, Account const&, Env& env) -> bool {
1012 PrettyAsset const xrpAsset{xrpIssue(), 1'000'000};
1013 broker = createLoanBroker(a1, env, xrpAsset);
1014 otherBroker = createLoanBroker(a1, env, xrpAsset);
1015 return BEAST_EXPECT(env.le(*broker) && env.le(*otherBroker));
1016 });
1017 }
1018
1019 void
1021 {
1022 using namespace jtx;
1023
1024 testcase << "loan broker pseudo-account pinned by a credential, " << cleanupLabel(features);
1025 std::optional<Keylet> brokerKeylet;
1027 features,
1028 "may not own Credential",
1029 [&](Account const&, Account const& a2, ApplyContext& ac) {
1030 if (!brokerKeylet)
1031 return false;
1032 auto const sleBroker = ac.view().read(*brokerKeylet);
1033 if (!sleBroker)
1034 return false;
1035 AccountID const pseudo = sleBroker->at(sfAccount);
1036 return pinCredential(pseudo, a2.id(), ac);
1037 },
1038 [&, this](Account const& a1, Account const&, Env& env) -> bool {
1039 PrettyAsset const xrpAsset{xrpIssue(), 1'000'000};
1040 brokerKeylet = createLoanBroker(a1, env, xrpAsset);
1041 return brokerKeylet.has_value();
1042 });
1043
1044 testcase << "loan broker pseudo-account linked to another broker's loan, "
1045 << cleanupLabel(features);
1046 std::optional<Keylet> otherLoan;
1048 features,
1049 "may not own Loan",
1050 [&](Account const&, Account const&, ApplyContext& ac) {
1051 if (!brokerKeylet || !otherLoan)
1052 return false;
1053 auto const sleBroker = ac.view().read(*brokerKeylet);
1054 return sleBroker && linkEntry(sleBroker->at(sfAccount), otherLoan->key, ac);
1055 },
1056 [&, this](Account const& a1, Account const& a2, Env& env) -> bool {
1057 PrettyAsset const xrpAsset{xrpIssue(), 1'000'000};
1058 brokerKeylet = createLoanBroker(a1, env, xrpAsset);
1059 otherLoan = createLoan(a1, a2, env, createLoanBroker(a1, env, xrpAsset));
1060 return otherLoan.has_value();
1061 });
1062 }
1063
1064 // Fund the broker's vault and have `borrower` take a loan from it.
1067 jtx::Account const& lender,
1068 jtx::Account const& borrower,
1069 jtx::Env& env,
1070 Keylet const& brokerKeylet)
1071 {
1072 using namespace jtx;
1073
1074 PrettyAsset const xrpAsset{xrpIssue(), 1'000'000};
1075 auto const sleBroker = env.le(brokerKeylet);
1076 if (!BEAST_EXPECT(sleBroker))
1077 return std::nullopt;
1078 Vault const vault{env};
1079 env(vault.deposit(
1080 {.depositor = lender, .id = sleBroker->at(sfVaultID), .amount = xrpAsset(100)}));
1081 env.close(std::chrono::seconds{61});
1082
1083 auto const loanKeylet =
1084 keylet::loan(brokerKeylet.key, SeqProxy::rawSequence(sleBroker->at(sfLoanSequence)));
1085 env(loan::set(borrower, brokerKeylet.key, xrpAsset(50).value()),
1086 loan::kCounterparty(lender),
1087 Sig(sfCounterpartySignature, lender),
1090 Fee(env.current()->fees().base * 2));
1091 env.close();
1092 if (!BEAST_EXPECT(env.le(loanKeylet)))
1093 return std::nullopt;
1094 return loanKeylet;
1095 }
1096
1097 void
1099 {
1100 using namespace jtx;
1101
1102 testcase << "AMM pseudo-account pinned by a credential, " << cleanupLabel(features);
1103 std::optional<AccountID> ammAccount;
1105 features,
1106 "may not own Credential",
1107 [&](Account const&, Account const& a2, ApplyContext& ac) {
1108 return ammAccount && pinCredential(*ammAccount, a2.id(), ac);
1109 },
1110 [&](Account const& a1, Account const&, Env& env) -> bool {
1111 AMM const amm(env, a1, XRP(100), a1["USD"](100));
1112 ammAccount = amm.ammAccount();
1113 return true;
1114 });
1115
1116 testcase << "AMM pseudo-account linked to an unrelated trust line, "
1117 << cleanupLabel(features);
1118 ammAccount.reset();
1120 features,
1121 "may not own RippleState",
1122 [&](Account const& a1, Account const& a2, ApplyContext& ac) {
1123 return ammAccount &&
1124 linkEntry(*ammAccount, keylet::trustLine(a2, a1["EUR"]).key, ac);
1125 },
1126 [&](Account const& a1, Account const& a2, Env& env) -> bool {
1127 env(trust(a2, a1["EUR"](100)));
1128 AMM const amm(env, a1, XRP(100), a1["USD"](100));
1129 ammAccount = amm.ammAccount();
1130 return true;
1131 });
1132 }
1133
1134 // Real transactions link only entries that belong to the pseudo-account,
1135 // so the ownership check lets every one of them through.
1136 void
1138 {
1139 using namespace jtx;
1140
1141 testcase << "pseudo-accounts own their own entries, post-Cleanup3.5";
1142 Env env{*this, all_};
1143 Account const owner{"owner"};
1144 Account const borrower{"borrower"};
1145 Account const issuer{"issuer"};
1146 env.fund(XRP(100'000), owner, borrower, issuer);
1147 env.close();
1148
1149 // Vault and broker holdings of an IOU and of an MPT, the broker in
1150 // its vault's directory, and the cover the broker holds.
1151 PrettyAsset const iou = issuer["IOU"];
1152 env(trust(owner, iou(1'000)));
1153 env(pay(issuer, owner, iou(1'000)));
1154 MPTTester mptt{env, issuer, kMptInitNoFund};
1155 mptt.create({.flags = tfMPTCanClawback | tfMPTCanTransfer | tfMPTCanLock});
1156 PrettyAsset const mpt = mptt.issuanceID();
1157 mptt.authorize({.account = owner});
1158 env(pay(issuer, owner, mpt(1'000)));
1159 env.close();
1160 for (auto const& asset : {iou, mpt})
1161 {
1162 auto const broker = createLoanBroker(owner, env, asset);
1163 env(loan_broker::coverDeposit(owner, broker.key, asset(10)));
1164 env.close();
1165 }
1166
1167 // A loan in its broker's directory.
1168 PrettyAsset const xrpAsset{xrpIssue(), 1'000'000};
1169 BEAST_EXPECT(createLoan(owner, borrower, env, createLoanBroker(owner, env, xrpAsset)));
1170
1171 // The AMM entry, the pool holdings and the LP token trust lines.
1172 AMM amm(env, issuer, XRP(100), iou(100));
1173 amm.deposit(owner, iou(10));
1174 }
1175
1176 void
1177 run() override
1178 {
1182 testVaultOwnership(all_ - fixCleanup3_5_0);
1184 testLoanBrokerOwnership(all_ - fixCleanup3_5_0);
1186 testAMMOwnership(all_ - fixCleanup3_5_0);
1188 }
1189};
1190
1191BEAST_DEFINE_TESTSUITE(InvariantsPseudoAccount, app, xrpl);
1192
1193} // namespace xrpl::test
A generic endpoint for log messages.
Definition Journal.h:44
TestcaseT testcase
Memberspace for declaring test cases.
Definition suite.h:155
State information when applying a tx.
ApplyView & view()
virtual SLE::pointer peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
virtual void insert(SLE::Ref sle)=0
Insert a new state SLE.
std::optional< std::uint64_t > dirInsert(Keylet const &directory, UInt256 const &key, std::function< void(SLE::Ref)> const &describe)
Insert an entry to a directory.
Definition ApplyView.h:373
virtual void erase(SLE::Ref sle)=0
Remove a peeked SLE.
RAII class to set and restore the current transaction rules.
Definition Rules.h:113
Number is a floating point type that can represent a wide range of values.
Definition Number.h:351
Writable ledger view that accumulates state and tx changes.
Definition OpenView.h:59
void rawReplace(SLE::Ref sle) override
Unconditionally replace a state item.
Definition OpenView.cpp:246
SLE::const_pointer read(Keylet const &k) const override
Return the state item associated with a key.
Definition OpenView.cpp:170
Rules const & rules() const override
Returns the tx processing rules.
Definition OpenView.cpp:151
virtual SLE::const_pointer read(Keylet const &k) const =0
Return the state item associated with a key.
std::shared_ptr< STLedgerEntry > pointer
static constexpr SeqProxy rawSequence(std::uint32_t v)
Factory function to return a sequence-based SeqProxy.
Definition SeqProxy.h:62
An immutable linear range of bytes.
Definition Slice.h:28
Keylet createLoanBroker(jtx::Account const &a, jtx::Env &env, jtx::PrettyAsset const &asset)
std::function< bool(test::jtx::Account const &a, test::jtx::Account const &b, ApplyContext &ac)> Precheck
test::jtx::Env makeEnv(FeatureBitset features)
void doInvariantCheck(std::vector< std::string > const &expectLogs, Precheck const &precheck, XRPAmount fee=XRPAmount{}, STTx tx=STTx{ttACCOUNT_SET, [](STObject &) {}}, std::initializer_list< TER > ters={tecINVARIANT_FAILED, tefINVARIANT_FAILED}, Preclose const &preclose={}, TxAccount setTxAccount=TxAccount::None, std::source_location const &loc=std::source_location::current(), TER initialResult=tesSUCCESS)
Run a specific test case to put the ledger into a state that will be detected by an invariant.
std::function< bool(test::jtx::Account const &a, test::jtx::Account const &b, test::jtx::Env &env)> Preclose
static char const * cleanupLabel(FeatureBitset features)
static bool linkEntry(AccountID const &owner, uint256 const &key, ApplyContext &ac)
std::optional< Keylet > createLoan(jtx::Account const &lender, jtx::Account const &borrower, jtx::Env &env, Keylet const &brokerKeylet)
static bool pinCredential(AccountID const &subject, AccountID const &issuer, ApplyContext &ac)
static std::optional< AccountID > brokerVaultPseudo(Keylet const &brokerKeylet, ApplyContext &ac)
void checkPinned(FeatureBitset features, std::string const &message, Precheck const &pin, Preclose const &setup)
std::stringstream const & messages() const
Convenience class to test AMM functionality.
Immutable cryptographic account descriptor.
Definition jtx/Account.h:21
AccountID id() const
Returns the Account ID.
A transaction testing environment.
Definition Env.h:161
Application & app()
Definition Env.h:300
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
Definition Env.cpp:133
SLE::const_pointer le(Account const &account) const
Return an account root.
Definition Env.cpp:311
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Definition Env.cpp:323
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Definition Env.h:377
Set the fee on a JTx.
Definition fee.h:20
Converts to IOU Issue or STAmount.
Test helper for creating, mutating, and asserting MPT and confidential MPT ledger state.
Definition mpt.h:512
MPTID const & issuanceID() const
Definition mpt.h:777
void create(MPTCreate const &arg=MPTCreate{}, std::source_location const &loc=std::source_location::current())
Definition mpt.cpp:346
void authorize(MPTAuthorize const &arg=MPTAuthorize{}, std::source_location const &loc=std::source_location::current())
Definition mpt.cpp:459
Converts to MPT Issue or STAmount.
Set the regular signature on a JTx.
Definition sig.h:19
T make_pair(T... args)
T make_shared(T... args)
std::optional< std::uint64_t > insertPage(ApplyView &view, std::uint64_t page, SLE::pointer node, std::uint64_t nextPage, SLE::Ref next, UInt256 const &key, Keylet const &directory, std::function< void(SLE::Ref)> const &describe)
std::uint64_t insertKey(ApplyView &view, SLE::Ref node, std::uint64_t page, bool preserveOrder, STVector256 &indexes, UInt256 const &key)
Definition ApplyView.cpp:70
std::uint64_t createRoot(ApplyView &view, Keylet const &directory, UInt256 const &key, std::function< void(SLE::Ref)> const &describe)
Helper functions for managing low-level directory operations.
Definition ApplyView.cpp:30
Keylet const & amendments() noexcept
The index of the amendment table.
Definition Indexes.cpp:260
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Definition Indexes.cpp:415
Keylet check(AccountID const &id, SeqProxy const &seq) noexcept
A Check.
Definition Indexes.cpp:372
Keylet unchecked(UInt256 const &key) noexcept
Any ledger entry.
Definition Indexes.cpp:409
Keylet vault(AccountID const &owner, SeqProxy const &seq) noexcept
Definition Indexes.cpp:565
Keylet page(UInt256 const &root, std::uint64_t const index=0) noexcept
A page in a directory.
Definition Indexes.cpp:421
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:233
Keylet loan(UInt256 const &loanBrokerID, SeqProxy const &loanSeq) noexcept
Definition Indexes.cpp:577
Keylet credential(AccountID const &subject, AccountID const &issuer, Slice const &credType) noexcept
Definition Indexes.cpp:559
Keylet trustLine(AccountID const &id0, AccountID const &id1, Currency const &currency) noexcept
The index of a trust line for a given currency.
Definition Indexes.cpp:287
Check operations.
Definition check.h:18
json::Value coverDeposit(AccountID const &account, UInt256 const &brokerID, STAmount const &amount, uint32_t flags)
json::Value set(AccountID const &account, UInt256 const &loanBrokerID, Number principalRequested, std::uint32_t flags)
json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
Definition pay.cpp:14
XrpT const XRP
Converts to XRP Issue or STAmount.
Definition amount.cpp:92
FeatureBitset testableAmendments()
Definition Env.h:92
json::Value trust(Account const &account, STAmount const &amount, std::uint32_t flags)
Modify a trust line.
Definition trust.cpp:18
static MPTInit const kMptInitNoFund
Definition mpt.h:201
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
constexpr XRPAmount
Convert XRP to drops (integral types).
Definition TxTest.h:53
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
Issue const & xrpIssue()
Returns an asset specifier that represents XRP.
Definition Issue.h:108
std::vector< SField const * > const & getPseudoAccountFields()
Returns the list of fields that define an ACCOUNT_ROOT as a pseudo-account if set.
@ tefINVARIANT_FAILED
Definition TER.h:177
std::unique_ptr< Transactor > makeTransactor(ApplyContext &ctx)
@ TapNone
Definition ApplyView.h:28
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
TERSubset< CanCvtToTER > TER
Definition TER.h:657
@ tecINVARIANT_FAILED
Definition TER.h:324
std::function< void(SLE::Ref)> describeOwnerDir(AccountID const &account)
Returns a function that sets the owner on a directory SLE.
@ tesSUCCESS
Definition TER.h:253
UInt256 uint256
Definition base_uint.h:587
T has_value(T... args)
T reset(T... args)
T str(T... args)
A pair of SHAMap key and LedgerEntryType.
Definition Keylet.h:20
UInt256 key
Definition Keylet.h:21
LedgerEntryType type
Definition Keylet.h:22