20#include <test/shamap/common.h>
21#include <test/unit_test/SuiteJournal.h>
23#include <xrpl/basics/Blob.h>
24#include <xrpl/basics/Buffer.h>
25#include <xrpl/beast/unit_test.h>
26#include <xrpl/beast/utility/Journal.h>
27#include <xrpl/shamap/SHAMap.h>
32#ifndef __INTELLISENSE__
140 "092891fe4ef6cee585fdc6fda0e09eb4d386363158ec3321b8123e5a772c6ca7");
142 "436ccbac3347baa1f1e53baeef1f43334da88f1f6d70d963b833afd6dfa289fe");
144 "b92891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e5a772c6ca8");
146 "b92891fe4ef6cee585fdc6fda2e09eb4d386363158ec3321b8123e5a772c6ca8");
148 "a92891fe4ef6cee585fdc6fda0e09eb4d386363158ec3321b8123e5a772c6ca7");
172 auto i = sMap.
begin();
174 unexpected(i == e || (*i != *i1),
"bad traverse");
176 unexpected(i == e || (*i != *i2),
"bad traverse");
187 unexpected(i == e || (*i != *i1),
"bad traverse");
189 unexpected(i == e || (*i != *i3),
"bad traverse");
191 unexpected(i == e || (*i != *i4),
"bad traverse");
204 unexpected(map2->getHash() != mapHash,
"bad snapshot");
207 BEAST_EXPECT(sMap.
compare(*map2, delta, 100));
208 BEAST_EXPECT(delta.
empty());
213 unexpected(map2->getHash() != mapHash,
"bad snapshot");
215 BEAST_EXPECT(sMap.
compare(*map2, delta, 100));
216 BEAST_EXPECT(delta.
size() == 1);
217 BEAST_EXPECT(delta.
begin()->first == h1);
218 BEAST_EXPECT(delta.
begin()->second.first ==
nullptr);
219 BEAST_EXPECT(delta.
begin()->second.second->key() == h1);
229 uint256(
"b92891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
231 uint256(
"b92881fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
233 uint256(
"b92691fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
235 uint256(
"b92791fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
237 uint256(
"b91891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
239 uint256(
"b99891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
241 uint256(
"f22891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
243 uint256(
"292891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
247 uint256(
"B7387CFEA0465759ADC718E8C42B52D2309D179B326E239EB5075C"
249 uint256(
"FBC195A9592A54AB44010274163CB6BA95F497EC5BA0A883184546"
251 uint256(
"4E7D2684B65DFD48937FFB775E20175C43AF0C94066F7D5679F51A"
253 uint256(
"7A2F312EB203695FFD164E038E281839EEF06A1B99BFC263F3CECC"
255 uint256(
"395A6691A372387A703FB0F2C6D2C405DAF307D0817F8F0E207596"
257 uint256(
"D044C0A696DE3169CC70AE216A1564D69DE96582865796142CE7D9"
259 uint256(
"76DCC77C4027309B5A91AD164083264D70B77B5E43E08AEDA5EBF9"
261 uint256(
"DF4220E93ADC6F5569063A01B4DC79F8DB9553B6A3222ADE23DEA0"
268 BEAST_EXPECT(map.
getHash() == beast::zero);
269 for (
int k = 0; k < keys.size(); ++k)
277 for (
int k = keys.size() - 1; k >= 0; --k)
280 BEAST_EXPECT(map.
delItem(keys[k]));
283 BEAST_EXPECT(map.
getHash() == beast::zero);
293 uint256(
"f22891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
295 uint256(
"b99891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
297 uint256(
"b92891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
299 uint256(
"b92881fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
301 uint256(
"b92791fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
303 uint256(
"b92691fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
305 uint256(
"b91891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
307 uint256(
"292891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
314 for (
auto const& k : keys)
323 for (
auto const& k : map)
325 BEAST_EXPECT(k.key() == keys[h]);
347 for (
unsigned char c = 1; c < 100; ++c)
355 auto root = map.getHash().as_uint256();
356 auto path = map.getProofPath(k);
360 BEAST_EXPECT(map.verifyProofPath(
root, k, *path));
364 path->insert(path->begin(), path->front());
365 BEAST_EXPECT(!map.verifyProofPath(
root, k, *path));
368 BEAST_EXPECT(!map.getProofPath(wrongKey));
374 goodPath = std::move(*path);
379 BEAST_EXPECT(map.verifyProofPath(rootHash, key, goodPath));
382 BEAST_EXPECT(!map.verifyProofPath(rootHash, key, badPath));
386 BEAST_EXPECT(!map.verifyProofPath(rootHash, key, badPath));
390 BEAST_EXPECT(!map.verifyProofPath(rootHash, key, badPath));
394 badPath.
front().back()--;
395 BEAST_EXPECT(!map.verifyProofPath(rootHash, key, badPath));
400 BEAST_EXPECT(!map.verifyProofPath(rootHash, key, badPath));
405BEAST_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)