3#include <gmock/gmock.h>
4#include <gtest/gtest.h>
16using testing::ElementsAre;
18TEST(MerkleCheckSimulationTest, AssertMembership)
21 FakePoseidon2
poseidon2 = FakePoseidon2();
23 EventEmitter<MerkleCheckEvent> emitter;
24 MerkleCheck merkle_check(
poseidon2, emitter);
27 uint64_t leaf_index = 30;
28 std::vector<FF> sibling_path = { 10, 2, 30, 4, 50, 6 };
31 merkle_check.assert_membership(leaf_value, leaf_index, sibling_path, root);
32 MerkleCheckEvent expect_event = {
33 .leaf_value = leaf_value,
34 .leaf_index = leaf_index,
35 .sibling_path = sibling_path,
40 uint64_t leaf_index2 = 31;
41 std::vector<FF> sibling_path2 = { 10, 2, 30, 4, 50, 7 };
43 merkle_check.assert_membership(leaf_value2, leaf_index2, sibling_path2, root2);
44 MerkleCheckEvent expect_event2 = {
45 .leaf_value = leaf_value2,
46 .leaf_index = leaf_index2,
47 .sibling_path = sibling_path2,
51 EXPECT_THAT(emitter.dump_events(), ElementsAre(expect_event, expect_event2));
54TEST(MerkleCheckSimulationTest, Write)
57 FakePoseidon2
poseidon2 = FakePoseidon2();
59 EventEmitter<MerkleCheckEvent> emitter;
60 MerkleCheck merkle_check(
poseidon2, emitter);
62 FF current_value = 333;
64 uint64_t leaf_index = 30;
65 std::vector<FF> sibling_path = { 10, 2, 30, 4, 50, 6 };
69 MerkleCheckEvent expect_event = {
70 .leaf_value = current_value,
71 .new_leaf_value = new_value,
72 .leaf_index = leaf_index,
73 .sibling_path = sibling_path,
75 .new_root = expected_new_root,
78 FF new_root = merkle_check.write(current_value, new_value, leaf_index, sibling_path, current_root);
80 EXPECT_EQ(new_root, expected_new_root);
81 EXPECT_THAT(emitter.dump_events(), ElementsAre(expect_event));
84TEST(MerkleCheckSimulationTest, NegativeBadFinalIndex)
87 FakePoseidon2
poseidon2 = FakePoseidon2();
89 EventEmitter<MerkleCheckEvent> emitter;
90 MerkleCheck merkle_check(
poseidon2, emitter);
93 uint64_t leaf_index = 64;
94 std::vector<FF> sibling_path = { 10, 2, 30, 4, 50, 6 };
98 "Merkle check's final node index must be 0 or 1");
100 "Merkle check's final node index must be 0 or 1");
103TEST(MerkleCheckSimulationTest, NegativeWrongRoot)
106 FakePoseidon2
poseidon2 = FakePoseidon2();
108 EventEmitter<MerkleCheckEvent> emitter;
109 MerkleCheck merkle_check(
poseidon2, emitter);
112 uint64_t leaf_index = 30;
113 std::vector<FF> sibling_path = { 10, 2, 30, 4, 50, 6 };
114 FF incorrect_root = 66;
117 "Merkle read check failed");
119 "Merkle read check failed");
122TEST(MerkleCheckSimulationTest, NegativeWrongLeafIndex)
125 FakePoseidon2
poseidon2 = FakePoseidon2();
127 EventEmitter<MerkleCheckEvent> emitter;
128 MerkleCheck merkle_check(
poseidon2, emitter);
131 uint64_t leaf_index = 30;
132 std::vector<FF> sibling_path = { 10, 2, 30, 4, 50, 6 };
134 uint64_t incorrect_leaf_index = 31;
136 "Merkle read check failed");
138 "Merkle read check failed");
141TEST(MerkleCheckSimulationTest, NegativeWrongSiblingPath)
144 FakePoseidon2
poseidon2 = FakePoseidon2();
146 EventEmitter<MerkleCheckEvent> emitter;
147 MerkleCheck merkle_check(
poseidon2, emitter);
150 uint64_t leaf_index = 30;
151 std::vector<FF> sibling_path = { 10, 2, 30, 4, 50, 6 };
154 sibling_path[2] = 11;
157 "Merkle read check failed");
159 "Merkle read check failed");
162TEST(MerkleCheckSimulationTest, NegativeWrongLeafValue)
165 FakePoseidon2
poseidon2 = FakePoseidon2();
167 EventEmitter<MerkleCheckEvent> emitter;
168 MerkleCheck merkle_check(
poseidon2, emitter);
171 uint64_t leaf_index = 30;
172 std::vector<FF> sibling_path = { 10, 2, 30, 4, 50, 6 };
174 FF incorrect_leaf_value = 334;
177 "Merkle read check failed");
179 "Merkle read check failed");
#define EXPECT_THROW_WITH_MESSAGE(code, expectedMessage)
TEST(EmitUnencryptedLogTest, Basic)
FF unconstrained_root_from_path(const FF &leaf_value, const uint64_t leaf_index, std::span< const FF > path)