From 08626f749ce4380807c0c10e3dc71bcf6f80479a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Wed, 5 Jun 2019 19:18:16 +0200 Subject: [PATCH] "Guess the string" contract --- src/ast_typed/combinators.ml | 5 +++++ src/test/integration_tests.ml | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/src/ast_typed/combinators.ml b/src/ast_typed/combinators.ml index f5859806e..350836fc0 100644 --- a/src/ast_typed/combinators.ml +++ b/src/ast_typed/combinators.ml @@ -76,6 +76,10 @@ let get_t_bytes (t:type_value) : unit result = match t.type_value' with | T_constant ("bytes", []) -> ok () | _ -> simple_fail "not a bytes" +let get_t_string (t:type_value) : unit result = match t.type_value' with + | T_constant ("string", []) -> ok () + | _ -> simple_fail "not a string" + let get_t_contract (t:type_value) : type_value result = match t.type_value' with | T_constant ("contract", [x]) -> ok x | _ -> simple_fail "not a contract" @@ -139,6 +143,7 @@ let assert_t_list t = let is_t_list = Function.compose to_bool get_t_list let is_t_nat = Function.compose to_bool get_t_nat +let is_t_string = Function.compose to_bool get_t_string let is_t_int = Function.compose to_bool get_t_int let assert_t_bytes = fun t -> diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index f3b8dfa58..e11a88a82 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -462,6 +462,12 @@ let guess_the_hash_mligo () : unit result = 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 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 main = test_suite "Integration (End to End)" [ test "type alias" type_alias ; test "function" function_ ; @@ -500,4 +506,5 @@ let main = test_suite "Integration (End to End)" [ test "counter contract mligo" counter_mligo ; (* test "guess the hash mligo" guess_the_hash_mligo ; *) (* test "failwith mligo" failwith_mligo ; *) + (* test "guess string mligo" guess_string_mligo ; *) ]