From 2566ebc7d0248ed7e0c3e08a4e669d38cd384c47 Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Wed, 23 Oct 2019 17:53:26 -0700 Subject: [PATCH 01/13] Add arithmetic tests for CameLIGO --- src/test/contracts/arithmetic.mligo | 30 +++++++++++++++++++++++++++++ src/test/integration_tests.ml | 14 ++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/test/contracts/arithmetic.mligo diff --git a/src/test/contracts/arithmetic.mligo b/src/test/contracts/arithmetic.mligo new file mode 100644 index 000000000..e4d65c19c --- /dev/null +++ b/src/test/contracts/arithmetic.mligo @@ -0,0 +1,30 @@ +// Test CameLIGO arithmetic operators + +let mod_op (n : int) : nat = + n mod 42 + +let plus_op (n : int) : int = + n + 42 + +let minus_op (n : int) : int = + n - 42 + +let times_op (n : int) : int = + n * 42 + +let div_op (n : int) : int = + n / 2 + +(* TODO (?): Support conversion from nat to int and back + +let int_op (n : nat) : int = + Int n + +*) + +(* TODO: Support negative operator + +let neg_op (n : int) : int = + -n + +*) diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index a5be3029b..3160ebf91 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -178,6 +178,19 @@ let arithmetic () : unit result = let%bind () = expect_eq_n_pos program "div_op" e_int (fun n -> e_int (n / 2)) in ok () +let arithmetic_mligo () : unit result = + let%bind program = mtype_file "./contracts/arithmetic.mligo" 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)) ; + ] 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 + 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 @@ -929,6 +942,7 @@ let main = test_suite "Integration (End to End)" [ test "multiple parameters" multiple_parameters ; test "bool" bool_expression ; test "arithmetic" arithmetic ; + test "arithmetic (mligo)" arithmetic_mligo ; test "bitiwse_arithmetic" bitwise_arithmetic ; test "string_arithmetic" string_arithmetic ; test "string_arithmetic (mligo)" string_arithmetic_mligo ; From ddc5b8e36daa873c6cd3387e5912bc22191c6508 Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Wed, 23 Oct 2019 18:29:49 -0700 Subject: [PATCH 02/13] Add failing boolean operator test --- src/test/contracts/boolean_operators.mligo | 16 ++++++++++++++++ src/test/integration_tests.ml | 14 ++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/test/contracts/boolean_operators.mligo diff --git a/src/test/contracts/boolean_operators.mligo b/src/test/contracts/boolean_operators.mligo new file mode 100644 index 000000000..7939ccf47 --- /dev/null +++ b/src/test/contracts/boolean_operators.mligo @@ -0,0 +1,16 @@ +// Test CameLIGO boolean operators + +let or_true (b : bool) : bool = + b or True + +let or_false (b : bool) : bool = + b or False + +let and_true (b : bool) : bool = + b and True + +let and_false (b : bool) : bool = + b and False + +let not_bool (b: bool) : bool = + not b diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 3160ebf91..e294d1e44 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -163,6 +163,19 @@ let bool_expression () : unit result = ] in ok () +let bool_expression_mligo () : unit result = + let%bind program = mtype_file "./contracts/boolean_operators.mligo" 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) ; + ("not_bool", fun b -> not b) ; + ] in + ok () + let arithmetic () : unit result = let%bind program = type_file "./contracts/arithmetic.ligo" in let%bind _ = @@ -941,6 +954,7 @@ let main = test_suite "Integration (End to End)" [ test "annotation" annotation ; test "multiple parameters" multiple_parameters ; test "bool" bool_expression ; + test "bool (mligo)" bool_expression_mligo ; test "arithmetic" arithmetic ; test "arithmetic (mligo)" arithmetic_mligo ; test "bitiwse_arithmetic" bitwise_arithmetic ; From 2aa201553c5b94539b0047488ccae649dfaa1dfe Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Wed, 23 Oct 2019 20:29:32 -0700 Subject: [PATCH 03/13] Add test for the if conditional in CameLIGO --- src/test/contracts/condition.mligo | 9 +++++++++ src/test/integration_tests.ml | 14 ++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 src/test/contracts/condition.mligo diff --git a/src/test/contracts/condition.mligo b/src/test/contracts/condition.mligo new file mode 100644 index 000000000..4a0a0038f --- /dev/null +++ b/src/test/contracts/condition.mligo @@ -0,0 +1,9 @@ +// Test if conditional in CameLIGO + +let main (i : int) : int = + let result : int = 23 in + if i = 2 then 42 else 0 + +let foo (b : bool) : int = + let x : int = 41 in + let x : int = 1 + (if b then x else main(x)) in x diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 3160ebf91..ecc69e7b4 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -619,6 +619,19 @@ let condition () : unit result = in ok () +let condition_mligo () : unit result = + let%bind program = mtype_file "./contracts/condition.mligo" in + let%bind _ = + let make_input = e_int in + let make_expected = fun n -> e_int (if n = 2 then 42 else 0) in + expect_eq_n program "main" make_input make_expected + in + let%bind _ = + let make_expected = fun b -> e_int (if b then 42 else 1) in + expect_eq_b program "foo" make_expected + in + ok () + let condition_simple () : unit result = let%bind program = type_file "./contracts/condition-simple.ligo" in let make_input = e_int in @@ -937,6 +950,7 @@ let main = test_suite "Integration (End to End)" [ test "record" record ; test "condition simple" condition_simple ; test "condition" condition ; + test "condition (mligo)" condition_mligo ; test "shadow" shadow ; test "annotation" annotation ; test "multiple parameters" multiple_parameters ; From 0bf37a2e21da949a2e6ace095f45dbbc850863a1 Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Thu, 24 Oct 2019 09:13:31 -0700 Subject: [PATCH 04/13] Fix boolean tests for CameLIGO --- src/test/contracts/boolean_operators.mligo | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/contracts/boolean_operators.mligo b/src/test/contracts/boolean_operators.mligo index 7939ccf47..7eb3cfd69 100644 --- a/src/test/contracts/boolean_operators.mligo +++ b/src/test/contracts/boolean_operators.mligo @@ -1,16 +1,16 @@ // Test CameLIGO boolean operators let or_true (b : bool) : bool = - b or True + b || true let or_false (b : bool) : bool = - b or False + b || false let and_true (b : bool) : bool = - b and True + b && true let and_false (b : bool) : bool = - b and False + b && false let not_bool (b: bool) : bool = not b From 99dfd18dea6f94205c416cea24b275035d9b14fd Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Thu, 24 Oct 2019 14:44:07 -0700 Subject: [PATCH 05/13] Add explanatory comment to annotation.ligo --- src/test/contracts/annotation.ligo | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/contracts/annotation.ligo b/src/test/contracts/annotation.ligo index 1eaef7b0c..7f5e969f4 100644 --- a/src/test/contracts/annotation.ligo +++ b/src/test/contracts/annotation.ligo @@ -1,3 +1,5 @@ +(* Test that a string is cast to an address given a type annotation *) + const lst : list(int) = list [] ; const address : address = ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address) ; From 0eb2b73afa3d930177256f39ef359ca558a69d52 Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Thu, 24 Oct 2019 15:27:26 -0700 Subject: [PATCH 06/13] Add CameLIGO test function utilizing multiple subroutines --- src/test/contracts/function-shared.mligo | 7 +++++++ src/test/integration_tests.ml | 9 +++++++++ 2 files changed, 16 insertions(+) create mode 100644 src/test/contracts/function-shared.mligo diff --git a/src/test/contracts/function-shared.mligo b/src/test/contracts/function-shared.mligo new file mode 100644 index 000000000..5fc3e0b29 --- /dev/null +++ b/src/test/contracts/function-shared.mligo @@ -0,0 +1,7 @@ +(* Test use of multiple subroutines in a CameLIGO function *) + +let foo (i: int) : int = i + 20 + +let bar (i: int) : int = i + 50 + +let foobar (i: int) : int = (foo i) + (bar i) diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index cc1ffc134..ba12aed84 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -150,6 +150,14 @@ let shared_function () : unit result = in ok () +let shared_function_mligo () : unit result = + let%bind program = mtype_file "./contracts/function-shared.mligo" in + let%bind () = + let make_expect = fun n -> (2 * n + 70) in + expect_eq_n_int program "foobar" make_expect + in + ok () + let bool_expression () : unit result = let%bind program = type_file "./contracts/boolean_operators.ligo" in let%bind _ = @@ -955,6 +963,7 @@ let main = test_suite "Integration (End to End)" [ test "complex function" complex_function ; test "closure" closure ; test "shared function" shared_function ; + test "shared function (mligo)" shared_function_mligo ; test "higher order" higher_order ; test "variant" variant ; test "variant (mligo)" variant_mligo ; From 8cfa583d556f73f0cd1702028ba82ddc83902b1e Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Fri, 25 Oct 2019 16:33:31 -0700 Subject: [PATCH 07/13] Add more string tests to CameLIGO --- src/test/contracts/string_arithmetic.mligo | 6 ++++++ src/test/integration_tests.ml | 3 +++ 2 files changed, 9 insertions(+) diff --git a/src/test/contracts/string_arithmetic.mligo b/src/test/contracts/string_arithmetic.mligo index 89d77ff60..1e1db9750 100644 --- a/src/test/contracts/string_arithmetic.mligo +++ b/src/test/contracts/string_arithmetic.mligo @@ -1,4 +1,10 @@ (* Test that the string concatenation syntax in CameLIGO works *) +let size_op (s : string) : nat = + String.size s + +let slice_op (s : string) : string = + String.slice 1p 2p s + let concat_syntax (s: string) = s ^ "test_literal" diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index ba12aed84..509b1f0d6 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -239,6 +239,9 @@ let string_arithmetic () : unit result = let string_arithmetic_mligo () : unit result = let%bind program = mtype_file "./contracts/string_arithmetic.mligo" in + let%bind () = expect_eq program "size_op" (e_string "tata") (e_nat 4) 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_eq program "concat_syntax" (e_string "string_") (e_string "string_test_literal") in ok () From f62481fb0a1c86dd47c475f6467272f961f77ade Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Mon, 28 Oct 2019 21:38:29 -0700 Subject: [PATCH 08/13] Add list match test to CameLIGO --- src/test/contracts/match.mligo | 22 ++++++++++++++++++++++ src/test/integration_tests.ml | 20 +++++++++++++++----- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/test/contracts/match.mligo b/src/test/contracts/match.mligo index 1665e9f27..bfe334546 100644 --- a/src/test/contracts/match.mligo +++ b/src/test/contracts/match.mligo @@ -11,3 +11,25 @@ let%entry main (p : param) storage = Add n -> n | Sub n -> 0-n) in (([] : operation list), storage) + +let match_list (l: int list) : int = + match l with + hd :: tl -> hd + | [] -> 10 + +(* TODO: Add support for matching options + +type option_param = + Add of int option +| Sub of int option + +let match_option (p : option_param) storage = + let storage = + storage + + (match p with + Some (Add n) -> n + | Some (Sub n) -> 0 - n + | None -> 0) + in (([] : operation list) , storage) + +*) diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 509b1f0d6..b03b9a51e 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -864,11 +864,21 @@ let let_in_mligo () : unit result = 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 + let%bind () = + 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 in + let%bind () = + let input = e_list [e_int 3] in + let expected = e_int 3 in + expect_eq program "match_list" input expected in + let%bind () = + let input = e_typed_list [] t_int in + let expected = e_int 10 in + expect_eq program "match_list" input expected in + ok () let match_matej () : unit result = let%bind program = mtype_file "./contracts/match_bis.mligo" in From c004fd24cdb6907c03a0e5ec5a13059ea5575f64 Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Mon, 28 Oct 2019 22:01:31 -0700 Subject: [PATCH 09/13] Add option and boolean match tests to CameLIGO --- src/test/contracts/match.mligo | 25 +++++++++---------------- src/test/integration_tests.ml | 12 ++++++++++++ 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/test/contracts/match.mligo b/src/test/contracts/match.mligo index bfe334546..394925538 100644 --- a/src/test/contracts/match.mligo +++ b/src/test/contracts/match.mligo @@ -12,24 +12,17 @@ let%entry main (p : param) storage = | Sub n -> 0-n) in (([] : operation list), storage) +let match_bool (b: bool) : int = + match b with + true -> 10 + | false -> 0 + let match_list (l: int list) : int = match l with hd :: tl -> hd | [] -> 10 -(* TODO: Add support for matching options - -type option_param = - Add of int option -| Sub of int option - -let match_option (p : option_param) storage = - let storage = - storage + - (match p with - Some (Add n) -> n - | Some (Sub n) -> 0 - n - | None -> 0) - in (([] : operation list) , storage) - -*) +let match_option (i : int option) : int = + match i with + Some n -> n + | None -> 0 diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index b03b9a51e..384f726f0 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -870,6 +870,14 @@ let match_variant () : unit result = 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 in + let%bind () = + let input = e_bool true in + let expected = e_int 10 in + expect_eq program "match_bool" input expected in + let%bind () = + let input = e_bool false in + let expected = e_int 0 in + expect_eq program "match_bool" input expected in let%bind () = let input = e_list [e_int 3] in let expected = e_int 3 in @@ -878,6 +886,10 @@ let match_variant () : unit result = let input = e_typed_list [] t_int in let expected = e_int 10 in expect_eq program "match_list" input expected in + let%bind () = + let make_input n = e_some (e_int n) in + let make_expected n = e_int n in + expect_eq_n program "match_option" make_input make_expected in ok () let match_matej () : unit result = From ec3f836605d7bd833292e8d20ba076d1ae72d1dc Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Mon, 28 Oct 2019 22:07:00 -0700 Subject: [PATCH 10/13] Add test for several function parameters in CameLIGO --- src/test/contracts/multiple-parameters.mligo | 4 ++++ src/test/integration_tests.ml | 13 +++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 src/test/contracts/multiple-parameters.mligo diff --git a/src/test/contracts/multiple-parameters.mligo b/src/test/contracts/multiple-parameters.mligo new file mode 100644 index 000000000..5a6e51297 --- /dev/null +++ b/src/test/contracts/multiple-parameters.mligo @@ -0,0 +1,4 @@ +(* Test function with several parameters *) + +let abcde (a : int) (b : int) (c : int) (d : int) (e : int) : int = + (c + e + 3) diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 384f726f0..00530e875 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -367,6 +367,18 @@ let multiple_parameters () : unit result = ] in ok () +let multiple_parameters_mligo () : unit result = + let%bind program = mtype_file "./contracts/multiple-parameters.mligo" in + let aux ((name : string) , make_input , make_output) = + let make_output' = fun n -> e_int @@ make_output n in + expect_eq_n program name make_input make_output' + in + let%bind _ = bind_list @@ List.map aux [ + (* Didn't include the other tests because they're probably not necessary *) + ("abcde", tuple_ez_int ["a";"b";"c";"d";"e"], fun n -> 2 * n + 3) ; + ] in + ok () + let record () : unit result = let%bind program = type_file "./contracts/record.ligo" in let%bind () = @@ -1001,6 +1013,7 @@ let main = test_suite "Integration (End to End)" [ test "shadow" shadow ; test "annotation" annotation ; test "multiple parameters" multiple_parameters ; + test "multiple parameters (mligo)" multiple_parameters_mligo ; test "bool" bool_expression ; test "bool (mligo)" bool_expression_mligo ; test "arithmetic" arithmetic ; From 2ff178543f9c2633a183bcd51d1a4abc0a31d45e Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Tue, 29 Oct 2019 20:33:18 -0700 Subject: [PATCH 11/13] Add more operations to CameLIGO set tests --- src/test/contracts/set_arithmetic.mligo | 20 ++++++++++++++++++++ src/test/integration_tests.ml | 19 ++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/test/contracts/set_arithmetic.mligo b/src/test/contracts/set_arithmetic.mligo index 23947077d..86d81fe67 100644 --- a/src/test/contracts/set_arithmetic.mligo +++ b/src/test/contracts/set_arithmetic.mligo @@ -1,4 +1,24 @@ (* Test set operations in CameLIGO *) +let add_op (s : string set) : string set = + Set.add "foobar" s + +let remove_op (s : string set) : string set = + Set.remove "foobar" s + +let remove_deep (s : string set * nat) : string set * nat = + Set.remove "foobar" s.(0) + +(* +let patch_op (s: string set) : string set = + begin patch s with set ["foobar"]; end with s + +let patch_op_deep (s: string set * nat) : string set * nat = + begin patch s.0 with set ["foobar"]; end with s +*) + +let mem_op (s : string set) : bool = + Set.mem "foobar" s + let size_op (s: string set) : nat = Set.size s diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 00530e875..1a25abe00 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -333,7 +333,24 @@ let set_arithmetic_mligo () : unit result = let%bind () = expect_eq program "size_op" (e_set [e_string "foo"; e_string "bar"; e_string "foobar"]) - (e_nat 3) in ok () + (e_nat 3) in + 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 + ok () let unit_expression () : unit result = let%bind program = type_file "./contracts/unit.ligo" in From 85345387d0bb126d56b22f37272dd81b9ac04d53 Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Tue, 29 Oct 2019 20:55:36 -0700 Subject: [PATCH 12/13] Add tuple tests to CameLIGO --- src/test/contracts/tuple.mligo | 15 +++++++++++++++ src/test/integration_tests.ml | 25 +++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 src/test/contracts/tuple.mligo diff --git a/src/test/contracts/tuple.mligo b/src/test/contracts/tuple.mligo new file mode 100644 index 000000000..178ecfe7b --- /dev/null +++ b/src/test/contracts/tuple.mligo @@ -0,0 +1,15 @@ +type abc = int * int * int + +let projection_abc (tpl : abc) : int = + tpl.(1) + +type foobar = int * int + +let fb : foobar = (0, 0) + +let projection (tpl : foobar) : int = + tpl.(0) + tpl.(1) + +type big_tuple = int * int * int * int * int + +let br : big_tuple = (23, 23, 23, 23, 23) diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 1a25abe00..7c5b18938 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -467,6 +467,30 @@ let tuple () : unit result = in ok () +let tuple_mligo () : unit result = + let%bind program = mtype_file "./contracts/tuple.mligo" in + let ez n = + e_tuple (List.map e_int n) in + 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 + 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 + expect_eq_n program "projection_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 () = @@ -1023,6 +1047,7 @@ let main = test_suite "Integration (End to End)" [ test "variant (mligo)" variant_mligo ; test "variant matching" variant_matching ; test "tuple" tuple ; + test "tuple (mligo)" tuple_mligo ; test "record" record ; test "condition simple" condition_simple ; test "condition" condition ; From 27b7527f18d8c6c191064dbcf3f333c9dcd4576d Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Tue, 29 Oct 2019 21:33:48 -0700 Subject: [PATCH 13/13] Add test for CameLIGO set fold --- src/test/contracts/set_arithmetic-1.mligo | 6 ++++++ src/test/integration_tests.ml | 6 ++++++ 2 files changed, 12 insertions(+) create mode 100644 src/test/contracts/set_arithmetic-1.mligo diff --git a/src/test/contracts/set_arithmetic-1.mligo b/src/test/contracts/set_arithmetic-1.mligo new file mode 100644 index 000000000..811b5b7af --- /dev/null +++ b/src/test/contracts/set_arithmetic-1.mligo @@ -0,0 +1,6 @@ +// Test set iteration + +let aggregate (i : int) (j : int) : int = i + j + +let fold_op (s : int set) : int = + Set.fold s 15 aggregate diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 7c5b18938..b0796453b 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -330,6 +330,7 @@ let set_arithmetic () : unit result = let set_arithmetic_mligo () : unit result = let%bind program = mtype_file "./contracts/set_arithmetic.mligo" in + let%bind program_1 = type_file "./contracts/set_arithmetic-1.ligo" in let%bind () = expect_eq program "size_op" (e_set [e_string "foo"; e_string "bar"; e_string "foobar"]) @@ -350,6 +351,11 @@ let set_arithmetic_mligo () : unit result = 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_1 "fold_op" + (e_set [ e_int 4 ; e_int 10 ]) + (e_int 29) + in ok () let unit_expression () : unit result =