22#include <xrpld/app/tx/applySteps.h>
23#include <xrpld/ledger/Dir.h>
25#include <xrpl/protocol/Feature.h>
26#include <xrpl/protocol/Indexes.h>
27#include <xrpl/protocol/TxFlags.h>
28#include <xrpl/protocol/jss.h>
42 {0xA0, 0x25, 0x80, 0x20, 0xE3, 0xB0, 0xC4, 0x42, 0x98, 0xFC,
43 0x1C, 0x14, 0x9A, 0xFB, 0xF4, 0xC8, 0x99, 0x6F, 0xB9, 0x24,
44 0x27, 0xAE, 0x41, 0xE4, 0x64, 0x9B, 0x93, 0x4C, 0xA4, 0x95,
45 0x99, 0x1B, 0x78, 0x52, 0xB8, 0x55, 0x81, 0x01, 0x00}};
49 {0xA0, 0x05, 0x80, 0x03, 0x61, 0x61, 0x61}};
52 {0xA0, 0x25, 0x80, 0x20, 0x98, 0x34, 0x87, 0x6D, 0xCF, 0xB0,
53 0x5C, 0xB1, 0x67, 0xA5, 0xC2, 0x49, 0x53, 0xEB, 0xA5, 0x8C,
54 0x4A, 0xC8, 0x9B, 0x1A, 0xDF, 0x57, 0xF2, 0x8F, 0x2F, 0x9D,
55 0x09, 0xAF, 0x10, 0x7E, 0xE8, 0xF0, 0x81, 0x01, 0x03}};
59 {0xA0, 0x06, 0x80, 0x04, 0x6E, 0x69, 0x6B, 0x62}};
62 {0xA0, 0x25, 0x80, 0x20, 0x6E, 0x4C, 0x71, 0x45, 0x30, 0xC0,
63 0xA4, 0x26, 0x8B, 0x3F, 0xA6, 0x3B, 0x1B, 0x60, 0x6F, 0x2D,
64 0x26, 0x4A, 0x2D, 0x85, 0x7B, 0xE8, 0xA0, 0x9C, 0x1D, 0xFD,
65 0x57, 0x0D, 0x15, 0x85, 0x8B, 0xD4, 0x81, 0x01, 0x04}};
76 env.
fund(
XRP(5000),
"alice",
"bob");
80 auto const seq1 = env.
seq(
"alice");
87 env(
finish(
"bob",
"alice", seq1),
92 auto const seq2 = env.
seq(
"alice");
100 env(
cancel(
"bob",
"alice", seq2),
fee(1500));
112 env.
fund(
XRP(5000),
"alice",
"bob");
116 auto const ts = env.
now() + 97s;
118 auto const seq = env.
seq(
"alice");
134 env.
fund(
XRP(5000),
"alice",
"bob");
138 auto const ts = env.
now() + 117s;
140 auto const seq = env.
seq(
"alice");
164 testcase(
"Timing: Finish and Cancel -> Finish");
166 env.
fund(
XRP(5000),
"alice",
"bob");
170 auto const fts = env.
now() + 117s;
171 auto const cts = env.
now() + 192s;
173 auto const seq = env.
seq(
"alice");
180 for (; env.
now() < fts; env.
close())
198 testcase(
"Timing: Finish and Cancel -> Cancel");
200 env.
fund(
XRP(5000),
"alice",
"bob");
204 auto const fts = env.
now() + 109s;
205 auto const cts = env.
now() + 184s;
207 auto const seq = env.
seq(
"alice");
214 for (; env.
now() < fts; env.
close())
226 for (; env.
now() < cts; env.
close())
250 auto const alice =
Account(
"alice");
251 auto const bob =
Account(
"bob");
253 env.
fund(
XRP(5000), alice, bob);
263 auto const seq = env.
seq(alice);
272 BEAST_EXPECT((*sle)[sfSourceTag] == 1);
273 BEAST_EXPECT((*sle)[sfDestinationTag] == 2);
288 env.
fund(
XRP(5000),
"bob",
"george");
299 env.
fund(
XRP(5000),
"bob",
"george");
312 testcase(
"Implied Finish Time (without fix1571)");
315 env.
fund(
XRP(5000),
"alice",
"bob",
"carol");
320 auto const seq1 = env.
seq(
"alice");
325 env(
finish(
"carol",
"alice", seq1),
fee(1500));
326 BEAST_EXPECT(env.
balance(
"bob") ==
XRP(5100));
332 auto const seq2 = env.
seq(
"alice");
338 env(
finish(
"carol",
"alice", seq2),
342 BEAST_EXPECT(env.
balance(
"bob") ==
XRP(5200));
346 testcase(
"Implied Finish Time (with fix1571)");
349 env.
fund(
XRP(5000),
"alice",
"bob",
"carol");
360 auto const seq = env.
seq(
"alice");
370 BEAST_EXPECT(env.
balance(
"bob") ==
XRP(5100));
383 env.
fund(
XRP(5000),
"alice",
"bob");
413 env(
escrow(
"alice",
"carol",
XRP(-1000)),
460 auto const accountReserve =
drops(env.
current()->fees().reserve);
461 auto const accountIncrement =
464 env.
fund(accountReserve + accountIncrement +
XRP(50),
"daniel");
469 env.
fund(accountReserve + accountIncrement +
XRP(50),
"evan");
474 env.
fund(accountReserve,
"frank");
482 auto const seq = env.
seq(
"hannah");
494 auto const seq = env.
seq(
"ivan");
517 env.
fund(
XRP(5000),
"alice",
"bob");
518 auto const seq = env.
seq(
"alice");
541 env.
fund(
XRP(5000),
"alice",
"bob",
"zelda");
542 auto const seq = env.
seq(
"alice");
567 env.
fund(
XRP(5000),
"alice",
"bob",
"zelda");
571 auto const seq = env.
seq(
"alice");
595 auto const baseFee = env.
current()->fees().base;
605 env.
fund(
XRP(5000),
"alice",
"bob",
"zelda");
611 auto const seq = env.
seq(
"alice");
623 auto const baseFee = env.
current()->fees().base;
631 env.
fund(
XRP(5000),
"alice",
"bob");
632 auto const seq = env.
seq(
"alice");
673 env.
fund(
XRP(5000),
"alice",
"bob");
674 auto const seq = env.
seq(
"alice");
709 env.
fund(
XRP(5000),
"alice",
"bob",
"zelda");
710 auto const seq = env.
seq(
"alice");
752 testcase(
"Escrow with CryptoConditions");
759 env.
fund(
XRP(5000),
"alice",
"bob",
"carol");
760 auto const seq = env.
seq(
"alice");
761 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 0);
765 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 1);
769 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 1);
773 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 1);
781 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 1);
787 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 1);
793 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 1);
802 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 1);
808 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 1);
814 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 1);
824 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 0);
827 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 0);
832 env.
fund(
XRP(5000),
"alice",
"bob",
"carol");
833 auto const seq = env.
seq(
"alice");
834 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 0);
848 env.
fund(
XRP(5000),
"alice",
"bob",
"carol");
850 auto const seq = env.
seq(
"alice");
854 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 1);
857 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 1);
865 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 1);
870 env.
fund(
XRP(5000),
"alice",
"bob",
"carol");
876 auto const p = v.
data();
877 auto const s = v.
size();
879 auto const ts = env.
now() + 1s;
912 auto const seq = env.
seq(
"alice");
927 env.
fund(
XRP(5000),
"alice",
"bob",
"carol");
933 auto const cp = cv.
data();
934 auto const cs = cv.
size();
940 auto const fp = fv.
data();
941 auto const fs = fv.
size();
943 auto const ts = env.
now() + 1s;
976 auto const seq = env.
seq(
"alice");
1073 env.
fund(
XRP(5000),
"alice",
"bob",
"carol");
1075 env(
escrow(
"alice",
"carol",
XRP(1000)),
1080 auto const seq = env.
seq(
"alice");
1081 env(
escrow(
"alice",
"carol",
XRP(1000)),
1119 env.
fund(
XRP(5000),
"alice",
"bob");
1122 {0xA2, 0x2B, 0x80, 0x20, 0x42, 0x4A, 0x70, 0x49, 0x49,
1123 0x52, 0x92, 0x67, 0xB6, 0x21, 0xB3, 0xD7, 0x91, 0x19,
1124 0xD7, 0x29, 0xB2, 0x38, 0x2C, 0xED, 0x8B, 0x29, 0x6C,
1125 0x3C, 0x02, 0x8F, 0xA9, 0x7D, 0x35, 0x0F, 0x6D, 0x07,
1126 0x81, 0x03, 0x06, 0x34, 0xD2, 0x82, 0x02, 0x03, 0xC8}};
1140 using namespace jtx;
1143 auto const alice =
Account(
"alice");
1144 auto const bruce =
Account(
"bruce");
1145 auto const carol =
Account(
"carol");
1151 env.
fund(
XRP(5000), alice, bruce, carol);
1152 auto const aseq = env.
seq(alice);
1153 auto const bseq = env.
seq(bruce);
1159 (*env.
meta())[sfTransactionResult] ==
1176 (*env.
meta())[sfTransactionResult] ==
1190 env(
finish(alice, alice, aseq));
1194 (*env.
meta())[sfTransactionResult] ==
1209 env(
cancel(bruce, bruce, bseq));
1213 (*env.
meta())[sfTransactionResult] ==
1226 env.
fund(
XRP(5000), alice, bruce, carol);
1227 auto const aseq = env.
seq(alice);
1228 auto const bseq = env.
seq(bruce);
1232 (*env.
meta())[sfTransactionResult] ==
1239 (*env.
meta())[sfTransactionResult] ==
1269 env(
finish(alice, alice, aseq));
1291 env(
cancel(bruce, bruce, bseq));
1319 using namespace jtx;
1328 auto const jtx = env.
jt(
1340 BEAST_EXPECT(!pf.consequences.isBlocker());
1341 BEAST_EXPECT(pf.consequences.fee() ==
drops(10));
1342 BEAST_EXPECT(pf.consequences.potentialSpend() ==
XRP(1000));
1346 auto const jtx = env.
jt(
cancel(
"bob",
"alice", 3),
seq(1),
fee(10));
1354 BEAST_EXPECT(!pf.consequences.isBlocker());
1355 BEAST_EXPECT(pf.consequences.fee() ==
drops(10));
1356 BEAST_EXPECT(pf.consequences.potentialSpend() ==
XRP(0));
1360 auto const jtx = env.
jt(
finish(
"bob",
"alice", 3),
seq(1),
fee(10));
1368 BEAST_EXPECT(!pf.consequences.isBlocker());
1369 BEAST_EXPECT(pf.consequences.fee() ==
drops(10));
1370 BEAST_EXPECT(pf.consequences.potentialSpend() ==
XRP(0));
1379 using namespace jtx;
1387 env.
fund(
XRP(5000), alice, bob);
1410 auto const ts = env.
now() + 97s;
1416 BEAST_EXPECT(env.
seq(alice) == aliceRootSeq);
1422 for (; env.
now() < ts; env.
close())
1424 env(
finish(bob, alice, escrowSeq),
1428 BEAST_EXPECT(env.
seq(bob) == bobRootSeq);
1432 env(
finish(bob, alice, escrowSeq),
1438 env(
finish(bob, alice, escrowSeq),
1442 BEAST_EXPECT(env.
seq(bob) == bobRootSeq);
1448 env.
fund(
XRP(5000), alice, bob);
1470 auto const ts = env.
now() + 117s;
1477 BEAST_EXPECT(env.
seq(alice) == aliceRootSeq);
1483 for (; env.
now() < ts; env.
close())
1485 env(
cancel(bob, alice, escrowSeq),
1489 BEAST_EXPECT(env.
seq(bob) == bobRootSeq);
1493 env(
finish(bob, alice, escrowSeq),
1499 BEAST_EXPECT(env.
seq(bob) == bobRootSeq);
1502 env(
cancel(bob, alice, escrowSeq),
1506 BEAST_EXPECT(env.
seq(bob) == bobRootSeq);
1518 using namespace jtx;
1524 Account const dillon{
"dillon "};
1527 const char credType[] =
"abcde";
1532 env.
fund(
XRP(5000), alice, bob);
1535 auto const seq = env.
seq(alice);
1545 "48004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6EA288B"
1555 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);
1602 testcase(
"Escrow with credentials without depositPreauth");
1607 env.
fund(
XRP(5000), alice, bob, carol, dillon, zelda);
1616 std::string const credIdx = jv[jss::result][jss::index].asString();
1618 auto const seq = env.
seq(alice);
1633 const char credType2[] =
"fghijk";
1639 auto const credIdxBob =
1641 env, bob, zelda, credType2)[jss::result][jss::index]
1644 auto const seq = env.
seq(alice);
std::string asString() const
Returns the unquoted string value.
testcase_t testcase
Memberspace for declaring test cases.
A class that simplifies iterating ledger directory pages.
const_iterator end() const
const_iterator begin() const
An immutable linear range of bytes.
Immutable cryptographic account descriptor.
A transaction testing environment.
std::uint32_t seq(Account const &account) const
Returns the next sequence number on account.
void require(Args const &... args)
Check a set of requirements.
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
JTx jt(JsonValue &&jv, FN const &... fN)
Create a JTx from parameters.
NetClock::time_point now()
Returns the current network time.
beast::Journal const journal
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
std::shared_ptr< STObject const > meta()
Return metadata for the last JTx.
PrettyAmount balance(Account const &account) const
Returns the XRP balance on an account.
void memoize(Account const &account)
Associate AccountID with account.
std::shared_ptr< SLE const > le(Account const &account) const
Return an account root.
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, std::uint32_t seq) noexcept
An escrow entry.
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Json::Value create(jtx::Account const &subject, jtx::Account const &issuer, std::string_view credType)
Json::Value accept(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 auth(Account const &account, Account const &auth)
Preauthorize for deposit.
Json::Value authCredentials(jtx::Account const &account, std::vector< AuthorizeCredentials > const &auth)
Json::Value create(Account const &account, std::uint32_t count)
Create one of more tickets.
Json::Value escrow(AccountID const &account, AccountID const &to, STAmount const &amount)
PrettyAmount drops(Integer i)
Returns an XRP PrettyAmount, which is trivially convertible to STAmount.
Json::Value fset(Account const &account, std::uint32_t on, std::uint32_t off=0)
Add and/or remove flag.
Json::Value cancel(AccountID const &account, Account const &from, std::uint32_t seq)
Json::Value finish(AccountID const &account, AccountID const &from, std::uint32_t seq)
owner_count< ltTICKET > tickets
Match the number of tickets on the account.
XRP_t const XRP
Converts to XRP Issue or STAmount.
FeatureBitset supported_amendments()
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
constexpr std::uint32_t asfDepositAuth
PreflightResult preflight(Application &app, Rules const &rules, STTx const &tx, ApplyFlags flags, beast::Journal j)
Gate a transaction based on static information.
constexpr std::uint32_t asfRequireDest
@ tecCRYPTOCONDITION_ERROR
@ tecINSUFFICIENT_RESERVE
constexpr std::uint32_t asfDisallowXRP
std::array< std::uint8_t, 39 > const cb2
void run() override
Runs the suite.
void testEscrowWithTickets()
void testEscrowConditions()
void testMetaAndOwnership()
std::array< std::uint8_t, 39 > const cb3
std::array< std::uint8_t, 7 > const fb2
std::array< std::uint8_t, 8 > const fb3
std::array< std::uint8_t, 39 > const cb1
std::array< std::uint8_t, 4 > const fb1
Set the "CancelAfter" time tag on a JTx.
Set the destination tag on a JTx.
Set the "FinishAfter" time tag on a JTx.
Set the sequence number on a JTx.
Set the source tag on a JTx.