Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polish test-dev script #348

Merged
merged 2 commits into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions scripts/devnet-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ PORT=5050
if [[ -n "${STARKNET_HARDHAT_DEV:-}" ]]; then
echo "Running dockerized Devnet..."
# Get default from config.json file
# We may be inside example dir or main plugin dir
# This script needs to be generic and work in both cases
# We may be inside example dir or main plugin dir
# This script needs to be generic and work in both cases
if [[ -e "./config.json" ]]; then
STARKNET_DEVNET_DEFAULT=$(node -e "console.log(require('./config.json').STARKNET_DEVNET)")
else
Expand All @@ -29,20 +29,27 @@ else
echo "Spawned devnet with PID $!"
fi

echo "Waiting for devnet... "
# Display the fact that devnet is loading by rotating a straight line |
loading_chars=("|" "/" "-" "\\")
total_loading_chars=${#loading_chars[@]}

sleep 1
for ((i = 0 ; i < 35 ; i++)); do
echo -ne "\r $((i+1)) "

MAX_WAIT=35 # seconds
for ((i = 0; i < $MAX_WAIT; i++)); do
loading_char_i=$((i % total_loading_chars))
loading_char=${loading_chars[$loading_char_i]}""
echo -ne "\r Spawning Devnet $loading_char"

if is_alive=$(curl -s -w "\n" "http://$HOST:$PORT/is_alive"); then
echo ""
echo "$is_alive"
break
else
sleep 1
fi
done

if [[ $i -ge 35 ]]; then
if [[ $i -ge "$MAX_WAIT" ]]; then
echo "Failed to run devnet :("
exit 1
fi
2 changes: 1 addition & 1 deletion scripts/setup-venv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ echo "python version: $(python --version)"
if [[ "$OSTYPE" == "darwin"* ]]; then
export HOMEBREW_NO_INSTALL_CLEANUP=1
brew ls --versions gmp || brew install gmp
CFLAGS=-I`brew --prefix gmp`/include LDFLAGS=-L`brew --prefix gmp`/lib pip3 install fastecdsa
CFLAGS=-I$(brew --prefix gmp)/include LDFLAGS=-L$(brew --prefix gmp)/lib pip3 install fastecdsa
fi

if [ "$TEST_SUBDIR" == "venv-tests" ]; then
Expand Down
28 changes: 16 additions & 12 deletions scripts/test-dev.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#!/bin/bash

TEST_SUBDIR_PENDING="true"
TEST_NAME_PENDING="true"
DEVNET_CONTAINER_NAME="starknet_hardhat_devnet"

# shut down container on exit
trap "
echo 'Stopping Devnet'
docker rm -f $DEVNET_CONTAINER_NAME
" EXIT

# Flag: dev mode for testing (and not usual CI)
export STARKNET_HARDHAT_DEV=1
Expand All @@ -10,6 +15,7 @@ export STARKNET_HARDHAT_DEV_NETWORK="integrated-devnet"
cd test

# Loops until a suitable TEST_SUBDIR is provided
TEST_SUBDIR_PENDING="true"
while [[ -n $TEST_SUBDIR_PENDING ]]; do
echo "(Tab to autocomplete)"
read -e -p "Test suite: " TEST_SUBDIR
Expand All @@ -32,6 +38,7 @@ TEST_SUBDIR="${TEST_SUBDIR%/}" # remove trailing slash
cd $TEST_SUBDIR

# Loops until a suitable test_name is provided
TEST_NAME_PENDING="true"
while [[ -n $TEST_NAME_PENDING ]]; do
echo ""
echo "(Tab to autocomplete)"
Expand Down Expand Up @@ -61,7 +68,7 @@ fi

if [[ "y" == "$RUN_SETUP" ]]; then
echo ""
source ./scripts/setup-cairo1-compiler.sh
source ./scripts/setup-cairo1-compiler.sh
rm -rf starknet-hardhat-example
git clone -b "${EXAMPLE_REPO_BRANCH:=plugin}" --single-branch https://github.com/0xSpaceShard/starknet-hardhat-example.git
cd starknet-hardhat-example
Expand All @@ -82,26 +89,23 @@ if [[ "y" == "$RUN_DEVNET" ]]; then
export STARKNET_HARDHAT_DEV_NETWORK="devnet"
./scripts/devnet-run.sh
echo ""
echo "Devnet running, to stop devnet use,"
echo "Devnet running, to stop devnet use:"
echo "+--------------------------------------+"
echo "| docker rm -f starknet_hardhat_devnet |"
echo "| docker rm -f $DEVNET_CONTAINER_NAME |"
echo "+--------------------------------------+"
fi

CONTINUE_TESTING="1"
while [[ "q" != "$CONTINUE_TESTING" ]]; do
while [[ "y" = "${CONTINUE_TESTING:-y}" ]]; do
echo ""
echo "Updating starknet-hardhat-plugin,"
echo "Loading your latest code changes"
cd starknet-hardhat-example
npm install ../ # install plugin from source (parent dir)
cd ..

echo ""
TEST_SUBDIR=$TEST_SUBDIR ./scripts/test.sh $test_name
echo ""
echo "----------------------------------------------"
echo ""
read -e -p "q to gracefully shutdown. Re-run test? " CONTINUE_TESTING
read -e -p "Re-run the test? (Y/n) " CONTINUE_TESTING
done

docker rm -f starknet_hardhat_devnet
echo "Devnet stopped."
2 changes: 2 additions & 0 deletions scripts/test-setup.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

trap 'for killable in $(jobs -p); do kill -9 $killable; done' EXIT

./scripts/ensure-python.sh
Expand Down