From ca1caf2e617433b836be9ba30f814880b9cdedcd Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Thu, 16 Jan 2020 20:27:50 -0800 Subject: [PATCH] Add bytes_unpack test for CameLIGO --- src/test/contracts/bytes_unpack.mligo | 11 +++++++++++ src/test/integration_tests.ml | 11 +++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/test/contracts/bytes_unpack.mligo diff --git a/src/test/contracts/bytes_unpack.mligo b/src/test/contracts/bytes_unpack.mligo new file mode 100644 index 000000000..e33f09b47 --- /dev/null +++ b/src/test/contracts/bytes_unpack.mligo @@ -0,0 +1,11 @@ +let id_string (p: string) : string option = + let packed: bytes = Bytes.pack p in + ((Bytes.unpack packed): string option) + +let id_int (p: int) : int option = + let packed: bytes = Bytes.pack p in + ((Bytes.unpack packed): int option) + +let id_address (p: address) : address option = + let packed: bytes = Bytes.pack p in + ((Bytes.unpack packed): address option) diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 394bcc4f0..83647bb12 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -1968,6 +1968,16 @@ let bytes_unpack () : unit result = let%bind () = expect_eq program "id_address" (e_address addr) (e_some (e_address addr)) in ok () +let bytes_unpack_mligo () : unit result = + let%bind program = mtype_file "./contracts/bytes_unpack.mligo" 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 empty_case () : unit result = let%bind program = type_file "./contracts/empty_case.ligo" in let%bind () = @@ -2012,6 +2022,7 @@ let empty_case_religo () : unit result = let main = test_suite "Integration (End to End)" [ test "bytes unpack" bytes_unpack ; + test "bytes unpack (mligo)" bytes_unpack ; test "key hash" key_hash ; test "chain id" chain_id ; test "type alias" type_alias ;