Michelson: improvements to bash test procedures

This commit is contained in:
Milo Davis 2017-09-15 13:40:50 +02:00 committed by Benjamin Canou
parent 84376e09a4
commit a2d54d2d1c
4 changed files with 50 additions and 18 deletions

View File

@ -1,6 +1,4 @@
parameter unit;
storage (pair (pair nat (pair nat (pair (pair (pair nat tez) nat) nat))) nat);
return (pair (pair nat (pair nat (pair (pair (pair nat tez) nat) nat))) nat);
code { CDR ;
MAP_CADDAADR { PUSH tez "1.00" ; ADD } ;
DUP ; PAIR };
return unit;
code { MAP_CDADDAADR { PUSH tez "1.00" ; ADD } };

View File

@ -1,7 +1,6 @@
parameter unit;
parameter tez;
storage (pair (pair nat (pair nat (pair (pair (pair nat tez) nat) nat))) nat);
return (pair (pair nat (pair nat (pair (pair (pair nat tez) nat) nat))) nat);
code { CDR ; DUP ;
DIP { CADDAADR ; PUSH tez "1.00" ; ADD } ;
return unit;
code { DUP ; CAR ; SWAP ; CDR ;
SET_CADDAADR ;
DUP ; PAIR };
UNIT ; PAIR };

View File

@ -64,10 +64,14 @@ trap cleanup EXIT INT
### Various helpers
run_contract_file () {
local contract=$1
local storage=$2
local input=$3
$client run program "$contract" on storage "$storage" and input "$input"
local contract="$1"
local storage="$2"
local input="$3"
local amount_flag=""
if [ ! -z "$4" ]; then
amount_flag="-amount $4"
fi
$client run program "$contract" on storage "$storage" and input "$input" $amount_flag
}
assert_output () {
@ -75,8 +79,9 @@ assert_output () {
local input=$2;
local storage=$3;
local expected=$4;
local amount=$5;
echo "Testing [$contract]"
local output=$(run_contract_file "$contract" "$input" "$storage" | sed '1,/output/d' |
local output=$(run_contract_file "$contract" "$input" "$storage" "$amount" | sed '1,/output/d' |
sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' ||
{ printf '\nTest failed with error at line %s\n' "$(caller)" 1>&2;
exit 1; });
@ -87,6 +92,24 @@ assert_output () {
fi
}
assert_storage () {
local contract=$1;
local input=$2;
local storage=$3;
local expected=$4;
local amount=$5;
echo "Testing [$contract]"
local storage=$(run_contract_file "$contract" "$input" "$storage" "$amount" | awk '/storage/{getline; print}' |
sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' ||
{ printf '\nTest failed with error at line %s\n' "$(caller)" 1>&2;
exit 1; });
if [ "$expected" != "$storage" ]; then
echo "Test at " `caller` failed 1>&2 ;
printf "Expected %s but got %s" "$expected" "$storage" 1>&2 ;
exit 1;
fi
}
assert_balance () {
local KEY="$1"
local EXPECTED_BALANCE="$2"
@ -172,6 +195,18 @@ assert_fails() {
fi
}
assert_contract_fails() {
local contract=$1;
local input=$2;
local storage=$3;
local amount=$4;
printf "Testing failure for [$contract]\n"
if run_contract_file "$contract" "$input" "$storage" "$amount" 2> /dev/null ; then
printf "Expected contract execution to fail, but succeeded:\n"
exit 1
fi
}
extract_operation_hash() {
grep "Operation hash is" | grep -o "'.*'" | tr -d "'"
}

View File

@ -265,12 +265,12 @@ assert_output $CONTRACT_PATH/set_cdr.tz '(Pair "hello" 0)' '1' '(Pair "hello" 1
assert_output $CONTRACT_PATH/set_cdr.tz '(Pair "hello" 500)' '3' '(Pair "hello" 3)'
assert_output $CONTRACT_PATH/set_cdr.tz '(Pair "hello" 7)' '100' '(Pair "hello" 100)'
assert_output $CONTRACT_PATH/set_caddaadr.tz \
assert_storage $CONTRACT_PATH/set_caddaadr.tz \
'(Pair (Pair 1 (Pair 2 (Pair (Pair (Pair 3 "0.00") 4) 5))) 6)' \
'Unit' \
'(Pair (Pair 1 (Pair 2 (Pair (Pair (Pair 3 "1.00") 4) 5))) 6)'
'"3.00"' \
'(Pair (Pair 1 (Pair 2 (Pair (Pair (Pair 3 "3.00") 4) 5))) 6)'
assert_output $CONTRACT_PATH/map_caddaadr.tz \
assert_storage $CONTRACT_PATH/map_caddaadr.tz \
'(Pair (Pair 1 (Pair 2 (Pair (Pair (Pair 3 "0.00") 4) 5))) 6)' \
'Unit' \
'(Pair (Pair 1 (Pair 2 (Pair (Pair (Pair 3 "1.00") 4) 5))) 6)'