20#include <test/shamap/common.h>
21#include <test/unit_test/SuiteJournal.h>
23#include <xrpld/shamap/SHAMap.h>
25#include <xrpl/basics/Blob.h>
26#include <xrpl/basics/Buffer.h>
27#include <xrpl/beast/unit_test.h>
28#include <xrpl/beast/utility/Journal.h>
33#ifndef __INTELLISENSE__
141 "092891fe4ef6cee585fdc6fda0e09eb4d386363158ec3321b8123e5a772c6ca7");
143 "436ccbac3347baa1f1e53baeef1f43334da88f1f6d70d963b833afd6dfa289fe");
145 "b92891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e5a772c6ca8");
147 "b92891fe4ef6cee585fdc6fda2e09eb4d386363158ec3321b8123e5a772c6ca8");
149 "a92891fe4ef6cee585fdc6fda0e09eb4d386363158ec3321b8123e5a772c6ca7");
173 auto i = sMap.
begin();
175 unexpected(i == e || (*i != *i1),
"bad traverse");
177 unexpected(i == e || (*i != *i2),
"bad traverse");
188 unexpected(i == e || (*i != *i1),
"bad traverse");
190 unexpected(i == e || (*i != *i3),
"bad traverse");
192 unexpected(i == e || (*i != *i4),
"bad traverse");
205 unexpected(map2->getHash() != mapHash,
"bad snapshot");
208 BEAST_EXPECT(sMap.
compare(*map2, delta, 100));
209 BEAST_EXPECT(delta.
empty());
214 unexpected(map2->getHash() != mapHash,
"bad snapshot");
216 BEAST_EXPECT(sMap.
compare(*map2, delta, 100));
217 BEAST_EXPECT(delta.
size() == 1);
218 BEAST_EXPECT(delta.
begin()->first == h1);
219 BEAST_EXPECT(delta.
begin()->second.first ==
nullptr);
220 BEAST_EXPECT(delta.
begin()->second.second->key() == h1);
230 uint256(
"b92891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
232 uint256(
"b92881fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
234 uint256(
"b92691fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
236 uint256(
"b92791fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
238 uint256(
"b91891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
240 uint256(
"b99891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
242 uint256(
"f22891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
244 uint256(
"292891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
248 uint256(
"B7387CFEA0465759ADC718E8C42B52D2309D179B326E239EB5075C"
250 uint256(
"FBC195A9592A54AB44010274163CB6BA95F497EC5BA0A883184546"
252 uint256(
"4E7D2684B65DFD48937FFB775E20175C43AF0C94066F7D5679F51A"
254 uint256(
"7A2F312EB203695FFD164E038E281839EEF06A1B99BFC263F3CECC"
256 uint256(
"395A6691A372387A703FB0F2C6D2C405DAF307D0817F8F0E207596"
258 uint256(
"D044C0A696DE3169CC70AE216A1564D69DE96582865796142CE7D9"
260 uint256(
"76DCC77C4027309B5A91AD164083264D70B77B5E43E08AEDA5EBF9"
262 uint256(
"DF4220E93ADC6F5569063A01B4DC79F8DB9553B6A3222ADE23DEA0"
269 BEAST_EXPECT(map.
getHash() == beast::zero);
270 for (
int k = 0; k < keys.size(); ++k)
278 for (
int k = keys.size() - 1; k >= 0; --k)
281 BEAST_EXPECT(map.
delItem(keys[k]));
284 BEAST_EXPECT(map.
getHash() == beast::zero);
294 uint256(
"f22891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
296 uint256(
"b99891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
298 uint256(
"b92891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
300 uint256(
"b92881fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
302 uint256(
"b92791fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
304 uint256(
"b92691fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
306 uint256(
"b91891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
308 uint256(
"292891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
315 for (
auto const& k : keys)
324 for (
auto const& k : map)
326 BEAST_EXPECT(k.key() == keys[h]);
348 for (
unsigned char c = 1; c < 100; ++c)
356 auto root = map.getHash().as_uint256();
357 auto path = map.getProofPath(k);
361 BEAST_EXPECT(map.verifyProofPath(
root, k, *path));
365 path->insert(path->begin(), path->front());
366 BEAST_EXPECT(!map.verifyProofPath(
root, k, *path));
369 BEAST_EXPECT(!map.getProofPath(wrongKey));
375 goodPath = std::move(*path);
380 BEAST_EXPECT(map.verifyProofPath(rootHash, key, goodPath));
383 BEAST_EXPECT(!map.verifyProofPath(rootHash, key, badPath));
387 BEAST_EXPECT(!map.verifyProofPath(rootHash, key, badPath));
391 BEAST_EXPECT(!map.verifyProofPath(rootHash, key, badPath));
395 badPath.
front().back()--;
396 BEAST_EXPECT(!map.verifyProofPath(rootHash, key, badPath));
401 BEAST_EXPECT(!map.verifyProofPath(rootHash, key, badPath));
406BEAST_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)