10#include <gtest/gtest.h>
22 bool success = db->read_block_data(blockNumber, blockData, *tx);
23 EXPECT_EQ(success, expectedSuccess);
24 if (expectedSuccess) {
25 EXPECT_EQ(blockData.
root, root);
28 success = db->read_node(root, nodeData, *tx);
29 EXPECT_EQ(success, expectedSuccess);
37 bool success = db->read_block_data(blockNumber, blockData, *tx);
38 EXPECT_EQ(success, expectedSuccess);
39 if (expectedSuccess) {
40 EXPECT_EQ(blockData.
root, root);
43 success = db->read_node(root, nodeData, *tx);
44 EXPECT_EQ(success, expectedRootSuccess);
54 bool success = db->read_block_data(blockNumber, blockData, *tx);
55 EXPECT_EQ(success, expectedSuccess);
56 if (expectedSuccess) {
57 EXPECT_EQ(blockData.
size, expectedSize);
66 bool success = db->read_leaf_index(leaf, retrieved, *tx);
67 EXPECT_EQ(success, entryShouldBePresent);
68 if (entryShouldBePresent) {
69 EXPECT_EQ(
index == retrieved, indexShouldBePresent);
74 bool expected_success =
true)
77 auto completion = [&](
const Response& response) ->
void {
78 EXPECT_EQ(response.
success, expected_success);
81 operation(completion);
85template <
typename LeafType,
typename Hash>
90 bool success = db->read_leaf_by_hash(Hash::hash(leaf.
get_hash_inputs()), fromStore, *tx);
91 EXPECT_EQ(success, shouldBePresent);
93 EXPECT_EQ(fromStore, leaf);
97template <
typename LeafValueType,
typename TypeOfTree>
101 bool expected_success,
102 bool includeUncommitted =
true)
106 EXPECT_EQ(response.success, expected_success);
107 if (expected_success) {
108 EXPECT_EQ(response.inner.leaf_indices, expected_indices);
113 tree.find_leaf_indices(leaves, includeUncommitted, completion);
117template <
typename LeafValueType,
typename TypeOfTree>
122 bool expected_success,
123 bool includeUncommitted =
true)
127 EXPECT_EQ(response.success, expected_success);
128 if (expected_success) {
129 EXPECT_EQ(response.inner.leaf_indices, expected_indices);
134 tree.find_leaf_indices_from(leaves, start_index, includeUncommitted, completion);
138template <
typename LeafValueType,
typename TypeOfTree>
143 bool expected_success,
144 bool includeUncommitted =
true)
148 EXPECT_EQ(response.success, expected_success);
149 if (expected_success) {
150 EXPECT_EQ(response.inner.leaf_indices, expected_indices);
155 tree.find_leaf_indices(leaves, blockNumber, includeUncommitted, completion);
159template <
typename LeafValueType,
typename TypeOfTree>
165 bool expected_success,
166 bool includeUncommitted =
true)
170 EXPECT_EQ(response.success, expected_success);
171 if (expected_success) {
172 EXPECT_EQ(response.inner.leaf_indices, expected_indices);
177 tree.find_leaf_indices_from(leaves, start_index, blockNumber, includeUncommitted, completion);
181template <
typename LeafValueType,
typename TypeOfTree>
185 bool expected_success,
186 bool includeUncommitted =
true)
188 check_find_leaf_index<LeafValueType, TypeOfTree>(
189 tree, { leaf }, {
std::make_optional(expected_index) }, expected_success, includeUncommitted);
192template <
typename LeafValueType,
typename TypeOfTree>
197 bool expected_success,
198 bool includeUncommitted =
true)
200 check_find_leaf_index_from<LeafValueType, TypeOfTree>(
201 tree, { leaf }, start_index, {
std::make_optional(expected_index) }, expected_success, includeUncommitted);
204template <
typename LeafValueType,
typename TypeOfTree>
209 bool expected_success,
210 bool includeUncommitted =
true)
212 check_historic_find_leaf_index<LeafValueType, TypeOfTree>(
213 tree, { leaf }, blockNumber, {
std::make_optional(expected_index) }, expected_success, includeUncommitted);
216template <
typename LeafValueType,
typename TypeOfTree>
222 bool expected_success,
223 bool includeUncommitted =
true)
225 check_historic_find_leaf_index_from<LeafValueType, TypeOfTree>(tree,
234template <
typename TypeOfTree>
237 bool includeUncommitted =
true,
238 bool expected_success =
true)
243 EXPECT_EQ(response.success, expected_success);
244 if (response.success) {
245 h = response.inner.path;
249 tree.get_sibling_path(
index, completion, includeUncommitted);
256 auto completion = [&](
auto completion) { tree.rollback(completion); };
262 auto completion = [&](
auto completion) { tree.checkpoint(completion); };
269 auto completion = [&](
auto completion) { tree.commit_checkpoint(completion); };
275 auto completion = [&](
auto completion) { tree.revert_checkpoint(completion); };
282 auto completion = [&](
auto completion) { tree.commit_all_checkpoints(completion); };
288 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