From 4835ac4d1053236d79467ce3de957cedf7c9329b Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Thu, 16 Jan 2020 22:46:28 -0800 Subject: [PATCH] Split e_bytes into e_bytes_hex, e_bytes_raw and e_bytes_string --- src/stages/ast_simplified/combinators.ml | 6 ++-- src/stages/ast_simplified/combinators.mli | 5 +-- src/test/integration_tests.ml | 42 +++++++++++------------ src/test/multisig_v2_tests.ml | 16 ++++----- src/test/typer_tests.ml | 2 +- 5 files changed, 37 insertions(+), 34 deletions(-) diff --git a/src/stages/ast_simplified/combinators.ml b/src/stages/ast_simplified/combinators.ml index 1077f991a..a082e2fa9 100644 --- a/src/stages/ast_simplified/combinators.ml +++ b/src/stages/ast_simplified/combinators.ml @@ -92,11 +92,13 @@ let e_chain_id ?loc s : expression = location_wrap ?loc @@ E_literal (Literal_ch let e'_bytes b : expression' result = let%bind bytes = generic_try (simple_error "bad hex to bytes") (fun () -> Hex.to_bytes (`Hex b)) in ok @@ E_literal (Literal_bytes bytes) -let e_bytes ?loc b : expression result = +let e_bytes_hex ?loc b : expression result = let%bind e' = e'_bytes b in ok @@ location_wrap ?loc e' -let e_bytes_ofbytes ?loc (b: bytes) : expression = +let e_bytes_raw ?loc (b: bytes) : expression = location_wrap ?loc @@ E_literal (Literal_bytes b) +let e_bytes_string ?loc (s: string) : expression = + location_wrap ?loc @@ E_literal (Literal_bytes (Hex.to_bytes (Hex.of_string s))) let e_big_map ?loc lst : expression = location_wrap ?loc @@ E_big_map lst let e_record ?loc map : expression = location_wrap ?loc @@ E_record map let e_tuple ?loc lst : expression = location_wrap ?loc @@ E_tuple lst diff --git a/src/stages/ast_simplified/combinators.mli b/src/stages/ast_simplified/combinators.mli index 376ec322e..2bc534748 100644 --- a/src/stages/ast_simplified/combinators.mli +++ b/src/stages/ast_simplified/combinators.mli @@ -60,8 +60,9 @@ val e_key_hash : ?loc:Location.t -> string -> expression val e_chain_id : ?loc:Location.t -> string -> expression val e_mutez : ?loc:Location.t -> int -> expression val e'_bytes : string -> expression' result -val e_bytes : ?loc:Location.t -> string -> expression result -val e_bytes_ofbytes : ?loc:Location.t -> bytes -> expression +val e_bytes_hex : ?loc:Location.t -> string -> expression result +val e_bytes_raw : ?loc:Location.t -> bytes -> expression +val e_bytes_string : ?loc:Location.t -> string -> expression val e_big_map : ?loc:Location.t -> ( expr * expr ) list -> expression (* val e_record : ?loc:Location.t -> ( expr * expr ) list -> expression diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 394bcc4f0..341897585 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -410,13 +410,13 @@ let string_arithmetic_religo () : unit result = 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 foo = e_bytes_hex "0f00" in + let%bind foototo = e_bytes_hex "0f007070" in + let%bind toto = e_bytes_hex "7070" in + let%bind empty = e_bytes_hex "" in + let%bind tata = e_bytes_hex "7a7a7a7a" in + let%bind at = e_bytes_hex "7a7a" in + let%bind ba = e_bytes_hex "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 @@ -430,13 +430,13 @@ let bytes_arithmetic () : unit result = let bytes_arithmetic_mligo () : unit result = let%bind program = mtype_file "./contracts/bytes_arithmetic.mligo" 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 foo = e_bytes_hex "0f00" in + let%bind foototo = e_bytes_hex "0f007070" in + let%bind toto = e_bytes_hex "7070" in + let%bind empty = e_bytes_hex "" in + let%bind tata = e_bytes_hex "7a7a7a7a" in + let%bind at = e_bytes_hex "7a7a" in + let%bind ba = e_bytes_hex "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 @@ -450,13 +450,13 @@ let bytes_arithmetic_mligo () : unit result = let bytes_arithmetic_religo () : unit result = let%bind program = retype_file "./contracts/bytes_arithmetic.religo" 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 foo = e_bytes_hex "0f00" in + let%bind foototo = e_bytes_hex "0f007070" in + let%bind toto = e_bytes_hex "7070" in + let%bind empty = e_bytes_hex "" in + let%bind tata = e_bytes_hex "7a7a7a7a" in + let%bind at = e_bytes_hex "7a7a" in + let%bind ba = e_bytes_hex "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 diff --git a/src/test/multisig_v2_tests.ml b/src/test/multisig_v2_tests.ml index eb4198c3e..b963b5194 100644 --- a/src/test/multisig_v2_tests.ml +++ b/src/test/multisig_v2_tests.ml @@ -56,7 +56,7 @@ let storage {state_hash ; threshold ; max_proposal ; max_msg_size ; id_counter_l ([],[]) id_counter_list in e_ez_record [ - ("state_hash" , e_bytes_ofbytes state_hash ) ; + ("state_hash" , e_bytes_raw state_hash ) ; ("threshold" , e_nat threshold ) ; ("max_proposal" , e_nat max_proposal ) ; ("max_message_size" , e_nat max_msg_size ) ; @@ -101,7 +101,7 @@ let message_size_exceeded () = let maximum_number_of_proposal () = let%bind program,_ = get_program () in let%bind packed_payload1 = pack_payload program (send_param empty_message) in - let bytes1 = e_bytes_ofbytes packed_payload1 in + let bytes1 = e_bytes_raw packed_payload1 in let init_storage = storage { threshold = 1 ; max_proposal = 1 ; max_msg_size = 15 ; state_hash = Bytes.empty ; id_counter_list = [1,1] ; @@ -119,7 +119,7 @@ let maximum_number_of_proposal () = let send_already_accounted () = let%bind program,_ = get_program () in let%bind packed_payload = pack_payload program empty_message in - let bytes = e_bytes_ofbytes packed_payload in + let bytes = e_bytes_raw packed_payload in let init_storage = storage { threshold = 2 ; max_proposal = 1 ; max_msg_size = 15 ; state_hash = Bytes.empty ; id_counter_list = [1,1 ; 2,0] ; @@ -135,7 +135,7 @@ let send_already_accounted () = let send_never_accounted () = let%bind program,_ = get_program () in let%bind packed_payload = pack_payload program empty_message in - let bytes = e_bytes_ofbytes packed_payload in + let bytes = e_bytes_raw packed_payload in let init_storage' = { threshold = 2 ; max_proposal = 1 ; max_msg_size = 15 ; state_hash = Bytes.empty ; id_counter_list = [1,0 ; 2,0] ; @@ -156,7 +156,7 @@ let send_never_accounted () = let withdraw_already_accounted_one () = let%bind program,_ = get_program () in let%bind packed_payload = pack_payload program empty_message in - let bytes = e_bytes_ofbytes packed_payload in + let bytes = e_bytes_raw packed_payload in let param = withdraw_param in let init_storage' = { threshold = 2 ; max_proposal = 1 ; max_msg_size = 1 ; state_hash = Bytes.empty ; @@ -177,7 +177,7 @@ let withdraw_already_accounted_one () = let withdraw_already_accounted_two () = let%bind program,_ = get_program () in let%bind packed_payload = pack_payload program empty_message in - let bytes = e_bytes_ofbytes packed_payload in + let bytes = e_bytes_raw packed_payload in let param = withdraw_param in let init_storage' = { threshold = 2 ; max_proposal = 2 ; max_msg_size = 1 ; state_hash = Bytes.empty ; @@ -198,7 +198,7 @@ let withdraw_already_accounted_two () = let counters_reset () = let%bind program,_ = get_program () in let%bind packed_payload = pack_payload program empty_message in - let bytes = e_bytes_ofbytes packed_payload in + let bytes = e_bytes_raw packed_payload in let param = send_param empty_message in let hash_after_msg = sha_256_hash (Bytes.concat Bytes.empty [Bytes.empty ; packed_payload]) in let init_storage' = { @@ -236,7 +236,7 @@ let withdraw_never_accounted () = let succeeded_storing () = let%bind program,_ = get_program () in let%bind packed_payload = pack_payload program empty_message in - let bytes = e_bytes_ofbytes packed_payload in + let bytes = e_bytes_raw packed_payload in let init_storage th = { threshold = th ; max_proposal = 1 ; max_msg_size = 15 ; state_hash = Bytes.empty ; id_counter_list = [1,0 ; 2,0 ; 3,0] ; diff --git a/src/test/typer_tests.ml b/src/test/typer_tests.ml index 0fc687385..b3a5c5b18 100644 --- a/src/test/typer_tests.ml +++ b/src/test/typer_tests.ml @@ -41,7 +41,7 @@ module TestExpressions = struct let bool () : unit result = test_expression I.(e_bool true) O.(t_bool ()) let string () : unit result = test_expression I.(e_string "s") O.(t_string ()) let bytes () : unit result = - let%bind b = I.e_bytes "0b" in + let%bind b = I.e_bytes_hex "0b" in test_expression b O.(t_bytes ()) let lambda () : unit result =