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/beast/unit_test.h>
7#include <xrpl/beast/utility/Journal.h>
8#include <xrpl/shamap/SHAMap.h>
13#ifndef __INTELLISENSE__
121 "092891fe4ef6cee585fdc6fda0e09eb4d386363158ec3321b8123e5a772c6ca7");
123 "436ccbac3347baa1f1e53baeef1f43334da88f1f6d70d963b833afd6dfa289fe");
125 "b92891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e5a772c6ca8");
127 "b92891fe4ef6cee585fdc6fda2e09eb4d386363158ec3321b8123e5a772c6ca8");
129 "a92891fe4ef6cee585fdc6fda0e09eb4d386363158ec3321b8123e5a772c6ca7");
153 auto i = sMap.
begin();
155 unexpected(i == e || (*i != *i1),
"bad traverse");
157 unexpected(i == e || (*i != *i2),
"bad traverse");
168 unexpected(i == e || (*i != *i1),
"bad traverse");
170 unexpected(i == e || (*i != *i3),
"bad traverse");
172 unexpected(i == e || (*i != *i4),
"bad traverse");
185 unexpected(map2->getHash() != mapHash,
"bad snapshot");
188 BEAST_EXPECT(sMap.
compare(*map2, delta, 100));
189 BEAST_EXPECT(delta.
empty());
194 unexpected(map2->getHash() != mapHash,
"bad snapshot");
196 BEAST_EXPECT(sMap.
compare(*map2, delta, 100));
197 BEAST_EXPECT(delta.
size() == 1);
198 BEAST_EXPECT(delta.
begin()->first == h1);
199 BEAST_EXPECT(delta.
begin()->second.first ==
nullptr);
200 BEAST_EXPECT(delta.
begin()->second.second->key() == h1);
210 uint256(
"b92891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
212 uint256(
"b92881fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
214 uint256(
"b92691fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
216 uint256(
"b92791fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
218 uint256(
"b91891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
220 uint256(
"b99891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
222 uint256(
"f22891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
224 uint256(
"292891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
228 uint256(
"B7387CFEA0465759ADC718E8C42B52D2309D179B326E239EB5075C"
230 uint256(
"FBC195A9592A54AB44010274163CB6BA95F497EC5BA0A883184546"
232 uint256(
"4E7D2684B65DFD48937FFB775E20175C43AF0C94066F7D5679F51A"
234 uint256(
"7A2F312EB203695FFD164E038E281839EEF06A1B99BFC263F3CECC"
236 uint256(
"395A6691A372387A703FB0F2C6D2C405DAF307D0817F8F0E207596"
238 uint256(
"D044C0A696DE3169CC70AE216A1564D69DE96582865796142CE7D9"
240 uint256(
"76DCC77C4027309B5A91AD164083264D70B77B5E43E08AEDA5EBF9"
242 uint256(
"DF4220E93ADC6F5569063A01B4DC79F8DB9553B6A3222ADE23DEA0"
249 BEAST_EXPECT(map.
getHash() == beast::zero);
250 for (
int k = 0; k < keys.size(); ++k)
258 for (
int k = keys.size() - 1; k >= 0; --k)
261 BEAST_EXPECT(map.
delItem(keys[k]));
264 BEAST_EXPECT(map.
getHash() == beast::zero);
274 uint256(
"f22891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
276 uint256(
"b99891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
278 uint256(
"b92891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
280 uint256(
"b92881fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
282 uint256(
"b92791fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
284 uint256(
"b92691fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
286 uint256(
"b91891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
288 uint256(
"292891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
295 for (
auto const& k : keys)
304 for (
auto const& k : map)
306 BEAST_EXPECT(k.key() == keys[h]);
328 for (
unsigned char c = 1; c < 100; ++c)
336 auto root = map.getHash().as_uint256();
337 auto path = map.getProofPath(k);
341 BEAST_EXPECT(map.verifyProofPath(
root, k, *path));
345 path->insert(path->begin(), path->front());
346 BEAST_EXPECT(!map.verifyProofPath(
root, k, *path));
349 BEAST_EXPECT(!map.getProofPath(wrongKey));
355 goodPath = std::move(*path);
360 BEAST_EXPECT(map.verifyProofPath(rootHash, key, goodPath));
363 BEAST_EXPECT(!map.verifyProofPath(rootHash, key, badPath));
367 BEAST_EXPECT(!map.verifyProofPath(rootHash, key, badPath));
371 BEAST_EXPECT(!map.verifyProofPath(rootHash, key, badPath));
375 badPath.
front().back()--;
376 BEAST_EXPECT(!map.verifyProofPath(rootHash, key, badPath));
381 BEAST_EXPECT(!map.verifyProofPath(rootHash, key, badPath));
386BEAST_DEFINE_TESTSUITE(SHAMapPathProof, shamap,
ripple);
A generic endpoint for log messages.
bool unexpected(Condition shouldBeFalse, String const &reason)
testcase_t testcase
Memberspace for declaring test cases.
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 & as_uint256() const
uint256 const & key() const
A SHAMap is both a radix tree with a fan-out of 16 and a Merkle tree.
bool compare(SHAMap const &otherMap, Delta &differences, int maxCount) const
void dump(bool withHashes=false) const
const_iterator end() const
bool addItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
SHAMapHash getHash() const
const_iterator begin() const
bool delItem(uint256 const &id)
std::shared_ptr< SHAMap > snapShot(bool isMutable) const
An immutable linear range of bytes.
static constexpr std::size_t size()
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)
A namespace for easy access to logging severity values.
bool operator!=(SHAMapItem const &a, SHAMapItem const &b)
bool operator==(SHAMapItem const &a, SHAMapItem const &b)
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)
Number root(Number f, unsigned d)