Scripts/Test: more shared scripts...
- introduced `test/utils/test_lib.inc.sh` to simplify usage of sandboxed node/client in the testsuite - it reuses code from `./script/{node,client}_lib.inc.sh` - use `wait_for_the_node_to_be_ready` to properly wait for the node to be launched rather to use a fexed delay - `test_multinode.sh` now launch 8 nodes.
This commit is contained in:
parent
e033176820
commit
d6348c009a
@ -2,6 +2,7 @@ FROM $base_image
|
|||||||
|
|
||||||
COPY src /home/opam/tezos/src
|
COPY src /home/opam/tezos/src
|
||||||
COPY test /home/opam/tezos/test
|
COPY test /home/opam/tezos/test
|
||||||
|
COPY scripts /home/opam/tezos/scripts
|
||||||
|
|
||||||
RUN sudo chown -R opam /home/opam/tezos && \
|
RUN sudo chown -R opam /home/opam/tezos && \
|
||||||
echo "PRODUCTION=yes" > /home/opam/tezos/src/Makefile.local && \
|
echo "PRODUCTION=yes" > /home/opam/tezos/src/Makefile.local && \
|
||||||
|
@ -1,8 +1,27 @@
|
|||||||
#! /bin/sh
|
#! /usr/bin/env bash
|
||||||
|
|
||||||
client_dir="${client_dir:=$HOME/.tezos-client}"
|
client_dir="${client_dir:=$HOME/.tezos-client}"
|
||||||
client="${client:=tezos-client -base-dir $client_dir}"
|
client="${client:=tezos-client -base-dir $client_dir}"
|
||||||
|
|
||||||
|
client_dirs=()
|
||||||
|
|
||||||
|
init_sandboxed_client() {
|
||||||
|
|
||||||
|
id="$1"
|
||||||
|
shift 1
|
||||||
|
|
||||||
|
rpc=$((18730 + id))
|
||||||
|
client_dir="$(mktemp -d -t tezos-client.XXXXXXXX)"
|
||||||
|
client_dirs+=("$client_dir")
|
||||||
|
client="$src_dir/tezos-client -base-dir $client_dir -addr 127.0.0.1 -port $rpc"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup_clients() {
|
||||||
|
rm -rf "${client_dirs[@]}"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
## Waiter ##################################################################
|
## Waiter ##################################################################
|
||||||
|
|
||||||
wait_for_the_node_to_be_ready() {
|
wait_for_the_node_to_be_ready() {
|
||||||
@ -138,18 +157,23 @@ log_endorser() {
|
|||||||
|
|
||||||
# key pairs from $src_dir/test/sandbox.json
|
# key pairs from $src_dir/test/sandbox.json
|
||||||
|
|
||||||
|
BOOTSTRAP1_IDENTITY="tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"
|
||||||
BOOTSTRAP1_PUBLIC="edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav"
|
BOOTSTRAP1_PUBLIC="edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav"
|
||||||
BOOTSTRAP1_SECRET="edskRuR1azSfboG86YPTyxrQgosh5zChf5bVDmptqLTb5EuXAm9rsnDYfTKhq7rDQujdn5WWzwUMeV3agaZ6J2vPQT58jJAJPi"
|
BOOTSTRAP1_SECRET="edskRuR1azSfboG86YPTyxrQgosh5zChf5bVDmptqLTb5EuXAm9rsnDYfTKhq7rDQujdn5WWzwUMeV3agaZ6J2vPQT58jJAJPi"
|
||||||
|
|
||||||
|
BOOTSTRAP2_IDENTITY="tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN"
|
||||||
BOOTSTRAP2_PUBLIC="edpktzNbDAUjUk697W7gYg2CRuBQjyPxbEg8dLccYYwKSKvkPvjtV9"
|
BOOTSTRAP2_PUBLIC="edpktzNbDAUjUk697W7gYg2CRuBQjyPxbEg8dLccYYwKSKvkPvjtV9"
|
||||||
BOOTSTRAP2_SECRET="edskRkJz4Rw2rM5NtabEWMbbg2bF4b1nfFajaqEuEk4SgU7eeDbym9gVQtBTbYo32WUg2zb5sNBkD1whRN7zX43V9bftBbtaKc"
|
BOOTSTRAP2_SECRET="edskRkJz4Rw2rM5NtabEWMbbg2bF4b1nfFajaqEuEk4SgU7eeDbym9gVQtBTbYo32WUg2zb5sNBkD1whRN7zX43V9bftBbtaKc"
|
||||||
|
|
||||||
|
BOOTSTRAP3_IDENTITY="tz1faswCTDciRzE4oJ9jn2Vm2dvjeyA9fUzU"
|
||||||
BOOTSTRAP3_PUBLIC="edpkuTXkJDGcFd5nh6VvMz8phXxU3Bi7h6hqgywNFi1vZTfQNnS1RV"
|
BOOTSTRAP3_PUBLIC="edpkuTXkJDGcFd5nh6VvMz8phXxU3Bi7h6hqgywNFi1vZTfQNnS1RV"
|
||||||
BOOTSTRAP3_SECRET="edskS3qsqsNgdjUqeMsVcEwBn8dkZ5iDRz6aF21KhcCtRiAkWBypUSbicccR4Vgqm9UdW2Vabuos6seezqgbXTrmcbLUG4rdAC"
|
BOOTSTRAP3_SECRET="edskS3qsqsNgdjUqeMsVcEwBn8dkZ5iDRz6aF21KhcCtRiAkWBypUSbicccR4Vgqm9UdW2Vabuos6seezqgbXTrmcbLUG4rdAC"
|
||||||
|
|
||||||
|
BOOTSTRAP4_IDENTITY="tz1b7tUupMgCNw2cCLpKTkSD1NZzB5TkP2sv"
|
||||||
BOOTSTRAP4_PUBLIC="edpkuFrRoDSEbJYgxRtLx2ps82UdaYc1WwfS9sE11yhauZt5DgCHbU"
|
BOOTSTRAP4_PUBLIC="edpkuFrRoDSEbJYgxRtLx2ps82UdaYc1WwfS9sE11yhauZt5DgCHbU"
|
||||||
BOOTSTRAP4_SECRET="edskRg9qcPqaVQa6jXWNMU5p71tseSuR7NzozgqZ9URsVDi81wTyPJdFSBdeakobyHUi4Xgu61jgKRQvkhXrPmEdEUfiqfiJFL"
|
BOOTSTRAP4_SECRET="edskRg9qcPqaVQa6jXWNMU5p71tseSuR7NzozgqZ9URsVDi81wTyPJdFSBdeakobyHUi4Xgu61jgKRQvkhXrPmEdEUfiqfiJFL"
|
||||||
|
|
||||||
|
BOOTSTRAP5_IDENTITY="tz1ddb9NMYHZi5UzPdzTZMYQQZoMub195zgv"
|
||||||
BOOTSTRAP5_PUBLIC="edpkv8EUUH68jmo3f7Um5PezmfGrRF24gnfLpH3sVNwJnV5bVCxL2n"
|
BOOTSTRAP5_PUBLIC="edpkv8EUUH68jmo3f7Um5PezmfGrRF24gnfLpH3sVNwJnV5bVCxL2n"
|
||||||
BOOTSTRAP5_SECRET="edskS7rLN2Df3nbS1EYvwJbWo4umD7yPM1SUeX7gp1WhCVpMFXjcCyM58xs6xsnTsVqHQmJQ2RxoAjJGedWfvFmjQy6etA3dgZ"
|
BOOTSTRAP5_SECRET="edskS7rLN2Df3nbS1EYvwJbWo4umD7yPM1SUeX7gp1WhCVpMFXjcCyM58xs6xsnTsVqHQmJQ2RxoAjJGedWfvFmjQy6etA3dgZ"
|
||||||
|
|
||||||
@ -175,3 +199,13 @@ add_sandboxed_bootstrap_identities() {
|
|||||||
${client} add secret key dictator ${DICTATOR_SECRET}
|
${client} add secret key dictator ${DICTATOR_SECRET}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
activate_alpha() {
|
||||||
|
|
||||||
|
${client} \
|
||||||
|
-block genesis \
|
||||||
|
activate protocol ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK \
|
||||||
|
with fitness 1 \
|
||||||
|
and key dictator
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#! /bin/sh
|
#! /usr/bin/env bash
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
@ -18,15 +18,10 @@ if [ $# -lt 1 ] || [ "$1" -le 0 ] || [ 10 -le "$1" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
id="$1"
|
|
||||||
shift 1
|
|
||||||
|
|
||||||
rpc=$((18730 + id))
|
|
||||||
client_dir="$(mktemp -td tezos-client-XXXXX)"
|
|
||||||
client="./tezos-client -base-dir $client_dir -addr 127.0.0.1 -port $rpc"
|
|
||||||
|
|
||||||
. "$script_dir/client_lib.inc.sh"
|
. "$script_dir/client_lib.inc.sh"
|
||||||
|
|
||||||
|
init_sandboxed_client "$1"
|
||||||
|
|
||||||
add_sandboxed_bootstrap_identities | sed -e 's/^/## /' 1>&2
|
add_sandboxed_bootstrap_identities | sed -e 's/^/## /' 1>&2
|
||||||
|
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#! /bin/sh
|
#! /usr/bin/env bash
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
@ -6,6 +6,8 @@ script_dir="$(cd "$(dirname "$0")" && echo "$(pwd -P)/")"
|
|||||||
src_dir="$(dirname "$script_dir")"
|
src_dir="$(dirname "$script_dir")"
|
||||||
cd "$src_dir"
|
cd "$src_dir"
|
||||||
|
|
||||||
|
source $script_dir/node_lib.inc.sh
|
||||||
|
|
||||||
if [ $# -lt 1 ] || [ "$1" -le 0 ] || [ 10 -le "$1" ]; then
|
if [ $# -lt 1 ] || [ "$1" -le 0 ] || [ 10 -le "$1" ]; then
|
||||||
echo "Small script to launch local and closed test network with a maximum of 9 nodes."
|
echo "Small script to launch local and closed test network with a maximum of 9 nodes."
|
||||||
echo
|
echo
|
||||||
@ -14,29 +16,12 @@ if [ $# -lt 1 ] || [ "$1" -le 0 ] || [ 10 -le "$1" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
id="$1"
|
|
||||||
shift 1
|
|
||||||
|
|
||||||
port=$((19730 + id))
|
|
||||||
rpc=$((18730 + id))
|
|
||||||
expected_pow="${expected_pow:-0.0}"
|
|
||||||
node_dir="$(mktemp -td tezos-node-XXXXX)"
|
|
||||||
peers="--no-bootstrap-peers $(seq -f '--peer localhost:1973%.f' 1 9) --closed"
|
|
||||||
node="$src_dir/tezos-node"
|
|
||||||
sandbox_param="--sandbox=$script_dir/sandbox.json"
|
|
||||||
|
|
||||||
cleanup () {
|
cleanup () {
|
||||||
set +e
|
set +e
|
||||||
echo Cleaning up...
|
echo Cleaning up...
|
||||||
rm -rf "$node_dir"
|
cleanup_nodes
|
||||||
}
|
}
|
||||||
trap cleanup EXIT INT
|
trap cleanup EXIT INT
|
||||||
|
|
||||||
$node config init \
|
start_sandboxed_node "$@"
|
||||||
--data-dir "$node_dir" \
|
wait $node_pids
|
||||||
--net-addr ":$port" \
|
|
||||||
--rpc-addr "[::]:$rpc" \
|
|
||||||
--expected-pow "$expected_pow" \
|
|
||||||
--connections 2 $peers
|
|
||||||
$node identity generate "$expected_pow" --data-dir "$node_dir"
|
|
||||||
$node run --data-dir "$node_dir" "$sandbox_param" "$@"
|
|
||||||
|
44
scripts/node_lib.inc.sh
Normal file
44
scripts/node_lib.inc.sh
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#! /usr/bin/env bash
|
||||||
|
|
||||||
|
node_dirs=()
|
||||||
|
node_pids=()
|
||||||
|
|
||||||
|
start_sandboxed_node() {
|
||||||
|
|
||||||
|
id=$1
|
||||||
|
max_peer_id=${max_peer_id:-9}
|
||||||
|
shift 1
|
||||||
|
|
||||||
|
port=$((19730 + id))
|
||||||
|
rpc=$((18730 + id))
|
||||||
|
expected_pow="${expected_pow:-0.0}"
|
||||||
|
expected_connections="${expected_connections:-3}"
|
||||||
|
node_dir="$(mktemp -d -t tezos-node.XXXXXXXX)"
|
||||||
|
peers=("--no-bootstrap-peers")
|
||||||
|
for peer_port in $(seq 19730 $((19730 + max_peer_id))); do
|
||||||
|
peers+=("--peer")
|
||||||
|
peers+=("127.0.0.1:$peer_port")
|
||||||
|
done
|
||||||
|
peers+=("--closed")
|
||||||
|
node="$src_dir/tezos-node"
|
||||||
|
sandbox_file="${sandbox_file:-$script_dir/sandbox.json}"
|
||||||
|
sandbox_param="--sandbox=$sandbox_file"
|
||||||
|
|
||||||
|
node_dirs+=("$node_dir")
|
||||||
|
|
||||||
|
$node config init \
|
||||||
|
--data-dir "$node_dir" \
|
||||||
|
--net-addr "127.0.0.1:$port" \
|
||||||
|
--rpc-addr "127.0.0.1:$rpc" \
|
||||||
|
--expected-pow "$expected_pow" \
|
||||||
|
--connections "$expected_connections"
|
||||||
|
$node identity generate "$expected_pow" --data-dir "$node_dir"
|
||||||
|
$node run --data-dir "$node_dir" "${peers[@]}" "$sandbox_param" "$@" &
|
||||||
|
node_pids+=("$!")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup_nodes() {
|
||||||
|
[ -z "${node_pids[0]}" ] || kill "${node_pids[@]}"
|
||||||
|
rm -rf "${node_dirs[@]}"
|
||||||
|
}
|
177
test/lib/test_lib.inc.sh
Executable file
177
test/lib/test_lib.inc.sh
Executable file
@ -0,0 +1,177 @@
|
|||||||
|
#! /usr/bin/env bash
|
||||||
|
|
||||||
|
test_lib_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && echo "$(pwd -P)")"
|
||||||
|
test_dir="$(dirname "$test_lib_dir")"
|
||||||
|
src_dir="$(dirname "$test_dir")"
|
||||||
|
cd "$test_dir"
|
||||||
|
|
||||||
|
sandbox_file="$test_dir/sandbox.json"
|
||||||
|
|
||||||
|
source $src_dir/scripts/node_lib.inc.sh
|
||||||
|
source $src_dir/scripts/client_lib.inc.sh
|
||||||
|
|
||||||
|
### Log files handling
|
||||||
|
|
||||||
|
display_file() {
|
||||||
|
echo
|
||||||
|
echo "#################"
|
||||||
|
echo "### $ cat $1"
|
||||||
|
sed -e 's/^/### /' $1
|
||||||
|
echo "#################"
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
|
||||||
|
log_files=()
|
||||||
|
|
||||||
|
register_log() {
|
||||||
|
log_files+=("$1")
|
||||||
|
}
|
||||||
|
|
||||||
|
show_logs=yes
|
||||||
|
|
||||||
|
display_logs() {
|
||||||
|
if [ "$show_logs" = "yes" ]; then
|
||||||
|
for file in "${log_files[@]}"; do
|
||||||
|
display_file $file;
|
||||||
|
done
|
||||||
|
good_run=OK
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
### Node/Client instances control
|
||||||
|
|
||||||
|
client_instances=()
|
||||||
|
|
||||||
|
start_node() {
|
||||||
|
local id=${1:-1}
|
||||||
|
start_sandboxed_node $id > LOG.$id 2>&1
|
||||||
|
register_log LOG.$id
|
||||||
|
init_sandboxed_client $id
|
||||||
|
wait_for_the_node_to_be_ready
|
||||||
|
add_sandboxed_bootstrap_identities
|
||||||
|
client_instances+=("$client")
|
||||||
|
export "client$id=$client"
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
set -e
|
||||||
|
display_logs
|
||||||
|
cleanup_nodes
|
||||||
|
cleanup_clients
|
||||||
|
}
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_output () {
|
||||||
|
local contract=$1;
|
||||||
|
local input=$2;
|
||||||
|
local storage=$3;
|
||||||
|
local expected=$4;
|
||||||
|
echo "Testing [$contract]"
|
||||||
|
local output=$(run_contract_file "$contract" "$input" "$storage" | 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; });
|
||||||
|
if [ "$expected" != "$output" ]; then
|
||||||
|
echo "Test at " `caller` failed 1>&2 ;
|
||||||
|
printf "Expected %s but got %s" "$expected" "$output" 1>&2 ;
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_balance () {
|
||||||
|
local KEY="$1"
|
||||||
|
local EXPECTED_BALANCE="$2"
|
||||||
|
local RESULT=$($client get balance for ${KEY})
|
||||||
|
if [ "${RESULT}" != "${EXPECTED_BALANCE}" ]; then
|
||||||
|
printf "Balance assertion failed for ${KEY} on line '%s'. Expected %s but got %s.\n" \
|
||||||
|
"$(caller)" "${EXPECTED_BALANCE}" "${RESULT}"
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
contract_name_of_file () {
|
||||||
|
basename "$1" ".tz"
|
||||||
|
}
|
||||||
|
|
||||||
|
init_contract_from_file () {
|
||||||
|
local FILE="$1"
|
||||||
|
local NAME=$(contract_name_of_file "${FILE}")
|
||||||
|
$client remember program "${NAME}" "file:${FILE}"
|
||||||
|
}
|
||||||
|
|
||||||
|
init_with_transfer () {
|
||||||
|
local FILE="$1"
|
||||||
|
local NAME=$(contract_name_of_file "${FILE}")
|
||||||
|
local KEY="$2"
|
||||||
|
local INITIAL_STORAGE="$3"
|
||||||
|
local TRANSFER_AMT="$4"
|
||||||
|
local TRANSFER_SRC=${5-bootstrap1}
|
||||||
|
echo "Originating [$NAME]"
|
||||||
|
$client originate contract ${NAME} \
|
||||||
|
for ${KEY} transferring "${TRANSFER_AMT}" \
|
||||||
|
from ${TRANSFER_SRC} running "${FILE}" -init "${INITIAL_STORAGE}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Takes a grep regexp and fails with an error message if command does not include
|
||||||
|
# the regexp
|
||||||
|
assert_in_output () {
|
||||||
|
local MATCHING="$1"
|
||||||
|
local INPUT="$2"
|
||||||
|
if ! grep -q "${MATCHING}" ${INPUT}; then
|
||||||
|
printf "\nFailure on line %s. Expected to find %s in output." \
|
||||||
|
"$(caller)" "${MATCHING}"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "[Assertion succeeded]"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
get_contract_addr () {
|
||||||
|
local CONTRACT_NAME="$1"
|
||||||
|
$client show known contract "${CONTRACT_NAME}"
|
||||||
|
}
|
||||||
|
|
||||||
|
contract_storage () {
|
||||||
|
local CONTRACT_NAME="$1" # Can be either an alias or hash
|
||||||
|
$client get storage for ${CONTRACT_NAME}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_storage_contains () {
|
||||||
|
local CONTRACT_NAME="$1"
|
||||||
|
local EXPECTED_STORAGE="$2"
|
||||||
|
contract_storage ${CONTRACT_NAME} | assert_in_output ${EXPECTED_STORAGE}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert() {
|
||||||
|
local expected="$1"
|
||||||
|
local result="$(cat)"
|
||||||
|
if [ "${result}" != "${expected}" ]; then
|
||||||
|
echo "Unexpected result: \"${result}\""
|
||||||
|
echo "Expected: \"${expected}\""
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_fails() {
|
||||||
|
printf "[Asserting failure]\n"
|
||||||
|
if "$@" 2> /dev/null; then
|
||||||
|
printf "Expected command line to fail, but succeeded:\n"
|
||||||
|
echo "$@"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
extract_operation_hash() {
|
||||||
|
grep "Operation hash is" | grep -o "'.*'" | tr -d "'"
|
||||||
|
}
|
@ -1,57 +1,66 @@
|
|||||||
#!/bin/bash
|
#! /usr/bin/env bash
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
source test_utils.sh
|
test_dir="$(cd "$(dirname "$0")" && echo "$(pwd -P)")"
|
||||||
|
source $test_dir/lib/test_lib.inc.sh
|
||||||
|
|
||||||
start_sandboxed_node
|
start_node 1
|
||||||
sleep 3
|
|
||||||
activate_alpha
|
activate_alpha
|
||||||
|
|
||||||
add_bootstrap_identities
|
key1=foo
|
||||||
|
key2=bar
|
||||||
|
|
||||||
${TZCLIENT} list known identities
|
$client gen keys $key1
|
||||||
|
$client gen keys $key2
|
||||||
|
|
||||||
${TZCLIENT} transfer 1000 from bootstrap1 to ${KEY1}
|
$client list known identities
|
||||||
${TZCLIENT} transfer 2000 from bootstrap1 to ${KEY2}
|
|
||||||
|
|
||||||
${TZCLIENT} get balance for ${KEY1} | assert "1,000.00 ꜩ"
|
$client transfer 1000 from bootstrap1 to $key1
|
||||||
${TZCLIENT} get balance for ${KEY2} | assert "2,000.00 ꜩ"
|
$client transfer 2000 from bootstrap1 to $key2
|
||||||
|
|
||||||
${TZCLIENT} transfer 1000 from ${KEY2} to ${KEY1}
|
$client get balance for $key1 | assert "1,000.00 ꜩ"
|
||||||
|
$client get balance for $key2 | assert "2,000.00 ꜩ"
|
||||||
|
|
||||||
${TZCLIENT} get balance for ${KEY1} | assert "2,000.00 ꜩ"
|
$client transfer 1000 from $key2 to $key1
|
||||||
${TZCLIENT} get balance for ${KEY2} | assert "999.95 ꜩ"
|
|
||||||
|
$client get balance for $key1 | assert "2,000.00 ꜩ"
|
||||||
|
$client get balance for $key2 | assert "999.95 ꜩ"
|
||||||
|
|
||||||
# Should fail
|
# Should fail
|
||||||
# ${TZCLIENT} transfer 999.95 from ${KEY2} to ${KEY1}
|
# $client transfer 999.95 from $key2 to $key1
|
||||||
|
|
||||||
${TZCLIENT} mine for bootstrap1
|
# wait for the delay between two block
|
||||||
|
sleep 1
|
||||||
|
|
||||||
${TZCLIENT} remember program noop file:contracts/noop.tz
|
$client mine for bootstrap1
|
||||||
${TZCLIENT} typecheck program noop
|
|
||||||
${TZCLIENT} originate contract noop \
|
|
||||||
for ${KEY1} transferring 1000 from bootstrap1 \
|
|
||||||
running noop
|
|
||||||
${TZCLIENT} transfer 10 from bootstrap1 to noop -arg "Unit"
|
|
||||||
|
|
||||||
${TZCLIENT} originate contract hardlimit \
|
$client remember program noop file:contracts/noop.tz
|
||||||
for ${KEY1} transferring 1000 from bootstrap1 \
|
$client typecheck program noop
|
||||||
running file:contracts/hardlimit.tz -init "3"
|
$client originate contract noop \
|
||||||
${TZCLIENT} transfer 10 from bootstrap1 to hardlimit -arg "Unit"
|
for $key1 transferring 1000 from bootstrap1 \
|
||||||
${TZCLIENT} transfer 10 from bootstrap1 to hardlimit -arg "Unit"
|
running noop
|
||||||
# ${TZCLIENT} transfer 10 from bootstrap1 to hardlimit -arg "unit" # should fail
|
$client transfer 10 from bootstrap1 to noop -arg "Unit"
|
||||||
|
|
||||||
${TZCLIENT} originate free account free_account for ${KEY1}
|
$client originate contract hardlimit \
|
||||||
${TZCLIENT} get delegate for free_account
|
for $key1 transferring 1000 from bootstrap1 \
|
||||||
${TZCLIENT} set delegate for free_account to ${KEY2}
|
running file:contracts/hardlimit.tz -init "3"
|
||||||
${TZCLIENT} get delegate for free_account
|
$client transfer 10 from bootstrap1 to hardlimit -arg "Unit"
|
||||||
|
$client transfer 10 from bootstrap1 to hardlimit -arg "Unit"
|
||||||
|
# $client transfer 10 from bootstrap1 to hardlimit -arg "unit" # should fail
|
||||||
|
|
||||||
${TZCLIENT} get balance for bootstrap5 | assert "4,000,000.00 ꜩ"
|
$client originate free account free_account for $key1
|
||||||
${TZCLIENT} transfer 4000000.00 from bootstrap5 to bootstrap1 -fee 0
|
$client get delegate for free_account
|
||||||
${TZCLIENT} transfer 4000000.00 from bootstrap1 to bootstrap5 -fee 0
|
$client set delegate for free_account to $key2
|
||||||
${TZCLIENT} get balance for bootstrap5 | assert "4,000,000.00 ꜩ"
|
$client get delegate for free_account
|
||||||
|
|
||||||
|
$client get balance for bootstrap5 | assert "4,000,000.00 ꜩ"
|
||||||
|
$client transfer 4000000.00 from bootstrap5 to bootstrap1 -fee 0
|
||||||
|
$client transfer 4000000.00 from bootstrap1 to bootstrap5 -fee 0
|
||||||
|
$client get balance for bootstrap5 | assert "4,000,000.00 ꜩ"
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo End of test
|
echo End of test
|
||||||
echo
|
echo
|
||||||
|
|
||||||
|
show_logs="no"
|
||||||
|
@ -1,17 +1,19 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
|
||||||
source test_utils.sh
|
test_dir="$(cd "$(dirname "$0")" && echo "$(pwd -P)")"
|
||||||
|
source $test_dir/lib/test_lib.inc.sh
|
||||||
start_sandboxed_node
|
|
||||||
sleep 3
|
|
||||||
|
|
||||||
|
start_node 1
|
||||||
activate_alpha
|
activate_alpha
|
||||||
|
|
||||||
add_bootstrap_identities
|
key1=foo
|
||||||
|
key2=bar
|
||||||
|
|
||||||
|
$client gen keys $key1
|
||||||
|
$client gen keys $key2
|
||||||
|
|
||||||
printf "\n\n"
|
printf "\n\n"
|
||||||
|
|
||||||
@ -203,67 +205,68 @@ assert_output $CONTRACT_PATH/check_signature.tz \
|
|||||||
'(Pair "26981d372a7b3866621bf79713d249197fe6d518ef702fa65738e1715bde9da54df04fefbcc84287ecaa9f74ad9296462731aa24bbcece63c6bf73a8f5752309" "abcd")' \
|
'(Pair "26981d372a7b3866621bf79713d249197fe6d518ef702fa65738e1715bde9da54df04fefbcc84287ecaa9f74ad9296462731aa24bbcece63c6bf73a8f5752309" "abcd")' \
|
||||||
'"tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"' False
|
'"tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"' False
|
||||||
|
|
||||||
|
$client transfer 1000 from bootstrap1 to $key1
|
||||||
|
$client transfer 2000 from bootstrap1 to $key2
|
||||||
|
|
||||||
${TZCLIENT} transfer 1000 from bootstrap1 to ${KEY1}
|
assert_balance $key1 "1,000.00 ꜩ"
|
||||||
${TZCLIENT} transfer 2000 from bootstrap1 to ${KEY2}
|
assert_balance $key2 "2,000.00 ꜩ"
|
||||||
|
|
||||||
assert_balance ${KEY1} "1,000.00 ꜩ"
|
|
||||||
assert_balance ${KEY2} "2,000.00 ꜩ"
|
|
||||||
|
|
||||||
# Create a contract and transfer 100 ꜩ to it
|
# Create a contract and transfer 100 ꜩ to it
|
||||||
init_with_transfer $CONTRACT_PATH/store_input.tz ${KEY1} '""' 100 bootstrap1
|
init_with_transfer $CONTRACT_PATH/store_input.tz $key1 '""' 100 bootstrap1
|
||||||
${TZCLIENT} transfer 100 from bootstrap1 to store_input -arg '"abcdefg"'
|
$client transfer 100 from bootstrap1 to store_input -arg '"abcdefg"'
|
||||||
assert_balance store_input "200.00 ꜩ"
|
assert_balance store_input "200.00 ꜩ"
|
||||||
assert_storage_contains store_input '"abcdefg"'
|
assert_storage_contains store_input '"abcdefg"'
|
||||||
${TZCLIENT} transfer 100 from bootstrap1 to store_input -arg '"xyz"'
|
$client transfer 100 from bootstrap1 to store_input -arg '"xyz"'
|
||||||
assert_storage_contains store_input '"xyz"'
|
assert_storage_contains store_input '"xyz"'
|
||||||
|
|
||||||
init_with_transfer $CONTRACT_PATH/transfer_amount.tz ${KEY1} '"0"' "100" bootstrap1
|
init_with_transfer $CONTRACT_PATH/transfer_amount.tz $key1 '"0"' "100" bootstrap1
|
||||||
${TZCLIENT} transfer 500 from bootstrap1 to transfer_amount -arg Unit
|
$client transfer 500 from bootstrap1 to transfer_amount -arg Unit
|
||||||
assert_storage_contains transfer_amount 500
|
assert_storage_contains transfer_amount 500
|
||||||
|
|
||||||
# This tests the `NOW` instruction.
|
# This tests the `NOW` instruction.
|
||||||
# This test may fail if timings are marginal, though I have not yet seen this happen
|
# This test may fail if timings are marginal, though I have not yet seen this happen
|
||||||
init_with_transfer $CONTRACT_PATH/store_now.tz ${KEY1} '"2017-07-13T09:19:01Z"' "100" bootstrap1
|
init_with_transfer $CONTRACT_PATH/store_now.tz $key1 '"2017-07-13T09:19:01Z"' "100" bootstrap1
|
||||||
${TZCLIENT} transfer 500 from bootstrap1 to store_now -arg Unit
|
$client transfer 500 from bootstrap1 to store_now -arg Unit
|
||||||
assert_storage_contains store_now "$(${TZCLIENT} get timestamp)"
|
assert_storage_contains store_now "$($client get timestamp)"
|
||||||
|
|
||||||
# Tests TRANSFER_TO
|
# Tests TRANSFER_TO
|
||||||
${TZCLIENT} originate account "test_transfer_account1" for ${KEY1} transferring 100 from bootstrap1
|
$client originate account "test_transfer_account1" for $key1 transferring 100 from bootstrap1
|
||||||
${TZCLIENT} originate account "test_transfer_account2" for ${KEY1} transferring 20 from bootstrap1
|
$client originate account "test_transfer_account2" for $key1 transferring 20 from bootstrap1
|
||||||
init_with_transfer $CONTRACT_PATH/transfer_to.tz ${KEY2} Unit 1000 bootstrap1
|
init_with_transfer $CONTRACT_PATH/transfer_to.tz $key2 Unit 1000 bootstrap1
|
||||||
assert_balance test_transfer_account1 "100.00 ꜩ"
|
assert_balance test_transfer_account1 "100.00 ꜩ"
|
||||||
${TZCLIENT} transfer 100 from bootstrap1 to transfer_to \
|
$client transfer 100 from bootstrap1 to transfer_to \
|
||||||
-arg "\"$(get_contract_addr test_transfer_account1)\""
|
-arg "\"$(get_contract_addr test_transfer_account1)\""
|
||||||
assert_balance test_transfer_account1 "200.00 ꜩ" # Why isn't this 200 ꜩ? Mining fee?
|
assert_balance test_transfer_account1 "200.00 ꜩ" # Why isn't this 200 ꜩ? Mining fee?
|
||||||
${TZCLIENT} transfer 100 from bootstrap1 to transfer_to \
|
$client transfer 100 from bootstrap1 to transfer_to \
|
||||||
-arg "\"$(get_contract_addr test_transfer_account2)\""
|
-arg "\"$(get_contract_addr test_transfer_account2)\""
|
||||||
assert_balance test_transfer_account2 "120.00 ꜩ" # Why isn't this 120 ꜩ? Mining fee?
|
assert_balance test_transfer_account2 "120.00 ꜩ" # Why isn't this 120 ꜩ? Mining fee?
|
||||||
|
|
||||||
# Tests create_account
|
# Tests create_account
|
||||||
init_with_transfer $CONTRACT_PATH/create_account.tz ${KEY2} \
|
init_with_transfer $CONTRACT_PATH/create_account.tz $key2 \
|
||||||
"\"$(get_contract_addr test_transfer_account1)\"" 1000 bootstrap1
|
"\"$(get_contract_addr test_transfer_account1)\"" 1000 bootstrap1
|
||||||
${TZCLIENT} transfer 100 from bootstrap1 to create_account \
|
$client transfer 100 from bootstrap1 to create_account \
|
||||||
-arg '"tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"' | assert_in_output "New contract"
|
-arg '"tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"' | assert_in_output "New contract"
|
||||||
|
|
||||||
# Creates a contract, transfers data to it and stores the data
|
# Creates a contract, transfers data to it and stores the data
|
||||||
init_with_transfer $CONTRACT_PATH/create_contract.tz ${KEY2} \
|
init_with_transfer $CONTRACT_PATH/create_contract.tz $key2 \
|
||||||
"\"$(get_contract_addr test_transfer_account1)\"" 1000 bootstrap1
|
"\"$(get_contract_addr test_transfer_account1)\"" 1000 bootstrap1
|
||||||
${TZCLIENT} transfer 0.00 from bootstrap1 to create_contract -arg '"tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"'
|
$client transfer 0.00 from bootstrap1 to create_contract -arg '"tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"'
|
||||||
assert_storage_contains create_contract '"abcdefg"'
|
assert_storage_contains create_contract '"abcdefg"'
|
||||||
|
|
||||||
# Test DEFAULT_ACCOUNT
|
# Test DEFAULT_ACCOUNT
|
||||||
init_with_transfer $CONTRACT_PATH/default_account.tz ${KEY1} \
|
init_with_transfer $CONTRACT_PATH/default_account.tz $key1 \
|
||||||
Unit 1000 bootstrap1
|
Unit 1000 bootstrap1
|
||||||
${TZCLIENT} transfer 0.00 from bootstrap1 to default_account -arg "\"$BOOTSTRAP4_IDENTITY\""
|
$client transfer 0.00 from bootstrap1 to default_account -arg "\"$BOOTSTRAP4_IDENTITY\""
|
||||||
assert_balance $BOOTSTRAP4_IDENTITY "4,000,100.00 ꜩ"
|
assert_balance $BOOTSTRAP4_IDENTITY "4,000,100.00 ꜩ"
|
||||||
account=tz1SuakBpFdG9b4twyfrSMqZzruxhpMeSrE5
|
account=tz1SuakBpFdG9b4twyfrSMqZzruxhpMeSrE5
|
||||||
${TZCLIENT} transfer 0.00 from bootstrap1 to default_account -arg "\"$account\""
|
$client transfer 0.00 from bootstrap1 to default_account -arg "\"$account\""
|
||||||
assert_balance $account "100.00 ꜩ"
|
assert_balance $account "100.00 ꜩ"
|
||||||
|
|
||||||
assert_fails ${TZCLIENT} typecheck data '(Map (Item 0 1) (Item 0 1))' against type '(map nat nat)'
|
assert_fails $client typecheck data '(Map (Item 0 1) (Item 0 1))' against type '(map nat nat)'
|
||||||
assert_fails ${TZCLIENT} typecheck data '(Map (Item 0 1) (Item 10 1) (Item 5 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 ${TZCLIENT} typecheck data '(Set "A" "C" "B")' against type '(set string)'
|
assert_fails $client typecheck data '(Set "A" "C" "B")' against type '(set string)'
|
||||||
assert_fails ${TZCLIENT} typecheck data '(Set "A" "B" "B")' against type '(set string)'
|
assert_fails $client typecheck data '(Set "A" "B" "B")' against type '(set string)'
|
||||||
|
|
||||||
printf "\nEnd of test\n"
|
printf "\nEnd of test\n"
|
||||||
|
|
||||||
|
show_logs="no"
|
||||||
|
@ -1,116 +1,88 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
source test_utils.sh
|
set -e
|
||||||
|
|
||||||
export LWT_ASYNC_METHOD="none"
|
test_dir="$(cd "$(dirname "$0")" && echo "$(pwd -P)")"
|
||||||
|
source $test_dir/lib/test_lib.inc.sh
|
||||||
|
|
||||||
node1_rpcs=3000
|
expected_connections=3
|
||||||
node1_addr=[::1]:3001
|
max_peer_id=8
|
||||||
node2_rpcs=3002
|
for i in $(seq 1 $max_peer_id); do
|
||||||
node2_addr=[::1]:3003
|
echo
|
||||||
node3_rpcs=3004
|
echo "## Starting node $i."
|
||||||
node3_addr=[::1]:3005
|
echo
|
||||||
node4_rpcs=3006
|
start_node $i
|
||||||
node4_addr=[::1]:3007
|
echo
|
||||||
|
done
|
||||||
CLIENT_1="$(make_client) -addr [::1] -port $node1_rpcs"
|
|
||||||
CLIENT_2="$(make_client) -addr [::1] -port $node2_rpcs"
|
|
||||||
CLIENT_3="$(make_client) -addr [::1] -port $node3_rpcs"
|
|
||||||
CLIENT_4="$(make_client) -addr [::1] -port $node4_rpcs"
|
|
||||||
|
|
||||||
|
## waiting for the node to establich connections
|
||||||
|
sleep 2
|
||||||
|
for client in "${client_instances[@]}"; do
|
||||||
|
echo
|
||||||
|
echo "### $client network stat"
|
||||||
|
echo
|
||||||
|
$client network stat
|
||||||
|
echo
|
||||||
|
done
|
||||||
|
|
||||||
|
activate_alpha
|
||||||
|
sleep 5
|
||||||
|
|
||||||
assert_propagation_level() {
|
assert_propagation_level() {
|
||||||
level=$1
|
level=$1
|
||||||
printf "\n\nAsserting all nodes have reached level %s\n" "$level"
|
printf "\n\nAsserting all nodes have reached level %s\n" "$level"
|
||||||
${CLIENT_1} rpc call /blocks/head/proto/context/level \
|
for client in "${client_instances[@]}"; do
|
||||||
| assert_in_output "\"level\": $level"
|
$client rpc call /blocks/head/proto/context/level \
|
||||||
${CLIENT_2} rpc call /blocks/head/proto/context/level \
|
| assert_in_output "\"level\": $level"
|
||||||
| assert_in_output "\"level\": $level"
|
done
|
||||||
${CLIENT_3} rpc call /blocks/head/proto/context/level \
|
|
||||||
| assert_in_output "\"level\": $level"
|
|
||||||
${CLIENT_4} rpc call /blocks/head/proto/context/level \
|
|
||||||
| assert_in_output "\"level\": $level"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
start_sandboxed_node --rpc-addr=[::1]:$node1_rpcs --net-addr=$node1_addr --peer=$node2_addr --no-bootstrap-peers
|
|
||||||
start_sandboxed_node --rpc-addr=[::1]:$node2_rpcs --net-addr=$node2_addr --peer=$node1_addr --no-bootstrap-peers
|
|
||||||
start_sandboxed_node --rpc-addr=[::1]:$node3_rpcs --net-addr=$node3_addr --peer=$node1_addr --no-bootstrap-peers
|
|
||||||
start_sandboxed_node --rpc-addr=[::1]:$node4_rpcs --net-addr=$node4_addr --peer=$node1_addr --no-bootstrap-peers
|
|
||||||
|
|
||||||
sleep 3
|
|
||||||
|
|
||||||
printf "\n\n"
|
|
||||||
|
|
||||||
activate_alpha [::1] $node1_rpcs
|
|
||||||
|
|
||||||
sleep 3
|
|
||||||
|
|
||||||
printf "\n\nAsserting protocol propagation\n"
|
printf "\n\nAsserting protocol propagation\n"
|
||||||
|
|
||||||
${CLIENT_1} rpc call /blocks/head/protocol \
|
for client in "${client_instances[@]}"; do
|
||||||
| assert_in_output "ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK"
|
$client rpc call /blocks/head/protocol \
|
||||||
${CLIENT_2} rpc call /blocks/head/protocol \
|
| assert_in_output "ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK"
|
||||||
| assert_in_output "ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK"
|
done
|
||||||
${CLIENT_3} rpc call /blocks/head/protocol \
|
|
||||||
| assert_in_output "ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK"
|
|
||||||
${CLIENT_4} rpc call /blocks/head/protocol \
|
|
||||||
| assert_in_output "ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK"
|
|
||||||
|
|
||||||
printf "\n\n"
|
printf "\n\n"
|
||||||
|
|
||||||
add_bootstrap_identities "${CLIENT_1}"
|
$client1 mine for bootstrap1
|
||||||
add_bootstrap_identities "${CLIENT_2}"
|
sleep 5
|
||||||
add_bootstrap_identities "${CLIENT_3}"
|
|
||||||
add_bootstrap_identities "${CLIENT_4}"
|
|
||||||
|
|
||||||
printf "\n\n"
|
|
||||||
|
|
||||||
${CLIENT_1} mine for bootstrap1
|
|
||||||
|
|
||||||
sleep 3
|
|
||||||
|
|
||||||
assert_propagation_level 2
|
assert_propagation_level 2
|
||||||
${CLIENT_2} mine for bootstrap2
|
|
||||||
|
|
||||||
sleep 3
|
|
||||||
|
|
||||||
|
$client2 mine for bootstrap2
|
||||||
|
sleep 5
|
||||||
assert_propagation_level 3
|
assert_propagation_level 3
|
||||||
${CLIENT_3} mine for bootstrap3
|
|
||||||
|
|
||||||
sleep 3
|
|
||||||
|
|
||||||
|
$client3 mine for bootstrap3
|
||||||
|
sleep 5
|
||||||
assert_propagation_level 4
|
assert_propagation_level 4
|
||||||
${CLIENT_4} mine for bootstrap4
|
|
||||||
|
|
||||||
sleep 3
|
|
||||||
|
|
||||||
|
$client4 mine for bootstrap4
|
||||||
|
sleep 5
|
||||||
assert_propagation_level 5
|
assert_propagation_level 5
|
||||||
|
|
||||||
endorse_hash=$(${CLIENT_3} endorse for bootstrap3 | extract_operation_hash)
|
endorse_hash=$($client3 endorse for bootstrap3 | extract_operation_hash)
|
||||||
|
transfer_hash=$($client4 transfer 500 from bootstrap1 to bootstrap3 | extract_operation_hash)
|
||||||
|
sleep 5
|
||||||
|
|
||||||
transfer_hash=$(${CLIENT_4} transfer 500 from bootstrap1 to bootstrap3 | extract_operation_hash)
|
$client4 mine for bootstrap4
|
||||||
|
sleep 5
|
||||||
sleep 3
|
|
||||||
|
|
||||||
${CLIENT_4} mine for bootstrap4
|
|
||||||
|
|
||||||
sleep 3
|
|
||||||
|
|
||||||
assert_contains_operation() {
|
assert_contains_operation() {
|
||||||
hash="$1"
|
hash="$1"
|
||||||
printf "Asserting operations list contains '$hash'\n"
|
printf "Asserting operations list contains '$hash'\n"
|
||||||
${CLIENT_1} rpc call /blocks/head/operations with {} \
|
for client in "${client_instances[@]}"; do
|
||||||
| assert_in_output $hash
|
$client rpc call /blocks/head/operations with {} \
|
||||||
${CLIENT_2} rpc call /blocks/head/operations with {} \
|
| assert_in_output $hash
|
||||||
| assert_in_output $hash
|
done
|
||||||
${CLIENT_3} rpc call /blocks/head/operations with {} \
|
|
||||||
| assert_in_output $hash
|
|
||||||
${CLIENT_4} rpc call /blocks/head/operations with {} \
|
|
||||||
| assert_in_output $hash
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_contains_operation $endorse_hash
|
assert_contains_operation $endorse_hash
|
||||||
assert_contains_operation $transfer_hash
|
assert_contains_operation $transfer_hash
|
||||||
|
|
||||||
# printf "\nEnd of test"
|
echo
|
||||||
|
echo End of test
|
||||||
|
echo
|
||||||
|
|
||||||
|
show_logs="no"
|
||||||
|
Loading…
Reference in New Issue
Block a user