20 #include <ripple/basics/StringUtilities.h>
21 #include <ripple/basics/random.h>
22 #include <ripple/beast/unit_test.h>
23 #include <ripple/beast/xor_shift_engine.h>
24 #include <ripple/shamap/SHAMap.h>
25 #include <ripple/shamap/SHAMapItem.h>
26 #include <test/shamap/common.h>
27 #include <test/unit_test/SuiteJournal.h>
37 boost::intrusive_ptr<SHAMapItem>
42 for (
int d = 0; d < 3; ++d)
56 for (
int i = 0; i < count; ++i)
63 log <<
"Unable to add item to map\n";
68 for (
auto const& item : items)
72 log <<
"Unable to remove item from map\n";
77 if (beforeHash != map.
getHash())
79 log <<
"Hashes do not match " << beforeHash <<
" " << map.
getHash()
98 for (
int i = 0; i < items; ++i)
112 source.
visitLeaves([&count](
auto const& item) { ++count; });
113 BEAST_EXPECT(count == items);
116 source.
walkMap(missingNodes, 2048);
117 BEAST_EXPECT(missingNodes.
empty());
131 unexpected(a.
size() < 1,
"NodeSize");
147 if (nodesMissing.empty())
153 for (
auto& it : nodesMissing)
160 fail(
"", __FILE__, __LINE__);
167 fail(
"", __FILE__, __LINE__);
176 b[i].first,
makeSlice(b[i].second),
nullptr)
178 fail(
"", __FILE__, __LINE__);
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)
SHAMapHash getHash() const
bool deepCompare(SHAMap &other) const
boost::intrusive_ptr< SHAMapItem > make_shamapitem(uint256 const &tag, Slice data)
A namespace for easy access to logging severity values.
BEAST_DEFINE_TESTSUITE(cluster, overlay, ripple)
Identifies a node inside a SHAMap.
boost::intrusive_ptr< SHAMapItem > makeRandomAS()
uint256 getSHA512Half() const
bool addItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
std::enable_if_t< std::is_integral< Integral >::value &&detail::is_engine< Engine >::value, Integral > rand_int(Engine &engine, Integral min, Integral max)
Return a uniformly distributed random integer.
A SHAMap is both a radix tree with a fan-out of 16 and a Merkle tree.
Slice slice() const noexcept
beast::xor_shift_engine eng_
std::vector< std::pair< SHAMapNodeID, uint256 > > getMissingNodes(int maxNodes, SHAMapSyncFilter *filter)
Check for nodes in the SHAMap not available.
void walkMap(std::vector< SHAMapMissingNode > &missingNodes, int maxMissing) const
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
bool confuseMap(SHAMap &map, int count)
bool getNodeFat(SHAMapNodeID const &wanted, std::vector< std::pair< SHAMapNodeID, Blob >> &data, bool fatLeaves, std::uint32_t depth) const
int add32(std::uint32_t i)
bool rand_bool(Engine &engine)
Return a random boolean value.
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.