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
const
next =
35
std::make_shared<Ledger>
(*prev, env.
app
().
getTimeKeeper
().
closeTime
());
36
next->updateSkipList();
37
history.
push_back
(next);
38
prev = next;
39
}
40
}
41
42
{
43
auto
const
l = *
std::next
(
std::begin
(history));
44
BEAST_EXPECT((*
std::begin
(history))->header().seq < l->header().seq);
45
BEAST_EXPECT(!
hashOfSeq
(*l, l->header().seq + 1, env.
journal
).has_value());
46
BEAST_EXPECT(
hashOfSeq
(*l, l->header().seq, env.
journal
) == l->header().hash);
47
BEAST_EXPECT(
hashOfSeq
(*l, l->header().seq - 1, env.
journal
) == l->header().parentHash);
48
BEAST_EXPECT(!
hashOfSeq
(*history.
back
(), l->header().seq, env.
journal
).has_value());
49
}
50
51
// ledger skip lists store up to the previous 256 hashes
52
for
(
auto
i = history.
crbegin
(); i != history.
crend
(); i += 256)
53
{
54
for
(
auto
n = i; n !=
std::next
(i, (*i)->header().seq - 256 > 1 ? 257 : 256); ++n)
55
{
56
BEAST_EXPECT(
57
hashOfSeq
(**i, (*n)->header().seq, env.
journal
) == (*n)->header().hash);
58
}
59
60
// edge case accessing beyond 256
61
BEAST_EXPECT(!
hashOfSeq
(**i, (*i)->header().seq - 258, env.
journal
).has_value());
62
}
63
64
// every 256th hash beyond the first 256 is stored
65
for
(
auto
i = history.
crbegin
(); i !=
std::next
(history.
crend
(), -512); i += 256)
66
{
67
for
(
auto
n =
std::next
(i, 512); n != history.
crend
(); n += 256)
68
{
69
BEAST_EXPECT(
70
hashOfSeq
(**i, (*n)->header().seq, env.
journal
) == (*n)->header().hash);
71
}
72
}
73
}
74
75
void
76
run
()
override
77
{
78
testSkipList
();
79
}
80
};
81
82
BEAST_DEFINE_TESTSUITE
(
SkipList
, ledger,
xrpl
);
83
84
}
// 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:105
xrpl::Config::features
std::unordered_set< UInt256, beast::Uhash<> > features
Definition
src/xrpld/core/Config.h:304
xrpl::Config::fees
FeeSetup fees
Definition
src/xrpld/core/Config.h:222
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:76
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:324
xrpl::kCreateGenesis
CreateGenesisT const kCreateGenesis
Definition
libxrpl/ledger/Ledger.cpp:51
xrpl::LedgerNameSpace::SkipList
@ SkipList
Definition
Indexes.cpp:91
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:92
vector
Generated by
1.17.0