Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 981f0f4

Browse files
fguthmannfannyguthmann
andauthored
Add documentation to syscalls/deprecated_syscall_response module (#866)
* added documentation * change format * modify // to /// --------- Co-authored-by: fannyguthmann <fanny.guthmann@post.idc.ac.il>
1 parent cdcab8c commit 981f0f4

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/syscalls/deprecated_syscall_response.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ use crate::{syscalls::syscall_handler_errors::SyscallHandlerError, utils::Addres
99
use cairo_vm::{felt, types::relocatable::Relocatable, vm::vm_core::VirtualMachine};
1010
use felt::Felt252;
1111

12+
/// Trait to write the response of a deprecated system call
13+
/// Takes in a mutable reference to a VirtualMachine and a Relocatable pointer to the system
14+
///## Parameters:
15+
///- vm: mutable reference to a VirtualMachine.
16+
///- syscall_ptr: Relocatable pointer to the system.
1217
pub(crate) trait DeprecatedWriteSyscallResponse {
1318
fn write_syscall_response(
1419
&self,
@@ -17,6 +22,7 @@ pub(crate) trait DeprecatedWriteSyscallResponse {
1722
) -> Result<(), SyscallHandlerError>;
1823
}
1924

25+
/// Structs to hold response data for different deprecated system calls
2026
#[derive(Clone, Debug, PartialEq)]
2127
pub(crate) struct DeprecatedCallContractResponse {
2228
retdata_size: usize,
@@ -143,6 +149,9 @@ impl DeprecatedDeployResponse {
143149
}
144150
}
145151

152+
/// Implementation of the DeprecatedWriteSyscallResponse trait for the different structs.
153+
/// Each struct writes the response of its corresponding system call in the VM's memory.
154+
146155
impl DeprecatedWriteSyscallResponse for DeprecatedCallContractResponse {
147156
fn write_syscall_response(
148157
&self,
@@ -317,19 +326,23 @@ mod tests {
317326
InMemoryStateReader,
318327
>;
319328

329+
/// Unit test to check the write_get_caller_address_response function
320330
#[test]
321331
fn write_get_caller_address_response() {
332+
// Initialize a VM and syscall handler
322333
let mut state = CachedState::new(Arc::new(InMemoryStateReader::default()), None, None);
323334
let syscall = DeprecatedBLSyscallHandler::default_with(&mut state);
324335
let mut vm = vm!();
325336

337+
// Write the response of get_caller_address into the VM's memory
326338
add_segments!(vm, 2);
327339

328340
let caller_address = 3;
329341
let response = DeprecatedGetCallerAddressResponse {
330342
caller_address: caller_address.into(),
331343
};
332344

345+
// Check if the correct value is written in the expected memory location
333346
assert!(syscall
334347
.write_syscall_response(&response, &mut vm, relocatable!(1, 0))
335348
.is_ok());

0 commit comments

Comments
 (0)