16#include <gtest/gtest.h>
28 bool success = db->read_block_data(blockNumber, blockData, *tx);
29 EXPECT_EQ(success, expectedSuccess);
30 if (expectedSuccess) {
31 EXPECT_EQ(blockData.
root, root);
34 success = db->read_node(root, nodeData, *tx);
35 EXPECT_EQ(success, expectedSuccess);
43 bool success = db->read_block_data(blockNumber, blockData, *tx);
44 EXPECT_EQ(success, expectedSuccess);
45 if (expectedSuccess) {
46 EXPECT_EQ(blockData.
root, root);
49 success = db->read_node(root, nodeData, *tx);
50 EXPECT_EQ(success, expectedRootSuccess);
60 bool success = db->read_block_data(blockNumber, blockData, *tx);
61 EXPECT_EQ(success, expectedSuccess);
62 if (expectedSuccess) {
63 EXPECT_EQ(blockData.
size, expectedSize);
72 bool success = db->read_leaf_index(leaf, retrieved, *tx);
73 EXPECT_EQ(success, entryShouldBePresent);
74 if (entryShouldBePresent) {
75 EXPECT_EQ(index == retrieved, indexShouldBePresent);
80 bool expected_success =
true)
83 auto completion = [&](
const Response& response) ->
void {
84 EXPECT_EQ(response.
success, expected_success);
87 operation(completion);
91template <
typename LeafType,
typename Hash>
96 bool success = db->read_leaf_by_hash(Hash::hash(leaf.
get_hash_inputs()), fromStore, *tx);
97 EXPECT_EQ(success, shouldBePresent);
99 EXPECT_EQ(fromStore, leaf);
103template <
typename LeafValueType,
typename TypeOfTree>
107 bool expected_success,
108 bool includeUncommitted =
true)
112 EXPECT_EQ(response.success, expected_success);
113 if (expected_success) {
114 EXPECT_EQ(response.inner.leaf_indices, expected_indices);
119 tree.find_leaf_indices(leaves, includeUncommitted, completion);
123template <
typename LeafValueType,
typename TypeOfTree>
128 bool expected_success,
129 bool includeUncommitted =
true)
133 EXPECT_EQ(response.success, expected_success);
134 if (expected_success) {
135 EXPECT_EQ(response.inner.leaf_indices, expected_indices);
140 tree.find_leaf_indices_from(leaves, start_index, includeUncommitted, completion);
144template <
typename LeafValueType,
typename TypeOfTree>
149 bool expected_success,
150 bool includeUncommitted =
true)
154 EXPECT_EQ(response.success, expected_success);
155 if (expected_success) {
156 EXPECT_EQ(response.inner.leaf_indices, expected_indices);
161 tree.find_leaf_indices(leaves, blockNumber, includeUncommitted, completion);
165template <
typename LeafValueType,
typename TypeOfTree>
171 bool expected_success,
172 bool includeUncommitted =
true)
176 EXPECT_EQ(response.success, expected_success);
177 if (expected_success) {
178 EXPECT_EQ(response.inner.leaf_indices, expected_indices);
183 tree.find_leaf_indices_from(leaves, start_index, blockNumber, includeUncommitted, completion);
187template <
typename LeafValueType,
typename TypeOfTree>
191 bool expected_success,
192 bool includeUncommitted =
true)
194 check_find_leaf_index<LeafValueType, TypeOfTree>(
195 tree, { leaf }, {
std::make_optional(expected_index) }, expected_success, includeUncommitted);
198template <
typename LeafValueType,
typename TypeOfTree>
203 bool expected_success,
204 bool includeUncommitted =
true)
206 check_find_leaf_index_from<LeafValueType, TypeOfTree>(
207 tree, { leaf }, start_index, {
std::make_optional(expected_index) }, expected_success, includeUncommitted);
210template <
typename LeafValueType,
typename TypeOfTree>
215 bool expected_success,
216 bool includeUncommitted =
true)
218 check_historic_find_leaf_index<LeafValueType, TypeOfTree>(
219 tree, { leaf }, blockNumber, {
std::make_optional(expected_index) }, expected_success, includeUncommitted);
222template <
typename LeafValueType,
typename TypeOfTree>
228 bool expected_success,
229 bool includeUncommitted =
true)
231 check_historic_find_leaf_index_from<LeafValueType, TypeOfTree>(tree,
240template <
typename TypeOfTree>
243 bool includeUncommitted =
true,
244 bool expected_success =
true)
249 EXPECT_EQ(response.success, expected_success);
250 if (response.success) {
251 h = response.inner.path;
255 tree.get_sibling_path(index, completion, includeUncommitted);
262 auto completion = [&](
auto completion) { tree.rollback(completion); };
268 auto completion = [&](
auto completion) { tree.checkpoint(completion); };
275 auto completion = [&](
auto completion) { tree.commit_checkpoint(completion); };
281 auto completion = [&](
auto completion) { tree.revert_checkpoint(completion); };
288 auto completion = [&](
auto completion) { tree.commit_all_checkpoints(completion); };
294 auto completion = [&](
auto completion) { tree.revert_all_checkpoints(completion); };
std::shared_ptr< LMDBTreeStore > SharedPtr
Used in parallel insertions in the the IndexedTree. Workers signal to other following workes as they ...
void signal_level(uint32_t level=0)
Signals that the given level has been passed.
void wait_for_level(uint32_t level=0)
Causes the thread to wait until the required level has been signalled.
std::unique_ptr< LMDBReadTransaction > Ptr
PublicDataLeafValue LeafValueType
void checkpoint_tree(TreeType &tree)
void commit_all_tree_checkpoints(TreeType &tree, bool expected_success=true)
void rollback_tree(TreeType &tree)
void check_indices_data(LMDBTreeStore::SharedPtr db, fr leaf, index_t index, bool entryShouldBePresent, bool indexShouldBePresent)
void check_historic_find_leaf_index_from(TypeOfTree &tree, const std::vector< LeafValueType > &leaves, block_number_t blockNumber, index_t start_index, const std::vector< std::optional< index_t > > &expected_indices, bool expected_success, bool includeUncommitted=true)
void check_leaf_by_hash(LMDBTreeStore::SharedPtr db, IndexedLeaf< LeafType > leaf, bool shouldBePresent)
void check_find_leaf_index(TypeOfTree &tree, const std::vector< LeafValueType > &leaves, const std::vector< std::optional< index_t > > &expected_indices, bool expected_success, bool includeUncommitted=true)
void check_block_and_root_data(LMDBTreeStore::SharedPtr db, block_number_t blockNumber, fr root, bool expectedSuccess)
void check_find_leaf_index_from(TypeOfTree &tree, const std::vector< LeafValueType > &leaves, index_t start_index, const std::vector< std::optional< index_t > > &expected_indices, bool expected_success, bool includeUncommitted=true)
void call_operation(std::function< void(std::function< void(const Response &response)>)> operation, bool expected_success=true)
void check_block_and_size_data(LMDBTreeStore::SharedPtr db, block_number_t blockNumber, index_t expectedSize, bool expectedSuccess)
void commit_checkpoint_tree(TreeType &tree, bool expected_success=true)
std::vector< fr > fr_sibling_path
void revert_checkpoint_tree(TreeType &tree, bool expected_success=true)
void revert_all_tree_checkpoints(TreeType &tree, bool expected_success=true)
void check_historic_find_leaf_index(TypeOfTree &tree, const std::vector< LeafValueType > &leaves, block_number_t blockNumber, const std::vector< std::optional< index_t > > &expected_indices, bool expected_success, bool includeUncommitted=true)
fr_sibling_path get_sibling_path(TypeOfTree &tree, index_t index, bool includeUncommitted=true, bool expected_success=true)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
std::vector< fr > get_hash_inputs() const