4#include <gmock/gmock.h>
5#include <gtest/gtest.h>
21using ::testing::ElementsAre;
22using ::testing::Return;
23using ::testing::ReturnRef;
24using ::testing::StrictMock;
26class DataCopySimulationTest :
public ::testing::Test {
28 DataCopySimulationTest()
30 ON_CALL(context, get_memory()).WillByDefault(ReturnRef(mem));
33 EXPECT_CALL(context, get_memory());
34 EXPECT_CALL(execution_id_manager, get_execution_id());
35 EXPECT_CALL(context, get_context_id());
43 DataCopy
data_copy = DataCopy(execution_id_manager, gt, event_emitter);
48class NestedCdCopySimulationTest :
public DataCopySimulationTest {
50 NestedCdCopySimulationTest()
58 EXPECT_CALL(
context, get_parent_id());
59 EXPECT_CALL(
context, has_parent()).WillRepeatedly(Return(
true));
63 MemoryValue::from<FF>(4), MemoryValue::from<FF>(5), MemoryValue::from<FF>(6),
64 MemoryValue::from<FF>(7), MemoryValue::from<FF>(8) };
70TEST_F(NestedCdCopySimulationTest, CdZero)
73 uint32_t cd_copy_size = 0;
79 EXPECT_TRUE(c.as_ff().is_zero());
82TEST_F(NestedCdCopySimulationTest, CdCopyAll)
85 uint32_t cd_copy_size =
static_cast<uint32_t
>(
calldata.size());
87 EXPECT_CALL(context, get_calldata(
cd_offset, cd_copy_size)).WillOnce(Return(calldata));
93 std::vector<FF> calldata_in_memory;
94 for (uint32_t i = 0; i < cd_copy_size; ++i) {
96 calldata_in_memory.emplace_back(c.as_ff());
98 EXPECT_THAT(calldata_in_memory, ElementsAre(1, 2, 3, 4, 5, 6, 7, 8));
101TEST_F(NestedCdCopySimulationTest, CdCopyPartial)
104 uint32_t cd_copy_size = 2;
106 EXPECT_CALL(context, get_calldata(
cd_offset, cd_copy_size))
108 MemoryValue::from<FF>(2) }));
113 std::vector<FF> calldata_in_memory;
114 for (uint32_t i = 0; i < cd_copy_size; ++i) {
116 calldata_in_memory.emplace_back(c.as_ff());
118 EXPECT_THAT(calldata_in_memory, ElementsAre(1, 2));
121TEST_F(NestedCdCopySimulationTest, CdFullWithPadding)
124 uint32_t cd_copy_size = 10;
127 MemoryValue::from<FF>(1), MemoryValue::from<FF>(2), MemoryValue::from<FF>(3), MemoryValue::from<FF>(4),
128 MemoryValue::from<FF>(5), MemoryValue::from<FF>(6), MemoryValue::from<FF>(7), MemoryValue::from<FF>(8),
129 MemoryValue::from<FF>(0), MemoryValue::from<FF>(0)
131 EXPECT_CALL(context, get_calldata(
cd_offset, cd_copy_size)).WillOnce(Return(expected_calldata));
136 std::vector<FF> calldata_in_memory;
137 for (uint32_t i = 0; i < cd_copy_size; ++i) {
139 calldata_in_memory.emplace_back(c.as_ff());
141 EXPECT_THAT(calldata_in_memory, ElementsAre(1, 2, 3, 4, 5, 6, 7, 8, 0, 0));
144TEST_F(NestedCdCopySimulationTest, CdPartialWithPadding)
147 uint32_t cd_copy_size = 4;
151 MemoryValue::from<FF>(7),
152 MemoryValue::from<FF>(8),
153 MemoryValue::from<FF>(0),
154 MemoryValue::from<FF>(0),
157 EXPECT_CALL(context, get_calldata(
cd_offset, cd_copy_size)).WillOnce(Return(expected_calldata));
162 std::vector<FF> calldata_in_memory;
163 for (uint32_t i = 0; i < cd_copy_size; ++i) {
165 calldata_in_memory.emplace_back(c.as_ff());
167 EXPECT_THAT(calldata_in_memory, ElementsAre(7, 8, 0, 0));
170class RdCopySimulationTest :
public DataCopySimulationTest {
172 RdCopySimulationTest()
175 EXPECT_CALL(context, get_last_rd_addr()).WillRepeatedly(Return(child_rd_addr));
176 EXPECT_CALL(context, get_last_rd_size()).WillRepeatedly(Return(child_rd_size));
177 EXPECT_CALL(context, get_last_child_id()).WillRepeatedly(Return(child_context_id));
178 EXPECT_CALL(context, has_parent()).WillRepeatedly(Return(
true));
179 EXPECT_CALL(context, get_last_child_id()).WillRepeatedly(Return(2));
182 MemoryValue::from<FF>(9), MemoryValue::from<FF>(10), MemoryValue::from<FF>(11), MemoryValue::from<FF>(12)
189TEST_F(RdCopySimulationTest, RdZero)
192 uint32_t rd_copy_size = 0;
193 uint32_t rd_offset = 0;
198 EXPECT_TRUE(c.as_ff().is_zero());
201TEST_F(RdCopySimulationTest, RdCopyAll)
204 uint32_t rd_copy_size =
static_cast<uint32_t
>(
returndata.size());
205 uint32_t rd_offset = 0;
207 EXPECT_CALL(context, get_returndata(rd_offset, rd_copy_size)).WillOnce(Return(
returndata));
212 std::vector<FF> returndata_in_memory;
213 for (uint32_t i = 0; i < rd_copy_size; ++i) {
215 returndata_in_memory.emplace_back(c.as_ff());
217 EXPECT_THAT(returndata_in_memory, ElementsAre(9, 10, 11, 12));
220TEST_F(RdCopySimulationTest, RdCopyPartial)
223 uint32_t rd_copy_size = 2;
224 uint32_t rd_offset = 1;
226 EXPECT_CALL(context, get_returndata(rd_offset, rd_copy_size))
228 MemoryValue::from<FF>(11) }));
233 std::vector<FF> returndata_in_memory;
234 for (uint32_t i = 0; i < rd_copy_size; ++i) {
236 returndata_in_memory.emplace_back(c.as_ff());
238 EXPECT_THAT(returndata_in_memory, ElementsAre(10, 11));
241TEST_F(RdCopySimulationTest, RdFullWithPadding)
244 uint32_t rd_copy_size = 10;
245 uint32_t rd_offset = 0;
248 MemoryValue::from<FF>(9), MemoryValue::from<FF>(10), MemoryValue::from<FF>(11), MemoryValue::from<FF>(12),
249 MemoryValue::from<FF>(0), MemoryValue::from<FF>(0), MemoryValue::from<FF>(0), MemoryValue::from<FF>(0),
250 MemoryValue::from<FF>(0), MemoryValue::from<FF>(0)
252 EXPECT_CALL(context, get_returndata(rd_offset, rd_copy_size)).WillOnce(Return(expected_returndata));
257 std::vector<FF> returndata_in_memory;
258 for (uint32_t i = 0; i < rd_copy_size; ++i) {
260 returndata_in_memory.emplace_back(c.as_ff());
262 EXPECT_THAT(returndata_in_memory, ElementsAre(9, 10, 11, 12, 0, 0, 0, 0, 0, 0));
265TEST_F(RdCopySimulationTest, RdPartialWithPadding)
268 uint32_t rd_copy_size = 4;
269 uint32_t rd_offset = 2;
272 MemoryValue::from<FF>(11),
273 MemoryValue::from<FF>(12),
274 MemoryValue::from<FF>(0),
275 MemoryValue::from<FF>(0),
278 EXPECT_CALL(context, get_returndata(rd_offset, rd_copy_size)).WillOnce(Return(expected_returndata));
283 std::vector<FF> returndata_in_memory;
284 for (uint32_t i = 0; i < rd_copy_size; ++i) {
286 returndata_in_memory.emplace_back(c.as_ff());
288 EXPECT_THAT(returndata_in_memory, ElementsAre(11, 12, 0, 0));
static TaggedValue from(T value)
void rd_copy(ContextInterface &context, uint32_t copy_size, uint32_t offset, MemoryAddress dst_addr) override
Copies returndata from the last executed context to the dst_addr.
void cd_copy(ContextInterface &context, uint32_t copy_size, uint32_t offset, MemoryAddress dst_addr) override
Writes calldata into dst_addr. There is slight difference in how enqueued and nested contexts are han...
const MemoryValue & get(MemoryAddress index) const override
ExecutionIdManager execution_id_manager
EventEmitter< DataCopyEvent > event_emitter
StrictMock< MockContext > context
TEST_F(IPATest, ChallengesAreZero)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
std::vector< MemoryValue > calldata
uint32_t child_context_id
std::vector< MemoryValue > returndata