support bytes_unpack operator in pascaligo + tests
This commit is contained in:
parent
78276f451e
commit
2d7c3eb216
@ -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
|
||||
|
11
src/test/contracts/bytes_unpack.ligo
Normal file
11
src/test/contracts/bytes_unpack.ligo
Normal file
@ -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))
|
@ -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 ;
|
||||
|
Loading…
Reference in New Issue
Block a user