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

Commit f05da40

Browse files
fguthmannfannyguthmannjuanbonomatias-gonz
authored
Added documentations to syscalls/deprecated_syscall_handler module (#883)
* added comments to file syscalls/deprecated_syscall_handler-module' * Update src/syscalls/deprecated_syscall_handler.rs Co-authored-by: Matías Ignacio González <maigonzalez@fi.uba.ar> * Update src/syscalls/deprecated_syscall_handler.rs Co-authored-by: Matías Ignacio González <maigonzalez@fi.uba.ar> --------- Co-authored-by: fannyguthmann <fanny.guthmann@post.idc.ac.il> Co-authored-by: Juan Bono <juanbono94@gmail.com> Co-authored-by: Matías Ignacio González <maigonzalez@fi.uba.ar>
1 parent 025ef97 commit f05da40

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/syscalls/deprecated_syscall_handler.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@ use cairo_vm::{
2222
};
2323
use std::{any::Any, collections::HashMap};
2424

25+
/// Definition of the deprecated syscall hint processor with associated structs
2526
pub(crate) struct DeprecatedSyscallHintProcessor<'a, S: StateReader> {
2627
pub(crate) builtin_hint_processor: BuiltinHintProcessor,
2728
pub(crate) syscall_handler: DeprecatedBLSyscallHandler<'a, S>,
2829
run_resources: RunResources,
2930
}
3031

