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 auto const baseFee = env.
current()->fees().base;
77 env.
fund(
XRP(5000),
"alice",
"bob");
81 auto const seq1 = env.
seq(
"alice");
88 env(
finish(
"bob",
"alice", seq1),
93 auto const seq2 = env.
seq(
"alice");
101 env(
cancel(
"bob",
"alice", seq2),
fee(baseFee * 150));
113 auto const baseFee = env.
current()->fees().base;
114 env.
fund(
XRP(5000),
"alice",
"bob");
118 auto const ts = env.
now() + 97s;
120 auto const seq = env.
seq(
"alice");
136 auto const baseFee = env.
current()->fees().base;
137 env.
fund(
XRP(5000),
"alice",
"bob");
141 auto const ts = env.
now() + 117s;
143 auto const seq = env.
seq(
"alice");
167 testcase(
"Timing: Finish and Cancel -> Finish");
169 auto const baseFee = env.
current()->fees().base;
170 env.
fund(
XRP(5000),
"alice",
"bob");
174 auto const fts = env.
now() + 117s;
175 auto const cts = env.
now() + 192s;
177 auto const seq = env.
seq(
"alice");
184 for (; env.
now() < fts; env.
close())
204 testcase(
"Timing: Finish and Cancel -> Cancel");
206 auto const baseFee = env.
current()->fees().base;
207 env.
fund(
XRP(5000),
"alice",
"bob");
211 auto const fts = env.
now() + 109s;
212 auto const cts = env.
now() + 184s;
214 auto const seq = env.
seq(
"alice");
221 for (; env.
now() < fts; env.
close())
233 for (; env.
now() < cts; env.
close())
259 auto const alice =
Account(
"alice");
260 auto const bob =
Account(
"bob");
262 env.
fund(
XRP(5000), alice, bob);
272 auto const seq = env.
seq(alice);
281 BEAST_EXPECT((*sle)[sfSourceTag] == 1);
282 BEAST_EXPECT((*sle)[sfDestinationTag] == 2);
297 env.
fund(
XRP(5000),
"bob",
"george");
308 env.
fund(
XRP(5000),
"bob",
"george");
321 testcase(
"Implied Finish Time (without fix1571)");
324 auto const baseFee = env.
current()->fees().base;
325 env.
fund(
XRP(5000),
"alice",
"bob",
"carol");
330 auto const seq1 = env.
seq(
"alice");
335 env(
finish(
"carol",
"alice", seq1),
fee(baseFee * 150));
336 BEAST_EXPECT(env.
balance(
"bob") ==
XRP(5100));
342 auto const seq2 = env.
seq(
"alice");
348 env(
finish(
"carol",
"alice", seq2),
352 BEAST_EXPECT(env.
balance(
"bob") ==
XRP(5200));
356 testcase(
"Implied Finish Time (with fix1571)");
359 auto const baseFee = env.
current()->fees().base;
360 env.
fund(
XRP(5000),
"alice",
"bob",
"carol");
371 auto const seq = env.
seq(
"alice");
381 BEAST_EXPECT(env.
balance(
"bob") ==
XRP(5100));
394 auto const baseFee = env.
current()->fees().base;
395 env.
fund(
XRP(5000),
"alice",
"bob");
425 env(
escrow(
"alice",
"carol",
XRP(-1000)),
472 auto const accountReserve =
drops(env.
current()->fees().reserve);
473 auto const accountIncrement =
476 env.
fund(accountReserve + accountIncrement +
XRP(50),
"daniel");
481 env.
fund(accountReserve + accountIncrement +
XRP(50),
"evan");
486 env.
fund(accountReserve,
"frank");
494 auto const seq = env.
seq(
"hannah");
506 auto const seq = env.
seq(
"ivan");
529 auto const baseFee = env.
current()->fees().base;
530 env.
fund(
XRP(5000),
"alice",
"bob");
531 auto const seq = env.
seq(
"alice");
554 auto const baseFee = env.
current()->fees().base;
555 env.
fund(
XRP(5000),
"alice",
"bob",
"zelda");
556 auto const seq = env.
seq(
"alice");
580 auto const baseFee = env.
current()->fees().base;
582 env.
fund(
XRP(5000),
"alice",
"bob",
"zelda");
586 auto const seq = env.
seq(
"alice");
618 auto const baseFee = env.
current()->fees().base;
620 env.
fund(
XRP(5000),
"alice",
"bob",
"zelda");
626 auto const seq = env.
seq(
"alice");
645 auto const baseFee = env.
current()->fees().base;
646 env.
fund(
XRP(5000),
"alice",
"bob");
647 auto const seq = env.
seq(
"alice");
687 auto const baseFee = env.
current()->fees().base;
689 env.
fund(
XRP(5000),
"alice",
"bob");
690 auto const seq = env.
seq(
"alice");
724 auto const baseFee = env.
current()->fees().base;
726 env.
fund(
XRP(5000),
"alice",
"bob",
"zelda");
727 auto const seq = env.
seq(
"alice");
769 testcase(
"Escrow with CryptoConditions");
776 auto const baseFee = env.
current()->fees().base;
777 env.
fund(
XRP(5000),
"alice",
"bob",
"carol");
778 auto const seq = env.
seq(
"alice");
779 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 0);
783 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 1);
787 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 1);
791 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 1);
799 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 1);
805 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 1);
811 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 1);
820 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 1);
826 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 1);
832 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 1);
842 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 0);
845 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 0);
850 auto const baseFee = env.
current()->fees().base;
851 env.
fund(
XRP(5000),
"alice",
"bob",
"carol");
852 auto const seq = env.
seq(
"alice");
853 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 0);
867 auto const baseFee = env.
current()->fees().base;
868 env.
fund(
XRP(5000),
"alice",
"bob",
"carol");
870 auto const seq = env.
seq(
"alice");
874 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 1);
877 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 1);
885 BEAST_EXPECT((*env.
le(
"alice"))[sfOwnerCount] == 1);
890 env.
fund(
XRP(5000),
"alice",
"bob",
"carol");
896 auto const p = v.
data();
897 auto const s = v.
size();
899 auto const ts = env.
now() + 1s;
932 auto const seq = env.
seq(
"alice");
933 auto const baseFee = env.
current()->fees().base;
948 env.
fund(
XRP(5000),
"alice",
"bob",
"carol");
954 auto const cp = cv.
data();
955 auto const cs = cv.
size();
961 auto const fp = fv.
data();
962 auto const fs = fv.
size();
964 auto const ts = env.
now() + 1s;
997 auto const seq = env.
seq(
"alice");
998 auto const baseFee = env.
current()->fees().base;
1088 fee(150 * baseFee));
1095 env.
fund(
XRP(5000),
"alice",
"bob",
"carol");
1097 env(
escrow(
"alice",
"carol",
XRP(1000)),
1102 auto const seq = env.
seq(
"alice");
1103 auto const baseFee = env.
current()->fees().base;
1104 env(
escrow(
"alice",
"carol",
XRP(1000)),
1135 fee(150 * baseFee));
1142 env.
fund(
XRP(5000),
"alice",
"bob");
1145 {0xA2, 0x2B, 0x80, 0x20, 0x42, 0x4A, 0x70, 0x49, 0x49,
1146 0x52, 0x92, 0x67, 0xB6, 0x21, 0xB3, 0xD7, 0x91, 0x19,
1147 0xD7, 0x29, 0xB2, 0x38, 0x2C, 0xED, 0x8B, 0x29, 0x6C,
1148 0x3C, 0x02, 0x8F, 0xA9, 0x7D, 0x35, 0x0F, 0x6D, 0x07,
1149 0x81, 0x03, 0x06, 0x34, 0xD2, 0x82, 0x02, 0x03, 0xC8}};
1163 using namespace jtx;
1166 auto const alice =
Account(
"alice");
1167 auto const bruce =
Account(
"bruce");
1168 auto const carol =
Account(
"carol");
1174 env.
fund(
XRP(5000), alice, bruce, carol);
1175 auto const aseq = env.
seq(alice);
1176 auto const bseq = env.
seq(bruce);
1182 (*env.
meta())[sfTransactionResult] ==
1199 (*env.
meta())[sfTransactionResult] ==
1213 env(
finish(alice, alice, aseq));
1217 (*env.
meta())[sfTransactionResult] ==
1232 env(
cancel(bruce, bruce, bseq));
1236 (*env.
meta())[sfTransactionResult] ==
1249 env.
fund(
XRP(5000), alice, bruce, carol);
1250 auto const aseq = env.
seq(alice);
1251 auto const bseq = env.
seq(bruce);
1255 (*env.
meta())[sfTransactionResult] ==
1262 (*env.
meta())[sfTransactionResult] ==
1292 env(
finish(alice, alice, aseq));
1314 env(
cancel(bruce, bruce, bseq));
1342 using namespace jtx;
1345 auto const baseFee = env.
current()->fees().base;
1352 auto const jtx = env.
jt(
1364 BEAST_EXPECT(!pf.consequences.isBlocker());
1365 BEAST_EXPECT(pf.consequences.fee() ==
drops(baseFee));
1366 BEAST_EXPECT(pf.consequences.potentialSpend() ==
XRP(1000));
1379 BEAST_EXPECT(!pf.consequences.isBlocker());
1380 BEAST_EXPECT(pf.consequences.fee() ==
drops(baseFee));
1381 BEAST_EXPECT(pf.consequences.potentialSpend() ==
XRP(0));
1394 BEAST_EXPECT(!pf.consequences.isBlocker());
1395 BEAST_EXPECT(pf.consequences.fee() ==
drops(baseFee));
1396 BEAST_EXPECT(pf.consequences.potentialSpend() ==
XRP(0));
1405 using namespace jtx;
1413 auto const baseFee = env.
current()->fees().base;
1414 env.
fund(
XRP(5000), alice, bob);
1437 auto const ts = env.
now() + 97s;
1443 BEAST_EXPECT(env.
seq(alice) == aliceRootSeq);
1449 for (; env.
now() < ts; env.
close())
1451 env(
finish(bob, alice, escrowSeq),
1455 BEAST_EXPECT(env.
seq(bob) == bobRootSeq);
1459 env(
finish(bob, alice, escrowSeq),
1465 env(
finish(bob, alice, escrowSeq),
1469 BEAST_EXPECT(env.
seq(bob) == bobRootSeq);
1474 auto const baseFee = env.
current()->fees().base;
1475 env.
fund(
XRP(5000), alice, bob);
1497 auto const ts = env.
now() + 117s;
1504 BEAST_EXPECT(env.
seq(alice) == aliceRootSeq);
1510 for (; env.
now() < ts; env.
close())
1512 env(
cancel(bob, alice, escrowSeq),
1516 BEAST_EXPECT(env.
seq(bob) == bobRootSeq);
1520 env(
finish(bob, alice, escrowSeq),
1526 BEAST_EXPECT(env.
seq(bob) == bobRootSeq);
1529 env(
cancel(bob, alice, escrowSeq),
1533 BEAST_EXPECT(env.
seq(bob) == bobRootSeq);
1545 using namespace jtx;
1551 Account const dillon{
"dillon "};
1554 char const credType[] =
"abcde";
1559 env.
fund(
XRP(5000), alice, bob);
1562 auto const seq = env.
seq(alice);
1572 "48004829F915654A81B11C4AB8218D96FED67F209B58328A72314FB6EA288B"
1582 env.
fund(
XRP(5000), alice, bob, carol, dillon, zelda);
1589 std::string const credIdx = jv[jss::result][jss::index].asString();
1591 auto const seq = env.
seq(alice);
1629 testcase(
"Escrow with credentials without depositPreauth");
1634 env.
fund(
XRP(5000), alice, bob, carol, dillon, zelda);
1643 std::string const credIdx = jv[jss::result][jss::index].asString();
1645 auto const seq = env.
seq(alice);
1660 char const credType2[] =
"fghijk";
1666 auto const credIdxBob =
1668 env, bob, zelda, credType2)[jss::result][jss::index]
1671 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.