@@ -22,13 +22,16 @@ use cairo_vm::{
22
22
} ;
23
23
use std:: { any:: Any , collections:: HashMap } ;
24
24
25
+ /// Definition of the deprecated syscall hint processor with associated structs
25
26
pub ( crate ) struct DeprecatedSyscallHintProcessor < ' a , S : StateReader > {
26
27
pub ( crate ) builtin_hint_processor : BuiltinHintProcessor ,
27
28
pub ( crate ) syscall_handler : DeprecatedBLSyscallHandler < ' a , S > ,
28
29
run_resources : RunResources ,
29
30
}
30
31
32
+ /// Implementations and methods for DeprecatedSyscallHintProcessor
31
33
impl < ' a , S : StateReader > DeprecatedSyscallHintProcessor < ' a , S > {
34
+ /// Constructor for DeprecatedSyscallHintProcessor
32
35
pub fn new (
33
36
syscall_handler : DeprecatedBLSyscallHandler < ' a , S > ,
34
37
run_resources : RunResources ,
@@ -40,6 +43,7 @@ impl<'a, S: StateReader> DeprecatedSyscallHintProcessor<'a, S> {
40
43
}
41
44
}
42
45
46
+ /// Method to determine if a syscall hint should be run
43
47
pub fn should_run_syscall_hint (
44
48
& mut self ,
45
49
vm : & mut VirtualMachine ,
@@ -57,13 +61,15 @@ impl<'a, S: StateReader> DeprecatedSyscallHintProcessor<'a, S> {
57
61
}
58
62
}
59
63
64
+ /// Method to execute a syscall hint
60
65
fn execute_syscall_hint (
61
66
& mut self ,
62
67
vm : & mut VirtualMachine ,
63
68
_exec_scopes : & mut ExecutionScopes ,
64
69
hint_data : & Box < dyn Any > ,
65
70
constants : & HashMap < String , Felt252 > ,
66
71
) -> Result < ( ) , SyscallHandlerError > {
72
+ // Match against specific syscall hint codes and call the appropriate handler
67
73
let hint_data = hint_data
68
74
. downcast_ref :: < HintProcessorData > ( )
69
75
. ok_or ( SyscallHandlerError :: WrongHintData ) ?;
@@ -149,7 +155,9 @@ impl<'a, S: StateReader> DeprecatedSyscallHintProcessor<'a, S> {
149
155
}
150
156
}
151
157
158
+ /// Implement the HintProcessorLogic trait for DeprecatedSyscallHintProcessor
152
159
impl < ' a , S : StateReader > HintProcessorLogic for DeprecatedSyscallHintProcessor < ' a , S > {
160
+ /// Executes the received hint
153
161
fn execute_hint (
154
162
& mut self ,
155
163
vm : & mut VirtualMachine ,
@@ -171,6 +179,7 @@ impl<'a, S: StateReader> HintProcessorLogic for DeprecatedSyscallHintProcessor<'
171
179
}
172
180
}
173
181
182
+ /// Implement the ResourceTracker trait for DeprecatedSyscallHintProcessor
174
183
impl < ' a , S : StateReader > ResourceTracker for DeprecatedSyscallHintProcessor < ' a , S > {
175
184
fn consumed ( & self ) -> bool {
176
185
self . run_resources . consumed ( )
@@ -189,7 +198,9 @@ impl<'a, S: StateReader> ResourceTracker for DeprecatedSyscallHintProcessor<'a,
189
198
}
190
199
}
191
200
201
+ /// Implement the HintProcessorPostRun trait for DeprecatedSyscallHintProcessor
192
202
impl < ' a , S : StateReader > HintProcessorPostRun for DeprecatedSyscallHintProcessor < ' a , S > {
203
+ /// Validates the execution post run
193
204
fn post_run (
194
205
& self ,
195
206
runner : & mut VirtualMachine ,
@@ -199,6 +210,7 @@ impl<'a, S: StateReader> HintProcessorPostRun for DeprecatedSyscallHintProcessor
199
210
}
200
211
}
201
212
213
+ /// Helper function to get the syscall pointer
202
214
fn get_syscall_ptr (
203
215
vm : & VirtualMachine ,
204
216
ids_data : & HashMap < String , HintReference > ,
@@ -209,6 +221,7 @@ fn get_syscall_ptr(
209
221
Ok ( syscall_ptr)
210
222
}
211
223
224
+ /// Unit tests for this module
212
225
#[ cfg( test) ]
213
226
mod tests {
214
227
use std:: sync:: Arc ;
@@ -247,6 +260,7 @@ mod tests {
247
260
> ;
248
261
type SyscallHintProcessor < ' a , T > = super :: DeprecatedSyscallHintProcessor < ' a , T > ;
249
262
263
+ /// Test checks if the send_message_to_l1 syscall is read correctly.
250
264
#[ test]
251
265
fn read_send_message_to_l1_request ( ) {
252
266
let mut state = CachedState :: < InMemoryStateReader > :: default ( ) ;
@@ -269,6 +283,7 @@ mod tests {
269
283
)
270
284
}
271
285
286
+ /// Test verifies if the read syscall can correctly read a deploy request.
272
287
#[ test]
273
288
fn read_deploy_syscall_request ( ) {
274
289
let mut state = CachedState :: < InMemoryStateReader > :: default ( ) ;
@@ -301,6 +316,7 @@ mod tests {
301
316
)
302
317
}
303
318
319
+ /// Test checks the get block timestamp for business logic.
304
320
#[ test]
305
321
fn get_block_timestamp_for_business_logic ( ) {
306
322
let mut state = CachedState :: < InMemoryStateReader > :: default ( ) ;
@@ -342,6 +358,7 @@ mod tests {
342
358
) ;
343
359
}
344
360
361
+ /// Test checks the get sequencer address for business logic.
345
362
#[ test]
346
363
fn get_sequencer_address_for_business_logic ( ) {
347
364
let mut vm = vm ! ( ) ;
@@ -372,6 +389,7 @@ mod tests {
372
389
assert_eq ! ( get_big_int( & vm, relocatable!( 1 , 2 ) ) . unwrap( ) , 0 . into( ) )
373
390
}
374
391
392
+ /// Test checks that the correct event has been emited witht th right parameters.
375
393
#[ test]
376
394
fn emit_event_test ( ) {
377
395
// create data and variables to execute hint
@@ -445,6 +463,7 @@ mod tests {
445
463
) ;
446
464
}
447
465
466
+ /// Test checks the get transaction information for business logic.
448
467
#[ test]
449
468
fn get_tx_info_for_business_logic_test ( ) {
450
469
let mut vm = vm ! ( ) ;
@@ -552,6 +571,7 @@ mod tests {
552
571
) ;
553
572
}
554
573
574
+ /// Test checks the get transaction information for business logic given the transaction info pointer.
555
575
#[ test]
556
576
fn get_tx_info_for_business_logic_with_tx_info_ptr ( ) {
557
577
let mut vm = vm ! ( ) ;
@@ -597,6 +617,7 @@ mod tests {
597
617
) ;
598
618
}
599
619
620
+ /// Test checks the get caller address is the correct one.
600
621
#[ test]
601
622
fn test_get_caller_address_ok ( ) {
602
623
let mut vm = vm ! ( ) ;
@@ -633,6 +654,7 @@ mod tests {
633
654
)
634
655
}
635
656
657
+ /// Test checks the message send to l1 is the correct one.
636
658
#[ test]
637
659
fn test_send_message_to_l1_ok ( ) {
638
660
let mut vm = vm ! ( ) ;
@@ -694,6 +716,7 @@ mod tests {
694
716
) ;
695
717
}
696
718
719
+ /// Test checks that the block number that we get is the correct one.
697
720
#[ test]
698
721
fn test_get_block_number ( ) {
699
722
let mut vm = vm ! ( ) ;
@@ -727,6 +750,7 @@ mod tests {
727
750
assert_matches ! ( get_integer( & vm, relocatable!( 2 , 1 ) ) , Ok ( 0 ) ) ;
728
751
}
729
752
753
+ /// Test checks the contract address we get is the correct one.
730
754
#[ test]
731
755
fn test_get_contract_address_ok ( ) {
732
756
let mut vm = vm ! ( ) ;
@@ -763,6 +787,7 @@ mod tests {
763
787
)
764
788
}
765
789
790
+ /// Test checks the transaction signature we get is the correct one.
766
791
#[ test]
767
792
fn test_gt_tx_signature ( ) {
768
793
let mut vm = vm ! ( ) ;
@@ -822,6 +847,7 @@ mod tests {
822
847
) ;
823
848
}
824
849
850
+ /// Tests the correct behavior of a storage read operation within a blockchain.
825
851
#[ test]
826
852
fn test_bl_storage_read_hint_ok ( ) {
827
853
let mut vm = vm ! ( ) ;
@@ -885,6 +911,7 @@ mod tests {
885
911
assert_matches ! ( get_big_int( & vm, relocatable!( 2 , 2 ) ) , Ok ( response) if response == storage_value ) ;
886
912
}
887
913
914
+ /// Tests the correct behavior of a storage write operation within a blockchain.
888
915
#[ test]
889
916
fn test_bl_storage_write_hint_ok ( ) {
890
917
let mut vm = vm ! ( ) ;
@@ -953,6 +980,7 @@ mod tests {
953
980
assert_eq ! ( write, Felt252 :: new( 45 ) ) ;
954
981
}
955
982
983
+ /// Tests the correct behavior of a deploy operation within a blockchain.
956
984
#[ test]
957
985
fn test_bl_deploy_ok ( ) {
958
986
let mut vm = vm ! ( ) ;
@@ -1043,6 +1071,7 @@ mod tests {
1043
1071
) ;
1044
1072
}
1045
1073
1074
+ /// Tests the correct behavior of a storage deploy and invoke operations within a blockchain.
1046
1075
#[ test]
1047
1076
fn test_deploy_and_invoke ( ) {
1048
1077
/*
0 commit comments