19#include <xrpld/ledger/BookDirs.h>
20#include <xrpld/ledger/Sandbox.h>
21#include <xrpl/basics/random.h>
22#include <xrpl/protocol/Feature.h>
23#include <xrpl/protocol/Protocol.h>
24#include <xrpl/protocol/jss.h>
37 BEAST_EXPECT(i < 17577);
41 for (
int j = 0; j != 3; ++j)
62 p->setFieldU64(sfIndexNext, 0);
64 p->setFieldU64(sfIndexNext, i + 1);
67 p->setFieldU64(sfIndexPrevious, n - 1);
69 p->setFieldU64(sfIndexPrevious, i - 1);
85 testcase(
"Directory Ordering (with 'SortedDirectories' amendment)");
88 env.
fund(
XRP(10000000), alice, gw);
99 auto const view = env.
closed();
109 auto const& v = p->getFieldV256(sfIndexes);
118 for (
auto const& e : v)
122 BEAST_EXPECT(c->getFieldU32(sfSequence) >= minSeq);
123 BEAST_EXPECT(c->getFieldU32(sfSequence) < maxSeq);
126 page = p->getFieldU64(sfIndexNext);
135 for (
auto const&
offer : book)
138 BEAST_EXPECT(
offer->getFieldAmount(sfTakerPays) == USD(count));
139 BEAST_EXPECT(
offer->getFieldAmount(sfTakerGets) ==
XRP(count));
149 auto const alice =
Account(
"alice");
150 auto const bob =
Account(
"bob");
151 auto const charlie =
Account(
"charlie");
156 env.
fund(
XRP(1000000), alice, charlie, gw);
163 env(
signers(alice, 1, {{bob, 1}}));
185 auto cl = currencies;
187 for (
auto const& c : cl)
189 env(
trust(alice, c(50)));
197 for (
auto const& c : cl)
199 env(
trust(alice, c(0)));
209 auto cl = currencies;
213 for (
auto c : currencies)
215 env(
trust(charlie, c(50)));
217 env(
pay(gw, charlie, c(50)));
230 for (
auto const& c : cl)
232 env(
offer(charlie,
XRP(50), c(50)));
241 for (
auto const& c : cl)
243 env(
pay(alice, charlie, c(50)));
254 testcase(
"RIPD-1353 Empty Offer Directories");
259 auto const gw =
Account{
"gateway"};
260 auto const alice =
Account{
"alice"};
261 auto const USD = gw[
"USD"];
263 env.
fund(
XRP(10000), alice, gw);
265 env.
trust(USD(1000), alice);
266 env(
pay(gw, alice, USD(1000)));
268 auto const firstOfferSeq = env.
seq(alice);
271 for (
int i = 0; i < 3; ++i)
277 for (
auto page : {0, 2, 1})
301 env.
trust(USD(0), alice);
302 env(
pay(alice, gw, alice[
"USD"](1000)));
316 auto const gw =
Account{
"gateway"};
317 auto const alice =
Account{
"alice"};
318 auto const USD = gw[
"USD"];
324 "fb71c9aa3310141da4b01d6c744a98286af2d72ab5448d5adc0910ca0c910880");
327 "bad0f021aa3b2f6754a8fe82a5779730aa0bbbab82f17201ef24900efc2c7312");
341 p->setFieldV256(sfIndexes, v);
366 p1->setFieldV256(sfIndexes, v1);
374 p2->setFieldV256(sfIndexes, v2);
388 BEAST_EXPECT(p1->getFieldU64(sfIndexNext) == 0);
389 BEAST_EXPECT(p1->getFieldU64(sfIndexPrevious) == 0);
393 BEAST_EXPECT(p0->getFieldU64(sfIndexNext) == 1);
394 BEAST_EXPECT(p0->getFieldU64(sfIndexPrevious) == 1);
404 auto const gw =
Account{
"gateway"};
405 auto const alice =
Account{
"alice"};
406 auto const USD = gw[
"USD"];
408 auto ledger_data = [
this](
Env& env) {
410 params[jss::type] = jss::directory;
411 params[jss::ledger_index] =
"validated";
413 env.rpc(
"json",
"ledger_data",
to_string(params))[jss::result];
414 BEAST_EXPECT(!result.isMember(jss::marker));
420 env.
fund(
XRP(10000), alice, gw);
422 env.
trust(USD(1000), alice);
423 env(
pay(gw, alice, USD(1000)));
427 auto const jrr = ledger_data(env);
428 auto const& jstate = jrr[jss::state];
430 for (
auto const& directory : jstate)
433 directory[
"LedgerEntryType"] ==
437 BEAST_EXPECT(!directory.isMember(
"PreviousTxnID"));
438 BEAST_EXPECT(!directory.isMember(
"PreviousTxnLgrSeq"));
449 auto const txID =
to_string(env.
tx()->getTransactionID());
450 auto const ledgerSeq = env.
current()->info().seq;
457 auto const jrr = ledger_data(env);
458 auto const& jstate = jrr[jss::state];
460 for (
auto const& directory : jstate)
463 directory[
"LedgerEntryType"] ==
465 if (directory[jss::Owner] == gw.human())
469 BEAST_EXPECT(!directory.isMember(
"PreviousTxnID"));
470 BEAST_EXPECT(!directory.isMember(
"PreviousTxnLgrSeq"));
478 directory.isMember(
"PreviousTxnID") &&
479 directory[
"PreviousTxnID"].asString() == txID);
481 directory.isMember(
"PreviousTxnLgrSeq") &&
482 directory[
"PreviousTxnLgrSeq"].asUInt() == ledgerSeq);
testcase_t testcase
Memberspace for declaring test cases.
bool dirRemove(Keylet const &directory, std::uint64_t page, uint256 const &key, bool keepRoot)
Remove an entry from a directory.
void push_back(uint256 const &v)
Discardable, editable view to a ledger.
void update(std::shared_ptr< SLE > const &sle) override
Indicate changes to a peeked SLE.
void insert(std::shared_ptr< SLE > const &sle) override
Insert a new state SLE.
std::optional< key_type > succ(key_type const &key, std::optional< key_type > const &last=std::nullopt) const override
Return the key of the next state item.
std::shared_ptr< SLE > peek(Keylet const &k) override
Prepare to modify the SLE associated with key.
Immutable cryptographic account descriptor.
A transaction testing environment.
std::shared_ptr< ReadView const > closed()
Returns the last closed ledger.
std::uint32_t seq(Account const &account) const
Returns the next sequence number on account.
std::shared_ptr< STTx const > tx() const
Return the tx data for the last JTx.
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.
void trust(STAmount const &amount, Account const &account)
Establish trust lines.
void enableFeature(uint256 const feature)
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Keylet child(uint256 const &key) noexcept
Any item that can be in an owner dir.
Keylet page(uint256 const &root, std::uint64_t index=0) noexcept
A page in a directory.
Keylet unchecked(uint256 const &key) noexcept
Any ledger entry.
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
bool checkArraySize(Json::Value const &val, unsigned int size)
Json::Value signers(Account const &account, std::uint32_t quorum, std::vector< signer > const &v)
Json::Value trust(Account const &account, STAmount const &amount, std::uint32_t flags)
Modify a trust line.
Json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
Json::Value noop(Account const &account)
The null transaction.
Json::Value offer(Account const &account, STAmount const &takerPays, STAmount const &takerGets, std::uint32_t flags)
Create an offer.
XRP_t const XRP
Converts to XRP Issue or STAmount.
FeatureBitset supported_amendments()
Json::Value offer_cancel(Account const &account, std::uint32_t offerSeq)
Cancel an offer.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Issue const & xrpIssue()
Returns an asset specifier that represents XRP.
std::size_t constexpr dirNodeMaxEntries
The maximum number of entries per directory page.
uint256 getQualityNext(uint256 const &uBase)
std::string to_string(base_uint< Bits, Tag > const &a)
uint256 getBookBase(Book const &book)
bool dirIsEmpty(ReadView const &view, Keylet const &k)
Returns true if the directory is empty.
beast::xor_shift_engine & default_prng()
Return the default random engine.
std::string currcode(std::size_t i)
void makePages(Sandbox &sb, uint256 const &base, std::uint64_t n)
void testDirectoryOrdering()
void run() override
Runs the suite.