1#include <test/shamap/common.h>
2#include <test/unit_test/SuiteJournal.h>
4#include <xrpl/basics/Blob.h>
5#include <xrpl/basics/Buffer.h>
6#include <xrpl/basics/SHAMapHash.h>
7#include <xrpl/basics/base_uint.h>
8#include <xrpl/beast/unit_test/suite.h>
9#include <xrpl/beast/utility/Journal.h>
10#include <xrpl/beast/utility/Zero.h>
11#include <xrpl/shamap/SHAMap.h>
12#include <xrpl/shamap/SHAMapInnerNode.h>
13#include <xrpl/shamap/SHAMapItem.h>
14#include <xrpl/shamap/SHAMapLeafNode.h>
15#include <xrpl/shamap/SHAMapMissingNode.h>
16#include <xrpl/shamap/SHAMapTreeNode.h>
28#ifndef __INTELLISENSE__
29static_assert(std::is_nothrow_destructible<SHAMap>{},
"");
30static_assert(!std::is_default_constructible<SHAMap>{},
"");
31static_assert(!std::is_copy_constructible<SHAMap>{},
"");
32static_assert(!std::is_copy_assignable<SHAMap>{},
"");
33static_assert(!std::is_move_constructible<SHAMap>{},
"");
34static_assert(!std::is_move_assignable<SHAMap>{},
"");
36static_assert(std::is_nothrow_destructible<SHAMap::ConstIterator>{},
"");
37static_assert(std::is_copy_constructible<SHAMap::ConstIterator>{},
"");
38static_assert(std::is_copy_assignable<SHAMap::ConstIterator>{},
"");
39static_assert(std::is_move_constructible<SHAMap::ConstIterator>{},
"");
40static_assert(std::is_move_assignable<SHAMap::ConstIterator>{},
"");
42static_assert(std::is_nothrow_destructible<SHAMapItem>{},
"");
43static_assert(!std::is_default_constructible<SHAMapItem>{},
"");
44static_assert(!std::is_copy_constructible<SHAMapItem>{},
"");
46static_assert(std::is_nothrow_destructible<SHAMapNodeID>{},
"");
47static_assert(std::is_default_constructible<SHAMapNodeID>{},
"");
48static_assert(std::is_copy_constructible<SHAMapNodeID>{},
"");
49static_assert(std::is_copy_assignable<SHAMapNodeID>{},
"");
50static_assert(std::is_move_constructible<SHAMapNodeID>{},
"");
51static_assert(std::is_move_assignable<SHAMapNodeID>{},
"");
53static_assert(std::is_nothrow_destructible<SHAMapHash>{},
"");
54static_assert(std::is_default_constructible<SHAMapHash>{},
"");
55static_assert(std::is_copy_constructible<SHAMapHash>{},
"");
56static_assert(std::is_copy_assignable<SHAMapHash>{},
"");
57static_assert(std::is_move_constructible<SHAMapHash>{},
"");
58static_assert(std::is_move_assignable<SHAMapHash>{},
"");
60static_assert(std::is_nothrow_destructible<SHAMapTreeNode>{},
"");
61static_assert(!std::is_default_constructible<SHAMapTreeNode>{},
"");
62static_assert(!std::is_copy_constructible<SHAMapTreeNode>{},
"");
63static_assert(!std::is_copy_assignable<SHAMapTreeNode>{},
"");
64static_assert(!std::is_move_constructible<SHAMapTreeNode>{},
"");
65static_assert(!std::is_move_assignable<SHAMapTreeNode>{},
"");
67static_assert(std::is_nothrow_destructible<SHAMapInnerNode>{},
"");
68static_assert(!std::is_default_constructible<SHAMapInnerNode>{},
"");
69static_assert(!std::is_copy_constructible<SHAMapInnerNode>{},
"");
70static_assert(!std::is_copy_assignable<SHAMapInnerNode>{},
"");
71static_assert(!std::is_move_constructible<SHAMapInnerNode>{},
"");
72static_assert(!std::is_move_assignable<SHAMapInnerNode>{},
"");
74static_assert(std::is_nothrow_destructible<SHAMapLeafNode>{},
"");
75static_assert(!std::is_default_constructible<SHAMapLeafNode>{},
"");
76static_assert(!std::is_copy_constructible<SHAMapLeafNode>{},
"");
77static_assert(!std::is_copy_assignable<SHAMapLeafNode>{},
"");
78static_assert(!std::is_move_constructible<SHAMapLeafNode>{},
"");
79static_assert(!std::is_move_assignable<SHAMapLeafNode>{},
"");
139 constexpr uint256 kH1(
"092891fe4ef6cee585fdc6fda0e09eb4d386363158ec3321b8123e5a772c6ca7");
140 constexpr uint256 kH2(
"436ccbac3347baa1f1e53baeef1f43334da88f1f6d70d963b833afd6dfa289fe");
141 constexpr uint256 kH3(
"b92891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e5a772c6ca8");
142 constexpr uint256 kH4(
"b92891fe4ef6cee585fdc6fda2e09eb4d386363158ec3321b8123e5a772c6ca8");
143 constexpr uint256 kH5(
"a92891fe4ef6cee585fdc6fda0e09eb4d386363158ec3321b8123e5a772c6ca7");
161 auto i = sMap.
begin();
163 unexpected(i == e || (*i != *i1),
"bad traverse");
165 unexpected(i == e || (*i != *i2),
"bad traverse");
176 unexpected(i == e || (*i != *i1),
"bad traverse");
178 unexpected(i == e || (*i != *i3),
"bad traverse");
180 unexpected(i == e || (*i != *i4),
"bad traverse");
197 unexpected(map2->getHash() != mapHash,
"bad snapshot");
200 BEAST_EXPECT(sMap.
compare(*map2, delta, 100));
201 BEAST_EXPECT(delta.
empty());
206 unexpected(map2->getHash() != mapHash,
"bad snapshot");
208 BEAST_EXPECT(sMap.
compare(*map2, delta, 100));
209 BEAST_EXPECT(delta.
size() == 1);
210 BEAST_EXPECT(delta.
begin()->first == kH1);
211 BEAST_EXPECT(delta.
begin()->second.first ==
nullptr);
212 BEAST_EXPECT(delta.
begin()->second.second->key() == kH1);
227 "b92891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
230 "b92881fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
233 "b92691fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
236 "b92791fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
239 "b91891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
242 "b99891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
245 "f22891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
248 "292891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
253 "B7387CFEA0465759ADC718E8C42B52D2309D179B326E239EB5075C"
256 "FBC195A9592A54AB44010274163CB6BA95F497EC5BA0A883184546"
259 "4E7D2684B65DFD48937FFB775E20175C43AF0C94066F7D5679F51A"
262 "7A2F312EB203695FFD164E038E281839EEF06A1B99BFC263F3CECC"
265 "395A6691A372387A703FB0F2C6D2C405DAF307D0817F8F0E207596"
268 "D044C0A696DE3169CC70AE216A1564D69DE96582865796142CE7D9"
271 "76DCC77C4027309B5A91AD164083264D70B77B5E43E08AEDA5EBF9"
274 "DF4220E93ADC6F5569063A01B4DC79F8DB9553B6A3222ADE23DEA0"
281 BEAST_EXPECT(map.
getHash() == beast::kZero);
282 for (
int k = 0; k < keys.
size(); ++k)
289 for (
int k = keys.
size() - 1; k >= 0; --k)
292 BEAST_EXPECT(map.
delItem(keys[k]));
295 BEAST_EXPECT(map.
getHash() == beast::kZero);
310 "f22891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
313 "b99891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
316 "b92891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
319 "b92881fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
322 "b92791fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
325 "b92691fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
328 "b91891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
331 "292891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
338 for (
auto const& k : keys)
345 for (
auto const& k : map)
347 BEAST_EXPECT(k.key() == keys[h]);
369 for (
unsigned char c = 1; c < 100; ++c)
395 goodPath = std::move(*
path);
415 badPath.
front().back()--;
A generic endpoint for log messages.
bool unexpected(Condition shouldBeFalse, String const &reason)
TestcaseT testcase
Memberspace for declaring test cases.
static constexpr std::size_t size()
Like std::vector<char> but better.
std::size_t size() const noexcept
Returns the number of bytes in the buffer.
std::uint8_t const * data() const noexcept
Return a pointer to beginning of the storage.
uint256 const & asUInt256() const
uint256 const & key() const
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)
static bool verifyProofPath(uint256 const &rootHash, uint256 const &key, std::vector< Blob > const &path)
Verify the proof path.
std::optional< std::vector< Blob > > getProofPath(uint256 const &key) const
Get the proof path of the key.
std::map< uint256, DeltaItem > Delta
void dump(bool withHashes=false) const
bool compare(SHAMap const &otherMap, Delta &differences, int maxCount) const
std::shared_ptr< SHAMap > snapShot(bool isMutable) const
ConstIterator end() const
SHAMapHash getHash() const
ConstIterator begin() const
bool delItem(uint256 const &id)
An immutable linear range of bytes.
void run() override
Runs the suite.
void run() override
Runs the suite.
void run(bool backed, beast::Journal const &journal)
static Buffer intToVuc(int v)
T emplace_back(T... args)
Severity
Severity level / threshold of a Journal message.
bool operator==(SHAMapItem const &a, SHAMapItem const &b)
bool operator!=(SHAMapItem const &a, SHAMapItem const &b)
BEAST_DEFINE_TESTSUITE(IntrusiveShared, basics, xrpl)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Number root(Number f, unsigned d)
boost::intrusive_ptr< SHAMapItem > makeShamapitem(uint256 const &tag, Slice data)