Michelson: improvements to bash test procedures
This commit is contained in:
parent
84376e09a4
commit
a2d54d2d1c
@ -1,6 +1,4 @@
|
|||||||
parameter unit;
|
parameter unit;
|
||||||
storage (pair (pair nat (pair nat (pair (pair (pair nat tez) nat) nat))) nat);
|
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);
|
return unit;
|
||||||
code { CDR ;
|
code { MAP_CDADDAADR { PUSH tez "1.00" ; ADD } };
|
||||||
MAP_CADDAADR { PUSH tez "1.00" ; ADD } ;
|
|
||||||
DUP ; PAIR };
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
parameter unit;
|
parameter tez;
|
||||||
storage (pair (pair nat (pair nat (pair (pair (pair nat tez) nat) nat))) nat);
|
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);
|
return unit;
|
||||||
code { CDR ; DUP ;
|
code { DUP ; CAR ; SWAP ; CDR ;
|
||||||
DIP { CADDAADR ; PUSH tez "1.00" ; ADD } ;
|
|
||||||
SET_CADDAADR ;
|
SET_CADDAADR ;
|
||||||
DUP ; PAIR };
|
UNIT ; PAIR };
|
||||||
|
@ -64,10 +64,14 @@ trap cleanup EXIT INT
|
|||||||
### Various helpers
|
### Various helpers
|
||||||
|
|
||||||
run_contract_file () {
|
run_contract_file () {
|
||||||
local contract=$1
|
local contract="$1"
|
||||||
local storage=$2
|
local storage="$2"
|
||||||
local input=$3
|
local input="$3"
|
||||||
$client run program "$contract" on storage "$storage" and input "$input"
|
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 () {
|
assert_output () {
|
||||||
@ -75,8 +79,9 @@ assert_output () {
|
|||||||
local input=$2;
|
local input=$2;
|
||||||
local storage=$3;
|
local storage=$3;
|
||||||
local expected=$4;
|
local expected=$4;
|
||||||
|
local amount=$5;
|
||||||
echo "Testing [$contract]"
|
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:]]*$//' ||
|
sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' ||
|
||||||
{ printf '\nTest failed with error at line %s\n' "$(caller)" 1>&2;
|
{ printf '\nTest failed with error at line %s\n' "$(caller)" 1>&2;
|
||||||
exit 1; });
|
exit 1; });
|
||||||
@ -87,6 +92,24 @@ assert_output () {
|
|||||||
fi
|
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 () {
|
assert_balance () {
|
||||||
local KEY="$1"
|
local KEY="$1"
|
||||||
local EXPECTED_BALANCE="$2"
|
local EXPECTED_BALANCE="$2"
|
||||||
@ -172,6 +195,18 @@ assert_fails() {
|
|||||||
fi
|
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() {
|
extract_operation_hash() {
|
||||||
grep "Operation hash is" | grep -o "'.*'" | tr -d "'"
|
grep "Operation hash is" | grep -o "'.*'" | tr -d "'"
|
||||||
}
|
}
|
||||||
|
@ -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" 500)' '3' '(Pair "hello" 3)'
|
||||||
assert_output $CONTRACT_PATH/set_cdr.tz '(Pair "hello" 7)' '100' '(Pair "hello" 100)'
|
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)' \
|
'(Pair (Pair 1 (Pair 2 (Pair (Pair (Pair 3 "0.00") 4) 5))) 6)' \
|
||||||
'Unit' \
|
'"3.00"' \
|
||||||
'(Pair (Pair 1 (Pair 2 (Pair (Pair (Pair 3 "1.00") 4) 5))) 6)'
|
'(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)' \
|
'(Pair (Pair 1 (Pair 2 (Pair (Pair (Pair 3 "0.00") 4) 5))) 6)' \
|
||||||
'Unit' \
|
'Unit' \
|
||||||
'(Pair (Pair 1 (Pair 2 (Pair (Pair (Pair 3 "1.00") 4) 5))) 6)'
|
'(Pair (Pair 1 (Pair 2 (Pair (Pair (Pair 3 "1.00") 4) 5))) 6)'
|
||||||
|
Loading…
Reference in New Issue
Block a user