Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/syscalls/deprecated_syscall_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -317,19 +326,23 @@ 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;
let response = DeprecatedGetCallerAddressResponse {
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());
Expand Down