1#include <test/shamap/common.h>
2#include <test/unit_test/SuiteJournal.h>
4#include <xrpl/basics/random.h>
5#include <xrpl/beast/unit_test.h>
6#include <xrpl/beast/xor_shift_engine.h>
7#include <xrpl/shamap/SHAMap.h>
8#include <xrpl/shamap/SHAMapItem.h>
18 boost::intrusive_ptr<SHAMapItem>
23 for (
int d = 0; d < 3; ++d)
37 for (
int i = 0; i < count; ++i)
44 log <<
"Unable to add item to map\n";
49 for (
auto const& item : items)
53 log <<
"Unable to remove item from map\n";
58 if (beforeHash != map.
getHash())
60 log <<
"Hashes do not match " << beforeHash <<
" " << map.
getHash()
79 for (
int i = 0; i < items; ++i)
93 source.
visitLeaves([&count](
auto const& item) { ++count; });
94 BEAST_EXPECT(count == items);
97 source.
walkMap(missingNodes, 2048);
98 BEAST_EXPECT(missingNodes.
empty());
104 destination.setSynching();
126 auto nodesMissing = destination.getMissingNodes(2048,
nullptr);
128 if (nodesMissing.empty())
134 for (
auto& it : nodesMissing)
141 fail(
"", __FILE__, __LINE__);
148 fail(
"", __FILE__, __LINE__);
157 b[i].first,
makeSlice(b[i].second),
nullptr)
159 fail(
"", __FILE__, __LINE__);
163 destination.clearSynching();
167 destination.invariants();
171BEAST_DEFINE_TESTSUITE(SHAMapSync, shamap,
xrpl);
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 addItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
void walkMap(std::vector< SHAMapMissingNode > &missingNodes, int maxMissing) const
bool deepCompare(SHAMap &other) const
void visitLeaves(std::function< void(boost::intrusive_ptr< SHAMapItem const > const &)> const &) const
Visit every leaf node in this SHAMap.
bool getNodeFat(SHAMapNodeID const &wanted, std::vector< std::pair< SHAMapNodeID, Blob > > &data, bool fatLeaves, std::uint32_t depth) const
SHAMapHash getHash() const
bool delItem(uint256 const &id)
uint256 getSHA512Half() const
Slice slice() const noexcept
bool confuseMap(SHAMap &map, int count)
boost::intrusive_ptr< SHAMapItem > makeRandomAS()
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.
boost::intrusive_ptr< SHAMapItem > make_shamapitem(uint256 const &tag, Slice data)
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)