20 #include <ripple/shamap/SHAMap.h>
21 #include <ripple/shamap/SHAMapItem.h>
22 #include <ripple/basics/random.h>
23 #include <ripple/basics/StringUtilities.h>
24 #include <ripple/beast/unit_test.h>
25 #include <ripple/beast/xor_shift_engine.h>
26 #include <test/shamap/common.h>
27 #include <test/unit_test/SuiteJournal.h>
41 for (
int d = 0; d < 3; ++d)
44 return std::make_shared<SHAMapItem>(
56 for (
int i = 0; i < count; ++i)
61 if (!map.
addItem (std::move(*item),
false,
false))
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 ())
80 "Hashes do not match " << beforeHash <<
98 for (
int i = 0; i < items; ++i)
116 BEAST_EXPECT(count == items);
119 source.
walkMap(missingNodes, 2048);
120 BEAST_EXPECT(missingNodes.
empty());
139 unexpected (gotNodes_a.
size () < 1,
"NodeSize");
155 if (nodesMissing.empty ())
162 for (
auto& it : nodesMissing)
172 fail(
"", __FILE__, __LINE__);
177 if (gotNodeIDs_b.
size() != gotNodes_b.
size() ||
178 gotNodeIDs_b.
empty())
179 fail(
"", __FILE__, __LINE__);
187 gotNodeIDs_b[i],
makeSlice(gotNodes_b[i]),
nullptr)
189 fail(
"", __FILE__, __LINE__);
198 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 getNodeFat(SHAMapNodeID node, std::vector< SHAMapNodeID > &nodeIDs, std::vector< Blob > &rawNode, bool fatLeaves, std::uint32_t depth) 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.
A namespace for easy access to logging severity values.
BEAST_DEFINE_TESTSUITE(cluster, overlay, ripple)
std::shared_ptr< SHAMapItem > makeRandomAS()
uint256 getSHA512Half() const
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.
beast::xor_shift_engine eng_
SHAMapAddNode addRootNode(SHAMapHash const &hash, Slice const &rootNode, SHANodeFormat format, SHAMapSyncFilter *filter)
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.
Blob const & peekData() const
bool confuseMap(SHAMap &map, int count)
bool addItem(SHAMapItem &&i, bool isTransaction, bool hasMeta)
bool rand_bool(Engine &engine)
Return a random boolean value.
bool delItem(uint256 const &id)