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/escrow.h>
8#include <test/jtx/pay.h>
9#include <test/jtx/token.h>
10#include <test/jtx/trust.h>
11#include <test/jtx/vault.h>
12#include <test/unit_test/SuiteJournal.h>
14#include <xrpl/basics/Number.h>
15#include <xrpl/basics/base_uint.h>
16#include <xrpl/basics/chrono.h>
17#include <xrpl/beast/unit_test/suite.h>
18#include <xrpl/beast/utility/Journal.h>
19#include <xrpl/beast/utility/Zero.h>
20#include <xrpl/ledger/ApplyView.h>
21#include <xrpl/ledger/OpenView.h>
22#include <xrpl/ledger/ReadView.h>
23#include <xrpl/ledger/helpers/AccountRootHelpers.h>
24#include <xrpl/ledger/helpers/RippleStateHelpers.h>
25#include <xrpl/protocol/AccountID.h>
26#include <xrpl/protocol/Feature.h>
27#include <xrpl/protocol/Indexes.h>
28#include <xrpl/protocol/Issue.h>
29#include <xrpl/protocol/Keylet.h>
30#include <xrpl/protocol/LedgerFormats.h>
31#include <xrpl/protocol/MPTIssue.h>
32#include <xrpl/protocol/Protocol.h>
33#include <xrpl/protocol/Rules.h>
34#include <xrpl/protocol/SField.h>
35#include <xrpl/protocol/STAmount.h>
36#include <xrpl/protocol/STLedgerEntry.h>
37#include <xrpl/protocol/STObject.h>
38#include <xrpl/protocol/STTx.h>
39#include <xrpl/protocol/SeqProxy.h>
40#include <xrpl/protocol/SystemParameters.h>
41#include <xrpl/protocol/TER.h>
42#include <xrpl/protocol/TxFormats.h>
43#include <xrpl/protocol/XRPAmount.h>
44#include <xrpl/tx/ApplyContext.h>
45#include <xrpl/tx/Transactor.h>
46#include <xrpl/tx/applySteps.h>
47#include <xrpl/tx/invariants/InvariantRunner.h>
72 {{
"XRP net change was positive: 500"}},
78 auto const amt = sle->getFieldAmount(sfBalance);
79 sle->setFieldAmount(sfBalance, amt +
STAmount{500});
80 ac.view().update(sle);
93 {{
"an account root was deleted"}},
103 ac.view().erase(sle);
113 {{
"account deletion succeeded without deleting an account"}},
121 {{
"account deletion succeeded but deleted multiple accounts"}},
126 if (!sleA1 || !sleA2)
133 ac.view().erase(sleA1);
134 ac.view().erase(sleA2);
145 testcase <<
"account root deletion left artifact";
148 {{
"account deletion left behind a non-zero balance"}},
152 auto const a1 =
A1.id();
156 if (!BEAST_EXPECT(*sleA1->at(sfBalance) !=
beast::kZero))
159 ac.view().erase(sleA1);
167 {{
"account deletion left behind a non-zero owner count"}},
171 auto const a1 =
A1.id();
179 BEAST_EXPECT(sleA1->at(sfOwnerCount) == 0);
182 ac.view().erase(sleA1);
190 {{
"account deletion left behind a sponsorship field"}},
196 sleA1->setFieldU32(sfSponsoredOwnerCount, 1);
198 ac.view().erase(sleA1);
206 {{
"account deletion left behind a sponsorship field"}},
212 sleA1->setFieldU32(sfSponsoringOwnerCount, 1);
214 ac.view().erase(sleA1);
222 {{
"account deletion left behind a sponsorship field"}},
224 auto const a1Id = a1.
id();
229 sleA1->setFieldU32(sfSponsoringAccountCount, 1);
231 ac.view().erase(sleA1);
239 {{
"account deletion left behind a sponsorship field"}},
245 sleA1->setAccountID(sfSponsor, a2.id());
247 ac.view().erase(sleA1);
256 {{
"account deletion left behind a sponsorship field"}},
262 sleA1->setAccountID(sfSponsor, a2.id());
264 ac.view().erase(sleA1);
276 using namespace std::string_literals;
279 {{
"account deletion left behind a "s + type.cStr() +
" object"}},
284 auto const a1 =
A1.
id();
291 ac.view().insert(newSLE);
296 ac.view().erase(sleA1);
306 {{
"account deletion left behind a NFTokenPage object"}},
316 sle->at(sfOwnerCount) = 0;
317 ac.view().erase(sle);
336 {{
"account deletion left behind a DirectoryNode object"}},
344 BEAST_EXPECT(sle->at(~sfAMMID));
345 BEAST_EXPECT(sle->at(~sfAMMID) == ammKey);
351 sle->at(sfOwnerCount) = 0;
352 ac.view().erase(sle);
362 AMM const amm(env, a1,
XRP(100), a1[
"USD"](50));
363 ammAcctID =
amm.ammAccount();
364 ammKey =
amm.ammID();
365 ammIssue =
amm.lptIssue();
369 {{
"account deletion left behind a AMM object"}},
378 BEAST_EXPECT(sle->at(~sfAMMID));
379 BEAST_EXPECT(sle->at(~sfAMMID) == ammKey);
381 for (
auto const& trustKeylet :
384 auto const line = ac.view().peek(trustKeylet);
390 STAmount const lowLimit = line->at(sfLowLimit);
391 STAmount const highLimit = line->at(sfHighLimit);
401 auto const ammSle = ac.view().peek(
keylet::amm(ammKey));
402 if (!BEAST_EXPECT(ammSle))
407 ac.view().dirRemove(ownerDirKeylet, ammSle->at(sfOwnerNode), ammKey,
false));
409 !ac.view().exists(ownerDirKeylet) || ac.view().emptyDirDelete(ownerDirKeylet));
415 sle->at(sfOwnerCount) = 0;
416 ac.view().erase(sle);
426 AMM const amm(env, a1,
XRP(100), a1[
"USD"](50));
427 ammAcctID =
amm.ammAccount();
428 ammKey =
amm.ammID();
429 ammIssue =
amm.lptIssue();
438 testcase <<
"ledger entry types don't match";
440 {{
"ledger entry type mismatch"}, {
"XRP net change of -1000000000 doesn't match fee 0"}},
447 ac.rawView().rawReplace(sleNew);
452 {{
"invalid ledger entry type added"}},
468 ac.view().insert(sleNew);
480 {{
"Cannot return non-native STAmount as XRPAmount"}},
486 STAmount const nonNative(a2[
"USD"](51));
487 sle->setFieldAmount(sfBalance, nonNative);
488 ac.view().update(sle);
493 {{
"incorrect account XRP balance"}, {
"XRP net change was positive: 99999999000000001"}},
502 BEAST_EXPECT(!sle->getFieldAmount(sfBalance).negative());
503 ac.view().update(sle);
509 {
"incorrect account XRP balance"},
510 {
"XRP net change of -1000000001 doesn't match fee 0"},
517 sle->setFieldAmount(sfBalance,
STAmount{1,
true});
518 BEAST_EXPECT(sle->getFieldAmount(sfBalance).negative());
519 ac.view().update(sle);
528 using namespace std::string_literals;
529 testcase <<
"Transaction fee checks";
532 {{
"fee paid was negative: -1"}, {
"XRP net change of 0 doesn't match fee -1"}},
546 {
"fee paid is 20 exceeds fee specified in transaction."},
547 {
"XRP net change of 0 doesn't match fee 20"},
568 sleNew->setAccountID(sfAccount, a1.
id());
569 sleNew->setFieldU32(sfSequence, (*sle)[sfSequence]);
570 sleNew->setFieldAmount(sfTakerPays,
XRP(-1));
571 ac.view().insert(sleNew);
583 sleNew->setAccountID(sfAccount, a1.
id());
584 sleNew->setFieldU32(sfSequence, (*sle)[sfSequence]);
585 sleNew->setFieldAmount(sfTakerPays, a1[
"USD"](10));
586 sleNew->setFieldAmount(sfTakerGets,
XRP(-1));
587 ac.view().insert(sleNew);
599 sleNew->setAccountID(sfAccount, a1.
id());
600 sleNew->setFieldU32(sfSequence, (*sle)[sfSequence]);
601 sleNew->setFieldAmount(sfTakerPays,
XRP(10));
602 sleNew->setFieldAmount(sfTakerGets,
XRP(11));
603 ac.view().insert(sleNew);
612 testcase <<
"valid new account root";
615 {{
"account root created illegally"}},
622 ac.view().insert(sleNew);
627 {{
"multiple accounts created in a single transaction"}},
634 ac.view().insert(sleA3);
640 ac.view().insert(sleA4);
646 {{
"account created with wrong starting sequence number"}},
652 sleNew->setFieldU32(sfSequence, ac.view().seq() + 1);
653 ac.view().insert(sleNew);
660 {{
"pseudo-account created by a wrong transaction type"}},
665 sleNew->setFieldU32(sfSequence, 0);
666 sleNew->setFieldH256(sfAMMID,
UInt256(1));
667 sleNew->setFieldU32(sfFlags, lsfDisableMaster | lsfDefaultRipple);
668 ac.view().insert(sleNew);
675 {{
"account created with wrong starting sequence number"}},
680 sleNew->setFieldU32(sfSequence, ac.view().seq());
681 sleNew->setFieldH256(sfAMMID,
UInt256(1));
682 sleNew->setFieldU32(sfFlags, lsfDisableMaster | lsfDefaultRipple | lsfDepositAuth);
683 ac.view().insert(sleNew);
690 {{
"pseudo-account created with wrong flags"}},
695 sleNew->setFieldU32(sfSequence, 0);
696 sleNew->setFieldH256(sfAMMID,
UInt256(1));
697 sleNew->setFieldU32(sfFlags, lsfDisableMaster | lsfDefaultRipple);
698 ac.view().insert(sleNew);
705 {{
"pseudo-account created with wrong flags"}},
710 sleNew->setFieldU32(sfSequence, 0);
711 sleNew->setFieldH256(sfAMMID,
UInt256(1));
714 lsfDisableMaster | lsfDefaultRipple | lsfDepositAuth | lsfRequireDestTag);
715 ac.view().insert(sleNew);
725 testcase(
"no modified unmodifiable fields");
734 return BEAST_EXPECT(env.le(loanBrokerKeylet));
743 [](
SLE::pointer& sle) { sle->at(sfAccount) = sle->at(sfOwner); },
744 [](
SLE::pointer& sle) { sle->at(sfOwner) = sle->at(sfAccount); },
745 [](
SLE::pointer& sle) { sle->at(sfManagementFeeRate) += 1; },
746 [](
SLE::pointer& sle) { sle->at(sfCoverRateMinimum) += 1; },
747 [](
SLE::pointer& sle) { sle->at(sfCoverRateLiquidation) += 1; },
748 [](
SLE::pointer& sle) { sle->setFlag(lsfLoanBrokerPrivate); },
749 [](
SLE::pointer& sle) { sle->at(sfLedgerEntryType) += 1; },
750 [](
SLE::pointer& sle) { sle->at(sfLedgerIndex) = sle->at(sfVaultID).value(); },
753 for (
auto const& mod : mods)
756 {{
"changed an unchangeable field"}},
758 auto sle = ac.view().peek(loanBrokerKeylet);
762 ac.view().update(sle);
776 Env{*
this,
all_ - featureLendingProtocolV1_2},
779 auto const sle = ac.view().peek(loanBrokerKeylet);
782 sle->setFlag(lsfLoanBrokerPrivate);
783 ac.view().update(sle);
805 auto const cases = std::to_array<Case>({
807 .before = lsfLoanOverpayment,
809 .expected =
"lsfLoanOverpayment flag toggled on immutable ledger entry",
813 .after = lsfLoanOverpayment,
814 .expected =
"lsfLoanOverpayment flag toggled on immutable ledger entry",
817 .before = lsfLoanDefault,
819 .expected =
"lsfLoanDefault flag cleared on immutable ledger entry",
823 for (
auto const& c : cases)
832 auto const brokerKeylet =
836 auto const sleLoan =
makeLoanSle(brokerKeylet.key, 1, a1.
id());
837 sleLoan->at(sfPrincipalOutstanding) =
Number(100);
838 sleLoan->at(sfTotalValueOutstanding) =
Number(150);
839 sleLoan->setFieldU32(sfPaymentRemaining, 1);
840 sleLoan->setFieldU32(sfFlags, c.before);
851 auto const sleLoan = ac.
view().
peek(loanKeylet);
852 if (!BEAST_EXPECT(sleLoan))
854 sleLoan->setFieldU32(sfFlags, c.after);
858 if (!BEAST_EXPECT(transactor))
860 TER const result = transactor->checkInvariants(
863 BEAST_EXPECT(sink.
messages().
str().contains(c.expected));
873 auto const cases = std::to_array<std::pair<std::uint32_t, std::uint32_t>>({
874 {lsfLoanOverpayment, 0},
875 {0, lsfLoanOverpayment},
878 for (
auto const& [before,
after] : cases)
880 Env env{*
this,
all_ - featureLendingProtocolV1_1};
887 auto const brokerKeylet =
891 auto const sleLoan =
makeLoanSle(brokerKeylet.key, 1, a1.
id());
892 sleLoan->at(sfPrincipalOutstanding) =
Number(100);
893 sleLoan->at(sfTotalValueOutstanding) =
Number(150);
894 sleLoan->setFieldU32(sfPaymentRemaining, 1);
895 sleLoan->setFieldU32(sfFlags, before);
906 auto const sleLoan = ac.
view().
peek(loanKeylet);
907 if (!BEAST_EXPECT(sleLoan))
909 sleLoan->setFieldU32(sfFlags,
after);
913 if (!BEAST_EXPECT(transactor))
915 TER const result = transactor->checkInvariants(
918 BEAST_EXPECT(sink.
messages().
str().contains(
"Loan Overpayment flag changed"));
934 bool expectFireIntegral;
935 bool expectFireTolerant;
940 auto const cases = std::to_array<Case>({
942 .totalValue =
Number(100),
944 .managementFee =
Number(0),
945 .expectFireIntegral =
false,
946 .expectFireTolerant =
false,
951 .managementFee =
Number(0),
952 .expectFireIntegral =
true,
953 .expectFireTolerant =
false,
956 .totalValue =
Number(100),
958 .managementFee =
Number(0),
959 .expectFireIntegral =
true,
960 .expectFireTolerant =
false,
963 .totalValue =
Number(100),
965 .managementFee =
Number(1),
966 .expectFireIntegral =
true,
967 .expectFireTolerant =
false,
972 .managementFee =
Number(0),
973 .expectFireIntegral =
true,
974 .expectFireTolerant =
true,
978 for (
bool const integralAsset : {
true,
false})
980 for (
auto const& c : cases)
984 Account const issuer{
"issuer"};
985 env.
fund(
XRP(1000), a1, issuer);
995 env(
trust(a1, iouAsset(1000)));
996 env(
pay(issuer, a1, iouAsset(1000)));
1002 if (!BEAST_EXPECT(env.
le(brokerKeylet)))
1008 auto const loanKeylet =
1013 auto const sleLoan =
makeLoanSle(brokerKeylet.key, 1, a1.
id());
1014 sleLoan->at(sfPrincipalOutstanding) =
Number(100);
1015 sleLoan->at(sfTotalValueOutstanding) =
Number(100);
1016 sleLoan->at(sfManagementFeeOutstanding) =
Number(0);
1017 sleLoan->at(sfLoanScale) = 0;
1018 sleLoan->setFieldU32(sfPaymentRemaining, 1);
1029 auto const sleLoan = ac.
view().
peek(loanKeylet);
1030 if (!BEAST_EXPECT(sleLoan))
1032 sleLoan->at(sfTotalValueOutstanding) = c.totalValue;
1033 sleLoan->at(sfPrincipalOutstanding) = c.principal;
1034 sleLoan->at(sfManagementFeeOutstanding) = c.managementFee;
1038 if (!BEAST_EXPECT(transactor))
1040 TER const result = transactor->checkInvariants(
1043 if (integralAsset ? c.expectFireIntegral : c.expectFireTolerant)
1046 BEAST_EXPECT(messages.contains(
"Loan interest due is negative"));
1052 BEAST_EXPECT(!messages.contains(
"Loan interest due is negative"));
1061 Preclose const createClosedEndedVault = [&,
this](
1063 auto const sub = env.now().time_since_epoch().count() + 60;
1065 Vault const vault{env};
1066 auto [tx,
keylet] = vault.create({
1070 .subscriptionDate = sub,
1071 .redemptionDate = red,
1074 closedEndedVaultKeylet =
keylet;
1075 return BEAST_EXPECT(env.le(closedEndedVaultKeylet));
1084 [](
SLE::pointer& sle) { sle->at(sfSubscriptionDate) += 1; },
1085 [](
SLE::pointer& sle) { sle->at(sfRedemptionDate) += 1; },
1088 for (
auto const& mod : mods)
1091 {{
"changed an unchangeable field"}},
1093 auto sle = ac.view().peek(closedEndedVaultKeylet);
1097 ac.view().update(sle);
1103 createClosedEndedVault);
1109 [](
SLE::pointer& sle) { sle->at(sfLedgerEntryType) += 1; },
1113 for (
auto const& mod : mods)
1116 {{
"changed an unchangeable field"}},
1122 ac.view().update(sle);
1133 bool const fixEnabled = features[fixCleanup3_1_3];
1141 auto const insertOrderedTrustLinePair = [](
ApplyContext& ac,
1145 auto const& badConfig,
1146 auto const& goodConfig) {
1147 char const*
const c1 =
"USD";
1148 char const*
const c2 =
"EUR";
1152 bool const k1First = k1.key < k2.key;
1153 auto const& badKey = k1First ? k1 : k2;
1154 auto const& goodKey = k1First ? k2 : k1;
1155 Issue const badIss{k1First ? a1[c1].currency : a1[c2].currency, a1.id()};
1156 Issue const goodIss{k1First ? a1[c2].currency : a1[c1].currency, a1.id()};
1159 badConfig(*sleBad, badIss);
1163 goodConfig(*sleGood, goodIss);
1179 insertOrderedTrustLinePair(
1197 fixEnabled ? failTers : passTers);
1204 "normal freeze was created",},}
1208 insertOrderedTrustLinePair(
1227 fixEnabled ? failTers : passTers);
1249 sleNew->setFieldU64(sfLockedAmount, 10);
1262 using namespace std::string_literals;
1265 auto const expectMessage =
1266 "SponsoredOwnerCount does not equal SponsoringOwnerCount delta.";
1273 sle->setFieldU32(sfSponsoredOwnerCount, 1);
1274 ac.view().update(sle);
1283 sle->setFieldU32(sfSponsoringOwnerCount, 1);
1284 ac.view().update(sle);
1290 auto const expectMessage =
1291 "OwnerCount must be greater than or equal to SponsoredOwnerCount.";
1298 sle->setFieldU32(sfOwnerCount, 0);
1299 sle->setFieldU32(sfSponsoredOwnerCount, 1);
1300 ac.view().update(sle);
1305 sle2->setFieldU32(sfSponsoringOwnerCount, 1);
1306 ac.view().update(sle2);
1312 auto const expectMessage =
1313 "SponsoredObjectOwnerCount does not equal SponsoredOwnerCount delta.";
1322 check->setAccountID(sfSponsor, a2.id());
1323 ac.view().update(
check);
1350 escrow->setFieldVL(sfBytecode,
Blob(1200, 0x00));
1351 escrow->setAccountID(sfSponsor, a2.id());
1352 ac.view().update(
escrow);
1362 sle1->setFieldU32(sfSponsoredOwnerCount, 1);
1363 sle2->setFieldU32(sfSponsoringOwnerCount, 1);
1364 ac.view().update(sle1);
1365 ac.view().update(sle2);
1372 using namespace std::chrono_literals;
1382 auto const expectMessage =
1383 "Invariant failed: Net delta of SponsoringAccountCount does "
1384 "not match net delta of sfSponsor presence.";
1391 sle->setFieldU32(sfSponsoringAccountCount, 1);
1392 ac.view().update(sle);
1401 sle->setAccountID(sfSponsor, a2.id());
1402 ac.view().update(sle);
1411 testcase <<
"object has pseudo-account";
1412 using namespace jtx;
1414 auto const amendments =
all_ | fixCleanup3_3_0;
1420 Env{*
this, amendments},
1421 {{
"deleted Vault without deleting its pseudo-account"}},
1423 auto const sle = ac.view().peek(vaultKeylet);
1426 ac.view().erase(sle);
1433 Vault const vault{env};
1434 auto [tx,
keylet] = vault.create({.owner = a1, .asset =
xrpIssue()});
1446 Env{*
this, amendments},
1447 {{
"deleted AMM without deleting its pseudo-account"}},
1449 auto const sle = ac.view().peek(
keylet::amm(ammID));
1452 ac.view().erase(sle);
1459 env.fund(
XRP(1'000), gw);
1460 AMM const amm(env, gw,
XRP(100), gw[
"USD"](100));
1461 ammID =
amm.ammID();
1470 Env{*
this, amendments},
1471 {{
"deleted LoanBroker without deleting its pseudo-account"}},
1473 auto const sle = ac.view().peek(loanBrokerKeylet);
1476 ac.view().erase(sle);
1485 return BEAST_EXPECT(env.le(loanBrokerKeylet));
1493 Env env{*
this, amendments};
1503 sleVault->makeFieldAbsent(sfAccount);
1513 auto const sle = ac.
view().
peek(vaultKeylet);
1514 if (!BEAST_EXPECT(sle))
1519 if (!BEAST_EXPECT(transactor))
1521 TER const result = transactor->checkInvariants(
1524 BEAST_EXPECT(sink.
messages().
str().contains(
"is missing pseudo-account field"));
1532 using namespace jtx;
1539 enum class ThrowFrom { VisitEntry, Finalize };
1543 ThrowFrom
const throwFrom;
1545 explicit ThrowingTxInvariantCheck(ThrowFrom throwFrom) : throwFrom(throwFrom)
1552 if (throwFrom == ThrowFrom::VisitEntry)
1559 if (throwFrom == ThrowFrom::Finalize)
1565 for (
auto const throwFrom : {ThrowFrom::VisitEntry, ThrowFrom::Finalize})
1583 if (!BEAST_EXPECT(sle))
1585 sle->at(sfSequence) = sle->at(sfSequence) + 1;
1588 ThrowingTxInvariantCheck throwing{throwFrom};
1593 BEAST_EXPECT(terExpect == terActual);
1595 "Transaction caused an exception during invariant checks"));
1603 testcase <<
"txCheck finalize returns false";
1604 using namespace jtx;
1637 FailingTxInvariantCheck failing;
1642 BEAST_EXPECT(terExpect == terActual);
1644 "Transaction has failed one or more transaction invariants"));
1648 "Transaction has failed one or more global invariants"));
A generic endpoint for log messages.
TestcaseT testcase
Memberspace for declaring test cases.
State information when applying a tx.
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.
virtual void erase(SLE::Ref sle)=0
Remove a peeked SLE.
virtual void update(SLE::Ref sle)=0
Indicate changes to a peeked SLE.
RAII class to set and restore the current transaction rules.
A currency issued by an account.
constexpr MPTID const & getMptID() const
Number is a floating point type that can represent a wide range of values.
Writable ledger view that accumulates state and tx changes.
void rawInsert(SLE::Ref sle) override
Unconditionally insert a state item.
Rules const & rules() const override
Returns the tx processing rules.
LedgerIndex seq() const
Returns the sequence number of the base ledger.
AccountID const & getIssuer() const
std::shared_ptr< STLedgerEntry > pointer
std::shared_ptr< STLedgerEntry const > const & ConstRef
void setFieldU32(SField const &field, std::uint32_t)
void setFieldAmount(SField const &field, STAmount const &)
static constexpr SeqProxy rawSequence(std::uint32_t v)
Factory function to return a sequence-based SeqProxy.
Runtime interface for a transaction-specific invariant check.
Keylet createLoanBroker(jtx::Account const &a, jtx::Env &env, jtx::PrettyAsset const &asset)
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.
static SLE::pointer makeLoanSle(UInt256 const &loanBrokerID, std::uint32_t loanSeq, AccountID const &borrower)
std::function< bool(test::jtx::Account const &a, test::jtx::Account const &b, test::jtx::Env &env)> Preclose
void testXRPBalanceCheck()
void testTransactionFeeCheck()
void testNoModifiedUnmodifiableFields()
void testInvariantOverwrite(FeatureBitset features)
void testObjectHasPseudoAccount()
void testAccountRootsNotRemoved()
void testTxCheckException()
void testTxCheckFinalizeFalse()
void run() override
Runs the suite.
void testAccountRootsDeletedClean()
void testValidNewAccountRoot()
std::stringstream const & messages() const
Convenience class to test AMM functionality.
Immutable cryptographic account descriptor.
AccountID id() const
Returns the Account ID.
A transaction testing environment.
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
SLE::const_pointer le(Account const &account) const
Return an account root.
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Keylet computation functions.
Keylet escrow(AccountID const &src, SeqProxy const &seq) noexcept
An escrow entry.
Keylet offer(AccountID const &id, SeqProxy const &seq) noexcept
An offer from an account.
Keylet const & amendments() noexcept
The index of the amendment table.
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet check(AccountID const &id, SeqProxy const &seq) noexcept
A Check.
Keylet amm(Asset const &issue1, Asset const &issue2) noexcept
AMM entry.
Keylet unchecked(UInt256 const &key) noexcept
Any ledger entry.
Keylet vault(AccountID const &owner, SeqProxy const &seq) noexcept
Keylet loanBroker(AccountID const &owner, SeqProxy const &seq) noexcept
Keylet account(AccountID const &id) noexcept
AccountID root.
Keylet loan(UInt256 const &loanBrokerID, SeqProxy const &loanSeq) noexcept
Keylet mptokenIssuance(MPTID const &issuanceID) noexcept
Keylet trustLine(AccountID const &id0, AccountID const &id1, Currency const ¤cy) noexcept
The index of a trust line for a given currency.
json::Value create(A const &account, A const &dest, STAmount const &sendMax)
Create a check.
json::Value create(AccountID const &account, AccountID const &to, STAmount const &amount)
auto const kCancelTime
Set the "CancelAfter" time tag on a JTx.
std::array< std::uint8_t, 39 > const kCb1
json::Value mint(jtx::Account const &account, std::uint32_t nfTokenTaxon)
Mint an NFToken.
json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
XrpT const XRP
Converts to XRP Issue or STAmount.
FeatureBitset testableAmendments()
json::Value trust(Account const &account, STAmount const &amount, std::uint32_t flags)
Modify a trust line.
PrettyAmount drops(Integer i)
Returns an XRP PrettyAmount, which is trivially convertible to STAmount.
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
constexpr XRPAmount
Convert XRP to drops (integral types).
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Issue const & xrpIssue()
Returns an asset specifier that represents XRP.
void increaseOwnerCount(ApplyView &view, SLE::Ref accountSle, SLE::Ref sponsorSle, std::uint32_t count, beast::Journal j)
Increase owner-count fields when the caller supplies the sponsor.
std::string to_string(BaseUInt< Bits, Tag > const &a)
TER checkInvariants(ApplyContext &ctx, TER result, XRPAmount fee, std::optional< std::reference_wrapper< TxInvariantCheck > > txCheck)
Run all protocol invariant checks plus the transaction-specific check in a single pass over the modif...
std::unique_ptr< Transactor > makeTransactor(ApplyContext &ctx)
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
MPTID makeMptID(std::uint32_t const sequence, AccountID const &account)
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
TERSubset< CanCvtToTER > TER
LedgerEntryType
Identifiers for on-ledger objects.
std::vector< unsigned char > Blob
Storage for linear binary data.
constexpr std::uint64_t kMaxMpTokenAmount
The maximum amount of MPTokenIssuance.
constexpr XRPAmount kInitialXrp
Configure the native currency.
TER trustDelete(ApplyView &view, SLE::Ref sleRippleState, AccountID const &uLowAccountID, AccountID const &uHighAccountID, beast::Journal j)
std::array< KeyletDesc< AccountID const & >, 6 > const kDirectAccountKeylets
constexpr std::uint32_t kMinInvestmentPeriod
Bounds on the length of a closed-ended vault's Investment phase (RedemptionDate - SubscriptionDate).
A pair of SHAMap key and LedgerEntryType.