From 81f10f2ae96986df8f5a665c21a56734f404dc68 Mon Sep 17 00:00:00 2001 From: fannyguthmann Date: Fri, 28 Jul 2023 12:15:24 +0300 Subject: [PATCH 1/3] added documentation --- src/syscalls/deprecated_syscall_response.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/syscalls/deprecated_syscall_response.rs b/src/syscalls/deprecated_syscall_response.rs index 1851f25ef..35408873c 100644 --- a/src/syscalls/deprecated_syscall_response.rs +++ b/src/syscalls/deprecated_syscall_response.rs @@ -9,6 +9,11 @@ use crate::{syscalls::syscall_handler_errors::SyscallHandlerError, utils::Addres use cairo_vm::{felt, types::relocatable::Relocatable, vm::vm_core::VirtualMachine}; use felt::Felt252; +// Trait to write the response of a deprecated system call +// Takes in a mutable reference to a VirtualMachine and a Relocatable pointer to the system +///## Parameters: +///- vm: mutable reference to a VirtualMachine. +///- syscall_ptr: Relocatable pointer to the system. pub(crate) trait DeprecatedWriteSyscallResponse { fn write_syscall_response( &self, @@ -17,6 +22,7 @@ pub(crate) trait DeprecatedWriteSyscallResponse { ) -> Result<(), SyscallHandlerError>; } +// Structs to hold response data for different deprecated system calls #[derive(Clone, Debug, PartialEq)] pub(crate) struct DeprecatedCallContractResponse { retdata_size: usize, @@ -143,6 +149,9 @@ impl DeprecatedDeployResponse { } } +// Implementation of the DeprecatedWriteSyscallResponse trait for the different structs. +// Each struct writes the response of its corresponding system call in the VM's memory. + impl DeprecatedWriteSyscallResponse for DeprecatedCallContractResponse { fn write_syscall_response( &self, @@ -317,12 +326,15 @@ mod tests { InMemoryStateReader, >; + // Unit test to check the write_get_caller_address_response function #[test] fn write_get_caller_address_response() { + // Initialize a VM and syscall handler let mut state = CachedState::new(Arc::new(InMemoryStateReader::default()), None, None); let syscall = DeprecatedBLSyscallHandler::default_with(&mut state); let mut vm = vm!(); + // Write the response of get_caller_address into the VM's memory add_segments!(vm, 2); let caller_address = 3; @@ -330,6 +342,7 @@ mod tests { caller_address: caller_address.into(), }; + // Check if the correct value is written in the expected memory location assert!(syscall .write_syscall_response(&response, &mut vm, relocatable!(1, 0)) .is_ok()); @@ -340,3 +353,4 @@ mod tests { assert_matches!(get_integer(&vm, relocatable!(1, 1)), Ok(x) if x == caller_address); } } + From 1394447a652cbd63d00b41983a8779dab4ae6d21 Mon Sep 17 00:00:00 2001 From: fannyguthmann Date: Fri, 28 Jul 2023 12:22:16 +0300 Subject: [PATCH 2/3] change format --- src/syscalls/deprecated_syscall_response.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/syscalls/deprecated_syscall_response.rs b/src/syscalls/deprecated_syscall_response.rs index 35408873c..e727faf43 100644 --- a/src/syscalls/deprecated_syscall_response.rs +++ b/src/syscalls/deprecated_syscall_response.rs @@ -353,4 +353,3 @@ mod tests { assert_matches!(get_integer(&vm, relocatable!(1, 1)), Ok(x) if x == caller_address); } } - From 829dc9f99fa6f240f7153eba34db83f6e06000c0 Mon Sep 17 00:00:00 2001 From: fannyguthmann Date: Fri, 28 Jul 2023 16:34:59 +0300 Subject: [PATCH 3/3] modify // to /// --- src/syscalls/deprecated_syscall_response.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/syscalls/deprecated_syscall_response.rs b/src/syscalls/deprecated_syscall_response.rs index e727faf43..85e3e9cc1 100644 --- a/src/syscalls/deprecated_syscall_response.rs +++ b/src/syscalls/deprecated_syscall_response.rs @@ -9,8 +9,8 @@ use crate::{syscalls::syscall_handler_errors::SyscallHandlerError, utils::Addres use cairo_vm::{felt, types::relocatable::Relocatable, vm::vm_core::VirtualMachine}; use felt::Felt252; -// Trait to write the response of a deprecated system call -// Takes in a mutable reference to a VirtualMachine and a Relocatable pointer to the system +/// Trait to write the response of a deprecated system call +/// Takes in a mutable reference to a VirtualMachine and a Relocatable pointer to the system ///## Parameters: ///- vm: mutable reference to a VirtualMachine. ///- syscall_ptr: Relocatable pointer to the system. @@ -22,7 +22,7 @@ pub(crate) trait DeprecatedWriteSyscallResponse { ) -> Result<(), SyscallHandlerError>; } -// Structs to hold response data for different deprecated system calls +/// Structs to hold response data for different deprecated system calls #[derive(Clone, Debug, PartialEq)] pub(crate) struct DeprecatedCallContractResponse { retdata_size: usize, @@ -149,8 +149,8 @@ impl DeprecatedDeployResponse { } } -// Implementation of the DeprecatedWriteSyscallResponse trait for the different structs. -// Each struct writes the response of its corresponding system call in the VM's memory. +/// Implementation of the DeprecatedWriteSyscallResponse trait for the different structs. +/// Each struct writes the response of its corresponding system call in the VM's memory. impl DeprecatedWriteSyscallResponse for DeprecatedCallContractResponse { fn write_syscall_response( @@ -326,7 +326,7 @@ mod tests { InMemoryStateReader, >; - // Unit test to check the write_get_caller_address_response function + /// Unit test to check the write_get_caller_address_response function #[test] fn write_get_caller_address_response() { // Initialize a VM and syscall handler