ligo/test/integration_tests.ml

711 lines
26 KiB
OCaml
Raw Normal View History

2019-05-13 00:56:22 +04:00
open Trace
open Ligo.Run
2019-05-13 00:56:22 +04:00
open Test_helpers
open Ast_simplified.Combinators
2019-09-10 17:19:15 +04:00
let mtype_file ?debug_simplify ?debug_typed = type_file ?debug_simplify ?debug_typed Cameligo
let type_file = type_file Pascaligo
2019-05-13 00:56:22 +04:00
2019-06-01 02:03:06 +04:00
let type_alias () : unit result =
let%bind program = type_file "./contracts/type-alias.ligo" in
expect_eq_evaluate program "foo" (e_int 23)
2019-05-13 00:56:22 +04:00
let function_ () : unit result =
let%bind program = type_file "./contracts/function.ligo" in
let make_expect = fun n -> n in
expect_eq_n_int program "main" make_expect
2019-05-20 20:17:26 +04:00
let assign () : unit result =
let%bind program = type_file "./contracts/assign.ligo" in
let make_expect = fun n -> n + 1 in
expect_eq_n_int program "main" make_expect
2019-05-13 00:56:22 +04:00
let annotation () : unit result =
let%bind program = type_file "./contracts/annotation.ligo" in
let%bind () =
expect_eq_evaluate program "lst" (e_list [])
2019-05-13 00:56:22 +04:00
in
let%bind () =
expect_eq_evaluate program "address" (e_address "tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx")
2019-05-13 00:56:22 +04:00
in
let%bind () =
expect_eq_evaluate program "address_2" (e_address "tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx")
2019-05-13 00:56:22 +04:00
in
ok ()
let complex_function () : unit result =
let%bind program = type_file "./contracts/function-complex.ligo" in
let make_expect = fun n -> (3 * n + 2) in
expect_eq_n_int program "main" make_expect
let variant () : unit result =
let%bind program = type_file "./contracts/variant.ligo" in
let%bind () =
let expected = e_constructor "Foo" (e_int 42) in
2019-05-13 00:56:22 +04:00
expect_eq_evaluate program "foo" expected in
let%bind () =
let expected = e_constructor "Bar" (e_bool true) in
2019-05-13 00:56:22 +04:00
expect_eq_evaluate program "bar" expected in
let%bind () =
let expected = e_constructor "Kee" (e_nat 23) in
2019-05-13 00:56:22 +04:00
expect_eq_evaluate program "kee" expected in
ok ()
let variant_matching () : unit result =
let%bind program = type_file "./contracts/variant-matching.ligo" in
let%bind () =
let make_input = fun n -> e_constructor "Foo" (e_int n) in
let make_expected = e_int in
2019-05-13 00:56:22 +04:00
expect_eq program "fb" (make_input 0) (make_expected 0) >>? fun () ->
expect_eq_n program "fb" make_input make_expected >>? fun () ->
expect_eq program "fb" (e_constructor "Kee" (e_nat 50)) (e_int 23) >>? fun () ->
expect_eq program "fb" (e_constructor "Bar" (e_bool true)) (e_int 42) >>? fun () ->
2019-05-13 00:56:22 +04:00
ok ()
in
ok ()
let closure () : unit result =
let%bind program = type_file "./contracts/closure.ligo" in
2019-08-21 12:28:27 +04:00
let%bind program_1 = type_file "./contracts/closure-1.ligo" in
let%bind program_2 = type_file "./contracts/closure-2.ligo" in
2019-08-21 18:34:34 +04:00
let%bind program_3 = type_file "./contracts/closure-3.ligo" in
let%bind _ =
let make_expect = fun n -> (49 + n) in
expect_eq_n_int program_3 "foobar" make_expect
in
2019-08-21 12:28:27 +04:00
let%bind _ =
let make_expect = fun n -> (45 + n) in
expect_eq_n_int program_2 "foobar" make_expect
in
2019-05-13 00:56:22 +04:00
let%bind () =
let make_expect = fun n -> (2 * n) in
2019-08-21 12:28:27 +04:00
expect_eq_n_int program_1 "foo" make_expect
2019-05-13 00:56:22 +04:00
in
let%bind _ =
let make_expect = fun n -> (4 * n) in
expect_eq_n_int program "toto" make_expect
in
ok ()
let shadow () : unit result =
let%bind program = type_file "./contracts/shadow.ligo" in
let make_expect = fun _ -> 0 in
expect_eq_n_int program "foo" make_expect
let higher_order () : unit result =
let%bind program = type_file "./contracts/high-order.ligo" in
let make_expect = fun n -> n in
expect_eq_n_int program "foobar" make_expect
let shared_function () : unit result =
let%bind program = type_file "./contracts/function-shared.ligo" in
let%bind () =
let make_expect = fun n -> (n + 1) in
expect_eq_n_int program "inc" make_expect
in
let%bind () =
let make_expect = fun n -> (n + 2) in
expect_eq_n_int program "double_inc" make_expect
in
let%bind () =
let make_expect = fun n -> (2 * n + 3) in
expect_eq program "foo" (e_int 0) (e_int @@ make_expect 0)
2019-05-13 00:56:22 +04:00
in
let%bind () =
let make_expect = fun n -> (2 * n + 3) in
expect_eq_n_int program "foo" make_expect
in
ok ()
let bool_expression () : unit result =
let%bind program = type_file "./contracts/boolean_operators.ligo" in
let%bind _ =
let aux (name , f) = expect_eq_b_bool program name f in
bind_map_list aux [
("or_true", fun b -> b || true) ;
("or_false", fun b -> b || false) ;
("and_true", fun b -> b && true) ;
("and_false", fun b -> b && false) ;
] in
ok ()
let arithmetic () : unit result =
let%bind program = type_file "./contracts/arithmetic.ligo" in
let%bind _ =
let aux (name , f) = expect_eq_n_int program name f in
bind_map_list aux [
("plus_op", fun n -> (n + 42)) ;
("minus_op", fun n -> (n - 42)) ;
("times_op", fun n -> (n * 42)) ;
("neg_op", fun n -> (-n)) ;
2019-05-13 00:56:22 +04:00
] in
let%bind () = expect_eq_n_pos program "int_op" e_nat e_int in
let%bind () = expect_eq_n_pos program "mod_op" e_int (fun n -> e_nat (n mod 42)) in
let%bind () = expect_eq_n_pos program "div_op" e_int (fun n -> e_int (n / 2)) in
2019-05-13 00:56:22 +04:00
ok ()
let bitwise_arithmetic () : unit result =
let%bind program = type_file "./contracts/bitwise_arithmetic.ligo" in
let%bind () = expect_eq program "or_op" (e_nat 7) (e_nat 7) in
let%bind () = expect_eq program "or_op" (e_nat 3) (e_nat 7) in
let%bind () = expect_eq program "or_op" (e_nat 2) (e_nat 6) in
let%bind () = expect_eq program "or_op" (e_nat 14) (e_nat 14) in
let%bind () = expect_eq program "or_op" (e_nat 10) (e_nat 14) in
let%bind () = expect_eq program "and_op" (e_nat 7) (e_nat 7) in
let%bind () = expect_eq program "and_op" (e_nat 3) (e_nat 3) in
let%bind () = expect_eq program "and_op" (e_nat 2) (e_nat 2) in
let%bind () = expect_eq program "and_op" (e_nat 14) (e_nat 6) in
let%bind () = expect_eq program "and_op" (e_nat 10) (e_nat 2) in
let%bind () = expect_eq program "xor_op" (e_nat 0) (e_nat 7) in
let%bind () = expect_eq program "xor_op" (e_nat 7) (e_nat 0) in
ok ()
let string_arithmetic () : unit result =
let%bind program = type_file "./contracts/string_arithmetic.ligo" in
let%bind () = expect_eq program "concat_op" (e_string "foo") (e_string "foototo") in
let%bind () = expect_eq program "concat_op" (e_string "") (e_string "toto") in
let%bind () = expect_eq program "slice_op" (e_string "tata") (e_string "at") in
let%bind () = expect_eq program "slice_op" (e_string "foo") (e_string "oo") in
let%bind () = expect_fail program "slice_op" (e_string "ba") in
ok ()
2019-09-07 20:42:59 +04:00
let bytes_arithmetic () : unit result =
let%bind program = type_file "./contracts/bytes_arithmetic.ligo" in
let%bind foo = e_bytes "0f00" in
let%bind foototo = e_bytes "0f007070" in
let%bind toto = e_bytes "7070" in
let%bind empty = e_bytes "" in
let%bind tata = e_bytes "7a7a7a7a" in
let%bind at = e_bytes "7a7a" in
let%bind ba = e_bytes "ba" in
let%bind () = expect_eq program "concat_op" foo foototo in
let%bind () = expect_eq program "concat_op" empty toto in
let%bind () = expect_eq program "slice_op" tata at in
let%bind () = expect_fail program "slice_op" foo in
let%bind () = expect_fail program "slice_op" ba in
let%bind b1 = run_simplityped program "hasherman" foo in
let%bind () = expect_eq program "hasherman" foo b1 in
let%bind b3 = run_simplityped program "hasherman" foototo in
let%bind () = Assert.assert_fail @@ Ast_simplified.Misc.assert_value_eq (b3 , b1) in
ok ()
2019-07-19 16:35:47 +04:00
let set_arithmetic () : unit result =
let%bind program = type_file "./contracts/set_arithmetic.ligo" in
2019-08-21 13:41:57 +04:00
let%bind program_1 = type_file "./contracts/set_arithmetic-1.ligo" in
let%bind () =
expect_eq program_1 "iter_op"
(e_set [e_int 2 ; e_int 4 ; e_int 7])
(e_int 13) in
2019-07-19 16:35:47 +04:00
let%bind () =
expect_eq program "add_op"
(e_set [e_string "foo" ; e_string "bar"])
(e_set [e_string "foo" ; e_string "bar" ; e_string "foobar"]) in
let%bind () =
expect_eq program "add_op"
(e_set [e_string "foo" ; e_string "bar" ; e_string "foobar"])
(e_set [e_string "foo" ; e_string "bar" ; e_string "foobar"]) in
let%bind () =
expect_eq program "remove_op"
(e_set [e_string "foo" ; e_string "bar"])
(e_set [e_string "foo" ; e_string "bar"]) in
let%bind () =
expect_eq program "remove_op"
(e_set [e_string "foo" ; e_string "bar" ; e_string "foobar"])
(e_set [e_string "foo" ; e_string "bar"]) in
let%bind () =
expect_eq program "mem_op"
(e_set [e_string "foo" ; e_string "bar" ; e_string "foobar"])
(e_bool true) in
let%bind () =
expect_eq program "mem_op"
(e_set [e_string "foo" ; e_string "bar"])
(e_bool false) in
ok ()
2019-05-13 00:56:22 +04:00
let unit_expression () : unit result =
let%bind program = type_file "./contracts/unit.ligo" in
expect_eq_evaluate program "u" (e_unit ())
2019-05-13 00:56:22 +04:00
let string_expression () : unit result =
let%bind program = type_file "./contracts/string.ligo" in
expect_eq_evaluate program "s" (e_string "toto")
2019-05-13 00:56:22 +04:00
let include_ () : unit result =
let%bind program = type_file "./contracts/includer.ligo" in
expect_eq_evaluate program "bar" (e_int 144)
2019-05-13 00:56:22 +04:00
let record_ez_int names n =
ez_e_record @@ List.map (fun x -> x, e_int n) names
2019-05-13 00:56:22 +04:00
let tuple_ez_int names n =
e_tuple @@ List.map (fun _ -> e_int n) names
2019-05-13 00:56:22 +04:00
let multiple_parameters () : unit result =
let%bind program = type_file "./contracts/multiple-parameters.ligo" in
let aux ((name : string) , make_input , make_output) =
let make_output' = fun n -> e_int @@ make_output n in
2019-05-13 00:56:22 +04:00
expect_eq_n program name make_input make_output'
in
let%bind _ = bind_list @@ List.map aux [
("ab", tuple_ez_int ["a";"b"], fun n -> 2 * n) ;
("abcd", tuple_ez_int ["a";"b";"c";"d"], fun n -> 4 * n + 2) ;
("abcde", tuple_ez_int ["a";"b";"c";"d";"e"], fun n -> 2 * n + 3) ;
2019-05-13 00:56:22 +04:00
] in
ok ()
let record () : unit result =
let%bind program = type_file "./contracts/record.ligo" in
let%bind () =
let expected = record_ez_int ["foo" ; "bar"] 0 in
expect_eq_evaluate program "fb" expected
in
let%bind () =
let%bind () = expect_eq_evaluate program "a" (e_int 42) in
let%bind () = expect_eq_evaluate program "b" (e_int 142) in
let%bind () = expect_eq_evaluate program "c" (e_int 242) in
2019-05-13 00:56:22 +04:00
ok ()
in
let%bind () =
let make_input = record_ez_int ["foo" ; "bar"] in
let make_expected = fun n -> e_int (2 * n) in
2019-05-13 00:56:22 +04:00
expect_eq_n program "projection" make_input make_expected
in
let%bind () =
let make_input = record_ez_int ["foo" ; "bar"] in
let make_expected = fun n -> ez_e_record [("foo" , e_int 256) ; ("bar" , e_int n) ] in
2019-05-13 00:56:22 +04:00
expect_eq_n program "modify" make_input make_expected
in
let%bind () =
let make_input = record_ez_int ["a" ; "b" ; "c"] in
let make_expected = fun n -> ez_e_record [
("a" , e_int n) ;
("b" , e_int 2048) ;
("c" , e_int n)
2019-05-13 00:56:22 +04:00
] in
expect_eq_n program "modify_abc" make_input make_expected
in
let%bind () =
let expected = record_ez_int ["a";"b";"c";"d";"e"] 23 in
expect_eq_evaluate program "br" expected
in
ok ()
let tuple () : unit result =
let%bind program = type_file "./contracts/tuple.ligo" in
let ez n =
e_tuple (List.map e_int n) in
2019-05-13 00:56:22 +04:00
let%bind () =
let expected = ez [0 ; 0] in
expect_eq_evaluate program "fb" expected
in
let%bind () =
let make_input = fun n -> ez [n ; n] in
let make_expected = fun n -> e_int (2 * n) in
2019-05-13 00:56:22 +04:00
expect_eq_n program "projection" make_input make_expected
in
let%bind () =
let make_input = fun n -> ez [n ; 2 * n ; n] in
let make_expected = fun n -> e_int (2 * n) in
2019-05-13 00:56:22 +04:00
expect_eq_n program "projection_abc" make_input make_expected
in
let%bind () =
let make_input = fun n -> ez [n ; n ; n] in
let make_expected = fun n -> ez [n ; 2048 ; n] in
expect_eq program "modify_abc" (make_input 12) (make_expected 12)
in
let%bind () =
let make_input = fun n -> ez [n ; n ; n] in
let make_expected = fun n -> ez [n ; 2048 ; n] in
expect_eq_n program "modify_abc" make_input make_expected
in
let%bind () =
let expected = ez [23 ; 23 ; 23 ; 23 ; 23] in
expect_eq_evaluate program "br" expected
in
ok ()
let option () : unit result =
let%bind program = type_file "./contracts/option.ligo" in
let%bind () =
let expected = e_some (e_int 42) in
2019-05-13 00:56:22 +04:00
expect_eq_evaluate program "s" expected
in
let%bind () =
let expected = e_typed_none t_int in
2019-05-13 00:56:22 +04:00
expect_eq_evaluate program "n" expected
in
ok ()
let map () : unit result =
let%bind program = type_file "./contracts/map.ligo" in
let ez lst =
let open Ast_simplified.Combinators in
let lst' = List.map (fun (x, y) -> e_int x, e_int y) lst in
e_typed_map lst' t_int t_int
2019-05-13 00:56:22 +04:00
in
let%bind () =
let make_input = fun n -> ez [(23, n) ; (42, 4)] in
let make_expected = e_int in
2019-05-13 00:56:22 +04:00
expect_eq_n program "gf" make_input make_expected
in
let%bind () =
let make_input = fun n -> ez List.(map (fun x -> (x, x)) @@ range n) in
let make_expected = e_nat in
2019-05-13 00:56:22 +04:00
expect_eq_n_strict_pos_small program "size_" make_input make_expected
in
let%bind () =
let expected = ez [(23, 0) ; (42, 0)] in
expect_eq_evaluate program "fb" expected
in
let%bind () =
let make_input = fun n ->
let m = ez [(23 , 0) ; (42 , 0)] in
e_tuple [(e_int n) ; m]
2019-05-13 00:56:22 +04:00
in
let make_expected = fun n -> ez [(23 , n) ; (42 , 0)] in
expect_eq_n_pos_small program "set_" make_input make_expected
in
let%bind () =
let make_input = fun n -> ez [(23, n) ; (42, 4)] in
let make_expected = fun _ -> e_some @@ e_int 4 in
2019-05-13 00:56:22 +04:00
expect_eq_n program "get" make_input make_expected
in
let%bind () =
let expected = ez @@ List.map (fun x -> (x, 23)) [144 ; 51 ; 42 ; 120 ; 421] in
expect_eq_evaluate program "bm" expected
in
let%bind () =
let input = ez [(23, 23) ; (42, 42)] in
let expected = ez [23, 23] in
expect_eq program "rm" input expected
in
2019-07-20 18:42:34 +04:00
let%bind () =
let input = ez [(1 , 10) ; (2 , 20) ; (3 , 30) ] in
let expected = e_int 66 in
expect_eq program "iter_op" input expected
in
let%bind () =
let input = ez [(1 , 10) ; (2 , 20) ; (3 , 30) ] in
let expected = ez [(1 , 11) ; (2 , 21) ; (3 , 31) ] in
expect_eq program "map_op" input expected
in
2019-05-13 00:56:22 +04:00
ok ()
let list () : unit result =
let%bind program = type_file "./contracts/list.ligo" in
let ez lst =
let lst' = List.map e_int lst in
e_typed_list lst' t_int
2019-05-13 00:56:22 +04:00
in
let%bind () =
let expected = ez [23 ; 42] in
expect_eq_evaluate program "fb" expected
in
2019-05-13 00:56:22 +04:00
let%bind () =
let make_input = fun n -> (ez @@ List.range n) in
let make_expected = e_nat in
2019-05-13 00:56:22 +04:00
expect_eq_n_strict_pos_small program "size_" make_input make_expected
in
let%bind () =
let expected = ez [144 ; 51 ; 42 ; 120 ; 421] in
expect_eq_evaluate program "bl" expected
in
2019-07-20 15:46:42 +04:00
let%bind () =
expect_eq program "iter_op"
(e_list [e_int 2 ; e_int 4 ; e_int 7])
(e_int 13)
in
let%bind () =
expect_eq program "map_op"
(e_list [e_int 2 ; e_int 4 ; e_int 7])
(e_list [e_int 3 ; e_int 5 ; e_int 8])
in
2019-05-13 00:56:22 +04:00
ok ()
let condition () : unit result =
let%bind program = type_file "./contracts/condition.ligo" in
let make_input = e_int in
let make_expected = fun n -> e_int (if n = 2 then 42 else 0) in
2019-05-13 00:56:22 +04:00
expect_eq_n program "main" make_input make_expected
2019-05-20 20:17:26 +04:00
let condition_simple () : unit result =
let%bind program = type_file "./contracts/condition-simple.ligo" in
let make_input = e_int in
let make_expected = fun _ -> e_int 42 in
2019-05-20 20:17:26 +04:00
expect_eq_n program "main" make_input make_expected
2019-05-13 00:56:22 +04:00
let loop () : unit result =
let%bind program = type_file "./contracts/loop.ligo" in
let%bind () =
let make_input = e_nat in
let make_expected = e_nat in
2019-05-13 00:56:22 +04:00
expect_eq_n_pos program "dummy" make_input make_expected
in
let%bind () =
let make_input = e_nat in
let make_expected = e_nat in
2019-05-13 00:56:22 +04:00
expect_eq_n_pos_mid program "counter" make_input make_expected
in
let%bind () =
let make_input = e_nat in
let make_expected = fun n -> e_nat (n * (n + 1) / 2) in
2019-05-13 00:56:22 +04:00
expect_eq_n_pos_mid program "sum" make_input make_expected
in
2019-07-19 16:35:47 +04:00
ok ()
2019-05-13 00:56:22 +04:00
let matching () : unit result =
let%bind program = type_file "./contracts/match.ligo" in
let%bind () =
let make_input = e_int in
let make_expected = fun n -> e_int (if n = 2 then 42 else 0) in
2019-05-13 00:56:22 +04:00
expect_eq_n program "match_bool" make_input make_expected
in
let%bind () =
let make_input = e_int in
let make_expected = fun n-> e_int (if n = 2 then 42 else 0) in
2019-05-13 00:56:22 +04:00
expect_eq_n program "match_expr_bool" make_input make_expected
in
let%bind () =
let aux n =
let input = match n with
| Some s -> e_some (e_int s)
| None -> e_typed_none t_int in
let expected = e_int (match n with
2019-05-13 00:56:22 +04:00
| Some s -> s
| None -> 23) in
trace (simple_error (Format.asprintf "on input %a" PP_helpers.(option int) n)) @@
expect_eq program "match_option" input expected
in
bind_iter_list aux
[Some 0 ; Some 2 ; Some 42 ; Some 163 ; Some (-1) ; None]
in
let%bind () =
let aux n =
let input = match n with
| Some s -> e_some (e_int s)
| None -> e_typed_none t_int in
let expected = e_int (match n with
2019-05-13 00:56:22 +04:00
| Some s -> s
| None -> 42) in
trace (simple_error (Format.asprintf "on input %a" PP_helpers.(option int) n)) @@
expect_eq program "match_expr_option" input expected
in
bind_iter_list aux
[Some 0 ; Some 2 ; Some 42 ; Some 163 ; Some (-1) ; None]
in
ok ()
let declarations () : unit result =
let%bind program = type_file "./contracts/declarations.ligo" in
let make_input = e_int in
let make_expected = fun n -> e_int (42 + n) in
expect_eq program "main" (make_input 0) (make_expected 0) >>? fun () ->
2019-05-13 00:56:22 +04:00
expect_eq_n program "main" make_input make_expected
2019-05-20 20:17:26 +04:00
let declaration_local () : unit result =
let%bind program = type_file "./contracts/declaration-local.ligo" in
let make_input = e_int in
let make_expected = fun _ -> e_int 42 in
2019-05-20 20:17:26 +04:00
expect_eq_n program "main" make_input make_expected
2019-05-13 00:56:22 +04:00
let quote_declaration () : unit result =
let%bind program = type_file "./contracts/quote-declaration.ligo" in
let make_input = e_int in
let make_expected = fun n -> e_int (42 + 2 * n) in
2019-05-13 00:56:22 +04:00
expect_eq_n program "main" make_input make_expected
let quote_declarations () : unit result =
let%bind program = type_file "./contracts/quote-declarations.ligo" in
let make_input = e_int in
let make_expected = fun n -> e_int (74 + 2 * n) in
2019-05-13 00:56:22 +04:00
expect_eq_n program "main" make_input make_expected
let counter_contract () : unit result =
let%bind program = type_file "./contracts/counter.ligo" in
let make_input = fun n-> e_pair (e_int n) (e_int 42) in
let make_expected = fun n -> e_pair (e_typed_list [] t_operation) (e_int (42 + n)) in
2019-05-13 00:56:22 +04:00
expect_eq_n program "main" make_input make_expected
let super_counter_contract () : unit result =
let%bind program = type_file "./contracts/super-counter.ligo" in
let make_input = fun n ->
let action = if n mod 2 = 0 then "Increment" else "Decrement" in
e_pair (e_constructor action (e_int n)) (e_int 42) in
2019-05-13 00:56:22 +04:00
let make_expected = fun n ->
let op = if n mod 2 = 0 then (+) else (-) in
e_pair (e_typed_list [] t_operation) (e_int (op 42 n)) in
2019-05-13 00:56:22 +04:00
expect_eq_n program "main" make_input make_expected
2019-06-12 22:41:29 +04:00
let super_counter_contract_mligo () : unit result =
let%bind program = mtype_file "./contracts/super-counter.mligo" in
let make_input = fun n ->
let action = if n mod 2 = 0 then "Increment" else "Decrement" in
e_pair (e_constructor action (e_int n)) (e_int 42) in
let make_expected = fun n ->
let op = if n mod 2 = 0 then (+) else (-) in
e_pair (e_typed_list [] t_operation) (e_int (op 42 n)) in
expect_eq_n program "main" make_input make_expected
2019-05-13 00:56:22 +04:00
let dispatch_counter_contract () : unit result =
let%bind program = type_file "./contracts/dispatch-counter.ligo" in
let make_input = fun n ->
let action = if n mod 2 = 0 then "Increment" else "Decrement" in
e_pair (e_constructor action (e_int n)) (e_int 42) in
2019-05-13 00:56:22 +04:00
let make_expected = fun n ->
let op = if n mod 2 = 0 then (+) else (-) in
e_pair (e_typed_list [] t_operation) (e_int (op 42 n)) in
2019-05-13 00:56:22 +04:00
expect_eq_n program "main" make_input make_expected
2019-06-05 21:19:44 +04:00
let failwith_mligo () : unit result =
let%bind program = mtype_file "./contracts/failwith.mligo" in
let make_input = e_pair (e_unit ()) (e_unit ()) in
let make_expected = e_pair (e_typed_list [] t_operation) (e_unit ()) in
expect_eq program "main" make_input make_expected
2019-05-13 00:56:22 +04:00
let guess_the_hash_mligo () : unit result =
let%bind program = mtype_file "./contracts/new-syntax.mligo" in
let make_input = fun n-> e_pair (e_int n) (e_int 42) in
let make_expected = fun n -> e_pair (e_typed_list [] t_operation) (e_int (42 + n)) in
2019-05-13 00:56:22 +04:00
expect_eq_n program "main" make_input make_expected
2019-06-05 21:18:16 +04:00
let guess_string_mligo () : unit result =
let%bind program = mtype_file "./contracts/guess_string.mligo" in
let make_input = fun n -> e_pair (e_int n) (e_int 42) in
let make_expected = fun n -> e_pair (e_typed_list [] t_operation) (e_int (42 + n))
in expect_eq_n program "main" make_input make_expected
let basic_mligo () : unit result =
let%bind typed = mtype_file ~debug_simplify:true "./contracts/basic.mligo" in
let%bind result = evaluate_typed "foo" typed in
Ligo.AST_Typed.assert_value_eq
(Ligo.AST_Typed.Combinators.e_a_empty_int (42 + 127), result)
let counter_mligo () : unit result =
let%bind program = mtype_file "./contracts/counter.mligo" in
let make_input n = e_pair (e_int n) (e_int 42) in
let make_expected n = e_pair (e_typed_list [] t_operation) (e_int (42 + n)) in
2019-06-05 21:18:16 +04:00
expect_eq_n program "main" make_input make_expected
let let_in_mligo () : unit result =
let%bind program = mtype_file "./contracts/letin.mligo" in
let make_input n = e_pair (e_int n) (e_pair (e_int 3) (e_int 5)) in
let make_expected n =
e_pair (e_typed_list [] t_operation) (e_pair (e_int (7+n)) (e_int (3+5)))
in expect_eq_n program "main" make_input make_expected
let match_variant () : unit result =
let%bind program = mtype_file "./contracts/match.mligo" in
let make_input n =
e_pair (e_constructor "Sub" (e_int n)) (e_int 3) in
let make_expected n =
e_pair (e_typed_list [] t_operation) (e_int (3-n))
in expect_eq_n program "main" make_input make_expected
2019-06-07 14:48:21 +04:00
let match_matej () : unit result =
let%bind program = mtype_file "./contracts/match_bis.mligo" in
let make_input n =
e_pair (e_constructor "Decrement" (e_int n)) (e_int 3) in
let make_expected n =
e_pair (e_typed_list [] t_operation) (e_int (3-n))
in expect_eq_n program "main" make_input make_expected
let mligo_list () : unit result =
let%bind program = mtype_file "./contracts/list.mligo" in
let make_input n =
e_pair (e_list [e_int n; e_int (2*n)])
(e_pair (e_int 3) (e_list [e_int 8])) in
let make_expected n =
e_pair (e_typed_list [] t_operation)
(e_pair (e_int (n+3)) (e_list [e_int (2*n)]))
in expect_eq_n program "main" make_input make_expected
2019-06-06 22:48:36 +04:00
let lambda_mligo () : unit result =
let%bind program = mtype_file "./contracts/lambda.mligo" in
let make_input = e_pair (e_unit ()) (e_unit ()) in
let make_expected = (e_unit ()) in
expect_eq program "main" make_input make_expected
let lambda_ligo () : unit result =
let%bind program = type_file "./contracts/lambda.ligo" in
let make_input = e_pair (e_unit ()) (e_unit ()) in
let make_expected = (e_unit ()) in
expect_eq program "main" make_input make_expected
2019-06-06 22:48:36 +04:00
let lambda2_mligo () : unit result =
let%bind program = mtype_file "./contracts/lambda2.mligo" in
let make_input = e_pair (e_unit ()) (e_unit ()) in
let make_expected = (e_unit ()) in
expect_eq program "main" make_input make_expected
let website1_ligo () : unit result =
let%bind program = type_file "./contracts/website1.ligo" in
let make_input = fun n-> e_pair (e_int n) (e_int 42) in
let make_expected = fun _n -> e_pair (e_typed_list [] t_operation) (e_int (42 + 1)) in
expect_eq_n program "main" make_input make_expected
let website2_ligo () : unit result =
let%bind program = type_file "./contracts/website2.ligo" in
let make_input = fun n ->
let action = if n mod 2 = 0 then "Increment" else "Decrement" in
e_pair (e_constructor action (e_int n)) (e_int 42) in
let make_expected = fun n ->
let op = if n mod 2 = 0 then (+) else (-) in
e_pair (e_typed_list [] t_operation) (e_int (op 42 n)) in
expect_eq_n program "main" make_input make_expected
2019-06-05 10:43:33 +04:00
let main = test_suite "Integration (End to End)" [
2019-06-01 02:03:06 +04:00
test "type alias" type_alias ;
2019-05-13 00:56:22 +04:00
test "function" function_ ;
2019-05-20 20:17:26 +04:00
test "assign" assign ;
test "declaration local" declaration_local ;
2019-05-13 00:56:22 +04:00
test "complex function" complex_function ;
2019-08-21 12:28:27 +04:00
test "closure" closure ;
test "shared function" shared_function ;
test "higher order" higher_order ;
2019-05-13 00:56:22 +04:00
test "variant" variant ;
test "variant matching" variant_matching ;
test "tuple" tuple ;
test "record" record ;
2019-05-20 20:17:26 +04:00
test "condition simple" condition_simple ;
2019-05-13 00:56:22 +04:00
test "condition" condition ;
test "shadow" shadow ;
test "annotation" annotation ;
test "multiple parameters" multiple_parameters ;
test "bool" bool_expression ;
test "arithmetic" arithmetic ;
test "bitiwse_arithmetic" bitwise_arithmetic ;
test "string_arithmetic" string_arithmetic ;
2019-09-07 20:42:59 +04:00
test "bytes_arithmetic" bytes_arithmetic ;
2019-08-21 12:28:27 +04:00
test "set_arithmetic" set_arithmetic ;
2019-05-13 00:56:22 +04:00
test "unit" unit_expression ;
test "string" string_expression ;
test "option" option ;
2019-08-21 12:28:27 +04:00
test "map" map ;
test "list" list ;
2019-05-13 00:56:22 +04:00
test "loop" loop ;
test "matching" matching ;
test "declarations" declarations ;
test "quote declaration" quote_declaration ;
test "quote declarations" quote_declarations ;
test "#include directives" include_ ;
test "counter contract" counter_contract ;
test "super counter contract" super_counter_contract ;
2019-06-12 22:41:29 +04:00
test "super counter contract" super_counter_contract_mligo ;
2019-05-13 00:56:22 +04:00
test "dispatch counter contract" dispatch_counter_contract ;
test "basic (mligo)" basic_mligo ;
test "counter contract (mligo)" counter_mligo ;
test "let-in (mligo)" let_in_mligo ;
test "match variant (mligo)" match_variant ;
2019-06-07 14:48:21 +04:00
test "match variant 2 (mligo)" match_matej ;
(* test "list matching (mligo)" mligo_list ; *)
2019-06-06 22:48:36 +04:00
(* test "guess the hash mligo" guess_the_hash_mligo ; WIP? *)
2019-06-05 21:19:44 +04:00
(* test "failwith mligo" failwith_mligo ; *)
2019-06-06 22:48:36 +04:00
(* test "guess string mligo" guess_string_mligo ; WIP? *)
test "lambda mligo" lambda_mligo ;
test "lambda ligo" lambda_ligo ;
2019-06-06 22:48:36 +04:00
(* test "lambda2 mligo" lambda2_mligo ; *)
test "website1 ligo" website1_ligo ;
test "website2 ligo" website2_ligo ;
2019-05-13 00:56:22 +04:00
]