Split e_bytes into e_bytes_hex, e_bytes_raw and e_bytes_string

This commit is contained in:
John David Pressman 2020-01-16 22:46:28 -08:00
parent 6ce1ca4fcd
commit 4835ac4d10
5 changed files with 37 additions and 34 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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] ;

View File

@ -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 =