2018-02-02 18:13:38 +01:00
#!/bin/bash
set -e
set -o pipefail
test_dir = " $( cd " $( dirname " $0 " ) " && echo " $( pwd -P) " ) "
source $test_dir /test_lib.inc.sh " $@ "
start_node 1
activate_alpha
2018-04-21 17:16:01 +02:00
bake
2018-02-02 18:13:38 +01:00
key1 = foo
key2 = bar
$client gen keys $key1
$client gen keys $key2
printf "\n\n"
# Assert all contracts typecheck
if [ ! $NO_TYPECHECK ] ; then
for contract in ` ls $contract_dir /*.tz` ; do
printf "[Typechecking %s]\n" " $contract " ;
${ client } typecheck program " $contract " ;
done
printf "All contracts are well typed\n\n"
fi
# FORMAT: assert_output contract_file storage input expected_result
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /ret_int.tz None Unit '(Some 300)'
2018-02-02 18:13:38 +01:00
# Identity on strings
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /str_id.tz None '"Hello"' '(Some "Hello")'
assert_storage $contract_dir /str_id.tz None '"abcd"' '(Some "abcd")'
2018-02-02 18:13:38 +01:00
# Identity on pairs
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /pair_id.tz None '(Pair True False)' '(Some (Pair True False))'
assert_storage $contract_dir /pair_id.tz None '(Pair False True)' '(Some (Pair False True))'
assert_storage $contract_dir /pair_id.tz None '(Pair True True)' '(Some (Pair True True))'
assert_storage $contract_dir /pair_id.tz None '(Pair False False)' '(Some (Pair False False))'
2018-02-02 18:13:38 +01:00
# Logical not
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /not.tz None True '(Some False)'
assert_storage $contract_dir /not.tz None False '(Some True)'
2018-02-02 18:13:38 +01:00
# Logical and
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /and.tz None "(Pair False False)" '(Some False)'
assert_storage $contract_dir /and.tz None "(Pair False True)" '(Some False)'
assert_storage $contract_dir /and.tz None "(Pair True False)" '(Some False)'
assert_storage $contract_dir /and.tz None "(Pair True True)" '(Some True)'
2018-02-02 18:13:38 +01:00
# Logical or
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /or.tz None "(Pair False False)" '(Some False)'
assert_storage $contract_dir /or.tz None "(Pair False True)" '(Some True)'
assert_storage $contract_dir /or.tz None "(Pair True False)" '(Some True)'
assert_storage $contract_dir /or.tz None "(Pair True True)" '(Some True)'
2018-02-02 18:13:38 +01:00
# XOR
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /xor.tz None "(Pair False False)" '(Some False)'
assert_storage $contract_dir /xor.tz None "(Pair False True)" '(Some True)'
assert_storage $contract_dir /xor.tz None "(Pair True False)" '(Some True)'
assert_storage $contract_dir /xor.tz None "(Pair True True)" '(Some False)'
2018-02-02 18:13:38 +01:00
# Build list
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /build_list.tz '{}' 0 "{ 0 }"
assert_storage $contract_dir /build_list.tz '{}' 3 "{ 0 ; 1 ; 2 ; 3 }"
assert_storage $contract_dir /build_list.tz '{}' 10 \
2018-02-02 18:13:38 +01:00
"{ 0 ; 1 ; 2 ; 3 ; 4 ; 5 ; 6 ; 7 ; 8 ; 9 ; 10 }"
# Concatenate all strings of a list into one string
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /concat_list.tz '""' '{ "a" ; "b" ; "c" }' '"abc"'
assert_storage $contract_dir /concat_list.tz '""' '{}' '""'
assert_storage $contract_dir /concat_list.tz \
'""' '{ "Hello" ; " " ; "World" ; "!" }' '"Hello World!"'
2018-02-02 18:13:38 +01:00
# Find maximum int in list -- returns None if not found
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /max_in_list.tz None '{}' 'None'
assert_storage $contract_dir /max_in_list.tz None '{ 1 }' '(Some 1)'
assert_storage $contract_dir /max_in_list.tz None '{ -1 }' '(Some -1)'
assert_storage $contract_dir /max_in_list.tz None \
2018-02-02 18:13:38 +01:00
'{ 10 ; -1 ; -20 ; 100 ; 0 }' '(Some 100)'
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /max_in_list.tz None \
2018-02-02 18:13:38 +01:00
'{ 10 ; -1 ; -20 ; 100 ; 0 }' '(Some 100)'
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /max_in_list.tz None \
2018-02-02 18:13:38 +01:00
'{ -10 ; -1 ; -20 ; -100 }' '(Some -1)'
# Identity on lists
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /list_id.tz '{""}' '{ "1" ; "2" ; "3" }' '{ "1" ; "2" ; "3" }'
assert_storage $contract_dir /list_id.tz '{""}' '{}' '{}'
assert_storage $contract_dir /list_id.tz '{""}' '{ "a" ; "b" ; "c" }' '{ "a" ; "b" ; "c" }'
2018-02-02 18:13:38 +01:00
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /list_id_map.tz '{""}' '{ "1" ; "2" ; "3" }' '{ "1" ; "2" ; "3" }'
assert_storage $contract_dir /list_id_map.tz '{""}' '{}' '{}'
assert_storage $contract_dir /list_id_map.tz '{""}' '{ "a" ; "b" ; "c" }' '{ "a" ; "b" ; "c" }'
2018-02-02 18:13:38 +01:00
# Identity on maps
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /map_id.tz '{}' '{ Elt 0 1 }' '{ Elt 0 1 }'
assert_storage $contract_dir /map_id.tz '{}' '{ Elt 0 0 }' '{ Elt 0 0 }'
assert_storage $contract_dir /map_id.tz '{}' '{ Elt 0 0 ; Elt 3 4 }' '{ Elt 0 0 ; Elt 3 4 }'
2018-02-02 18:13:38 +01:00
# Map block on lists
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /list_map_block.tz '{0}' '{}' '{}'
assert_storage $contract_dir /list_map_block.tz '{0}' '{ 1 ; 1 ; 1 ; 1 }' '{ 1 ; 2 ; 3 ; 4 }'
assert_storage $contract_dir /list_map_block.tz '{0}' '{ 1 ; 2 ; 3 ; 0 }' '{ 1 ; 3 ; 5 ; 3 }'
2018-02-02 18:13:38 +01:00
# List iter
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /list_iter.tz 0 '{ 10 ; 2 ; 1 }' 20
assert_storage $contract_dir /list_iter.tz 0 '{ 3 ; 6 ; 9 }' 162
2018-02-02 18:13:38 +01:00
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /list_iter2.tz '"?"' '{ "a" ; "b" ; "c" }' '"cba"'
assert_storage $contract_dir /list_iter2.tz '"?"' '{}' '""'
2018-02-02 18:13:38 +01:00
# Identity on sets
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /set_id.tz '{}' '{ "a" ; "b" ; "c" }' '{ "a" ; "b" ; "c" }'
assert_storage $contract_dir /set_id.tz '{}' '{}' '{}'
assert_storage $contract_dir /set_id.tz '{}' '{ "asdf" ; "bcde" }' '{ "asdf" ; "bcde" }'
2018-02-02 18:13:38 +01:00
# Set member -- set is in storage
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /set_member.tz '(Pair {} None)' '"Hi"' '(Pair {} (Some False))'
assert_storage $contract_dir /set_member.tz '(Pair { "Hi" } None)' '"Hi"' '(Pair { "Hi" } (Some True))'
assert_storage $contract_dir /set_member.tz '(Pair { "Hello" ; "World" } None)' '""' '(Pair { "Hello" ; "World" } (Some False))'
2018-02-02 18:13:38 +01:00
# Set size
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /set_size.tz 111 '{}' 0
assert_storage $contract_dir /set_size.tz 111 '{ 1 }' 1
assert_storage $contract_dir /set_size.tz 111 '{ 1 ; 2 ; 3 }' 3
assert_storage $contract_dir /set_size.tz 111 '{ 1 ; 2 ; 3 ; 4 ; 5 ; 6 }' 6
2018-02-02 18:13:38 +01:00
# Set iter
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /set_iter.tz 111 '{}' 0
assert_storage $contract_dir /set_iter.tz 111 '{ 1 }' 1
assert_storage $contract_dir /set_iter.tz 111 '{ -100 ; 1 ; 2 ; 3 }' '-94'
2018-02-02 18:13:38 +01:00
# Map size
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /map_size.tz 111 '{}' 0
assert_storage $contract_dir /map_size.tz 111 '{ Elt "a" 1 }' 1
assert_storage $contract_dir /map_size.tz 111 \
2018-02-02 18:13:38 +01:00
'{ Elt "a" 1 ; Elt "b" 2 ; Elt "c" 3 }' 3
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /map_size.tz 111 \
2018-02-02 18:13:38 +01:00
'{ 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
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /contains_all.tz \
None '(Pair {} {})' '(Some True)'
assert_storage $contract_dir /contains_all.tz \
None '(Pair { "a" } { "B" })' '(Some False)'
assert_storage $contract_dir /contains_all.tz \
None '(Pair { "A" } { "B" })' '(Some False)'
assert_storage $contract_dir /contains_all.tz \
None '(Pair { "B" } { "B" })' '(Some True)'
assert_storage $contract_dir /contains_all.tz None \
'(Pair { "B" ; "C" ; "asdf" } { "B" ; "B" ; "asdf" ; "C" })' '(Some True)'
assert_storage $contract_dir /contains_all.tz None \
'(Pair { "B" ; "B" ; "asdf" ; "C" } { "B" ; "C" ; "asdf" })' '(Some True)'
2018-02-02 18:13:38 +01:00
# Concatenate the string in storage with all strings in the given list
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /concat_hello.tz '{}' \
2018-02-02 18:13:38 +01:00
'{ "World!" }' '{ "Hello World!" }'
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /concat_hello.tz '{}' \
2018-02-02 18:13:38 +01:00
'{}' '{}'
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /concat_hello.tz '{}' \
2018-02-02 18:13:38 +01:00
'{ "test1" ; "test2" }' '{ "Hello test1" ; "Hello test2" }'
# Create an empty map and add a string to it
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /empty_map.tz '{}' Unit \
2018-02-02 18:13:38 +01:00
'{ Elt "hello" "world" }'
# Get the value stored at the given key in the map
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /get_map_value.tz '(Pair None { Elt "hello" "hi" })' \
'"hello"' '(Pair (Some "hi") { Elt "hello" "hi" })'
assert_storage $contract_dir /get_map_value.tz '(Pair None { Elt "hello" "hi" })' \
'""' '(Pair None { Elt "hello" "hi" })'
assert_storage $contract_dir /get_map_value.tz \
'(Pair None { Elt "1" "one" ; Elt "2" "two" })' \
'"1"' '(Pair (Some "one") { Elt "1" "one" ; Elt "2" "two" })'
2018-02-02 18:13:38 +01:00
# Map iter
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /map_iter.tz '(Pair 0 0)' '{ Elt 0 100 ; Elt 2 100 }' '(Pair 2 200)'
assert_storage $contract_dir /map_iter.tz '(Pair 0 0)' '{ Elt 1 1 ; Elt 2 100 }' '(Pair 3 101)'
2018-02-02 18:13:38 +01:00
# Return True if True branch of if was taken and False otherwise
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /if.tz None True '(Some True)'
assert_storage $contract_dir /if.tz None False '(Some False)'
2018-02-02 18:13:38 +01:00
# Generate a pair of or types
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /swap_left_right.tz '(Left "X")' '(Left True)' '(Right True)'
assert_storage $contract_dir /swap_left_right.tz '(Left "X")' '(Right "a")' '(Left "a")'
2018-02-02 18:13:38 +01:00
# Reverse a list
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /reverse.tz '{""}' '{}' '{}'
assert_storage $contract_dir /reverse.tz '{""}' '{ "c" ; "b" ; "a" }' '{ "a" ; "b" ; "c" }'
assert_storage $contract_dir /reverse_loop.tz '{""}' '{}' '{}'
assert_storage $contract_dir /reverse_loop.tz '{""}' '{ "c" ; "b" ; "a" }' '{ "a" ; "b" ; "c" }'
2018-02-02 18:13:38 +01:00
# Reverse using LOOP_LEFT
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /loop_left.tz '{""}' '{}' '{}'
assert_storage $contract_dir /loop_left.tz '{""}' '{ "c" ; "b" ; "a" }' '{ "a" ; "b" ; "c" }'
2018-02-02 18:13:38 +01:00
# Exec concat contract
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /exec_concat.tz '"?"' '""' '"_abc"'
assert_storage $contract_dir /exec_concat.tz '"?"' '"test"' '"test_abc"'
2018-02-02 18:13:38 +01:00
# Get current steps to quota
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /steps_to_quota.tz 111 Unit 399992
2018-02-02 18:13:38 +01:00
# Get the current balance of the contract
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /balance.tz '"111"' Unit '"4,000,000"'
2018-02-02 18:13:38 +01:00
# Test comparisons on tez { EQ ; GT ; LT ; GE ; LE }
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /compare.tz '{}' '(Pair "1.00" "2.00")' '{ False ; False ; True ; False ; True }'
assert_storage $contract_dir /compare.tz '{}' '(Pair "2.00" "1.00")' '{ False ; True ; False ; True ; False }'
assert_storage $contract_dir /compare.tz '{}' '(Pair "2.37" "2.37")' '{ True ; False ; False ; True ; True }'
2018-02-02 18:13:38 +01:00
# Test addition and subtraction on tez
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /tez_add_sub.tz None '(Pair "2" "1")' '(Some (Pair "3" "1"))'
assert_storage $contract_dir /tez_add_sub.tz None '(Pair "2.31" "1.01")' '(Some (Pair "3.32" "1.3"))'
2018-02-02 18:13:38 +01:00
# Test get first element of list
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /first.tz '111' '{ 1 ; 2 ; 3 ; 4 }' '1'
assert_storage $contract_dir /first.tz '111' '{ 4 }' '4'
2018-02-02 18:13:38 +01:00
# Hash input string
# Test assumed to be correct -- hash is based on encoding of AST
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /hash_string.tz '"?"' '"abcdefg"' '"exprv3MnhXvjthGzZ7jDtXRRFremZyey9rsGtL7JRkeaQX1fThN7WF"'
assert_storage $contract_dir /hash_string.tz '"?"' '"12345"' '"expru81QVHsW2qaWLNHnMHSxDNhqtat17ajadri6mKUvXyc2EWHZC3"'
2018-02-02 18:13:38 +01:00
# Test ASSERT
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /assert.tz Unit True Unit
assert_fails $client run program $contract_dir /assert.tz on storage Unit and input False
2018-02-02 18:13:38 +01:00
# COMPARE; ASSERT_
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /assert_eq.tz Unit '(Pair -1 -1)' Unit
assert_fails $client run program $contract_dir /assert_eq.tz on storage Unit and input '(Pair 0 -1)'
2018-02-02 18:13:38 +01:00
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /assert_eq.tz Unit '(Pair -1 -1)' Unit
assert_fails $client run program $contract_dir /assert_eq.tz on storage Unit and input '(Pair 0 -1)'
2018-02-02 18:13:38 +01:00
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /assert_neq.tz Unit '(Pair 0 -1)' Unit
assert_fails $client run program $contract_dir /assert_neq.tz on storage Unit and input '(Pair -1 -1)'
2018-02-02 18:13:38 +01:00
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /assert_lt.tz Unit '(Pair -1 0)' Unit
assert_fails $client run program $contract_dir /assert_lt.tz on storage Unit and input '(Pair 0 -1)'
assert_fails $client run program $contract_dir /assert_lt.tz on storage Unit and input '(Pair 0 0)'
2018-02-02 18:13:38 +01:00
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /assert_le.tz Unit '(Pair 0 0)' Unit
assert_storage $contract_dir /assert_le.tz Unit '(Pair -1 0)' Unit
assert_fails $client run program $contract_dir /assert_le.tz on storage Unit and input '(Pair 0 -1)'
2018-02-02 18:13:38 +01:00
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /assert_gt.tz Unit '(Pair 0 -1)' Unit
assert_fails $client run program $contract_dir /assert_gt.tz on storage Unit and input '(Pair -1 0)'
assert_fails $client run program $contract_dir /assert_gt.tz on storage Unit and input '(Pair 0 0)'
2018-02-02 18:13:38 +01:00
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /assert_ge.tz Unit '(Pair 0 0)' Unit
assert_storage $contract_dir /assert_ge.tz Unit '(Pair 0 -1)' Unit
assert_fails $client run program $contract_dir /assert_ge.tz on storage Unit and input '(Pair -1 0)'
2018-02-02 18:13:38 +01:00
# ASSERT_CMP
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /assert_cmpeq.tz Unit '(Pair -1 -1)' Unit
assert_fails $client run program $contract_dir /assert_cmpeq.tz on storage Unit and input '(Pair 0 -1)'
2018-02-02 18:13:38 +01:00
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /assert_cmpeq.tz Unit '(Pair -1 -1)' Unit
assert_fails $client run program $contract_dir /assert_cmpeq.tz on storage Unit and input '(Pair 0 -1)'
2018-02-02 18:13:38 +01:00
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /assert_cmpneq.tz Unit '(Pair 0 -1)' Unit
assert_fails $client run program $contract_dir /assert_cmpneq.tz on storage Unit and input '(Pair -1 -1)'
2018-02-02 18:13:38 +01:00
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /assert_cmplt.tz Unit '(Pair -1 0)' Unit
assert_fails $client run program $contract_dir /assert_cmplt.tz on storage Unit and input '(Pair 0 -1)'
assert_fails $client run program $contract_dir /assert_cmplt.tz on storage Unit and input '(Pair 0 0)'
2018-02-02 18:13:38 +01:00
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /assert_cmple.tz Unit '(Pair 0 0)' Unit
assert_storage $contract_dir /assert_cmple.tz Unit '(Pair -1 0)' Unit
assert_fails $client run program $contract_dir /assert_cmple.tz on storage Unit and input '(Pair 0 -1)'
2018-02-02 18:13:38 +01:00
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /assert_cmpgt.tz Unit '(Pair 0 -1)' Unit
assert_fails $client run program $contract_dir /assert_cmpgt.tz on storage Unit and input '(Pair -1 0)'
assert_fails $client run program $contract_dir /assert_cmpgt.tz on storage Unit and input '(Pair 0 0)'
2018-02-02 18:13:38 +01:00
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /assert_cmpge.tz Unit '(Pair 0 0)' Unit
assert_storage $contract_dir /assert_cmpge.tz Unit '(Pair 0 -1)' Unit
assert_fails $client run program $contract_dir /assert_cmpge.tz on storage Unit and input '(Pair -1 0)'
2018-02-02 18:13:38 +01:00
# IF_SOME
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /if_some.tz '"?"' '(Some "hello")' '"hello"'
assert_storage $contract_dir /if_some.tz '"?"' 'None' '""'
2018-02-02 18:13:38 +01:00
# Tests the SET_CAR and SET_CDR instructions
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /set_car.tz '(Pair "hello" 0)' '"world"' '(Pair "world" 0)'
assert_storage $contract_dir /set_car.tz '(Pair "hello" 0)' '"abc"' '(Pair "abc" 0)'
assert_storage $contract_dir /set_car.tz '(Pair "hello" 0)' '""' '(Pair "" 0)'
2018-02-02 18:13:38 +01:00
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /set_cdr.tz '(Pair "hello" 0)' '1' '(Pair "hello" 1)'
assert_storage $contract_dir /set_cdr.tz '(Pair "hello" 500)' '3' '(Pair "hello" 3)'
assert_storage $contract_dir /set_cdr.tz '(Pair "hello" 7)' '100' '(Pair "hello" 100)'
2018-02-02 18:13:38 +01:00
assert_storage $contract_dir /set_caddaadr.tz \
'(Pair (Pair 1 (Pair 2 (Pair (Pair (Pair 3 "0") 4) 5))) 6)' \
'"3"' \
'(Pair (Pair 1 (Pair 2 (Pair (Pair (Pair 3 "3") 4) 5))) 6)'
assert_storage $contract_dir /map_caddaadr.tz \
'(Pair (Pair 1 (Pair 2 (Pair (Pair (Pair 3 "0") 4) 5))) 6)' \
'Unit' \
'(Pair (Pair 1 (Pair 2 (Pair (Pair (Pair 3 "1") 4) 5))) 6)'
# Did the given key sign the string? (key is bootstrap1)
2018-04-05 17:17:27 +02:00
assert_success $client run program $contract_dir /check_signature.tz \
on storage '(Pair "1f19f8f37e80d96797b019f30d23ede6a26a0f698220f942103a3401f047623746e51a9c6e77e269b5df9593994ab96b001aae0f73728a2259187cb640b61e01" "hello")' \
and input '"edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav"'
assert_fails $client run program $contract_dir /check_signature.tz \
on storage '(Pair "1f19f8f37e80d96797b019f30d23ede6a26a0f698220f942103a3401f047623746e51a9c6e77e269b5df9593994ab96b001aae0f73728a2259187cb640b61e01" "abcd")' \
and input '"edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav"'
2018-02-02 18:13:38 +01:00
# Convert a public key to a public key hash
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /hash_key.tz None '"edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav"' \
'(Some "tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx")'
assert_storage $contract_dir /hash_key.tz None '"edpkuJqtDcA2m2muMxViSM47MPsGQzmyjnNTawUPqR8vZTAMcx61ES"' \
'(Some "tz1XPTDmvT3vVE5Uunngmixm7gj7zmdbPq6k")'
2018-02-02 18:13:38 +01:00
2018-03-14 17:16:18 +01:00
bake_after $client transfer 1,000 from bootstrap1 to $key1
bake_after $client transfer 2,000 from bootstrap1 to $key2
2018-02-02 18:13:38 +01:00
assert_balance $key1 "1,000 ꜩ"
assert_balance $key2 "2,000 ꜩ"
# Create a contract and transfer 100 ꜩ to it
init_with_transfer $contract_dir /store_input.tz $key1 '""' 100 bootstrap1
2018-03-14 17:16:18 +01:00
bake_after $client transfer 100 from bootstrap1 to store_input -arg '"abcdefg"'
2018-02-02 18:13:38 +01:00
assert_balance store_input "200 ꜩ"
assert_storage_contains store_input '"abcdefg"'
2018-03-14 17:16:18 +01:00
bake_after $client transfer 100 from bootstrap1 to store_input -arg '"xyz"'
2018-02-02 18:13:38 +01:00
assert_storage_contains store_input '"xyz"'
init_with_transfer $contract_dir /transfer_amount.tz $key1 '"0"' "100" bootstrap1
2018-03-14 17:16:18 +01:00
bake_after $client transfer 500 from bootstrap1 to transfer_amount -arg Unit
2018-02-02 18:13:38 +01:00
assert_storage_contains transfer_amount 500
# This tests the `NOW` instruction.
# This test may fail if timings are marginal, though I have not yet seen this happen
init_with_transfer $contract_dir /store_now.tz $key1 '"2017-07-13T09:19:01Z"' "100" bootstrap1
2018-03-14 17:16:18 +01:00
bake_after $client transfer 500 from bootstrap1 to store_now -arg Unit
2018-02-02 18:13:38 +01:00
assert_storage_contains store_now " $( $client get timestamp) "
# Test timestamp operations
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /add_timestamp_delta.tz None '(Pair 100 100)' '(Some "1970-01-01T00:03:20Z")'
assert_storage $contract_dir /add_timestamp_delta.tz None '(Pair 100 -100)' '(Some "1970-01-01T00:00:00Z")'
assert_storage $contract_dir /add_timestamp_delta.tz None '(Pair "1970-01-01T00:00:00Z" 0)' '(Some "1970-01-01T00:00:00Z")'
2018-02-02 18:13:38 +01:00
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /add_delta_timestamp.tz None '(Pair 100 100)' '(Some "1970-01-01T00:03:20Z")'
assert_storage $contract_dir /add_delta_timestamp.tz None '(Pair -100 100)' '(Some "1970-01-01T00:00:00Z")'
assert_storage $contract_dir /add_delta_timestamp.tz None '(Pair 0 "1970-01-01T00:00:00Z")' '(Some "1970-01-01T00:00:00Z")'
2018-02-02 18:13:38 +01:00
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /sub_timestamp_delta.tz 111 '(Pair 100 100)' '"1970-01-01T00:00:00Z"'
assert_storage $contract_dir /sub_timestamp_delta.tz 111 '(Pair 100 -100)' '"1970-01-01T00:03:20Z"'
assert_storage $contract_dir /sub_timestamp_delta.tz 111 '(Pair 100 2000000000000000000)' -1999999999999999900
2018-02-02 18:13:38 +01:00
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /diff_timestamps.tz 111 '(Pair 0 0)' 0
assert_storage $contract_dir /diff_timestamps.tz 111 '(Pair 0 1)' -1
assert_storage $contract_dir /diff_timestamps.tz 111 '(Pair 1 0)' 1
assert_storage $contract_dir /diff_timestamps.tz 111 '(Pair "1970-01-01T00:03:20Z" "1970-01-01T00:00:00Z")' 200
2018-02-02 18:13:38 +01:00
2018-03-14 17:16:18 +01:00
2018-02-02 18:13:38 +01:00
# Tests TRANSFER_TO
2018-03-14 17:16:18 +01:00
bake_after $client originate account "test_transfer_account1" for $key1 transferring 100 from bootstrap1
bake_after $client originate account "test_transfer_account2" for $key1 transferring 20 from bootstrap1
2018-02-02 18:13:38 +01:00
init_with_transfer $contract_dir /transfer_to.tz $key2 Unit 1,000 bootstrap1
assert_balance test_transfer_account1 "100 ꜩ"
2018-03-14 17:16:18 +01:00
bake_after $client transfer 100 from bootstrap1 to transfer_to \
-arg " \" $( get_contract_addr test_transfer_account1) \" "
2018-02-02 18:13:38 +01:00
assert_balance test_transfer_account1 "200 ꜩ" # Why isn't this 200 ꜩ? Baking fee?
2018-03-14 17:16:18 +01:00
bake_after $client transfer 100 from bootstrap1 to transfer_to \
2018-02-02 18:13:38 +01:00
-arg " \" $( get_contract_addr test_transfer_account2) \" "
assert_balance test_transfer_account2 "120 ꜩ" # Why isn't this 120 ꜩ? Baking fee?
2018-03-14 17:16:18 +01:00
2018-02-02 18:13:38 +01:00
# Tests create_account
init_with_transfer $contract_dir /create_account.tz $key2 \
" \" $( get_contract_addr test_transfer_account1) \" " 1,000 bootstrap1
$client transfer 100 from bootstrap1 to create_account \
2018-03-14 17:16:18 +01:00
-arg '"tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"' | assert_in_output "New contract"
2018-04-21 17:16:01 +02:00
bake
2018-02-02 18:13:38 +01:00
# Creates a contract, transfers data to it and stores the data
init_with_transfer $contract_dir /create_contract.tz $key2 \
" \" $( get_contract_addr test_transfer_account1) \" " 1,000 bootstrap1
2018-04-05 17:17:27 +02:00
created_contract = \
` $client transfer 0 from bootstrap1 to create_contract -arg '"tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"' \
| grep 'New contract' \
| sed -E 's/.*(TZ1[a-zA-Z0-9]+).*/\1/' \
| head -1`
bake
assert_storage_contains $created_contract '"abcdefg"'
2018-02-02 18:13:38 +01:00
2018-04-04 10:13:59 +02:00
# Test IMPLICIT_ACCOUNT
2018-02-02 18:13:38 +01:00
init_with_transfer $contract_dir /default_account.tz $key1 \
Unit 1,000 bootstrap1
2018-03-14 17:16:18 +01:00
bake_after $client transfer 0 from bootstrap1 to default_account -arg " \" $BOOTSTRAP4_IDENTITY \" "
2018-02-02 18:13:38 +01:00
assert_balance $BOOTSTRAP4_IDENTITY "4,000,100 ꜩ"
account = tz1SuakBpFdG9b4twyfrSMqZzruxhpMeSrE5
2018-03-14 17:16:18 +01:00
bake_after $client transfer 0 from bootstrap1 to default_account -arg " \" $account \" "
2018-02-02 18:13:38 +01:00
assert_balance $account "100 ꜩ"
# Test SELF
init_with_transfer $contract_dir /self.tz $key1 \
'"tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"' 1,000 bootstrap1
2018-03-14 17:16:18 +01:00
bake_after $client transfer 0 from bootstrap1 to self
2018-02-02 18:13:38 +01:00
assert_storage_contains self " \" $( get_contract_addr self) \" "
2017-12-14 16:45:04 +01:00
# Test sets and map literals
2018-02-02 18:13:38 +01:00
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)'
2017-12-14 16:45:04 +01:00
# Test hash consistency between Michelson and the CLI
2018-02-02 18:13:38 +01:00
hash_result = ` $client hash data '(Pair "22220.00" (Pair "2017-12-13T04:49:00Z" 034))' \
2018-02-09 22:28:32 -05:00
of type '(pair tez (pair timestamp int))' | grep expr`
2018-02-02 18:13:38 +01:00
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /hash_consistency_checker.tz '"?"' \
2018-02-02 18:13:38 +01:00
'(Pair "22220.00" (Pair "2017-12-13T04:49:00Z" 034))' " $hash_result "
2018-04-05 17:17:27 +02:00
assert_storage $contract_dir /hash_consistency_checker.tz '"?"' \
2018-02-02 18:13:38 +01:00
'(Pair "22,220" (Pair "2017-12-13T04:49:00+00:00" 34))' " $hash_result "
2017-12-14 16:45:04 +01:00
# Test for big maps
init_with_transfer $contract_dir /big_map_mem.tz $key1 \
'(Pair { Elt 1 Unit ; Elt 2 Unit ; Elt 3 Unit } Unit)' \
100 bootstrap1
2018-04-21 17:16:01 +02:00
bake_after $client transfer 1 from bootstrap1 to big_map_mem -arg '(Pair 0 False)'
2017-12-14 16:45:04 +01:00
assert_fails $client transfer 1 from bootstrap1 to big_map_mem -arg '(Pair 0 True)'
2018-04-21 17:16:01 +02:00
bake_after $client transfer 1 from bootstrap1 to big_map_mem -arg '(Pair 1 True)'
2017-12-14 16:45:04 +01:00
assert_fails $client transfer 1 from bootstrap1 to big_map_mem -arg '(Pair 1 False)'
2018-04-21 17:16:01 +02:00
bake_after $client transfer 1 from bootstrap1 to big_map_mem -arg '(Pair 2 True)'
2017-12-14 16:45:04 +01:00
assert_fails $client transfer 1 from bootstrap1 to big_map_mem -arg '(Pair 2 False)'
2018-04-21 17:16:01 +02:00
bake_after $client transfer 1 from bootstrap1 to big_map_mem -arg '(Pair 3 True)'
2017-12-14 16:45:04 +01:00
assert_fails $client transfer 1 from bootstrap1 to big_map_mem -arg '(Pair 3 False)'
2018-04-21 17:16:01 +02:00
bake_after $client transfer 1 from bootstrap1 to big_map_mem -arg '(Pair 4 False)'
2017-12-14 16:45:04 +01:00
assert_fails $client transfer 1 from bootstrap1 to big_map_mem -arg '(Pair 4 True)'
2018-03-30 22:58:11 -04:00
assert_fails $client typecheck data '3' against type \
'(int @aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)'
$client typecheck data '3' against type \
'(int @aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)'
2017-12-14 16:45:04 +01:00
init_with_transfer $contract_dir /big_map_get_add.tz $key1 \
'(Pair { Elt 0 1 ; Elt 1 2 ; Elt 2 3 } Unit)' \
100 bootstrap1
2018-04-21 17:16:01 +02:00
bake_after $client transfer 1 from bootstrap1 to big_map_get_add -arg '(Pair (Pair 200 (Some 2)) (Pair 200 (Some 2)))'
bake_after $client transfer 1 from bootstrap1 to big_map_get_add -arg '(Pair (Pair 200 None) (Pair 200 None))'
bake_after $client transfer 1 from bootstrap1 to big_map_get_add -arg '(Pair (Pair 200 None) (Pair 300 None))'
bake_after $client transfer 1 from bootstrap1 to big_map_get_add -arg '(Pair (Pair 1 None) (Pair 200 None))'
bake_after $client transfer 1 from bootstrap1 to big_map_get_add -arg '(Pair (Pair 1 (Some 2)) (Pair 0 (Some 1)))'
bake_after $client transfer 1 from bootstrap1 to big_map_get_add -arg '(Pair (Pair 400 (Some 1232)) (Pair 400 (Some 1232)))'
bake_after $client transfer 1 from bootstrap1 to big_map_get_add -arg '(Pair (Pair 401 (Some 0)) (Pair 400 (Some 1232)))'
2017-12-14 16:45:04 +01:00
2018-02-02 18:13:38 +01:00
printf "\nEnd of test\n"
show_logs = "no"