@@ -13,9 +13,9 @@ use test_case::test_case;
1313use tokio:: sync:: OnceCell ;
1414use url:: Url ;
1515
16- // https://sepolia.starkscan.co/class/0x02a9b456118a86070a8c116c41b02e490f3dcc9db3cad945b4e9a7fd7cec9168#code
16+ // Deployment of contract from /tests/data/data_transformer
1717const TEST_CLASS_HASH : Felt =
18- Felt :: from_hex_unchecked ( "0x02a9b456118a86070a8c116c41b02e490f3dcc9db3cad945b4e9a7fd7cec9168 " ) ;
18+ Felt :: from_hex_unchecked ( "0x032e6763d5e778f153e5b6ea44200d94ec89aac7b42a0aef0e4e0caac8dafdab " ) ;
1919
2020static CLASS : OnceCell < ContractClass > = OnceCell :: const_new ( ) ;
2121
@@ -435,6 +435,113 @@ async fn test_happy_case_nested_struct_function_cairo_expression_input() -> anyh
435435 Ok ( ( ) )
436436}
437437
438+ #[ tokio:: test]
439+ async fn test_happy_case_span_function_cairo_expression_input ( ) -> anyhow:: Result < ( ) > {
440+ let contract_class = CLASS . get_or_init ( init_class) . await . to_owned ( ) ;
441+
442+ let input = String :: from ( "array![1, 2, 3].span()" ) ;
443+
444+ let result = Calldata :: new ( input)
445+ . serialized ( contract_class, & get_selector_from_name ( "span_fn" ) . unwrap ( ) ) ?;
446+
447+ let expected_output = [
448+ Felt :: from_hex_unchecked ( "0x3" ) ,
449+ Felt :: from_hex_unchecked ( "0x1" ) ,
450+ Felt :: from_hex_unchecked ( "0x2" ) ,
451+ Felt :: from_hex_unchecked ( "0x3" ) ,
452+ ] ;
453+
454+ assert_eq ! ( result, expected_output) ;
455+
456+ Ok ( ( ) )
457+ }
458+
459+ #[ tokio:: test]
460+ async fn test_happy_case_empty_span_function_cairo_expression_input ( ) -> anyhow:: Result < ( ) > {
461+ let contract_class = CLASS . get_or_init ( init_class) . await . to_owned ( ) ;
462+
463+ let input = String :: from ( "array![].span()" ) ;
464+
465+ let result = Calldata :: new ( input)
466+ . serialized ( contract_class, & get_selector_from_name ( "span_fn" ) . unwrap ( ) ) ?;
467+
468+ let expected_output = [ Felt :: from_hex_unchecked ( "0x0" ) ] ;
469+
470+ assert_eq ! ( result, expected_output) ;
471+
472+ Ok ( ( ) )
473+ }
474+
475+ #[ tokio:: test]
476+ async fn test_span_function_array_input ( ) {
477+ let contract_class = CLASS . get_or_init ( init_class) . await . to_owned ( ) ;
478+
479+ let input = String :: from ( "array![1, 2, 3]" ) ;
480+
481+ let result = Calldata :: new ( input)
482+ . serialized ( contract_class, & get_selector_from_name ( "span_fn" ) . unwrap ( ) ) ;
483+
484+ result
485+ . unwrap_err ( )
486+ . assert_contains ( r#"Expected "core::array::Span::<core::felt252>", got array"# ) ;
487+ }
488+
489+ #[ tokio:: test]
490+ async fn test_span_function_unsupported_method ( ) {
491+ let contract_class = CLASS . get_or_init ( init_class) . await . to_owned ( ) ;
492+
493+ let input = String :: from ( "array![1, 2, 3].into()" ) ;
494+
495+ let result = Calldata :: new ( input)
496+ . serialized ( contract_class, & get_selector_from_name ( "span_fn" ) . unwrap ( ) ) ;
497+
498+ result
499+ . unwrap_err ( )
500+ . assert_contains ( r#"Invalid function name, expected "span", got "into""# ) ;
501+ }
502+
503+ #[ tokio:: test]
504+ async fn test_span_function_unsupported_operator ( ) {
505+ let contract_class = CLASS . get_or_init ( init_class) . await . to_owned ( ) ;
506+
507+ let input = String :: from ( "array![1, 2, 3]*span()" ) ;
508+
509+ let result = Calldata :: new ( input)
510+ . serialized ( contract_class, & get_selector_from_name ( "span_fn" ) . unwrap ( ) ) ;
511+
512+ result
513+ . unwrap_err ( )
514+ . assert_contains ( r#"Invalid operator, expected ".", got "*""# ) ;
515+ }
516+
517+ #[ tokio:: test]
518+ async fn test_span_function_unsupported_right_hand_side ( ) {
519+ let contract_class = CLASS . get_or_init ( init_class) . await . to_owned ( ) ;
520+
521+ let input = String :: from ( "array![1, 2, 3].span" ) ;
522+
523+ let result = Calldata :: new ( input)
524+ . serialized ( contract_class, & get_selector_from_name ( "span_fn" ) . unwrap ( ) ) ;
525+
526+ result
527+ . unwrap_err ( )
528+ . assert_contains ( r#"Only calling ".span()" on "array![]" is supported, got "span""# ) ;
529+ }
530+
531+ #[ tokio:: test]
532+ async fn test_span_function_unsupported_left_hand_side ( ) {
533+ let contract_class = CLASS . get_or_init ( init_class) . await . to_owned ( ) ;
534+
535+ let input = String :: from ( "(1, 2, 3).span" ) ;
536+
537+ let result = Calldata :: new ( input)
538+ . serialized ( contract_class, & get_selector_from_name ( "span_fn" ) . unwrap ( ) ) ;
539+
540+ result. unwrap_err ( ) . assert_contains (
541+ r#"Only "array![]" is supported as left-hand side of "." operator, got "(1, 2, 3)""# ,
542+ ) ;
543+ }
544+
438545#[ tokio:: test]
439546async fn test_happy_case_enum_function_empty_variant_cairo_expression_input ( ) -> anyhow:: Result < ( ) >
440547{
@@ -451,6 +558,7 @@ async fn test_happy_case_enum_function_empty_variant_cairo_expression_input() ->
451558
452559 Ok ( ( ) )
453560}
561+
454562#[ tokio:: test]
455563async fn test_happy_case_enum_function_one_argument_variant_cairo_expression_input ( )
456564-> anyhow:: Result < ( ) > {
0 commit comments