"Guess the string" contract

This commit is contained in:
Georges Dupéron 2019-06-05 19:18:16 +02:00
parent a0624614ee
commit 08626f749c
2 changed files with 12 additions and 0 deletions

View File

@ -76,6 +76,10 @@ let get_t_bytes (t:type_value) : unit result = match t.type_value' with
| T_constant ("bytes", []) -> ok () | T_constant ("bytes", []) -> ok ()
| _ -> simple_fail "not a bytes" | _ -> 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 let get_t_contract (t:type_value) : type_value result = match t.type_value' with
| T_constant ("contract", [x]) -> ok x | T_constant ("contract", [x]) -> ok x
| _ -> simple_fail "not a contract" | _ -> 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_list = Function.compose to_bool get_t_list
let is_t_nat = Function.compose to_bool get_t_nat 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 is_t_int = Function.compose to_bool get_t_int
let assert_t_bytes = fun t -> let assert_t_bytes = fun t ->

View File

@ -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 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 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)" [ let main = test_suite "Integration (End to End)" [
test "type alias" type_alias ; test "type alias" type_alias ;
test "function" function_ ; test "function" function_ ;
@ -500,4 +506,5 @@ let main = test_suite "Integration (End to End)" [
test "counter contract mligo" counter_mligo ; test "counter contract mligo" counter_mligo ;
(* test "guess the hash mligo" guess_the_hash_mligo ; *) (* test "guess the hash mligo" guess_the_hash_mligo ; *)
(* test "failwith mligo" failwith_mligo ; *) (* test "failwith mligo" failwith_mligo ; *)
(* test "guess string mligo" guess_string_mligo ; *)
] ]