diff --git a/src/passes/operators/operators.ml b/src/passes/operators/operators.ml index 424032703..485701813 100644 --- a/src/passes/operators/operators.ml +++ b/src/passes/operators/operators.ml @@ -92,6 +92,7 @@ module Simplify = struct | "bytes_concat" -> ok C_CONCAT | "bytes_slice" -> ok C_SLICE | "bytes_pack" -> ok C_BYTES_PACK + | "bytes_unpack" -> ok C_BYTES_UNPACK | "set_empty" -> ok C_SET_EMPTY | "set_mem" -> ok C_SET_MEM | "set_add" -> ok C_SET_ADD diff --git a/src/test/contracts/bytes_unpack.ligo b/src/test/contracts/bytes_unpack.ligo new file mode 100644 index 000000000..c6b087635 --- /dev/null +++ b/src/test/contracts/bytes_unpack.ligo @@ -0,0 +1,11 @@ +function id_string (const p : string) : option(string) is block { + const packed : bytes = bytes_pack(p) ; +} with (bytes_unpack(packed): option(string)) + +function id_int (const p : int) : option(int) is block { + const packed : bytes = bytes_pack(p) ; +} with (bytes_unpack(packed): option(int)) + +function id_address (const p : address) : option(address) is block { + const packed : bytes = bytes_pack(p) ; +} with (bytes_unpack(packed): option(address)) \ No newline at end of file diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index d5b1c940c..b633f3faa 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -1812,7 +1812,18 @@ let let_in_multi_bind () : unit result = (e_string "mynameisbob") in ok () +let bytes_unpack () : unit result = + let%bind program = type_file "./contracts/bytes_unpack.ligo" in + let%bind () = expect_eq program "id_string" (e_string "teststring") (e_some (e_string "teststring")) in + let%bind () = expect_eq program "id_int" (e_int 42) (e_some (e_int 42)) in + let open Proto_alpha_utils.Memory_proto_alpha in + let addr = Protocol.Alpha_context.Contract.to_b58check @@ + (List.nth dummy_environment.identities 0).implicit_contract in + let%bind () = expect_eq program "id_address" (e_address addr) (e_some (e_address addr)) in + ok () + let main = test_suite "Integration (End to End)" [ + test "bytes unpack" bytes_unpack ; test "key hash" key_hash ; test "chain id" chain_id ; test "type alias" type_alias ;