xrpld
Loading...
Searching...
No Matches
SkipList_test.cpp
1#include <test/jtx/Env.h>
2
3#include <xrpld/core/Config.h>
4
5#include <xrpl/basics/base_uint.h>
6#include <xrpl/beast/unit_test/suite.h>
7#include <xrpl/ledger/Ledger.h>
8#include <xrpl/ledger/View.h>
9
10#include <iterator>
11#include <memory>
12#include <vector>
13
14namespace xrpl::test {
15
17{
18 void
20 {
21 jtx::Env env(*this);
23 {
24 Config const config;
25 auto prev = std::make_shared<Ledger>(
27 Rules{config.features},
28 config.fees.toFees(),
30 env.app().getNodeFamily());
31 history.push_back(prev);
32 for (auto i = 0; i < 1023; ++i)
33 {
34 auto next = std::make_shared<Ledger>(*prev, env.app().getTimeKeeper().closeTime());
35 next->updateSkipList();
36 history.push_back(next);
37 prev = next;
38 }
39 }
40
41 {
42 auto l = *(std::next(std::begin(history)));
43 BEAST_EXPECT((*std::begin(history))->header().seq < l->header().seq);
44 BEAST_EXPECT(!hashOfSeq(*l, l->header().seq + 1, env.journal).has_value());
45 BEAST_EXPECT(hashOfSeq(*l, l->header().seq, env.journal) == l->header().hash);
46 BEAST_EXPECT(hashOfSeq(*l, l->header().seq - 1, env.journal) == l->header().parentHash);
47 BEAST_EXPECT(!hashOfSeq(*history.back(), l->header().seq, env.journal).has_value());
48 }
49
50 // ledger skip lists store up to the previous 256 hashes
51 for (auto i = history.crbegin(); i != history.crend(); i += 256)
52 {
53 for (auto n = i; n != std::next(i, (*i)->header().seq - 256 > 1 ? 257 : 256); ++n)
54 {
55 BEAST_EXPECT(
56 hashOfSeq(**i, (*n)->header().seq, env.journal) == (*n)->header().hash);
57 }
58
59 // edge case accessing beyond 256
60 BEAST_EXPECT(!hashOfSeq(**i, (*i)->header().seq - 258, env.journal).has_value());
61 }
62
63 // every 256th hash beyond the first 256 is stored
64 for (auto i = history.crbegin(); i != std::next(history.crend(), -512); i += 256)
65 {
66 for (auto n = std::next(i, 512); n != history.crend(); n += 256)
67 {
68 BEAST_EXPECT(
69 hashOfSeq(**i, (*n)->header().seq, env.journal) == (*n)->header().hash);
70 }
71 }
72 }
73
74 void
75 run() override
76 {
78 }
79};
80
82
83} // namespace xrpl::test
T back(T... args)
T begin(T... args)
A testsuite class.
Definition suite.h:50
std::unordered_set< uint256, beast::Uhash<> > features
Definition Config.h:261
FeeSetup fees
Definition Config.h:189
Rules controlling protocol behavior.
Definition Rules.h:33
virtual TimeKeeper & getTimeKeeper()=0
time_point closeTime() const
Returns the predicted close time, in network time.
Definition TimeKeeper.h:56
void run() override
Runs the suite.
A transaction testing environment.
Definition Env.h:143
Application & app()
Definition Env.h:280
beast::Journal const journal
Definition Env.h:184
T make_shared(T... args)
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
CreateGenesisT const kCreateGenesis
std::optional< uint256 > hashOfSeq(ReadView const &ledger, LedgerIndex seq, beast::Journal journal)
Return the hash of a ledger by sequence.
Definition View.cpp:270
T next(T... args)
T push_back(T... args)
T crbegin(T... args)
T crend(T... args)
Fees toFees() const
Convert to a Fees object for use with Ledger construction.
Definition Config.h:64