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__
120 constexpr uint256 h1(
"092891fe4ef6cee585fdc6fda0e09eb4d386363158ec3321b8123e5a772c6ca7");
121 constexpr uint256 h2(
"436ccbac3347baa1f1e53baeef1f43334da88f1f6d70d963b833afd6dfa289fe");
122 constexpr uint256 h3(
"b92891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e5a772c6ca8");
123 constexpr uint256 h4(
"b92891fe4ef6cee585fdc6fda2e09eb4d386363158ec3321b8123e5a772c6ca8");
124 constexpr uint256 h5(
"a92891fe4ef6cee585fdc6fda0e09eb4d386363158ec3321b8123e5a772c6ca7");
142 auto i = sMap.
begin();
144 unexpected(i == e || (*i != *i1),
"bad traverse");
146 unexpected(i == e || (*i != *i2),
"bad traverse");
157 unexpected(i == e || (*i != *i1),
"bad traverse");
159 unexpected(i == e || (*i != *i3),
"bad traverse");
161 unexpected(i == e || (*i != *i4),
"bad traverse");
174 unexpected(map2->getHash() != mapHash,
"bad snapshot");
177 BEAST_EXPECT(sMap.
compare(*map2, delta, 100));
178 BEAST_EXPECT(delta.
empty());
183 unexpected(map2->getHash() != mapHash,
"bad snapshot");
185 BEAST_EXPECT(sMap.
compare(*map2, delta, 100));
186 BEAST_EXPECT(delta.
size() == 1);
187 BEAST_EXPECT(delta.
begin()->first == h1);
188 BEAST_EXPECT(delta.
begin()->second.first ==
nullptr);
189 BEAST_EXPECT(delta.
begin()->second.second->key() == h1);
199 uint256(
"b92891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
201 uint256(
"b92881fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
203 uint256(
"b92691fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
205 uint256(
"b92791fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
207 uint256(
"b91891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
209 uint256(
"b99891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
211 uint256(
"f22891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
213 uint256(
"292891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
217 uint256(
"B7387CFEA0465759ADC718E8C42B52D2309D179B326E239EB5075C"
219 uint256(
"FBC195A9592A54AB44010274163CB6BA95F497EC5BA0A883184546"
221 uint256(
"4E7D2684B65DFD48937FFB775E20175C43AF0C94066F7D5679F51A"
223 uint256(
"7A2F312EB203695FFD164E038E281839EEF06A1B99BFC263F3CECC"
225 uint256(
"395A6691A372387A703FB0F2C6D2C405DAF307D0817F8F0E207596"
227 uint256(
"D044C0A696DE3169CC70AE216A1564D69DE96582865796142CE7D9"
229 uint256(
"76DCC77C4027309B5A91AD164083264D70B77B5E43E08AEDA5EBF9"
231 uint256(
"DF4220E93ADC6F5569063A01B4DC79F8DB9553B6A3222ADE23DEA0"
238 BEAST_EXPECT(map.
getHash() == beast::zero);
239 for (
int k = 0; k < keys.size(); ++k)
245 for (
int k = keys.size() - 1; k >= 0; --k)
248 BEAST_EXPECT(map.
delItem(keys[k]));
251 BEAST_EXPECT(map.
getHash() == beast::zero);
261 uint256(
"f22891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
263 uint256(
"b99891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
265 uint256(
"b92891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
267 uint256(
"b92881fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
269 uint256(
"b92791fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
271 uint256(
"b92691fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
273 uint256(
"b91891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
275 uint256(
"292891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e"
282 for (
auto const& k : keys)
289 for (
auto const& k : map)
291 BEAST_EXPECT(k.key() == keys[h]);
313 for (
unsigned char c = 1; c < 100; ++c)
319 auto root = map.getHash().as_uint256();
320 auto path = map.getProofPath(k);
324 BEAST_EXPECT(map.verifyProofPath(
root, k, *path));
328 path->insert(path->begin(), path->front());
329 BEAST_EXPECT(!map.verifyProofPath(
root, k, *path));
332 BEAST_EXPECT(!map.getProofPath(wrongKey));
338 goodPath = std::move(*path);
343 BEAST_EXPECT(map.verifyProofPath(rootHash, key, goodPath));
346 BEAST_EXPECT(!map.verifyProofPath(rootHash, key, badPath));
350 BEAST_EXPECT(!map.verifyProofPath(rootHash, key, badPath));
354 BEAST_EXPECT(!map.verifyProofPath(rootHash, key, badPath));
358 badPath.
front().back()--;
359 BEAST_EXPECT(!map.verifyProofPath(rootHash, key, badPath));
364 BEAST_EXPECT(!map.verifyProofPath(rootHash, key, badPath));
369BEAST_DEFINE_TESTSUITE(SHAMapPathProof, shamap,
xrpl);
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 addItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
const_iterator end() const
const_iterator begin() const
void dump(bool withHashes=false) const
bool compare(SHAMap const &otherMap, Delta &differences, int maxCount) const
std::shared_ptr< SHAMap > snapShot(bool isMutable) const
SHAMapHash getHash() const
bool delItem(uint256 const &id)
An immutable linear range of bytes.
static constexpr std::size_t size()
void run() override
Runs the suite.
static Buffer IntToVUC(int v)
void run() override
Runs the suite.
void run(bool backed, beast::Journal const &journal)
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)