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>
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)
113 source.
visitLeaves([&count](
auto const& item) { ++count; });
114 BEAST_EXPECT(count == items);
117 source.
walkMap(missingNodes, 2048);
118 BEAST_EXPECT(missingNodes.
empty());
137 unexpected(gotNodes_a.
size() < 1,
"NodeSize");
139 BEAST_EXPECT(destination
154 if (nodesMissing.empty())
161 for (
auto& it : nodesMissing)
172 fail(
"", __FILE__, __LINE__);
178 if (gotNodeIDs_b.
size() != gotNodes_b.
size() ||
179 gotNodeIDs_b.
empty())
180 fail(
"", __FILE__, __LINE__);
189 gotNodeIDs_b[i],
makeSlice(gotNodes_b[i]),
nullptr)
191 fail(
"", __FILE__, __LINE__);
199 log <<
"Checking destination invariants..." <<
std::endl;
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
bool addItem(SHAMapNodeType type, SHAMapItem &&i)
A namespace for easy access to logging severity values.
BEAST_DEFINE_TESTSUITE(cluster, overlay, ripple)
Identifies a node inside a SHAMap.
std::shared_ptr< SHAMapItem > makeRandomAS()
uint256 getSHA512Half() const
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.
void visitLeaves(std::function< void(std::shared_ptr< SHAMapItem const > const &)> const &) const
Visit every leaf node in this SHAMap.
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)
int add32(std::uint32_t i)
bool rand_bool(Engine &engine)
Return a random boolean value.
bool getNodeFat(SHAMapNodeID const &wanted, std::vector< SHAMapNodeID > &nodeIDs, std::vector< Blob > &rawNodes, bool fatLeaves, std::uint32_t depth) const
bool delItem(uint256 const &id)