20#include <test/shamap/common.h>
21#include <test/unit_test/SuiteJournal.h>
23#include <xrpld/shamap/SHAMap.h>
24#include <xrpld/shamap/SHAMapItem.h>
26#include <xrpl/basics/random.h>
27#include <xrpl/beast/unit_test.h>
28#include <xrpl/beast/xor_shift_engine.h>
38 boost::intrusive_ptr<SHAMapItem>
43 for (
int d = 0; d < 3; ++d)
57 for (
int i = 0; i < count; ++i)
64 log <<
"Unable to add item to map\n";
69 for (
auto const& item : items)
73 log <<
"Unable to remove item from map\n";
78 if (beforeHash != map.
getHash())
80 log <<
"Hashes do not match " << beforeHash <<
" " << map.
getHash()
99 for (
int i = 0; i < items; ++i)
113 source.
visitLeaves([&count](
auto const& item) { ++count; });
114 BEAST_EXPECT(count == items);
117 source.
walkMap(missingNodes, 2048);
118 BEAST_EXPECT(missingNodes.
empty());
148 if (nodesMissing.empty())
154 for (
auto& it : nodesMissing)
161 fail(
"", __FILE__, __LINE__);
168 fail(
"", __FILE__, __LINE__);
177 b[i].first,
makeSlice(b[i].second),
nullptr)
179 fail(
"", __FILE__, __LINE__);
191BEAST_DEFINE_TESTSUITE(SHAMapSync, shamap,
ripple);
log_os< char > log
Logging output stream.
bool unexpected(Condition shouldBeFalse, String const &reason)
void fail(String const &reason, char const *file, int line)
Record a failure.
Identifies a node inside a SHAMap.
A SHAMap is both a radix tree with a fan-out of 16 and a Merkle tree.
bool getNodeFat(SHAMapNodeID const &wanted, std::vector< std::pair< SHAMapNodeID, Blob > > &data, bool fatLeaves, std::uint32_t depth) const
bool addItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
SHAMapHash getHash() const
void walkMap(std::vector< SHAMapMissingNode > &missingNodes, int maxMissing) const
std::vector< std::pair< SHAMapNodeID, uint256 > > getMissingNodes(int maxNodes, SHAMapSyncFilter *filter)
Check for nodes in the SHAMap not available.
bool delItem(uint256 const &id)
void visitLeaves(std::function< void(boost::intrusive_ptr< SHAMapItem const > const &)> const &) const
Visit every leaf node in this SHAMap.
bool deepCompare(SHAMap &other) const
Slice slice() const noexcept
uint256 getSHA512Half() const
boost::intrusive_ptr< SHAMapItem > makeRandomAS()
bool confuseMap(SHAMap &map, int count)
void run() override
Runs the suite.
beast::xor_shift_engine eng_
A namespace for easy access to logging severity values.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::enable_if_t< std::is_integral< Integral >::value, Integral > rand_int()
std::enable_if_t< std::is_same< T, char >::value||std::is_same< T, unsigned char >::value, Slice > makeSlice(std::array< T, N > const &a)
boost::intrusive_ptr< SHAMapItem > make_shamapitem(uint256 const &tag, Slice data)