Michelson: Collection literals are now sequences
This commit is contained in:
parent
2364a66403
commit
f1132b8044
@ -19,14 +19,11 @@ type prim =
|
||||
| K_storage
|
||||
| K_code
|
||||
| D_False
|
||||
| D_Item
|
||||
| D_Elt
|
||||
| D_Left
|
||||
| D_List
|
||||
| D_Map
|
||||
| D_None
|
||||
| D_Pair
|
||||
| D_Right
|
||||
| D_Set
|
||||
| D_Some
|
||||
| D_True
|
||||
| D_Unit
|
||||
@ -141,14 +138,11 @@ let string_of_prim = function
|
||||
| K_storage -> "storage"
|
||||
| K_code -> "code"
|
||||
| D_False -> "False"
|
||||
| D_Item -> "Item"
|
||||
| D_Elt -> "Elt"
|
||||
| D_Left -> "Left"
|
||||
| D_List -> "List"
|
||||
| D_Map -> "Map"
|
||||
| D_None -> "None"
|
||||
| D_Pair -> "Pair"
|
||||
| D_Right -> "Right"
|
||||
| D_Set -> "Set"
|
||||
| D_Some -> "Some"
|
||||
| D_True -> "True"
|
||||
| D_Unit -> "Unit"
|
||||
@ -244,14 +238,11 @@ let prim_of_string = function
|
||||
| "storage" -> ok K_storage
|
||||
| "code" -> ok K_code
|
||||
| "False" -> ok D_False
|
||||
| "Item" -> ok D_Item
|
||||
| "Elt" -> ok D_Elt
|
||||
| "Left" -> ok D_Left
|
||||
| "List" -> ok D_List
|
||||
| "Map" -> ok D_Map
|
||||
| "None" -> ok D_None
|
||||
| "Pair" -> ok D_Pair
|
||||
| "Right" -> ok D_Right
|
||||
| "Set" -> ok D_Set
|
||||
| "Some" -> ok D_Some
|
||||
| "True" -> ok D_True
|
||||
| "Unit" -> ok D_Unit
|
||||
@ -391,14 +382,11 @@ let prim_encoding =
|
||||
("storage", K_storage) ;
|
||||
("code", K_code) ;
|
||||
("False", D_False) ;
|
||||
("Item", D_Item) ;
|
||||
("Elt", D_Elt) ;
|
||||
("Left", D_Left) ;
|
||||
("List", D_List) ;
|
||||
("Map", D_Map) ;
|
||||
("None", D_None) ;
|
||||
("Pair", D_Pair) ;
|
||||
("Right", D_Right) ;
|
||||
("Set", D_Set) ;
|
||||
("Some", D_Some) ;
|
||||
("True", D_True) ;
|
||||
("Unit", D_Unit) ;
|
||||
|
@ -17,14 +17,11 @@ type prim =
|
||||
| K_storage
|
||||
| K_code
|
||||
| D_False
|
||||
| D_Item
|
||||
| D_Elt
|
||||
| D_Left
|
||||
| D_List
|
||||
| D_Map
|
||||
| D_None
|
||||
| D_Pair
|
||||
| D_Right
|
||||
| D_Set
|
||||
| D_Some
|
||||
| D_True
|
||||
| D_Unit
|
||||
|
@ -266,14 +266,11 @@ let namespace = function
|
||||
| K_storage
|
||||
| K_code -> Keyword_namespace
|
||||
| D_False
|
||||
| D_Item
|
||||
| D_Elt
|
||||
| D_Left
|
||||
| D_List
|
||||
| D_Map
|
||||
| D_None
|
||||
| D_Pair
|
||||
| D_Right
|
||||
| D_Set
|
||||
| D_Some
|
||||
| D_True
|
||||
| D_Unit -> Constant_namespace
|
||||
@ -625,7 +622,7 @@ let rec unparse_data
|
||||
Prim (-1, D_None, [], None)
|
||||
| List_t t, items ->
|
||||
let items = List.map (unparse_data t) items in
|
||||
Prim (-1, D_List, items, None)
|
||||
Seq (-1, items, None)
|
||||
| Set_t t, set ->
|
||||
let t = ty_of_comparable_ty t in
|
||||
let items =
|
||||
@ -633,18 +630,18 @@ let rec unparse_data
|
||||
(fun item acc ->
|
||||
unparse_data t item :: acc )
|
||||
set [] in
|
||||
Prim (-1, D_Set, List.rev items, None)
|
||||
Seq (-1, List.rev items, None)
|
||||
| Map_t (kt, vt), map ->
|
||||
let kt = ty_of_comparable_ty kt in
|
||||
let items =
|
||||
map_fold (fun k v acc ->
|
||||
Prim (-1, D_Item,
|
||||
Prim (-1, D_Elt,
|
||||
[ unparse_data kt k;
|
||||
unparse_data vt v ],
|
||||
None)
|
||||
:: acc)
|
||||
map [] in
|
||||
Prim (-1, D_Map, List.rev items, None)
|
||||
Seq (-1, List.rev items, None)
|
||||
| Lambda_t _, Lam (_, original_code) ->
|
||||
root original_code
|
||||
|
||||
@ -1133,17 +1130,19 @@ let rec parse_data
|
||||
| Option_t _, expr ->
|
||||
traced (fail (unexpected expr [] Constant_namespace [ D_Some ; D_None ]))
|
||||
(* Lists *)
|
||||
| List_t t, Prim (_, D_List, vs, _) ->
|
||||
| List_t t, Seq (loc, items, annot) ->
|
||||
fail_unexpected_annot loc annot >>=? fun () ->
|
||||
traced @@
|
||||
fold_right_s
|
||||
(fun v rest ->
|
||||
parse_data ?type_logger ctxt t v >>=? fun v ->
|
||||
return (v :: rest))
|
||||
vs []
|
||||
items []
|
||||
| List_t _, expr ->
|
||||
traced (fail (unexpected expr [] Constant_namespace [ D_List ]))
|
||||
traced (fail (Invalid_kind (location expr, [ Seq_kind ], kind expr)))
|
||||
(* Sets *)
|
||||
| Set_t t, (Prim (loc, D_Set, vs, _) as expr) ->
|
||||
| Set_t t, (Seq (loc, vs, annot) as expr) ->
|
||||
fail_unexpected_annot loc annot >>=? fun () ->
|
||||
fold_left_s
|
||||
(fun (last_value, set) v ->
|
||||
parse_comparable_data ?type_logger ctxt t v >>=? fun v ->
|
||||
@ -1160,12 +1159,13 @@ let rec parse_data
|
||||
return (Some v, set_update v true set))
|
||||
(None, empty_set t) vs >>|? snd |> traced
|
||||
| Set_t _, expr ->
|
||||
traced (fail (unexpected expr [] Constant_namespace [ D_Set ]))
|
||||
traced (fail (Invalid_kind (location expr, [ Seq_kind ], kind expr)))
|
||||
(* Maps *)
|
||||
| Map_t (tk, tv), (Prim (loc, D_Map, vs, _) as expr) ->
|
||||
| Map_t (tk, tv), (Seq (loc, vs, annot) as expr) ->
|
||||
fail_unexpected_annot loc annot >>=? fun () ->
|
||||
(fold_left_s
|
||||
(fun (last_value, map) -> function
|
||||
| Prim (_, D_Item, [ k; v ], _) ->
|
||||
| Prim (_, D_Elt, [ k; v ], _) ->
|
||||
parse_comparable_data ?type_logger ctxt tk k >>=? fun k ->
|
||||
parse_data ?type_logger ctxt tv v >>=? fun v ->
|
||||
begin match last_value with
|
||||
@ -1179,15 +1179,15 @@ let rec parse_data
|
||||
| None -> return ()
|
||||
end >>=? fun () ->
|
||||
return (Some k, map_update k (Some v) map)
|
||||
| Prim (loc, D_Item, l, _) ->
|
||||
fail @@ Invalid_arity (loc, D_Item, 2, List.length l)
|
||||
| Prim (loc, D_Elt, l, _) ->
|
||||
fail @@ Invalid_arity (loc, D_Elt, 2, List.length l)
|
||||
| Prim (loc, name, _, _) ->
|
||||
fail @@ Invalid_primitive (loc, [ D_Item ], name)
|
||||
fail @@ Invalid_primitive (loc, [ D_Elt ], name)
|
||||
| Int _ | String _ | Seq _ ->
|
||||
fail (error ()))
|
||||
(None, empty_map tk) vs) >>|? snd |> traced
|
||||
| Map_t _, expr ->
|
||||
traced (fail (unexpected expr [] Constant_namespace [ D_Map ]))
|
||||
traced (fail (Invalid_kind (location expr, [ Seq_kind ], kind expr)))
|
||||
|
||||
and parse_comparable_data
|
||||
: type a. ?type_logger:(int -> Script.expr list -> Script.expr list -> unit) ->
|
||||
|
@ -132,14 +132,11 @@ module Script : sig
|
||||
| K_storage
|
||||
| K_code
|
||||
| D_False
|
||||
| D_Item
|
||||
| D_Elt
|
||||
| D_Left
|
||||
| D_List
|
||||
| D_Map
|
||||
| D_None
|
||||
| D_Pair
|
||||
| D_Right
|
||||
| D_Set
|
||||
| D_Some
|
||||
| D_True
|
||||
| D_Unit
|
||||
|
@ -73,124 +73,124 @@ assert_output $CONTRACT_PATH/xor.tz Unit "(Pair True True)" False
|
||||
|
||||
|
||||
# Build list
|
||||
assert_output $CONTRACT_PATH/build_list.tz Unit 0 "(List 0)"
|
||||
assert_output $CONTRACT_PATH/build_list.tz Unit 3 "(List 0 1 2 3)"
|
||||
assert_output $CONTRACT_PATH/build_list.tz Unit 0 "{ 0 }"
|
||||
assert_output $CONTRACT_PATH/build_list.tz Unit 3 "{ 0 ; 1 ; 2 ; 3 }"
|
||||
assert_output $CONTRACT_PATH/build_list.tz Unit 10 \
|
||||
"(List 0 1 2 3 4 5 6 7 8 9 10)"
|
||||
"{ 0 ; 1 ; 2 ; 3 ; 4 ; 5 ; 6 ; 7 ; 8 ; 9 ; 10 }"
|
||||
|
||||
# Concatenate all strings of a list into one string
|
||||
assert_output $CONTRACT_PATH/concat_list.tz Unit '(List "a" "b" "c")' '"abc"'
|
||||
assert_output $CONTRACT_PATH/concat_list.tz Unit '(List )' '""'
|
||||
assert_output $CONTRACT_PATH/concat_list.tz Unit '{ "a" ; "b" ; "c" }' '"abc"'
|
||||
assert_output $CONTRACT_PATH/concat_list.tz Unit '{}' '""'
|
||||
assert_output $CONTRACT_PATH/concat_list.tz \
|
||||
Unit '(List "Hello" " " "World" "!")' '"Hello World!"'
|
||||
Unit '{ "Hello" ; " " ; "World" ; "!" }' '"Hello World!"'
|
||||
|
||||
# Find maximum int in list -- returns None if not found
|
||||
assert_output $CONTRACT_PATH/max_in_list.tz Unit '(List)' 'None'
|
||||
assert_output $CONTRACT_PATH/max_in_list.tz Unit '(List 1)' '(Some 1)'
|
||||
assert_output $CONTRACT_PATH/max_in_list.tz Unit '(List -1)' '(Some -1)'
|
||||
assert_output $CONTRACT_PATH/max_in_list.tz Unit '{}' 'None'
|
||||
assert_output $CONTRACT_PATH/max_in_list.tz Unit '{ 1 }' '(Some 1)'
|
||||
assert_output $CONTRACT_PATH/max_in_list.tz Unit '{ -1 }' '(Some -1)'
|
||||
assert_output $CONTRACT_PATH/max_in_list.tz Unit \
|
||||
'(List 10 -1 -20 100 0)' '(Some 100)'
|
||||
'{ 10 ; -1 ; -20 ; 100 ; 0 }' '(Some 100)'
|
||||
assert_output $CONTRACT_PATH/max_in_list.tz Unit \
|
||||
'(List 10 -1 -20 100 0)' '(Some 100)'
|
||||
'{ 10 ; -1 ; -20 ; 100 ; 0 }' '(Some 100)'
|
||||
assert_output $CONTRACT_PATH/max_in_list.tz Unit \
|
||||
'(List -10 -1 -20 -100)' '(Some -1)'
|
||||
'{ -10 ; -1 ; -20 ; -100 }' '(Some -1)'
|
||||
|
||||
# Identity on lists
|
||||
assert_output $CONTRACT_PATH/list_id.tz Unit '(List "1" "2" "3")' '(List "1" "2" "3")'
|
||||
assert_output $CONTRACT_PATH/list_id.tz Unit '(List)' 'List'
|
||||
assert_output $CONTRACT_PATH/list_id.tz Unit '(List "a" "b" "c")' '(List "a" "b" "c")'
|
||||
assert_output $CONTRACT_PATH/list_id.tz Unit '{ "1" ; "2" ; "3" }' '{ "1" ; "2" ; "3" }'
|
||||
assert_output $CONTRACT_PATH/list_id.tz Unit '{}' '{}'
|
||||
assert_output $CONTRACT_PATH/list_id.tz Unit '{ "a" ; "b" ; "c" }' '{ "a" ; "b" ; "c" }'
|
||||
|
||||
assert_output $CONTRACT_PATH/list_id_map.tz Unit '(List "1" "2" "3")' '(List "1" "2" "3")'
|
||||
assert_output $CONTRACT_PATH/list_id_map.tz Unit '(List)' 'List'
|
||||
assert_output $CONTRACT_PATH/list_id_map.tz Unit '(List "a" "b" "c")' '(List "a" "b" "c")'
|
||||
assert_output $CONTRACT_PATH/list_id_map.tz Unit '{ "1" ; "2" ; "3" }' '{ "1" ; "2" ; "3" }'
|
||||
assert_output $CONTRACT_PATH/list_id_map.tz Unit '{}' '{}'
|
||||
assert_output $CONTRACT_PATH/list_id_map.tz Unit '{ "a" ; "b" ; "c" }' '{ "a" ; "b" ; "c" }'
|
||||
|
||||
|
||||
# Identity on maps
|
||||
assert_output $CONTRACT_PATH/map_id.tz Unit '(Map (Item 0 1))' '(Map (Item 0 1))'
|
||||
assert_output $CONTRACT_PATH/map_id.tz Unit '(Map (Item 0 0))' '(Map (Item 0 0))'
|
||||
assert_output $CONTRACT_PATH/map_id.tz Unit '(Map (Item 0 0) (Item 3 4))' '(Map (Item 0 0) (Item 3 4))'
|
||||
assert_output $CONTRACT_PATH/map_id.tz Unit '{ Elt 0 1 }' '{ Elt 0 1 }'
|
||||
assert_output $CONTRACT_PATH/map_id.tz Unit '{ Elt 0 0 }' '{ Elt 0 0 }'
|
||||
assert_output $CONTRACT_PATH/map_id.tz Unit '{ Elt 0 0 ; Elt 3 4 }' '{ Elt 0 0 ; Elt 3 4 }'
|
||||
|
||||
# Map block on lists
|
||||
assert_output $CONTRACT_PATH/list_map_block.tz Unit '(List)' 'List'
|
||||
assert_output $CONTRACT_PATH/list_map_block.tz Unit '(List 1 1 1 1)' '(List 1 2 3 4)'
|
||||
assert_output $CONTRACT_PATH/list_map_block.tz Unit '(List 1 2 3 0)' '(List 1 3 5 3)'
|
||||
assert_output $CONTRACT_PATH/list_map_block.tz Unit '{}' '{}'
|
||||
assert_output $CONTRACT_PATH/list_map_block.tz Unit '{ 1 ; 1 ; 1 ; 1 }' '{ 1 ; 2 ; 3 ; 4 }'
|
||||
assert_output $CONTRACT_PATH/list_map_block.tz Unit '{ 1 ; 2 ; 3 ; 0 }' '{ 1 ; 3 ; 5 ; 3 }'
|
||||
|
||||
# List iter
|
||||
assert_output $CONTRACT_PATH/list_iter.tz Unit '(List 10 2 1)' 20
|
||||
assert_output $CONTRACT_PATH/list_iter.tz Unit '(List 3 6 9)' 162
|
||||
assert_output $CONTRACT_PATH/list_iter.tz Unit '{ 10 ; 2 ; 1 }' 20
|
||||
assert_output $CONTRACT_PATH/list_iter.tz Unit '{ 3 ; 6 ; 9 }' 162
|
||||
|
||||
assert_output $CONTRACT_PATH/list_iter2.tz Unit '(List "a" "b" "c")' '"cba"'
|
||||
assert_output $CONTRACT_PATH/list_iter2.tz Unit '(List)' '""'
|
||||
assert_output $CONTRACT_PATH/list_iter2.tz Unit '{ "a" ; "b" ; "c" }' '"cba"'
|
||||
assert_output $CONTRACT_PATH/list_iter2.tz Unit '{}' '""'
|
||||
|
||||
|
||||
# Identity on sets
|
||||
assert_output $CONTRACT_PATH/set_id.tz Unit '(Set "a" "b" "c")' '(Set "a" "b" "c")'
|
||||
assert_output $CONTRACT_PATH/set_id.tz Unit '(Set)' 'Set'
|
||||
assert_output $CONTRACT_PATH/set_id.tz Unit '(Set "asdf" "bcde")' '(Set "asdf" "bcde")'
|
||||
assert_output $CONTRACT_PATH/set_id.tz Unit '{ "a" ; "b" ; "c" }' '{ "a" ; "b" ; "c" }'
|
||||
assert_output $CONTRACT_PATH/set_id.tz Unit '{}' '{}'
|
||||
assert_output $CONTRACT_PATH/set_id.tz Unit '{ "asdf" ; "bcde" }' '{ "asdf" ; "bcde" }'
|
||||
|
||||
# Set member -- set is in storage
|
||||
assert_output $CONTRACT_PATH/set_member.tz '(Set)' '"Hi"' 'False'
|
||||
assert_output $CONTRACT_PATH/set_member.tz '(Set "Hi")' '"Hi"' 'True'
|
||||
assert_output $CONTRACT_PATH/set_member.tz '(Set "Hello" "World")' '""' 'False'
|
||||
assert_output $CONTRACT_PATH/set_member.tz '{}' '"Hi"' 'False'
|
||||
assert_output $CONTRACT_PATH/set_member.tz '{ "Hi" }' '"Hi"' 'True'
|
||||
assert_output $CONTRACT_PATH/set_member.tz '{ "Hello" ; "World" }' '""' 'False'
|
||||
|
||||
# Set size
|
||||
assert_output $CONTRACT_PATH/set_size.tz Unit '(Set)' 0
|
||||
assert_output $CONTRACT_PATH/set_size.tz Unit '(Set 1)' 1
|
||||
assert_output $CONTRACT_PATH/set_size.tz Unit '(Set 1 2 3)' 3
|
||||
assert_output $CONTRACT_PATH/set_size.tz Unit '(Set 1 2 3 4 5 6)' 6
|
||||
assert_output $CONTRACT_PATH/set_size.tz Unit '{}' 0
|
||||
assert_output $CONTRACT_PATH/set_size.tz Unit '{ 1 }' 1
|
||||
assert_output $CONTRACT_PATH/set_size.tz Unit '{ 1 ; 2 ; 3 }' 3
|
||||
assert_output $CONTRACT_PATH/set_size.tz Unit '{ 1 ; 2 ; 3 ; 4 ; 5 ; 6 }' 6
|
||||
|
||||
# Set iter
|
||||
assert_output $CONTRACT_PATH/set_iter.tz Unit '(Set)' 0
|
||||
assert_output $CONTRACT_PATH/set_iter.tz Unit '(Set 1)' 1
|
||||
assert_output $CONTRACT_PATH/set_iter.tz Unit '(Set -100 1 2 3)' '-94'
|
||||
assert_output $CONTRACT_PATH/set_iter.tz Unit '{}' 0
|
||||
assert_output $CONTRACT_PATH/set_iter.tz Unit '{ 1 }' 1
|
||||
assert_output $CONTRACT_PATH/set_iter.tz Unit '{ -100 ; 1 ; 2 ; 3 }' '-94'
|
||||
|
||||
# Map size
|
||||
assert_output $CONTRACT_PATH/map_size.tz Unit '(Map)' 0
|
||||
assert_output $CONTRACT_PATH/map_size.tz Unit '(Map (Item "a" 1))' 1
|
||||
assert_output $CONTRACT_PATH/map_size.tz Unit '{}' 0
|
||||
assert_output $CONTRACT_PATH/map_size.tz Unit '{ Elt "a" 1 }' 1
|
||||
assert_output $CONTRACT_PATH/map_size.tz Unit \
|
||||
'(Map (Item "a" 1) (Item "b" 2) (Item "c" 3))' 3
|
||||
'{ Elt "a" 1 ; Elt "b" 2 ; Elt "c" 3 }' 3
|
||||
assert_output $CONTRACT_PATH/map_size.tz Unit \
|
||||
'(Map (Item "a" 1) (Item "b" 2) (Item "c" 3) (Item "d" 4) (Item "e" 5) (Item "f" 6))' 6
|
||||
'{ Elt "a" 1 ; Elt "b" 2 ; Elt "c" 3 ; Elt "d" 4 ; Elt "e" 5 ; Elt "f" 6 }' 6
|
||||
|
||||
# Contains all elements -- does the second list contain all of the same elements
|
||||
# as the first one? I'm ignoring element multiplicity
|
||||
assert_output $CONTRACT_PATH/contains_all.tz \
|
||||
Unit '(Pair (List) (List))' 'True'
|
||||
Unit '(Pair {} {})' 'True'
|
||||
assert_output $CONTRACT_PATH/contains_all.tz \
|
||||
Unit '(Pair (List "a") (List "B"))' 'False'
|
||||
Unit '(Pair { "a" } { "B" })' 'False'
|
||||
assert_output $CONTRACT_PATH/contains_all.tz \
|
||||
Unit '(Pair (List "A") (List "B"))' 'False'
|
||||
Unit '(Pair { "A" } { "B" })' 'False'
|
||||
assert_output $CONTRACT_PATH/contains_all.tz \
|
||||
Unit '(Pair (List "B") (List "B"))' 'True'
|
||||
Unit '(Pair { "B" } { "B" })' 'True'
|
||||
assert_output $CONTRACT_PATH/contains_all.tz Unit \
|
||||
'(Pair (List "B" "C" "asdf") (List "B" "B" "asdf" "C"))' 'True'
|
||||
'(Pair { "B" ; "C" ; "asdf" } { "B" ; "B" ; "asdf" ; "C" })' 'True'
|
||||
assert_output $CONTRACT_PATH/contains_all.tz Unit \
|
||||
'(Pair (List "B" "B" "asdf" "C") (List "B" "C" "asdf"))' 'True'
|
||||
'(Pair { "B" ; "B" ; "asdf" ; "C" } { "B" ; "C" ; "asdf" })' 'True'
|
||||
|
||||
# Concatenate the string in storage with all strings in the given list
|
||||
assert_output $CONTRACT_PATH/concat_hello.tz Unit \
|
||||
'(List "World!")' '(List "Hello World!")'
|
||||
'{ "World!" }' '{ "Hello World!" }'
|
||||
assert_output $CONTRACT_PATH/concat_hello.tz Unit \
|
||||
'(List)' 'List'
|
||||
'{}' '{}'
|
||||
assert_output $CONTRACT_PATH/concat_hello.tz Unit \
|
||||
'(List "test1" "test2")' '(List "Hello test1" "Hello test2")'
|
||||
'{ "test1" ; "test2" }' '{ "Hello test1" ; "Hello test2" }'
|
||||
|
||||
# Create an empty map and add a string to it
|
||||
assert_output $CONTRACT_PATH/empty_map.tz Unit Unit \
|
||||
'(Map (Item "hello" "world"))'
|
||||
'{ Elt "hello" "world" }'
|
||||
|
||||
# Get the value stored at the given key in the map
|
||||
assert_output $CONTRACT_PATH/get_map_value.tz '(Map (Item "hello" "hi"))' \
|
||||
assert_output $CONTRACT_PATH/get_map_value.tz '{ Elt "hello" "hi" }' \
|
||||
'"hello"' '(Some "hi")'
|
||||
assert_output $CONTRACT_PATH/get_map_value.tz '(Map (Item "hello" "hi"))' \
|
||||
assert_output $CONTRACT_PATH/get_map_value.tz '{ Elt "hello" "hi" }' \
|
||||
'""' 'None'
|
||||
assert_output $CONTRACT_PATH/get_map_value.tz \
|
||||
'(Map (Item "1" "one") (Item "2" "two"))' \
|
||||
'{ Elt "1" "one" ; Elt "2" "two" }' \
|
||||
'"1"' '(Some "one")'
|
||||
|
||||
# Map iter
|
||||
assert_output $CONTRACT_PATH/map_iter.tz Unit '(Map (Item 0 100) (Item 2 100))' '(Pair 2 200)'
|
||||
assert_output $CONTRACT_PATH/map_iter.tz Unit '(Map (Item 1 1) (Item 2 100))' '(Pair 3 101)'
|
||||
assert_output $CONTRACT_PATH/map_iter.tz Unit '{ Elt 0 100 ; Elt 2 100 }' '(Pair 2 200)'
|
||||
assert_output $CONTRACT_PATH/map_iter.tz Unit '{ Elt 1 1 ; Elt 2 100 }' '(Pair 3 101)'
|
||||
|
||||
# Return True if True branch of if was taken and False otherwise
|
||||
assert_output $CONTRACT_PATH/if.tz Unit True True
|
||||
@ -201,14 +201,14 @@ assert_output $CONTRACT_PATH/swap_left_right.tz Unit '(Left True)' '(Right True)
|
||||
assert_output $CONTRACT_PATH/swap_left_right.tz Unit '(Right "a")' '(Left "a")'
|
||||
|
||||
# Reverse a list
|
||||
assert_output $CONTRACT_PATH/reverse.tz Unit '(List )' 'List'
|
||||
assert_output $CONTRACT_PATH/reverse.tz Unit '(List "c" "b" "a")' '(List "a" "b" "c")'
|
||||
assert_output $CONTRACT_PATH/reverse_loop.tz Unit '(List )' 'List'
|
||||
assert_output $CONTRACT_PATH/reverse_loop.tz Unit '(List "c" "b" "a")' '(List "a" "b" "c")'
|
||||
assert_output $CONTRACT_PATH/reverse.tz Unit '{}' '{}'
|
||||
assert_output $CONTRACT_PATH/reverse.tz Unit '{ "c" ; "b" ; "a" }' '{ "a" ; "b" ; "c" }'
|
||||
assert_output $CONTRACT_PATH/reverse_loop.tz Unit '{}' '{}'
|
||||
assert_output $CONTRACT_PATH/reverse_loop.tz Unit '{ "c" ; "b" ; "a" }' '{ "a" ; "b" ; "c" }'
|
||||
|
||||
# Reverse using LOOP_LEFT
|
||||
assert_output $CONTRACT_PATH/loop_left.tz Unit '(List )' 'List'
|
||||
assert_output $CONTRACT_PATH/loop_left.tz Unit '(List "c" "b" "a")' '(List "a" "b" "c")'
|
||||
assert_output $CONTRACT_PATH/loop_left.tz Unit '{}' '{}'
|
||||
assert_output $CONTRACT_PATH/loop_left.tz Unit '{ "c" ; "b" ; "a" }' '{ "a" ; "b" ; "c" }'
|
||||
|
||||
# Exec concat contract
|
||||
assert_output $CONTRACT_PATH/exec_concat.tz Unit '""' '"_abc"'
|
||||
@ -220,18 +220,18 @@ assert_output $CONTRACT_PATH/steps_to_quota.tz Unit Unit 39991
|
||||
# Get the current balance of the contract
|
||||
assert_output $CONTRACT_PATH/balance.tz Unit Unit '"4,000,000"'
|
||||
|
||||
# Test comparisons on tez (List EQ GT LT GE LE)
|
||||
assert_output $CONTRACT_PATH/compare.tz Unit '(Pair "1" "2")' '(List False False True False True)'
|
||||
assert_output $CONTRACT_PATH/compare.tz Unit '(Pair "2" "1")' '(List False True False True False)'
|
||||
assert_output $CONTRACT_PATH/compare.tz Unit '(Pair "2.37" "2.37")' '(List True False False True True)'
|
||||
# Test comparisons on tez { EQ ; GT ; LT ; GE ; LE }
|
||||
assert_output $CONTRACT_PATH/compare.tz Unit '(Pair "1.00" "2.00")' '{ False ; False ; True ; False ; True }'
|
||||
assert_output $CONTRACT_PATH/compare.tz Unit '(Pair "2.00" "1.00")' '{ False ; True ; False ; True ; False }'
|
||||
assert_output $CONTRACT_PATH/compare.tz Unit '(Pair "2.37" "2.37")' '{ True ; False ; False ; True ; True }'
|
||||
|
||||
# Test addition and subtraction on tez
|
||||
assert_output $CONTRACT_PATH/tez_add_sub.tz Unit '(Pair "2" "1")' '(Pair "3" "1")'
|
||||
assert_output $CONTRACT_PATH/tez_add_sub.tz Unit '(Pair "2.31" "1.01")' '(Pair "3.32" "1.3")'
|
||||
|
||||
# Test get first element of list
|
||||
assert_output $CONTRACT_PATH/first.tz Unit '(List 1 2 3 4)' '1'
|
||||
assert_output $CONTRACT_PATH/first.tz Unit '(List 4)' '4'
|
||||
assert_output $CONTRACT_PATH/first.tz Unit '{ 1 ; 2 ; 3 ; 4 }' '1'
|
||||
assert_output $CONTRACT_PATH/first.tz Unit '{ 4 }' '4'
|
||||
|
||||
# Hash input string
|
||||
# Test assumed to be correct -- hash is based on encoding of AST
|
||||
@ -405,10 +405,10 @@ account=tz1SuakBpFdG9b4twyfrSMqZzruxhpMeSrE5
|
||||
$client transfer 0 from bootstrap1 to default_account -arg "\"$account\""
|
||||
assert_balance $account "100 ꜩ"
|
||||
|
||||
assert_fails $client typecheck data '(Map (Item 0 1) (Item 0 1))' against type '(map nat nat)'
|
||||
assert_fails $client typecheck data '(Map (Item 0 1) (Item 10 1) (Item 5 1))' against type '(map nat nat)'
|
||||
assert_fails $client typecheck data '(Set "A" "C" "B")' against type '(set string)'
|
||||
assert_fails $client typecheck data '(Set "A" "B" "B")' against type '(set string)'
|
||||
assert_fails $client typecheck data '{ Elt 0 1 ; Elt 0 1 }' against type '(map nat nat)'
|
||||
assert_fails $client typecheck data '{ Elt 0 1 ; Elt 10 1 ; Elt 5 1 }' against type '(map nat nat)'
|
||||
assert_fails $client typecheck data '{ "A" ; "C" ; "B" }' against type '(set string)'
|
||||
assert_fails $client typecheck data '{ "A" ; "B" ; "B" }' against type '(set string)'
|
||||
|
||||
hash_result=`$client hash data '(Pair "22220.00" (Pair "2017-12-13T04:49:00Z" 034))' \
|
||||
of type '(pair tez (pair timestamp int))'`
|
||||
|
Loading…
Reference in New Issue
Block a user