1
1
use blockifier:: retdata;
2
- use cairo_vm:: types:: relocatable:: MaybeRelocatable ;
3
- use cairo_vm:: vm:: runners:: cairo_runner:: CairoArg ;
4
2
3
+ use crate :: test_utils:: cairo_runner:: { EndpointArg , PointerArg , ValueArg } ;
5
4
use crate :: test_utils:: errors:: Cairo0EntryPointRunnerError ;
6
5
use crate :: test_utils:: utils:: run_cairo_function_and_check_result;
7
6
@@ -15,38 +14,90 @@ use crate::test_utils::utils::run_cairo_function_and_check_result;
15
14
/// b: felt,
16
15
/// }
17
16
///
18
- /// func dummy_function (number: felt, array: felt*, tuple: felt*, simple_struct: SimpleStruct*,
19
- /// compound_struct: CompoundStruct*) -> (res1: felt, res2: felt, res3: felt) {
17
+ /// func pass_felt_and_pointers (number: felt, array: felt*, tuple: felt*, simple_struct:
18
+ /// SimpleStruct*, compound_struct: CompoundStruct*) -> (res1: felt, res2: felt, res3: felt) {
20
19
/// let res1 = number + array[0];
21
20
/// let res2 = tuple[0] + tuple[1];
22
21
/// let res3 = simple_struct.a + compound_struct.simple_struct.b;
23
22
/// return (res1=res1, res2=res2, res3=res3);
24
23
/// }
24
+ ///
25
+ /// func pass_structs_and_tuples(tuple: (felt, felt), named_tuple: (a: felt, b:felt), simple_struct:
26
+ /// SimpleStruct, compound_struct: CompoundStruct) -> (res1: felt, res2: felt, res3: felt) {
27
+ /// let res1 = tuple[0] + tuple[1];
28
+ /// let res2 = named_tuple.a + named_tuple.b;
29
+ /// let res3 = simple_struct.a + compound_struct.simple_struct.b;
30
+ /// return (res1=res1, res2=res2, res3=res3);
31
+ /// }
25
32
const COMPILED_DUMMY_FUNCTION : & str = include_str ! ( "compiled_dummy_function.json" ) ;
26
33
27
34
#[ test]
28
- fn test_cairo0_function_runner ( ) -> Result < ( ) , Cairo0EntryPointRunnerError > {
35
+ fn test_felt_and_pointers ( ) -> Result < ( ) , Cairo0EntryPointRunnerError > {
29
36
let number = 2 ;
30
37
let ( first_array_val, second_array_val) = ( 3 , 4 ) ;
31
38
let ( first_tuple_val, second_tuple_val) = ( 5 , 6 ) ;
32
39
let ( first_simple_struct_val, second_simple_struct_val) = ( 7 , 8 ) ;
33
40
let compound_struct_val = 9 ;
34
- let array = CairoArg :: Array ( vec ! [ first_array_val. into( ) , second_array_val. into( ) ] ) ;
35
- let tuple = CairoArg :: Array ( vec ! [ first_tuple_val. into( ) , second_tuple_val. into( ) ] ) ;
36
- let simple_struct =
37
- CairoArg :: Array ( vec ! [ first_simple_struct_val. into( ) , second_simple_struct_val. into( ) ] ) ;
38
- let compound_struct = CairoArg :: Composed ( vec ! [
39
- MaybeRelocatable :: from( compound_struct_val) . into( ) ,
41
+ let array = EndpointArg :: Pointer ( PointerArg :: Array ( vec ! [
42
+ first_array_val. into( ) ,
43
+ second_array_val. into( ) ,
44
+ ] ) ) ;
45
+ let tuple = EndpointArg :: Pointer ( PointerArg :: Array ( vec ! [
46
+ first_tuple_val. into( ) ,
47
+ second_tuple_val. into( ) ,
48
+ ] ) ) ;
49
+ let simple_struct = EndpointArg :: Pointer ( PointerArg :: Array ( vec ! [
50
+ first_simple_struct_val. into( ) ,
51
+ second_simple_struct_val. into( ) ,
52
+ ] ) ) ;
53
+ let compound_struct = EndpointArg :: Pointer ( PointerArg :: Composed ( vec ! [
54
+ compound_struct_val. into( ) ,
40
55
simple_struct. clone( ) ,
41
- ] ) ;
56
+ ] ) ) ;
42
57
run_cairo_function_and_check_result (
43
58
COMPILED_DUMMY_FUNCTION ,
44
- "dummy_function " ,
45
- & [ MaybeRelocatable :: from ( number) . into ( ) , array, tuple, simple_struct, compound_struct] ,
59
+ "pass_felt_and_pointers " ,
60
+ & [ number. into ( ) , array, tuple, simple_struct, compound_struct] ,
46
61
& retdata ! [
47
62
( number + first_array_val) . into( ) ,
48
63
( first_tuple_val + second_tuple_val) . into( ) ,
49
64
( first_simple_struct_val + second_simple_struct_val) . into( )
50
65
] ,
51
66
)
52
67
}
68
+
69
+ #[ test]
70
+ fn test_tuples_and_structs ( ) -> Result < ( ) , Cairo0EntryPointRunnerError > {
71
+ let ( first_tuple_val, second_tuple_val) = ( 3 , 4 ) ;
72
+ let ( first_named_tuple_val, second_named_tuple_val) = ( 5 , 6 ) ;
73
+ let ( first_simple_struct_val, second_simple_struct_val) = ( 7 , 8 ) ;
74
+ let compound_struct_val = 9 ;
75
+ let tuple =
76
+ EndpointArg :: Value ( ValueArg :: Array ( vec ! [ first_tuple_val. into( ) , second_tuple_val. into( ) ] ) ) ;
77
+ let named_tuple = EndpointArg :: Value ( ValueArg :: Array ( vec ! [
78
+ first_named_tuple_val. into( ) ,
79
+ second_named_tuple_val. into( ) ,
80
+ ] ) ) ;
81
+ let simple_struct = EndpointArg :: Value ( ValueArg :: Array ( vec ! [
82
+ first_simple_struct_val. into( ) ,
83
+ second_simple_struct_val. into( ) ,
84
+ ] ) ) ;
85
+ let simple_struct_pointer = EndpointArg :: Pointer ( PointerArg :: Array ( vec ! [
86
+ first_simple_struct_val. into( ) ,
87
+ second_simple_struct_val. into( ) ,
88
+ ] ) ) ;
89
+ let compound_struct = EndpointArg :: Value ( ValueArg :: Composed ( vec ! [
90
+ compound_struct_val. into( ) ,
91
+ simple_struct_pointer,
92
+ ] ) ) ;
93
+ run_cairo_function_and_check_result (
94
+ COMPILED_DUMMY_FUNCTION ,
95
+ "pass_structs_and_tuples" ,
96
+ & [ tuple, named_tuple, simple_struct, compound_struct] ,
97
+ & retdata ! [
98
+ ( first_tuple_val + second_tuple_val) . into( ) ,
99
+ ( first_named_tuple_val + second_named_tuple_val) . into( ) ,
100
+ ( first_simple_struct_val + second_simple_struct_val) . into( )
101
+ ] ,
102
+ )
103
+ }
0 commit comments