32+
/// Implementations and methods for DeprecatedSyscallHintProcessor
3133
impl<'a, S: StateReader> DeprecatedSyscallHintProcessor<'a, S> {
34+
/// Constructor for DeprecatedSyscallHintProcessor
3235
pub fn new(
3336
syscall_handler: DeprecatedBLSyscallHandler<'a, S>,
3437
run_resources: RunResources,
@@ -40,6 +43,7 @@ impl<'a, S: StateReader> DeprecatedSyscallHintProcessor<'a, S> {
4043
}
4144
}
4245

46+
/// Method to determine if a syscall hint should be run
4347
pub fn should_run_syscall_hint(
4448
&mut self,
4549
vm: &mut VirtualMachine,
@@ -57,13 +61,15 @@ impl<'a, S: StateReader> DeprecatedSyscallHintProcessor<'a, S> {
5761
}
5862
}
5963

64+
/// Method to execute a syscall hint
6065
fn execute_syscall_hint(
6166
&mut self,
6267
vm: &mut VirtualMachine,
6368
_exec_scopes: &mut ExecutionScopes,
6469
hint_data: &Box<dyn Any>,
6570
constants: &HashMap<String, Felt252>,
6671
) -> Result<(), SyscallHandlerError> {
72+
// Match against specific syscall hint codes and call the appropriate handler
6773
let hint_data = hint_data
6874
.downcast_ref::<HintProcessorData>()
6975
.ok_or(SyscallHandlerError::WrongHintData)?;
@@ -149,7 +155,9 @@ impl<'a, S: StateReader> DeprecatedSyscallHintProcessor<'a, S> {
149155
}
150156
}
151157

158+
/// Implement the HintProcessorLogic trait for DeprecatedSyscallHintProcessor
152159
impl<'a, S: StateReader> HintProcessorLogic for DeprecatedSyscallHintProcessor<'a, S> {
160+
/// Executes the received hint
153161
fn execute_hint(
154162
&mut self,
155163
vm: &mut VirtualMachine,
@@ -171,6 +179,7 @@ impl<'a, S: StateReader> HintProcessorLogic for DeprecatedSyscallHintProcessor<'
171179
}
172180
}
173181

182+
/// Implement the ResourceTracker trait for DeprecatedSyscallHintProcessor
174183
impl<'a, S: StateReader> ResourceTracker for DeprecatedSyscallHintProcessor<'a, S> {
175184
fn consumed(&self) -> bool {
176185
self.run_resources.consumed()
@@ -189,7 +198,9 @@ impl<'a, S: StateReader> ResourceTracker for DeprecatedSyscallHintProcessor<'a,
189198
}
190199
}
191200

201+
/// Implement the HintProcessorPostRun trait for DeprecatedSyscallHintProcessor
192202
impl<'a, S: StateReader> HintProcessorPostRun for DeprecatedSyscallHintProcessor<'a, S> {
203+
/// Validates the execution post run
193204
fn post_run(
194205
&self,
195206
runner: &mut VirtualMachine,
@@ -199,6 +210,7 @@ impl<'a, S: StateReader> HintProcessorPostRun for DeprecatedSyscallHintProcessor
199210
}
200211
}
201212

213+
/// Helper function to get the syscall pointer
202214
fn get_syscall_ptr(
203215
vm: &VirtualMachine,
204216
ids_data: &HashMap<String, HintReference>,
@@ -209,6 +221,7 @@ fn get_syscall_ptr(
209221
Ok(syscall_ptr)
210222
}
211223

224+
/// Unit tests for this module
212225
#[cfg(test)]
213226
mod tests {
214227
use std::sync::Arc;
@@ -247,6 +260,7 @@ mod tests {
247260
>;
248261
type SyscallHintProcessor<'a, T> = super::DeprecatedSyscallHintProcessor<'a, T>;
249262

263+
/// Test checks if the send_message_to_l1 syscall is read correctly.
250264
#[test]
251265
fn read_send_message_to_l1_request() {
252266
let mut state = CachedState::<InMemoryStateReader>::default();
@@ -269,6 +283,7 @@ mod tests {
269283
)
270284
}
271285

286+
/// Test verifies if the read syscall can correctly read a deploy request.
272287
#[test]
273288
fn read_deploy_syscall_request() {
274289
let mut state = CachedState::<InMemoryStateReader>::default();
@@ -301,6 +316,7 @@ mod tests {
301316
)
302317
}
303318

319+
/// Test checks the get block timestamp for business logic.
304320
#[test]
305321
fn get_block_timestamp_for_business_logic() {
306322
let mut state = CachedState::<InMemoryStateReader>::default();
@@ -342,6 +358,7 @@ mod tests {
342358
);
343359
}
344360

361+
/// Test checks the get sequencer address for business logic.
345362
#[test]
346363
fn get_sequencer_address_for_business_logic() {
347364
let mut vm = vm!();
@@ -372,6 +389,7 @@ mod tests {
372389
assert_eq!(get_big_int(&vm, relocatable!(1, 2)).unwrap(), 0.into())
373390
}
374391

392+
/// Test checks that the correct event has been emited witht th right parameters.
375393
#[test]
376394
fn emit_event_test() {
377395
// create data and variables to execute hint
@@ -445,6 +463,7 @@ mod tests {
445463
);
446464
}
447465

466+
/// Test checks the get transaction information for business logic.
448467
#[test]
449468
fn get_tx_info_for_business_logic_test() {
450469
let mut vm = vm!();
@@ -552,6 +571,7 @@ mod tests {
552571
);
553572
}
554573

574+
/// Test checks the get transaction information for business logic given the transaction info pointer.
555575
#[test]
556576
fn get_tx_info_for_business_logic_with_tx_info_ptr() {
557577
let mut vm = vm!();
@@ -597,6 +617,7 @@ mod tests {
597617
);
598618
}
599619

620+
/// Test checks the get caller address is the correct one.
600621
#[test]
601622
fn test_get_caller_address_ok() {
602623
let mut vm = vm!();
@@ -633,6 +654,7 @@ mod tests {
633654
)
634655
}
635656

657+
/// Test checks the message send to l1 is the correct one.
636658
#[test]
637659
fn test_send_message_to_l1_ok() {
638660
let mut vm = vm!();
@@ -694,6 +716,7 @@ mod tests {
694716
);
695717
}
696718

719+
/// Test checks that the block number that we get is the correct one.
697720
#[test]
698721
fn test_get_block_number() {
699722
let mut vm = vm!();
@@ -727,6 +750,7 @@ mod tests {
727750
assert_matches!(get_integer(&vm, relocatable!(2, 1)), Ok(0));
728751
}
729752

753+
/// Test checks the contract address we get is the correct one.
730754
#[test]
731755
fn test_get_contract_address_ok() {
732756
let mut vm = vm!();
@@ -763,6 +787,7 @@ mod tests {
763787
)
764788
}
765789

790+
/// Test checks the transaction signature we get is the correct one.
766791
#[test]
767792
fn test_gt_tx_signature() {
768793
let mut vm = vm!();
@@ -822,6 +847,7 @@ mod tests {
822847
);
823848
}
824849

850+
/// Tests the correct behavior of a storage read operation within a blockchain.
825851
#[test]
826852
fn test_bl_storage_read_hint_ok() {
827853
let mut vm = vm!();
@@ -885,6 +911,7 @@ mod tests {
885911
assert_matches!(get_big_int(&vm, relocatable!(2, 2)), Ok(response) if response == storage_value );
886912
}
887913

914+
/// Tests the correct behavior of a storage write operation within a blockchain.
888915
#[test]
889916
fn test_bl_storage_write_hint_ok() {
890917
let mut vm = vm!();
@@ -953,6 +980,7 @@ mod tests {
953980
assert_eq!(write, Felt252::new(45));
954981
}
955982

983+
/// Tests the correct behavior of a deploy operation within a blockchain.
956984
#[test]
957985
fn test_bl_deploy_ok() {
958986
let mut vm = vm!();
@@ -1043,6 +1071,7 @@ mod tests {
10431071
);
10441072
}
10451073

1074+
/// Tests the correct behavior of a storage deploy and invoke operations within a blockchain.
10461075
#[test]
10471076
fn test_deploy_and_invoke() {
10481077
/*

0 commit comments

Comments
 (0)