2#include <test/jtx/Env.h>
3#include <test/jtx/TestHelpers.h>
4#include <test/jtx/amount.h>
5#include <test/jtx/balance.h>
6#include <test/jtx/credentials.h>
7#include <test/jtx/deposit.h>
8#include <test/jtx/escrow.h>
9#include <test/jtx/fee.h>
10#include <test/jtx/flags.h>
11#include <test/jtx/seq.h>
12#include <test/jtx/tag.h>
13#include <test/jtx/ter.h>
14#include <test/jtx/ticket.h>
15#include <test/jtx/txflags.h>
17#include <xrpl/basics/Slice.h>
18#include <xrpl/beast/unit_test/suite.h>
19#include <xrpl/ledger/ApplyView.h>
20#include <xrpl/protocol/Feature.h>
21#include <xrpl/protocol/Indexes.h>
22#include <xrpl/protocol/SField.h>
23#include <xrpl/protocol/SeqProxy.h>
24#include <xrpl/protocol/TER.h>
25#include <xrpl/protocol/TxFlags.h>
26#include <xrpl/protocol/jss.h>
27#include <xrpl/tx/applySteps.h>
48 Env env(*
this, features);
49 auto const baseFee = env.
current()->fees().base;
50 env.
fund(
XRP(5000),
"alice",
"bob");
54 auto const seq1 = env.
seq(
"alice");
66 auto const seq2 = env.
seq(
"alice");
85 Env env(*
this, features);
86 auto const baseFee = env.
current()->fees().base;
87 env.
fund(
XRP(5000),
"alice",
"bob");
91 auto const ts = env.
now() + 97s;
93 auto const seq = env.
seq(
"alice");
106 Env env(*
this, features);
107 auto const baseFee = env.
current()->fees().base;
108 env.
fund(
XRP(5000),
"alice",
"bob");
112 auto const ts = env.
now() + 117s;
114 auto const seq = env.
seq(
"alice");
136 testcase(
"Timing: Finish and Cancel -> Finish");
137 Env env(*
this, features);
138 auto const baseFee = env.
current()->fees().base;
139 env.
fund(
XRP(5000),
"alice",
"bob");
143 auto const fts = env.
now() + 117s;
144 auto const cts = env.
now() + 192s;
146 auto const seq = env.
seq(
"alice");
153 for (; env.
now() < fts; env.
close())
167 testcase(
"Timing: Finish and Cancel -> Cancel");
168 Env env(*
this, features);
169 auto const baseFee = env.
current()->fees().base;
170 env.
fund(
XRP(5000),
"alice",
"bob");
174 auto const fts = env.
now() + 109s;
175 auto const cts = env.
now() + 184s;
177 auto const seq = env.
seq(
"alice");
184 for (; env.
now() < fts; env.
close())
192 for (; env.
now() < cts; env.
close())
212 Env env(*
this, features);
214 auto const alice =
Account(
"alice");
215 auto const bob =
Account(
"bob");
217 env.
fund(
XRP(5000), alice, bob);
221 env(
fset(bob, asfRequireDest));
227 auto const seq = env.
seq(alice);
236 BEAST_EXPECT((*sle)[sfSourceTag] == 1);
237 BEAST_EXPECT((*sle)[sfDestinationTag] == 2);
238 if (features[fixIncludeKeyletFields])
240 BEAST_EXPECT((*sle)[sfSequence] == seq);
244 BEAST_EXPECT(!sle->isFieldPresent(sfSequence));
259 Env env(*
this, features);
261 env.
fund(
XRP(5000),
"bob",
"george");
262 env(
fset(
"george", asfDisallowXRP));
273 testcase(
"RequiresConditionOrFinishAfter");
275 Env env(*
this, features);
276 auto const baseFee = env.
current()->fees().base;
277 env.
fund(
XRP(5000),
"alice",
"bob",
"carol");
288 auto const seq = env.
seq(
"alice");
298 BEAST_EXPECT(env.
balance(
"bob") ==
XRP(5100));
302 auto const seqFt = env.
seq(
"alice");
310 BEAST_EXPECT(env.
balance(
"bob") ==
XRP(5200));
321 Env env(*
this, features);
322 auto const baseFee = env.
current()->fees().base;
323 env.
fund(
XRP(5000),
"alice",
"bob",
"gw");
351 bool const withTokenEscrow = env.
current()->rules().enabled(featureTokenEscrow);
397 env(
fset(
"carol", asfRequireDest));
413 auto const accountIncrement =
drops(env.
current()->fees().increment);
433 auto const seq = env.
seq(
"hannah");
443 auto const seq = env.
seq(
"ivan");
465 Env env(*
this, features);
466 auto const baseFee = env.
current()->fees().base;
467 env.
fund(
XRP(5000),
"alice",
"bob");
468 auto const seq = env.
seq(
"alice");
489 Env env(*
this, features);
490 auto const baseFee = env.
current()->fees().base;
491 env.
fund(
XRP(5000),
"alice",
"bob",
"zelda");
492 auto const seq = env.
seq(
"alice");
515 Env env(*
this, features);
516 auto const baseFee = env.
current()->fees().base;
518 env.
fund(
XRP(5000),
"alice",
"bob",
"zelda");
519 env(
fset(
"bob", asfDepositAuth));
522 auto const seq = env.
seq(
"alice");
553 Env env(*
this, features);
554 auto const baseFee = env.
current()->fees().base;
556 env.
fund(
XRP(5000),
"alice",
"bob",
"zelda");
557 env(
fset(
"bob", asfDepositAuth));
562 auto const seq = env.
seq(
"alice");
580 Env env(*
this, features);
581 auto const baseFee = env.
current()->fees().base;
582 env.
fund(
XRP(5000),
"alice",
"bob");
583 auto const seq = env.
seq(
"alice");
622 Env env(*
this, features);
623 auto const baseFee = env.
current()->fees().base;
625 env.
fund(
XRP(5000),
"alice",
"bob");
626 auto const seq = env.
seq(
"alice");
639 env(
fset(
"alice", asfDepositAuth));
659 Env env(*
this, features);
660 auto const baseFee = env.
current()->fees().base;
662 env.
fund(
XRP(5000),
"alice",
"bob",
"zelda");
663 auto const seq = env.
seq(
"alice");
682 env(
fset(
"alice", asfDepositAuth));
705 testcase(
"Escrow with CryptoConditions");
711 Env env(*
this, features);
712 auto const baseFee = env.
current()->fees().base;
713 env.
fund(
XRP(5000),
"alice",
"bob",
"carol");
714 auto const seq = env.
seq(
"alice");
715 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 0);
719 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 1);
723 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 1);
727 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 1);
735 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 1);
741 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 1);
747 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 1);
756 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 1);
762 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 1);
768 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 1);
779 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 0);
782 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 0);
786 Env env(*
this, features);
787 auto const baseFee = env.
current()->fees().base;
788 env.
fund(
XRP(5000),
"alice",
"bob",
"carol");
789 auto const seq = env.
seq(
"alice");
790 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 0);
804 Env env(*
this, features);
805 auto const baseFee = env.
current()->fees().base;
806 env.
fund(
XRP(5000),
"alice",
"bob",
"carol");
808 auto const seq = env.
seq(
"alice");
812 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 1);
815 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 1);
823 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 1);
827 Env env(*
this, features);
828 env.
fund(
XRP(5000),
"alice",
"bob",
"carol");
834 auto const p = v.
data();
835 auto const s = v.
size();
837 auto const ts = env.
now() + 1s;
870 auto const seq = env.
seq(
"alice");
871 auto const baseFee = env.
current()->fees().base;
885 Env env(*
this, features);
886 env.
fund(
XRP(5000),
"alice",
"bob",
"carol");
892 auto const cp = cv.
data();
893 auto const cs = cv.
size();
899 auto const fp = fv.
data();
900 auto const fs = fv.
size();
902 auto const ts = env.
now() + 1s;
935 auto const seq = env.
seq(
"alice");
936 auto const baseFee = env.
current()->fees().base;
944 TER const malformedCondTer =
950 Ter(malformedCondTer));
955 Ter(malformedCondTer));
960 Ter(malformedCondTer));
965 Ter(malformedCondTer));
970 Ter(malformedCondTer));
975 Ter(malformedCondTer));
980 Ter(malformedCondTer));
1028 Fee(150 * baseFee));
1034 Env env(*
this, features);
1035 env.
fund(
XRP(5000),
"alice",
"bob",
"carol");
1042 auto const seq = env.
seq(
"alice");
1043 auto const baseFee = env.
current()->fees().base;
1048 TER const emptyCondTer =
1079 Fee(150 * baseFee));
1085 Env env(*
this, features);
1086 env.
fund(
XRP(5000),
"alice",
"bob");
1090 0xA2, 0x2B, 0x80, 0x20, 0x42, 0x4A, 0x70, 0x49, 0x49, 0x52, 0x92, 0x67,
1091 0xB6, 0x21, 0xB3, 0xD7, 0x91, 0x19, 0xD7, 0x29, 0xB2, 0x38, 0x2C, 0xED,
1092 0x8B, 0x29, 0x6C, 0x3C, 0x02, 0x8F, 0xA9, 0x7D, 0x35, 0x0F, 0x6D, 0x07,
1093 0x81, 0x03, 0x06, 0x34, 0xD2, 0x82, 0x02, 0x03, 0xC8,
1105 Env env(*
this, features);
1106 env.
fund(
XRP(5000),
"alice",
"bob",
"carol");
1109 auto const seq = env.
seq(
"alice");
1118 auto const baseFee = env.
current()->fees().base;
1119 auto const bobBalance = env.
balance(
"bob");
1120 bool const fixEnabled = features[fixCleanup3_5_0];
1121 auto const jt = env.
jt(
1125 Fee(150 * baseFee));
1131 BEAST_EXPECT(pf.ter == (fixEnabled ?
TER{temMALFORMED} :
TER{tesSUCCESS}));
1136 Balance(
"bob", fixEnabled ? bobBalance : bobBalance -
drops(150 * baseFee)));
1144 using namespace jtx;
1147 auto const alice =
Account(
"alice");
1148 auto const bruce =
Account(
"bruce");
1149 auto const carol =
Account(
"carol");
1154 Env env(*
this, features);
1155 env.
fund(
XRP(5000), alice, bruce, carol);
1156 auto const aseq = env.
seq(alice);
1157 auto const bseq = env.
seq(bruce);
1173 std::find(aod.begin(), aod.end(), aa) != aod.end());
1190 std::find(bod.begin(), bod.end(), bb) != bod.end());
1204 std::find(aod.begin(), aod.end(), aa) == aod.end());
1210 std::find(bod.begin(), bod.end(), bb) != bod.end());
1224 std::find(bod.begin(), bod.end(), bb) == bod.end());
1230 Env env(*
this, features);
1231 env.
fund(
XRP(5000), alice, bruce, carol);
1232 auto const aseq = env.
seq(alice);
1233 auto const bseq = env.
seq(bruce);
1257 std::find(aod.begin(), aod.end(), ab) != aod.end());
1263 std::find(bod.begin(), bod.end(), ab) != bod.end());
1266 std::find(bod.begin(), bod.end(), bc) != bod.end());
1272 std::find(cod.begin(), cod.end(), bc) != cod.end());
1285 std::find(aod.begin(), aod.end(), ab) == aod.end());
1291 std::find(bod.begin(), bod.end(), ab) == bod.end());
1294 std::find(bod.begin(), bod.end(), bc) != bod.end());
1310 std::find(aod.begin(), aod.end(), ab) == aod.end());
1316 std::find(bod.begin(), bod.end(), ab) == bod.end());
1319 std::find(bod.begin(), bod.end(), bc) == bod.end());
1332 using namespace jtx;
1334 Env env(*
this, features);
1335 auto const baseFee = env.
current()->fees().base;
1342 auto const jtx = env.
jt(
1350 BEAST_EXPECT(!pf.consequences.isBlocker());
1351 BEAST_EXPECT(pf.consequences.fee() ==
drops(baseFee));
1352 BEAST_EXPECT(pf.consequences.potentialSpend() ==
XRP(1000));
1360 BEAST_EXPECT(!pf.consequences.isBlocker());
1361 BEAST_EXPECT(pf.consequences.fee() ==
drops(baseFee));
1362 BEAST_EXPECT(pf.consequences.potentialSpend() ==
XRP(0));
1370 BEAST_EXPECT(!pf.consequences.isBlocker());
1371 BEAST_EXPECT(pf.consequences.fee() ==
drops(baseFee));
1372 BEAST_EXPECT(pf.consequences.potentialSpend() ==
XRP(0));
1381 using namespace jtx;
1388 Env env(*
this, features);
1389 auto const baseFee = env.
current()->fees().base;
1390 env.
fund(
XRP(5000), alice, bob);
1413 auto const ts = env.
now() + 97s;
1419 BEAST_EXPECT(env.
seq(alice) == aliceRootSeq);
1425 for (; env.
now() < ts; env.
close())
1431 BEAST_EXPECT(env.
seq(bob) == bobRootSeq);
1445 BEAST_EXPECT(env.
seq(bob) == bobRootSeq);
1449 Env env(*
this, features);
1450 auto const baseFee = env.
current()->fees().base;
1451 env.
fund(
XRP(5000), alice, bob);
1473 auto const ts = env.
now() + 117s;
1480 BEAST_EXPECT(env.
seq(alice) == aliceRootSeq);
1486 for (; env.
now() < ts; env.
close())
1492 BEAST_EXPECT(env.
seq(bob) == bobRootSeq);
1502 BEAST_EXPECT(env.
seq(bob) == bobRootSeq);
1509 BEAST_EXPECT(env.
seq(bob) == bobRootSeq);
1521 using namespace jtx;
1527 Account const dillon{
"dillon"};
1530 char const credType[] =
"abcde";
1534 Env env(*
this, features - featureCredentials);
1535 env.
fund(
XRP(5000), alice, bob);
1538 auto const seq = env.
seq(alice);
1542 env(
fset(bob, asfDepositAuth));
1548 "48004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6EA288B"
1554 Env env(*
this, features);
1556 env.
fund(
XRP(5000), alice, bob, carol, dillon, zelda);
1562 std::string const credIdx = jv[jss::result][jss::index].asString();
1564 auto const seq = env.
seq(alice);
1569 env(
fset(bob, asfDepositAuth));
1602 testcase(
"Escrow with credentials without depositPreauth");
1605 Env env(*
this, features);
1607 env.
fund(
XRP(5000), alice, bob, carol, dillon, zelda);
1615 std::string const credIdx = jv[jss::result][jss::index].asString();
1617 auto const seq = env.
seq(alice);
1632 char const credType2[] =
"random";
1638 auto const credIdxBob =
1642 auto const seq = env.
seq(alice);
1647 env(
fset(bob, asfDepositAuth));
1686 testWithFeats(all - featureTokenEscrow - featureSmartEscrow);
1687 testTags(all - fixIncludeKeyletFields);
TestcaseT testcase
Memberspace for declaring test cases.
std::string asString() const
Returns the unquoted string value.
static constexpr SeqProxy rawSequence(std::uint32_t v)
Factory function to return a sequence-based SeqProxy.
An immutable linear range of bytes.
Immutable cryptographic account descriptor.
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::uint32_t seq(Account const &account) const
Returns the next sequence number on account.
JTx jt(JsonValue &&jv, FN const &... fN)
Create a JTx from parameters.
PrettyAmount balance(Account const &account) const
Returns the XRP balance on an account.
std::shared_ptr< STObject const > meta()
Return metadata for the last JTx.
void memoize(Account const &account)
Associate AccountID with account.
beast::Journal const journal
void require(Args const &... args)
Check a set of requirements.
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
NetClock::time_point now()
Returns the current network time.
Set the expected result code for a JTx The test will fail if the code doesn't match.
Set a ticket sequence on a JTx.
Keylet escrow(AccountID const &src, SeqProxy const &seq) noexcept
An escrow entry.
json::Value accept(jtx::Account const &subject, jtx::Account const &issuer, std::string_view credType)
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 authCredentials(jtx::Account const &account, std::vector< AuthorizeCredentials > const &auth)
json::Value auth(Account const &account, Account const &auth)
Preauthorize for deposit.
json::Value create(AccountID const &account, AccountID const &to, STAmount const &amount)
json::Value cancel(AccountID const &account, Account const &from, std::uint32_t seq)
auto const kCancelTime
Set the "CancelAfter" time tag on a JTx.
auto const kFinishTime
Set the "FinishAfter" time tag on a JTx.
std::array< std::uint8_t, 8 > const kFb3
std::array< std::uint8_t, 7 > const kFb2
std::array< std::uint8_t, 39 > const kCb2
json::Value finish(AccountID const &account, AccountID const &from, std::uint32_t seq)
std::array< std::uint8_t, 4 > const kFb1
std::array< std::uint8_t, 39 > const kCb1
std::array< std::uint8_t, 39 > const kCb3
json::Value create(Account const &account, std::uint32_t count)
Create one of more tickets.
XrpT const XRP
Converts to XRP Issue or STAmount.
FeatureBitset testableAmendments()
std::vector< SLE::const_pointer > ownerDirEntries(ReadView const &view, AccountID const &account)
Return the ledger entries in an account's owner directory.
PrettyAmount drops(Integer i)
Returns an XRP PrettyAmount, which is trivially convertible to STAmount.
OwnerCount< ltTICKET > Tickets
Match the number of tickets on the account.
json::Value fset(Account const &account, std::uint32_t on, std::uint32_t off=0)
Add and/or remove flag.
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
static STAmount accountReserve(jtx::Env const &env, std::uint32_t count=1)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
PreflightResult preflight(ServiceRegistry ®istry, Rules const &rules, STTx const &tx, ApplyFlags flags, beast::Journal j)
Gate a transaction based on static information.
bool isTesSuccess(TER x) noexcept
TERSubset< CanCvtToTER > TER
@ tecCRYPTOCONDITION_ERROR
@ tecINSUFFICIENT_RESERVE
void testEscrowConditions(FeatureBitset features)
void testEnablement(FeatureBitset features)
void testFails(FeatureBitset features)
void testTags(FeatureBitset features)
void testMetaAndOwnership(FeatureBitset features)
void testWithFeats(FeatureBitset features)
void run() override
Runs the suite.
void testConsequences(FeatureBitset features)
void testEscrowWithTickets(FeatureBitset features)
void testDisallowXRP(FeatureBitset features)
void testCredentials(FeatureBitset features)
void testTiming(FeatureBitset features)
void testRequiresConditionOrFinishAfter(FeatureBitset features)
void testLockup(FeatureBitset features)
Set the destination tag on a JTx.
Set the sequence number on a JTx.
Set the source tag on a JTx.