xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
test
ledger
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
14
namespace
xrpl::test
{
15
16
class
SkipList_test
:
public
beast::unit_test::Suite
17
{
18
void
19
testSkipList
()
20
{
21
jtx::Env
env(*
this
);
22
std::vector<std::shared_ptr<Ledger>
> history;
23
{
24
Config
const
config;
25
auto
prev =
std::make_shared<Ledger>
(
26
kCreateGenesis
,
27
Rules
{config.
features
},
28
config.
fees
.
toFees
(),
29
std::vector<UInt256>
{},
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
{
77
testSkipList
();
78
}
79
};
80
81
BEAST_DEFINE_TESTSUITE
(
SkipList
, ledger,
xrpl
);
82
83
}
// namespace xrpl::test
std::vector::back
T back(T... args)
std::begin
T begin(T... args)
beast::unit_test::Suite
A testsuite class.
Definition
suite.h:52
xrpl::Config
Definition
src/xrpld/core/Config.h:89
xrpl::Config::features
std::unordered_set< UInt256, beast::Uhash<> > features
Definition
src/xrpld/core/Config.h:288
xrpl::Config::fees
FeeSetup fees
Definition
src/xrpld/core/Config.h:206
xrpl::Rules
Rules controlling protocol behavior.
Definition
Rules.h:40
xrpl::ServiceRegistry::getTimeKeeper
virtual TimeKeeper & getTimeKeeper()=0
xrpl::TimeKeeper::closeTime
time_point closeTime() const
Returns the predicted close time, in network time.
Definition
TimeKeeper.h:61
xrpl::test::SkipList_test
Definition
SkipList_test.cpp:17
xrpl::test::SkipList_test::testSkipList
void testSkipList()
Definition
SkipList_test.cpp:19
xrpl::test::SkipList_test::run
void run() override
Runs the suite.
Definition
SkipList_test.cpp:75
xrpl::test::jtx::Env
A transaction testing environment.
Definition
Env.h:161
xrpl::test::jtx::Env::app
Application & app()
Definition
Env.h:300
xrpl::test::jtx::Env::journal
beast::Journal const journal
Definition
Env.h:204
iterator
std::make_shared
T make_shared(T... args)
memory
xrpl::test
Definition
STLedgerEntry.h:21
xrpl::test::BEAST_DEFINE_TESTSUITE
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::hashOfSeq
std::optional< UInt256 > hashOfSeq(ReadView const &ledger, LedgerIndex seq, beast::Journal journal)
Return the hash of a ledger by sequence.
Definition
View.cpp:323
xrpl::kCreateGenesis
CreateGenesisT const kCreateGenesis
Definition
libxrpl/ledger/Ledger.cpp:51
xrpl::LedgerNameSpace::SkipList
@ SkipList
Definition
Indexes.cpp:78
std::next
T next(T... args)
std::vector::push_back
T push_back(T... args)
std::vector::crbegin
T crbegin(T... args)
std::vector::crend
T crend(T... args)
xrpl::FeeSetup::toFees
Fees toFees() const
Convert to a Fees object for use with Ledger construction.
Definition
src/xrpld/core/Config.h:77
vector
Generated by
1.17.0