@@ -9,6 +9,11 @@ use crate::{syscalls::syscall_handler_errors::SyscallHandlerError, utils::Addres
9
9
use cairo_vm:: { felt, types:: relocatable:: Relocatable , vm:: vm_core:: VirtualMachine } ;
10
10
use felt:: Felt252 ;
11
11
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.
12
17
pub ( crate ) trait DeprecatedWriteSyscallResponse {
13
18
fn write_syscall_response (
14
19
& self ,
@@ -17,6 +22,7 @@ pub(crate) trait DeprecatedWriteSyscallResponse {
17
22
) -> Result < ( ) , SyscallHandlerError > ;
18
23
}
19
24
25
+ /// Structs to hold response data for different deprecated system calls
20
26
#[ derive( Clone , Debug , PartialEq ) ]
21
27
pub ( crate ) struct DeprecatedCallContractResponse {
22
28
retdata_size : usize ,
@@ -143,6 +149,9 @@ impl DeprecatedDeployResponse {
143
149
}
144
150
}
145
151
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
+
146
155
impl DeprecatedWriteSyscallResponse for DeprecatedCallContractResponse {
147
156
fn write_syscall_response (
148
157
& self ,
@@ -317,19 +326,23 @@ mod tests {
317
326
InMemoryStateReader ,
318
327
> ;
319
328
329
+ /// Unit test to check the write_get_caller_address_response function
320
330
#[ test]
321
331
fn write_get_caller_address_response ( ) {
332
+ // Initialize a VM and syscall handler
322
333
let mut state = CachedState :: new ( Arc :: new ( InMemoryStateReader :: default ( ) ) , None , None ) ;
323
334
let syscall = DeprecatedBLSyscallHandler :: default_with ( & mut state) ;
324
335
let mut vm = vm ! ( ) ;
325
336
337
+ // Write the response of get_caller_address into the VM's memory
326
338
add_segments ! ( vm, 2 ) ;
327
339
328
340
let caller_address = 3 ;
329
341
let response = DeprecatedGetCallerAddressResponse {
330
342
caller_address : caller_address. into ( ) ,
331
343
} ;
332
344
345
+ // Check if the correct value is written in the expected memory location
333
346
assert ! ( syscall
334
347
. write_syscall_response( & response, & mut vm, relocatable!( 1 , 0 ) )
335
348
. is_ok( ) ) ;
0 commit comments