Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
discard_reconstruction.test.cpp
Go to the documentation of this file.
2
3#include <gmock/gmock.h>
4#include <gtest/gtest.h>
5
7
8namespace bb::avm2::tracegen {
9namespace {
10
12
13struct PayloadEvent {
14 uint64_t foo;
15};
16
17struct Row {
18 uint64_t foo;
19 bool discard;
20
21 bool operator==(const Row& other) const = default;
22};
23
25
26using ::testing::AllOf;
27using ::testing::ElementsAre;
28
30{
32
33 process_with_discard(events, [&](const PayloadEvent& event, bool discard) {
34 rows.push_back({ .foo = event.foo, .discard = discard });
35 });
36
37 return rows;
38}
39
40TEST(DiscardReconstructionTest, DiscardNestedReverts)
41{
43 CheckPointEventType::CREATE_CHECKPOINT,
44 PayloadEvent{
45 .foo = 1000,
46 },
47
48 CheckPointEventType::CREATE_CHECKPOINT,
49 PayloadEvent{
50 .foo = 1001,
51 },
52 CheckPointEventType::REVERT_CHECKPOINT,
53 PayloadEvent{
54 .foo = 1002,
55 },
56 CheckPointEventType::REVERT_CHECKPOINT,
57 PayloadEvent{
58 .foo = 1003,
59 },
60 };
61
62 auto rows = tracegen(events);
63
64 EXPECT_THAT(rows,
65 ElementsAre(AllOf(Row{ .foo = 1000, .discard = 1 }),
66 AllOf(Row{ .foo = 1001, .discard = 1 }),
67 AllOf(Row{ .foo = 1002, .discard = 1 }),
68 // Not discarded
69 AllOf(Row{ .foo = 1003, .discard = 0 })));
70}
71
72TEST(DiscardReconstructionTest, DiscardSequentialReverts)
73{
75 PayloadEvent{
76 .foo = 1000,
77 },
78
79 CheckPointEventType::CREATE_CHECKPOINT,
80 PayloadEvent{
81 .foo = 1001,
82 },
83 CheckPointEventType::REVERT_CHECKPOINT,
84 PayloadEvent{
85 .foo = 1002,
86 },
87 CheckPointEventType::CREATE_CHECKPOINT,
88 PayloadEvent{
89 .foo = 1003,
90 },
91 CheckPointEventType::REVERT_CHECKPOINT,
92 PayloadEvent{
93 .foo = 1004,
94 },
95 };
96
97 auto rows = tracegen(events);
98
99 EXPECT_THAT(rows,
100 ElementsAre(AllOf(Row{ .foo = 1000, .discard = 0 }),
101 // First discarded checkpoint
102 AllOf(Row{ .foo = 1001, .discard = 1 }),
103 // End first discarded checkpoint
104 AllOf(Row{ .foo = 1002, .discard = 0 }),
105 // Second discarded checkpoint
106 AllOf(Row{ .foo = 1003, .discard = 1 }),
107 // End second discarded checkpoint
108 AllOf(Row{ .foo = 1004, .discard = 0 })));
109}
110
111} // namespace
112} // namespace bb::avm2::tracegen
TEST(EmitUnencryptedLogTest, Basic)
void process_with_discard(const std::vector< std::variant< EventType, simulation::CheckPointEventType > > &events, ProcessEventFn &&process_event)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
simulation::PublicDataTreeReadWriteEvent event